]> git.pond.sub.org Git - empserver/blob - src/lib/subs/unitsub.c
(unit_list): New, create by combining shp_list() and lnd_list().
[empserver] / src / lib / subs / unitsub.c
1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2007, Dave Pare, Jeff Bailey, Thomas Ruschak,
4  *                           Ken Stevens, Steve McClure
5  *
6  *  This program is free software; you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation; either version 2 of the License, or
9  *  (at your option) any later version.
10  *
11  *  This program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with this program; if not, write to the Free Software
18  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  *
20  *  ---
21  *
22  *  See files README, COPYING and CREDITS in the root of the source
23  *  tree for related information and legal notices.  It is expected
24  *  that future projects/authors will amend these files as needed.
25  *
26  *  ---
27  *
28  *  unitsub.c: Common subroutines for multiple type of units
29  * 
30  *  Known contributors to this file:
31  *     Ron Koenderink, 2007
32  */
33
34 #include <config.h>
35
36 #include "empobj.h"
37 #include "file.h"
38 #include "prototypes.h"
39 #include "unit.h"
40
41 void
42 unit_list(struct emp_qelem *unit_list)
43 {
44     struct emp_qelem *qp;
45     struct emp_qelem *next;
46     struct ulist *ulp;
47     struct empobj *unit;
48     struct lndstr *lnd;
49     struct shpstr *shp;
50
51     CANT_HAPPEN(QEMPTY(unit_list));
52
53     qp = unit_list->q_back;
54     ulp = (struct ulist *)qp;
55
56     if (ulp->unit.ef_type == EF_LAND)
57         pr("lnd#     land type       x,y    a  eff  sh gun xl  mu tech retr fuel\n");
58     else
59         pr("shp#     ship type       x,y   fl  eff mil  sh gun pn he xl ln mob tech\n");
60
61     for (; qp != unit_list; qp = next) {
62         next = qp->q_back;
63         ulp = (struct ulist *)qp;
64         lnd = &ulp->unit.land;
65         shp = &ulp->unit.ship;
66         unit = &ulp->unit.gen;
67         pr("%4d ", unit->uid);
68         pr("%-16.16s ", emp_obj_chr_name(unit));
69         prxy("%4d,%-4d ", unit->x, unit->y, unit->own);
70         pr("%1.1s", &unit->group);
71         pr("%4d%%", unit->effic);
72         if (unit->ef_type == EF_LAND) {
73             pr("%4d", lnd->lnd_item[I_SHELL]);
74             pr("%4d", lnd->lnd_item[I_GUN]);
75             count_land_planes(lnd);
76             pr("%3d", lnd->lnd_nxlight);
77         } else {
78             pr("%4d", shp->shp_item[I_MILIT]);
79             pr("%4d", shp->shp_item[I_SHELL]);
80             pr("%4d", shp->shp_item[I_GUN]);
81             count_planes(shp);
82             pr("%3d", shp->shp_nplane);
83             pr("%3d", shp->shp_nchoppers);
84             pr("%3d", shp->shp_nxlight);
85             count_units(shp);
86             pr("%3d", shp->shp_nland);
87         }
88         pr("%4d", unit->mobil);
89         pr("%4d", unit->tech);
90         if (unit->ef_type == EF_LAND) {
91             pr("%4d%%", lnd->lnd_retreat);
92             pr("%5d", lnd->lnd_fuel);
93         }
94         pr("\n");
95     }
96 }