2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2008, Dave Pare, Jeff Bailey, Thomas Ruschak,
4 * Ken Stevens, Steve McClure
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.
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.
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
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.
28 * unitsub.c: Common subroutines for multiple type of units
30 * Known contributors to this file:
31 * Ron Koenderink, 2007
39 #include "prototypes.h"
43 unit_list(struct emp_qelem *unit_list)
46 struct emp_qelem *next;
52 CANT_HAPPEN(QEMPTY(unit_list));
54 qp = unit_list->q_back;
55 ulp = (struct ulist *)qp;
57 if (ulp->unit.ef_type == EF_LAND)
58 pr("lnd# land type x,y a eff sh gun xl mu tech retr fuel\n");
60 pr("shp# ship type x,y fl eff mil sh gun pn he xl ln mob tech\n");
62 for (; qp != unit_list; qp = next) {
64 ulp = (struct ulist *)qp;
65 lnd = &ulp->unit.land;
66 shp = &ulp->unit.ship;
67 unit = &ulp->unit.gen;
68 pr("%4d ", unit->uid);
69 pr("%-16.16s ", emp_obj_chr_name(unit));
70 prxy("%4d,%-4d ", unit->x, unit->y, unit->own);
71 pr("%1.1s", &unit->group);
72 pr("%4d%%", unit->effic);
73 if (unit->ef_type == EF_LAND) {
74 pr("%4d", lnd->lnd_item[I_SHELL]);
75 pr("%4d", lnd->lnd_item[I_GUN]);
76 count_land_planes(lnd);
77 pr("%3d", lnd->lnd_nxlight);
79 pr("%4d", shp->shp_item[I_MILIT]);
80 pr("%4d", shp->shp_item[I_SHELL]);
81 pr("%4d", shp->shp_item[I_GUN]);
83 pr("%3d", shp->shp_nplane);
84 pr("%3d", shp->shp_nchoppers);
85 pr("%3d", shp->shp_nxlight);
87 pr("%3d", shp->shp_nland);
89 pr("%4d", unit->mobil);
90 pr("%4d", unit->tech);
91 if (unit->ef_type == EF_LAND) {
92 pr("%4d%%", lnd->lnd_retreat);
93 pr("%5d", lnd->lnd_fuel);
100 unit_put(struct emp_qelem *list, natid actor)
102 struct emp_qelem *qp;
103 struct emp_qelem *newqp;
108 ulp = (struct ulist *)qp;
110 mpr(actor, "%s stopped at %s\n", obj_nameof(&ulp->unit.gen),
111 xyas(ulp->unit.gen.x, ulp->unit.gen.y,
113 if (ulp->unit.ef_type == EF_LAND) {
114 if (ulp->mobil < -127)
116 ulp->unit.land.lnd_mobil = ulp->mobil;
119 if (ulp->unit.ef_type == EF_SHIP)
120 ulp->unit.ship.shp_mobil = (int)ulp->mobil;
121 put_empobj(ulp->unit.gen.ef_type, ulp->unit.gen.uid, &ulp->unit.gen);
130 unit_path(int together, struct empobj *unit, char *buf)
134 struct sctstr d_sect, sect;
139 if (!sarg_xy(buf, &destx, &desty))
142 pr("Cannot go to a destination sector if not all starting in the same sector\n");
145 if (!getsect(destx, desty, &d_sect)) {
146 pr("%d,%d is not a sector\n", destx, desty);
149 if (unit->ef_type == EF_SHIP) {
150 cp = BestShipPath(buf, unit->x, unit->y,
151 d_sect.sct_x, d_sect.sct_y, player->cnum);
152 if (!cp || unit->mobil <= 0) {
153 pr("Can't get to '%s' right now.\n",
154 xyas(d_sect.sct_x, d_sect.sct_y, player->cnum));
158 getsect(unit->x, unit->y, §);
159 mtype = lnd_mobtype((struct lndstr *)unit);
160 cp = BestLandPath(buf, §, &d_sect, &dummy, mtype);
162 pr("No owned %s from %s to %s!\n",
163 mtype == MOB_RAIL ? "railway" : "path",
164 xyas(unit->x, unit->y, player->cnum),
165 xyas(d_sect.sct_x, d_sect.sct_y, player->cnum));
168 pr("Using path '%s'\n", cp);
174 unit_view(struct emp_qelem *list)
177 struct emp_qelem *qp;
178 struct emp_qelem *next;
181 for (qp = list->q_back; qp != list; qp = next) {
183 ulp = (struct ulist *)qp;
184 getsect(ulp->unit.gen.x, ulp->unit.gen.y, §);
185 if (ulp->unit.ef_type == EF_SHIP) {
186 if (((struct mchrstr *)ulp->chrp)->m_flags & M_FOOD)
187 pr("[fert:%d] ", sect.sct_fertil);
188 if (((struct mchrstr *)ulp->chrp)->m_flags & M_OIL)
189 pr("[oil:%d] ", sect.sct_oil);
191 pr("%s @ %s %d%% %s\n", obj_nameof(&ulp->unit.gen),
192 xyas(ulp->unit.gen.x, ulp->unit.gen.y, player->cnum),
193 sect.sct_effic, dchr[sect.sct_type].d_name);