setsector setresource: Switch to edit_sect()
One copy of the code suffices. "Fertility content" becomes just "Fertility" in messages. Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
This commit is contained in:
parent
f52a7e2739
commit
e109d981b8
5 changed files with 48 additions and 155 deletions
|
@ -54,6 +54,8 @@ extern void finish_server(void);
|
|||
* src/lib/commands/ *.c
|
||||
*/
|
||||
extern int check_market(void);
|
||||
extern int edit_sect(struct sctstr *, char *, char *);
|
||||
extern int edit_sect_i(struct sctstr *, char *, int);
|
||||
extern int load_comm_ok(struct sctstr *, natid, i_type, int);
|
||||
extern void gift(natid, natid, void *, char *);
|
||||
extern int display_mark(i_type, int);
|
||||
|
@ -63,7 +65,6 @@ extern int nav_map(int, int, int);
|
|||
extern int do_unit_move(struct emp_qelem *, int *, double *, double *);
|
||||
extern int count_pop(int);
|
||||
extern int scuttle_tradeship(struct shpstr *, int);
|
||||
extern void resnoise(struct sctstr *, char *, int, int);
|
||||
extern int line_of_sight(char **rad, int ax, int ay, int bx, int by);
|
||||
extern void plane_sona(struct emp_qelem *, int, int, struct shiplist **);
|
||||
extern char *prsub(struct shpstr *);
|
||||
|
|
|
@ -54,8 +54,6 @@ static void print_plane(struct plnstr *);
|
|||
static void print_land(struct lndstr *);
|
||||
static void print_ship(struct shpstr *);
|
||||
static char *getin(char *, char **);
|
||||
static int edit_sect(struct sctstr *, char *, char *);
|
||||
static int edit_sect_i(struct sctstr *, char *, int);
|
||||
static int edit_nat(struct natstr *, char *, char *);
|
||||
static int edit_ship(struct shpstr *, char *, char *);
|
||||
static int edit_land(struct lndstr *, char *, char *);
|
||||
|
@ -415,7 +413,7 @@ warn_deprecated(char key)
|
|||
}
|
||||
#endif
|
||||
|
||||
static int
|
||||
int
|
||||
edit_sect_i(struct sctstr *sect, char *key, int arg)
|
||||
{
|
||||
int new;
|
||||
|
@ -573,7 +571,7 @@ edit_sect_i(struct sctstr *sect, char *key, int arg)
|
|||
return RET_OK;
|
||||
}
|
||||
|
||||
static int
|
||||
int
|
||||
edit_sect(struct sctstr *sect, char *key, char *p)
|
||||
{
|
||||
coord newx, newy;
|
||||
|
|
|
@ -45,7 +45,7 @@ setres(void)
|
|||
{
|
||||
struct sctstr sect;
|
||||
char *what;
|
||||
int amt;
|
||||
int ret;
|
||||
char *p;
|
||||
struct nstr_sect nstr;
|
||||
char buf[1024];
|
||||
|
@ -64,35 +64,30 @@ setres(void)
|
|||
p = getstarg(player->argp[3], "What value : ", buf);
|
||||
if (!p || !*p)
|
||||
return RET_SYN;
|
||||
amt = atoi(p);
|
||||
amt = LIMIT_TO(amt, 0, 100);
|
||||
if (!check_sect_ok(§))
|
||||
return RET_FAIL;
|
||||
switch (char0) {
|
||||
case 'i':
|
||||
resnoise(§, "Iron ore content", sect.sct_min, amt);
|
||||
sect.sct_min = (unsigned char)amt;
|
||||
ret = edit_sect(§, "i", p);
|
||||
break;
|
||||
case 'g':
|
||||
resnoise(§, "Gold content", sect.sct_gmin, amt);
|
||||
sect.sct_gmin = (unsigned char)amt;
|
||||
ret = edit_sect(§, "g", p);
|
||||
break;
|
||||
case 'o':
|
||||
resnoise(§, "Oil content", sect.sct_oil, amt);
|
||||
sect.sct_oil = (unsigned char)amt;
|
||||
ret = edit_sect(§, "c", p);
|
||||
break;
|
||||
case 'f':
|
||||
resnoise(§, "Fertility content", sect.sct_fertil, amt);
|
||||
sect.sct_fertil = (unsigned char)amt;
|
||||
ret = edit_sect(§, "f", p);
|
||||
break;
|
||||
case 'u':
|
||||
resnoise(§, "Uranium content", sect.sct_uran, amt);
|
||||
sect.sct_uran = (unsigned char)amt;
|
||||
ret = edit_sect(§, "u", p);
|
||||
break;
|
||||
default:
|
||||
pr("huh?\n");
|
||||
return RET_SYN;
|
||||
ret = RET_SYN;
|
||||
}
|
||||
if (ret != RET_OK)
|
||||
return ret;
|
||||
putsect(§);
|
||||
}
|
||||
return RET_OK;
|
||||
|
|
|
@ -35,10 +35,6 @@
|
|||
#include <config.h>
|
||||
|
||||
#include "commands.h"
|
||||
#include "news.h"
|
||||
#include "optlist.h"
|
||||
|
||||
static void resbenefit(natid, int);
|
||||
|
||||
/*
|
||||
* format: setres thing <sect> <#>
|
||||
|
@ -48,7 +44,7 @@ setsector(void)
|
|||
{
|
||||
struct sctstr sect;
|
||||
char *what;
|
||||
int amt, current;
|
||||
int amt, ret;
|
||||
char *p;
|
||||
struct nstr_sect nstr;
|
||||
char buf[1024];
|
||||
|
@ -73,68 +69,22 @@ setsector(void)
|
|||
return RET_FAIL;
|
||||
switch (char0) {
|
||||
case 'i':
|
||||
current = sect.sct_min;
|
||||
current += amt;
|
||||
current = LIMIT_TO(current, 0, 100);
|
||||
resnoise(§, "Iron ore content", sect.sct_min, current);
|
||||
sect.sct_min = (unsigned char)current;
|
||||
ret = edit_sect_i(§, "i", sect.sct_min + amt);
|
||||
break;
|
||||
case 'g':
|
||||
current = sect.sct_gmin;
|
||||
current += amt;
|
||||
current = LIMIT_TO(current, 0, 100);
|
||||
resnoise(§, "Gold content", sect.sct_gmin, current);
|
||||
sect.sct_gmin = (unsigned char)current;
|
||||
ret = edit_sect_i(§, "g", sect.sct_gmin + amt);
|
||||
break;
|
||||
case 'o':
|
||||
switch (char1) {
|
||||
case 'i':
|
||||
current = sect.sct_oil;
|
||||
current += amt;
|
||||
current = LIMIT_TO(current, 0, 100);
|
||||
resnoise(§, "Oil content", sect.sct_oil, current);
|
||||
sect.sct_oil = (unsigned char)current;
|
||||
ret = edit_sect_i(§, "c", sect.sct_oil + amt);
|
||||
break;
|
||||
break;
|
||||
case 'w':
|
||||
if ((amt < 0) || (amt > MAXNOC - 1))
|
||||
return RET_SYN;
|
||||
pr("Owner of %s changed from %s to %s.\n",
|
||||
xyas(sect.sct_x, sect.sct_y, player->cnum),
|
||||
prnatid(sect.sct_own), prnatid(amt));
|
||||
if (amt == sect.sct_own)
|
||||
break;
|
||||
if (sect.sct_own && sect.sct_own != player->cnum) {
|
||||
wu(0, sect.sct_own,
|
||||
"Sector %s taken from you by an act of %s!\n",
|
||||
xyas(sect.sct_x, sect.sct_y, sect.sct_own),
|
||||
cname(player->cnum));
|
||||
resbenefit(sect.sct_own, -1);
|
||||
}
|
||||
if (amt && amt != player->cnum) {
|
||||
wu(0, amt,
|
||||
"Sector %s given to you by an act of %s!\n",
|
||||
xyas(sect.sct_x, sect.sct_y, amt),
|
||||
cname(player->cnum));
|
||||
resbenefit(amt, 1);
|
||||
}
|
||||
sect.sct_own = (natid)amt;
|
||||
ret = edit_sect(§, "o", p);
|
||||
break;
|
||||
case 'l':
|
||||
if ((amt < 0) || (amt > MAXNOC - 1))
|
||||
return RET_SYN;
|
||||
pr("Old owner of %s changed from %s to %s.\n",
|
||||
xyas(sect.sct_x, sect.sct_y, player->cnum),
|
||||
prnatid(sect.sct_oldown), prnatid(amt));
|
||||
if (amt == sect.sct_oldown)
|
||||
break;
|
||||
if (sect.sct_own && sect.sct_own != player->cnum)
|
||||
wu(0, sect.sct_own,
|
||||
"Old owner of %s changed from %s to %s"
|
||||
" by an act of %s\n",
|
||||
xyas(sect.sct_x, sect.sct_y, player->cnum),
|
||||
prnatid(sect.sct_oldown), prnatid(amt),
|
||||
cname(player->cnum));
|
||||
sect.sct_oldown = (natid)amt;
|
||||
ret = edit_sect(§, "O", p);
|
||||
break;
|
||||
default:
|
||||
pr("huh?\n");
|
||||
|
@ -142,32 +92,15 @@ setsector(void)
|
|||
}
|
||||
break;
|
||||
case 'e':
|
||||
current = sect.sct_effic;
|
||||
current += amt;
|
||||
current = LIMIT_TO(current, 0, 100);
|
||||
resnoise(§, "Efficiency", sect.sct_effic, current);
|
||||
sect.sct_effic = current;
|
||||
ret = edit_sect_i(§, "e", sect.sct_effic + amt);
|
||||
break;
|
||||
case 'm':
|
||||
switch (char1) {
|
||||
case 'i':
|
||||
current = sect.sct_mines;
|
||||
current += amt;
|
||||
current = LIMIT_TO(current, 0, MINES_MAX);
|
||||
if (sect.sct_own == sect.sct_oldown)
|
||||
resnoise(§, "Mines", sect.sct_mines, current);
|
||||
else
|
||||
pr("Mines of %s changed from %d to %d\n",
|
||||
xyas(sect.sct_x, sect.sct_y, player->cnum),
|
||||
sect.sct_mines, current);
|
||||
sect.sct_mines = current;
|
||||
ret = edit_sect_i(§, "M", sect.sct_mines + amt);
|
||||
break;
|
||||
case 'o':
|
||||
current = sect.sct_mobil;
|
||||
current += amt;
|
||||
current = LIMIT_TO(current, -127, 127);
|
||||
resnoise(§, "Mobility", sect.sct_mobil, current);
|
||||
sect.sct_mobil = current;
|
||||
ret = edit_sect_i(§, "m", sect.sct_mobil + amt);
|
||||
break;
|
||||
default:
|
||||
pr("huh?\n");
|
||||
|
@ -175,58 +108,24 @@ setsector(void)
|
|||
}
|
||||
break;
|
||||
case 'a':
|
||||
current = sect.sct_avail;
|
||||
current += amt;
|
||||
current = LIMIT_TO(current, 0, 9999);
|
||||
resnoise(§, "Available workforce", sect.sct_avail, current);
|
||||
sect.sct_avail = (short)current;
|
||||
ret = edit_sect_i(§, "a", sect.sct_avail + amt);
|
||||
break;
|
||||
case 'w':
|
||||
current = sect.sct_work;
|
||||
current += amt;
|
||||
current = LIMIT_TO(current, 0, 100);
|
||||
resnoise(§, "Workforce percentage", sect.sct_work, current);
|
||||
sect.sct_work = (unsigned char)current;
|
||||
ret = edit_sect_i(§, "w", sect.sct_work + amt);
|
||||
break;
|
||||
case 'f':
|
||||
current = sect.sct_fertil;
|
||||
current += amt;
|
||||
current = LIMIT_TO(current, 0, 100);
|
||||
resnoise(§, "Fertility content", sect.sct_fertil, current);
|
||||
sect.sct_fertil = (unsigned char)current;
|
||||
ret = edit_sect_i(§, "f", sect.sct_fertil + amt);
|
||||
break;
|
||||
case 'u':
|
||||
current = sect.sct_uran;
|
||||
current += amt;
|
||||
current = LIMIT_TO(current, 0, 100);
|
||||
resnoise(§, "Uranium content", sect.sct_uran, current);
|
||||
sect.sct_uran = (unsigned char)current;
|
||||
ret = edit_sect_i(§, "u", sect.sct_uran + amt);
|
||||
break;
|
||||
default:
|
||||
pr("huh?\n");
|
||||
return RET_SYN;
|
||||
ret = RET_SYN;
|
||||
}
|
||||
if (ret != RET_OK)
|
||||
return ret;
|
||||
putsect(§);
|
||||
}
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
static void
|
||||
resbenefit(natid who, int goodness)
|
||||
{
|
||||
if (opt_GODNEWS && getnatp(who)->nat_stat != STAT_GOD && goodness)
|
||||
nreport(player->cnum, goodness > 0 ? N_AIDS : N_HURTS, who, 1);
|
||||
}
|
||||
|
||||
void
|
||||
resnoise(struct sctstr *sptr, char *name, int old, int new)
|
||||
{
|
||||
pr("%s of %s changed from %d to %d\n",
|
||||
name, xyas(sptr->sct_x, sptr->sct_y, player->cnum), old, new);
|
||||
if (sptr->sct_own && sptr->sct_own != player->cnum && new != old)
|
||||
wu(0, sptr->sct_own,
|
||||
"%s in %s was changed from %d to %d by an act of %s\n",
|
||||
name, xyas(sptr->sct_x, sptr->sct_y, sptr->sct_own),
|
||||
old, new, cname(player->cnum));
|
||||
resbenefit(sptr->sct_own, new - old);
|
||||
}
|
||||
|
|
|
@ -320,37 +320,37 @@
|
|||
Play#0 output Play#0 6 0 640
|
||||
Play#0 input setres f 2,2 0
|
||||
Play#0 command setresource
|
||||
Play#0 output Play#0 1 Fertility content of 2,2 changed from 0 to 0
|
||||
Play#0 output Play#0 1 Fertility of 2,2 changed from 0 to 0
|
||||
Play#0 output Play#0 6 0 640
|
||||
Play#0 input setres f 4,2 -1
|
||||
Play#0 command setresource
|
||||
Play#0 output Play#0 1 Fertility content of 4,2 changed from 0 to 0
|
||||
Play#0 output Play#0 1 Fertility of 4,2 changed from 0 to 0
|
||||
Play#0 output Play#0 6 0 640
|
||||
Play#0 input setres f 6,2 100
|
||||
Play#0 command setresource
|
||||
Play#0 output Play#0 1 Fertility content of 6,2 changed from 0 to 100
|
||||
Play#0 output Play#0 1 Fertility of 6,2 changed from 0 to 100
|
||||
Play#0 output Play#0 6 0 640
|
||||
Play#0 input setres f 8,2 101
|
||||
Play#0 command setresource
|
||||
Play#0 output Play#0 1 Fertility content of 8,2 changed from 0 to 100
|
||||
Play#0 output Play#0 1 Fertility of 8,2 changed from 0 to 100
|
||||
Play#0 output Play#0 6 0 640
|
||||
Play#0 input setsect f 1,3 -2147483648
|
||||
Play#0 command setsector
|
||||
Play#0 output Play#0 1 Fertility content of 1,3 changed from 0 to 0
|
||||
Play#0 output Play#0 1 Fertility of 1,3 changed from 0 to 0
|
||||
Play#0 output Play#0 6 0 640
|
||||
Play#0 input setsect f 3:7,3 1
|
||||
Play#0 command setsector
|
||||
Play#0 output Play#0 1 Fertility content of 3,3 changed from 0 to 1
|
||||
Play#0 output Play#0 1 Fertility content of 5,3 changed from 0 to 1
|
||||
Play#0 output Play#0 1 Fertility content of 7,3 changed from 0 to 1
|
||||
Play#0 output Play#0 1 Fertility of 3,3 changed from 0 to 1
|
||||
Play#0 output Play#0 1 Fertility of 5,3 changed from 0 to 1
|
||||
Play#0 output Play#0 1 Fertility of 7,3 changed from 0 to 1
|
||||
Play#0 output Play#0 6 0 640
|
||||
Play#0 input setsect f 5,3 2147483647
|
||||
Play#0 command setsector
|
||||
Play#0 output Play#0 1 Fertility content of 5,3 changed from 1 to 0
|
||||
Play#0 output Play#0 1 Fertility of 5,3 changed from 1 to 0
|
||||
Play#0 output Play#0 6 0 640
|
||||
Play#0 input setsect f 7,3 -1
|
||||
Play#0 command setsector
|
||||
Play#0 output Play#0 1 Fertility content of 7,3 changed from 1 to 0
|
||||
Play#0 output Play#0 1 Fertility of 7,3 changed from 1 to 0
|
||||
Play#0 output Play#0 6 0 640
|
||||
Play#0 input edit l 1,1 c 0
|
||||
Play#0 command edit
|
||||
|
@ -692,7 +692,7 @@
|
|||
Play#0 output Play#0 6 0 640
|
||||
Play#0 input setsect f -1,-1 50
|
||||
Play#0 command setsector
|
||||
Play#0 output Play#0 1 Fertility content of -1,-1 changed from 0 to 50
|
||||
Play#0 output Play#0 1 Fertility of -1,-1 changed from 0 to 50
|
||||
Play#0 output Play#0 6 0 640
|
||||
Play#0 input setsect ol 1:3,-3 1
|
||||
Play#0 command setsector
|
||||
|
@ -1543,13 +1543,13 @@
|
|||
Play#0 output Play#0 1 Gold content in 7,3 was changed from 1 to 0 by an act of POGO
|
||||
Play#0 output Play#0 1 Fertility in 5,1 was changed from 0 to 100 by an act of POGO
|
||||
Play#0 output Play#0 1 Fertility in 7,1 was changed from 0 to 100 by an act of POGO
|
||||
Play#0 output Play#0 1 Fertility content in 6,2 was changed from 0 to 100 by an act of POGO
|
||||
Play#0 output Play#0 1 Fertility content in 8,2 was changed from 0 to 100 by an act of POGO
|
||||
Play#0 output Play#0 1 Fertility content in 3,3 was changed from 0 to 1 by an act of POGO
|
||||
Play#0 output Play#0 1 Fertility content in 5,3 was changed from 0 to 1 by an act of POGO
|
||||
Play#0 output Play#0 1 Fertility content in 7,3 was changed from 0 to 1 by an act of POGO
|
||||
Play#0 output Play#0 1 Fertility content in 5,3 was changed from 1 to 0 by an act of POGO
|
||||
Play#0 output Play#0 1 Fertility content in 7,3 was changed from 1 to 0 by an act of POGO
|
||||
Play#0 output Play#0 1 Fertility in 6,2 was changed from 0 to 100 by an act of POGO
|
||||
Play#0 output Play#0 1 Fertility in 8,2 was changed from 0 to 100 by an act of POGO
|
||||
Play#0 output Play#0 1 Fertility in 3,3 was changed from 0 to 1 by an act of POGO
|
||||
Play#0 output Play#0 1 Fertility in 5,3 was changed from 0 to 1 by an act of POGO
|
||||
Play#0 output Play#0 1 Fertility in 7,3 was changed from 0 to 1 by an act of POGO
|
||||
Play#0 output Play#0 1 Fertility in 5,3 was changed from 1 to 0 by an act of POGO
|
||||
Play#0 output Play#0 1 Fertility in 7,3 was changed from 1 to 0 by an act of POGO
|
||||
Play#0 output Play#0 1 Oil content in 5,1 was changed from 0 to 100 by an act of POGO
|
||||
Play#0 output Play#0 1 Oil content in 7,1 was changed from 0 to 100 by an act of POGO
|
||||
Play#0 output Play#0 1 Oil content in 6,2 was changed from 0 to 100 by an act of POGO
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue