]> git.pond.sub.org Git - empserver/blobdiff - src/lib/subs/move.c
move_ground: Fix getsect() error checking
[empserver] / src / lib / subs / move.c
index 0d7de92ac88a2ee2df0de2b4c86d44d3476b418e..95ac4e820789481702e2fe564047832860e192a0 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
  *  move.c: Move something somewhere.
  *
  *  Known contributors to this file:
- *     Markus Armbruster, 2004-2011
+ *     Markus Armbruster, 2004-2012
  */
 
 #include <config.h>
 
 #include <ctype.h>
+#include "chance.h"
 #include "damage.h"
-#include "file.h"
 #include "map.h"
 #include "nsc.h"
 #include "path.h"
@@ -64,7 +64,6 @@ move_ground(struct sctstr *start, struct sctstr *end,
     int dir;
     char scanspace[1024];
     char *argp[128];
-    int intcost;
     int takedam = *dam;
     int out = 0;
     char prompt[128];
@@ -112,7 +111,7 @@ move_ground(struct sctstr *start, struct sctstr *end,
     curx = start->sct_x;
     cury = start->sct_y;
     total_mcost = 0.0;
-    if (getsect(curx, cury, &sect) < 0) {
+    if (!getsect(curx, cury, &sect)) {
        logerror("move_path: getsect %d,%d", curx, cury);
        return -1;
     }
@@ -172,13 +171,6 @@ move_ground(struct sctstr *start, struct sctstr *end,
        }
        if (dir == DIR_MAP) {
            parse(movstr, scanspace, argp, NULL, NULL, NULL);
-           if (argp[0][1]) {
-               pr("Use of '%c' without a space before its argument is deprecated.\n"
-                  "Support for it will go away in a future release\n",
-                  *movstr);
-               argp[2] = argp[1];
-               argp[1] = argp[0] + 1;
-           }
            if (!exploring)
                map(curx, cury, argp[1], argp[2]);
            *movstr = 0;
@@ -199,7 +191,7 @@ move_ground(struct sctstr *start, struct sctstr *end,
         */
        tmpx = curx + diroff[dir][0];
        tmpy = cury + diroff[dir][1];
-       if (getsect(tmpx, tmpy, &next) < 0) {
+       if (!getsect(tmpx, tmpy, &next)) {
            pr("You can't go there...\n");
            *movstr = 0;
            continue;
@@ -255,16 +247,11 @@ move_ground(struct sctstr *start, struct sctstr *end,
            break;
     }
     *end = sect;
-    intcost = (int)total_mcost;
-    if (intcost < 0)
-       return -1;
     if ((start->sct_x == end->sct_x) && (start->sct_y == end->sct_y)
        && !out)
        return -1;
 
-    if (chance(total_mcost - intcost))
-       intcost++;
-    return intcost;
+    return roundavg(total_mcost);
 }