/*
* Empire - A multi-player, client/server Internet based war game.
- * Copyright (C) 1986-2008, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ * Copyright (C) 1986-2010, Dave Pare, Jeff Bailey, Thomas Ruschak,
* Ken Stevens, Steve McClure
*
* This program is free software; you can redistribute it and/or modify
* Known contributors to this file:
* Ken Stevens, 1995
* Steve McClure, 1998-2000
- * Markus Armbruster, 2004-2008
+ * Markus Armbruster, 2004-2009
*/
#include <config.h>
#include "unit.h"
static void lnd_mess(char *, struct ulist *);
-static int lnd_hit_mine(struct lndstr *, struct lchrstr *);
+static int lnd_hit_mine(struct lndstr *);
static int has_helpful_engineer(coord, coord, natid);
double
return value;
}
+int
+lnd_reaction_range(struct lndstr *lp)
+{
+ struct sctstr sect;
+
+ getsect(lp->lnd_x, lp->lnd_y, §);
+ if (sect.sct_type == SCT_HEADQ && sect.sct_effic >= 60)
+ return lchr[lp->lnd_type].l_rad + 1;
+ return lchr[lp->lnd_type].l_rad;
+}
+
void
lnd_print(struct ulist *llp, char *s)
{
taken = llp->unit.land.lnd_item[I_MILIT];
/* Spies always die */
- if (((struct lchrstr *)llp->chrp)->l_flags & L_SPY) {
- eff_eq = 100;
+ if (((struct lchrstr *)llp->chrp)->l_flags & L_SPY)
llp->unit.land.lnd_effic = 0;
- } else {
+ else {
eff_eq = ldround(cas * 100.0 /
((struct lchrstr *)llp->chrp)->l_item[I_MILIT], 1);
llp->unit.land.lnd_effic -= eff_eq;
prland(&llp->unit.land));
continue;
}
- if (sect.sct_type == SCT_BSPAN) {
+ if (SCT_MINES_ARE_SEAMINES(§)) {
if (verbose)
- mpr(actor, "%s is on a bridge. No mines there!\n",
- prland(&llp->unit.land));
+ mpr(actor, "%s is in a %s sector. No landmines there!\n",
+ prland(&llp->unit.land), dchr[sect.sct_type].d_name);
continue;
}
if (takemob) {
getsect(llp->unit.land.lnd_x, llp->unit.land.lnd_y, §);
if (sect.sct_oldown == llp->unit.land.lnd_own)
continue;
- if (sect.sct_type == SCT_BSPAN)
- continue;
- if (!sect.sct_mines)
+ if (SCT_LANDMINES(§) == 0)
continue;
if (chance(DMINE_LHITCHANCE(sect.sct_mines) / (1 + 2 * with_eng))) {
- lnd_hit_mine(&llp->unit.land, ((struct lchrstr *)llp->chrp));
+ lnd_hit_mine(&llp->unit.land);
sect.sct_mines--;
putsect(§);
putland(llp->unit.land.lnd_uid, &llp->unit.land);
for (qp = list->q_back; qp != list; qp = next) {
next = qp->q_back;
llp = (struct ulist *)qp;
- /* have to get it again because of collateral damage */
+ /* land unit might have changed (launched SAMs, collateral dmg) */
getland(llp->unit.land.lnd_uid, &llp->unit.land);
landdamage(&llp->unit.land, dam);
putland(llp->unit.land.lnd_uid, &llp->unit.land);
lnd_missile_interdiction(struct emp_qelem *list, coord newx, coord newy,
natid victim)
{
- int dam;
+ int mindam = lnd_count(list) * 20;
+ int hardtarget = lnd_easiest_target(list);
+ int dam, newdam, sublaunch;
+ int stopping = 0;
+ struct plist *plp;
struct emp_qelem msl_list, *qp, *newqp;
msl_sel(&msl_list, newx, newy, victim, P_T, P_MAR, MI_INTERDICT);
- dam = msl_launch_mindam(&msl_list, newx, newy,
- lnd_easiest_target(list), EF_LAND,
- lnd_count(list) * 20, "troops", victim,
- MI_INTERDICT);
+ dam = 0;
+ for (qp = msl_list.q_back; qp != &msl_list; qp = newqp) {
+ newqp = qp->q_back;
+ plp = (struct plist *)qp;
+
+ if (dam < mindam && mission_pln_equip(plp, NULL, 'p') >= 0) {
+ if (msl_launch(&plp->plane, EF_LAND, "troops",
+ newx, newy, victim, &sublaunch) < 0)
+ goto use_up_msl;
+ stopping = 1;
+ if (msl_hit(&plp->plane, hardtarget, EF_LAND,
+ N_LND_MISS, N_LND_SMISS, sublaunch, victim)) {
+ newdam = pln_damage(&plp->plane, 'p', 1);
+ dam += newdam;
+ } else {
+ newdam = pln_damage(&plp->plane, 'p', 0);
+ collateral_damage(newx, newy, newdam);
+ }
+ use_up_msl:
+ plp->plane.pln_effic = 0;
+ putplane(plp->plane.pln_uid, &plp->plane);
+ }
+ emp_remque(qp);
+ free(qp);
+ }
+
if (dam) {
mpr(victim, "missile interdiction mission does %d damage!\n", dam);
collateral_damage(newx, newy, dam);
+ lnd_damage(list, dam);
}
- qp = msl_list.q_forw;
- while (qp != msl_list.q_forw) {
- newqp = qp->q_forw;
- emp_remque(qp);
- free(qp);
- qp = newqp;
- }
- return dam;
+ return stopping;
}
#if 0
double guneff;
int shell, gun;
int dam;
+ int stopping = 0;
int totdam = 0;
int i;
putsect(&fsect);
if (dam < 0)
continue;
+ stopping = 1;
totdam += dam;
mpr(victim, "Incoming fire does %d damage!\n", dam);
wu(0, fsect.sct_own,
nreport(fsect.sct_own, N_SCT_SHELL, victim, 1);
}
if (totdam > 0)
- return lnd_damage(list, totdam);
- return 0;
+ lnd_damage(list, totdam);
+ return stopping;
}
#endif
+static int
+lnd_mission_interdiction(struct emp_qelem *list, coord x, coord y,
+ natid victim)
+{
+ int dam;
+
+ dam = unit_interdict(x, y, victim, "land units",
+ lnd_easiest_target(list),
+ MI_INTERDICT);
+ if (dam >= 0)
+ lnd_damage(list, dam);
+ return dam >= 0;
+}
+
int
lnd_interdict(struct emp_qelem *list, coord newx, coord newy, natid victim)
{
stopping |= lnd_fort_interdiction(list, newx, newy, victim);
#endif
- stopping |=
- lnd_damage(list,
- unit_interdict(newx, newy, victim, "land units",
- lnd_easiest_target(list), MI_INTERDICT));
-
- stopping |=
- lnd_damage(list,
- lnd_missile_interdiction(list, newx, newy, victim));
+ stopping |= lnd_mission_interdiction(list, newx, newy, victim);
+ stopping |= lnd_missile_interdiction(list, newx, newy, victim);
return stopping;
}
}
static int
-lnd_hit_mine(struct lndstr *lp, struct lchrstr *lcp)
+lnd_hit_mine(struct lndstr *lp)
{
int m;
nreport(lp->lnd_own, N_LHIT_MINE, 0, 1);
m = MINE_LDAMAGE();
- if (lcp->l_flags & L_ENGINEER)
+ if (lchr[lp->lnd_type].l_flags & L_ENGINEER)
m /= 2;
landdamage(lp, m);
pr("%s was shot and killed.\n", prland(&llp->unit.land));
llp->unit.land.lnd_effic = 0;
putland(llp->unit.land.lnd_uid, &llp->unit.land);
- lnd_delete(llp, 0);
+ lnd_delete(llp, NULL);
}
}
}
/* move survivors to done */
for (qp = cur.q_back; qp != &cur; qp = next) {
next = qp->q_back;
- llp = (struct ulist *)qp;
emp_remque(qp);
emp_insque(qp, &done);
}