]> git.pond.sub.org Git - empserver/blobdiff - src/lib/commands/edit.c
commands: Rename the command functions
[empserver] / src / lib / commands / edit.c
index a51f25623240cab431cc2aa6f9c4e91645664e75..80683694a160c04c45452c4005624a6792a78d49 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2015, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *  Copyright (C) 1986-2021, Dave Pare, Jeff Bailey, Thomas Ruschak,
  *                Ken Stevens, Steve McClure, Markus Armbruster
  *
  *  Empire is free software: you can redistribute it and/or modify
@@ -31,7 +31,7 @@
  *     Chad Zabel, 1994
  *     Steve McClure, 1998-2000
  *     Ron Koenderink, 2003-2009
- *     Markus Armbruster, 2003-2015
+ *     Markus Armbruster, 2003-2018
  */
 
 #include <config.h>
@@ -63,7 +63,7 @@ static int edit_plane(struct plnstr *, char *, char *);
 static int edit_nuke(struct nukstr *, char *, char *);
 
 int
-edit(void)
+c_edit(void)
 {
     union empobj_storage item;
     char *what;
@@ -226,8 +226,6 @@ print_sect(struct sctstr *sect)
 static void
 print_nat(struct natstr *np)
 {
-    int i;
-
     pr("Country #: %2d\n", np->nat_cnum);
     pr("Name <n>: %-20s\t", np->nat_cnam);
     pr("Representative <r>: %s\n", np->nat_pnam);
@@ -245,14 +243,6 @@ print_nat(struct natstr *np)
     pr("Happiness <H>: %.2f\n", np->nat_level[NAT_HLEV]);
     pr("Money <M>: $%6d\n", np->nat_money);
     pr("Telegrams <t>: %6d\n", np->nat_tgms);
-    if (opt_HIDDEN) {
-       pr("Countries contacted: ");
-       for (i = 0; i < MAXNOC; i++) {
-           if (getcontact(np, i))
-               pr("%d(%d) ", i, getcontact(np, i));
-       }
-       pr("\n");
-    }
 }
 
 static void
@@ -274,6 +264,28 @@ print_plane(struct plnstr *plane)
     pr("Land Unit <y>: %d\n", plane->pln_land);
 }
 
+static void
+print_items(short item[])
+{
+    pr("  civ  mil   uw food   sh  gun  pet iron dust  bar  oil  lcm  hcm  rad\n"
+       "    c    m    u    f    s    g    p    i    d    B    o    l    h    r\n"
+       "%5d%5d%5d%5d%5d%5d%5d%5d%5d%5d%5d%5d%5d%5d\n",
+       item[I_CIVIL],
+       item[I_MILIT],
+       item[I_UW],
+       item[I_FOOD],
+       item[I_SHELL],
+       item[I_GUN],
+       item[I_PETROL],
+       item[I_IRON],
+       item[I_DUST],
+       item[I_BAR],
+       item[I_OIL],
+       item[I_LCM],
+       item[I_HCM],
+       item[I_RAD]);
+}
+
 static void
 print_land(struct lndstr *land)
 {
@@ -292,22 +304,7 @@ print_land(struct lndstr *land)
     pr("Retreat percentage <Z>: %d\n", land->lnd_retreat);
     pr("Retreat path <R>: '%s'\t\tRetreat Flags <W>: %d\n",
        land->lnd_rpath, land->lnd_rflags);
-    pr("civ mil  uw food shl gun  pet  irn  dst  oil  lcm  hcm rad\n");
-    pr("  c   m   u    f   s   g    p    i    d    o    l    h   r\n");
-    pr("%3d", land->lnd_item[I_CIVIL]);
-    pr("%4d", land->lnd_item[I_MILIT]);
-    pr("%4d", land->lnd_item[I_UW]);
-    pr("%5d", land->lnd_item[I_FOOD]);
-    pr("%4d", land->lnd_item[I_SHELL]);
-    pr("%4d", land->lnd_item[I_GUN]);
-    pr("%5d", land->lnd_item[I_PETROL]);
-    pr("%5d", land->lnd_item[I_IRON]);
-    pr("%5d", land->lnd_item[I_DUST]);
-    pr("%5d", land->lnd_item[I_OIL]);
-    pr("%5d", land->lnd_item[I_LCM]);
-    pr("%5d", land->lnd_item[I_HCM]);
-    pr("%4d", land->lnd_item[I_RAD]);
-    pr("\n");
+    print_items(land->lnd_item);
 }
 
 static void
@@ -326,22 +323,7 @@ print_ship(struct shpstr *ship)
        ship->shp_rpath, ship->shp_rflags);
     pr("Plague Stage <a>: %d\t\t", ship->shp_pstage);
     pr("Plague Time <b>: %d\n", ship->shp_ptime);
-    pr("civ mil  uw food shl gun  pet  irn  dst  oil  lcm  hcm rad\n");
-    pr("  c   m   u    f   s   g    p    i    d    o    l    h   r\n");
-    pr("%3d", ship->shp_item[I_CIVIL]);
-    pr("%4d", ship->shp_item[I_MILIT]);
-    pr("%4d", ship->shp_item[I_UW]);
-    pr("%5d", ship->shp_item[I_FOOD]);
-    pr("%4d", ship->shp_item[I_SHELL]);
-    pr("%4d", ship->shp_item[I_GUN]);
-    pr("%5d", ship->shp_item[I_PETROL]);
-    pr("%5d", ship->shp_item[I_IRON]);
-    pr("%5d", ship->shp_item[I_DUST]);
-    pr("%5d", ship->shp_item[I_OIL]);
-    pr("%5d", ship->shp_item[I_LCM]);
-    pr("%5d", ship->shp_item[I_HCM]);
-    pr("%4d", ship->shp_item[I_RAD]);
-    pr("\n");
+    print_items(ship->shp_item);
 }
 
 static void
@@ -465,7 +447,7 @@ edit_sect_i(struct sctstr *sect, char *key, int arg)
        break;
     case 'x':
        new = LIMIT_TO(arg, 0, CHE_MAX);
-       divine_sct_change_quiet(sect, "Guerillas", new != sect->sct_che,
+       divine_sct_change_quiet(sect, "Guerrillas", new != sect->sct_che,
                                "from %d to %d", sect->sct_che, new);
        sect->sct_che = new;
        break;
@@ -868,6 +850,17 @@ edit_item(struct empobj *unit, short item[], struct ichrstr *ip, int arg,
     item[ip->i_uid] = arg;
 }
 
+static void
+edit_unit_item(struct empobj *unit, short item[], char *key, int arg,
+              short lim[])
+{
+    char lowkey[2];
+
+    lowkey[0] = tolower(*key);
+    lowkey[1] = 0;
+    edit_item(unit, item, item_by_name(lowkey), arg, lim);
+}
+
 static void
 limit_item(struct empobj *unit, short item[], short lim[])
 {
@@ -953,12 +946,13 @@ edit_ship(struct shpstr *ship, char *key, char *p)
     case 'p':
     case 'i':
     case 'd':
+    case 'B':
     case 'o':
     case 'l':
     case 'h':
     case 'r':
-       edit_item((struct empobj *)ship, ship->shp_item, item_by_name(key),
-                 arg, mcp->m_item);
+       edit_unit_item((struct empobj *)ship, ship->shp_item, key, arg,
+                      mcp->m_item);
        break;
     default:
        pr("huh? (%s)\n", key);
@@ -1007,6 +1001,8 @@ edit_land(struct lndstr *land, char *key, char *p)
        break;
     case 'F':
        arg = LIMIT_TO(arg, 0, 127);
+       if (land->lnd_ship >= 0 || land->lnd_land >= 0)
+           arg = 0;
        divine_unit_change((struct empobj *)land, "Fortification",
                           arg != land->lnd_harden, arg - land->lnd_harden,
                           "from %d to %d", land->lnd_harden, arg);
@@ -1042,6 +1038,20 @@ edit_land(struct lndstr *land, char *key, char *p)
        divine_load((struct empobj *)land, EF_LAND, arg);
        land->lnd_land = arg;
        break;
+    case 'A':
+       arg = LIMIT_TO(arg, 0, PLG_EXPOSED);
+       divine_unit_change_quiet((struct empobj *)land, "Plague stage",
+                                arg != land->lnd_pstage,
+                                "from %d to %d", land->lnd_pstage, arg);
+       land->lnd_pstage = arg;
+       break;
+    case 'b':
+       arg = LIMIT_TO(arg, 0, 32767);
+       divine_unit_change_quiet((struct empobj *)land, "Plague time",
+                                arg != land->lnd_ptime,
+                                "from %d to %d", land->lnd_ptime, arg);
+       land->lnd_ptime = arg;
+       break;
     case 'Z':
        arg = LIMIT_TO(arg, 0, 100);
        divine_unit_change((struct empobj *)land, "Retreat percentage",
@@ -1070,12 +1080,13 @@ edit_land(struct lndstr *land, char *key, char *p)
     case 'p':
     case 'i':
     case 'd':
+    case 'B':
     case 'o':
     case 'l':
     case 'h':
     case 'r':
-       edit_item((struct empobj *)land, land->lnd_item, item_by_name(key),
-                 arg, lcp->l_item);
+       edit_unit_item((struct empobj *)land, land->lnd_item, key, arg,
+                      lcp->l_item);
        break;
     default:
        pr("huh? (%s)\n", key);
@@ -1124,6 +1135,16 @@ edit_plane(struct plnstr *plane, char *key, char *p)
                           "from %d to %d", plane->pln_tech, arg);
        pln_set_tech(plane, arg);
        break;
+    case 'F':
+       arg = LIMIT_TO(arg, 0, 127);
+       if (!(pcp->pl_flags & P_M)
+           || plane->pln_ship >= 0 || plane->pln_land >= 0)
+           arg = 0;
+       divine_unit_change((struct empobj *)plane, "Fortification",
+                          arg != plane->pln_harden, arg - plane->pln_harden,
+                          "from %d to %d", plane->pln_harden, arg);
+       plane->pln_harden = arg;
+       break;
     case 'r':
        arg = LIMIT_TO(arg, 0, pl_range(pcp, plane->pln_tech));
        divine_unit_change((struct empobj *)plane, "Range",
@@ -1165,6 +1186,8 @@ edit_plane(struct plnstr *plane, char *key, char *p)
        divine_flag_change((struct empobj *)plane, "Flags",
                           plane->pln_flags, arg, plane_flags);
        plane->pln_flags = arg;
+       if (pln_is_in_orbit(plane))
+           plane->pln_ship = plane->pln_land = -1;
        break;
     default:
        pr("huh? (%s)\n", key);