(nxtitemp, trade_getitem, trade_desc, trade_check_item_ok, nxtitem,

oprange, show_mission, nameofitem, build_mission_list_type,
unit_map, xdvisible, trdswitchown, ontradingblock, trad, check_trade,
unit_type_name, start_stop_unit, scut, scra, mission, multifire,
perform_mission, fuel, NSC_GENITEM): Replace struct genitem with
struct empobj.  Remove genitem.h and create a new file empobj.h.
Replace multiple instances of unions of ef_type structures with
one standard union empobj_storage which is a superset of the individual
instances.
This commit is contained in:
Ron Koenderink 2006-07-07 15:15:43 +00:00
parent 9e75e5e009
commit 79ee88f7c6
29 changed files with 191 additions and 270 deletions

View file

@ -25,37 +25,63 @@
*
* ---
*
* genitem.h: Definition for generic items
* genobj.h: General empire objects.
*
* Known contributors to this file:
*
*/
/*
* XXX cheap hack; this depends on the fact
* that units are all the same starting from the top.
* If you change the units, DON'T CHANGE the tops to
* be non-identical. Also, if you change types of
* parts of the tops, be sure to change this file!
* Ron Koenderink, 2006
* Markus Armbruster, 2006
*/
#ifndef GENITEM_H
#define GENITEM_H
#ifndef EMPOBJ_H
#define EMPOBJ_H
struct genitem {
short ef_type;
natid own;
#include "commodity.h"
#include "land.h"
#include "loan.h"
#include "lost.h"
#include "plane.h"
#include "nat.h"
#include "news.h"
#include "nuke.h"
#include "sect.h"
#include "ship.h"
#include "trade.h"
#include "treaty.h"
struct empobj {
short ef_type; /* is always valid */
natid own; /* is valid if EFF_OWNER is set in table def. */
short uid;
coord x;
coord y;
coord x; /* is valid if EFF_XY is set in table def. */
coord y; /* is valid if EFF_XY is set in table def. */
signed char type;
signed char effic;
signed char mobil;
unsigned char off;
short tech;
char group;
short tech;
char group; /* is valid if EFF_GROUP is set in table def. */
coord opx, opy;
short mission;
short radius;
};
union empobj_storage {
short ef_type;
struct empobj gen;
struct comstr comm;
struct lndstr land;
struct lonstr loan;
struct loststr lost;
struct natstr nat;
struct nwsstr news;
struct nukstr nuke;
struct plnstr plane;
struct realmstr realm;
struct sctstr sect;
struct shpstr ship;
struct trdstr trade;
struct trtstr treaty;
};
#endif

View file

@ -72,7 +72,7 @@ struct empfile {
/*
* EFF_XY / EFF_OWNER / EFF_GROUP assert that coordinates / owner /
* group of such a table's entries can be safely obtained by
* dereferencing entry address cast to struct genitem *.
* dereferencing entry address cast to struct empobj *.
*/
#define EFF_XY bit(0)
#define EFF_OWNER bit(1)

View file

@ -47,7 +47,7 @@
#define LAND_MINFIREEFF 40 /* arty must be this effic to fire */
struct lndstr {
/* initial part must match struct genitem */
/* initial part must match struct empobj */
short ef_type;
natid lnd_own; /* owner's country num */
short lnd_uid; /* unit id (land unit) */
@ -62,7 +62,7 @@ struct lndstr {
coord lnd_opx, lnd_opy; /* Op sector coords */
short lnd_mission; /* mission code */
short lnd_radius; /* mission radius */
/* end of part matching struct genitem */
/* end of part matching struct empobj */
signed char lnd_flags; /* unit flags (unused) */
short lnd_ship; /* pointer to transporting ship */
signed char lnd_harden; /* fortification */

View file

@ -35,10 +35,10 @@
#define LOST_H
struct loststr {
/* initial part must match struct genitem */
/* initial part must match struct empobj */
short ef_type;
natid lost_owner; /* Who lost it */
/* end of part matching struct genitem */
/* end of part matching struct empobj */
int lost_uid; /* lost ID (assigned, otherwise unused) */
char lost_type; /* Type of thing (ship, plane, nuke, land, sector) */
short lost_id; /* ID of lost thing */

View file

@ -64,10 +64,10 @@ typedef enum {
* If we had working virtual selectors, we could remove r_cnum and r_realm.
*/
struct realmstr {
/* initial part must match struct genitem */
/* initial part must match struct empobj */
short ef_type;
natid r_cnum; /* country number */
/* end of part matching struct genitem */
/* end of part matching struct empobj */
short r_uid; /* realm table index */
unsigned short r_realm; /* realm number */
short r_xl, r_xh; /* horizontal bounds */
@ -76,10 +76,10 @@ struct realmstr {
};
struct natstr {
/* initial part must match struct genitem */
/* initial part must match struct empobj */
short ef_type;
natid nat_cnum; /* our country number */
/* end of part matching struct genitem */
/* end of part matching struct empobj */
nat_status nat_stat;
char nat_cnam[20]; /* country name */
char nat_pnam[20]; /* representative */

View file

@ -38,7 +38,7 @@
#define MIN_DRNUKE_CONST 0.001
struct nukstr {
/* initial part must match struct genitem */
/* initial part must match struct empobj */
short ef_type;
natid nuk_own;
short nuk_uid;
@ -52,7 +52,7 @@ struct nukstr {
coord nuk_opx, nuk_opy; /* Op sector coords, unused */
short nuk_mission; /* mission code, unused */
short nuk_radius; /* mission radius, unused */
/* end of part matching struct genitem */
/* end of part matching struct empobj */
short nuk_ship; /* currently aboard ship (unused) */
short nuk_plane; /* currently aboard plane */
short nuk_land; /* currently aboard land (unused) */

View file

@ -43,7 +43,7 @@
#define PLANE_MINEFF 10
struct plnstr {
/* initial part must match struct genitem */
/* initial part must match struct empobj */
short ef_type;
natid pln_own; /* owning country */
short pln_uid; /* plane unit id */
@ -59,7 +59,7 @@ struct plnstr {
coord pln_opy; /* Op sector coords */
short pln_mission; /* mission code */
short pln_radius; /* mission radius */
/* end of part matching struct genitem */
/* end of part matching struct empobj */
unsigned char pln_range; /* total distance, not radius */
unsigned char pln_range_max; /* max range for this plane */
short pln_ship; /* pointer to carrier */

View file

@ -488,14 +488,14 @@ extern int num_shipsatxy(coord, coord, int, int);
extern int islist(char *);
/* src/lib/subs/mission.c */
extern char *mission_name(short);
extern char *nameofitem(struct genitem *, int);
extern char *nameofitem(struct empobj *, int);
extern int collateral_damage(coord, coord, int, struct emp_qelem *);
extern int mission_pln_equip(struct plist *, struct ichrstr *, int, char);
extern int ground_interdict(coord, coord, natid, char *);
extern int unit_interdict(coord, coord, natid, char *, int, int);
extern int off_support(coord, coord, natid, natid);
extern int def_support(coord, coord, natid, natid);
extern int oprange(struct genitem *, int, int *);
extern int oprange(struct empobj *, int, int *);
extern int cando(int, int);
extern void show_mission(int, struct nstr_item *);
extern int air_defense(coord, coord, natid, struct emp_qelem *,

View file

@ -40,13 +40,13 @@
#include "item.h"
struct sctstr {
/* initial part must match struct genitem */
/* initial part must match struct empobj */
short ef_type;
natid sct_own; /* owner's country num */
short sct_elev; /* elevation/depth */
coord sct_x; /* x coord of sector */
coord sct_y; /* y coord of sector */
/* end of part matching struct genitem */
/* end of part matching struct empobj */
unsigned char sct_type; /* sector type */
unsigned char sct_effic; /* 0% to 100% */
short sct_mobil; /* mobility units */

View file

@ -60,7 +60,7 @@
#define MAXSHPNAMLEN 24
struct shpstr {
/* initial part must match struct genitem */
/* initial part must match struct empobj */
short ef_type;
natid shp_own; /* owner's country num */
short shp_uid; /* unit id (ship #) */
@ -75,7 +75,7 @@ struct shpstr {
coord shp_opx, shp_opy; /* Op sector coords */
short shp_mission; /* mission code */
short shp_radius; /* mission radius */
/* end of part matching struct genitem */
/* end of part matching struct empobj */
unsigned char shp_nplane; /* number of planes on board */
unsigned char shp_nland; /* number of land units on board */
short shp_armor;

View file

@ -47,7 +47,7 @@
#include "ship.h"
#include "queue.h"
#include "xy.h"
#include "genitem.h"
#include "empobj.h"
#include "trade.h"
#include "player.h"
#include "prototypes.h" /* must come at end, after defines and typedefs */

View file

@ -37,12 +37,6 @@
#ifndef TRADE_H
#define TRADE_H
#include "genitem.h"
#include "nuke.h"
#include "plane.h"
#include "land.h"
#include "ship.h"
struct trdstr {
short ef_type;
natid trd_owner;
@ -56,19 +50,11 @@ struct trdstr {
coord trd_y;
};
union trdgenstr {
struct genitem gen;
struct nukstr nuk;
struct plnstr pln;
struct lndstr lnd;
struct shpstr shp;
};
extern int trade_check_ok(struct trdstr *, union trdgenstr *);
extern int trade_check_item_ok(union trdgenstr *);
extern char *trade_nameof(struct trdstr *, union trdgenstr *);
extern int trade_desc(struct trdstr *, union trdgenstr *);
extern int trade_getitem(struct trdstr *, union trdgenstr *);
extern int trade_check_ok(struct trdstr *, union empobj_storage *);
extern int trade_check_item_ok(union empobj_storage *);
extern char *trade_nameof(struct trdstr *, union empobj_storage *);
extern int trade_desc(struct trdstr *, union empobj_storage *);
extern int trade_getitem(struct trdstr *, union empobj_storage *);
#define gettrade(n, p) ef_read(EF_TRADE, (n), (p))
#define puttrade(n, p) ef_write(EF_TRADE, (n), (p))

View file

@ -37,28 +37,18 @@
#include "player.h"
#include "plague.h"
#include "xy.h"
#include "ship.h"
#include "plane.h"
#include "land.h"
#include "nat.h"
#include "nsc.h"
#include "file.h"
#include "sect.h"
#include "optlist.h"
#include "commands.h"
union item_u {
struct shpstr ship;
struct lndstr land;
};
#include "empobj.h"
int
fuel(void)
{
static int shp_or_lnd[] = { EF_SHIP, EF_LAND, EF_BAD };
struct nstr_item ni;
union item_u item, item2;
union empobj_storage item, item2;
int type;
struct mchrstr *mp;
struct lchrstr *lcp;

View file

@ -321,7 +321,7 @@ lload(void)
void
gift(natid givee, natid giver, void *ptr, int type, char *mesg)
{
struct genitem *gen = ptr;
struct empobj *gen = ptr;
char *p;
if (giver != givee) {

View file

@ -36,13 +36,7 @@
#include "misc.h"
#include "player.h"
#include "xy.h"
#include "treaty.h"
#include "nat.h"
#include "ship.h"
#include "land.h"
#include "sect.h"
#include "retreat.h"
#include "news.h"
#include "nsc.h"
#include "file.h"
#include "queue.h"
@ -50,6 +44,7 @@
#include "optlist.h"
#include "damage.h"
#include "commands.h"
#include "empobj.h"
enum targ_type {
targ_land, targ_ship, targ_sub, targ_unit, targ_bogus
@ -64,12 +59,6 @@ struct flist {
int victim; /* who I was shooting at */
};
union item_u {
struct shpstr ship;
struct sctstr sect;
struct lndstr land;
};
static void add_to_fired_queue(struct emp_qelem *, struct emp_qelem *);
static int defend(struct emp_qelem *al,
struct emp_qelem *dl,
@ -120,7 +109,7 @@ multifire(void)
char *p;
int nfiring = 0;
int ndefending = 0;
union item_u item;
union empobj_storage item;
struct emp_qelem fired, defended;
double odds;
char buf[1024];

View file

@ -37,24 +37,13 @@
#include "misc.h"
#include "player.h"
#include "xy.h"
#include "sect.h"
#include "ship.h"
#include "land.h"
#include "plane.h"
#include "nat.h"
#include "nsc.h"
#include "file.h"
#include "path.h"
#include "mission.h"
#include "genitem.h"
#include "commands.h"
#include "optlist.h"
union item_u {
struct shpstr ship;
struct plnstr plane;
struct lndstr land;
};
#include "empobj.h"
/*
* mission <type> <planes/ships/units> <mission type> <op sector> [<radius>]
@ -69,8 +58,8 @@ mission(void)
coord x, y;
int desired_radius, radius;
struct sctstr opsect;
union item_u item;
struct genitem *gp;
union empobj_storage item;
struct empobj *gp;
int num = 0, mobmax, mobused, dist;
struct nstr_item ni;
char prompt[128];
@ -212,7 +201,7 @@ mission(void)
mobused = ldround(mission_mob_cost * (double)mobmax, 1);
while (nxtitem(&ni, &item)) {
gp = (struct genitem *)&item;
gp = (struct empobj *)&item;
if (!player->owner || gp->own == 0)
continue;

View file

@ -36,27 +36,17 @@
#include "misc.h"
#include "player.h"
#include "xy.h"
#include "sect.h"
#include "ship.h"
#include "plane.h"
#include "land.h"
#include "nat.h"
#include "nsc.h"
#include "file.h"
#include "commands.h"
#include "optlist.h"
union item_u {
struct shpstr ship;
struct plnstr plane;
struct lndstr land;
};
#include "empobj.h"
int
scra(void)
{
struct nstr_item ni;
union item_u item;
union empobj_storage item;
int type;
struct sctstr sect;
struct mchrstr *mp;

View file

@ -35,31 +35,20 @@
#include "misc.h"
#include "player.h"
#include "sect.h"
#include "news.h"
#include "xy.h"
#include "ship.h"
#include "land.h"
#include "plane.h"
#include "nat.h"
#include "nsc.h"
#include "file.h"
#include "commands.h"
#include "optlist.h"
#include "empobj.h"
static void scuttle_land(struct lndstr *);
union item_u {
struct shpstr ship;
struct plnstr plane;
struct lndstr land;
};
int
scut(void)
{
struct nstr_item ni;
union item_u item;
union empobj_storage item;
int type;
struct mchrstr *mp;
char *p;

View file

@ -63,7 +63,7 @@ set(void)
struct trdstr trade;
struct nstr_item ni;
struct nstr_item ni_trade;
union trdgenstr item;
union empobj_storage item;
struct sctstr sect;
int freeslot;
int foundslot;

View file

@ -38,20 +38,10 @@
#include "misc.h"
#include "player.h"
#include "xy.h"
#include "sect.h"
#include "nsc.h"
#include "nat.h"
#include "path.h"
#include "file.h"
#include "commands.h"
union item_u {
struct genitem gen;
struct shpstr ship;
struct plnstr plane;
struct lndstr land;
struct nukstr nuke;
};
#include "empobj.h"
static int start_stop(int);
static int start_stop_sector(char *, int);
@ -59,7 +49,7 @@ static void start_stop_hdr(int);
static void proff(int);
static int start_stop_unit(int, char *, int);
static void start_stop_unit_hdr(int);
static char *unit_type_name(union item_u *);
static char *unit_type_name(union empobj_storage *);
int
start(void)
@ -167,7 +157,7 @@ proff(int off)
static int
start_stop_unit(int type, char *arg, int off)
{
union item_u unit;
union empobj_storage unit;
int nunit;
struct nstr_item nstr;
@ -211,7 +201,7 @@ start_stop_unit_hdr(int off)
}
static char *
unit_type_name(union item_u *unit)
unit_type_name(union empobj_storage *unit)
{
int type = unit->gen.type;

View file

@ -47,7 +47,6 @@
#include "nat.h"
#include "land.h"
#include "plane.h"
#include "genitem.h"
#include "commands.h"
static void expose_ship(struct shpstr *s1, struct shpstr *s2);

View file

@ -71,7 +71,7 @@ trad(void)
struct nstr_item ni;
struct trdstr trade;
struct trdstr tmpt;
union trdgenstr tg;
union empobj_storage tg;
int plflags;
double canspend;
time_t now;
@ -193,8 +193,8 @@ trad(void)
*/
if (((trade.trd_type == EF_PLANE) || (trade.trd_type == EF_NUKE))
&& ((trade.trd_type == EF_NUKE) ||
!(tg.pln.pln_flags & PLN_LAUNCHED))) {
plflags = plchr[(int)tg.pln.pln_type].pl_flags;
!(tg.plane.pln_flags & PLN_LAUNCHED))) {
plflags = plchr[(int)tg.plane.pln_type].pl_flags;
while (1) {
p = getstring("Destination sector: ", buf);
if (!trade_check_ok(&trade, &tg))
@ -292,7 +292,7 @@ check_trade(void)
struct lndstr land;
struct natstr *natp;
struct trdstr trade;
union trdgenstr tg;
union empobj_storage tg;
time_t now;
double subleft;
double monleft;
@ -380,68 +380,68 @@ check_trade(void)
putnat(natp);
switch (trade.trd_type) {
case EF_NUKE:
tg.nuk.nuk_x = trade.trd_x;
tg.nuk.nuk_y = trade.trd_y;
makelost(EF_NUKE, tg.nuk.nuk_own, tg.nuk.nuk_uid,
tg.nuk.nuk_x, tg.nuk.nuk_y);
tg.nuk.nuk_own = trade.trd_maxbidder;
makenotlost(EF_NUKE, tg.nuk.nuk_own, tg.nuk.nuk_uid,
tg.nuk.nuk_x, tg.nuk.nuk_y);
tg.nuke.nuk_x = trade.trd_x;
tg.nuke.nuk_y = trade.trd_y;
makelost(EF_NUKE, tg.nuke.nuk_own, tg.nuke.nuk_uid,
tg.nuke.nuk_x, tg.nuke.nuk_y);
tg.nuke.nuk_own = trade.trd_maxbidder;
makenotlost(EF_NUKE, tg.nuke.nuk_own, tg.nuke.nuk_uid,
tg.nuke.nuk_x, tg.nuke.nuk_y);
break;
case EF_PLANE:
if ((tg.pln.pln_flags & PLN_LAUNCHED) == 0) {
tg.pln.pln_x = trade.trd_x;
tg.pln.pln_y = trade.trd_y;
if ((tg.plane.pln_flags & PLN_LAUNCHED) == 0) {
tg.plane.pln_x = trade.trd_x;
tg.plane.pln_y = trade.trd_y;
}
makelost(EF_PLANE, tg.pln.pln_own, tg.pln.pln_uid,
tg.pln.pln_x, tg.pln.pln_y);
tg.pln.pln_own = trade.trd_maxbidder;
makenotlost(EF_PLANE, tg.pln.pln_own, tg.pln.pln_uid,
tg.pln.pln_x, tg.pln.pln_y);
tg.pln.pln_wing = 0;
makelost(EF_PLANE, tg.plane.pln_own, tg.plane.pln_uid,
tg.plane.pln_x, tg.plane.pln_y);
tg.plane.pln_own = trade.trd_maxbidder;
makenotlost(EF_PLANE, tg.plane.pln_own, tg.plane.pln_uid,
tg.plane.pln_x, tg.plane.pln_y);
tg.plane.pln_wing = 0;
/* no cheap version of fly */
if (opt_MOB_ACCESS) {
tg.pln.pln_mobil = -(etu_per_update / sect_mob_neg_factor);
tg.plane.pln_mobil = -(etu_per_update / sect_mob_neg_factor);
} else {
tg.pln.pln_mobil = 0;
tg.plane.pln_mobil = 0;
}
tg.pln.pln_mission = 0;
tg.pln.pln_harden = 0;
time(&tg.pln.pln_access);
tg.pln.pln_ship = -1;
tg.pln.pln_land = -1;
tg.plane.pln_mission = 0;
tg.plane.pln_harden = 0;
time(&tg.plane.pln_access);
tg.plane.pln_ship = -1;
tg.plane.pln_land = -1;
break;
case EF_SHIP:
takeover_ship(&tg.shp, trade.trd_maxbidder, 0);
takeover_ship(&tg.ship, trade.trd_maxbidder, 0);
break;
case EF_LAND:
tg.lnd.lnd_x = trade.trd_x;
tg.lnd.lnd_y = trade.trd_y;
if (tg.lnd.lnd_ship >= 0) {
tg.land.lnd_x = trade.trd_x;
tg.land.lnd_y = trade.trd_y;
if (tg.land.lnd_ship >= 0) {
struct shpstr ship;
getship(tg.lnd.lnd_ship, &ship);
getship(tg.land.lnd_ship, &ship);
ship.shp_nland--;
putship(ship.shp_uid, &ship);
}
makelost(EF_LAND, tg.lnd.lnd_own, tg.lnd.lnd_uid,
tg.lnd.lnd_x, tg.lnd.lnd_y);
tg.lnd.lnd_own = trade.trd_maxbidder;
makenotlost(EF_LAND, tg.lnd.lnd_own, tg.lnd.lnd_uid,
tg.lnd.lnd_x, tg.lnd.lnd_y);
tg.lnd.lnd_army = 0;
makelost(EF_LAND, tg.land.lnd_own, tg.land.lnd_uid,
tg.land.lnd_x, tg.land.lnd_y);
tg.land.lnd_own = trade.trd_maxbidder;
makenotlost(EF_LAND, tg.land.lnd_own, tg.land.lnd_uid,
tg.land.lnd_x, tg.land.lnd_y);
tg.land.lnd_army = 0;
/* no cheap version of fly */
if (opt_MOB_ACCESS) {
tg.lnd.lnd_mobil = -(etu_per_update / sect_mob_neg_factor);
tg.land.lnd_mobil = -(etu_per_update / sect_mob_neg_factor);
} else {
tg.lnd.lnd_mobil = 0;
tg.land.lnd_mobil = 0;
}
tg.lnd.lnd_harden = 0;
time(&tg.lnd.lnd_access);
tg.lnd.lnd_mission = 0;
tg.land.lnd_harden = 0;
time(&tg.land.lnd_access);
tg.land.lnd_mission = 0;
/* Drop any land units this unit was carrying */
snxtitem_xy(&ni, EF_LAND, tg.lnd.lnd_x, tg.lnd.lnd_y);
snxtitem_xy(&ni, EF_LAND, tg.land.lnd_x, tg.land.lnd_y);
while (nxtitem(&ni, &land)) {
if (land.lnd_land != tg.lnd.lnd_uid)
if (land.lnd_land != tg.land.lnd_uid)
continue;
land.lnd_land = -1;
wu(0, land.lnd_own, "unit #%d dropped in %s\n",
@ -450,7 +450,7 @@ check_trade(void)
putland(land.lnd_uid, &land);
}
/* Drop any planes this unit was carrying */
snxtitem_xy(&ni, EF_PLANE, tg.lnd.lnd_x, tg.lnd.lnd_y);
snxtitem_xy(&ni, EF_PLANE, tg.land.lnd_x, tg.land.lnd_y);
while (nxtitem(&ni, &plane)) {
if (plane.pln_flags & PLN_LAUNCHED)
continue;
@ -462,8 +462,8 @@ check_trade(void)
xyas(plane.pln_x, plane.pln_y, plane.pln_own));
putplane(plane.pln_uid, &plane);
}
tg.lnd.lnd_ship = -1;
tg.lnd.lnd_land = -1;
tg.land.lnd_ship = -1;
tg.land.lnd_land = -1;
break;
default:
logerror("Bad trade type %d in trade\n", trade.trd_type);
@ -490,7 +490,7 @@ int
ontradingblock(int type, void *ptr)
{
struct trdstr trade;
union trdgenstr tg;
union empobj_storage tg;
int n;
for (n = 0; gettrade(n, &trade); n++) {
@ -500,7 +500,7 @@ ontradingblock(int type, void *ptr)
continue;
if (trade.trd_type != type)
continue;
if (tg.gen.uid == ((struct genitem *)ptr)->uid)
if (tg.gen.uid == ((struct empobj *)ptr)->uid)
return 1;
}
return 0;
@ -510,7 +510,7 @@ void
trdswitchown(int type, void *ptr, int newown)
{
struct trdstr trade;
union trdgenstr tg;
union empobj_storage tg;
int n;
for (n = 0; gettrade(n, &trade); n++) {
@ -520,7 +520,7 @@ trdswitchown(int type, void *ptr, int newown)
continue;
if (trade.trd_type != type)
continue;
if (tg.gen.uid != ((struct genitem *)ptr)->uid)
if (tg.gen.uid != ((struct empobj *)ptr)->uid)
continue;
if (trade.trd_owner == trade.trd_maxbidder)
trade.trd_maxbidder = newown;

View file

@ -197,7 +197,7 @@ xdftr(int n)
static int
xdvisible(int type, void *p)
{
struct genitem *gp = p;
struct empobj *gp = p;
struct trtstr *tp = p;
struct lonstr *lp = p;
struct natstr *natp;

View file

@ -322,28 +322,28 @@ unit_map(int unit_type, int uid, struct nstr_sect *nsp, char *originp)
struct lndstr origl;
struct plnstr origp;
struct nukstr orign;
struct genitem *gp;
struct empobj *gp;
struct range range;
if (unit_type == EF_LAND) {
if (!getland(uid, &origl) || !player->owner || origl.lnd_own == 0)
return RET_FAIL;
gp = (struct genitem *)&origl;
gp = (struct empobj *)&origl;
*originp = *lchr[(int)origl.lnd_type].l_name;
} else if (unit_type == EF_PLANE) {
if (!getplane(uid, &origp) || !player->owner || origp.pln_own == 0)
return RET_FAIL;
gp = (struct genitem *)&origp;
gp = (struct empobj *)&origp;
*originp = *plchr[(int)origp.pln_type].pl_name;
} else if (unit_type == EF_NUKE) {
if (!getnuke(uid, &orign) || !player->owner || orign.nuk_own == 0)
return RET_FAIL;
gp = (struct genitem *)&orign;
gp = (struct empobj *)&orign;
*originp = 'n';
} else {
if (!getship(uid, &origs) || !player->owner || origs.shp_own == 0)
return RET_FAIL;
gp = (struct genitem *)&origs;
gp = (struct empobj *)&origs;
*originp = *mchr[(int)origs.shp_type].m_name;
}

View file

@ -41,21 +41,8 @@
#include <stddef.h>
#include "misc.h"
#include "xy.h"
#include "loan.h"
#include "nsc.h"
#include "news.h"
#include "nuke.h"
#include "plane.h"
#include "ship.h"
#include "land.h"
#include "sect.h"
#include "trade.h"
#include "treaty.h"
#include "genitem.h"
#include "nat.h"
#include "map.h"
#include "commodity.h"
#include "lost.h"
#include "empobj.h"
#include "product.h"
#include "file.h"
@ -191,20 +178,20 @@ struct castr dchr_ca[] = {
};
#define NSC_GENITEM(ef_type, ef_chr) \
{ NSC_SHORT, 0, 0, fldoff(genitem, uid), "uid", ef_type}, \
{ NSC_NATID, 0, 0, fldoff(genitem, own), "owner", EF_NATION}, \
{ NSC_XCOORD, 0, 0, fldoff(genitem, x), "xloc", EF_BAD}, \
{ NSC_YCOORD, 0, 0, fldoff(genitem, y), "yloc", EF_BAD}, \
{ NSC_CHAR, 0, 0, fldoff(genitem, type), "type", ef_chr}, \
{ NSC_CHAR, 0, 0, fldoff(genitem, effic), "effic", EF_BAD}, \
{ NSC_CHAR , 0, 0, fldoff(genitem, mobil), "mobil", EF_BAD}, \
{ NSC_UCHAR , 0, 0, fldoff(genitem, off), "off", EF_BAD}, \
{ NSC_SHORT, 0, 0, fldoff(genitem, tech), "tech", EF_BAD}, \
{ NSC_STRINGY, NSC_EXTRA, 1, fldoff(genitem, group), "group", EF_BAD}, \
{ NSC_XCOORD, 0, 0, fldoff(genitem, opx), "opx", EF_BAD}, \
{ NSC_YCOORD, 0, 0, fldoff(genitem, opy), "opy", EF_BAD}, \
{ NSC_SHORT, 0, 0, fldoff(genitem, mission), "mission", EF_MISSIONS}, \
{ NSC_SHORT, 0, 0, fldoff(genitem, radius), "radius", EF_BAD}
{ NSC_SHORT, 0, 0, fldoff(empobj, uid), "uid", ef_type}, \
{ NSC_NATID, 0, 0, fldoff(empobj, own), "owner", EF_NATION}, \
{ NSC_XCOORD, 0, 0, fldoff(empobj, x), "xloc", EF_BAD}, \
{ NSC_YCOORD, 0, 0, fldoff(empobj, y), "yloc", EF_BAD}, \
{ NSC_CHAR, 0, 0, fldoff(empobj, type), "type", ef_chr}, \
{ NSC_CHAR, 0, 0, fldoff(empobj, effic), "effic", EF_BAD}, \
{ NSC_CHAR , 0, 0, fldoff(empobj, mobil), "mobil", EF_BAD}, \
{ NSC_UCHAR , 0, 0, fldoff(empobj, off), "off", EF_BAD}, \
{ NSC_SHORT, 0, 0, fldoff(empobj, tech), "tech", EF_BAD}, \
{ NSC_STRINGY, NSC_EXTRA, 1, fldoff(empobj, group), "group", EF_BAD}, \
{ NSC_XCOORD, 0, 0, fldoff(empobj, opx), "opx", EF_BAD}, \
{ NSC_YCOORD, 0, 0, fldoff(empobj, opy), "opy", EF_BAD}, \
{ NSC_SHORT, 0, 0, fldoff(empobj, mission), "mission", EF_MISSIONS}, \
{ NSC_SHORT, 0, 0, fldoff(empobj, radius), "radius", EF_BAD}
struct castr ship_ca[] = {
NSC_GENITEM(EF_SHIP, EF_SHIP_CHR),

View file

@ -37,23 +37,17 @@
#include "misc.h"
#include "player.h"
#include "xy.h"
#include "sect.h"
#include "ship.h"
#include "land.h"
#include "plane.h"
#include "nat.h"
#include "nsc.h"
#include "file.h"
#include "path.h"
#include "mission.h"
#include "genitem.h"
#include "news.h"
#include "item.h"
#include <fcntl.h>
#include "damage.h"
#include "queue.h"
#include "prototypes.h"
#include "optlist.h"
#include "empobj.h"
struct genlist {
struct emp_qelem queue; /* list of units */
@ -68,12 +62,6 @@ struct airport {
natid own;
};
union item_u {
struct shpstr ship;
struct plnstr plane;
struct lndstr land;
};
static void add_airport(struct emp_qelem *, coord, coord);
static int air_damage(struct emp_qelem *, coord, coord, int, natid,
char *, int);
@ -301,8 +289,8 @@ build_mission_list_type(struct genlist *mi, coord x, coord y, int mission,
{
struct nstr_item ni;
struct genlist *glp;
struct genitem *gp;
union item_u item;
struct empobj *gp;
union empobj_storage item;
int dist;
int radius;
int relat;
@ -310,7 +298,7 @@ build_mission_list_type(struct genlist *mi, coord x, coord y, int mission,
snxtitem_all(&ni, type);
while (nxtitem(&ni, &item)) {
gp = (struct genitem *)&item;
gp = (struct empobj *)&item;
if (gp->own == 0)
continue;
@ -427,7 +415,7 @@ perform_mission(coord x, coord y, natid victim, struct emp_qelem *list,
struct emp_qelem *newqp;
struct genlist *glp;
struct plist *plp;
struct genitem *gp;
struct empobj *gp;
struct lndstr *lp;
struct shpstr *sp;
struct sctstr sect;
@ -817,7 +805,7 @@ cando(int mission, int type)
}
char *
nameofitem(struct genitem *gp, int type)
nameofitem(struct empobj *gp, int type)
{
switch (type) {
case EF_SHIP:
@ -858,11 +846,11 @@ void
show_mission(int type, struct nstr_item *np)
{
int first = 1, radius;
union item_u item;
struct genitem *gp;
union empobj_storage item;
struct empobj *gp;
while (nxtitem(np, &item)) {
gp = (struct genitem *)&item;
gp = (struct empobj *)&item;
if (!player->owner || gp->own == 0)
continue;
@ -909,7 +897,7 @@ show_mission(int type, struct nstr_item *np)
}
int
oprange(struct genitem *gp, int type, int *radius)
oprange(struct empobj *gp, int type, int *radius)
{
int range;
struct shpstr ship;
@ -1462,7 +1450,7 @@ air_defense(coord x, coord y, natid victim, struct emp_qelem *bomb_list,
struct emp_qelem *qp, interceptors, airp, i, empty, *next;
struct plist *plp;
struct genlist *glp;
struct genitem *gp;
struct empobj *gp;
struct genlist mi[MAXNOC];
char buf[512];
char *path;

View file

@ -40,18 +40,17 @@
#include "land.h"
#include "nsc.h"
#include "file.h"
#include "genitem.h"
#include "prototypes.h"
int
nxtitem(struct nstr_item *np, void *ptr)
{
struct genitem *gp;
struct empobj *gp;
int selected;
if (np->sel == NS_UNDEF)
return 0;
gp = (struct genitem *)ptr;
gp = (struct empobj *)ptr;
do {
if (np->sel == NS_LIST) {
np->index++;

View file

@ -53,39 +53,39 @@
#include "optlist.h"
int
trade_check_ok(struct trdstr *tp, union trdgenstr *tgp)
trade_check_ok(struct trdstr *tp, union empobj_storage *tgp)
{
return check_trade_ok(tp) && trade_check_item_ok(tgp);
}
int
trade_check_item_ok(union trdgenstr *tgp)
trade_check_item_ok(union empobj_storage *tgp)
{
if (tgp->gen.ef_type == EF_LAND)
return check_land_ok(&tgp->lnd);
return check_land_ok(&tgp->land);
if (tgp->gen.ef_type == EF_PLANE)
return check_plane_ok(&tgp->pln);
return check_plane_ok(&tgp->plane);
if (tgp->gen.ef_type == EF_SHIP)
return check_ship_ok(&tgp->shp);
return check_ship_ok(&tgp->ship);
if (tgp->gen.ef_type == EF_NUKE)
return check_nuke_ok(&tgp->nuk);
return check_nuke_ok(&tgp->nuke);
CANT_REACH();
pr("Trade lot went bad!\n");
return 0;
}
char *
trade_nameof(struct trdstr *tp, union trdgenstr *tgp)
trade_nameof(struct trdstr *tp, union empobj_storage *tgp)
{
switch (tp->trd_type) {
case EF_NUKE:
return nchr[(int)tgp->nuk.nuk_type].n_name;
return nchr[(int)tgp->nuke.nuk_type].n_name;
case EF_PLANE:
return plchr[(int)tgp->pln.pln_type].pl_name;
return plchr[(int)tgp->plane.pln_type].pl_name;
case EF_SHIP:
return mchr[(int)tgp->shp.shp_type].m_name;
return mchr[(int)tgp->ship.shp_type].m_name;
case EF_LAND:
return lchr[(int)tgp->lnd.lnd_type].l_name;
return lchr[(int)tgp->land.lnd_type].l_name;
}
return "Bad trade type, get help";
}
@ -96,7 +96,7 @@ trade_nameof(struct trdstr *tp, union trdgenstr *tgp)
* Return 1 on success, 0 on error
*/
int
trade_desc(struct trdstr *tp, union trdgenstr *tgp)
trade_desc(struct trdstr *tp, union empobj_storage *tgp)
{
i_type it;
struct sctstr sect;
@ -110,14 +110,14 @@ trade_desc(struct trdstr *tp, union trdgenstr *tgp)
switch (tp->trd_type) {
case EF_NUKE:
np = &tgp->nuk;
np = &tgp->nuke;
tp->trd_owner = np->nuk_own;
pr("(%3d) tech %d %d%% %s #%d",
tp->trd_owner, np->nuk_tech, np->nuk_effic,
nchr[(int)np->nuk_type].n_name, tp->trd_unitid);
break;
case EF_SHIP:
sp = &tgp->shp;
sp = &tgp->ship;
tp->trd_owner = sp->shp_own;
pr("(%3d) tech %d %d%% %s [",
tp->trd_owner, sp->shp_tech, sp->shp_effic, prship(sp));
@ -174,7 +174,7 @@ trade_desc(struct trdstr *tp, union trdgenstr *tgp)
pr(" at sea");
break;
case EF_LAND:
lp = &tgp->lnd;
lp = &tgp->land;
tp->trd_owner = lp->lnd_own;
pr("(%3d) tech %d %d%% %s [",
tp->trd_owner,
@ -201,7 +201,7 @@ trade_desc(struct trdstr *tp, union trdgenstr *tgp)
getsect(lp->lnd_x, lp->lnd_y, &sect);
break;
case EF_PLANE:
pp = &tgp->pln;
pp = &tgp->plane;
tp->trd_owner = pp->pln_own;
pr("(%3d) tech %d %d%% %s #%d",
tp->trd_owner,
@ -220,7 +220,7 @@ trade_desc(struct trdstr *tp, union trdgenstr *tgp)
}
int
trade_getitem(struct trdstr *tp, union trdgenstr *tgp)
trade_getitem(struct trdstr *tp, union empobj_storage *tgp)
{
if (!ef_read(tp->trd_type, tp->trd_unitid, tgp))
return 0;

View file

@ -39,7 +39,6 @@
#include "land.h"
#include "nsc.h"
#include "file.h"
#include "genitem.h"
#include "player.h"
#include "update.h"
#include "gen.h"
@ -48,7 +47,7 @@
void *
nxtitemp(struct nstr_item *np)
{
struct genitem *gp;
struct empobj *gp;
int selected;
if (np->sel == NS_UNDEF)