]> git.pond.sub.org Git - empserver/blobdiff - src/lib/commands/arm.c
arm: Rework "cannot carry nukes" test for robustness
[empserver] / src / lib / commands / arm.c
index 61ccc2ef5a014751a5b12e79aef383f13a5a8355..74ea9485eb69487f22b8a614e740f349efbed02c 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2011, 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
@@ -30,7 +30,7 @@
  *     Dave Pare, 1986
  *     Ken Stevens, 1995
  *     Steve McClure, 2000
- *     Markus Armbruster, 2006-2011
+ *     Markus Armbruster, 2006-2021
  */
 
 #include <config.h>
@@ -61,11 +61,13 @@ arm(void)
            && relations_with(pl.pln_own, player->cnum) != ALLIED)
            continue;
        plc = &plchr[(int)pl.pln_type];
-       if ((plc->pl_flags & (P_O | P_N | P_MAR))
-           || (plc->pl_flags & (P_M | P_F)) == (P_M | P_F)) {
+       if (!(plc->pl_flags & (P_B | P_T | P_C))
+           || (plc->pl_flags & P_MAR)) {
            pr("A %s cannot carry nuclear devices!\n", plc->pl_name);
            return RET_FAIL;
        }
+       if (CANT_HAPPEN(pl.pln_flags & PLN_LAUNCHED))
+           continue;
        if (opt_MARKET) {
            if (ontradingblock(EF_PLANE, &pl)) {
                pr("You cannot arm %s while it is on the trading block!\n",
@@ -102,6 +104,11 @@ 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 == 'y' || *p == 'Y')
            pl.pln_flags |= PLN_AIRBURST;
@@ -140,6 +147,8 @@ disarm(void)
            continue;
        if (!getnuke(nuk_on_plane(&pl), &nuke))
            continue;
+       if (CANT_HAPPEN(pl.pln_flags & PLN_LAUNCHED))
+           continue;
        if (opt_MARKET) {
            if (ontradingblock(EF_PLANE, &pl)) {
                pr("You cannot disarm %s while it is on the trading block!\n",