]> git.pond.sub.org Git - empserver/commitdiff
setsector setresource: Switch to edit_sect()
authorMarkus Armbruster <armbru@pond.sub.org>
Sat, 26 Jan 2013 14:54:54 +0000 (15:54 +0100)
committerMarkus Armbruster <armbru@pond.sub.org>
Thu, 6 Jun 2013 17:55:01 +0000 (19:55 +0200)
One copy of the code suffices.

"Fertility content" becomes just "Fertility" in messages.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
include/prototypes.h
src/lib/commands/edit.c
src/lib/commands/setres.c
src/lib/commands/setsect.c
tests/actofgod/journal.log

index 517a142fe1e848b171c60356a970cb361e4fa3a5..ca38d2f2d722ef386e4cc5e0336dbb19a7a6d242 100644 (file)
@@ -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 *);
index 6d01ed570d91c3458dcb623ba927c7bc802d9444..4842ecffe14d2bb23974681d90cc74d5e0cce4f3 100644 (file)
@@ -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;
index 7d479003aba31eb1de2a991bfb2dcfe7b9a3c750..a20378710d427d3cae416f3668d630aa11f35e24 100644 (file)
@@ -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(&sect))
            return RET_FAIL;
        switch (char0) {
        case 'i':
-           resnoise(&sect, "Iron ore content", sect.sct_min, amt);
-           sect.sct_min = (unsigned char)amt;
+           ret = edit_sect(&sect, "i", p);
            break;
        case 'g':
-           resnoise(&sect, "Gold content", sect.sct_gmin, amt);
-           sect.sct_gmin = (unsigned char)amt;
+           ret = edit_sect(&sect, "g", p);
            break;
        case 'o':
-           resnoise(&sect, "Oil content", sect.sct_oil, amt);
-           sect.sct_oil = (unsigned char)amt;
+           ret = edit_sect(&sect, "c", p);
            break;
        case 'f':
-           resnoise(&sect, "Fertility content", sect.sct_fertil, amt);
-           sect.sct_fertil = (unsigned char)amt;
+           ret = edit_sect(&sect, "f", p);
            break;
        case 'u':
-           resnoise(&sect, "Uranium content", sect.sct_uran, amt);
-           sect.sct_uran = (unsigned char)amt;
+           ret = edit_sect(&sect, "u", p);
            break;
        default:
            pr("huh?\n");
-           return RET_SYN;
+           ret = RET_SYN;
        }
+       if (ret != RET_OK)
+           return ret;
        putsect(&sect);
     }
     return RET_OK;
index 12ff7b93ddfaf076980486aa5defdb5619844666..d00ee57734f260bd70ec4ab5e5ca16af70da0a2a 100644 (file)
 #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(&sect, "Iron ore content", sect.sct_min, current);
-           sect.sct_min = (unsigned char)current;
+           ret = edit_sect_i(&sect, "i", sect.sct_min + amt);
            break;
        case 'g':
-           current = sect.sct_gmin;
-           current += amt;
-           current = LIMIT_TO(current, 0, 100);
-           resnoise(&sect, "Gold content", sect.sct_gmin, current);
-           sect.sct_gmin = (unsigned char)current;
+           ret = edit_sect_i(&sect, "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(&sect, "Oil content", sect.sct_oil, current);
-               sect.sct_oil = (unsigned char)current;
+               ret = edit_sect_i(&sect, "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(&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(&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(&sect, "Efficiency", sect.sct_effic, current);
-           sect.sct_effic = current;
+           ret = edit_sect_i(&sect, "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(&sect, "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(&sect, "M", sect.sct_mines + amt);
                break;
            case 'o':
-               current = sect.sct_mobil;
-               current += amt;
-               current = LIMIT_TO(current, -127, 127);
-               resnoise(&sect, "Mobility", sect.sct_mobil, current);
-               sect.sct_mobil = current;
+               ret = edit_sect_i(&sect, "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(&sect, "Available workforce", sect.sct_avail, current);
-           sect.sct_avail = (short)current;
+           ret = edit_sect_i(&sect, "a", sect.sct_avail + amt);
            break;
        case 'w':
-           current = sect.sct_work;
-           current += amt;
-           current = LIMIT_TO(current, 0, 100);
-           resnoise(&sect, "Workforce percentage", sect.sct_work, current);
-           sect.sct_work = (unsigned char)current;
+           ret = edit_sect_i(&sect, "w", sect.sct_work + amt);
            break;
        case 'f':
-           current = sect.sct_fertil;
-           current += amt;
-           current = LIMIT_TO(current, 0, 100);
-           resnoise(&sect, "Fertility content", sect.sct_fertil, current);
-           sect.sct_fertil = (unsigned char)current;
+           ret = edit_sect_i(&sect, "f", sect.sct_fertil + amt);
            break;
        case 'u':
-           current = sect.sct_uran;
-           current += amt;
-           current = LIMIT_TO(current, 0, 100);
-           resnoise(&sect, "Uranium content", sect.sct_uran, current);
-           sect.sct_uran = (unsigned char)current;
+           ret = edit_sect_i(&sect, "u", sect.sct_uran + amt);
            break;
        default:
            pr("huh?\n");
-           return RET_SYN;
+           ret = RET_SYN;
        }
+       if (ret != RET_OK)
+           return ret;
        putsect(&sect);
     }
     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);
-}
index c14278f7bfc8c656fd57d2af81f714b25fb6e9db..a768be0754fc22c866f4fedf2d4613b90e633731 100644 (file)
     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
     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
     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