diff --git a/include/empobj.h b/include/empobj.h index 546ef46b..65b7a615 100644 --- a/include/empobj.h +++ b/include/empobj.h @@ -84,6 +84,6 @@ union empobj_storage { struct trtstr treaty; }; -extern char * probjname(union empobj_storage *gp); -#endif +extern char *obj_nameof(struct empobj *gp); +#endif diff --git a/include/prototypes.h b/include/prototypes.h index 0ff66342..0bb5d1af 100644 --- a/include/prototypes.h +++ b/include/prototypes.h @@ -488,7 +488,6 @@ extern int num_shipsatxy(coord, coord, int, int); extern int islist(char *); /* src/lib/subs/mission.c */ extern char *mission_name(short); -extern char *nameofitem(struct empobj *, int); extern int collateral_damage(coord, coord, int, struct emp_qelem *); extern int mission_pln_equip(struct plist *, struct ichrstr *, int, char); extern int ground_interdict(coord, coord, natid, char *); diff --git a/src/lib/commands/miss.c b/src/lib/commands/miss.c index 2621602a..88167b52 100644 --- a/src/lib/commands/miss.c +++ b/src/lib/commands/miss.c @@ -203,12 +203,12 @@ mission(void) if ((mission && (gp->mobil < mobused)) && mission_mob_cost) { pr("%s: not enough mobility! (needs %d)\n", - nameofitem(gp, type), mobused); + obj_nameof(gp), mobused); continue; } if (mission == MI_RESERVE && !lnd_can_attack((struct lndstr *)gp)) { pr("%s is not designed to fight ground troops\n", - prland((struct lndstr *)gp)); + obj_nameof(gp)); continue; } if (*p == '.') { @@ -225,7 +225,7 @@ mission(void) mission == MI_AIR_DEFENSE) && (oprange(gp, &radius) < dist)) { pr("%s: out of range! (range %d)\n", - nameofitem(gp, type), oprange(gp, &radius)); + obj_nameof(gp), oprange(gp, &radius)); continue; } @@ -234,13 +234,13 @@ mission(void) if ((mission == MI_INTERDICT) && (type == EF_SHIP)) 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; } if ((mission == MI_INTERDICT) && (type == EF_LAND)) 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; } @@ -306,7 +306,7 @@ mission(void) mission == MI_DSUPPORT || mission == MI_INTERDICT || mission == MI_AIR_DEFENSE) { 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); } else if (mission == MI_RESERVE) { int plus = 2; @@ -322,9 +322,9 @@ mission(void) } 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) { - pr("%s on %s mission\n", nameofitem(gp, type), + pr("%s on %s mission\n", obj_nameof(gp), mission_name(mission)); } diff --git a/src/lib/common/empobj.c b/src/lib/common/empobj.c new file mode 100644 index 00000000..8254841f --- /dev/null +++ b/src/lib/common/empobj.c @@ -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 ""; +} diff --git a/src/lib/subs/mission.c b/src/lib/subs/mission.c index 7f8b1e06..4c733d3d 100644 --- a/src/lib/subs/mission.c +++ b/src/lib/subs/mission.c @@ -804,20 +804,6 @@ cando(int mission, int type) 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 * 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"); first = 0; } - pr("%-25s", nameofitem(gp, type)); + pr("%-25s", obj_nameof(gp)); prxy(" %3d,%-3d", gp->x, gp->y, player->cnum); if (gp->mission == MI_INTERDICT || gp->mission == MI_SUPPORT || gp->mission == MI_OSUPPORT ||