]> git.pond.sub.org Git - empserver/blobdiff - src/lib/subs/retreat.c
(retreat_ship1, retreat_land1): Simplify slightly.
[empserver] / src / lib / subs / retreat.c
index 2902f0f99c3b4209a7a34f1859ff4a35f5127afd..145302a8ace350181dc584d44926bf70d31d07a8 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-2007, Dave Pare, Jeff Bailey, Thomas Ruschak,
  *                           Ken Stevens, Steve McClure
  *
  *  This program is free software; you can redistribute it and/or modify
 
 #include <config.h>
 
-#include <string.h>
+#include "damage.h"
+#include "file.h"
+#include "land.h"
+#include "map.h"
 #include "misc.h"
-#include "player.h"
 #include "nat.h"
-#include "retreat.h"
-#include "ship.h"
-#include "land.h"
-#include "sect.h"
 #include "news.h"
-#include "xy.h"
 #include "nsc.h"
+#include "optlist.h"
 #include "path.h"
-#include "file.h"
-#include "damage.h"
+#include "player.h"
 #include "prototypes.h"
-#include "optlist.h"
+#include "retreat.h"
+#include "sect.h"
+#include "ship.h"
+#include "xy.h"
 
 static int findcondition(char);
 static int retreat_land1(struct lndstr *, char, int);
@@ -215,7 +215,7 @@ retreat_ship1(struct shpstr *sp, char code, int orig)
        return 0;
     }
 
-    n = (-1 * MAX_RETREAT);
+    n = -MAX_RETREAT;
     stopping = 0;
     while (!stopping && n) {
        dx = dy = 0;
@@ -268,7 +268,6 @@ retreat_ship1(struct shpstr *sp, char code, int orig)
        mines = sect.sct_mines;
        changed = 0;
        if ((mcp->m_flags & M_SWEEP) && sect.sct_type == SCT_WATER) {
-           sp->shp_mobil -= mobcost;
            max = mcp->m_item[I_SHELL];
            shells = sp->shp_item[I_SHELL];
            for (m = 0; mines > 0 && m < 5; m++) {
@@ -425,7 +424,7 @@ retreat_land1(struct lndstr *lp, char code, int orig)
        return 0;
     }
 
-    n = (-1 * MAX_RETREAT);
+    n = -MAX_RETREAT;
     stopping = 0;
     while (!stopping && n) {
        dx = dy = 0;
@@ -458,11 +457,10 @@ retreat_land1(struct lndstr *lp, char code, int orig)
        newy = ynorm(lp->lnd_y + dy);
 
        getsect(newx, newy, &sect);
-       if ((sect.sct_type == SCT_WATER) ||
-           (sect.sct_type == SCT_MOUNT) ||
-           (sect.sct_type == SCT_SANCT) ||
-           (sect.sct_type == SCT_WASTE) ||
-           (sect.sct_own != lp->lnd_own)) {
+       mobcost = lnd_mobcost(lp, &sect);
+       if (mobcost < 0
+           || sect.sct_type == SCT_MOUNT
+           || sect.sct_own != lp->lnd_own) {
            wu(0, lp->lnd_own, "%s %s,\nbut could not retreat to %s!\n",
               prland(lp),
               conditions[findcondition(code)].desc[orig],
@@ -471,7 +469,6 @@ retreat_land1(struct lndstr *lp, char code, int orig)
                putland(lp->lnd_uid, lp);
            return 0;
        }
-       mobcost = lnd_mobcost(lp, &sect, MOB_ROAD);
        lp->lnd_x = newx;
        lp->lnd_y = newy;
        lp->lnd_mobil -= mobcost;
@@ -502,6 +499,8 @@ retreat_land1(struct lndstr *lp, char code, int orig)
               xyas(newx, newy, lp->lnd_own));
            nreport(lp->lnd_own, N_LHIT_MINE, 0, 1);
            m = MINE_LDAMAGE();
+           if (lcp->l_flags & L_ENGINEER)
+               m /= 2;
            landdamage(lp, m);
            mines--;
            sect.sct_mines = mines;