(put_empobj): New. Put generic empobj into the appropriate data file.

(get_empobj_chr): New.  Get characteristics for empobj.
(mission, build_mission_list_type): Switch to use new
functions put_empobj() and get_empobj_chr().
This commit is contained in:
Ron Koenderink 2006-07-20 14:12:35 +00:00
parent 8e7199c338
commit a62989d4a3
4 changed files with 50 additions and 22 deletions

View file

@ -85,5 +85,7 @@ union empobj_storage {
};
extern char *obj_nameof(struct empobj *gp);
extern int put_empobj(struct empobj *gp);
extern void *get_empobj_chr(struct empobj *gp);
#endif

View file

@ -333,17 +333,7 @@ mission(void)
gp->mission = mission;
gp->opx = x;
gp->opy = y;
switch (type) {
case EF_SHIP:
putship(gp->uid, &item.ship);
break;
case EF_LAND:
putland(gp->uid, &item.land);
break;
case EF_PLANE:
putplane(gp->uid, &item.plane);
break;
}
put_empobj(gp);
}
if (num == 0) {
pr("No %s%s\n", ef_nameof(type), splur(num));

View file

@ -55,3 +55,49 @@ obj_nameof(struct empobj *gp)
CANT_HAPPEN("unsupported TYPE");
return "";
}
int
put_empobj(struct empobj *gp)
{
switch (gp->ef_type)
{
case EF_SECTOR:
return ef_write(gp->ef_type, sctoff(gp->x, gp->y), gp);
case EF_NATION:
case EF_BMAP:
case EF_MAP:
return ef_write(gp->ef_type, gp->own, gp);
default:
return ef_write(gp->ef_type, gp->uid, gp);
}
}
void *
get_empobj_chr(struct empobj *gp)
{
void *cp;
switch (gp->ef_type) {
case EF_LAND:
cp = &lchr[(int)gp->type];
break;
case EF_SHIP:
cp = &mchr[(int)gp->type];
break;
case EF_PLANE:
cp = &plchr[(int)gp->type];
break;
case EF_NUKE:
cp = &nchr[(int)gp->type];
break;
case EF_SECTOR:
cp = &dchr[(int)gp->type];
break;
default:
CANT_HAPPEN("unsupported TYPE");
cp = NULL;
break;
}
return cp;
}

View file

@ -362,17 +362,7 @@ build_mission_list_type(struct genlist *mi, coord x, coord y, int mission,
glp = malloc(sizeof(struct genlist));
memset(glp, 0, sizeof(struct genlist));
glp->type = type;
switch (type) {
case EF_LAND:
glp->cp = &lchr[(int)gp->type];
break;
case EF_SHIP:
glp->cp = &mchr[(int)gp->type];
break;
case EF_PLANE:
glp->cp = &plchr[(int)gp->type];
break;
}
glp->cp = get_empobj_chr(gp);
glp->thing = malloc(sizeof(item));
memcpy(glp->thing, &item, sizeof(item));
emp_insque(&glp->queue, &mi[gp->own].queue);