New struct emptypedstr to avoid depending on empobj.h there.
Remove now superfluous manual initializations elsewhere.
This doesn't fix any missing initializations.
#include "types.h"
struct empobj {
- short ef_type; /* is always valid */
+ /*
+ * initial part must match struct emptypedstr
+ * valid if EFF_TYPED is set in table's flags
+ */
+ short ef_type;
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 */
+ /* end of part matching struct emptypedstr */
+ natid own; /* valid if EFF_OWNER is in table's flags */
+ coord x; /* valid if EFF_XY is in table's flags */
+ coord y; /* valid if EFF_XY is in table's flags */
+ signed char type; /* valid for sectors and units */
/* remaining are valid for units */
signed char effic;
signed char mobil;
unsigned char off;
short tech;
- char group; /* is valid if EFF_GROUP is set in table def. */
+ char group; /* valid if EFF_GROUP is in table's flags */
coord opx, opy;
short mission;
short radius;
int (*prewrite)(int, void *); /* called before write, unless null */
};
+struct emptypedstr {
+ short ef_type;
+ short uid;
+};
+
/*
* Flag bits for struct empfile member flags
* Immutable flags are properties of the table and thus cannot change.
* The remaining flags record how the table is being used.
*/
/* Immutable flags, fixed at compile-time */
-/* Table entries' addresses can't be safely cast to struct emptyped *. */
+/* Dereferencing entry address cast to struct emptypedstr * is safe */
#define EFF_TYPED bit(0)
/*
* EFF_XY / EFF_OWNER / EFF_GROUP assert that coordinates / owner /
struct loststr {
/* initial part must match struct empobj */
short ef_type;
- int lost_uid; /* lost ID (assigned, otherwise unused) */
+ int lost_uid;
natid lost_owner; /* Who lost it */
/* end of part matching struct empobj */
short lost_type; /* Type of thing (ship, plane, nuke, land, sector) */
struct nwsstr {
/* initial part must match struct empobj */
short ef_type;
- short nws_uid; /* unused */
+ short nws_uid;
/* end of part matching struct empobj */
natid nws_ano; /* "actor" country # */
signed char nws_vrb; /* action (verb) */
do_blank(struct empfile *ep, void *buf, int id, int count)
{
int i;
+ struct emptypedstr *elt;
memset(buf, 0, count * ep->size);
- if (ep->init) {
- for (i = 0; i < count; i++)
- ep->init(id + i, (char *)buf + i * ep->size);
+ for (i = 0; i < count; i++) {
+ elt = (struct emptypedstr *)((char *)buf + i * ep->size);
+ if (ep->flags & EFF_TYPED) {
+ elt->ef_type = ep->uid;
+ elt->uid = id + i;
+ }
+ if (ep->init)
+ ep->init(id + i, (void *)elt);
}
}
void
lnd_init(int n, void *ptr)
{
- struct lndstr *lp = ptr;
-
- lp->ef_type = EF_LAND;
- lp->lnd_uid = n;
- lp->lnd_own = 0;
}
char *
void
nuk_init(int n, void *ptr)
{
- struct nukstr *np = ptr;
-
- np->ef_type = EF_NUKE;
- np->nuk_uid = n;
- np->nuk_own = 0;
}
int
void
pln_init(int n, void *ptr)
{
- struct plnstr *pp = ptr;
-
- pp->ef_type = EF_PLANE;
- pp->pln_uid = n;
- pp->pln_own = 0;
}
char *
void
shp_init(int n, void *ptr)
{
- struct shpstr *sp = ptr;
-
- sp->ef_type = EF_SHIP;
- sp->shp_uid = n;
- sp->shp_own = 0;
}
char *