(obj_nameof): New.

(nameofitem): Remove, switch callers to to obj_nameof().
(mission, show_mission): Convert functions to use obj_nameof()
instead of nameofitem().
This commit is contained in:
Ron Koenderink 2006-07-10 23:14:26 +00:00
parent e42053d928
commit 6d90861aae
5 changed files with 64 additions and 26 deletions

View file

@ -84,6 +84,6 @@ union empobj_storage {
struct trtstr treaty; struct trtstr treaty;
}; };
extern char * probjname(union empobj_storage *gp); extern char *obj_nameof(struct empobj *gp);
#endif
#endif

View file

@ -488,7 +488,6 @@ extern int num_shipsatxy(coord, coord, int, int);
extern int islist(char *); extern int islist(char *);
/* src/lib/subs/mission.c */ /* src/lib/subs/mission.c */
extern char *mission_name(short); extern char *mission_name(short);
extern char *nameofitem(struct empobj *, int);
extern int collateral_damage(coord, coord, int, struct emp_qelem *); extern int collateral_damage(coord, coord, int, struct emp_qelem *);
extern int mission_pln_equip(struct plist *, struct ichrstr *, int, char); extern int mission_pln_equip(struct plist *, struct ichrstr *, int, char);
extern int ground_interdict(coord, coord, natid, char *); extern int ground_interdict(coord, coord, natid, char *);

View file

@ -203,12 +203,12 @@ mission(void)
if ((mission && (gp->mobil < mobused)) && mission_mob_cost) { if ((mission && (gp->mobil < mobused)) && mission_mob_cost) {
pr("%s: not enough mobility! (needs %d)\n", pr("%s: not enough mobility! (needs %d)\n",
nameofitem(gp, type), mobused); obj_nameof(gp), mobused);
continue; continue;
} }
if (mission == MI_RESERVE && !lnd_can_attack((struct lndstr *)gp)) { if (mission == MI_RESERVE && !lnd_can_attack((struct lndstr *)gp)) {
pr("%s is not designed to fight ground troops\n", pr("%s is not designed to fight ground troops\n",
prland((struct lndstr *)gp)); obj_nameof(gp));
continue; continue;
} }
if (*p == '.') { if (*p == '.') {
@ -225,7 +225,7 @@ mission(void)
mission == MI_AIR_DEFENSE) && mission == MI_AIR_DEFENSE) &&
(oprange(gp, &radius) < dist)) { (oprange(gp, &radius) < dist)) {
pr("%s: out of range! (range %d)\n", pr("%s: out of range! (range %d)\n",
nameofitem(gp, type), oprange(gp, &radius)); obj_nameof(gp), oprange(gp, &radius));
continue; continue;
} }
@ -234,13 +234,13 @@ mission(void)
if ((mission == MI_INTERDICT) && (type == EF_SHIP)) if ((mission == MI_INTERDICT) && (type == EF_SHIP))
if (mchr[(int)gp->type].m_frnge < 1) { if (mchr[(int)gp->type].m_frnge < 1) {
pr("%s: cannot fire at range!\n", nameofitem(gp, type)); pr("%s: cannot fire at range!\n", obj_nameof(gp));
continue; continue;
} }
if ((mission == MI_INTERDICT) && (type == EF_LAND)) if ((mission == MI_INTERDICT) && (type == EF_LAND))
if (lchr[(int)gp->type].l_frg < 1) { if (lchr[(int)gp->type].l_frg < 1) {
pr("%s: cannot fire at range!\n", nameofitem(gp, type)); pr("%s: cannot fire at range!\n", obj_nameof(gp));
continue; continue;
} }
@ -306,7 +306,7 @@ mission(void)
mission == MI_DSUPPORT || mission == MI_INTERDICT || mission == MI_DSUPPORT || mission == MI_INTERDICT ||
mission == MI_AIR_DEFENSE) { mission == MI_AIR_DEFENSE) {
pr("%s on %s mission, centered on %s, radius %d\n", pr("%s on %s mission, centered on %s, radius %d\n",
nameofitem(gp, type), mission_name(mission), obj_nameof(gp), mission_name(mission),
xyas(x, y, player->cnum), gp->radius); xyas(x, y, player->cnum), gp->radius);
} else if (mission == MI_RESERVE) { } else if (mission == MI_RESERVE) {
int plus = 2; int plus = 2;
@ -322,9 +322,9 @@ mission(void)
} }
pr("%s on %s mission with maximum reaction radius %d\n", pr("%s on %s mission with maximum reaction radius %d\n",
nameofitem(gp, type), mission_name(mission), plus); obj_nameof(gp), mission_name(mission), plus);
} else if (mission) { } else if (mission) {
pr("%s on %s mission\n", nameofitem(gp, type), pr("%s on %s mission\n", obj_nameof(gp),
mission_name(mission)); mission_name(mission));
} }

53
src/lib/common/empobj.c Normal file
View file

@ -0,0 +1,53 @@
/*
* Empire - A multi-player, client/server Internet based war game.
* Copyright (C) 1986-2006, Dave Pare, Jeff Bailey, Thomas Ruschak,
* Ken Stevens, Steve McClure
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* ---
*
* See files README, COPYING and CREDITS in the root of the source
* tree for related information and legal notices. It is expected
* that future projects/authors will amend these files as needed.
*
* ---
*
* empobj.c: Common functions on struct empobj and
* union empobj_storage
*
* Known contributors to this file:
* Ron Koenderink, 2006
* Markus Armbruster, 2006
*/
#include "empobj.h"
char *
obj_nameof(struct empobj *gp)
{
switch (gp->ef_type) {
case EF_SHIP:
return prship((struct shpstr *)gp);
case EF_PLANE:
return prplane((struct plnstr *)gp);
case EF_LAND:
return prland((struct lndstr *)gp);
case EF_NUKE:
return prnuke((struct nukstr *)gp);
}
CANT_HAPPEN("unsupported TYPE");
return "";
}

View file

@ -804,20 +804,6 @@ cando(int mission, int type)
return 0; return 0;
} }
char *
nameofitem(struct empobj *gp, int type)
{
switch (type) {
case EF_SHIP:
return prship((struct shpstr *)gp);
case EF_PLANE:
return prplane((struct plnstr *)gp);
case EF_LAND:
return prland((struct lndstr *)gp);
}
return NULL;
}
char * char *
mission_name(short mission) mission_name(short mission)
{ {
@ -858,7 +844,7 @@ show_mission(int type, struct nstr_item *np)
pr("Thing x,y op-sect rad mission\n"); pr("Thing x,y op-sect rad mission\n");
first = 0; first = 0;
} }
pr("%-25s", nameofitem(gp, type)); pr("%-25s", obj_nameof(gp));
prxy(" %3d,%-3d", gp->x, gp->y, player->cnum); prxy(" %3d,%-3d", gp->x, gp->y, player->cnum);
if (gp->mission == MI_INTERDICT || gp->mission == MI_SUPPORT || if (gp->mission == MI_INTERDICT || gp->mission == MI_SUPPORT ||
gp->mission == MI_OSUPPORT || gp->mission == MI_OSUPPORT ||