From 49780e2c6cf6a269283d8e0d4a23b74048c869bc Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Mon, 25 Feb 2008 08:23:19 +0100 Subject: [PATCH] Extend the common header of struct empobj to include uid Make sure all members of unit empobj_storage share uid in addition to ef_type. Add matching uid member to struct gamestr, struct natstr and struct sctstr, and set them. Swap struct empobj members uid and own to make that easier, and update struct comstr, struct lndstr, struct lonstr, struct loststr, struct nwsstr, struct nukstr, struct plnstr, struct realmstr, struct shpstr, struct trdstr, struct trtstr accordingly. Note that the uid isn't properly set for struct nwsstr, struct lonstr, struct trdstr, struct comstr and struct loststr. To be fixed. --- include/commodity.h | 2 +- include/empobj.h | 2 +- include/game.h | 1 + include/land.h | 2 +- include/loan.h | 4 +++- include/lost.h | 2 +- include/nat.h | 3 ++- include/news.h | 4 +++- include/nuke.h | 2 +- include/plane.h | 2 +- include/sect.h | 4 ++-- include/ship.h | 2 +- include/trade.h | 2 +- include/treaty.h | 4 +++- src/lib/commands/edit.c | 1 + src/lib/commands/swap.c | 2 ++ src/lib/global/nsc.c | 6 ++++-- src/util/fairland.c | 1 + src/util/files.c | 3 ++- 19 files changed, 32 insertions(+), 17 deletions(-) diff --git a/include/commodity.h b/include/commodity.h index 41573303b..46a038eb8 100644 --- a/include/commodity.h +++ b/include/commodity.h @@ -43,8 +43,8 @@ struct comstr { /* initial part must match struct empobj */ short ef_type; - natid com_owner; short com_uid; + natid com_owner; /* end of part matching struct empobj */ i_type com_type; int com_amount; diff --git a/include/empobj.h b/include/empobj.h index 97dc00e51..8300211fe 100644 --- a/include/empobj.h +++ b/include/empobj.h @@ -52,8 +52,8 @@ struct empobj { short ef_type; /* is always valid */ - natid own; /* is valid if EFF_OWNER is set in table def. */ short uid; + natid own; /* is valid if EFF_OWNER is set in table def. */ 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; /* is valid for sectors and units */ diff --git a/include/game.h b/include/game.h index 2e3292481..5d0d897b6 100644 --- a/include/game.h +++ b/include/game.h @@ -39,6 +39,7 @@ struct gamestr { /* initial part must match struct empobj */ short ef_type; + short game_uid; /* end of part matching struct empobj */ char game_upd_disable; /* updates disabled? */ /* diff --git a/include/land.h b/include/land.h index 339cf410c..bd4972315 100644 --- a/include/land.h +++ b/include/land.h @@ -49,8 +49,8 @@ struct lndstr { /* initial part must match struct empobj */ short ef_type; - natid lnd_own; /* owner's country num */ short lnd_uid; /* unit id (land unit) */ + natid lnd_own; /* owner's country num */ coord lnd_x; /* x location in abs coords */ coord lnd_y; /* y location in abs coords */ signed char lnd_type; /* index in lchr[] */ diff --git a/include/loan.h b/include/loan.h index 21c60b13b..f2ec2c082 100644 --- a/include/loan.h +++ b/include/loan.h @@ -41,9 +41,11 @@ #define SECS_PER_DAY (60*60*24) struct lonstr { + /* initial part must match struct empobj */ short ef_type; - natid l_loner; /* loan shark */ short l_uid; + /* end of part matching struct empobj */ + natid l_loner; /* loan shark */ natid l_lonee; /* sucker */ signed char l_status; /* loan status */ short l_sell; /* pointer to trade file (unused) */ diff --git a/include/lost.h b/include/lost.h index acfae5c97..a377c6ec1 100644 --- a/include/lost.h +++ b/include/lost.h @@ -40,9 +40,9 @@ struct loststr { /* initial part must match struct empobj */ short ef_type; + int lost_uid; /* lost ID (assigned, otherwise unused) */ natid lost_owner; /* Who lost it */ /* end of part matching struct empobj */ - int lost_uid; /* lost ID (assigned, otherwise unused) */ short lost_type; /* Type of thing (ship, plane, nuke, land, sector) */ short lost_id; /* ID of lost thing */ coord lost_x; diff --git a/include/nat.h b/include/nat.h index c7cb01731..b54c8bf9e 100644 --- a/include/nat.h +++ b/include/nat.h @@ -69,9 +69,9 @@ typedef enum { struct realmstr { /* initial part must match struct empobj */ short ef_type; + short r_uid; /* realm table index */ natid r_cnum; /* country number */ /* 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 */ short r_yl, r_yh; /* vertical bounds */ @@ -81,6 +81,7 @@ struct realmstr { struct natstr { /* initial part must match struct empobj */ short ef_type; + short nat_uid; /* equals nat_cnum */ natid nat_cnum; /* our country number */ /* end of part matching struct empobj */ nat_status nat_stat; diff --git a/include/news.h b/include/news.h index 888c78d41..cc182a910 100644 --- a/include/news.h +++ b/include/news.h @@ -45,9 +45,11 @@ #include "nsc.h" struct nwsstr { + /* initial part must match struct empobj */ short ef_type; - natid nws_ano; /* "actor" country # */ short nws_uid; /* unused */ + /* end of part matching struct empobj */ + natid nws_ano; /* "actor" country # */ signed char nws_vrb; /* action (verb) */ natid nws_vno; /* "victim" country # */ signed char nws_ntm; /* number of times */ diff --git a/include/nuke.h b/include/nuke.h index 3c42a4e9e..cc90de951 100644 --- a/include/nuke.h +++ b/include/nuke.h @@ -43,8 +43,8 @@ struct nukstr { /* initial part must match struct empobj */ short ef_type; - natid nuk_own; short nuk_uid; + natid nuk_own; coord nuk_x, nuk_y; /* current loc of device */ signed char nuk_type; /* index in nchr[] */ signed char nuk_effic; /* unused, always 100% */ diff --git a/include/plane.h b/include/plane.h index 25c6fd0e4..f072ba785 100644 --- a/include/plane.h +++ b/include/plane.h @@ -46,8 +46,8 @@ struct plnstr { /* initial part must match struct empobj */ short ef_type; - natid pln_own; /* owning country */ short pln_uid; /* plane unit id */ + natid pln_own; /* owning country */ coord pln_x; /* plane x-y */ coord pln_y; signed char pln_type; /* index in plchr[] */ diff --git a/include/sect.h b/include/sect.h index a960706ee..8d9f9d4eb 100644 --- a/include/sect.h +++ b/include/sect.h @@ -44,8 +44,8 @@ struct sctstr { /* initial part must match struct empobj */ short ef_type; + short sct_uid; /* equals sctoff(sct_x, sct_y) */ 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 */ signed char sct_type; /* sector type */ @@ -62,7 +62,7 @@ struct sctstr { coord sct_dist_y; short sct_avail; /* available workforce for "other things" */ short sct_flags; /* temporary flags */ - short sct_fill; /* gunk */ + short sct_elev; /* elevation/depth */ unsigned char sct_work; /* pct of civ actually working */ unsigned char sct_coastal; /* is this a coastal sector? */ signed char sct_newtype; /* for changing designations */ diff --git a/include/ship.h b/include/ship.h index 65097564f..cbfed235b 100644 --- a/include/ship.h +++ b/include/ship.h @@ -63,8 +63,8 @@ struct shpstr { /* initial part must match struct empobj */ short ef_type; - natid shp_own; /* owner's country num */ short shp_uid; /* unit id (ship #) */ + natid shp_own; /* owner's country num */ coord shp_x; /* x location in abs coords */ coord shp_y; /* y location in abs coords */ signed char shp_type; /* index in mchr[] */ diff --git a/include/trade.h b/include/trade.h index 45b4dfe0b..8db1e6fe9 100644 --- a/include/trade.h +++ b/include/trade.h @@ -43,8 +43,8 @@ struct trdstr { /* initial part must match struct empobj */ short ef_type; - natid trd_owner; short trd_uid; + natid trd_owner; /* end of part matching struct empobj */ short trd_type; short trd_unitid; diff --git a/include/treaty.h b/include/treaty.h index ba072745a..a8c5d258b 100644 --- a/include/treaty.h +++ b/include/treaty.h @@ -38,9 +38,11 @@ #include "types.h" struct trtstr { + /* initial part must match struct empobj */ short ef_type; - natid trt_cna; /* proposer */ short trt_uid; + /* end of part matching struct empobj */ + natid trt_cna; /* proposer */ natid trt_cnb; /* acceptor */ signed char trt_status; /* treaty status */ char trt_fill; diff --git a/src/lib/commands/edit.c b/src/lib/commands/edit.c index b15f8e018..6e678c804 100644 --- a/src/lib/commands/edit.c +++ b/src/lib/commands/edit.c @@ -593,6 +593,7 @@ doland(char op, int arg, char *p, struct sctstr *sect) return RET_SYN; sect->sct_x = newx; sect->sct_y = newy; + sect->sct_uid = XYOFFSET(newx, newy); break; case 'D': if (!sarg_xy(p, &newx, &newy)) diff --git a/src/lib/commands/swap.c b/src/lib/commands/swap.c index 6c8fd3073..a28b89913 100644 --- a/src/lib/commands/swap.c +++ b/src/lib/commands/swap.c @@ -63,12 +63,14 @@ swaps(void) /* change the location of secta to that of sectb */ secta.sct_x = sectb.sct_x; secta.sct_y = sectb.sct_y; + secta.sct_uid = sectb.sct_uid; secta.sct_dist_x = sectb.sct_x; secta.sct_dist_y = sectb.sct_y; secta.sct_coastal = sectb.sct_coastal; /* change the location of sectb to where secta was */ sectb.sct_x = tmp.sct_x; sectb.sct_y = tmp.sct_y; + sectb.sct_uid = tmp.sct_uid; sectb.sct_dist_x = tmp.sct_x; sectb.sct_dist_y = tmp.sct_y; sectb.sct_coastal = tmp.sct_coastal; diff --git a/src/lib/global/nsc.c b/src/lib/global/nsc.c index b23987e35..b463e0491 100644 --- a/src/lib/global/nsc.c +++ b/src/lib/global/nsc.c @@ -103,9 +103,10 @@ struct castr pchr_ca[] = { }; struct castr sect_ca[] = { - /* uid is encoded in x, y */ + /* uid needs to be NSC_DEITY because it discloses true origin */ + {NSC_SHORT, NSC_DEITY | NSC_EXTRA, 0, fldoff(sctstr, sct_uid), "uid", + EF_SECTOR}, {NSC_NATID, 0, 0, fldoff(sctstr, sct_own), "owner", EF_NATION}, - {NSC_SHORT, NSC_DEITY, 0, fldoff(sctstr, sct_elev), "elev", EF_BAD}, {NSC_XCOORD, NSC_CONST, 0, fldoff(sctstr, sct_x), "xloc", EF_BAD}, {NSC_YCOORD, NSC_CONST, 0, fldoff(sctstr, sct_y), "yloc", EF_BAD}, {NSC_CHAR, 0, 0, fldoff(sctstr, sct_type), "des", EF_SECTOR_CHR}, @@ -121,6 +122,7 @@ struct castr sect_ca[] = { {NSC_XCOORD, 0, 0, fldoff(sctstr, sct_dist_x), "xdist", EF_BAD}, {NSC_YCOORD, 0, 0, fldoff(sctstr, sct_dist_y), "ydist", EF_BAD}, {NSC_SHORT, 0, 0, fldoff(sctstr, sct_avail), "avail", EF_BAD}, + {NSC_SHORT, NSC_DEITY, 0, fldoff(sctstr, sct_elev), "elev", EF_BAD}, {NSC_UCHAR, 0, 0, fldoff(sctstr, sct_work), "work", EF_BAD}, {NSC_UCHAR, 0, 0, fldoff(sctstr, sct_coastal), "coastal", EF_BAD}, {NSC_CHAR, 0, 0, fldoff(sctstr, sct_newtype), "newdes", EF_SECTOR_CHR}, diff --git a/src/util/fairland.c b/src/util/fairland.c index 104aa9df7..4598eba61 100644 --- a/src/util/fairland.c +++ b/src/util/fairland.c @@ -1214,6 +1214,7 @@ static void fl_sct_init(coord x, coord y, struct sctstr *sp) { sp->ef_type = EF_SECTOR; + sp->sct_uid = XYOFFSET(x, y); sp->sct_x = x; sp->sct_y = y; sp->sct_dist_x = x; diff --git a/src/util/files.c b/src/util/files.c index 2d8c93712..4618ba6ef 100644 --- a/src/util/files.c +++ b/src/util/files.c @@ -154,7 +154,7 @@ main(int argc, char *argv[]) memset(&nat, 0, sizeof(nat)); for (i = 1; i < MAXNOC; i++) { nat.ef_type = EF_NATION; - nat.nat_cnum = i; + nat.nat_cnum = nat.nat_uid = i; putnat((&nat)); } memset(&realm, 0, sizeof(realm)); @@ -208,6 +208,7 @@ file_sct_init(coord x, coord y, struct sctstr *ptr) struct sctstr *sp = (struct sctstr *)ptr; sp->ef_type = EF_SECTOR; + sp->sct_uid = XYOFFSET(x, y); sp->sct_x = x; sp->sct_y = y; sp->sct_dist_x = x; -- 2.43.0