/*
* Empire - A multi-player, client/server Internet based war game.
- * Copyright (C) 1986-2006, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ * Copyright (C) 1986-2008, 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-2006
*/
#include <config.h>
#include <math.h>
-#include "misc.h"
-#include "player.h"
-#include "file.h"
-#include "sect.h"
-#include "path.h"
-#include "news.h"
-#include "nat.h"
-#include "xy.h"
-#include "land.h"
-#include "ship.h"
-#include "nsc.h"
-#include "mission.h"
-#include "plane.h"
+#include <stdlib.h>
#include "combat.h"
#include "damage.h"
+#include "file.h"
+#include "misc.h"
+#include "mission.h"
+#include "nsc.h"
#include "optlist.h"
+#include "path.h"
+#include "player.h"
#include "prototypes.h"
+#include "xy.h"
+#include "empobj.h"
+#include "unit.h"
-static void lnd_mess(char *, struct llist *);
+static void lnd_mess(char *, struct ulist *);
static int lnd_hit_mine(struct lndstr *, struct lchrstr *);
+static int has_helpful_engineer(coord, coord, natid);
-int
+double
attack_val(int combat_mode, struct lndstr *lp)
{
int men;
switch (combat_mode) {
case A_ATTACK:
- return (int)value;
+ return value;
case A_ASSAULT:
if (!(lcp->l_flags & L_MARINE))
- return (int)(assault_penalty * value);
+ return assault_penalty * value;
break;
case A_BOARD:
if (!(lcp->l_flags & L_MARINE))
- return (int)(assault_penalty * men);
+ return assault_penalty * men;
}
- return (int)value;
+ return value;
}
-int
+double
defense_val(struct lndstr *lp)
{
int men;
if (value < 1.0 && men > 0 && !(lcp->l_flags & L_SPY))
return 1;
- return (int)value;
+ return value;
}
void
-lnd_print(struct llist *llp, char *s)
+lnd_print(struct ulist *llp, char *s)
{
- if (llp->land.lnd_own == player->cnum)
- pr("%s %s\n", prland(&llp->land), s);
+ if (llp->unit.land.lnd_own == player->cnum)
+ pr("%s %s\n", prland(&llp->unit.land), s);
else
- wu(0, llp->land.lnd_own, "%s %s\n", prland(&llp->land), s);
+ wu(0, llp->unit.land.lnd_own, "%s %s\n", prland(&llp->unit.land), s);
}
void
-lnd_delete(struct llist *llp, char *s)
+lnd_delete(struct ulist *llp, char *s)
{
if (s)
lnd_print(llp, s);
- putland(llp->land.lnd_uid, &llp->land);
+ putland(llp->unit.land.lnd_uid, &llp->unit.land);
emp_remque((struct emp_qelem *)llp);
free(llp);
}
int
-lnd_take_casualty(int combat_mode, struct llist *llp, int cas)
+lnd_take_casualty(int combat_mode, struct ulist *llp, int cas)
/* attacking or assaulting or paratrooping? */
/* number of casualties to take */
{
signed char orig;
int mob;
- taken = llp->land.lnd_item[I_MILIT];
+ taken = llp->unit.land.lnd_item[I_MILIT];
/* Spies always die */
- if (llp->lcp->l_flags & L_SPY) {
+ if (((struct lchrstr *)llp->chrp)->l_flags & L_SPY) {
eff_eq = 100;
- llp->land.lnd_effic = 0;
+ llp->unit.land.lnd_effic = 0;
} else {
- eff_eq = ldround(cas * 100.0 / llp->lcp->l_mil, 1);
- llp->land.lnd_effic -= eff_eq;
- lnd_submil(&llp->land, cas);
+ eff_eq = ldround(cas * 100.0 /
+ ((struct lchrstr *)llp->chrp)->l_item[I_MILIT], 1);
+ llp->unit.land.lnd_effic -= eff_eq;
+ lnd_submil(&llp->unit.land, cas);
}
- if (llp->land.lnd_effic < LAND_MINEFF) {
+ if (llp->unit.land.lnd_effic < LAND_MINEFF) {
sprintf(buf, "dies %s %s!",
combat_mode ? att_mode[combat_mode] : "defending",
- xyas(llp->land.lnd_x, llp->land.lnd_y, llp->land.lnd_own));
+ xyas(llp->unit.land.lnd_x, llp->unit.land.lnd_y,
+ llp->unit.land.lnd_own));
lnd_delete(llp, buf);
/* Since we killed the unit, we killed all the mil on it */
return taken;
} else {
/* Ok, now, how many did we take off? (sould be the diff) */
- taken = taken - llp->land.lnd_item[I_MILIT];
+ taken = taken - llp->unit.land.lnd_item[I_MILIT];
}
- if (llp->land.lnd_effic >= llp->land.lnd_retreat)
+ if (llp->unit.land.lnd_effic >= llp->unit.land.lnd_retreat)
return taken;
/* we're being boarded */
- if (llp->land.lnd_ship >= 0 && combat_mode == A_DEFEND)
+ if (llp->unit.land.lnd_ship >= 0 && combat_mode == A_DEFEND)
return taken;
/* we're being boarded */
- if (llp->land.lnd_land >= 0 && combat_mode == A_DEFEND)
+ if (llp->unit.land.lnd_land >= 0 && combat_mode == A_DEFEND)
return taken;
/* Have to make a retreat check */
- ret_chance = llp->land.lnd_retreat - llp->land.lnd_effic;
+ ret_chance = llp->unit.land.lnd_retreat - llp->unit.land.lnd_effic;
if (roll(100) < ret_chance) {
pr("\n");
lnd_print(llp, "fails morale check!");
- llp->land.lnd_mission = 0;
- llp->land.lnd_harden = 0;
- if (llp->land.lnd_ship >= 0 || llp->land.lnd_land >= 0)
+ llp->unit.land.lnd_mission = 0;
+ llp->unit.land.lnd_harden = 0;
+ if (llp->unit.land.lnd_ship >= 0 || llp->unit.land.lnd_land >= 0)
nowhere_to_go = 1;
else if (combat_mode == A_DEFEND) {
/*
biggest = -1;
nowned = 0;
for (n = 1; n <= 6; ++n) {
- ret_x = llp->land.lnd_x + diroff[n][0];
- ret_y = llp->land.lnd_y + diroff[n][1];
+ ret_x = llp->unit.land.lnd_x + diroff[n][0];
+ ret_y = llp->unit.land.lnd_y + diroff[n][1];
getsect(ret_x, ret_y, §);
- if (sect.sct_own != llp->land.lnd_own)
+ if (sect.sct_own != llp->unit.land.lnd_own)
continue;
if (sect.sct_type == SCT_MOUNT)
continue;
- mobcost = lnd_mobcost(&llp->land, &rsect);
+ mobcost = lnd_mobcost(&llp->unit.land, &rsect);
if (mobcost < 0)
continue;
++nowned;
nowhere_to_go = 1;
else {
/* retreat to bx,by */
- llp->land.lnd_x = bx;
- llp->land.lnd_y = by;
+ llp->unit.land.lnd_x = bx;
+ llp->unit.land.lnd_y = by;
+ /* FIXME landmines */
getsect(bx, by, &rsect);
- mob = llp->land.lnd_mobil - (int)bmcost;
+ mob = llp->unit.land.lnd_mobil - (int)bmcost;
if (mob < -127)
mob = -127;
- orig = llp->land.lnd_mobil;
- llp->land.lnd_mobil = (signed char)mob;
- if (llp->land.lnd_mobil > orig)
- llp->land.lnd_mobil = -127;
+ orig = llp->unit.land.lnd_mobil;
+ llp->unit.land.lnd_mobil = (signed char)mob;
+ if (llp->unit.land.lnd_mobil > orig)
+ llp->unit.land.lnd_mobil = -127;
sprintf(buf, "retreats at %d%% efficiency to %s!",
- llp->land.lnd_effic,
- xyas(bx, by, llp->land.lnd_own));
+ llp->unit.land.lnd_effic,
+ xyas(bx, by, llp->unit.land.lnd_own));
lnd_delete(llp, buf);
}
} else { /* attacking from a sector */
sprintf(buf, "leaves the battlefield at %d%% efficiency",
- llp->land.lnd_effic);
- if ((llp->land.lnd_mobil - (int)llp->mobil) < -127)
- llp->land.lnd_mobil = -127;
+ llp->unit.land.lnd_effic);
+ if ((llp->unit.land.lnd_mobil - (int)llp->mobil) < -127)
+ llp->unit.land.lnd_mobil = -127;
else
- llp->land.lnd_mobil -= (int)llp->mobil;
+ llp->unit.land.lnd_mobil -= (int)llp->mobil;
llp->mobil = 0.0;
lnd_delete(llp, buf);
}
}
if (nowhere_to_go) {
/* nowhere to go.. take more casualties */
- llp->land.lnd_effic -= 10;
- lnd_submil(&llp->land, llp->lcp->l_mil / 10);
- if (llp->land.lnd_effic < LAND_MINEFF)
+ llp->unit.land.lnd_effic -= 10;
+ lnd_submil(&llp->unit.land,
+ ((struct lchrstr *)llp->chrp)->l_item[I_MILIT] / 10);
+ if (llp->unit.land.lnd_effic < LAND_MINEFF)
lnd_delete(llp, "has nowhere to retreat, and dies!");
else
lnd_print(llp,
lnd_takemob(struct emp_qelem *list, double loss)
{
struct emp_qelem *qp, *next;
- struct llist *llp;
+ struct ulist *llp;
int new;
int mcost = ldround(combat_mob * loss, 1);
for (qp = list->q_forw; qp != list; qp = next) {
next = qp->q_forw;
- llp = (struct llist *)qp;
+ llp = (struct ulist *)qp;
/*
if (chance(loss))
- use_supply(&llp->land);
- if (llp->land.lnd_mission == MI_RESERVE)
- new = llp->land.lnd_mobil - mcost/2;
+ use_supply(&llp->unit.land);
+ if (llp->unit.land.lnd_mission == MI_RESERVE)
+ new = llp->unit.land.lnd_mobil - mcost/2;
else
*/
- new = llp->land.lnd_mobil - mcost;
+ new = llp->unit.land.lnd_mobil - mcost;
if (new < -127)
new = -127;
- llp->land.lnd_mobil = (signed char)new;
+ llp->unit.land.lnd_mobil = (signed char)new;
}
}
return lp->lnd_spy * (lp->lnd_effic / 100.0);
}
-int
+double
intelligence_report(int destination, struct lndstr *lp, int spy,
char *mess)
{
if (lp->lnd_ship < 0 || lcp->l_flags & L_MARINE)
estimate *= lp->lnd_def;
- return (int)estimate;
+ return estimate;
}
/* Used by the spy command to count land units in a sector. If used
void
lnd_sel(struct nstr_item *ni, struct emp_qelem *list)
-
-
-/* int wantflags;
- int nowantflags;
-*/
{
struct lndstr land;
struct lchrstr *lcp;
- struct llist *llp;
+ struct ulist *llp;
+ int this_mot;
+ int mobtype = MOB_MOVE; /* indeterminate */
emp_initque(list);
while (nxtitem(ni, &land)) {
continue;
}
}
+ /*
+ * The marching code gets confused when trains and non-trains
+ * march together. Disallow for now.
+ */
+ this_mot = lnd_mobtype(&land);
+ if (this_mot != mobtype) {
+ if (mobtype == MOB_MOVE)
+ mobtype = this_mot;
+ else if (mobtype == MOB_MARCH) {
+ pr("%s is a train and can't march with the leader.\n",
+ prland(&land));
+ continue;
+ } else {
+ pr("%s can't rail-march with the leading train.\n",
+ prland(&land));
+ continue;
+ }
+ }
+
lcp = &lchr[(int)land.lnd_type];
-/* if (wantflags && (lcp->m_flags & wantflags) != wantflags)
- continue;
- if (nowantflags && lcp->m_flags & nowantflags)
- continue;
-*/
- /* This abuse is better fixed by building a unit with the normal negative
- mobility that everything else is built with */
-/* Just so that the player can't build a bunch of land units, and them
- march them a few minutes later... */
-/*
- if (opt_MOB_ACCESS) {
- if (land.lnd_effic < 11 &&
- land.lnd_mobil < etu_per_update) {
- pr("Land unit #%d needs at least %d mob to march.\n",
- land.lnd_uid, etu_per_update);
- continue;
- }
- }
-*/
land.lnd_mission = 0;
land.lnd_rflags = 0;
land.lnd_harden = 0;
memset(land.lnd_rpath, 0, sizeof(land.lnd_rpath));
putland(land.lnd_uid, &land);
- llp = malloc(sizeof(struct llist));
- llp->lcp = lcp;
- llp->land = land;
+ llp = malloc(sizeof(struct ulist));
+ llp->chrp = (struct empobj_chr *)lcp;
+ llp->unit.land = land;
llp->mobil = land.lnd_mobil;
emp_insque(&llp->queue, list);
}
{
struct emp_qelem *qp;
struct emp_qelem *next;
- struct llist *llp;
+ struct ulist *llp;
struct sctstr sect;
struct lndstr land;
coord allx;
*togetherp = 1;
for (qp = list->q_back; qp != list; qp = next) {
next = qp->q_back;
- llp = (struct llist *)qp;
- getland(llp->land.lnd_uid, &land);
+ llp = (struct ulist *)qp;
+ getland(llp->unit.land.lnd_uid, &land);
if (land.lnd_own != actor) {
mpr(actor, "%s was disbanded at %s\n",
prland(&land), xyas(land.lnd_x, land.lnd_y, land.lnd_own));
lnd_mess("was sucked into the sky by a strange looking spaceland", llp); /* heh -KHS */
continue;
}
- if (!(lchr[(int)llp->land.lnd_type].l_flags & L_SPY) &&
- !(lchr[(int)llp->land.lnd_type].l_flags & L_TRAIN) &&
- llp->land.lnd_item[I_MILIT] == 0) {
+ if (!(lchr[(int)llp->unit.land.lnd_type].l_flags & L_SPY) &&
+ !(lchr[(int)llp->unit.land.lnd_type].l_flags & L_TRAIN) &&
+ llp->unit.land.lnd_item[I_MILIT] == 0) {
lnd_mess("has no mil on it to guide it", llp);
continue;
}
rel = getrel(getnatp(sect.sct_own), player->cnum);
if (sect.sct_own != land.lnd_own && rel != ALLIED &&
- !(lchr[(int)llp->land.lnd_type].l_flags & L_SPY) &&
+ !(lchr[(int)llp->unit.land.lnd_type].l_flags & L_SPY) &&
sect.sct_own) {
sprintf(mess, "has been kidnapped by %s", cname(sect.sct_own));
lnd_mess(mess, llp);
*minmobp = llp->mobil;
if (llp->mobil > *maxmobp)
*maxmobp = llp->mobil;
- llp->land = land;
- }
-}
-
-void
-lnd_put(struct emp_qelem *list, natid actor)
-{
- struct emp_qelem *qp;
- struct emp_qelem *newqp;
- struct llist *llp;
-
- qp = list->q_back;
- while (qp != list) {
- llp = (struct llist *)qp;
- if (actor) {
- mpr(actor, "%s stopped at %s\n", prland(&llp->land),
- xyas(llp->land.lnd_x, llp->land.lnd_y, llp->land.lnd_own));
- if (llp->mobil < -127)
- llp->mobil = -127;
- llp->land.lnd_mobil = llp->mobil;
- }
- putland(llp->land.lnd_uid, &llp->land);
- newqp = qp->q_back;
- emp_remque(qp);
- free(qp);
- qp = newqp;
+ llp->unit.land = land;
}
}
{
struct emp_qelem *qp;
struct emp_qelem *next;
- struct llist *llp;
+ struct ulist *llp;
struct sctstr sect;
int mines, m, max, sshells, lshells;
for (qp = land_list->q_back; qp != land_list; qp = next) {
next = qp->q_back;
- llp = (struct llist *)qp;
- if (!(llp->lcp->l_flags & L_ENGINEER)) {
+ llp = (struct ulist *)qp;
+ if (!(((struct lchrstr *)llp->chrp)->l_flags & L_ENGINEER)) {
if (verbose)
- mpr(actor, "%s is not an engineer!\n", prland(&llp->land));
+ mpr(actor, "%s is not an engineer!\n",
+ prland(&llp->unit.land));
continue;
}
if (takemob && llp->mobil < 0.0) {
lnd_mess("is out of mobility", llp);
continue;
}
- getsect(llp->land.lnd_x, llp->land.lnd_y, §);
- if (sect.sct_oldown == llp->land.lnd_own) {
+ getsect(llp->unit.land.lnd_x, llp->unit.land.lnd_y, §);
+ if (sect.sct_oldown == llp->unit.land.lnd_own) {
if (verbose)
mpr(actor,
"%s is in a sector completely owned by you. Don't bother digging up mines there!\n",
- prland(&llp->land));
+ prland(&llp->unit.land));
continue;
}
if (sect.sct_type == SCT_BSPAN) {
if (verbose)
mpr(actor, "%s is on a bridge. No mines there!\n",
- prland(&llp->land));
+ prland(&llp->unit.land));
continue;
}
if (takemob) {
- llp->mobil -= lnd_pathcost(&llp->land, 0.2);
- llp->land.lnd_mobil = (int)llp->mobil;
- llp->land.lnd_harden = 0;
+ llp->mobil -= lnd_pathcost(&llp->unit.land, 0.2);
+ llp->unit.land.lnd_mobil = (int)llp->mobil;
+ llp->unit.land.lnd_harden = 0;
}
- putland(llp->land.lnd_uid, &llp->land);
+ putland(llp->unit.land.lnd_uid, &llp->unit.land);
if (!(mines = sect.sct_mines))
continue;
- max = llp->lcp->l_item[I_SHELL];
- lshells = llp->land.lnd_item[I_SHELL];
+ max = ((struct lchrstr *)llp->chrp)->l_item[I_SHELL];
+ lshells = llp->unit.land.lnd_item[I_SHELL];
sshells = sect.sct_item[I_SHELL];
for (m = 0; mines > 0 && m < max * 2; m++) {
- if (chance(0.5 * llp->lcp->l_att)) {
+ if (chance(0.5 * ((struct lchrstr *)llp->chrp)->l_att)) {
mpr(actor, "Sweep...\n");
mines--;
if (lshells < max)
}
}
sect.sct_mines = mines;
- llp->land.lnd_item[I_SHELL] = lshells;
+ llp->unit.land.lnd_item[I_SHELL] = lshells;
sect.sct_item[I_SHELL] = sshells;
- putland(llp->land.lnd_uid, &llp->land);
+ putland(llp->unit.land.lnd_uid, &llp->unit.land);
putsect(§);
}
}
{
struct emp_qelem *qp;
struct emp_qelem *next;
- struct llist *llp;
+ struct ulist *llp;
for (qp = list->q_back; qp != list; qp = next) {
next = qp->q_back;
- llp = (struct llist *)qp;
- if (llp->lcp->l_flags & L_ENGINEER)
+ llp = (struct ulist *)qp;
+ if (((struct lchrstr *)llp->chrp)->l_flags & L_ENGINEER)
return 1;
}
return 0;
{
struct emp_qelem *qp;
struct emp_qelem *next;
- struct llist *llp;
+ struct ulist *llp;
struct sctstr sect;
int stopping = 0;
int with_eng = contains_engineer(land_list);
for (qp = land_list->q_back; qp != land_list; qp = next) {
next = qp->q_back;
- llp = (struct llist *)qp;
- getsect(llp->land.lnd_x, llp->land.lnd_y, §);
- if (sect.sct_oldown == llp->land.lnd_own)
+ llp = (struct ulist *)qp;
+ 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)
continue;
if (chance(DMINE_LHITCHANCE(sect.sct_mines) / (1 + 2 * with_eng))) {
- lnd_hit_mine(&llp->land, llp->lcp);
+ lnd_hit_mine(&llp->unit.land, ((struct lchrstr *)llp->chrp));
sect.sct_mines--;
putsect(§);
- putland(llp->land.lnd_uid, &llp->land);
- if (!llp->land.lnd_own) {
+ putland(llp->unit.land.lnd_uid, &llp->unit.land);
+ if (!llp->unit.land.lnd_own) {
stopping = 1;
emp_remque(qp);
free(qp);
return stopping;
}
-void
-lnd_list(struct emp_qelem *land_list)
-{
- struct emp_qelem *qp;
- struct emp_qelem *next;
- struct llist *llp;
- struct lndstr *lnd;
-
- pr("lnd# land type x,y a eff sh gun xl mu tech retr fuel\n");
-
- for (qp = land_list->q_back; qp != land_list; qp = next) {
- next = qp->q_back;
- llp = (struct llist *)qp;
- lnd = &llp->land;
- pr("%4d ", lnd->lnd_uid);
- pr("%-16.16s ", llp->lcp->l_name);
- prxy("%4d,%-4d ", lnd->lnd_x, lnd->lnd_y, llp->land.lnd_own);
- pr("%1.1s", &lnd->lnd_army);
- pr("%4d%%", lnd->lnd_effic);
- pr("%4d", lnd->lnd_item[I_SHELL]);
- pr("%4d", lnd->lnd_item[I_GUN]);
- count_land_planes(lnd);
- pr("%3d", lnd->lnd_nxlight);
- pr("%4d", lnd->lnd_mobil);
- pr("%4d", lnd->lnd_tech);
- pr("%4d%%", lnd->lnd_retreat);
- pr("%5d\n", lnd->lnd_fuel);
- }
-}
-
static void
-lnd_mess(char *str, struct llist *llp)
+lnd_mess(char *str, struct ulist *llp)
{
- mpr(llp->land.lnd_own, "%s %s & stays in %s\n",
- prland(&llp->land),
- str, xyas(llp->land.lnd_x, llp->land.lnd_y, llp->land.lnd_own));
+ mpr(llp->unit.land.lnd_own, "%s %s & stays in %s\n",
+ prland(&llp->unit.land),
+ str, xyas(llp->unit.land.lnd_x, llp->unit.land.lnd_y,
+ llp->unit.land.lnd_own));
if (llp->mobil < -127)
llp->mobil = -127;
- llp->land.lnd_mobil = llp->mobil;
- putland(llp->land.lnd_uid, &llp->land);
+ llp->unit.land.lnd_mobil = llp->mobil;
+ putland(llp->unit.land.lnd_uid, &llp->unit.land);
emp_remque((struct emp_qelem *)llp);
free(llp);
}
{
struct emp_qelem *qp;
struct emp_qelem *next;
- struct llist *llp;
int count = 0;
for (qp = list->q_back; qp != list; qp = next) {
next = qp->q_back;
- llp = (struct llist *)qp;
++count;
}
return count;
{
struct emp_qelem *qp;
struct emp_qelem *next;
- struct llist *llp;
+ struct ulist *llp;
int dam;
int count;
dam = ldround((double)totdam / count, 1);
for (qp = list->q_back; qp != list; qp = next) {
next = qp->q_back;
- llp = (struct llist *)qp;
+ llp = (struct ulist *)qp;
/* have to get it again because of collateral damage */
- getland(llp->land.lnd_uid, &llp->land);
- landdamage(&llp->land, dam);
- putland(llp->land.lnd_uid, &llp->land);
- if (!llp->land.lnd_own) {
+ getland(llp->unit.land.lnd_uid, &llp->unit.land);
+ landdamage(&llp->unit.land, dam);
+ putland(llp->unit.land.lnd_uid, &llp->unit.land);
+ if (!llp->unit.land.lnd_own) {
emp_remque(qp);
free(qp);
}
{
struct emp_qelem *qp;
struct emp_qelem *next;
- struct llist *llp;
+ struct ulist *llp;
int hard;
int easiest = 9876; /* things start great for victim */
int count = 0;
for (qp = list->q_back; qp != list; qp = next) {
next = qp->q_back;
- llp = (struct llist *)qp;
- hard = lnd_hardtarget(&llp->land);
+ llp = (struct ulist *)qp;
+ hard = lnd_hardtarget(&llp->unit.land);
if (hard < easiest)
easiest = hard; /* things get worse for victim */
++count;
static int
lnd_hit_mine(struct lndstr *lp, struct lchrstr *lcp)
{
- double m;
+ int m;
mpr(lp->lnd_own, "Blammo! Landmines detected in %s! ",
xyas(lp->lnd_x, lp->lnd_y, lp->lnd_own));
m = MINE_LDAMAGE();
if (lcp->l_flags & L_ENGINEER)
- m /= 2.0;
-
- landdamage(lp, ldround(m, 1));
+ m /= 2;
- return (int)m;
+ landdamage(lp, m);
+ return m;
}
double
struct emp_qelem *qp;
struct emp_qelem *qp2;
struct emp_qelem *next;
- struct llist *llp;
+ struct ulist *llp;
struct emp_qelem cur, done;
coord dx;
coord dy;
int oldown;
if (dir <= DIR_STOP || dir >= DIR_VIEW) {
- lnd_put(list, actor);
+ unit_put(list, actor);
return 1;
}
dx = diroff[dir][0];
dy = diroff[dir][1];
for (qp = list->q_back; qp != list; qp = next) {
next = qp->q_back;
- llp = (struct llist *)qp;
- getsect(llp->land.lnd_x, llp->land.lnd_y, &osect);
+ llp = (struct ulist *)qp;
+ getsect(llp->unit.land.lnd_x, llp->unit.land.lnd_y, &osect);
oldown = osect.sct_own;
- newx = xnorm(llp->land.lnd_x + dx);
- newy = ynorm(llp->land.lnd_y + dy);
+ newx = xnorm(llp->unit.land.lnd_x + dx);
+ newy = ynorm(llp->unit.land.lnd_y + dy);
getsect(newx, newy, §);
rel = getrel(getnatp(sect.sct_own), player->cnum);
if ((sect.sct_own != actor && rel != ALLIED &&
- !(lchr[(int)llp->land.lnd_type].l_flags & L_SPY) &&
+ !(lchr[(int)llp->unit.land.lnd_type].l_flags & L_SPY) &&
sect.sct_own) || (sect.sct_type == SCT_WATER ||
sect.sct_type == SCT_SANCT ||
sect.sct_type == SCT_WASTE)) {
continue;
}
}
- if (sect.sct_rail == 0 &&
- lchr[(int)llp->land.lnd_type].l_flags & L_TRAIN) {
+ if ((!intrchr[INT_RAIL].in_enable || sect.sct_rail == 0)
+ && lnd_mobtype(&llp->unit.land) == MOB_RAIL) {
if (together) {
pr("no rail system in %s\n", xyas(newx, newy, actor));
return 1;
}
/* Note we check would_abandon first because we don't want
to always have to do these checks */
- if (would_abandon(&osect, I_CIVIL, 0, &llp->land)) {
+ if (would_abandon(&osect, I_CIVIL, 0, &llp->unit.land)) {
stop = 0;
- if (!want_to_abandon(&osect, I_CIVIL, 0, &llp->land)) {
+ if (!want_to_abandon(&osect, I_CIVIL, 0, &llp->unit.land)) {
stop = 1;
}
/* now check stuff */
if (!check_sect_ok(&osect))
return 1;
for (qp2 = list->q_back; qp2 != list; qp2 = qp2->q_back) {
- if (!check_land_ok(&((struct llist *)qp2)->land))
+ if (!check_land_ok(&((struct ulist *)qp2)->unit.land))
return 1;
}
if (stop) {
lnd_mess("is out of mobility", llp);
continue;
}
- llp->land.lnd_x = newx;
- llp->land.lnd_y = newy;
- llp->mobil -= lnd_mobcost(&llp->land, §);
- llp->land.lnd_mobil = (int)llp->mobil;
- llp->land.lnd_harden = 0;
- putland(llp->land.lnd_uid, &llp->land);
+ llp->unit.land.lnd_x = newx;
+ llp->unit.land.lnd_y = newy;
+ llp->mobil -= lnd_mobcost(&llp->unit.land, §);
+ llp->unit.land.lnd_mobil = (int)llp->mobil;
+ llp->unit.land.lnd_harden = 0;
+ putland(llp->unit.land.lnd_uid, &llp->unit.land);
putsect(&osect);
getsect(osect.sct_x, osect.sct_y, &osect);
if (osect.sct_own != oldown && oldown == player->cnum) {
}
if (rel != ALLIED && sect.sct_own != actor && sect.sct_own) { /* must be a spy */
/* Always a 10% chance of getting caught. */
- if (chance(LND_SPY_DETECT_CHANCE(llp->land.lnd_effic))) {
+ if (chance(LND_SPY_DETECT_CHANCE(llp->unit.land.lnd_effic))) {
if (rel == NEUTRAL || rel == FRIENDLY) {
wu(0, sect.sct_own,
"%s unit spotted in %s\n", cname(player->cnum),
xyas(sect.sct_x, sect.sct_y, sect.sct_own));
- setrel(sect.sct_own, llp->land.lnd_own, HOSTILE);
+ setrel(sect.sct_own, llp->unit.land.lnd_own, HOSTILE);
} else if (rel == HOSTILE || rel == AT_WAR ||
rel == SITZKRIEG || rel == MOBILIZATION) {
wu(0, sect.sct_own,
"%s spy shot in %s\n", cname(player->cnum),
xyas(sect.sct_x, sect.sct_y, sect.sct_own));
- pr("%s was shot and killed.\n", prland(&llp->land));
- llp->land.lnd_effic = 0;
- putland(llp->land.lnd_uid, &llp->land);
+ 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);
}
}
emp_initque(&cur);
emp_initque(&done);
while (!QEMPTY(list)) {
- llp = (struct llist *)list->q_back;
- newx = llp->land.lnd_x;
- newy = llp->land.lnd_y;
+ llp = (struct ulist *)list->q_back;
+ newx = llp->unit.land.lnd_x;
+ newy = llp->unit.land.lnd_y;
/* move units in NEWX,NEWY to cur */
visible = 0;
for (qp = list->q_back; qp != list; qp = next) {
next = qp->q_back;
- llp = (struct llist *)qp;
- if (llp->land.lnd_x == newx && llp->land.lnd_y == newy) {
+ llp = (struct ulist *)qp;
+ if (llp->unit.land.lnd_x == newx && llp->unit.land.lnd_y == newy) {
emp_remque(qp);
emp_insque(qp, &cur);
- if (!(lchr[(int)llp->land.lnd_type].l_flags & L_SPY))
+ if (!(lchr[(int)llp->unit.land.lnd_type].l_flags & L_SPY))
visible = 1;
}
}
/* move survivors to done */
for (qp = cur.q_back; qp != &cur; qp = next) {
next = qp->q_back;
- llp = (struct llist *)qp;
+ llp = (struct ulist *)qp;
emp_remque(qp);
emp_insque(qp, &done);
}
}
return (int)dam;
}
-
-char *
-lnd_path(int together, struct lndstr *lp, char *buf)
-{
- coord destx;
- coord desty;
- struct sctstr d_sect, sect;
- char *cp;
- double dummy;
- int mtype;
-
- if (!sarg_xy(buf, &destx, &desty))
- return 0;
- if (!together) {
- pr("Cannot go to a destination sector if not all starting in the same sector\n");
- return 0;
- }
- if (!getsect(destx, desty, &d_sect)) {
- pr("%d,%d is not a sector\n", destx, desty);
- return 0;
- }
- getsect(lp->lnd_x, lp->lnd_y, §);
- mtype = lnd_mobtype(lp);
- cp = BestLandPath(buf, §, &d_sect, &dummy, mtype);
- if (!cp) {
- pr("No owned %s from %s to %s!\n",
- mtype == MOB_RAIL ? "railway" : "path",
- xyas(lp->lnd_x, lp->lnd_y, player->cnum),
- xyas(d_sect.sct_x, d_sect.sct_y, player->cnum));
- return 0;
- }
- pr("Using path '%s'\n", cp);
- return cp;
-}
-
int
lnd_can_attack(struct lndstr *lp)
{
/*
* Increase fortification value of LP.
- * Fortification costs mobility. Use up to HARD_AMT mobility.
+ * Fortification costs mobility. Use up to MOB mobility.
* Return actual fortification increase.
*/
int
-lnd_fortify (struct lndstr *lp, int hard_amt)
+lnd_fortify(struct lndstr *lp, int mob)
{
- int mob_used;
- int eng;
+ int hard_amt;
+ double mob_used, mult;
- if ((lp->lnd_ship >= 0) || lp->lnd_land >= 0)
+ if (lp->lnd_ship >= 0 || lp->lnd_land >= 0)
return 0;
- hard_amt = MIN(lp->lnd_mobil, hard_amt);
-
- if ((lp->lnd_harden + hard_amt) > land_mob_max)
- hard_amt = land_mob_max - lp->lnd_harden;
-
- eng = has_helpful_engineer(lp->lnd_x, lp->lnd_y, lp->lnd_own);
+ mob_used = MIN(lp->lnd_mobil, mob);
+ if (mob_used < 0)
+ return 0;
- if (eng)
- hard_amt *= 1.5;
+ mult = has_helpful_engineer(lp->lnd_x, lp->lnd_y, lp->lnd_own)
+ ? 1.5 : 1.0;
- if ((lp->lnd_harden + hard_amt) > land_mob_max)
+ hard_amt = (int)(mob_used * mult);
+ if (lp->lnd_harden + hard_amt > land_mob_max) {
hard_amt = land_mob_max - lp->lnd_harden;
+ mob_used = ceil(hard_amt / mult);
+ }
- /* Ok, set the mobility used */
- mob_used = hard_amt;
-
- /* Now, if an engineer helped, it's really only 2/3rds of
- that */
- if (eng)
- mob_used /= 1.5;
-
- /* If we increased it, but not much, we gotta take at least 1
- mob point. */
- if (mob_used <= 0 && hard_amt > 0)
- mob_used = 1;
-
- lp->lnd_mobil -= mob_used;
- if (lp->lnd_mobil < 0)
- lp->lnd_mobil = 0;
-
+ lp->lnd_mobil -= (int)mob_used;
lp->lnd_harden += hard_amt;
lp->lnd_harden = MIN(lp->lnd_harden, land_mob_max);
return hard_amt;
}
+/*
+ * Is there a engineer unit at X,Y that can help nation CN?
+ */
+static int
+has_helpful_engineer(coord x, coord y, natid cn)
+{
+ struct nstr_item ni;
+ struct lndstr land;
+
+ snxtitem_xy(&ni, EF_LAND, x, y);
+ while (nxtitem(&ni, &land)) {
+ if (land.lnd_own != cn && getrel(getnatp(land.lnd_own), cn) != ALLIED)
+ continue;
+ if (lchr[(int)land.lnd_type].l_flags & L_ENGINEER)
+ return 1;
+ }
+
+ return 0;
+}
+
/*
* Set LP's tech to TLEV along with everything else that depends on it.
*/
lp->lnd_frg = (int)LND_FRG(lcp->l_frg, tech_diff);
lp->lnd_acc = (int)LND_ACC(lcp->l_acc, tech_diff);
lp->lnd_dam = (int)LND_DAM(lcp->l_dam, tech_diff);
- lp->lnd_ammo = (int)LND_AMM(lcp->l_ammo, lcp->l_dam, tech_diff);
+ lp->lnd_ammo = (int)LND_AMM(lcp->l_ammo, tech_diff);
lp->lnd_aaf = (int)LND_AAF(lcp->l_aaf, tech_diff);
lp->lnd_fuelc = (int)LND_FC(lcp->l_fuelc, tech_diff);
lp->lnd_fuelu = (int)LND_FU(lcp->l_fuelu, tech_diff);