(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().
This commit is contained in:
Ron Koenderink 2007-01-23 01:41:37 +00:00
parent 99e30073f2
commit 038cc74d4e
7 changed files with 98 additions and 69 deletions

View file

@ -207,7 +207,6 @@ extern void count_units(struct shpstr *);
extern void lnd_count_units(struct lndstr *); extern void lnd_count_units(struct lndstr *);
extern void lnd_mar(struct emp_qelem *, double *, double *, int *, natid); extern void lnd_mar(struct emp_qelem *, double *, double *, int *, natid);
extern void lnd_put(struct emp_qelem *, 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_hardtarget(struct lndstr *);
extern int lnd_mar_one_sector(struct emp_qelem *, int, natid, int); extern int lnd_mar_one_sector(struct emp_qelem *, int, natid, int);
extern int lnd_support(natid, natid, coord, coord, int); extern int lnd_support(natid, natid, coord, coord, int);

View file

@ -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 int shp_sweep(struct emp_qelem *, int, int, natid);
extern char *shp_path(int, struct shpstr *, char *); extern char *shp_path(int, struct shpstr *, char *);
extern void shp_put(struct emp_qelem *, natid); 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 shp_check_nav(struct sctstr *, struct shpstr *);
extern int sect_has_dock(struct sctstr *); extern int sect_has_dock(struct sctstr *);
extern int shp_hardtarget(struct shpstr *); extern int shp_hardtarget(struct shpstr *);

View file

@ -42,4 +42,4 @@ struct ulist {
int supplied; /* LAND only */ int supplied; /* LAND only */
}; };
extern void unit_list(struct emp_qelem *);

View file

@ -227,10 +227,7 @@ do_unit_move(struct emp_qelem *ulist, int *together,
} }
continue; continue;
case 'i': case 'i':
if (type == EF_SHIP) unit_list(ulist);
shp_list(ulist);
else
lnd_list(ulist);
continue; continue;
case 'm': case 'm':
if (type == EF_SHIP) if (type == EF_SHIP)

View file

@ -742,36 +742,6 @@ lnd_check_mines(struct emp_qelem *land_list)
return stopping; 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 static void
lnd_mess(char *str, struct ulist *llp) lnd_mess(char *str, struct ulist *llp)
{ {

View file

@ -318,38 +318,6 @@ shp_check_mines(struct emp_qelem *ship_list)
return stopping; 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 static void
shp_mess(char *str, struct ulist *mlp) shp_mess(char *str, struct ulist *mlp)

96
src/lib/subs/unitsub.c Normal file
View file

@ -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 <config.h>
#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");
}
}