From 038cc74d4edf0c3d769fefcd6c115626d6036dae Mon Sep 17 00:00:00 2001 From: Ron Koenderink Date: Tue, 23 Jan 2007 01:41:37 +0000 Subject: [PATCH] (unit_list): New, create by combining shp_list() and lnd_list(). (do_unit_move): Replace call to shp_list() and lnd_list() with unit_list(). (shp_list, lnd_list): Remove, not needed, replaced by unit_list(). --- include/land.h | 1 - include/prototypes.h | 1 - include/unit.h | 2 +- src/lib/commands/navi.c | 5 +-- src/lib/subs/lndsub.c | 30 ------------- src/lib/subs/shpsub.c | 32 -------------- src/lib/subs/unitsub.c | 96 +++++++++++++++++++++++++++++++++++++++++ 7 files changed, 98 insertions(+), 69 deletions(-) create mode 100644 src/lib/subs/unitsub.c diff --git a/include/land.h b/include/land.h index 0f7992a3e..8af468b6b 100644 --- a/include/land.h +++ b/include/land.h @@ -207,7 +207,6 @@ extern void count_units(struct shpstr *); extern void lnd_count_units(struct lndstr *); extern void lnd_mar(struct emp_qelem *, double *, double *, int *, natid); extern void lnd_put(struct emp_qelem *, natid); -extern void lnd_list(struct emp_qelem *); extern int lnd_hardtarget(struct lndstr *); extern int lnd_mar_one_sector(struct emp_qelem *, int, natid, int); extern int lnd_support(natid, natid, coord, coord, int); diff --git a/include/prototypes.h b/include/prototypes.h index 154900067..26fa3193e 100644 --- a/include/prototypes.h +++ b/include/prototypes.h @@ -666,7 +666,6 @@ extern void shp_nav(struct emp_qelem *, double *, double *, int *, natid); extern int shp_sweep(struct emp_qelem *, int, int, natid); extern char *shp_path(int, struct shpstr *, char *); extern void shp_put(struct emp_qelem *, natid); -extern void shp_list(struct emp_qelem *); extern int shp_check_nav(struct sctstr *, struct shpstr *); extern int sect_has_dock(struct sctstr *); extern int shp_hardtarget(struct shpstr *); diff --git a/include/unit.h b/include/unit.h index 835129711..6209bdcea 100644 --- a/include/unit.h +++ b/include/unit.h @@ -42,4 +42,4 @@ struct ulist { int supplied; /* LAND only */ }; - +extern void unit_list(struct emp_qelem *); diff --git a/src/lib/commands/navi.c b/src/lib/commands/navi.c index c10fda105..fc496aafa 100644 --- a/src/lib/commands/navi.c +++ b/src/lib/commands/navi.c @@ -227,10 +227,7 @@ do_unit_move(struct emp_qelem *ulist, int *together, } continue; case 'i': - if (type == EF_SHIP) - shp_list(ulist); - else - lnd_list(ulist); + unit_list(ulist); continue; case 'm': if (type == EF_SHIP) diff --git a/src/lib/subs/lndsub.c b/src/lib/subs/lndsub.c index d359a4010..00c5cdd35 100644 --- a/src/lib/subs/lndsub.c +++ b/src/lib/subs/lndsub.c @@ -742,36 +742,6 @@ lnd_check_mines(struct emp_qelem *land_list) return stopping; } -void -lnd_list(struct emp_qelem *land_list) -{ - struct emp_qelem *qp; - struct emp_qelem *next; - struct ulist *llp; - struct lndstr *lnd; - - pr("lnd# land type x,y a eff sh gun xl mu tech retr fuel\n"); - - for (qp = land_list->q_back; qp != land_list; qp = next) { - next = qp->q_back; - llp = (struct ulist *)qp; - lnd = &llp->unit.land; - pr("%4d ", lnd->lnd_uid); - pr("%-16.16s ", ((struct lchrstr *)llp->chrp)->l_name); - prxy("%4d,%-4d ", lnd->lnd_x, lnd->lnd_y, llp->unit.land.lnd_own); - pr("%1.1s", &lnd->lnd_army); - pr("%4d%%", lnd->lnd_effic); - pr("%4d", lnd->lnd_item[I_SHELL]); - pr("%4d", lnd->lnd_item[I_GUN]); - count_land_planes(lnd); - pr("%3d", lnd->lnd_nxlight); - pr("%4d", lnd->lnd_mobil); - pr("%4d", lnd->lnd_tech); - pr("%4d%%", lnd->lnd_retreat); - pr("%5d\n", lnd->lnd_fuel); - } -} - static void lnd_mess(char *str, struct ulist *llp) { diff --git a/src/lib/subs/shpsub.c b/src/lib/subs/shpsub.c index 2e6fb0cf0..679a11952 100644 --- a/src/lib/subs/shpsub.c +++ b/src/lib/subs/shpsub.c @@ -318,38 +318,6 @@ shp_check_mines(struct emp_qelem *ship_list) return stopping; } -void -shp_list(struct emp_qelem *ship_list) -{ - struct emp_qelem *qp; - struct emp_qelem *next; - struct ulist *mlp; - struct shpstr *shp; - - pr("shp# ship type x,y fl eff mil sh gun pn he xl ln mob tech\n"); - - for (qp = ship_list->q_back; qp != ship_list; qp = next) { - next = qp->q_back; - mlp = (struct ulist *)qp; - shp = &mlp->unit.ship; - pr("%4d ", shp->shp_uid); - pr("%-16.16s ", ((struct mchrstr *)mlp->chrp)->m_name); - prxy("%4d,%-4d ", shp->shp_x, shp->shp_y, mlp->unit.ship.shp_own); - pr("%1.1s", &shp->shp_fleet); - pr("%4d%%", shp->shp_effic); - pr("%4d", shp->shp_item[I_MILIT]); - pr("%4d", shp->shp_item[I_SHELL]); - pr("%4d", shp->shp_item[I_GUN]); - count_planes(shp); - pr("%3d", shp->shp_nplane); - pr("%3d", shp->shp_nchoppers); - pr("%3d", shp->shp_nxlight); - count_units(shp); - pr("%3d", shp->shp_nland); - pr("%4d", shp->shp_mobil); - pr("%4d\n", shp->shp_tech); - } -} static void shp_mess(char *str, struct ulist *mlp) diff --git a/src/lib/subs/unitsub.c b/src/lib/subs/unitsub.c new file mode 100644 index 000000000..e19e9b977 --- /dev/null +++ b/src/lib/subs/unitsub.c @@ -0,0 +1,96 @@ +/* + * Empire - A multi-player, client/server Internet based war game. + * Copyright (C) 1986-2007, 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. + * + * --- + * + * unitsub.c: Common subroutines for multiple type of units + * + * Known contributors to this file: + * Ron Koenderink, 2007 + */ + +#include + +#include "empobj.h" +#include "file.h" +#include "prototypes.h" +#include "unit.h" + +void +unit_list(struct emp_qelem *unit_list) +{ + struct emp_qelem *qp; + struct emp_qelem *next; + struct ulist *ulp; + struct empobj *unit; + struct lndstr *lnd; + struct shpstr *shp; + + CANT_HAPPEN(QEMPTY(unit_list)); + + qp = unit_list->q_back; + ulp = (struct ulist *)qp; + + if (ulp->unit.ef_type == EF_LAND) + pr("lnd# land type x,y a eff sh gun xl mu tech retr fuel\n"); + else + pr("shp# ship type x,y fl eff mil sh gun pn he xl ln mob tech\n"); + + for (; qp != unit_list; qp = next) { + next = qp->q_back; + ulp = (struct ulist *)qp; + lnd = &ulp->unit.land; + shp = &ulp->unit.ship; + unit = &ulp->unit.gen; + pr("%4d ", unit->uid); + pr("%-16.16s ", emp_obj_chr_name(unit)); + prxy("%4d,%-4d ", unit->x, unit->y, unit->own); + pr("%1.1s", &unit->group); + pr("%4d%%", unit->effic); + if (unit->ef_type == EF_LAND) { + pr("%4d", lnd->lnd_item[I_SHELL]); + pr("%4d", lnd->lnd_item[I_GUN]); + count_land_planes(lnd); + pr("%3d", lnd->lnd_nxlight); + } else { + pr("%4d", shp->shp_item[I_MILIT]); + pr("%4d", shp->shp_item[I_SHELL]); + pr("%4d", shp->shp_item[I_GUN]); + count_planes(shp); + pr("%3d", shp->shp_nplane); + pr("%3d", shp->shp_nchoppers); + pr("%3d", shp->shp_nxlight); + count_units(shp); + pr("%3d", shp->shp_nland); + } + pr("%4d", unit->mobil); + pr("%4d", unit->tech); + if (unit->ef_type == EF_LAND) { + pr("%4d%%", lnd->lnd_retreat); + pr("%5d", lnd->lnd_fuel); + } + pr("\n"); + } +} -- 2.43.0