]> git.pond.sub.org Git - empserver/blobdiff - src/lib/commands/arm.c
Update copyright notice
[empserver] / src / lib / commands / arm.c
index b2975fa070f141d17b849e9200a735342d24944d..62b30abaa6bf170dd6799332664a9124fadb9112 100644 (file)
@@ -1,11 +1,11 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2006, Dave Pare, Jeff Bailey, Thomas Ruschak,
- *                           Ken Stevens, Steve McClure
+ *  Copyright (C) 1986-2020, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *                Ken Stevens, Steve McClure, Markus Armbruster
  *
- *  This program is free software; you can redistribute it and/or modify
+ *  Empire is free software: you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
+ *  the Free Software Foundation, either version 3 of the License, or
  *  (at your option) any later version.
  *
  *  This program is distributed in the hope that it will be useful,
@@ -14,8 +14,7 @@
  *  GNU General Public License for more details.
  *
  *  You should have received a copy of the GNU General Public License
- *  along with this program; if not, write to the Free Software
- *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
  *
  *  ---
  *
  *  ---
  *
  *  arm.c: Arm planes (missiles) with nuclear devices
- * 
+ *
  *  Known contributors to this file:
  *     Dave Pare, 1986
  *     Ken Stevens, 1995
  *     Steve McClure, 2000
- *     Markus Armbruster, 2006
+ *     Markus Armbruster, 2006-2011
  */
 
 #include <config.h>
 
+#include <stdio.h>
 #include "commands.h"
 #include "nuke.h"
 #include "optlist.h"
@@ -54,14 +54,15 @@ arm(void)
     char buf[1024];
     char prompt[128];
 
-    if (!snxtitem(&ni, EF_PLANE, player->argp[1]))
+    if (!snxtitem(&ni, EF_PLANE, player->argp[1], NULL))
        return RET_SYN;
     while (nxtitem(&ni, &pl)) {
        if (!player->owner
-           && getrel(getnatp(pl.pln_own), player->cnum) != ALLIED)
+           && relations_with(pl.pln_own, player->cnum) != ALLIED)
            continue;
        plc = &plchr[(int)pl.pln_type];
-       if ((plc->pl_flags & (P_O | P_M)) == (P_O | P_M)) {
+       if ((plc->pl_flags & (P_O | P_N | P_MAR))
+           || (plc->pl_flags & (P_M | P_F)) == (P_M | P_F)) {
            pr("A %s cannot carry nuclear devices!\n", plc->pl_name);
            return RET_FAIL;
        }
@@ -72,7 +73,7 @@ arm(void)
                return RET_FAIL;
            }
        }
-       if (pl.pln_nuketype < 0) {
+       if (!getnuke(nuk_on_plane(&pl), &nuke)) {
            sprintf(prompt, "Nuclear device for %s: ", prplane(&pl));
            p = getstarg(player->argp[2], prompt, buf);
            if (!p || !*p)
@@ -82,19 +83,16 @@ arm(void)
            nukno = atoi(p);
            if (!getnuke(nukno, &nuke) || !player->owner)
                return RET_FAIL;
-       } else {
-           if (nuk_on_plane(&nuke, pl.pln_uid) < 0) {
-               CANT_REACH();
-               continue;
-           }
        }
        ncp = &nchr[nuke.nuk_type];
-       if (pl.pln_load < ncp->n_weight) {
+       if (pln_load(&pl) < ncp->n_weight) {
            pr("A %s cannot carry %s devices!\n",
               plc->pl_name, ncp->n_name);
            return RET_FAIL;
        }
        p = getstarg(player->argp[3], "Airburst [n]? ", buf);
+       if (!p)
+           return RET_FAIL;
 
        if (!check_plane_ok(&pl) || !check_nuke_ok(&nuke))
            return RET_FAIL;
@@ -104,16 +102,21 @@ arm(void)
               prnuke(&nuke), nuke.nuk_plane);
            return RET_FAIL;
        }
+       if (nuke.nuk_x != pl.pln_x || nuke.nuk_y != pl.pln_y) {
+           pr("%s isn't in the same sector as %s!\n",
+              prnuke(&nuke), prplane(&pl));
+           return RET_FAIL;
+       }
 
-       if (p && (*p == 'y' || *p == 'Y'))
+       if (*p == 'y' || *p == 'Y')
            pl.pln_flags |= PLN_AIRBURST;
        else
            pl.pln_flags &= ~PLN_AIRBURST;
+       pl.pln_mission = 0;
 
        snprintf(buf, sizeof(buf), "armed on your %s in %s",
                 prplane(&pl), xyas(pl.pln_x, pl.pln_y, pl.pln_own));
        gift(pl.pln_own, player->cnum, &nuke, buf);
-       pl.pln_nuketype = nuke.nuk_type;
        nuke.nuk_plane = pl.pln_uid;
        putplane(pl.pln_uid, &pl);
        putnuke(nuke.nuk_uid, &nuke);
@@ -135,12 +138,12 @@ disarm(void)
     struct sctstr sect;
     char buf[128];
 
-    if (!snxtitem(&ni, EF_PLANE, player->argp[1]))
+    if (!snxtitem(&ni, EF_PLANE, player->argp[1], NULL))
        return RET_SYN;
     while (nxtitem(&ni, &pl)) {
        if (!player->owner)
            continue;
-       if (pl.pln_nuketype == -1)
+       if (!getnuke(nuk_on_plane(&pl), &nuke))
            continue;
        if (opt_MARKET) {
            if (ontradingblock(EF_PLANE, &pl)) {
@@ -149,13 +152,9 @@ disarm(void)
                return RET_FAIL;
            }
        }
-       if (nuk_on_plane(&nuke, pl.pln_uid) < 0) {
-           CANT_REACH();
-           continue;
-       }
        getsect(nuke.nuk_x, nuke.nuk_y, &sect);
        if (!player->owner
-           && getrel(getnatp(sect.sct_own), player->cnum) != ALLIED) {
+           && relations_with(sect.sct_own, player->cnum) != ALLIED) {
            pr("Disarming %s in sector %s requires an alliance!\n",
               prplane(&pl), xyas(sect.sct_x, sect.sct_y, player->cnum));
            continue;
@@ -165,7 +164,6 @@ disarm(void)
                 xyas(sect.sct_x, sect.sct_y, sect.sct_own));
        gift(sect.sct_own, player->cnum, &nuke, buf);
        nuke.nuk_plane = -1;
-       pl.pln_nuketype = -1;
        pl.pln_flags &= ~PLN_AIRBURST;
        putplane(pl.pln_uid, &pl);
        putnuke(nuke.nuk_uid, &nuke);