]> git.pond.sub.org Git - empserver/blobdiff - src/lib/commands/edit.c
Update copyright notice
[empserver] / src / lib / commands / edit.c
index 41a450e76562ed7f8349171313b792761ea4ef5e..9ba0410f5e5f3253cf1f3d1fb29b782ed13959ae 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2014, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *  Copyright (C) 1986-2017, 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-2013
+ *     Markus Armbruster, 2003-2016
  */
 
 #include <config.h>
@@ -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
@@ -559,8 +549,14 @@ edit_sect(struct sctstr *sect, char *key, char *p)
                         newsect.sct_own);
        report_god_gives("Sector ", xyas(newx, newy, sect->sct_own),
                         sect->sct_own);
+       if (sect->sct_x == sect->sct_dist_x
+           && sect->sct_y == sect->sct_dist_y) {
+           sect->sct_dist_x = newx;
+           sect->sct_dist_y = newy;
+       }
        sect->sct_x = newx;
        sect->sct_y = newy;
+       sect->sct_coastal = newsect.sct_coastal;
        ef_set_uid(EF_SECTOR, sect, XYOFFSET(newx, newy));
        break;
     case 'D':
@@ -798,7 +794,7 @@ edit_unit(struct empobj *unit, char *key, char *p,
            return RET_FAIL;
        }
        divine_unit_change_quiet(unit, "Location",
-                                unit->own && unit->own != player->cnum,
+                                newx != unit->x || newy != unit->y,
                                 "from %s to %s",
                                 xyas(unit->x, unit->y, player->cnum),
                                 xyas(newx, newy, player->cnum));
@@ -811,8 +807,7 @@ edit_unit(struct empobj *unit, char *key, char *p,
               xyas(unit->x, unit->y, unit->own),
               xyas(newx, newy, unit->own),
               cname(player->cnum));
-       unit->x = newx;
-       unit->y = newy;
+       unit_teleport(unit, newx, newy);
        break;
     case 'E':
        arg = LIMIT_TO(arg, mineff, 100);
@@ -879,6 +874,7 @@ edit_ship(struct shpstr *ship, char *key, char *p)
 {
     struct mchrstr *mcp = &mchr[ship->shp_type];
     int arg = atoi(p);
+    int ret;
 
     switch (*key) {
     case 'U':
@@ -887,8 +883,9 @@ edit_ship(struct shpstr *ship, char *key, char *p)
     case 'E':
     case 'M':
     case 'F':
-       return edit_unit((struct empobj *)ship, key, p,
-                        SHIP_MINEFF, "fleet", 0);
+       ret = edit_unit((struct empobj *)ship, key, p,
+                       SHIP_MINEFF, "fleet", 0);
+       return ret;
     case 't':
        arg = ef_elt_byname(EF_SHIP_CHR, p);
        if (arg < 0) {
@@ -898,12 +895,12 @@ edit_ship(struct shpstr *ship, char *key, char *p)
        divine_unit_change((struct empobj *)ship, "Type",
                           arg != ship->shp_type, 0,
                           "to %s", mchr[arg].m_name);
+       if (ship->shp_tech < mchr[arg].m_tech)
+           shp_set_tech(ship, mchr[arg].m_tech);
        ship->shp_type = arg;
+       shp_set_tech(ship, ship->shp_tech);
        limit_item((struct empobj *)ship, ship->shp_item, mchr[arg].m_item);
-       if (ship->shp_tech >= mchr[arg].m_tech)
-           break;
-       arg = mchr[arg].m_tech;
-       /* fall through */
+       break;
     case 'T':
        arg = LIMIT_TO(arg, mcp->m_tech, SHRT_MAX);
        divine_unit_change((struct empobj *)ship, "Tech level",
@@ -985,12 +982,12 @@ edit_land(struct lndstr *land, char *key, char *p)
        divine_unit_change((struct empobj *)land, "Type",
                           arg != land->lnd_type, 0,
                           "to %s", lchr[arg].l_name);
+       if (land->lnd_tech < lchr[arg].l_tech)
+           lnd_set_tech(land, lchr[arg].l_tech);
        land->lnd_type = arg;
+       lnd_set_tech(land, land->lnd_tech);
        limit_item((struct empobj *)land, land->lnd_item, lchr[arg].l_item);
-       if (land->lnd_tech >= lchr[arg].l_tech)
-           break;
-       arg = lchr[arg].l_tech;
-       /* fall through */
+       break;
     case 't':
        arg = LIMIT_TO(arg, lcp->l_tech, SHRT_MAX);
        divine_unit_change((struct empobj *)land, "Tech level",
@@ -1035,6 +1032,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",
@@ -1102,11 +1113,14 @@ edit_plane(struct plnstr *plane, char *key, char *p)
        divine_unit_change((struct empobj *)plane, "Type",
                           arg != plane->pln_type, 0,
                           "to %s", plchr[arg].pl_name);
+       if (plane->pln_tech < plchr[arg].pl_tech)
+           pln_set_tech(plane, plchr[arg].pl_tech);
+       if (plane->pln_range >= pln_range_max(plane))
+           /* preserve unlimited range, pln_set_tech() will adjust */
+           plane->pln_range = UCHAR_MAX;
        plane->pln_type = arg;
-       if (plane->pln_tech >= plchr[arg].pl_tech)
-           break;
-       arg = plchr[arg].pl_tech;
-       /* fall through */
+       pln_set_tech(plane, plane->pln_tech);
+       break;
     case 't':
        arg = LIMIT_TO(arg, pcp->pl_tech, SHRT_MAX);
        divine_unit_change((struct empobj *)plane, "Tech level",
@@ -1185,11 +1199,10 @@ edit_nuke(struct nukstr *nuke, char *key, char *p)
        divine_unit_change((struct empobj *)nuke, "Type",
                           arg != nuke->nuk_type, 0,
                           "to %s", nchr[arg].n_name);
+       if (nuke->nuk_tech < nchr[arg].n_tech)
+           nuke->nuk_tech = nchr[arg].n_tech;
        nuke->nuk_type = arg;
-       if (nuke->nuk_tech >= nchr[arg].n_tech)
-           break;
-       arg = nchr[arg].n_tech;
-       /* fall through */
+       break;
     case 'T':
        arg = LIMIT_TO(arg, ncp->n_tech, SHRT_MAX);
        divine_unit_change((struct empobj *)nuke, "Tech level",