Combined struct llist and struct mlist into superset struct ulist.

(assa, set_leader, switch_leader, set_flagship, switch_flagship,
take_move_in_mob, get_land, ask_olist, att_get_defense,
get_dlist, get_ototal, get_dtotal, kill_land, att_infect_units,
put_land, att_reacting_units, count_bodies, att_fight,
send_reacting_units_home, take_def, ask_move_in, move_in_land,
lnd_print, lnd_delete, lnd_take_casualty, lnd_takemob,
lnd_sel, lnd_mar, lnd_put, lnd_sweep, contains_engineer,
lnd_check_mines, lnd_list, lnd_mess,
lnd_damage, lnd_easiest_target, lnd_mar_one_sector, shp_sel,
shp_nav, shp_put, shp_sweep, shp_check_one_mines, shp_check_mines,
shp_list, shp_mess, shp_count, shp_damage_one, shp_damage,
shp_contains, most_valuable_ship, shp_easiest_target,
shp_missile_interdiction, notify_coastguard,
shp_view, shp_nav_one_sector, shp_missdef, nav_ship,
fltp_to_list): Switch to struct ulist from either struct mlist
or struct llist.
This commit is contained in:
Ron Koenderink 2006-09-25 03:29:06 +00:00
parent 7d90028f20
commit cd8d742392
11 changed files with 514 additions and 471 deletions

View file

@ -179,16 +179,6 @@ struct lchrstr {
extern struct lchrstr lchr[LND_TYPE_MAX + 2]; extern struct lchrstr lchr[LND_TYPE_MAX + 2];
struct llist {
struct emp_qelem queue; /* list of units */
coord x, y; /* x,y it came from */
struct lchrstr *lcp; /* pointer to desc of land unit */
struct lndstr land; /* struct land unit */
int eff;
double mobil;
int supplied;
};
enum { enum {
LND_AIROPS_EFF = 50 /* min. efficiency for air ops */ LND_AIROPS_EFF = 50 /* min. efficiency for air ops */
}; };
@ -205,9 +195,9 @@ extern char *lnd_path(int, struct lndstr *, char *);
extern double attack_val(int, struct lndstr *); extern double attack_val(int, struct lndstr *);
extern double defense_val(struct lndstr *); extern double defense_val(struct lndstr *);
extern void lnd_print(struct llist *, char *); extern void lnd_print(struct ulist *, char *);
extern void lnd_delete(struct llist *, char *); extern void lnd_delete(struct ulist *, char *);
extern int lnd_take_casualty(int, struct llist *, int); extern int lnd_take_casualty(int, struct ulist *, int);
extern void lnd_submil(struct lndstr *, int); extern void lnd_submil(struct lndstr *, int);
extern void lnd_takemob(struct emp_qelem *, double); extern void lnd_takemob(struct emp_qelem *, double);
extern int lnd_spyval(struct lndstr *); extern int lnd_spyval(struct lndstr *);

View file

@ -185,13 +185,6 @@ struct mchrstr {
extern struct mchrstr mchr[SHP_TYPE_MAX + 2]; extern struct mchrstr mchr[SHP_TYPE_MAX + 2];
struct mlist {
struct emp_qelem queue; /* list of ships */
struct mchrstr *mcp; /* pointer to desc of ship */
struct shpstr ship; /* struct ship */
double mobil; /* how much mobility the ship has left */
};
#define SHP_DEF(b, t) (t ? (b * (logx(t, 40.0) < 1.0 ? 1.0 : \ #define SHP_DEF(b, t) (t ? (b * (logx(t, 40.0) < 1.0 ? 1.0 : \
logx(t, 40.0))) : b) logx(t, 40.0))) : b)
#define SHP_SPD(b, t) (t ? (b * (logx(t, 35.0) < 1.0 ? 1.0 : \ #define SHP_SPD(b, t) (t ? (b * (logx(t, 35.0) < 1.0 ? 1.0 : \

45
include/unit.h Normal file
View file

@ -0,0 +1,45 @@
/*
* Empire - A multi-player, client/server Internet based war game.
* Copyright (C) 1986-2006, Dave Pare, Jeff Bailey, Thomas Ruschak,
* Ken Stevens, Steve McClure
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* ---
*
* See files README, COPYING and CREDITS in the root of the source
* tree for related information and legal notices. It is expected
* that future projects/authors will amend these files as needed.
*
* ---
*
* unit.h: Generalize unit data structures and functions.
*
* Known contributors to this file:
* Ron Koenderink, 2006
* Markus Armbruster, 2006
*/
struct ulist {
struct emp_qelem queue; /* list of units */
double mobil; /* how much mobility the unit has left */
struct empobj_chr *chrp; /* pointer to characteristics unit */
union empobj_storage unit; /* unit */
coord x, y; /* x,y it came from LAND only */
int eff; /* LAND only */
int supplied; /* LAND only */
};

View file

@ -36,10 +36,10 @@
#include "combat.h" #include "combat.h"
#include "commands.h" #include "commands.h"
#include "land.h"
#include "mission.h" #include "mission.h"
#include "path.h" #include "path.h"
#include "ship.h" #include "empobj.h"
#include "unit.h"
int int
assa(void) assa(void)
@ -59,7 +59,7 @@ assa(void)
int n; int n;
int ourtotal; int ourtotal;
struct emp_qelem *qp, *next; struct emp_qelem *qp, *next;
struct llist *llp; struct ulist *llp;
int rel; int rel;
att_combat_init(off, EF_SHIP); att_combat_init(off, EF_SHIP);
@ -149,8 +149,8 @@ assa(void)
} }
for (qp = olist.q_forw; qp != &olist; qp = next) { for (qp = olist.q_forw; qp != &olist; qp = next) {
next = qp->q_forw; next = qp->q_forw;
llp = (struct llist *)qp; llp = (struct ulist *)qp;
if (lchr[(int)llp->land.lnd_type].l_flags & L_SPY) if (lchr[(int)llp->unit.land.lnd_type].l_flags & L_SPY)
continue; continue;
ourtotal++; ourtotal++;
} }
@ -163,34 +163,34 @@ assa(void)
for (qp = olist.q_forw; qp != &olist; qp = next) { for (qp = olist.q_forw; qp != &olist; qp = next) {
next = qp->q_forw; next = qp->q_forw;
llp = (struct llist *)qp; llp = (struct ulist *)qp;
rel = getrel(getnatp(def->own), player->cnum); rel = getrel(getnatp(def->own), player->cnum);
if (chance(0.10) || rel == ALLIED || !def->own) { if (chance(0.10) || rel == ALLIED || !def->own) {
pr("%s made it on shore safely.\n", prland(&llp->land)); pr("%s made it on shore safely.\n", prland(&llp->unit.land));
llp->land.lnd_x = def->x; llp->unit.land.lnd_x = def->x;
llp->land.lnd_y = def->y; llp->unit.land.lnd_y = def->y;
llp->land.lnd_ship = -1; llp->unit.land.lnd_ship = -1;
putland(llp->land.lnd_uid, &llp->land); putland(llp->unit.land.lnd_uid, &llp->unit.land);
} else { } else {
pr("%s was spotted", prland(&llp->land)); pr("%s was spotted", prland(&llp->unit.land));
if (rel == HOSTILE || rel == AT_WAR || rel == SITZKRIEG || if (rel == HOSTILE || rel == AT_WAR || rel == SITZKRIEG ||
rel == MOBILIZATION) { rel == MOBILIZATION) {
wu(0, def->own, "%s spy shot and killed in %s.\n", wu(0, def->own, "%s spy shot and killed in %s.\n",
cname(player->cnum), xyas(def->x, def->y, cname(player->cnum), xyas(def->x, def->y,
def->own)); def->own));
pr(" and was killed in the attempt.\n"); pr(" and was killed in the attempt.\n");
llp->land.lnd_effic = 0; llp->unit.land.lnd_effic = 0;
putland(llp->land.lnd_uid, &llp->land); putland(llp->unit.land.lnd_uid, &llp->unit.land);
lnd_delete(llp, ""); lnd_delete(llp, "");
} else { } else {
wu(0, def->own, "%s spy spotted in %s.\n", wu(0, def->own, "%s spy spotted in %s.\n",
cname(player->cnum), xyas(def->x, def->y, cname(player->cnum), xyas(def->x, def->y,
def->own)); def->own));
pr(" but made it ok.\n"); pr(" but made it ok.\n");
llp->land.lnd_x = def->x; llp->unit.land.lnd_x = def->x;
llp->land.lnd_y = def->y; llp->unit.land.lnd_y = def->y;
llp->land.lnd_ship = -1; llp->unit.land.lnd_ship = -1;
putland(llp->land.lnd_uid, &llp->land); putland(llp->unit.land.lnd_uid, &llp->unit.land);
} }
} }
} }

View file

@ -37,9 +37,10 @@
#include <ctype.h> #include <ctype.h>
#include "commands.h" #include "commands.h"
#include "file.h" #include "file.h"
#include "land.h"
#include "map.h" #include "map.h"
#include "path.h" #include "path.h"
#include "empobj.h"
#include "unit.h"
static int set_leader(struct emp_qelem *list, struct lndstr **leaderp); static int set_leader(struct emp_qelem *list, struct lndstr **leaderp);
static void switch_leader(struct emp_qelem *list, int land_uid); static void switch_leader(struct emp_qelem *list, int land_uid);
@ -187,16 +188,16 @@ march(void)
static int static int
set_leader(struct emp_qelem *list, struct lndstr **leaderp) set_leader(struct emp_qelem *list, struct lndstr **leaderp)
{ {
struct llist *llp = (struct llist *)(list->q_back); struct ulist *llp = (struct ulist *)(list->q_back);
if (!*leaderp) if (!*leaderp)
pr("Leader is "); pr("Leader is ");
else if ((*leaderp)->lnd_uid != llp->land.lnd_uid) else if ((*leaderp)->lnd_uid != llp->unit.land.lnd_uid)
pr("Changing leader to "); pr("Changing leader to ");
else else
return 0; return 0;
*leaderp = &llp->land; *leaderp = &llp->unit.land;
pr("%s\n", prland(&llp->land)); pr("%s\n", prland(&llp->unit.land));
return 1; return 1;
} }
@ -204,7 +205,7 @@ static void
switch_leader(struct emp_qelem *list, int land_uid) switch_leader(struct emp_qelem *list, int land_uid)
{ {
struct emp_qelem *qp, *save; struct emp_qelem *qp, *save;
struct llist *llp; struct ulist *llp;
if (QEMPTY(list)) if (QEMPTY(list))
return; return;
@ -214,8 +215,8 @@ switch_leader(struct emp_qelem *list, int land_uid)
emp_remque(qp); emp_remque(qp);
emp_insque(qp, list); emp_insque(qp, list);
qp = list->q_back; qp = list->q_back;
llp = (struct llist *)qp; llp = (struct ulist *)qp;
if (llp->land.lnd_uid == land_uid || land_uid == -1) if (llp->unit.land.lnd_uid == land_uid || land_uid == -1)
break; break;
} while (list->q_back != save); } while (list->q_back != save);
} }

View file

@ -38,7 +38,8 @@
#include "map.h" #include "map.h"
#include "optlist.h" #include "optlist.h"
#include "path.h" #include "path.h"
#include "ship.h" #include "empobj.h"
#include "unit.h"
static int set_flagship(struct emp_qelem *list, struct shpstr **flagshipp); static int set_flagship(struct emp_qelem *list, struct shpstr **flagshipp);
static void switch_flagship(struct emp_qelem *list, int ship_uid); static void switch_flagship(struct emp_qelem *list, int ship_uid);
@ -288,16 +289,16 @@ nav_map(int x, int y, int show_designations)
static int static int
set_flagship(struct emp_qelem *list, struct shpstr **flagshipp) set_flagship(struct emp_qelem *list, struct shpstr **flagshipp)
{ {
struct mlist *mlp = (struct mlist *)(list->q_back); struct ulist *mlp = (struct ulist *)(list->q_back);
if (!*flagshipp) if (!*flagshipp)
pr("Flagship is "); pr("Flagship is ");
else if ((*flagshipp)->shp_uid != mlp->ship.shp_uid) else if ((*flagshipp)->shp_uid != mlp->unit.ship.shp_uid)
pr("Changing flagship to "); pr("Changing flagship to ");
else else
return 0; return 0;
*flagshipp = &mlp->ship; *flagshipp = &mlp->unit.ship;
pr("%s\n", prship(&mlp->ship)); pr("%s\n", prship(&mlp->unit.ship));
return 1; return 1;
} }
@ -305,7 +306,7 @@ static void
switch_flagship(struct emp_qelem *list, int ship_uid) switch_flagship(struct emp_qelem *list, int ship_uid)
{ {
struct emp_qelem *qp, *save; struct emp_qelem *qp, *save;
struct mlist *mlp; struct ulist *mlp;
if (QEMPTY(list)) if (QEMPTY(list))
return; return;
@ -315,8 +316,8 @@ switch_flagship(struct emp_qelem *list, int ship_uid)
emp_remque(qp); emp_remque(qp);
emp_insque(qp, list); emp_insque(qp, list);
qp = list->q_back; qp = list->q_back;
mlp = (struct mlist *)qp; mlp = (struct ulist *)qp;
if (mlp->ship.shp_uid == ship_uid || ship_uid == -1) if (mlp->unit.ship.shp_uid == ship_uid || ship_uid == -1)
break; break;
} while (list->q_back != save); } while (list->q_back != save);
} }

View file

@ -39,31 +39,25 @@
#include <math.h> #include <math.h>
#include "combat.h" #include "combat.h"
#include "file.h" #include "file.h"
#include "item.h"
#include "land.h"
#include "lost.h"
#include "map.h" #include "map.h"
#include "misc.h" #include "misc.h"
#include "mission.h" #include "mission.h"
#include "nat.h"
#include "news.h"
#include "nsc.h" #include "nsc.h"
#include "optlist.h" #include "optlist.h"
#include "path.h" #include "path.h"
#include "plague.h" #include "plague.h"
#include "player.h" #include "player.h"
#include "prototypes.h" #include "prototypes.h"
#include "sect.h"
#include "ship.h"
#include "treaty.h"
#include "xy.h" #include "xy.h"
#include "empobj.h"
#include "unit.h"
#define CASUALTY_LUMP 1 /* How big casualty chunks should be */ #define CASUALTY_LUMP 1 /* How big casualty chunks should be */
static void ask_olist(int combat_mode, struct combat *off, static void ask_olist(int combat_mode, struct combat *off,
struct combat *def, struct emp_qelem *olist, struct combat *def, struct emp_qelem *olist,
char *land_answer, int *a_spyp, int *a_engineerp); char *land_answer, int *a_spyp, int *a_engineerp);
static void take_move_in_mob(int combat_mode, struct llist *llp, static void take_move_in_mob(int combat_mode, struct ulist *llp,
struct combat *off, struct combat *def); struct combat *off, struct combat *def);
static void move_in_land(int combat_mode, struct combat *off, static void move_in_land(int combat_mode, struct combat *off,
struct emp_qelem *olist, struct combat *def); struct emp_qelem *olist, struct combat *def);
@ -90,7 +84,7 @@ static int take_def(int combat_mode, struct emp_qelem *list,
struct combat *off, struct combat *def); struct combat *off, struct combat *def);
static int get_land(int combat_mode, struct combat *def, int uid, static int get_land(int combat_mode, struct combat *def, int uid,
struct llist *llp, int victim_land); struct ulist *llp, int victim_land);
char *att_mode[] = { char *att_mode[] = {
/* must match combat types in combat.h */ /* must match combat types in combat.h */
@ -984,7 +978,7 @@ ask_olist(int combat_mode, struct combat *off, struct combat *def,
struct nstr_item ni; struct nstr_item ni;
struct lndstr land; struct lndstr land;
double mobcost; double mobcost;
struct llist *llp; struct ulist *llp;
struct lchrstr *lcp; struct lchrstr *lcp;
double att_val; double att_val;
int count = 0; int count = 0;
@ -1110,19 +1104,19 @@ ask_olist(int combat_mode, struct combat *off, struct combat *def,
land_answer[(int)land.lnd_army] != 'Y') land_answer[(int)land.lnd_army] != 'Y')
continue; continue;
} }
if (!(llp = malloc(sizeof(struct llist)))) { if (!(llp = malloc(sizeof(struct ulist)))) {
logerror("Malloc failed in attack!\n"); logerror("Malloc failed in attack!\n");
abort_attack(); abort_attack();
return; return;
} }
memset(llp, 0, sizeof(struct llist)); memset(llp, 0, sizeof(struct ulist));
emp_insque(&llp->queue, olist); emp_insque(&llp->queue, olist);
llp->mobil = mobcost; llp->mobil = mobcost;
if (!get_land(combat_mode, def, land.lnd_uid, llp, 0)) if (!get_land(combat_mode, def, land.lnd_uid, llp, 0))
continue; continue;
if (lnd_spyval(&land) > *a_spyp) if (lnd_spyval(&land) > *a_spyp)
*a_spyp = lnd_spyval(&land); *a_spyp = lnd_spyval(&land);
if (llp->lcp->l_flags & L_ENGINEER) if (((struct lchrstr *)llp->chrp)->l_flags & L_ENGINEER)
++*a_engineerp; ++*a_engineerp;
if (def->type == EF_SHIP && ++count >= maxland) if (def->type == EF_SHIP && ++count >= maxland)
break; break;
@ -1179,7 +1173,7 @@ att_get_defense(struct emp_qelem *olist, struct combat *def,
{ {
int d_spy = 0; int d_spy = 0;
struct emp_qelem *qp; struct emp_qelem *qp;
struct llist *llp; struct ulist *llp;
int dtotal; int dtotal;
int old_dtotal; int old_dtotal;
@ -1195,8 +1189,8 @@ att_get_defense(struct emp_qelem *olist, struct combat *def,
att_reacting_units(def, dlist, a_spy, &d_spy, ototal); att_reacting_units(def, dlist, a_spy, &d_spy, ototal);
for (qp = olist->q_forw; qp != olist; qp = qp->q_forw) { for (qp = olist->q_forw; qp != olist; qp = qp->q_forw) {
llp = (struct llist *)qp; llp = (struct ulist *)qp;
intelligence_report(def->own, &llp->land, d_spy, intelligence_report(def->own, &llp->unit.land, d_spy,
"Scouts report attacking unit:"); "Scouts report attacking unit:");
} }
@ -1215,7 +1209,7 @@ get_dlist(struct combat *def, struct emp_qelem *list, int a_spy,
int *d_spyp) int *d_spyp)
{ {
struct nstr_item ni; struct nstr_item ni;
struct llist *llp; struct ulist *llp;
struct lndstr land; struct lndstr land;
/* In here is where you need to take out spies and trains from the defending /* In here is where you need to take out spies and trains from the defending
@ -1240,12 +1234,12 @@ get_dlist(struct combat *def, struct emp_qelem *list, int a_spy,
"Scouts report defending unit:"); "Scouts report defending unit:");
continue; continue;
} }
if (!(llp = malloc(sizeof(struct llist)))) { if (!(llp = malloc(sizeof(struct ulist)))) {
logerror("Malloc failed in attack!\n"); logerror("Malloc failed in attack!\n");
abort_attack(); abort_attack();
return; return;
} }
memset(llp, 0, sizeof(struct llist)); memset(llp, 0, sizeof(struct ulist));
emp_insque(&llp->queue, list); emp_insque(&llp->queue, list);
llp->supplied = has_supply(&land); llp->supplied = has_supply(&land);
if (!get_land(A_DEFEND, def, land.lnd_uid, llp, 1)) if (!get_land(A_DEFEND, def, land.lnd_uid, llp, 1))
@ -1263,7 +1257,7 @@ get_ototal(int combat_mode, struct combat *off, struct emp_qelem *olist,
{ {
double ototal = 0.0; double ototal = 0.0;
struct emp_qelem *qp, *next; struct emp_qelem *qp, *next;
struct llist *llp; struct ulist *llp;
int n, w; int n, w;
/* /*
@ -1284,26 +1278,26 @@ get_ototal(int combat_mode, struct combat *off, struct emp_qelem *olist,
for (qp = olist->q_forw; qp != olist; qp = next) { for (qp = olist->q_forw; qp != olist; qp = next) {
next = qp->q_forw; next = qp->q_forw;
llp = (struct llist *)qp; llp = (struct ulist *)qp;
if (check && !get_land(combat_mode, 0, llp->land.lnd_uid, llp, 0)) if (check && !get_land(combat_mode, 0, llp->unit.land.lnd_uid, llp, 0))
continue; continue;
if (combat_mode == A_ATTACK) { if (combat_mode == A_ATTACK) {
w = -1; w = -1;
for (n = 0; n <= off->last; ++n) { for (n = 0; n <= off->last; ++n) {
if (off[n].type == EF_BAD) if (off[n].type == EF_BAD)
continue; continue;
if ((off[n].x == llp->land.lnd_x) && if ((off[n].x == llp->unit.land.lnd_x) &&
(off[n].y == llp->land.lnd_y)) (off[n].y == llp->unit.land.lnd_y))
w = n; w = n;
} }
if (w < 0) { if (w < 0) {
lnd_delete(llp, "is in a sector not owned by you"); lnd_delete(llp, "is in a sector not owned by you");
continue; continue;
} }
ototal += attack_val(combat_mode, &llp->land) * ototal += attack_val(combat_mode, &llp->unit.land) *
att_combat_eff(off + w); att_combat_eff(off + w);
} else { } else {
ototal += attack_val(combat_mode, &llp->land); ototal += attack_val(combat_mode, &llp->unit.land);
} }
} }
ototal *= osupport; ototal *= osupport;
@ -1319,7 +1313,7 @@ get_dtotal(struct combat *def, struct emp_qelem *list, double dsupport,
{ {
double dtotal = 0.0, eff = 1.0, d_unit; double dtotal = 0.0, eff = 1.0, d_unit;
struct emp_qelem *qp, *next; struct emp_qelem *qp, *next;
struct llist *llp; struct ulist *llp;
if (check && att_get_combat(def, 1) < 0) if (check && att_get_combat(def, 1) < 0)
return 0; return 0;
@ -1333,10 +1327,10 @@ get_dtotal(struct combat *def, struct emp_qelem *list, double dsupport,
for (qp = list->q_forw; qp != list; qp = next) { for (qp = list->q_forw; qp != list; qp = next) {
next = qp->q_forw; next = qp->q_forw;
llp = (struct llist *)qp; llp = (struct ulist *)qp;
if (check && !get_land(A_DEFEND, def, llp->land.lnd_uid, llp, 1)) if (check && !get_land(A_DEFEND, def, llp->unit.land.lnd_uid, llp, 1))
continue; continue;
d_unit = defense_val(&llp->land); d_unit = defense_val(&llp->unit.land);
if (!llp->supplied) if (!llp->supplied)
d_unit /= 2.0; d_unit /= 2.0;
dtotal += d_unit * eff; dtotal += d_unit * eff;
@ -1353,18 +1347,18 @@ get_dtotal(struct combat *def, struct emp_qelem *list, double dsupport,
*/ */
static int static int
get_land(int combat_mode, struct combat *def, int uid, struct llist *llp, get_land(int combat_mode, struct combat *def, int uid, struct ulist *llp,
int victim_land) int victim_land)
{ {
struct lndstr *lp = &llp->land; struct lndstr *lp = &llp->unit.land;
char buf[512]; char buf[512];
getland(uid, lp); getland(uid, lp);
if (!llp->lcp) { /* first time */ if (!llp->chrp) { /* first time */
llp->x = llp->land.lnd_x; llp->x = llp->unit.land.lnd_x;
llp->y = llp->land.lnd_y; llp->y = llp->unit.land.lnd_y;
llp->lcp = &lchr[(int)llp->land.lnd_type]; llp->chrp = (struct empobj_chr *)&lchr[(int)llp->unit.land.lnd_type];
} else { /* not first time */ } else { /* not first time */
if (lp->lnd_effic < LAND_MINEFF) { if (lp->lnd_effic < LAND_MINEFF) {
sprintf(buf, "was destroyed and is no longer a part of the %s", sprintf(buf, "was destroyed and is no longer a part of the %s",
@ -1400,7 +1394,7 @@ get_land(int combat_mode, struct combat *def, int uid, struct llist *llp,
} }
} }
} }
llp->eff = llp->land.lnd_effic; llp->eff = llp->unit.land.lnd_effic;
return 1; return 1;
} }
@ -1416,13 +1410,13 @@ static void
kill_land(struct emp_qelem *list) kill_land(struct emp_qelem *list)
{ {
struct emp_qelem *qp, *next; struct emp_qelem *qp, *next;
struct llist *llp; struct ulist *llp;
for (qp = list->q_forw; qp != list; qp = next) { for (qp = list->q_forw; qp != list; qp = next) {
next = qp->q_forw; next = qp->q_forw;
llp = (struct llist *)qp; llp = (struct ulist *)qp;
if (llp->land.lnd_ship >= 0) { if (llp->unit.land.lnd_ship >= 0) {
llp->land.lnd_effic = 0; llp->unit.land.lnd_effic = 0;
lnd_delete(llp, "cannot return to the ship, and dies!"); lnd_delete(llp, "cannot return to the ship, and dies!");
} }
} }
@ -1432,15 +1426,15 @@ static void
att_infect_units(struct emp_qelem *list, int plague) att_infect_units(struct emp_qelem *list, int plague)
{ {
struct emp_qelem *qp, *next; struct emp_qelem *qp, *next;
struct llist *llp; struct ulist *llp;
if (!plague) if (!plague)
return; return;
for (qp = list->q_forw; qp != list; qp = next) { for (qp = list->q_forw; qp != list; qp = next) {
next = qp->q_forw; next = qp->q_forw;
llp = (struct llist *)qp; llp = (struct ulist *)qp;
if (llp->land.lnd_pstage == PLG_HEALTHY) if (llp->unit.land.lnd_pstage == PLG_HEALTHY)
llp->land.lnd_pstage = PLG_EXPOSED; llp->unit.land.lnd_pstage = PLG_EXPOSED;
} }
} }
@ -1448,21 +1442,21 @@ static void
put_land(struct emp_qelem *list) put_land(struct emp_qelem *list)
{ {
struct emp_qelem *qp, *next; struct emp_qelem *qp, *next;
struct llist *llp; struct ulist *llp;
for (qp = list->q_forw; qp != list; qp = next) { for (qp = list->q_forw; qp != list; qp = next) {
next = qp->q_forw; next = qp->q_forw;
llp = (struct llist *)qp; llp = (struct ulist *)qp;
llp->land.lnd_mission = 0; llp->unit.land.lnd_mission = 0;
llp->land.lnd_harden = 0; llp->unit.land.lnd_harden = 0;
llp->land.lnd_mobil -= (int)llp->mobil; llp->unit.land.lnd_mobil -= (int)llp->mobil;
llp->mobil = 0.0; llp->mobil = 0.0;
putland(llp->land.lnd_uid, &llp->land); putland(llp->unit.land.lnd_uid, &llp->unit.land);
if (llp->land.lnd_own != player->cnum) { if (llp->unit.land.lnd_own != player->cnum) {
emp_remque((struct emp_qelem *)llp); emp_remque((struct emp_qelem *)llp);
free(llp); free(llp);
} else } else
get_land(A_ATTACK, 0, llp->land.lnd_uid, llp, 0); get_land(A_ATTACK, 0, llp->unit.land.lnd_uid, llp, 0);
} }
} }
@ -1478,7 +1472,7 @@ att_reacting_units(struct combat *def, struct emp_qelem *list, int a_spy,
struct nstr_item ni; struct nstr_item ni;
struct lndstr land; struct lndstr land;
struct sctstr sect, dsect; struct sctstr sect, dsect;
struct llist *llp; struct ulist *llp;
int dtotal; int dtotal;
double new_land = 0; double new_land = 0;
double mobcost; double mobcost;
@ -1555,14 +1549,14 @@ att_reacting_units(struct combat *def, struct emp_qelem *list, int a_spy,
wu(0, land.lnd_own, "%s reacts to %s.\n", wu(0, land.lnd_own, "%s reacts to %s.\n",
prland(&land), xyas(land.lnd_x, land.lnd_y, land.lnd_own)); prland(&land), xyas(land.lnd_x, land.lnd_y, land.lnd_own));
llp = malloc(sizeof(struct llist)); llp = malloc(sizeof(struct ulist));
memset(llp, 0, sizeof(struct llist)); memset(llp, 0, sizeof(struct ulist));
llp->supplied = 1; llp->supplied = 1;
llp->x = origx; llp->x = origx;
llp->y = origy; llp->y = origy;
llp->lcp = &lchr[(int)land.lnd_type]; llp->chrp = (struct empobj_chr *)&lchr[(int)land.lnd_type];
llp->land = land; llp->unit.land = land;
emp_insque(&llp->queue, list); emp_insque(&llp->queue, list);
if (lnd_spyval(&land) > *d_spyp) if (lnd_spyval(&land) > *d_spyp)
*d_spyp = lnd_spyval(&land); *d_spyp = lnd_spyval(&land);
@ -1766,13 +1760,13 @@ count_bodies(struct combat *off, struct emp_qelem *list)
int n; int n;
int bodies = 0; int bodies = 0;
struct emp_qelem *qp; struct emp_qelem *qp;
struct llist *llp; struct ulist *llp;
for (n = 0; n <= off->last; ++n) for (n = 0; n <= off->last; ++n)
bodies += off[n].troops; bodies += off[n].troops;
for (qp = list->q_forw; qp != list; qp = qp->q_forw) { for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
llp = (struct llist *)qp; llp = (struct ulist *)qp;
bodies += llp->land.lnd_item[I_MILIT]; bodies += llp->unit.land.lnd_item[I_MILIT];
} }
return bodies; return bodies;
} }
@ -2084,7 +2078,7 @@ take_casualty(int combat_mode, struct combat *off, struct emp_qelem *olist)
int biggest_troops = 0, index = -1; int biggest_troops = 0, index = -1;
int n, tot_troops = 0, biggest_mil, cas; int n, tot_troops = 0, biggest_mil, cas;
struct emp_qelem *qp, *biggest; struct emp_qelem *qp, *biggest;
struct llist *llp; struct ulist *llp;
for (n = 0; n <= off->last; ++n) { for (n = 0; n <= off->last; ++n) {
if (off[n].type != EF_BAD) { if (off[n].type != EF_BAD) {
@ -2141,17 +2135,17 @@ take_casualty(int combat_mode, struct combat *off, struct emp_qelem *olist)
biggest = NULL; biggest = NULL;
biggest_mil = -1; biggest_mil = -1;
for (qp = olist->q_forw; qp != olist; qp = qp->q_forw) { for (qp = olist->q_forw; qp != olist; qp = qp->q_forw) {
llp = (struct llist *)qp; llp = (struct ulist *)qp;
if (llp->land.lnd_item[I_MILIT] > biggest_mil) { if (llp->unit.land.lnd_item[I_MILIT] > biggest_mil) {
biggest_mil = llp->land.lnd_item[I_MILIT]; biggest_mil = llp->unit.land.lnd_item[I_MILIT];
biggest = qp; biggest = qp;
} }
} }
if (biggest == NULL) if (biggest == NULL)
return CASUALTY_LUMP - to_take; return CASUALTY_LUMP - to_take;
llp = (struct llist *)biggest; llp = (struct ulist *)biggest;
cas = lnd_take_casualty(combat_mode, llp, to_take); cas = lnd_take_casualty(combat_mode, llp, to_take);
return CASUALTY_LUMP - (to_take - cas); return CASUALTY_LUMP - (to_take - cas);
} }
@ -2162,17 +2156,18 @@ static void
send_reacting_units_home(struct emp_qelem *list) send_reacting_units_home(struct emp_qelem *list)
{ {
struct emp_qelem *qp, *next; struct emp_qelem *qp, *next;
struct llist *llp; struct ulist *llp;
char buf[1024]; char buf[1024];
for (qp = list->q_forw; qp != list; qp = next) { for (qp = list->q_forw; qp != list; qp = next) {
next = qp->q_forw; next = qp->q_forw;
llp = (struct llist *)qp; llp = (struct ulist *)qp;
if ((llp->land.lnd_x != llp->x) || (llp->land.lnd_y != llp->y)) { if ((llp->unit.land.lnd_x != llp->x) ||
(llp->unit.land.lnd_y != llp->y)) {
sprintf(buf, "returns to %s", sprintf(buf, "returns to %s",
xyas(llp->x, llp->y, llp->land.lnd_own)); xyas(llp->x, llp->y, llp->unit.land.lnd_own));
llp->land.lnd_x = llp->x; llp->unit.land.lnd_x = llp->x;
llp->land.lnd_y = llp->y; llp->unit.land.lnd_y = llp->y;
lnd_delete(llp, buf); lnd_delete(llp, buf);
} }
} }
@ -2207,7 +2202,7 @@ take_def(int combat_mode, struct emp_qelem *list, struct combat *off,
{ {
int n; int n;
int occuppied = 0; int occuppied = 0;
struct llist *llp, *delete_me = 0; struct ulist *llp, *delete_me = 0;
char buf[1024]; char buf[1024];
struct sctstr sect; struct sctstr sect;
struct shpstr ship; struct shpstr ship;
@ -2239,16 +2234,16 @@ take_def(int combat_mode, struct emp_qelem *list, struct combat *off,
pr_com(2, def, def->own)); pr_com(2, def, def->own));
return 0; return 0;
} else { } else {
llp = (struct llist *)list->q_forw; llp = (struct ulist *)list->q_forw;
llp->land.lnd_x = def->x; llp->unit.land.lnd_x = def->x;
llp->land.lnd_y = def->y; llp->unit.land.lnd_y = def->y;
take_move_in_mob(combat_mode, llp, off, def); take_move_in_mob(combat_mode, llp, off, def);
if (def->type == EF_SHIP) { if (def->type == EF_SHIP) {
llp->land.lnd_ship = def->shp_uid; llp->unit.land.lnd_ship = def->shp_uid;
sprintf(buf, "boards %s", prcom(0, def)); sprintf(buf, "boards %s", prcom(0, def));
delete_me = llp; delete_me = llp;
} else { } else {
llp->land.lnd_ship = -1; llp->unit.land.lnd_ship = -1;
sprintf(buf, "moves in to occupy %s", sprintf(buf, "moves in to occupy %s",
xyas(def->x, def->y, player->cnum)); xyas(def->x, def->y, player->cnum));
lnd_delete(llp, buf); lnd_delete(llp, buf);
@ -2289,7 +2284,7 @@ ask_move_in(struct combat *off, struct emp_qelem *olist,
{ {
int n; int n;
struct emp_qelem *qp, *next; struct emp_qelem *qp, *next;
struct llist *llp; struct ulist *llp;
char buf[512]; char buf[512];
char prompt[512]; char prompt[512];
char land_answer[256]; char land_answer[256];
@ -2308,29 +2303,30 @@ ask_move_in(struct combat *off, struct emp_qelem *olist,
memset(land_answer, 0, sizeof(land_answer)); memset(land_answer, 0, sizeof(land_answer));
for (qp = olist->q_forw; qp != olist; qp = next) { for (qp = olist->q_forw; qp != olist; qp = next) {
next = qp->q_forw; next = qp->q_forw;
llp = (struct llist *)qp; llp = (struct ulist *)qp;
answerp = &land_answer[(int)llp->land.lnd_army]; answerp = &land_answer[(int)llp->unit.land.lnd_army];
if (player->aborted || att_get_combat(def, 0) < 0) if (player->aborted || att_get_combat(def, 0) < 0)
*answerp = 'N'; *answerp = 'N';
if (*answerp == 'Y') if (*answerp == 'Y')
continue; continue;
if (*answerp != 'N') { if (*answerp != 'N') {
if (!get_land(A_ATTACK, def, llp->land.lnd_uid, llp, 0)) if (!get_land(A_ATTACK, def, llp->unit.land.lnd_uid, llp, 0))
continue; continue;
sprintf(prompt, "Move in with %s (%c %d%%) [ynYNq?] ", sprintf(prompt, "Move in with %s (%c %d%%) [ynYNq?] ",
prland(&llp->land), prland(&llp->unit.land),
llp->land.lnd_army ? llp->land.lnd_army : '~', llp->unit.land.lnd_army ? llp->unit.land.lnd_army : '~',
llp->land.lnd_effic); llp->unit.land.lnd_effic);
*answerp = att_prompt(prompt, llp->land.lnd_army); *answerp = att_prompt(prompt, llp->unit.land.lnd_army);
if (player->aborted || att_get_combat(def, 0) < 0) if (player->aborted || att_get_combat(def, 0) < 0)
*answerp = 'N'; *answerp = 'N';
if (!get_land(A_ATTACK, def, llp->land.lnd_uid, llp, 0)) if (!get_land(A_ATTACK, def, llp->unit.land.lnd_uid, llp, 0))
continue; continue;
} }
if (*answerp == 'y' || *answerp == 'Y') if (*answerp == 'y' || *answerp == 'Y')
continue; continue;
sprintf(buf, "stays in %s", sprintf(buf, "stays in %s",
xyas(llp->land.lnd_x, llp->land.lnd_y, player->cnum)); xyas(llp->unit.land.lnd_x, llp->unit.land.lnd_y,
player->cnum));
lnd_delete(llp, buf); lnd_delete(llp, buf);
} }
if (QEMPTY(olist)) if (QEMPTY(olist))
@ -2338,11 +2334,12 @@ ask_move_in(struct combat *off, struct emp_qelem *olist,
if (att_get_combat(def, 0) < 0) { if (att_get_combat(def, 0) < 0) {
for (qp = olist->q_forw; qp != olist; qp = next) { for (qp = olist->q_forw; qp != olist; qp = next) {
next = qp->q_forw; next = qp->q_forw;
llp = (struct llist *)qp; llp = (struct ulist *)qp;
if (!get_land(A_ATTACK, def, llp->land.lnd_uid, llp, 0)) if (!get_land(A_ATTACK, def, llp->unit.land.lnd_uid, llp, 0))
continue; continue;
sprintf(buf, "stays in %s", sprintf(buf, "stays in %s",
xyas(llp->land.lnd_x, llp->land.lnd_y, player->cnum)); xyas(llp->unit.land.lnd_x, llp->unit.land.lnd_y,
player->cnum));
lnd_delete(llp, buf); lnd_delete(llp, buf);
} }
return; return;
@ -2359,23 +2356,23 @@ move_in_land(int combat_mode, struct combat *off, struct emp_qelem *olist,
struct combat *def) struct combat *def)
{ {
struct emp_qelem *qp, *next; struct emp_qelem *qp, *next;
struct llist *llp; struct ulist *llp;
char buf[512]; char buf[512];
if (QEMPTY(olist)) if (QEMPTY(olist))
return; return;
for (qp = olist->q_forw; qp != olist; qp = next) { for (qp = olist->q_forw; qp != olist; qp = next) {
next = qp->q_forw; next = qp->q_forw;
llp = (struct llist *)qp; llp = (struct ulist *)qp;
if (!get_land(combat_mode, def, llp->land.lnd_uid, llp, 0)) if (!get_land(combat_mode, def, llp->unit.land.lnd_uid, llp, 0))
continue; continue;
take_move_in_mob(combat_mode, llp, off, def); take_move_in_mob(combat_mode, llp, off, def);
llp->land.lnd_x = def->x; llp->unit.land.lnd_x = def->x;
llp->land.lnd_y = def->y; llp->unit.land.lnd_y = def->y;
if (def->type == EF_SHIP) if (def->type == EF_SHIP)
llp->land.lnd_ship = def->shp_uid; llp->unit.land.lnd_ship = def->shp_uid;
else else
llp->land.lnd_ship = -1; llp->unit.land.lnd_ship = -1;
} }
if (QEMPTY(olist)) if (QEMPTY(olist))
return; return;
@ -2392,7 +2389,7 @@ move_in_land(int combat_mode, struct combat *off, struct emp_qelem *olist,
return; return;
for (qp = olist->q_forw; qp != olist; qp = next) { for (qp = olist->q_forw; qp != olist; qp = next) {
next = qp->q_forw; next = qp->q_forw;
llp = (struct llist *)qp; llp = (struct ulist *)qp;
lnd_print(llp, buf); lnd_print(llp, buf);
} }
if (QEMPTY(olist)) if (QEMPTY(olist))
@ -2523,7 +2520,7 @@ ask_move_in_off(struct combat *off, struct combat *def)
/* Charge land units for moving into a sector or onto a ship */ /* Charge land units for moving into a sector or onto a ship */
static void static void
take_move_in_mob(int combat_mode, struct llist *llp, struct combat *off, take_move_in_mob(int combat_mode, struct ulist *llp, struct combat *off,
struct combat *def) struct combat *def)
{ {
int mobcost; int mobcost;
@ -2531,37 +2528,39 @@ take_move_in_mob(int combat_mode, struct llist *llp, struct combat *off,
switch (combat_mode) { switch (combat_mode) {
case A_ATTACK: case A_ATTACK:
mobcost = lnd_pathcost(&llp->land, mobcost = lnd_pathcost(&llp->unit.land,
att_mobcost(off->own, def, att_mobcost(off->own, def,
lnd_mobtype(&llp->land))); lnd_mobtype(&llp->unit.land)));
new = llp->land.lnd_mobil - mobcost; new = llp->unit.land.lnd_mobil - mobcost;
if (new < -127) if (new < -127)
new = -127; new = -127;
llp->land.lnd_mobil = new; llp->unit.land.lnd_mobil = new;
break; break;
case A_ASSAULT: case A_ASSAULT:
if (off->shp_mcp->m_flags & M_LAND) { if (off->shp_mcp->m_flags & M_LAND) {
if (llp->lcp->l_flags & L_MARINE) if (((struct lchrstr *)llp->chrp)->l_flags & L_MARINE)
llp->land.lnd_mobil -= llp->unit.land.lnd_mobil -=
(float)etu_per_update * land_mob_scale * 0.5; (float)etu_per_update * land_mob_scale * 0.5;
else else
llp->land.lnd_mobil -= (float)etu_per_update * land_mob_scale; llp->unit.land.lnd_mobil -= (float)etu_per_update *
land_mob_scale;
} else { } else {
if (llp->lcp->l_flags & L_MARINE) if (((struct lchrstr *)llp->chrp)->l_flags & L_MARINE)
llp->land.lnd_mobil = 0; llp->unit.land.lnd_mobil = 0;
else else
llp->land.lnd_mobil = -(float)etu_per_update * land_mob_scale; llp->unit.land.lnd_mobil = -(float)etu_per_update *
land_mob_scale;
} }
break; break;
case A_BOARD: case A_BOARD:
/* I arbitrarily chose the numbers 10 and 40 below -KHS */ /* I arbitrarily chose the numbers 10 and 40 below -KHS */
if (llp->lcp->l_flags & L_MARINE) if (((struct lchrstr *)llp->chrp)->l_flags & L_MARINE)
llp->land.lnd_mobil -= 10; llp->unit.land.lnd_mobil -= 10;
else else
llp->land.lnd_mobil -= 40; llp->unit.land.lnd_mobil -= 40;
break; break;
} }
llp->land.lnd_harden = 0; llp->unit.land.lnd_harden = 0;
} }
static void static void

View file

@ -40,22 +40,18 @@
#include "combat.h" #include "combat.h"
#include "damage.h" #include "damage.h"
#include "file.h" #include "file.h"
#include "land.h"
#include "misc.h" #include "misc.h"
#include "mission.h" #include "mission.h"
#include "nat.h"
#include "news.h"
#include "nsc.h" #include "nsc.h"
#include "optlist.h" #include "optlist.h"
#include "path.h" #include "path.h"
#include "plane.h"
#include "player.h" #include "player.h"
#include "prototypes.h" #include "prototypes.h"
#include "sect.h"
#include "ship.h"
#include "xy.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 lnd_hit_mine(struct lndstr *, struct lchrstr *);
double double
@ -128,26 +124,26 @@ defense_val(struct lndstr *lp)
} }
void void
lnd_print(struct llist *llp, char *s) lnd_print(struct ulist *llp, char *s)
{ {
if (llp->land.lnd_own == player->cnum) if (llp->unit.land.lnd_own == player->cnum)
pr("%s %s\n", prland(&llp->land), s); pr("%s %s\n", prland(&llp->unit.land), s);
else 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 void
lnd_delete(struct llist *llp, char *s) lnd_delete(struct ulist *llp, char *s)
{ {
if (s) if (s)
lnd_print(llp, 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); emp_remque((struct emp_qelem *)llp);
free(llp); free(llp);
} }
int 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? */ /* attacking or assaulting or paratrooping? */
/* number of casualties to take */ /* number of casualties to take */
{ {
@ -168,49 +164,51 @@ lnd_take_casualty(int combat_mode, struct llist *llp, int cas)
signed char orig; signed char orig;
int mob; int mob;
taken = llp->land.lnd_item[I_MILIT]; taken = llp->unit.land.lnd_item[I_MILIT];
/* Spies always die */ /* Spies always die */
if (llp->lcp->l_flags & L_SPY) { if (((struct lchrstr *)llp->chrp)->l_flags & L_SPY) {
eff_eq = 100; eff_eq = 100;
llp->land.lnd_effic = 0; llp->unit.land.lnd_effic = 0;
} else { } else {
eff_eq = ldround(cas * 100.0 / llp->lcp->l_mil, 1); eff_eq = ldround(cas * 100.0 /
llp->land.lnd_effic -= eff_eq; ((struct lchrstr *)llp->chrp)->l_mil, 1);
lnd_submil(&llp->land, cas); 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!", sprintf(buf, "dies %s %s!",
combat_mode ? att_mode[combat_mode] : "defending", 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); lnd_delete(llp, buf);
/* Since we killed the unit, we killed all the mil on it */ /* Since we killed the unit, we killed all the mil on it */
return taken; return taken;
} else { } else {
/* Ok, now, how many did we take off? (sould be the diff) */ /* 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; return taken;
/* we're being boarded */ /* 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; return taken;
/* we're being boarded */ /* 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; return taken;
/* Have to make a retreat check */ /* 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) { if (roll(100) < ret_chance) {
pr("\n"); pr("\n");
lnd_print(llp, "fails morale check!"); lnd_print(llp, "fails morale check!");
llp->land.lnd_mission = 0; llp->unit.land.lnd_mission = 0;
llp->land.lnd_harden = 0; llp->unit.land.lnd_harden = 0;
if (llp->land.lnd_ship >= 0 || llp->land.lnd_land >= 0) if (llp->unit.land.lnd_ship >= 0 || llp->unit.land.lnd_land >= 0)
nowhere_to_go = 1; nowhere_to_go = 1;
else if (combat_mode == A_DEFEND) { else if (combat_mode == A_DEFEND) {
/* /*
@ -222,14 +220,14 @@ lnd_take_casualty(int combat_mode, struct llist *llp, int cas)
biggest = -1; biggest = -1;
nowned = 0; nowned = 0;
for (n = 1; n <= 6; ++n) { for (n = 1; n <= 6; ++n) {
ret_x = llp->land.lnd_x + diroff[n][0]; ret_x = llp->unit.land.lnd_x + diroff[n][0];
ret_y = llp->land.lnd_y + diroff[n][1]; ret_y = llp->unit.land.lnd_y + diroff[n][1];
getsect(ret_x, ret_y, &sect); getsect(ret_x, ret_y, &sect);
if (sect.sct_own != llp->land.lnd_own) if (sect.sct_own != llp->unit.land.lnd_own)
continue; continue;
if (sect.sct_type == SCT_MOUNT) if (sect.sct_type == SCT_MOUNT)
continue; continue;
mobcost = lnd_mobcost(&llp->land, &rsect); mobcost = lnd_mobcost(&llp->unit.land, &rsect);
if (mobcost < 0) if (mobcost < 0)
continue; continue;
++nowned; ++nowned;
@ -245,38 +243,38 @@ lnd_take_casualty(int combat_mode, struct llist *llp, int cas)
nowhere_to_go = 1; nowhere_to_go = 1;
else { else {
/* retreat to bx,by */ /* retreat to bx,by */
llp->land.lnd_x = bx; llp->unit.land.lnd_x = bx;
llp->land.lnd_y = by; llp->unit.land.lnd_y = by;
/* FIXME landmines */ /* FIXME landmines */
getsect(bx, by, &rsect); getsect(bx, by, &rsect);
mob = llp->land.lnd_mobil - (int)bmcost; mob = llp->unit.land.lnd_mobil - (int)bmcost;
if (mob < -127) if (mob < -127)
mob = -127; mob = -127;
orig = llp->land.lnd_mobil; orig = llp->unit.land.lnd_mobil;
llp->land.lnd_mobil = (signed char)mob; llp->unit.land.lnd_mobil = (signed char)mob;
if (llp->land.lnd_mobil > orig) if (llp->unit.land.lnd_mobil > orig)
llp->land.lnd_mobil = -127; llp->unit.land.lnd_mobil = -127;
sprintf(buf, "retreats at %d%% efficiency to %s!", sprintf(buf, "retreats at %d%% efficiency to %s!",
llp->land.lnd_effic, llp->unit.land.lnd_effic,
xyas(bx, by, llp->land.lnd_own)); xyas(bx, by, llp->unit.land.lnd_own));
lnd_delete(llp, buf); lnd_delete(llp, buf);
} }
} else { /* attacking from a sector */ } else { /* attacking from a sector */
sprintf(buf, "leaves the battlefield at %d%% efficiency", sprintf(buf, "leaves the battlefield at %d%% efficiency",
llp->land.lnd_effic); llp->unit.land.lnd_effic);
if ((llp->land.lnd_mobil - (int)llp->mobil) < -127) if ((llp->unit.land.lnd_mobil - (int)llp->mobil) < -127)
llp->land.lnd_mobil = -127; llp->unit.land.lnd_mobil = -127;
else else
llp->land.lnd_mobil -= (int)llp->mobil; llp->unit.land.lnd_mobil -= (int)llp->mobil;
llp->mobil = 0.0; llp->mobil = 0.0;
lnd_delete(llp, buf); lnd_delete(llp, buf);
} }
} }
if (nowhere_to_go) { if (nowhere_to_go) {
/* nowhere to go.. take more casualties */ /* nowhere to go.. take more casualties */
llp->land.lnd_effic -= 10; llp->unit.land.lnd_effic -= 10;
lnd_submil(&llp->land, llp->lcp->l_mil / 10); lnd_submil(&llp->unit.land, ((struct lchrstr *)llp->chrp)->l_mil / 10);
if (llp->land.lnd_effic < LAND_MINEFF) if (llp->unit.land.lnd_effic < LAND_MINEFF)
lnd_delete(llp, "has nowhere to retreat, and dies!"); lnd_delete(llp, "has nowhere to retreat, and dies!");
else else
lnd_print(llp, lnd_print(llp,
@ -290,24 +288,24 @@ void
lnd_takemob(struct emp_qelem *list, double loss) lnd_takemob(struct emp_qelem *list, double loss)
{ {
struct emp_qelem *qp, *next; struct emp_qelem *qp, *next;
struct llist *llp; struct ulist *llp;
int new; int new;
int mcost = ldround(combat_mob * loss, 1); int mcost = ldround(combat_mob * loss, 1);
for (qp = list->q_forw; qp != list; qp = next) { for (qp = list->q_forw; qp != list; qp = next) {
next = qp->q_forw; next = qp->q_forw;
llp = (struct llist *)qp; llp = (struct ulist *)qp;
/* /*
if (chance(loss)) if (chance(loss))
use_supply(&llp->land); use_supply(&llp->unit.land);
if (llp->land.lnd_mission == MI_RESERVE) if (llp->unit.land.lnd_mission == MI_RESERVE)
new = llp->land.lnd_mobil - mcost/2; new = llp->unit.land.lnd_mobil - mcost/2;
else else
*/ */
new = llp->land.lnd_mobil - mcost; new = llp->unit.land.lnd_mobil - mcost;
if (new < -127) if (new < -127)
new = -127; new = -127;
llp->land.lnd_mobil = (signed char)new; llp->unit.land.lnd_mobil = (signed char)new;
} }
} }
@ -478,7 +476,7 @@ lnd_sel(struct nstr_item *ni, struct emp_qelem *list)
{ {
struct lndstr land; struct lndstr land;
struct lchrstr *lcp; struct lchrstr *lcp;
struct llist *llp; struct ulist *llp;
int this_mot; int this_mot;
int mobtype = MOB_MOVE; /* indeterminate */ int mobtype = MOB_MOVE; /* indeterminate */
@ -518,9 +516,9 @@ lnd_sel(struct nstr_item *ni, struct emp_qelem *list)
land.lnd_harden = 0; land.lnd_harden = 0;
memset(land.lnd_rpath, 0, sizeof(land.lnd_rpath)); memset(land.lnd_rpath, 0, sizeof(land.lnd_rpath));
putland(land.lnd_uid, &land); putland(land.lnd_uid, &land);
llp = malloc(sizeof(struct llist)); llp = malloc(sizeof(struct ulist));
llp->lcp = lcp; llp->chrp = (struct empobj_chr *)lcp;
llp->land = land; llp->unit.land = land;
llp->mobil = land.lnd_mobil; llp->mobil = land.lnd_mobil;
emp_insque(&llp->queue, list); emp_insque(&llp->queue, list);
} }
@ -533,7 +531,7 @@ lnd_mar(struct emp_qelem *list, double *minmobp, double *maxmobp,
{ {
struct emp_qelem *qp; struct emp_qelem *qp;
struct emp_qelem *next; struct emp_qelem *next;
struct llist *llp; struct ulist *llp;
struct sctstr sect; struct sctstr sect;
struct lndstr land; struct lndstr land;
coord allx; coord allx;
@ -547,8 +545,8 @@ lnd_mar(struct emp_qelem *list, double *minmobp, double *maxmobp,
*togetherp = 1; *togetherp = 1;
for (qp = list->q_back; qp != list; qp = next) { for (qp = list->q_back; qp != list; qp = next) {
next = qp->q_back; next = qp->q_back;
llp = (struct llist *)qp; llp = (struct ulist *)qp;
getland(llp->land.lnd_uid, &land); getland(llp->unit.land.lnd_uid, &land);
if (land.lnd_own != actor) { if (land.lnd_own != actor) {
mpr(actor, "%s was disbanded at %s\n", mpr(actor, "%s was disbanded at %s\n",
prland(&land), xyas(land.lnd_x, land.lnd_y, land.lnd_own)); prland(&land), xyas(land.lnd_x, land.lnd_y, land.lnd_own));
@ -568,15 +566,15 @@ lnd_mar(struct emp_qelem *list, double *minmobp, double *maxmobp,
lnd_mess("was sucked into the sky by a strange looking spaceland", llp); /* heh -KHS */ lnd_mess("was sucked into the sky by a strange looking spaceland", llp); /* heh -KHS */
continue; continue;
} }
if (!(lchr[(int)llp->land.lnd_type].l_flags & L_SPY) && if (!(lchr[(int)llp->unit.land.lnd_type].l_flags & L_SPY) &&
!(lchr[(int)llp->land.lnd_type].l_flags & L_TRAIN) && !(lchr[(int)llp->unit.land.lnd_type].l_flags & L_TRAIN) &&
llp->land.lnd_item[I_MILIT] == 0) { llp->unit.land.lnd_item[I_MILIT] == 0) {
lnd_mess("has no mil on it to guide it", llp); lnd_mess("has no mil on it to guide it", llp);
continue; continue;
} }
rel = getrel(getnatp(sect.sct_own), player->cnum); rel = getrel(getnatp(sect.sct_own), player->cnum);
if (sect.sct_own != land.lnd_own && rel != ALLIED && 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) { sect.sct_own) {
sprintf(mess, "has been kidnapped by %s", cname(sect.sct_own)); sprintf(mess, "has been kidnapped by %s", cname(sect.sct_own));
lnd_mess(mess, llp); lnd_mess(mess, llp);
@ -596,7 +594,7 @@ lnd_mar(struct emp_qelem *list, double *minmobp, double *maxmobp,
*minmobp = llp->mobil; *minmobp = llp->mobil;
if (llp->mobil > *maxmobp) if (llp->mobil > *maxmobp)
*maxmobp = llp->mobil; *maxmobp = llp->mobil;
llp->land = land; llp->unit.land = land;
} }
} }
@ -605,19 +603,20 @@ lnd_put(struct emp_qelem *list, natid actor)
{ {
struct emp_qelem *qp; struct emp_qelem *qp;
struct emp_qelem *newqp; struct emp_qelem *newqp;
struct llist *llp; struct ulist *llp;
qp = list->q_back; qp = list->q_back;
while (qp != list) { while (qp != list) {
llp = (struct llist *)qp; llp = (struct ulist *)qp;
if (actor) { if (actor) {
mpr(actor, "%s stopped at %s\n", prland(&llp->land), mpr(actor, "%s stopped at %s\n", prland(&llp->unit.land),
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));
if (llp->mobil < -127) if (llp->mobil < -127)
llp->mobil = -127; llp->mobil = -127;
llp->land.lnd_mobil = llp->mobil; llp->unit.land.lnd_mobil = llp->mobil;
} }
putland(llp->land.lnd_uid, &llp->land); putland(llp->unit.land.lnd_uid, &llp->unit.land);
newqp = qp->q_back; newqp = qp->q_back;
emp_remque(qp); emp_remque(qp);
free(qp); free(qp);
@ -631,16 +630,17 @@ lnd_sweep(struct emp_qelem *land_list, int verbose, int takemob,
{ {
struct emp_qelem *qp; struct emp_qelem *qp;
struct emp_qelem *next; struct emp_qelem *next;
struct llist *llp; struct ulist *llp;
struct sctstr sect; struct sctstr sect;
int mines, m, max, sshells, lshells; int mines, m, max, sshells, lshells;
for (qp = land_list->q_back; qp != land_list; qp = next) { for (qp = land_list->q_back; qp != land_list; qp = next) {
next = qp->q_back; next = qp->q_back;
llp = (struct llist *)qp; llp = (struct ulist *)qp;
if (!(llp->lcp->l_flags & L_ENGINEER)) { if (!(((struct lchrstr *)llp->chrp)->l_flags & L_ENGINEER)) {
if (verbose) 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; continue;
} }
if (takemob && llp->mobil < 0.0) { if (takemob && llp->mobil < 0.0) {
@ -648,33 +648,33 @@ lnd_sweep(struct emp_qelem *land_list, int verbose, int takemob,
lnd_mess("is out of mobility", llp); lnd_mess("is out of mobility", llp);
continue; continue;
} }
getsect(llp->land.lnd_x, llp->land.lnd_y, &sect); getsect(llp->unit.land.lnd_x, llp->unit.land.lnd_y, &sect);
if (sect.sct_oldown == llp->land.lnd_own) { if (sect.sct_oldown == llp->unit.land.lnd_own) {
if (verbose) if (verbose)
mpr(actor, mpr(actor,
"%s is in a sector completely owned by you. Don't bother digging up mines there!\n", "%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; continue;
} }
if (sect.sct_type == SCT_BSPAN) { if (sect.sct_type == SCT_BSPAN) {
if (verbose) if (verbose)
mpr(actor, "%s is on a bridge. No mines there!\n", mpr(actor, "%s is on a bridge. No mines there!\n",
prland(&llp->land)); prland(&llp->unit.land));
continue; continue;
} }
if (takemob) { if (takemob) {
llp->mobil -= lnd_pathcost(&llp->land, 0.2); llp->mobil -= lnd_pathcost(&llp->unit.land, 0.2);
llp->land.lnd_mobil = (int)llp->mobil; llp->unit.land.lnd_mobil = (int)llp->mobil;
llp->land.lnd_harden = 0; 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)) if (!(mines = sect.sct_mines))
continue; continue;
max = llp->lcp->l_item[I_SHELL]; max = ((struct lchrstr *)llp->chrp)->l_item[I_SHELL];
lshells = llp->land.lnd_item[I_SHELL]; lshells = llp->unit.land.lnd_item[I_SHELL];
sshells = sect.sct_item[I_SHELL]; sshells = sect.sct_item[I_SHELL];
for (m = 0; mines > 0 && m < max * 2; m++) { 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"); mpr(actor, "Sweep...\n");
mines--; mines--;
if (lshells < max) if (lshells < max)
@ -684,9 +684,9 @@ lnd_sweep(struct emp_qelem *land_list, int verbose, int takemob,
} }
} }
sect.sct_mines = mines; 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; sect.sct_item[I_SHELL] = sshells;
putland(llp->land.lnd_uid, &llp->land); putland(llp->unit.land.lnd_uid, &llp->unit.land);
putsect(&sect); putsect(&sect);
} }
} }
@ -696,12 +696,12 @@ contains_engineer(struct emp_qelem *list)
{ {
struct emp_qelem *qp; struct emp_qelem *qp;
struct emp_qelem *next; struct emp_qelem *next;
struct llist *llp; struct ulist *llp;
for (qp = list->q_back; qp != list; qp = next) { for (qp = list->q_back; qp != list; qp = next) {
next = qp->q_back; next = qp->q_back;
llp = (struct llist *)qp; llp = (struct ulist *)qp;
if (llp->lcp->l_flags & L_ENGINEER) if (((struct lchrstr *)llp->chrp)->l_flags & L_ENGINEER)
return 1; return 1;
} }
return 0; return 0;
@ -712,27 +712,27 @@ lnd_check_mines(struct emp_qelem *land_list)
{ {
struct emp_qelem *qp; struct emp_qelem *qp;
struct emp_qelem *next; struct emp_qelem *next;
struct llist *llp; struct ulist *llp;
struct sctstr sect; struct sctstr sect;
int stopping = 0; int stopping = 0;
int with_eng = contains_engineer(land_list); int with_eng = contains_engineer(land_list);
for (qp = land_list->q_back; qp != land_list; qp = next) { for (qp = land_list->q_back; qp != land_list; qp = next) {
next = qp->q_back; next = qp->q_back;
llp = (struct llist *)qp; llp = (struct ulist *)qp;
getsect(llp->land.lnd_x, llp->land.lnd_y, &sect); getsect(llp->unit.land.lnd_x, llp->unit.land.lnd_y, &sect);
if (sect.sct_oldown == llp->land.lnd_own) if (sect.sct_oldown == llp->unit.land.lnd_own)
continue; continue;
if (sect.sct_type == SCT_BSPAN) if (sect.sct_type == SCT_BSPAN)
continue; continue;
if (!sect.sct_mines) if (!sect.sct_mines)
continue; continue;
if (chance(DMINE_LHITCHANCE(sect.sct_mines) / (1 + 2 * with_eng))) { 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--; sect.sct_mines--;
putsect(&sect); putsect(&sect);
putland(llp->land.lnd_uid, &llp->land); putland(llp->unit.land.lnd_uid, &llp->unit.land);
if (!llp->land.lnd_own) { if (!llp->unit.land.lnd_own) {
stopping = 1; stopping = 1;
emp_remque(qp); emp_remque(qp);
free(qp); free(qp);
@ -747,18 +747,18 @@ lnd_list(struct emp_qelem *land_list)
{ {
struct emp_qelem *qp; struct emp_qelem *qp;
struct emp_qelem *next; struct emp_qelem *next;
struct llist *llp; struct ulist *llp;
struct lndstr *lnd; struct lndstr *lnd;
pr("lnd# land type x,y a eff sh gun xl mu tech retr fuel\n"); 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) { for (qp = land_list->q_back; qp != land_list; qp = next) {
next = qp->q_back; next = qp->q_back;
llp = (struct llist *)qp; llp = (struct ulist *)qp;
lnd = &llp->land; lnd = &llp->unit.land;
pr("%4d ", lnd->lnd_uid); pr("%4d ", lnd->lnd_uid);
pr("%-16.16s ", llp->lcp->l_name); pr("%-16.16s ", ((struct lchrstr *)llp->chrp)->l_name);
prxy("%4d,%-4d ", lnd->lnd_x, lnd->lnd_y, llp->land.lnd_own); prxy("%4d,%-4d ", lnd->lnd_x, lnd->lnd_y, llp->unit.land.lnd_own);
pr("%1.1s", &lnd->lnd_army); pr("%1.1s", &lnd->lnd_army);
pr("%4d%%", lnd->lnd_effic); pr("%4d%%", lnd->lnd_effic);
pr("%4d", lnd->lnd_item[I_SHELL]); pr("%4d", lnd->lnd_item[I_SHELL]);
@ -773,15 +773,16 @@ lnd_list(struct emp_qelem *land_list)
} }
static void 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", mpr(llp->unit.land.lnd_own, "%s %s & stays in %s\n",
prland(&llp->land), prland(&llp->unit.land),
str, xyas(llp->land.lnd_x, llp->land.lnd_y, llp->land.lnd_own)); str, xyas(llp->unit.land.lnd_x, llp->unit.land.lnd_y,
llp->unit.land.lnd_own));
if (llp->mobil < -127) if (llp->mobil < -127)
llp->mobil = -127; llp->mobil = -127;
llp->land.lnd_mobil = llp->mobil; llp->unit.land.lnd_mobil = llp->mobil;
putland(llp->land.lnd_uid, &llp->land); putland(llp->unit.land.lnd_uid, &llp->unit.land);
emp_remque((struct emp_qelem *)llp); emp_remque((struct emp_qelem *)llp);
free(llp); free(llp);
} }
@ -791,12 +792,12 @@ lnd_count(struct emp_qelem *list)
{ {
struct emp_qelem *qp; struct emp_qelem *qp;
struct emp_qelem *next; struct emp_qelem *next;
struct llist *llp; struct ulist *llp;
int count = 0; int count = 0;
for (qp = list->q_back; qp != list; qp = next) { for (qp = list->q_back; qp != list; qp = next) {
next = qp->q_back; next = qp->q_back;
llp = (struct llist *)qp; llp = (struct ulist *)qp;
++count; ++count;
} }
return count; return count;
@ -807,7 +808,7 @@ lnd_damage(struct emp_qelem *list, int totdam)
{ {
struct emp_qelem *qp; struct emp_qelem *qp;
struct emp_qelem *next; struct emp_qelem *next;
struct llist *llp; struct ulist *llp;
int dam; int dam;
int count; int count;
@ -816,12 +817,12 @@ lnd_damage(struct emp_qelem *list, int totdam)
dam = ldround((double)totdam / count, 1); dam = ldround((double)totdam / count, 1);
for (qp = list->q_back; qp != list; qp = next) { for (qp = list->q_back; qp != list; qp = next) {
next = qp->q_back; next = qp->q_back;
llp = (struct llist *)qp; llp = (struct ulist *)qp;
/* have to get it again because of collateral damage */ /* have to get it again because of collateral damage */
getland(llp->land.lnd_uid, &llp->land); getland(llp->unit.land.lnd_uid, &llp->unit.land);
landdamage(&llp->land, dam); landdamage(&llp->unit.land, dam);
putland(llp->land.lnd_uid, &llp->land); putland(llp->unit.land.lnd_uid, &llp->unit.land);
if (!llp->land.lnd_own) { if (!llp->unit.land.lnd_own) {
emp_remque(qp); emp_remque(qp);
free(qp); free(qp);
} }
@ -834,15 +835,15 @@ lnd_easiest_target(struct emp_qelem *list)
{ {
struct emp_qelem *qp; struct emp_qelem *qp;
struct emp_qelem *next; struct emp_qelem *next;
struct llist *llp; struct ulist *llp;
int hard; int hard;
int easiest = 9876; /* things start great for victim */ int easiest = 9876; /* things start great for victim */
int count = 0; int count = 0;
for (qp = list->q_back; qp != list; qp = next) { for (qp = list->q_back; qp != list; qp = next) {
next = qp->q_back; next = qp->q_back;
llp = (struct llist *)qp; llp = (struct ulist *)qp;
hard = lnd_hardtarget(&llp->land); hard = lnd_hardtarget(&llp->unit.land);
if (hard < easiest) if (hard < easiest)
easiest = hard; /* things get worse for victim */ easiest = hard; /* things get worse for victim */
++count; ++count;
@ -1029,7 +1030,7 @@ lnd_mar_one_sector(struct emp_qelem *list, int dir, natid actor,
struct emp_qelem *qp; struct emp_qelem *qp;
struct emp_qelem *qp2; struct emp_qelem *qp2;
struct emp_qelem *next; struct emp_qelem *next;
struct llist *llp; struct ulist *llp;
struct emp_qelem cur, done; struct emp_qelem cur, done;
coord dx; coord dx;
coord dy; coord dy;
@ -1050,15 +1051,15 @@ lnd_mar_one_sector(struct emp_qelem *list, int dir, natid actor,
dy = diroff[dir][1]; dy = diroff[dir][1];
for (qp = list->q_back; qp != list; qp = next) { for (qp = list->q_back; qp != list; qp = next) {
next = qp->q_back; next = qp->q_back;
llp = (struct llist *)qp; llp = (struct ulist *)qp;
getsect(llp->land.lnd_x, llp->land.lnd_y, &osect); getsect(llp->unit.land.lnd_x, llp->unit.land.lnd_y, &osect);
oldown = osect.sct_own; oldown = osect.sct_own;
newx = xnorm(llp->land.lnd_x + dx); newx = xnorm(llp->unit.land.lnd_x + dx);
newy = ynorm(llp->land.lnd_y + dy); newy = ynorm(llp->unit.land.lnd_y + dy);
getsect(newx, newy, &sect); getsect(newx, newy, &sect);
rel = getrel(getnatp(sect.sct_own), player->cnum); rel = getrel(getnatp(sect.sct_own), player->cnum);
if ((sect.sct_own != actor && rel != ALLIED && 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_own) || (sect.sct_type == SCT_WATER ||
sect.sct_type == SCT_SANCT || sect.sct_type == SCT_SANCT ||
sect.sct_type == SCT_WASTE)) { sect.sct_type == SCT_WASTE)) {
@ -1072,7 +1073,7 @@ lnd_mar_one_sector(struct emp_qelem *list, int dir, natid actor,
} }
} }
if ((!intrchr[INT_RAIL].in_enable || sect.sct_rail == 0) if ((!intrchr[INT_RAIL].in_enable || sect.sct_rail == 0)
&& lnd_mobtype(&llp->land) == MOB_RAIL) { && lnd_mobtype(&llp->unit.land) == MOB_RAIL) {
if (together) { if (together) {
pr("no rail system in %s\n", xyas(newx, newy, actor)); pr("no rail system in %s\n", xyas(newx, newy, actor));
return 1; return 1;
@ -1085,9 +1086,9 @@ lnd_mar_one_sector(struct emp_qelem *list, int dir, natid actor,
} }
/* Note we check would_abandon first because we don't want /* Note we check would_abandon first because we don't want
to always have to do these checks */ 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; 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; stop = 1;
} }
/* now check stuff */ /* now check stuff */
@ -1096,7 +1097,7 @@ lnd_mar_one_sector(struct emp_qelem *list, int dir, natid actor,
if (!check_sect_ok(&osect)) if (!check_sect_ok(&osect))
return 1; return 1;
for (qp2 = list->q_back; qp2 != list; qp2 = qp2->q_back) { 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; return 1;
} }
if (stop) { if (stop) {
@ -1108,12 +1109,12 @@ lnd_mar_one_sector(struct emp_qelem *list, int dir, natid actor,
lnd_mess("is out of mobility", llp); lnd_mess("is out of mobility", llp);
continue; continue;
} }
llp->land.lnd_x = newx; llp->unit.land.lnd_x = newx;
llp->land.lnd_y = newy; llp->unit.land.lnd_y = newy;
llp->mobil -= lnd_mobcost(&llp->land, &sect); llp->mobil -= lnd_mobcost(&llp->unit.land, &sect);
llp->land.lnd_mobil = (int)llp->mobil; llp->unit.land.lnd_mobil = (int)llp->mobil;
llp->land.lnd_harden = 0; llp->unit.land.lnd_harden = 0;
putland(llp->land.lnd_uid, &llp->land); putland(llp->unit.land.lnd_uid, &llp->unit.land);
putsect(&osect); putsect(&osect);
getsect(osect.sct_x, osect.sct_y, &osect); getsect(osect.sct_x, osect.sct_y, &osect);
if (osect.sct_own != oldown && oldown == player->cnum) { if (osect.sct_own != oldown && oldown == player->cnum) {
@ -1123,20 +1124,20 @@ lnd_mar_one_sector(struct emp_qelem *list, int dir, natid actor,
} }
if (rel != ALLIED && sect.sct_own != actor && sect.sct_own) { /* must be a spy */ if (rel != ALLIED && sect.sct_own != actor && sect.sct_own) { /* must be a spy */
/* Always a 10% chance of getting caught. */ /* 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) { if (rel == NEUTRAL || rel == FRIENDLY) {
wu(0, sect.sct_own, wu(0, sect.sct_own,
"%s unit spotted in %s\n", cname(player->cnum), "%s unit spotted in %s\n", cname(player->cnum),
xyas(sect.sct_x, sect.sct_y, sect.sct_own)); 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 || } else if (rel == HOSTILE || rel == AT_WAR ||
rel == SITZKRIEG || rel == MOBILIZATION) { rel == SITZKRIEG || rel == MOBILIZATION) {
wu(0, sect.sct_own, wu(0, sect.sct_own,
"%s spy shot in %s\n", cname(player->cnum), "%s spy shot in %s\n", cname(player->cnum),
xyas(sect.sct_x, sect.sct_y, sect.sct_own)); xyas(sect.sct_x, sect.sct_y, sect.sct_own));
pr("%s was shot and killed.\n", prland(&llp->land)); pr("%s was shot and killed.\n", prland(&llp->unit.land));
llp->land.lnd_effic = 0; llp->unit.land.lnd_effic = 0;
putland(llp->land.lnd_uid, &llp->land); putland(llp->unit.land.lnd_uid, &llp->unit.land);
lnd_delete(llp, 0); lnd_delete(llp, 0);
} }
} }
@ -1153,18 +1154,18 @@ lnd_mar_one_sector(struct emp_qelem *list, int dir, natid actor,
emp_initque(&cur); emp_initque(&cur);
emp_initque(&done); emp_initque(&done);
while (!QEMPTY(list)) { while (!QEMPTY(list)) {
llp = (struct llist *)list->q_back; llp = (struct ulist *)list->q_back;
newx = llp->land.lnd_x; newx = llp->unit.land.lnd_x;
newy = llp->land.lnd_y; newy = llp->unit.land.lnd_y;
/* move units in NEWX,NEWY to cur */ /* move units in NEWX,NEWY to cur */
visible = 0; visible = 0;
for (qp = list->q_back; qp != list; qp = next) { for (qp = list->q_back; qp != list; qp = next) {
next = qp->q_back; next = qp->q_back;
llp = (struct llist *)qp; llp = (struct ulist *)qp;
if (llp->land.lnd_x == newx && llp->land.lnd_y == newy) { if (llp->unit.land.lnd_x == newx && llp->unit.land.lnd_y == newy) {
emp_remque(qp); emp_remque(qp);
emp_insque(qp, &cur); 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; visible = 1;
} }
} }
@ -1174,7 +1175,7 @@ lnd_mar_one_sector(struct emp_qelem *list, int dir, natid actor,
/* move survivors to done */ /* move survivors to done */
for (qp = cur.q_back; qp != &cur; qp = next) { for (qp = cur.q_back; qp != &cur; qp = next) {
next = qp->q_back; next = qp->q_back;
llp = (struct llist *)qp; llp = (struct ulist *)qp;
emp_remque(qp); emp_remque(qp);
emp_insque(qp, &done); emp_insque(qp, &done);
} }

View file

@ -39,28 +39,23 @@
#include <stdlib.h> #include <stdlib.h>
#include "damage.h" #include "damage.h"
#include "file.h" #include "file.h"
#include "item.h"
#include "land.h"
#include "map.h" #include "map.h"
#include "misc.h" #include "misc.h"
#include "mission.h" #include "mission.h"
#include "nat.h"
#include "news.h"
#include "nsc.h" #include "nsc.h"
#include "optlist.h" #include "optlist.h"
#include "path.h" #include "path.h"
#include "plane.h"
#include "player.h" #include "player.h"
#include "prototypes.h" #include "prototypes.h"
#include "queue.h" #include "queue.h"
#include "sect.h"
#include "server.h" #include "server.h"
#include "ship.h"
#include "xy.h" #include "xy.h"
#include "empobj.h"
#include "unit.h"
static int shp_check_one_mines(struct mlist *); static int shp_check_one_mines(struct ulist *);
static int shp_hit_mine(struct shpstr *, struct mchrstr *); static int shp_hit_mine(struct shpstr *, struct mchrstr *);
static void shp_mess(char *, struct mlist *); static void shp_mess(char *, struct ulist *);
void void
shp_sel(struct nstr_item *ni, struct emp_qelem *list) shp_sel(struct nstr_item *ni, struct emp_qelem *list)
@ -72,7 +67,7 @@ shp_sel(struct nstr_item *ni, struct emp_qelem *list)
{ {
struct shpstr ship; struct shpstr ship;
struct mchrstr *mcp; struct mchrstr *mcp;
struct mlist *mlp; struct ulist *mlp;
emp_initque(list); emp_initque(list);
while (nxtitem(ni, &ship)) { while (nxtitem(ni, &ship)) {
@ -107,9 +102,9 @@ shp_sel(struct nstr_item *ni, struct emp_qelem *list)
ship.shp_rflags = 0; ship.shp_rflags = 0;
memset(ship.shp_rpath, 0, sizeof(ship.shp_rpath)); memset(ship.shp_rpath, 0, sizeof(ship.shp_rpath));
putship(ship.shp_uid, &ship); putship(ship.shp_uid, &ship);
mlp = malloc(sizeof(struct mlist)); mlp = malloc(sizeof(struct ulist));
mlp->mcp = mcp; mlp->chrp = (struct empobj_chr *)mcp;
mlp->ship = ship; mlp->unit.ship = ship;
mlp->mobil = ship.shp_mobil; mlp->mobil = ship.shp_mobil;
emp_insque(&mlp->queue, list); emp_insque(&mlp->queue, list);
} }
@ -122,7 +117,7 @@ shp_nav(struct emp_qelem *list, double *minmobp, double *maxmobp,
{ {
struct emp_qelem *qp; struct emp_qelem *qp;
struct emp_qelem *next; struct emp_qelem *next;
struct mlist *mlp; struct ulist *mlp;
struct sctstr sect; struct sctstr sect;
struct shpstr ship; struct shpstr ship;
coord allx; coord allx;
@ -134,8 +129,8 @@ shp_nav(struct emp_qelem *list, double *minmobp, double *maxmobp,
*togetherp = 1; *togetherp = 1;
for (qp = list->q_back; qp != list; qp = next) { for (qp = list->q_back; qp != list; qp = next) {
next = qp->q_back; next = qp->q_back;
mlp = (struct mlist *)qp; mlp = (struct ulist *)qp;
getship(mlp->ship.shp_uid, &ship); getship(mlp->unit.ship.shp_uid, &ship);
if (ship.shp_own != actor) { if (ship.shp_own != actor) {
mpr(actor, "%s was sunk at %s\n", mpr(actor, "%s was sunk at %s\n",
prship(&ship), xyas(ship.shp_x, ship.shp_y, actor)); prship(&ship), xyas(ship.shp_x, ship.shp_y, actor));
@ -187,7 +182,7 @@ shp_nav(struct emp_qelem *list, double *minmobp, double *maxmobp,
*minmobp = mlp->mobil; *minmobp = mlp->mobil;
if (mlp->mobil > *maxmobp) if (mlp->mobil > *maxmobp)
*maxmobp = mlp->mobil; *maxmobp = mlp->mobil;
mlp->ship = ship; mlp->unit.ship = ship;
} }
} }
@ -196,15 +191,16 @@ shp_put(struct emp_qelem *list, natid actor)
{ {
struct emp_qelem *qp; struct emp_qelem *qp;
struct emp_qelem *newqp; struct emp_qelem *newqp;
struct mlist *mlp; struct ulist *mlp;
qp = list->q_back; qp = list->q_back;
while (qp != list) { while (qp != list) {
mlp = (struct mlist *)qp; mlp = (struct ulist *)qp;
mpr(actor, "%s stopped at %s\n", prship(&mlp->ship), mpr(actor, "%s stopped at %s\n", prship(&mlp->unit.ship),
xyas(mlp->ship.shp_x, mlp->ship.shp_y, mlp->ship.shp_own)); xyas(mlp->unit.ship.shp_x, mlp->unit.ship.shp_y,
mlp->ship.shp_mobil = (int)mlp->mobil; mlp->unit.ship.shp_own));
putship(mlp->ship.shp_uid, &mlp->ship); mlp->unit.ship.shp_mobil = (int)mlp->mobil;
putship(mlp->unit.ship.shp_uid, &mlp->unit.ship);
newqp = qp->q_back; newqp = qp->q_back;
emp_remque(qp); emp_remque(qp);
free(qp); free(qp);
@ -217,7 +213,7 @@ shp_sweep(struct emp_qelem *ship_list, int verbose, int takemob, natid actor)
{ {
struct emp_qelem *qp; struct emp_qelem *qp;
struct emp_qelem *next; struct emp_qelem *next;
struct mlist *mlp; struct ulist *mlp;
struct sctstr sect; struct sctstr sect;
int mines, m, max, shells; int mines, m, max, shells;
int changed = 0; int changed = 0;
@ -225,34 +221,35 @@ shp_sweep(struct emp_qelem *ship_list, int verbose, int takemob, natid actor)
for (qp = ship_list->q_back; qp != ship_list; qp = next) { for (qp = ship_list->q_back; qp != ship_list; qp = next) {
next = qp->q_back; next = qp->q_back;
mlp = (struct mlist *)qp; mlp = (struct ulist *)qp;
if (!(mlp->mcp->m_flags & M_SWEEP)) { if (!(((struct mchrstr *)mlp->chrp)->m_flags & M_SWEEP)) {
if (verbose) if (verbose)
mpr(actor, "%s doesn't have minesweeping capability!\n", mpr(actor, "%s doesn't have minesweeping capability!\n",
prship(&mlp->ship)); prship(&mlp->unit.ship));
continue; continue;
} }
if (takemob && mlp->mobil <= 0.0) { if (takemob && mlp->mobil <= 0.0) {
if (verbose) if (verbose)
mpr(actor, "%s is out of mobility!\n", prship(&mlp->ship)); mpr(actor, "%s is out of mobility!\n",
prship(&mlp->unit.ship));
continue; continue;
} }
getsect(mlp->ship.shp_x, mlp->ship.shp_y, &sect); getsect(mlp->unit.ship.shp_x, mlp->unit.ship.shp_y, &sect);
if (sect.sct_type != SCT_WATER) { if (sect.sct_type != SCT_WATER) {
if (verbose) if (verbose)
mpr(actor, "%s is not at sea. No mines there!\n", mpr(actor, "%s is not at sea. No mines there!\n",
prship(&mlp->ship)); prship(&mlp->unit.ship));
continue; continue;
} }
if (takemob) { if (takemob) {
mlp->mobil -= shp_mobcost(&mlp->ship); mlp->mobil -= shp_mobcost(&mlp->unit.ship);
mlp->ship.shp_mobil = (int)mlp->mobil; mlp->unit.ship.shp_mobil = (int)mlp->mobil;
} }
putship(mlp->ship.shp_uid, &mlp->ship); putship(mlp->unit.ship.shp_uid, &mlp->unit.ship);
if (!(mines = sect.sct_mines)) if (!(mines = sect.sct_mines))
continue; continue;
max = mlp->mcp->m_item[I_SHELL]; max = ((struct mchrstr *)mlp->chrp)->m_item[I_SHELL];
shells = mlp->ship.shp_item[I_SHELL]; shells = mlp->unit.ship.shp_item[I_SHELL];
for (m = 0; mines > 0 && m < 5; m++) { for (m = 0; mines > 0 && m < 5; m++) {
if (chance(0.66)) { if (chance(0.66)) {
mpr(actor, "Sweep...\n"); mpr(actor, "Sweep...\n");
@ -262,13 +259,13 @@ shp_sweep(struct emp_qelem *ship_list, int verbose, int takemob, natid actor)
} }
} }
sect.sct_mines = mines; sect.sct_mines = mines;
mlp->ship.shp_item[I_SHELL] = shells; mlp->unit.ship.shp_item[I_SHELL] = shells;
if (shp_check_one_mines(mlp)) { if (shp_check_one_mines(mlp)) {
stopping = 1; stopping = 1;
emp_remque(qp); emp_remque(qp);
free(qp); free(qp);
} }
putship(mlp->ship.shp_uid, &mlp->ship); putship(mlp->unit.ship.shp_uid, &mlp->unit.ship);
putsect(&sect); putsect(&sect);
} }
if (changed) if (changed)
@ -277,25 +274,25 @@ shp_sweep(struct emp_qelem *ship_list, int verbose, int takemob, natid actor)
} }
static int static int
shp_check_one_mines(struct mlist *mlp) shp_check_one_mines(struct ulist *mlp)
{ {
struct sctstr sect; struct sctstr sect;
int actor; int actor;
getsect(mlp->ship.shp_x, mlp->ship.shp_y, &sect); getsect(mlp->unit.ship.shp_x, mlp->unit.ship.shp_y, &sect);
if (sect.sct_type != SCT_WATER) if (sect.sct_type != SCT_WATER)
return 0; return 0;
if (!sect.sct_mines) if (!sect.sct_mines)
return 0; return 0;
if (chance(DMINE_HITCHANCE(sect.sct_mines))) { if (chance(DMINE_HITCHANCE(sect.sct_mines))) {
actor = mlp->ship.shp_own; actor = mlp->unit.ship.shp_own;
shp_hit_mine(&mlp->ship, mlp->mcp); shp_hit_mine(&mlp->unit.ship, ((struct mchrstr *)mlp->chrp));
sect.sct_mines--; sect.sct_mines--;
if (map_set(actor, sect.sct_x, sect.sct_y, 'X', 0)) if (map_set(actor, sect.sct_x, sect.sct_y, 'X', 0))
writemap(actor); writemap(actor);
putsect(&sect); putsect(&sect);
putship(mlp->ship.shp_uid, &mlp->ship); putship(mlp->unit.ship.shp_uid, &mlp->unit.ship);
if (!mlp->ship.shp_own) if (!mlp->unit.ship.shp_own)
return 1; return 1;
} }
return 0; return 0;
@ -306,12 +303,12 @@ shp_check_mines(struct emp_qelem *ship_list)
{ {
struct emp_qelem *qp; struct emp_qelem *qp;
struct emp_qelem *next; struct emp_qelem *next;
struct mlist *mlp; struct ulist *mlp;
int stopping = 0; int stopping = 0;
for (qp = ship_list->q_back; qp != ship_list; qp = next) { for (qp = ship_list->q_back; qp != ship_list; qp = next) {
next = qp->q_back; next = qp->q_back;
mlp = (struct mlist *)qp; mlp = (struct ulist *)qp;
if (shp_check_one_mines(mlp)) { if (shp_check_one_mines(mlp)) {
stopping = 1; stopping = 1;
emp_remque(qp); emp_remque(qp);
@ -326,18 +323,18 @@ shp_list(struct emp_qelem *ship_list)
{ {
struct emp_qelem *qp; struct emp_qelem *qp;
struct emp_qelem *next; struct emp_qelem *next;
struct mlist *mlp; struct ulist *mlp;
struct shpstr *shp; struct shpstr *shp;
pr("shp# ship type x,y fl eff mil sh gun pn he xl ln mob tech\n"); pr("shp# ship type x,y fl eff mil sh gun pn he xl ln mob tech\n");
for (qp = ship_list->q_back; qp != ship_list; qp = next) { for (qp = ship_list->q_back; qp != ship_list; qp = next) {
next = qp->q_back; next = qp->q_back;
mlp = (struct mlist *)qp; mlp = (struct ulist *)qp;
shp = &mlp->ship; shp = &mlp->unit.ship;
pr("%4d ", shp->shp_uid); pr("%4d ", shp->shp_uid);
pr("%-16.16s ", mlp->mcp->m_name); pr("%-16.16s ", ((struct mchrstr *)mlp->chrp)->m_name);
prxy("%4d,%-4d ", shp->shp_x, shp->shp_y, mlp->ship.shp_own); prxy("%4d,%-4d ", shp->shp_x, shp->shp_y, mlp->unit.ship.shp_own);
pr("%1.1s", &shp->shp_fleet); pr("%1.1s", &shp->shp_fleet);
pr("%4d%%", shp->shp_effic); pr("%4d%%", shp->shp_effic);
pr("%4d", shp->shp_item[I_MILIT]); pr("%4d", shp->shp_item[I_MILIT]);
@ -355,13 +352,14 @@ shp_list(struct emp_qelem *ship_list)
} }
static void static void
shp_mess(char *str, struct mlist *mlp) shp_mess(char *str, struct ulist *mlp)
{ {
mpr(mlp->ship.shp_own, "%s %s & stays in %s\n", mpr(mlp->unit.ship.shp_own, "%s %s & stays in %s\n",
prship(&mlp->ship), prship(&mlp->unit.ship),
str, xyas(mlp->ship.shp_x, mlp->ship.shp_y, mlp->ship.shp_own)); str, xyas(mlp->unit.ship.shp_x, mlp->unit.ship.shp_y,
mlp->ship.shp_mobil = (int)mlp->mobil; mlp->unit.ship.shp_own));
putship(mlp->ship.shp_uid, &mlp->ship); mlp->unit.ship.shp_mobil = (int)mlp->mobil;
putship(mlp->unit.ship.shp_uid, &mlp->unit.ship);
emp_remque((struct emp_qelem *)mlp); emp_remque((struct emp_qelem *)mlp);
free(mlp); free(mlp);
} }
@ -411,17 +409,19 @@ shp_count(struct emp_qelem *list, int wantflags, int nowantflags,
{ {
struct emp_qelem *qp; struct emp_qelem *qp;
struct emp_qelem *next; struct emp_qelem *next;
struct mlist *mlp; struct ulist *mlp;
int count = 0; int count = 0;
for (qp = list->q_back; qp != list; qp = next) { for (qp = list->q_back; qp != list; qp = next) {
next = qp->q_back; next = qp->q_back;
mlp = (struct mlist *)qp; mlp = (struct ulist *)qp;
if (mlp->ship.shp_x != x || mlp->ship.shp_y != y) if (mlp->unit.ship.shp_x != x || mlp->unit.ship.shp_y != y)
continue; continue;
if (wantflags && (mlp->mcp->m_flags & wantflags) != wantflags) if (wantflags &&
(((struct mchrstr *)mlp->chrp)->m_flags & wantflags) != wantflags)
continue; continue;
if (nowantflags && mlp->mcp->m_flags & nowantflags) if (nowantflags &&
((struct mchrstr *)mlp->chrp)->m_flags & nowantflags)
continue; continue;
++count; ++count;
} }
@ -429,11 +429,11 @@ shp_count(struct emp_qelem *list, int wantflags, int nowantflags,
} }
static void static void
shp_damage_one(struct mlist *mlp, int dam) shp_damage_one(struct ulist *mlp, int dam)
{ {
shipdamage(&mlp->ship, dam); shipdamage(&mlp->unit.ship, dam);
putship(mlp->ship.shp_uid, &mlp->ship); putship(mlp->unit.ship.shp_uid, &mlp->unit.ship);
if (!mlp->ship.shp_own) { if (!mlp->unit.ship.shp_own) {
emp_remque((struct emp_qelem *)mlp); emp_remque((struct emp_qelem *)mlp);
free(mlp); free(mlp);
} }
@ -445,7 +445,7 @@ shp_damage(struct emp_qelem *list, int totdam, int wantflags,
{ {
struct emp_qelem *qp; struct emp_qelem *qp;
struct emp_qelem *next; struct emp_qelem *next;
struct mlist *mlp; struct ulist *mlp;
int dam; int dam;
int count; int count;
@ -455,12 +455,14 @@ shp_damage(struct emp_qelem *list, int totdam, int wantflags,
dam = ldround((double)totdam / count, 1); dam = ldround((double)totdam / count, 1);
for (qp = list->q_back; qp != list; qp = next) { for (qp = list->q_back; qp != list; qp = next) {
next = qp->q_back; next = qp->q_back;
mlp = (struct mlist *)qp; mlp = (struct ulist *)qp;
if (mlp->ship.shp_x != x || mlp->ship.shp_y != y) if (mlp->unit.ship.shp_x != x || mlp->unit.ship.shp_y != y)
continue; continue;
if (wantflags && (mlp->mcp->m_flags & wantflags) != wantflags) if (wantflags &&
(((struct mchrstr *)mlp->chrp)->m_flags & wantflags) != wantflags)
continue; continue;
if (nowantflags && mlp->mcp->m_flags & nowantflags) if (nowantflags &&
((struct mchrstr *)mlp->chrp)->m_flags & nowantflags)
continue; continue;
shp_damage_one(mlp, dam); shp_damage_one(mlp, dam);
} }
@ -473,47 +475,50 @@ shp_contains(struct emp_qelem *list, int newx, int newy, int wantflags,
{ {
struct emp_qelem *qp; struct emp_qelem *qp;
struct emp_qelem *next; struct emp_qelem *next;
struct mlist *mlp; struct ulist *mlp;
for (qp = list->q_back; qp != list; qp = next) { for (qp = list->q_back; qp != list; qp = next) {
next = qp->q_back; next = qp->q_back;
mlp = (struct mlist *)qp; mlp = (struct ulist *)qp;
/* If the ship isn't in the requested sector, then continue */ /* If the ship isn't in the requested sector, then continue */
if (newx != mlp->ship.shp_x || newy != mlp->ship.shp_y) if (newx != mlp->unit.ship.shp_x || newy != mlp->unit.ship.shp_y)
continue; continue;
if (wantflags && (mlp->mcp->m_flags & wantflags) != wantflags) if (wantflags &&
(((struct mchrstr *)mlp->chrp)->m_flags & wantflags) != wantflags)
continue; continue;
if (nowantflags && mlp->mcp->m_flags & nowantflags) if (nowantflags &&
((struct mchrstr *)mlp->chrp)->m_flags & nowantflags)
continue; continue;
return 1; return 1;
} }
return 0; return 0;
} }
static struct mlist * static struct ulist *
most_valuable_ship(struct emp_qelem *list) most_valuable_ship(struct emp_qelem *list)
{ {
struct emp_qelem *qp; struct emp_qelem *qp;
struct emp_qelem *next; struct emp_qelem *next;
struct mlist *mlp; struct ulist *mlp;
struct mlist *mvs = 0; struct ulist *mvs = 0;
for (qp = list->q_back; qp != list; qp = next) { for (qp = list->q_back; qp != list; qp = next) {
next = qp->q_back; next = qp->q_back;
mlp = (struct mlist *)qp; mlp = (struct ulist *)qp;
if (mlp->mcp->m_flags & M_SUB) if (((struct mchrstr *)mlp->chrp)->m_flags & M_SUB)
continue; continue;
if (!mlp->mcp->m_nxlight && if (!((struct mchrstr *)mlp->chrp)->m_nxlight &&
!mlp->mcp->m_nchoppers && !((struct mchrstr *)mlp->chrp)->m_nchoppers &&
mlp->mcp->m_cost < 1000 && ((struct mchrstr *)mlp->chrp)->m_cost < 1000 &&
!mlp->mcp->m_nplanes && !mlp->mcp->m_nland) !((struct mchrstr *)mlp->chrp)->m_nplanes &&
!((struct mchrstr *)mlp->chrp)->m_nland)
continue; continue;
if (!mvs) { if (!mvs) {
mvs = mlp; mvs = mlp;
continue; continue;
} }
if (mlp->mcp->m_cost * mlp->ship.shp_effic > if (((struct mchrstr *)mlp->chrp)->m_cost * mlp->unit.ship.shp_effic >
mvs->mcp->m_cost * mvs->ship.shp_effic) ((struct mchrstr *)mlp->chrp)->m_cost * mvs->unit.ship.shp_effic)
mvs = mlp; mvs = mlp;
} }
return mvs; return mvs;
@ -524,19 +529,21 @@ shp_easiest_target(struct emp_qelem *list, int wantflags, int nowantflags)
{ {
struct emp_qelem *qp; struct emp_qelem *qp;
struct emp_qelem *next; struct emp_qelem *next;
struct mlist *mlp; struct ulist *mlp;
int hard; int hard;
int easiest = 9876; /* things start great for victim */ int easiest = 9876; /* things start great for victim */
int count = 0; int count = 0;
for (qp = list->q_back; qp != list; qp = next) { for (qp = list->q_back; qp != list; qp = next) {
next = qp->q_back; next = qp->q_back;
mlp = (struct mlist *)qp; mlp = (struct ulist *)qp;
if (wantflags && (mlp->mcp->m_flags & wantflags) != wantflags) if (wantflags &&
(((struct mchrstr *)mlp->chrp)->m_flags & wantflags) != wantflags)
continue; continue;
if (nowantflags && mlp->mcp->m_flags & nowantflags) if (nowantflags &&
((struct mchrstr *)mlp->chrp)->m_flags & nowantflags)
continue; continue;
hard = shp_hardtarget(&mlp->ship); hard = shp_hardtarget(&mlp->unit.ship);
if (hard < easiest) if (hard < easiest)
easiest = hard; /* things get worse for victim */ easiest = hard; /* things get worse for victim */
++count; ++count;
@ -552,16 +559,16 @@ shp_missile_interdiction(struct emp_qelem *list, coord newx, coord newy,
int twotries; int twotries;
int stopping = 0; int stopping = 0;
struct emp_qelem msl_list, *qp, *newqp; struct emp_qelem msl_list, *qp, *newqp;
struct mlist *mvs; struct ulist *mvs;
char what[512]; char what[512];
msl_sel(&msl_list, newx, newy, victim, P_T | P_MAR, 0, MI_INTERDICT); msl_sel(&msl_list, newx, newy, victim, P_T | P_MAR, 0, MI_INTERDICT);
twotries = 0; twotries = 0;
while (!QEMPTY(&msl_list) && (mvs = most_valuable_ship(list))) { while (!QEMPTY(&msl_list) && (mvs = most_valuable_ship(list))) {
sprintf(what, "%s", prship(&mvs->ship)); sprintf(what, "%s", prship(&mvs->unit.ship));
dam = msl_launch_mindam(&msl_list, newx, newy, dam = msl_launch_mindam(&msl_list, newx, newy,
shp_hardtarget(&mvs->ship), shp_hardtarget(&mvs->unit.ship),
EF_SHIP, 1, what, victim, MI_INTERDICT); EF_SHIP, 1, what, victim, MI_INTERDICT);
if (dam) { if (dam) {
mpr(victim, mpr(victim,
@ -594,7 +601,7 @@ notify_coastguard(struct emp_qelem *list, int trange, struct sctstr *sectp)
{ {
struct emp_qelem *qp; struct emp_qelem *qp;
struct emp_qelem *next; struct emp_qelem *next;
struct mlist *mlp; struct ulist *mlp;
struct natstr *natp; struct natstr *natp;
int vrange; int vrange;
@ -611,17 +618,18 @@ notify_coastguard(struct emp_qelem *list, int trange, struct sctstr *sectp)
for (qp = list->q_back; qp != list; qp = next) { for (qp = list->q_back; qp != list; qp = next) {
next = qp->q_back; next = qp->q_back;
mlp = (struct mlist *)qp; mlp = (struct ulist *)qp;
if (mlp->mcp->m_flags & M_SUB) if (((struct mchrstr *)mlp->chrp)->m_flags & M_SUB)
continue; continue;
if (natp->nat_flags & NF_COASTWATCH) if (natp->nat_flags & NF_COASTWATCH)
wu(0, sectp->sct_own, wu(0, sectp->sct_own,
"%s %s sighted at %s\n", "%s %s sighted at %s\n",
cname(mlp->ship.shp_own), cname(mlp->unit.ship.shp_own),
prship(&mlp->ship), prship(&mlp->unit.ship),
xyas(mlp->ship.shp_x, mlp->ship.shp_y, sectp->sct_own)); xyas(mlp->unit.ship.shp_x, mlp->unit.ship.shp_y,
sectp->sct_own));
if (opt_HIDDEN) if (opt_HIDDEN)
setcont(sectp->sct_own, mlp->ship.shp_own, FOUND_COAST); setcont(sectp->sct_own, mlp->unit.ship.shp_own, FOUND_COAST);
} }
return 1; return 1;
@ -787,19 +795,19 @@ shp_view(struct emp_qelem *list)
struct sctstr sect; struct sctstr sect;
struct emp_qelem *qp; struct emp_qelem *qp;
struct emp_qelem *next; struct emp_qelem *next;
struct mlist *mlp; struct ulist *mlp;
for (qp = list->q_back; qp != list; qp = next) { for (qp = list->q_back; qp != list; qp = next) {
next = qp->q_back; next = qp->q_back;
mlp = (struct mlist *)qp; mlp = (struct ulist *)qp;
getsect(mlp->ship.shp_x, mlp->ship.shp_y, &sect); getsect(mlp->unit.ship.shp_x, mlp->unit.ship.shp_y, &sect);
if (mlp->mcp->m_flags & M_FOOD) if (((struct mchrstr *)mlp->chrp)->m_flags & M_FOOD)
mpr(mlp->ship.shp_own, "[fert:%d] ", sect.sct_fertil); mpr(mlp->unit.ship.shp_own, "[fert:%d] ", sect.sct_fertil);
if (mlp->mcp->m_flags & M_OIL) if (((struct mchrstr *)mlp->chrp)->m_flags & M_OIL)
mpr(mlp->ship.shp_own, "[oil:%d] ", sect.sct_oil); mpr(mlp->unit.ship.shp_own, "[oil:%d] ", sect.sct_oil);
mpr(mlp->ship.shp_own, "%s @ %s %d%% %s\n", mpr(mlp->unit.ship.shp_own, "%s @ %s %d%% %s\n",
prship(&mlp->ship), prship(&mlp->unit.ship),
xyas(mlp->ship.shp_x, mlp->ship.shp_y, player->cnum), xyas(mlp->unit.ship.shp_x, mlp->unit.ship.shp_y, player->cnum),
sect.sct_effic, dchr[sect.sct_type].d_name); sect.sct_effic, dchr[sect.sct_type].d_name);
} }
} }
@ -811,7 +819,7 @@ shp_nav_one_sector(struct emp_qelem *list, int dir, natid actor,
struct sctstr sect; struct sctstr sect;
struct emp_qelem *qp; struct emp_qelem *qp;
struct emp_qelem *next; struct emp_qelem *next;
struct mlist *mlp; struct ulist *mlp;
struct emp_qelem done; struct emp_qelem done;
coord dx; coord dx;
coord dy; coord dy;
@ -832,16 +840,16 @@ shp_nav_one_sector(struct emp_qelem *list, int dir, natid actor,
dy = diroff[dir][1]; dy = diroff[dir][1];
for (qp = list->q_back; qp != list; qp = next) { for (qp = list->q_back; qp != list; qp = next) {
next = qp->q_back; next = qp->q_back;
mlp = (struct mlist *)qp; mlp = (struct ulist *)qp;
newx = xnorm(mlp->ship.shp_x + dx); newx = xnorm(mlp->unit.ship.shp_x + dx);
newy = ynorm(mlp->ship.shp_y + dy); newy = ynorm(mlp->unit.ship.shp_y + dy);
getsect(newx, newy, &sect); getsect(newx, newy, &sect);
navigate = shp_check_nav(&sect, &mlp->ship); navigate = shp_check_nav(&sect, &mlp->unit.ship);
if (navigate != CN_NAVIGABLE || if (navigate != CN_NAVIGABLE ||
(sect.sct_own && actor != sect.sct_own && (sect.sct_own && actor != sect.sct_own &&
getrel(getnatp(sect.sct_own), actor) < FRIENDLY)) { getrel(getnatp(sect.sct_own), actor) < FRIENDLY)) {
if (dchr[sect.sct_type].d_nav == NAV_CANAL && if (dchr[sect.sct_type].d_nav == NAV_CANAL &&
!(mlp->mcp->m_flags & M_CANAL) && !(((struct mchrstr *)mlp->chrp)->m_flags & M_CANAL) &&
navigate == CN_LANDLOCKED) navigate == CN_LANDLOCKED)
sprintf(dp, sprintf(dp,
"is too large to fit into the canal system at %s", "is too large to fit into the canal system at %s",
@ -861,25 +869,27 @@ shp_nav_one_sector(struct emp_qelem *list, int dir, natid actor,
shp_mess("is out of mobility", mlp); shp_mess("is out of mobility", mlp);
continue; continue;
} }
mobcost = shp_mobcost(&mlp->ship); mobcost = shp_mobcost(&mlp->unit.ship);
mlp->ship.shp_x = newx; mlp->unit.ship.shp_x = newx;
mlp->ship.shp_y = newy; mlp->unit.ship.shp_y = newy;
if (mlp->mobil - mobcost < -127) { if (mlp->mobil - mobcost < -127) {
mlp->mobil = -127; mlp->mobil = -127;
} else { } else {
mlp->mobil -= mobcost; mlp->mobil -= mobcost;
} }
mlp->ship.shp_mobil = (int)mlp->mobil; mlp->unit.ship.shp_mobil = (int)mlp->mobil;
putship(mlp->ship.shp_uid, &mlp->ship); putship(mlp->unit.ship.shp_uid, &mlp->unit.ship);
/* Now update the map for this ship */ /* Now update the map for this ship */
tech = techfact(mlp->ship.shp_tech, mlp->mcp->m_vrnge); tech = techfact(mlp->unit.ship.shp_tech,
if (mlp->mcp->m_flags & M_SONAR) ((struct mchrstr *)mlp->chrp)->m_vrnge);
tf = techfact(mlp->ship.shp_tech, 1.0); if (((struct mchrstr *)mlp->chrp)->m_flags & M_SONAR)
tf = techfact(mlp->unit.ship.shp_tech, 1.0);
else else
tf = 0.0; tf = 0.0;
radmapupd(mlp->ship.shp_own, mlp->ship.shp_x, mlp->ship.shp_y, radmapupd(mlp->unit.ship.shp_own,
(int)mlp->ship.shp_effic, (int)tech, tf); mlp->unit.ship.shp_x, mlp->unit.ship.shp_y,
(int)mlp->unit.ship.shp_effic, (int)tech, tf);
} }
if (QEMPTY(list)) if (QEMPTY(list))
return stopping; return stopping;
@ -893,15 +903,16 @@ shp_nav_one_sector(struct emp_qelem *list, int dir, natid actor,
/* interdict ships sector by sector */ /* interdict ships sector by sector */
emp_initque(&done); emp_initque(&done);
while (!QEMPTY(list)) { while (!QEMPTY(list)) {
mlp = (struct mlist *)list->q_back; mlp = (struct ulist *)list->q_back;
newx = mlp->ship.shp_x; newx = mlp->unit.ship.shp_x;
newy = mlp->ship.shp_y; newy = mlp->unit.ship.shp_y;
stopping |= shp_interdict(list, newx, newy, actor); stopping |= shp_interdict(list, newx, newy, actor);
/* move survivors in this sector to done */ /* move survivors in this sector to done */
for (qp = list->q_back; qp != list; qp = next) { for (qp = list->q_back; qp != list; qp = next) {
next = qp->q_back; next = qp->q_back;
mlp = (struct mlist *)qp; mlp = (struct ulist *)qp;
if (mlp->ship.shp_x == newx && mlp->ship.shp_y == newy) { if (mlp->unit.ship.shp_x == newx &&
mlp->unit.ship.shp_y == newy) {
emp_remque(qp); emp_remque(qp);
emp_insque(qp, &done); emp_insque(qp, &done);
} }
@ -1028,18 +1039,18 @@ void
shp_missdef(struct shpstr *sp, natid victim) shp_missdef(struct shpstr *sp, natid victim)
{ {
struct emp_qelem list; struct emp_qelem list;
struct mlist *mlp; struct ulist *mlp;
int eff; int eff;
char buf[512]; char buf[512];
emp_initque(&list); emp_initque(&list);
mlp = malloc(sizeof(struct mlist)); mlp = malloc(sizeof(struct ulist));
mlp->mcp = &mchr[(int)sp->shp_type]; mlp->chrp = (struct empobj_chr *)&mchr[(int)sp->shp_type];
mlp->ship = *sp; mlp->unit.ship = *sp;
mlp->mobil = sp->shp_mobil; mlp->mobil = sp->shp_mobil;
emp_insque(&mlp->queue, &list); emp_insque(&mlp->queue, &list);
sprintf(buf, "%s", prship(&mlp->ship)); sprintf(buf, "%s", prship(&mlp->unit.ship));
eff = sp->shp_effic; eff = sp->shp_effic;
if (most_valuable_ship(&list)) { if (most_valuable_ship(&list)) {

View file

@ -36,11 +36,11 @@
#include <ctype.h> #include <ctype.h>
#include "item.h"
#include "nsc.h" #include "nsc.h"
#include "path.h" #include "path.h"
#include "ship.h"
#include "update.h" #include "update.h"
#include "empobj.h"
#include "unit.h"
static void swap(struct shpstr *); static void swap(struct shpstr *);
@ -233,7 +233,7 @@ nav_ship(struct shpstr *sp)
char buf[1024]; char buf[1024];
struct emp_qelem ship_list; struct emp_qelem ship_list;
struct emp_qelem *qp, *newqp; struct emp_qelem *qp, *newqp;
struct mlist *mlp; struct ulist *mlp;
int dummyint; int dummyint;
double dummydouble; double dummydouble;
int dir; int dir;
@ -249,9 +249,9 @@ nav_ship(struct shpstr *sp)
/* Make a list of one ships so we can use the navi.c code */ /* Make a list of one ships so we can use the navi.c code */
emp_initque(&ship_list); emp_initque(&ship_list);
mlp = malloc(sizeof(struct mlist)); mlp = malloc(sizeof(struct ulist));
mlp->mcp = mchr + sp->shp_type; mlp->chrp = (struct empobj_chr *)(mchr + sp->shp_type);
mlp->ship = *sp; mlp->unit.ship = *sp;
mlp->mobil = sp->shp_mobil; mlp->mobil = sp->shp_mobil;
emp_insque(&mlp->queue, &ship_list); emp_insque(&mlp->queue, &ship_list);
@ -268,9 +268,10 @@ nav_ship(struct shpstr *sp)
sectp = getsectp(sp->shp_x, sp->shp_y); sectp = getsectp(sp->shp_x, sp->shp_y);
if (opt_FUEL && if (opt_FUEL &&
sectp->sct_own != 0 && sectp->sct_own != 0 &&
sp->shp_fuel <= 0 && mlp->mcp->m_fuelu != 0) sp->shp_fuel <= 0 &&
((struct mchrstr *)mlp->chrp)->m_fuelu != 0)
auto_fuel_ship(sp); auto_fuel_ship(sp);
mlp->ship.shp_fuel = sp->shp_fuel; mlp->unit.ship.shp_fuel = sp->shp_fuel;
cp = BestShipPath(buf, sp->shp_x, sp->shp_y, cp = BestShipPath(buf, sp->shp_x, sp->shp_y,
sp->shp_destx[0], sp->shp_desty[0], sp->shp_destx[0], sp->shp_desty[0],

View file

@ -39,8 +39,9 @@
#include <math.h> #include <math.h>
#include "nsc.h" #include "nsc.h"
#include "path.h" #include "path.h"
#include "ship.h"
#include "update.h" #include "update.h"
#include "empobj.h"
#include "unit.h"
static void fltp_to_list(struct fltheadstr *, struct emp_qelem *); static void fltp_to_list(struct fltheadstr *, struct emp_qelem *);
@ -316,15 +317,15 @@ static void
fltp_to_list(struct fltheadstr *fltp, struct emp_qelem *list) fltp_to_list(struct fltheadstr *fltp, struct emp_qelem *list)
{ {
struct fltelemstr *fe; struct fltelemstr *fe;
struct mlist *mlp; struct ulist *mlp;
struct shpstr *sp; struct shpstr *sp;
emp_initque(list); emp_initque(list);
for (fe = fltp->head; fe; fe = fe->next) { for (fe = fltp->head; fe; fe = fe->next) {
mlp = malloc(sizeof(struct mlist)); mlp = malloc(sizeof(struct ulist));
sp = getshipp(fe->num); sp = getshipp(fe->num);
mlp->mcp = mchr + sp->shp_type; mlp->chrp = (struct empobj_chr *)(mchr + sp->shp_type);
mlp->ship = *sp; mlp->unit.ship = *sp;
mlp->mobil = fe->mobil; mlp->mobil = fe->mobil;
emp_insque(&mlp->queue, list); emp_insque(&mlp->queue, list);
} }