]> git.pond.sub.org Git - empserver/blobdiff - src/lib/subs/retreat.c
Clean up dead stores
[empserver] / src / lib / subs / retreat.c
index 2db7c9010d54b46f05d65774704e2f2a2f798be2..75c6d984c4e8aeab146c1381d35e2c81e92fe93c 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-2010, Dave Pare, Jeff Bailey, Thomas Ruschak,
  *                           Ken Stevens, Steve McClure
  *
  *  This program is free software; you can redistribute it and/or modify
  *  ---
  *
  *  retreat.c: Retreat subroutines
- * 
+ *
  *  Known contributors to this file:
  *     Steve McClure, 2000
  */
 
 #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);
@@ -59,7 +59,7 @@ struct ccode {
     char *desc[2];
 };
 
-struct ccode conditions[] = {
+static struct ccode conditions[] = {
     { 'i', { "retreated with a damaged friend",
             "was damaged" } },
     { 't', { "retreated with a torpedoed ship",
@@ -139,14 +139,12 @@ retreat_ship1(struct shpstr *sp, char code, int orig)
     int shells;
     double mobcost;
     struct mchrstr *mcp;
-    int time_to_stop;
     int changed;
 
     sp->shp_mission = 0;
     if (sp->shp_own == 0)
        return 0;
 
-    n = 0;
     if (sp->shp_effic < SHIP_MINEFF) {
        wu(0, sp->shp_own,
           "%s %s,\nbut it died in the attack, and so couldn't retreat!\n",
@@ -216,9 +214,8 @@ retreat_ship1(struct shpstr *sp, char code, int orig)
        return 0;
     }
 
-    n = (-1 * MAX_RETREAT);
+    n = -MAX_RETREAT;
     stopping = 0;
-    time_to_stop = 0;
     while (!stopping && n) {
        dx = dy = 0;
        if (sp->shp_rpath[0] == 0) {
@@ -248,8 +245,7 @@ retreat_ship1(struct shpstr *sp, char code, int orig)
        mcp = &mchr[(int)sp->shp_type];
        newx = xnorm(sp->shp_x + dx);
        newy = ynorm(sp->shp_y + dy);
-       mobcost = sp->shp_effic * 0.01 * sp->shp_speed;
-       mobcost = 480.0 / (mobcost + techfact(sp->shp_tech, mobcost));
+       mobcost = shp_mobcost(sp);
 
        getsect(newx, newy, &sect);
        if (shp_check_nav(&sect, sp) != CN_NAVIGABLE ||
@@ -270,7 +266,9 @@ retreat_ship1(struct shpstr *sp, char code, int orig)
 
        mines = sect.sct_mines;
        changed = 0;
-       if ((mcp->m_flags & M_SWEEP) && mines > 0 && !player->owner) {
+       if (sect.sct_type != SCT_WATER || mines <= 0)
+           continue;
+       if (mcp->m_flags & M_SWEEP) {
            max = mcp->m_item[I_SHELL];
            shells = sp->shp_item[I_SHELL];
            for (m = 0; mines > 0 && m < 5; m++) {
@@ -278,22 +276,23 @@ retreat_ship1(struct shpstr *sp, char code, int orig)
                    mines--;
                    shells = MIN(max, shells + 1);
                    changed |= map_set(sp->shp_own, sp->shp_x, sp->shp_y,
-                       'X', 0);
+                                      'X', 0);
                }
            }
            if (sect.sct_mines != mines) {
                wu(0, sp->shp_own,
                   "%s cleared %d mine%s in %s while retreating\n",
-                  prship(sp), sect.sct_mines-mines, splur(sect.sct_mines-mines),
+                  prship(sp), sect.sct_mines - mines,
+                  splur(sect.sct_mines - mines),
                   xyas(newx, newy, sp->shp_own));
+               sect.sct_mines = mines;
+               sp->shp_item[I_SHELL] = shells;
+               putsect(&sect);
            }
-           sect.sct_mines = mines;
-           sect.sct_item[I_SHELL] = shells;
-           putsect(&sect);
            if (changed)
                writemap(sp->shp_own);
        }
-       if (mines > 0 && !player->owner && chance(DMINE_HITCHANCE(mines))) {
+       if (chance(DMINE_HITCHANCE(mines))) {
            wu(0, sp->shp_own,
               "%s %s,\nand hit a mine in %s while retreating!\n",
               prship(sp), conditions[findcondition(code)].desc[orig],
@@ -306,19 +305,15 @@ retreat_ship1(struct shpstr *sp, char code, int orig)
                writemap(sp->shp_own);
            sect.sct_mines = mines;
            putsect(&sect);
-           if (sp->shp_effic < SHIP_MINEFF)
-               time_to_stop = 1;
            if (!orig)
                putship(sp->shp_uid, sp);
            return 0;
        }
-       if (time_to_stop)
-           stopping = 1;
     }
 
     if (orig) {
-       wu(0, sp->shp_own, "%s %s, and retreated to %s\n", prship(sp),
-          conditions[findcondition(code)].desc[orig],
+       wu(0, sp->shp_own, "%s %s, and retreated to %s\n",
+          prship(sp), conditions[findcondition(code)].desc[orig],
           xyas(sp->shp_x, sp->shp_y, sp->shp_own));
     } else {
        wu(0, sp->shp_own, "%s %s, and ended up at %s\n",
@@ -404,13 +399,11 @@ retreat_land1(struct lndstr *lp, char code, int orig)
     int shells;
     double mobcost;
     struct lchrstr *lcp;
-    int time_to_stop;
 
     lp->lnd_mission = 0;
     if (lp->lnd_own == 0)
        return 0;
 
-    n = 0;
     if (lp->lnd_effic < LAND_MINEFF) {
        wu(0, lp->lnd_own,
           "%s %s,\nbut it died in the attack, and so couldn't retreat!\n",
@@ -431,9 +424,8 @@ retreat_land1(struct lndstr *lp, char code, int orig)
        return 0;
     }
 
-    n = (-1 * MAX_RETREAT);
+    n = -MAX_RETREAT;
     stopping = 0;
-    time_to_stop = 0;
     while (!stopping && n) {
        dx = dy = 0;
        if (lp->lnd_rpath[0] == 0) {
@@ -465,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],
@@ -478,16 +469,16 @@ 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;
        if (stopping)
            continue;
 
-       mines = sect.sct_mines;
-       if ((lcp->l_flags & L_ENGINEER) && mines > 0 &&
-           (sect.sct_oldown != lp->lnd_own)) {
+       mines = SCT_LANDMINES(&sect);
+       if (mines <= 0 || sect.sct_oldown == lp->lnd_own)
+           continue;
+       if (lcp->l_flags & L_ENGINEER) {
            max = lcp->l_item[I_SHELL];
            shells = lp->lnd_item[I_SHELL];
            for (m = 0; mines > 0 && m < 5; m++) {
@@ -500,8 +491,7 @@ retreat_land1(struct lndstr *lp, char code, int orig)
            lp->lnd_item[I_SHELL] = shells;
            putsect(&sect);
        }
-       if (mines > 0 && (sect.sct_oldown != lp->lnd_own) &&
-           chance(DMINE_HITCHANCE(mines))) {
+       if (chance(DMINE_LHITCHANCE(mines))) {
            wu(0, lp->lnd_own,
               "%s %s,\nand hit a mine in %s while retreating!\n",
               prland(lp),
@@ -509,18 +499,16 @@ 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;
            putsect(&sect);
-           if (lp->lnd_effic < LAND_MINEFF)
-               time_to_stop = 1;
            if (!orig)
                putland(lp->lnd_uid, lp);
            return 0;
        }
-       if (time_to_stop)
-           stopping = 1;
     }
 
     if (orig) {