]> git.pond.sub.org Git - empserver/commitdiff
(get_empobjp): New. Returns a pointer an empobj.
authorRon Koenderink <rkoenderink@yahoo.ca>
Wed, 26 Jul 2006 00:21:58 +0000 (00:21 +0000)
committerRon Koenderink <rkoenderink@yahoo.ca>
Wed, 26 Jul 2006 00:21:58 +0000 (00:21 +0000)
(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
src/lib/commands/map.c
src/lib/commands/move.c
src/lib/common/empobj.c
src/lib/common/maps.c

index b2ef2252ce29bccb6d39c1fca750b7cafb22167d..408da5f0787a1a3e1586a1d3beec54b1599d27ea 100644 (file)
@@ -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
index db0e38c1c00c74799b6636a22d5dc4ac4f824de8..ec0cc792e1fe7efd1a1450fd4f0128f5d404fdbe 100644 (file)
@@ -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];
index 02cd4fdae59abefe07745231a255a9d1af514a19..3733658af43766c0a5ad5a359b3133bda74eaa0b 100644 (file)
@@ -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
index af371bbd1658a03a6013a2ea9d5fa41d34448cf9..64740efbd92bd09383f115ee951c1297bd6f4b26 100644 (file)
@@ -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)
 {
index 1698947400ef97554aa8779df33de8a5ef411816..2db3681af50c8bc25a416c8fab5c795206bb5aa2 100644 (file)
@@ -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);