]> git.pond.sub.org Git - empserver/blobdiff - src/lib/subs/retreat.c
(lnd_mobtype): New.
[empserver] / src / lib / subs / retreat.c
index 5a90d29c8bb0784a0029f8869a0c7b1b38c9775a..cbfdecc139b311c0650fa9a30852c3f6674baa28 100644 (file)
@@ -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,7 +139,6 @@ 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;
@@ -218,7 +217,6 @@ retreat_ship1(struct shpstr *sp, char code, int orig)
 
     n = (-1 * MAX_RETREAT);
     stopping = 0;
-    time_to_stop = 0;
     while (!stopping && n) {
        dx = dy = 0;
        if (sp->shp_rpath[0] == 0) {
@@ -248,12 +246,11 @@ 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 ||
-           (sect.sct_own && !player->owner &&
+           (sect.sct_own && sect.sct_own != sp->shp_own &&
             getrel(getnatp(sect.sct_own), sp->shp_own) < FRIENDLY)) {
            wu(0, sp->shp_own, "%s %s,\nbut could not retreat to %s!\n",
               prship(sp), conditions[findcondition(code)].desc[orig],
@@ -270,7 +267,8 @@ 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 ((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++) {
@@ -278,7 +276,7 @@ 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) {
@@ -286,14 +284,15 @@ retreat_ship1(struct shpstr *sp, char code, int orig)
                   "%s cleared %d mine%s in %s while retreating\n",
                   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 (sect.sct_type == SCT_WATER && mines > 0
+           && 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,7 +399,6 @@ 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)
@@ -433,7 +427,6 @@ retreat_land1(struct lndstr *lp, char code, int orig)
 
     n = (-1 * MAX_RETREAT);
     stopping = 0;
-    time_to_stop = 0;
     while (!stopping && n) {
        dx = dy = 0;
        if (lp->lnd_rpath[0] == 0) {
@@ -465,11 +458,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,7 +470,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;
@@ -501,7 +492,7 @@ retreat_land1(struct lndstr *lp, char code, int orig)
            putsect(&sect);
        }
        if (mines > 0 && (sect.sct_oldown != lp->lnd_own) &&
-           chance(DMINE_HITCHANCE(mines))) {
+           chance(DMINE_LHITCHANCE(mines))) {
            wu(0, lp->lnd_own,
               "%s %s,\nand hit a mine in %s while retreating!\n",
               prland(lp),
@@ -513,14 +504,10 @@ retreat_land1(struct lndstr *lp, char code, int orig)
            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) {