From fec9878ca4ccf9c5a68893ccbea025a55b46f7f6 Mon Sep 17 00:00:00 2001 From: Ron Koenderink Date: Wed, 26 Jul 2006 00:21:58 +0000 Subject: [PATCH] (get_empobjp): New. Returns a pointer an empobj. (emp_obj_chr_name): New. Returns a pointer to the characteristics name for an empobj. (unit_map): Simplify unit_map() by using get_empobjp() and emp_obj_chr_name(). (map, cmd_move_map): Switch to EF_SHIP as unit_map does not default to EF_SHIP for EF_BAD anymore. --- include/empobj.h | 2 ++ src/lib/commands/map.c | 2 +- src/lib/commands/move.c | 2 +- src/lib/common/empobj.c | 28 ++++++++++++++++++++++++++++ src/lib/common/maps.c | 31 +++++++++---------------------- 5 files changed, 41 insertions(+), 24 deletions(-) diff --git a/include/empobj.h b/include/empobj.h index b2ef2252c..408da5f07 100644 --- a/include/empobj.h +++ b/include/empobj.h @@ -85,8 +85,10 @@ union empobj_storage { }; extern char *obj_nameof(struct empobj *gp); +extern struct empobj *get_empobjp(int type, int id); extern int put_empobj(struct empobj *gp); extern void *get_empobj_chr(struct empobj *gp); +extern char *emp_obj_chr_name(struct empobj *gp); extern int get_empobj_mob_max(int ef_type); #endif diff --git a/src/lib/commands/map.c b/src/lib/commands/map.c index db0e38c1c..ec0cc792e 100644 --- a/src/lib/commands/map.c +++ b/src/lib/commands/map.c @@ -43,7 +43,7 @@ int map(void) { - int unit_type = EF_BAD; + int unit_type = EF_SHIP; int bmap = 0; char *str; char buf[1024]; diff --git a/src/lib/commands/move.c b/src/lib/commands/move.c index 02cd4fdae..3733658af 100644 --- a/src/lib/commands/move.c +++ b/src/lib/commands/move.c @@ -343,7 +343,7 @@ move(void) static int cmd_move_map(coord curx, coord cury, char *arg) { - return display_region_map(0, EF_BAD, curx, cury, arg); + return display_region_map(0, EF_SHIP, curx, cury, arg); } int diff --git a/src/lib/common/empobj.c b/src/lib/common/empobj.c index af371bbd1..64740efbd 100644 --- a/src/lib/common/empobj.c +++ b/src/lib/common/empobj.c @@ -57,6 +57,14 @@ obj_nameof(struct empobj *gp) return ""; } +struct empobj * +get_empobjp(int type, int id) +{ + if (CANT_HAPPEN(type == EF_SECTOR || type == EF_BAD)) + return NULL; + else + return (struct empobj *)ef_ptr(type, id); +} int put_empobj(struct empobj *gp) @@ -103,6 +111,26 @@ get_empobj_chr(struct empobj *gp) return cp; } +char * +emp_obj_chr_name(struct empobj *gp) +{ + switch (gp->ef_type) { + case EF_LAND: + return lchr[(int)gp->type].l_name; + case EF_SHIP: + return mchr[(int)gp->type].m_name; + case EF_PLANE: + return plchr[(int)gp->type].pl_name; + case EF_NUKE: + return nchr[(int)gp->type].n_name; + case EF_SECTOR: + return dchr[(int)gp->type].d_name; + default: + CANT_REACH(); + return NULL; + } +} + int get_empobj_mob_max(int ef_type) { diff --git a/src/lib/common/maps.c b/src/lib/common/maps.c index 169894740..2db3681af 100644 --- a/src/lib/common/maps.c +++ b/src/lib/common/maps.c @@ -376,33 +376,20 @@ map_char(unsigned char type, natid own, int owner_or_god) int unit_map(int unit_type, int uid, struct nstr_sect *nsp, char *originp) { - struct shpstr origs; - struct lndstr origl; - struct plnstr origp; - struct nukstr orign; struct empobj *gp; struct range range; + char *name; - if (unit_type == EF_LAND) { - if (!getland(uid, &origl) || !player->owner || origl.lnd_own == 0) - return RET_FAIL; - gp = (struct empobj *)&origl; - *originp = *lchr[(int)origl.lnd_type].l_name; - } else if (unit_type == EF_PLANE) { - if (!getplane(uid, &origp) || !player->owner || origp.pln_own == 0) - return RET_FAIL; - gp = (struct empobj *)&origp; - *originp = *plchr[(int)origp.pln_type].pl_name; - } else if (unit_type == EF_NUKE) { - if (!getnuke(uid, &orign) || !player->owner || orign.nuk_own == 0) - return RET_FAIL; - gp = (struct empobj *)&orign; + gp = get_empobjp(unit_type, uid); + if (!gp || !player->owner || gp->own == 0) + return RET_FAIL; + + if (unit_type == EF_NUKE) *originp = 'n'; - } else { - if (!getship(uid, &origs) || !player->owner || origs.shp_own == 0) + else { + if ((name = emp_obj_chr_name(gp)) == NULL) return RET_FAIL; - gp = (struct empobj *)&origs; - *originp = *mchr[(int)origs.shp_type].m_name; + *originp = *name; } range.lx = xnorm(gp->x - 10); -- 2.43.0