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
32 * Markus Armbruster, 2008
40 #include "prototypes.h"
44 unit_list(struct emp_qelem *unit_list)
47 struct emp_qelem *next;
54 if (CANT_HAPPEN(QEMPTY(unit_list)))
56 qp = unit_list->q_back;
57 ulp = (struct ulist *)qp;
58 type = ulp->unit.ef_type;
59 if (CANT_HAPPEN(type != EF_LAND && type != EF_SHIP))
63 pr("lnd# land type x,y a eff sh gun xl mu tech retr\n");
65 pr("shp# ship type x,y fl eff mil sh gun pn he xl ln mob tech\n");
67 for (; qp != unit_list; qp = next) {
69 ulp = (struct ulist *)qp;
70 lnd = &ulp->unit.land;
71 shp = &ulp->unit.ship;
72 unit = &ulp->unit.gen;
73 if (CANT_HAPPEN(type != unit->ef_type))
75 pr("%4d ", unit->uid);
76 pr("%-16.16s ", empobj_chr_name(unit));
77 prxy("%4d,%-4d ", unit->x, unit->y, unit->own);
78 pr("%1.1s", &unit->group);
79 pr("%4d%%", unit->effic);
80 if (type == EF_LAND) {
81 pr("%4d", lnd->lnd_item[I_SHELL]);
82 pr("%4d", lnd->lnd_item[I_GUN]);
83 count_land_planes(lnd);
84 pr("%3d", lnd->lnd_nxlight);
86 pr("%4d", shp->shp_item[I_MILIT]);
87 pr("%4d", shp->shp_item[I_SHELL]);
88 pr("%4d", shp->shp_item[I_GUN]);
90 pr("%3d", shp->shp_nplane);
91 pr("%3d", shp->shp_nchoppers);
92 pr("%3d", shp->shp_nxlight);
94 pr("%3d", shp->shp_nland);
96 pr("%4d", unit->mobil);
97 pr("%4d", unit->tech);
98 if (type == EF_LAND) {
99 pr("%4d%%", lnd->lnd_retreat);
106 unit_put(struct emp_qelem *list, natid actor)
108 struct emp_qelem *qp;
109 struct emp_qelem *newqp;
115 ulp = (struct ulist *)qp;
116 unit = &ulp->unit.gen;
117 if (CANT_HAPPEN(unit->ef_type != EF_LAND
118 && unit->ef_type != EF_SHIP))
121 mpr(actor, "%s stopped at %s\n", obj_nameof(unit),
122 xyas(unit->x, unit->y, unit->own));
123 if (unit->ef_type == EF_LAND) {
124 if (ulp->mobil < -127)
126 unit->mobil = ulp->mobil;
129 if (unit->ef_type == EF_SHIP)
130 unit->mobil = (int)ulp->mobil;
131 put_empobj(unit->ef_type, unit->uid, unit);
140 unit_path(int together, struct empobj *unit, char *buf)
144 struct sctstr d_sect, sect;
149 if (CANT_HAPPEN(unit->ef_type != EF_LAND && unit->ef_type != EF_SHIP))
152 if (!sarg_xy(buf, &destx, &desty))
155 pr("Cannot go to a destination sector if not all starting in the same sector\n");
158 if (!getsect(destx, desty, &d_sect)) {
159 pr("%d,%d is not a sector\n", destx, desty);
162 if (unit->ef_type == EF_SHIP) {
163 cp = BestShipPath(buf, unit->x, unit->y,
164 d_sect.sct_x, d_sect.sct_y, player->cnum);
165 if (!cp || unit->mobil <= 0) {
166 pr("Can't get to '%s' right now.\n",
167 xyas(d_sect.sct_x, d_sect.sct_y, player->cnum));
171 getsect(unit->x, unit->y, §);
172 mtype = lnd_mobtype((struct lndstr *)unit);
173 cp = BestLandPath(buf, §, &d_sect, &dummy, mtype);
175 pr("No owned %s from %s to %s!\n",
176 mtype == MOB_RAIL ? "railway" : "path",
177 xyas(unit->x, unit->y, player->cnum),
178 xyas(d_sect.sct_x, d_sect.sct_y, player->cnum));
181 pr("Using path '%s'\n", cp);
187 unit_view(struct emp_qelem *list)
190 struct emp_qelem *qp;
191 struct emp_qelem *next;
194 for (qp = list->q_back; qp != list; qp = next) {
196 ulp = (struct ulist *)qp;
197 if (CANT_HAPPEN(!(ef_flags(ulp->unit.ef_type) & EFF_XY)))
199 getsect(ulp->unit.gen.x, ulp->unit.gen.y, §);
200 if (ulp->unit.ef_type == EF_SHIP) {
201 if (((struct mchrstr *)ulp->chrp)->m_flags & M_FOOD)
202 pr("[fert:%d] ", sect.sct_fertil);
203 if (((struct mchrstr *)ulp->chrp)->m_flags & M_OIL)
204 pr("[oil:%d] ", sect.sct_oil);
206 pr("%s @ %s %d%% %s\n", obj_nameof(&ulp->unit.gen),
207 xyas(ulp->unit.gen.x, ulp->unit.gen.y, player->cnum),
208 sect.sct_effic, dchr[sect.sct_type].d_name);