From: Markus Armbruster Date: Wed, 30 Dec 2009 13:07:51 +0000 (+0100) Subject: Store uids as int to support more sectors and units X-Git-Tag: v4.3.24~44 X-Git-Url: http://git.pond.sub.org/?p=empserver;a=commitdiff_plain;h=ba2044be189f10349f4dba1bbe80c35ba0e81bae Store uids as int to support more sectors and units Before, they were stored as short. Wider uids use more space, but the next commit will recover it by narrowing other members. The use of short has always limited the number of ships, planes, land units and nukes to SHRT_MAX (commonly 32768). Only the most extreme games ever came close. Commit 49780e2c (v4.3.12) added struct sctstr member sct_uid to make struct empobj member uid work for sectors. This made the limit apply to sectors as well. We've had games with more than 32768 sectors. --- diff --git a/include/commodity.h b/include/commodity.h index e35457851..a36d9b45d 100644 --- a/include/commodity.h +++ b/include/commodity.h @@ -43,7 +43,7 @@ struct comstr { /* initial part must match struct empobj */ short ef_type; - short com_uid; + int com_uid; unsigned com_seqno; time_t com_timestamp; natid com_owner; diff --git a/include/empobj.h b/include/empobj.h index 373ec0212..5ff65486f 100644 --- a/include/empobj.h +++ b/include/empobj.h @@ -56,7 +56,7 @@ struct empobj { * valid if EFF_TYPED is set in table's flags */ short ef_type; - short uid; + int uid; unsigned seqno; time_t timestamp; /* end of part matching struct emptypedstr */ diff --git a/include/file.h b/include/file.h index 9aa6f3892..e0a56cadb 100644 --- a/include/file.h +++ b/include/file.h @@ -86,7 +86,7 @@ struct empfile { struct emptypedstr { short ef_type; - short uid; + int uid; unsigned seqno; time_t timestamp; }; diff --git a/include/game.h b/include/game.h index 9f77dc0ff..a465d2ae1 100644 --- a/include/game.h +++ b/include/game.h @@ -39,7 +39,7 @@ struct gamestr { /* initial part must match struct empobj */ short ef_type; - short game_uid; + int game_uid; unsigned game_seqno; time_t game_timestamp; /* end of part matching struct empobj */ diff --git a/include/land.h b/include/land.h index 2da78f6bd..91d9f01c3 100644 --- a/include/land.h +++ b/include/land.h @@ -50,7 +50,7 @@ struct lndstr { /* initial part must match struct empobj */ short ef_type; - short lnd_uid; /* unit id (land unit) */ + int lnd_uid; /* unit id (land #) */ unsigned lnd_seqno; time_t lnd_timestamp; /* Last time this unit was touched */ natid lnd_own; /* owner's country num */ @@ -66,7 +66,7 @@ struct lndstr { short lnd_mission; /* mission code */ short lnd_radius; /* mission radius */ /* end of part matching struct empobj */ - short lnd_ship; /* pointer to transporting ship */ + int lnd_ship; /* uid of transporting ship, or -1 */ signed char lnd_harden; /* fortification */ short lnd_retreat; /* retreat percentage */ int lnd_rflags; /* When do I retreat? */ @@ -75,7 +75,7 @@ struct lndstr { short lnd_item[I_MAX+1]; /* amount of items on board */ short lnd_pstage; /* plague stage */ short lnd_ptime; /* how many etus remain in this stage */ - short lnd_land; /* pointer to transporting unit */ + int lnd_land; /* uid of transporting land unit, or -1 */ short lnd_access; /* Last tick mob was updated (MOB_ACCESS) */ }; diff --git a/include/loan.h b/include/loan.h index f0a8416ad..1015acb4b 100644 --- a/include/loan.h +++ b/include/loan.h @@ -43,7 +43,7 @@ struct lonstr { /* initial part must match struct empobj */ short ef_type; - short l_uid; + int l_uid; unsigned l_seqno; time_t l_timestamp; /* end of part matching struct empobj */ diff --git a/include/lost.h b/include/lost.h index 1f81eb78d..63e68d8c5 100644 --- a/include/lost.h +++ b/include/lost.h @@ -40,13 +40,13 @@ struct loststr { /* initial part must match struct empobj */ short ef_type; - short lost_uid; + int lost_uid; unsigned lost_seqno; time_t lost_timestamp; /* When it was lost */ natid lost_owner; /* Who lost it */ /* end of part matching struct empobj */ short lost_type; /* Type of thing (ship, plane, nuke, land, sector) */ - short lost_id; /* ID of lost thing */ + int lost_id; /* uid of lost thing (0 for sector)*/ coord lost_x; coord lost_y; }; diff --git a/include/nat.h b/include/nat.h index 5749a1bd0..ce1390151 100644 --- a/include/nat.h +++ b/include/nat.h @@ -71,7 +71,7 @@ enum nat_status { struct realmstr { /* initial part must match struct empobj */ short ef_type; - short r_uid; /* realm table index */ + int r_uid; /* realm table index */ unsigned r_seqno; time_t r_timestamp; /* Last time this realm was touched */ natid r_cnum; /* country number */ @@ -84,7 +84,7 @@ struct realmstr { struct natstr { /* initial part must match struct empobj */ short ef_type; - short nat_uid; /* equals nat_cnum */ + int nat_uid; /* equals nat_cnum */ unsigned nat_seqno; time_t nat_timestamp; natid nat_cnum; /* our country number */ diff --git a/include/nsc.h b/include/nsc.h index 1ff8271c7..980d716db 100644 --- a/include/nsc.h +++ b/include/nsc.h @@ -172,7 +172,7 @@ struct nstr_item { int dist; /* NS_DIST: distance selector */ coord cx, cy; /* NS_DIST: center x-y, NS_XY: xy */ char group; /* NS_GROUP: fleet/wing match */ - short next; /* NS_CARGO: next item */ + int next; /* NS_CARGO: next item */ int size; /* NS_LIST: size of list */ int index; /* NS_LIST: index */ int list[NS_LSIZE]; /* NS_LIST: item list */ diff --git a/include/nuke.h b/include/nuke.h index ccefbe233..d24a83edc 100644 --- a/include/nuke.h +++ b/include/nuke.h @@ -43,7 +43,7 @@ struct nukstr { /* initial part must match struct empobj */ short ef_type; - short nuk_uid; + int nuk_uid; /* unit id (nuke #) */ unsigned nuk_seqno; time_t nuk_timestamp; /* Last time this nuke was touched */ natid nuk_own; @@ -58,7 +58,7 @@ struct nukstr { short nuk_mission; /* mission code, unused */ short nuk_radius; /* mission radius, unused */ /* end of part matching struct empobj */ - short nuk_plane; /* currently aboard plane */ + int nuk_plane; /* uid of transporting plane, or -1 */ }; struct nchrstr { diff --git a/include/plane.h b/include/plane.h index 0079367c3..fa3a3f5db 100644 --- a/include/plane.h +++ b/include/plane.h @@ -47,7 +47,7 @@ struct plnstr { /* initial part must match struct empobj */ short ef_type; - short pln_uid; /* plane unit id */ + int pln_uid; /* unit id (plane #) */ unsigned pln_seqno; time_t pln_timestamp; /* Last time this plane was touched */ natid pln_own; /* owning country */ @@ -65,8 +65,8 @@ struct plnstr { short pln_radius; /* mission radius */ /* end of part matching struct empobj */ unsigned char pln_range; /* total distance, not radius */ - short pln_ship; /* pointer to carrier */ - short pln_land; /* pointer to carrier */ + int pln_ship; /* uid of carrier, or -1 */ + int pln_land; /* uid of transporting land unit, or -1 */ signed char pln_harden; /* for missiles */ signed char pln_flags; /* State of the plane */ short pln_access; /* Last tick mob was updated (MOB_ACCESS) */ @@ -136,7 +136,7 @@ struct plist { extern struct plchrstr plchr[PLN_TYPE_MAX + 2]; struct shiplist { - short uid; + int uid; struct shiplist *next; }; diff --git a/include/sect.h b/include/sect.h index 7c5f8673c..01fda989d 100644 --- a/include/sect.h +++ b/include/sect.h @@ -45,7 +45,7 @@ struct sctstr { /* initial part must match struct empobj */ short ef_type; - short sct_uid; /* equals XYOFFSET(sct_x, sct_y) */ + int sct_uid; /* equals XYOFFSET(sct_x, sct_y) */ unsigned sct_seqno; time_t sct_timestamp; /* Last time this sector was written to */ natid sct_own; /* owner's country num */ diff --git a/include/ship.h b/include/ship.h index bc92699d4..a0b325d38 100644 --- a/include/ship.h +++ b/include/ship.h @@ -64,7 +64,7 @@ struct shpstr { /* initial part must match struct empobj */ short ef_type; - short shp_uid; /* unit id (ship #) */ + int shp_uid; /* unit it (ship #) */ unsigned shp_seqno; time_t shp_timestamp; /* Last time this ship was touched. */ natid shp_own; /* owner's country num */ @@ -93,7 +93,7 @@ struct shpstr { short shp_access; /* Last tick mob was updated (MOB_ACCESS) */ unsigned char shp_mobquota; /* mobility quota */ char shp_path[MAXSHPPATH]; - short shp_follow; + int shp_follow; char shp_name[MAXSHPNAMLEN]; /* name set with the "name" command */ coord shp_orig_x; coord shp_orig_y; /* Where we were built */ diff --git a/include/trade.h b/include/trade.h index 6fc9919e2..d40060c63 100644 --- a/include/trade.h +++ b/include/trade.h @@ -43,13 +43,13 @@ struct trdstr { /* initial part must match struct empobj */ short ef_type; - short trd_uid; + int trd_uid; unsigned trd_seqno; time_t trd_timestamp; natid trd_owner; /* end of part matching struct empobj */ short trd_type; - short trd_unitid; + int trd_unitid; long trd_price; int trd_maxbidder; time_t trd_markettime; diff --git a/include/treaty.h b/include/treaty.h index bef96d599..0c6902f67 100644 --- a/include/treaty.h +++ b/include/treaty.h @@ -40,7 +40,7 @@ struct trtstr { /* initial part must match struct empobj */ short ef_type; - short trt_uid; + int trt_uid; unsigned trt_seqno; time_t trt_timestamp; /* end of part matching struct empobj */ diff --git a/src/lib/commands/mfir.c b/src/lib/commands/mfir.c index 88d110ff4..aaf15727f 100644 --- a/src/lib/commands/mfir.c +++ b/src/lib/commands/mfir.c @@ -46,7 +46,7 @@ enum targ_type { struct flist { struct emp_qelem queue; /* list of fired things */ short type; /* EF_SECTOR, EF_SHIP or EF_LAND */ - short uid; + int uid; coord x, y; int defdam; /* damage defenders did */ natid victim; diff --git a/src/lib/common/cargo.c b/src/lib/common/cargo.c index fd6d84a6a..b7774e37d 100644 --- a/src/lib/common/cargo.c +++ b/src/lib/common/cargo.c @@ -40,8 +40,8 @@ #include "unit.h" struct clink { - short next; - short head[EF_NUKE - EF_PLANE + 1]; + int next; + int head[EF_NUKE - EF_PLANE + 1]; }; /* @@ -70,15 +70,15 @@ struct clink { * cargo lists know nothing about that. */ static struct clink *clink[EF_NUKE + 1]; -static short nclink[EF_NUKE + 1]; +static int nclink[EF_NUKE + 1]; /* * Return pointer to CL's cargo list head for file type TYPE. */ -static short * +static int * clink_headp(struct clink *cl, int type) { - static short dummy; + static int dummy; if (CANT_HAPPEN(type < EF_PLANE || type > EF_NUKE)) { dummy = -1; @@ -104,7 +104,7 @@ clink_init(struct clink *cl) * Check whether *UIDP is a valid uid for file type TYPE. */ static void -clink_check1(short *uidp, int type) +clink_check1(int *uidp, int type) { if (CANT_HAPPEN(*uidp >= nclink[type])) *uidp = -1; @@ -138,7 +138,7 @@ clink_check(int type) static void clink_add(struct clink *cl, int type, int uid) { - short *head = clink_headp(cl, type); + int *head = clink_headp(cl, type); if (CANT_HAPPEN(type < 0 || type > EF_NUKE || uid < 0 || uid >= nclink[type])) @@ -157,10 +157,10 @@ clink_add(struct clink *cl, int type, int uid) static void clink_rem(struct clink *cl, int type, int uid) { - short *head = clink_headp(cl, type); + int *head = clink_headp(cl, type); struct clink *linkv; int n; - short *p; + int *p; if (CANT_HAPPEN(type < 0 || type > EF_NUKE)) return; @@ -308,7 +308,7 @@ unit_onresize(int type) int unit_cargo_first(int type, int uid, int cargo_type) { - short *headp; + int *headp; if (CANT_HAPPEN(type < EF_SHIP || type > EF_NUKE)) return -1; diff --git a/src/lib/common/nsc.c b/src/lib/common/nsc.c index c237b5e0f..1281459a4 100644 --- a/src/lib/common/nsc.c +++ b/src/lib/common/nsc.c @@ -131,7 +131,7 @@ struct castr pchr_ca[] = { struct castr sect_ca[] = { #define CURSTR struct sctstr /* uid needs to be NSC_DEITY because it discloses true origin */ - {"uid", fldoff(sct_uid), NSC_SHORT, 0, NULL, + {"uid", fldoff(sct_uid), NSC_INT, 0, NULL, EF_SECTOR, NSC_DEITY | NSC_EXTRA}, {"timestamp", fldoff(sct_timestamp), NSC_TIME, 0, NULL, EF_BAD, NSC_EXTRA}, @@ -211,7 +211,7 @@ struct castr dchr_ca[] = { }; #define NSC_GENITEM(ef_type, ef_chr) \ - {"uid", empobjoff(uid), NSC_SHORT, 0, NULL, ef_type, 0}, \ + {"uid", empobjoff(uid), NSC_INT, 0, NULL, ef_type, 0}, \ {"timestamp", empobjoff(timestamp), NSC_TIME, 0, NULL, EF_BAD, NSC_EXTRA}, \ {"owner", empobjoff(own), NSC_NATID, 0, NULL, EF_NATION, 0}, \ {"xloc", empobjoff(x), NSC_XCOORD, 0, NULL, EF_BAD, 0}, \ @@ -249,7 +249,7 @@ struct castr ship_ca[] = { {"access", fldoff(shp_access), NSC_SHORT, 0, NULL, EF_BAD, 0}, {"mquota", fldoff(shp_mobquota), NSC_UCHAR, 0, NULL, EF_BAD, 0}, {"path", fldoff(shp_path), NSC_STRINGY, MAXSHPPATH, NULL, EF_BAD, 0}, - {"follow", fldoff(shp_follow), NSC_SHORT, 0, NULL, EF_BAD, 0}, + {"follow", fldoff(shp_follow), NSC_INT, 0, NULL, EF_BAD, 0}, {"name", fldoff(shp_name), NSC_STRINGY, MAXSHPNAMLEN, NULL, EF_BAD, 0}, /* should let builder access xbuilt, ybuilt, but can't express that: */ @@ -300,8 +300,8 @@ struct castr plane_ca[] = { NSC_GENITEM(EF_PLANE, EF_PLANE_CHR), {"wing", fldoff(pln_wing), NSC_STRINGY, 1, NULL, EF_BAD, 0}, {"range", fldoff(pln_range), NSC_UCHAR, 0, NULL, EF_BAD, 0}, - {"ship", fldoff(pln_ship), NSC_SHORT, 0, NULL, EF_BAD, 0}, - {"land", fldoff(pln_land), NSC_SHORT, 0, NULL, EF_BAD, 0}, + {"ship", fldoff(pln_ship), NSC_INT, 0, NULL, EF_BAD, 0}, + {"land", fldoff(pln_land), NSC_INT, 0, NULL, EF_BAD, 0}, {"harden", fldoff(pln_harden), NSC_CHAR, 0, NULL, EF_BAD, 0}, {"flags", fldoff(pln_flags), NSC_CHAR, 0, NULL, EF_PLANE_FLAGS, NSC_BITS}, @@ -340,7 +340,7 @@ struct castr land_ca[] = { #define CURSTR struct lndstr NSC_GENITEM(EF_LAND, EF_LAND_CHR), {"army", fldoff(lnd_army), NSC_STRINGY, 1, NULL, EF_BAD, 0}, - {"ship", fldoff(lnd_ship), NSC_SHORT, 0, NULL, EF_BAD, 0}, + {"ship", fldoff(lnd_ship), NSC_INT, 0, NULL, EF_BAD, 0}, {"harden", fldoff(lnd_harden), NSC_CHAR, 0, NULL, EF_BAD, 0}, {"retreat", fldoff(lnd_retreat), NSC_SHORT, 0, NULL, EF_BAD, 0}, {"rflags", fldoff(lnd_rflags), NSC_INT, 0, NULL, @@ -350,7 +350,7 @@ struct castr land_ca[] = { {"pstage", fldoff(lnd_pstage), NSC_SHORT, 0, NULL, EF_PLAGUE_STAGES, NSC_DEITY}, {"ptime", fldoff(lnd_ptime), NSC_SHORT, 0, NULL, EF_BAD, NSC_DEITY}, - {"land", fldoff(lnd_land), NSC_SHORT, 0, NULL, EF_BAD, 0}, + {"land", fldoff(lnd_land), NSC_INT, 0, NULL, EF_BAD, 0}, {"access", fldoff(lnd_access), NSC_SHORT, 0, NULL, EF_BAD, 0}, {"att", 0, NSC_DOUBLE, 0, nsc_lnd_att, EF_BAD, NSC_EXTRA}, {"def", 0, NSC_DOUBLE, 0, nsc_lnd_def, EF_BAD, NSC_EXTRA}, @@ -406,7 +406,7 @@ struct castr lchr_ca[] = { struct castr nuke_ca[] = { #define CURSTR struct nukstr NSC_GENITEM(EF_NUKE, EF_NUKE_CHR), - {"plane", fldoff(nuk_plane), NSC_SHORT, 0, NULL, EF_BAD, 0}, + {"plane", fldoff(nuk_plane), NSC_INT, 0, NULL, EF_BAD, 0}, {NULL, 0, NSC_NOTYPE, 0, NULL, EF_BAD, 0} #undef CURSTR }; @@ -432,7 +432,7 @@ struct castr nchr_ca[] = { struct castr treaty_ca[] = { #define CURSTR struct trtstr - {"uid", fldoff(trt_uid), NSC_SHORT, 0, NULL, EF_TREATY, 0}, + {"uid", fldoff(trt_uid), NSC_INT, 0, NULL, EF_TREATY, 0}, {"timestamp", fldoff(trt_timestamp), NSC_TIME, 0, NULL, EF_BAD, NSC_EXTRA}, {"cna", fldoff(trt_cna), NSC_NATID, 0, NULL, EF_NATION, 0}, @@ -450,7 +450,7 @@ struct castr treaty_ca[] = { struct castr loan_ca[] = { #define CURSTR struct lonstr - {"uid", fldoff(l_uid), NSC_SHORT, 0, NULL, EF_LOAN, 0}, + {"uid", fldoff(l_uid), NSC_INT, 0, NULL, EF_LOAN, 0}, {"timestamp", fldoff(l_timestamp), NSC_TIME, 0, NULL, EF_BAD, NSC_EXTRA}, {"loaner", fldoff(l_loner), NSC_NATID, 0, NULL, EF_NATION, 0}, @@ -487,7 +487,7 @@ struct castr lost_ca[] = { EF_BAD, 0}, {"owner", fldoff(lost_owner), NSC_NATID, 0, NULL, EF_NATION, 0}, {"type", fldoff(lost_type), NSC_CHAR, 0, NULL, EF_TABLE, 0}, - {"id", fldoff(lost_id), NSC_SHORT, 0, NULL, EF_BAD, 0}, + {"id", fldoff(lost_id), NSC_INT, 0, NULL, EF_BAD, 0}, {"x", fldoff(lost_x), NSC_XCOORD, 0, NULL, EF_BAD, 0}, {"y", fldoff(lost_y), NSC_YCOORD, 0, NULL, EF_BAD, 0}, {NULL, 0, NSC_NOTYPE, 0, NULL, EF_BAD, 0} @@ -496,7 +496,7 @@ struct castr lost_ca[] = { struct castr commodity_ca[] = { #define CURSTR struct comstr - {"uid", fldoff(com_uid), NSC_SHORT, 0, NULL, EF_COMM, 0}, + {"uid", fldoff(com_uid), NSC_INT, 0, NULL, EF_COMM, 0}, {"timestamp", fldoff(com_timestamp), NSC_TIME, 0, NULL, EF_BAD, NSC_EXTRA}, {"owner", fldoff(com_owner), NSC_NATID, 0, NULL, EF_NATION, 0}, @@ -517,12 +517,12 @@ struct castr commodity_ca[] = { struct castr trade_ca[] = { #define CURSTR struct trdstr - {"uid", fldoff(trd_uid), NSC_SHORT, 0, NULL, EF_TRADE, 0}, + {"uid", fldoff(trd_uid), NSC_INT, 0, NULL, EF_TRADE, 0}, {"timestamp", fldoff(trd_timestamp), NSC_TIME, 0, NULL, EF_BAD, NSC_EXTRA}, {"owner", fldoff(trd_owner), NSC_NATID, 0, NULL, EF_NATION, 0}, {"type", fldoff(trd_type), NSC_CHAR, 0, NULL, EF_TABLE, 0}, - {"unitid", fldoff(trd_unitid), NSC_SHORT, 0, NULL, EF_BAD, 0}, + {"unitid", fldoff(trd_unitid), NSC_INT, 0, NULL, EF_BAD, 0}, {"price", fldoff(trd_price), NSC_LONG, 0, NULL, EF_BAD, 0}, {"maxbidder", fldoff(trd_maxbidder), NSC_INT, 0, NULL, EF_NATION, 0}, {"markettime", fldoff(trd_markettime), NSC_TIME, 0, NULL, EF_BAD, 0},