]> git.pond.sub.org Git - empserver/blobdiff - src/lib/commands/tran.c
Fix sloppy sanity check for mobility going negative in transport
[empserver] / src / lib / commands / tran.c
index 512288aa32086938152db932362deda2c50fbc6f..a3335ed5057fb2611df4060bb7a8dbe6c7397035 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2006, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *  Copyright (C) 1986-2009, Dave Pare, Jeff Bailey, Thomas Ruschak,
  *                           Ken Stevens, Steve McClure
  *
  *  This program is free software; you can redistribute it and/or modify
  *  ---
  *
  *  tran.c: Transport nuclear devices and planes
- * 
+ *
  *  Known contributors to this file:
  *     Steve McClure, 2000
- *     Markus Armbruster, 2006
+ *     Markus Armbruster, 2006-2009
  */
 
 #include <config.h>
 
-#include <string.h>
-#include "misc.h"
-#include "player.h"
-#include "sect.h"
+#include "commands.h"
+#include "land.h"
 #include "nuke.h"
-#include "xy.h"
-#include "nsc.h"
 #include "plane.h"
 #include "ship.h"
-#include "file.h"
-#include "nat.h"
-#include "land.h"
-#include "commands.h"
 
-static int tran_map(coord curx, coord cury, char *arg);
+static int tran_pmap(coord curx, coord cury, char *arg);
+static int tran_nmap(coord curx, coord cury, char *arg);
 static int tran_nuke(void);
 static int tran_plane(void);
 
@@ -60,7 +53,7 @@ tran(void)
 
     what = getstarg(player->argp[1], "transport what (nuke or plane): ",
                    buf);
-    if (what == 0)
+    if (!what)
        return RET_SYN;
     if (*what == 'n')
        return tran_nuke();
@@ -84,7 +77,7 @@ tran_nuke(void)
 
     weight = 0;
     count = 0;
-    if (!snxtitem(&nstr, EF_NUKE, player->argp[2]))
+    if (!snxtitem(&nstr, EF_NUKE, player->argp[2], NULL))
        return RET_SYN;
     while (nxtitem(&nstr, &nuke)) {
        if (!player->owner)
@@ -107,7 +100,7 @@ tran_nuke(void)
        ++count;
     }
     if (count == 0) {
-       pr("No planes\n");
+       pr("No nukes\n");
        return RET_FAIL;
     }
     if (!getsect(srcx, srcy, &sect) || !player->owner) {
@@ -120,7 +113,7 @@ tran_nuke(void)
     }
     dam = 0;
     mcost = move_ground(&sect, &endsect, weight,
-                       player->argp[3], tran_map, 0, &dam);
+                       player->argp[3], tran_nmap, 0, &dam);
     if (mcost < 0)
        return 0;
 
@@ -141,8 +134,9 @@ tran_nuke(void)
     else
        pr("No mobility used\n");
     getsect(srcx, srcy, &sect);
-    sect.sct_mobil -= mcost;
-    if (sect.sct_mobil < 0)
+    if (sect.sct_mobil >= mcost)
+       sect.sct_mobil -= mcost;
+    else
        sect.sct_mobil = 0;
     putsect(&sect);
     return RET_OK;
@@ -163,7 +157,7 @@ tran_plane(void)
 
     weight = 0;
     count = 0;
-    if (!snxtitem(&nstr, EF_PLANE, player->argp[2]))
+    if (!snxtitem(&nstr, EF_PLANE, player->argp[2], NULL))
        return RET_SYN;
     /*
      * First do some sanity checks: make sure that they are all in the,
@@ -182,8 +176,7 @@ tran_plane(void)
            pr("%s has been hardened and can't be transported\n",
               prplane(&plane));
            return RET_FAIL;
-       } else if ((plane.pln_flags & PLN_LAUNCHED) &&
-                  (plchr[type].pl_flags & P_O)) {
+       } else if (pln_is_in_orbit(&plane)) {
            pr("%s is in space and can't be transported\n",
               prplane(&plane));
            return RET_FAIL;
@@ -214,7 +207,7 @@ tran_plane(void)
     }
     dam = 1;
     mcost = move_ground(&sect, &endsect, weight,
-                       player->argp[3], tran_map, 0, &dam);
+                       player->argp[3], tran_pmap, 0, &dam);
     dam /= count;
     if (mcost < 0)
        return 0;
@@ -237,8 +230,9 @@ tran_plane(void)
     else
        pr("No mobility used\n");
     getsect(srcx, srcy, &sect);
-    sect.sct_mobil -= mcost;
-    if (sect.sct_mobil < 0)
+    if (sect.sct_mobil >= mcost)
+       sect.sct_mobil -= mcost;
+    else
        sect.sct_mobil = 0;
     putsect(&sect);
     return RET_OK;
@@ -251,11 +245,14 @@ tran_plane(void)
  */
 /*ARGSUSED*/
 static int
-tran_map(coord curx, coord cury, char *arg)
+tran_pmap(coord curx, coord cury, char *arg)
+{
+    return display_region_map(0, EF_PLANE, curx, cury, arg);
+}
+
+static int
+tran_nmap(coord curx, coord cury, char *arg)
 {
-    player->argp[0] = "map";
-    player->argp[1] = arg;
-    player->argp[2] = NULL;
-    player->condarg = NULL;
-    return map();
+    return display_region_map(0, EF_NUKE, curx, cury, arg);
 }
+