(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))