Let players stop/start units:
(genitem, lndstr, nukstr, plnstr, shpstr): New members off, lnd_off, nuk_off, pln_off, shp_off. (NSC_GENITEM): New selector off. (land, nuke, plan, shi): Display efficiency prefixed by `=' when off. (start, stop, player_coms): Rewrite, new syntax. Print only objects that actually change. (start_hdr, stop_hdr, start_stop_hdr): Consolidate. (item_u, start_stop, start_stop_sector, proff, start_stop_unit) (start_stop_unit_hdr, unit_type_name): New. (upd_land, upd_plane, planerepair, upd_ship): Obey and clear stoppage.
This commit is contained in:
parent
520446ef39
commit
eb1512d75f
22 changed files with 218 additions and 179 deletions
|
@ -25,11 +25,12 @@
|
|||
*
|
||||
* ---
|
||||
*
|
||||
* stop.c: Stop a sector from producing
|
||||
* stop.c: Stop a sector or unit from producing
|
||||
*
|
||||
* Known contributors to this file:
|
||||
* Thomas Ruschak, 1992
|
||||
* Steve McClure, 1998
|
||||
* Markus Armbruster, 2006
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
@ -44,24 +45,84 @@
|
|||
#include "file.h"
|
||||
#include "commands.h"
|
||||
|
||||
static void stop_hdr(void);
|
||||
union item_u {
|
||||
struct genitem gen;
|
||||
struct shpstr ship;
|
||||
struct plnstr plane;
|
||||
struct lndstr land;
|
||||
struct nukstr nuke;
|
||||
};
|
||||
|
||||
static int start_stop(int);
|
||||
static int start_stop_sector(char *, int);
|
||||
static void start_stop_hdr(int);
|
||||
static void proff(int);
|
||||
static int start_stop_unit(int, char *, int);
|
||||
static void start_stop_unit_hdr(int);
|
||||
static char *unit_type_name(union item_u *);
|
||||
|
||||
int
|
||||
start(void)
|
||||
{
|
||||
return start_stop(0);
|
||||
}
|
||||
|
||||
int
|
||||
stop(void)
|
||||
{
|
||||
return start_stop(1);
|
||||
}
|
||||
|
||||
static int
|
||||
start_stop(int off)
|
||||
{
|
||||
static int sct_or_unit[] = {
|
||||
EF_SECTOR, EF_SHIP, EF_PLANE, EF_LAND, EF_NUKE, EF_BAD
|
||||
};
|
||||
int type;
|
||||
char *arg, *p;
|
||||
char buf[1024];
|
||||
|
||||
if (player->argp[1] && !isalpha(*player->argp[1])) {
|
||||
/* accept legacy syntax */
|
||||
type = EF_SECTOR;
|
||||
arg = player->argp[1];
|
||||
} else {
|
||||
p = getstarg(player->argp[1],
|
||||
"Sector, ship, plane, land unit or nuke? ", buf);
|
||||
if (p == 0)
|
||||
return RET_SYN;
|
||||
type = ef_byname_from(p, sct_or_unit);
|
||||
if (type < 0) {
|
||||
pr("Sectors, ships, planes, land units or nukes only!");
|
||||
return RET_SYN;
|
||||
}
|
||||
arg = player->argp[2];
|
||||
}
|
||||
|
||||
if (type == EF_SECTOR)
|
||||
return start_stop_sector(arg, off);
|
||||
return start_stop_unit(type, arg, off);
|
||||
}
|
||||
|
||||
static int
|
||||
start_stop_sector(char *arg, int off)
|
||||
{
|
||||
struct sctstr sect;
|
||||
int nsect;
|
||||
struct nstr_sect nstr;
|
||||
|
||||
if (!snxtsct(&nstr, player->argp[1]))
|
||||
if (!snxtsct(&nstr, arg))
|
||||
return RET_SYN;
|
||||
prdate();
|
||||
nsect = 0;
|
||||
while (nxtsct(&nstr, §)) {
|
||||
if (!player->owner)
|
||||
continue;
|
||||
if (!sect.sct_off == !off)
|
||||
continue;
|
||||
if (nsect++ == 0)
|
||||
stop_hdr();
|
||||
start_stop_hdr(off);
|
||||
if (player->god)
|
||||
pr("%3d ", sect.sct_own);
|
||||
prxy("%4d,%-4d", nstr.x, nstr.y, player->cnum);
|
||||
|
@ -71,18 +132,12 @@ stop(void)
|
|||
else
|
||||
pr(" ");
|
||||
pr("%4d%%", sect.sct_effic);
|
||||
|
||||
pr(" will not produce or gain efficiency.\n");
|
||||
if (sect.sct_off != 1) {
|
||||
sect.sct_off = 1;
|
||||
putsect(§);
|
||||
}
|
||||
proff(off);
|
||||
sect.sct_off = off;
|
||||
putsect(§);
|
||||
}
|
||||
if (nsect == 0) {
|
||||
if (player->argp[1])
|
||||
pr("%s: No sector(s)\n", player->argp[1]);
|
||||
else
|
||||
pr("%s: No sector(s)\n", "");
|
||||
pr("%s: No sector(s)\n", arg ? arg : "");
|
||||
return RET_FAIL;
|
||||
} else
|
||||
pr("%d sector%s\n", nsect, splur(nsect));
|
||||
|
@ -90,12 +145,86 @@ stop(void)
|
|||
}
|
||||
|
||||
static void
|
||||
stop_hdr(void)
|
||||
start_stop_hdr(int off)
|
||||
{
|
||||
if (player->god)
|
||||
pr(" ");
|
||||
pr("PRODUCTION STOPPAGE\n");
|
||||
pr("PRODUCTION %s\n", off ? "STOPPAGE" : "STARTING");
|
||||
if (player->god)
|
||||
pr("own ");
|
||||
pr(" sect eff\n");
|
||||
}
|
||||
|
||||
static void
|
||||
proff(int off)
|
||||
{
|
||||
if (off)
|
||||
pr(" will not produce or gain efficiency.\n");
|
||||
else
|
||||
pr(" will be updated normally.\n");
|
||||
}
|
||||
|
||||
static int
|
||||
start_stop_unit(int type, char *arg, int off)
|
||||
{
|
||||
union item_u unit;
|
||||
int nunit;
|
||||
struct nstr_item nstr;
|
||||
|
||||
if (!snxtitem(&nstr, type, arg))
|
||||
return RET_SYN;
|
||||
prdate();
|
||||
nunit = 0;
|
||||
while (nxtitem(&nstr, &unit)) {
|
||||
if (!player->owner)
|
||||
continue;
|
||||
if (!unit.gen.off == !off)
|
||||
continue;
|
||||
if (nunit++ == 0)
|
||||
start_stop_unit_hdr(off);
|
||||
if (player->god)
|
||||
pr("%3d ", unit.gen.own);
|
||||
pr("%4d %-4.4s ", nstr.cur, unit_type_name(&unit));
|
||||
prxy("%4d,%-4d", unit.gen.x, unit.gen.y, player->cnum);
|
||||
pr("%4d%%", unit.gen.effic);
|
||||
proff(off);
|
||||
unit.gen.off = off;
|
||||
ef_write(type, nstr.cur, &unit);
|
||||
}
|
||||
if (nunit == 0) {
|
||||
pr("%s: No %s(s)\n", arg ? arg : "", ef_nameof(type));
|
||||
return RET_FAIL;
|
||||
} else
|
||||
pr("%d %s%s\n", nunit, ef_nameof(type), splur(nunit));
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
start_stop_unit_hdr(int off)
|
||||
{
|
||||
if (player->god)
|
||||
pr(" ");
|
||||
pr("PRODUCTION %s\n", off ? "STOPPAGE" : "STARTING");
|
||||
if (player->god)
|
||||
pr("own ");
|
||||
pr(" # x,y eff\n");
|
||||
}
|
||||
|
||||
static char *
|
||||
unit_type_name(union item_u *unit)
|
||||
{
|
||||
int type = unit->gen.type;
|
||||
|
||||
switch (unit->gen.ef_type) {
|
||||
case EF_SHIP:
|
||||
return mchr[type].m_name;
|
||||
case EF_PLANE:
|
||||
return plchr[type].pl_name;
|
||||
case EF_LAND:
|
||||
return lchr[type].l_name;
|
||||
case EF_NUKE:
|
||||
return nchr[type].n_name;
|
||||
}
|
||||
CANT_REACH();
|
||||
return "?";
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue