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
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 * stop.c: Stop a sector or unit from producing
30 * Known contributors to this file:
31 * Thomas Ruschak, 1992
33 * Markus Armbruster, 2006
43 static int start_stop(int);
44 static int start_stop_sector(char *, int);
45 static void start_stop_hdr(int);
46 static void proff(int);
47 static int start_stop_unit(int, char *, int);
48 static void start_stop_unit_hdr(int);
49 static char *unit_type_name(union empobj_storage *);
66 static int sct_or_unit[] = {
67 EF_SECTOR, EF_SHIP, EF_PLANE, EF_LAND, EF_NUKE, EF_BAD
73 if (player->argp[1] && !isalpha(*player->argp[1])) {
74 /* accept legacy syntax */
76 arg = player->argp[1];
78 p = getstarg(player->argp[1],
79 "Sector, ship, plane, land unit or nuke? ", buf);
82 type = ef_byname_from(p, sct_or_unit);
84 pr("Sectors, ships, planes, land units or nukes only!\n");
87 arg = player->argp[2];
90 if (type == EF_SECTOR)
91 return start_stop_sector(arg, off);
92 return start_stop_unit(type, arg, off);
96 start_stop_sector(char *arg, int off)
100 struct nstr_sect nstr;
102 if (!snxtsct(&nstr, arg))
106 while (nxtsct(&nstr, §)) {
109 if (!sect.sct_off == !off)
114 pr("%3d ", sect.sct_own);
115 prxy("%4d,%-4d", nstr.x, nstr.y, player->cnum);
116 pr(" %c", dchr[sect.sct_type].d_mnem);
117 if (sect.sct_newtype != sect.sct_type)
118 pr("%c", dchr[sect.sct_newtype].d_mnem);
121 pr("%4d%%", sect.sct_effic);
127 pr("%s: No sector(s)\n", arg ? arg : "");
130 pr("%d sector%s\n", nsect, splur(nsect));
135 start_stop_hdr(int off)
139 pr("PRODUCTION %s\n", off ? "STOPPAGE" : "STARTING");
149 pr(" will not produce or gain efficiency.\n");
151 pr(" will be updated normally.\n");
155 start_stop_unit(int type, char *arg, int off)
157 union empobj_storage unit;
159 struct nstr_item nstr;
161 if (!snxtitem(&nstr, type, arg))
165 while (nxtitem(&nstr, &unit)) {
168 if (!unit.gen.off == !off)
171 start_stop_unit_hdr(off);
173 pr("%3d ", unit.gen.own);
174 pr("%4d %-4.4s ", nstr.cur, unit_type_name(&unit));
175 prxy("%4d,%-4d", unit.gen.x, unit.gen.y, player->cnum);
176 pr("%4d%%", unit.gen.effic);
179 ef_write(type, nstr.cur, &unit);
182 pr("%s: No %s(s)\n", arg ? arg : "", ef_nameof(type));
185 pr("%d %s%s\n", nunit, ef_nameof(type), splur(nunit));
190 start_stop_unit_hdr(int off)
194 pr("PRODUCTION %s\n", off ? "STOPPAGE" : "STARTING");
201 unit_type_name(union empobj_storage *unit)
203 int type = unit->gen.type;
205 switch (unit->gen.ef_type) {
207 return mchr[type].m_name;
209 return plchr[type].pl_name;
211 return lchr[type].l_name;
213 return nchr[type].n_name;