2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2006, 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
46 static int start_stop(int);
47 static int start_stop_sector(char *, int);
48 static void start_stop_hdr(int);
49 static void proff(int);
50 static int start_stop_unit(int, char *, int);
51 static void start_stop_unit_hdr(int);
52 static char *unit_type_name(union empobj_storage *);
69 static int sct_or_unit[] = {
70 EF_SECTOR, EF_SHIP, EF_PLANE, EF_LAND, EF_NUKE, EF_BAD
76 if (player->argp[1] && !isalpha(*player->argp[1])) {
77 /* accept legacy syntax */
79 arg = player->argp[1];
81 p = getstarg(player->argp[1],
82 "Sector, ship, plane, land unit or nuke? ", buf);
85 type = ef_byname_from(p, sct_or_unit);
87 pr("Sectors, ships, planes, land units or nukes only!\n");
90 arg = player->argp[2];
93 if (type == EF_SECTOR)
94 return start_stop_sector(arg, off);
95 return start_stop_unit(type, arg, off);
99 start_stop_sector(char *arg, int off)
103 struct nstr_sect nstr;
105 if (!snxtsct(&nstr, arg))
109 while (nxtsct(&nstr, §)) {
112 if (!sect.sct_off == !off)
117 pr("%3d ", sect.sct_own);
118 prxy("%4d,%-4d", nstr.x, nstr.y, player->cnum);
119 pr(" %c", dchr[sect.sct_type].d_mnem);
120 if (sect.sct_newtype != sect.sct_type)
121 pr("%c", dchr[sect.sct_newtype].d_mnem);
124 pr("%4d%%", sect.sct_effic);
130 pr("%s: No sector(s)\n", arg ? arg : "");
133 pr("%d sector%s\n", nsect, splur(nsect));
138 start_stop_hdr(int off)
142 pr("PRODUCTION %s\n", off ? "STOPPAGE" : "STARTING");
152 pr(" will not produce or gain efficiency.\n");
154 pr(" will be updated normally.\n");
158 start_stop_unit(int type, char *arg, int off)
160 union empobj_storage unit;
162 struct nstr_item nstr;
164 if (!snxtitem(&nstr, type, arg))
168 while (nxtitem(&nstr, &unit)) {
171 if (!unit.gen.off == !off)
174 start_stop_unit_hdr(off);
176 pr("%3d ", unit.gen.own);
177 pr("%4d %-4.4s ", nstr.cur, unit_type_name(&unit));
178 prxy("%4d,%-4d", unit.gen.x, unit.gen.y, player->cnum);
179 pr("%4d%%", unit.gen.effic);
182 ef_write(type, nstr.cur, &unit);
185 pr("%s: No %s(s)\n", arg ? arg : "", ef_nameof(type));
188 pr("%d %s%s\n", nunit, ef_nameof(type), splur(nunit));
193 start_stop_unit_hdr(int off)
197 pr("PRODUCTION %s\n", off ? "STOPPAGE" : "STARTING");
204 unit_type_name(union empobj_storage *unit)
206 int type = unit->gen.type;
208 switch (unit->gen.ef_type) {
210 return mchr[type].m_name;
212 return plchr[type].pl_name;
214 return lchr[type].l_name;
216 return nchr[type].n_name;