]> git.pond.sub.org Git - empserver/blobdiff - src/lib/subs/attsub.c
Update copyright notice
[empserver] / src / lib / subs / attsub.c
index af3df3a6fafc8708b16bea2dc3461ff2f6e02ae8..10dd576e832a817e7e1d8068f57ac9b253c70a9e 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2014, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *  Copyright (C) 1986-2016, Dave Pare, Jeff Bailey, Thomas Ruschak,
  *                Ken Stevens, Steve McClure, Markus Armbruster
  *
  *  Empire is free software: you can redistribute it and/or modify
@@ -29,7 +29,7 @@
  *  Known contributors to this file:
  *     Ken Stevens, 1995
  *     Steve McClure, 1996-2000
- *     Markus Armbruster, 2006-2014
+ *     Markus Armbruster, 2006-2015
  */
 
 #include <config.h>
@@ -415,6 +415,11 @@ put_combat(struct combat *com)
        putship(com->shp_uid, &ship);
     }
     com->mobcost = 0;
+    /*
+     * FIXME if we just sank the ship, att_get_combat() will report
+     * "not in the same sector", and proceed to clobber *com.  See
+     * also the workaround in boar().
+     */
     att_get_combat(com, com->own != player->cnum);
 }
 
@@ -740,8 +745,8 @@ att_ask_offense(int combat_mode, struct combat *off, struct combat *def,
 }
 
 /*
- * Return path cost for ATTACKER to enter sector given by DEF.
- * MOBTYPE is a mobility type accepted by sector_mcost().
+ * Return path cost for @attacker to enter sector given by @def.
+ * @mobtype is a mobility type accepted by sector_mcost().
  */
 static double
 att_mobcost(natid attacker, struct combat *def, int mobtype)
@@ -851,7 +856,7 @@ calc_mobcost(int combat_mode, struct combat *off, struct combat *def,
        case EF_SHIP:
            /* the 2 in the formula below is a fudge factor */
            getship(def->shp_uid, &ship);
-           off->mobcost += (def->eff / 100) * (shp_speed(&ship) / 2);
+           off->mobcost += shp_speed(&ship) / 2 * def->eff / 100;
        }
     }
 }
@@ -1076,7 +1081,7 @@ ask_olist(int combat_mode, struct combat *off, struct combat *def,
        llp->eff = llp->unit.land.lnd_effic;
        if (lnd_spyval(&land) > *a_spyp)
            *a_spyp = lnd_spyval(&land);
-       if (((struct lchrstr *)llp->chrp)->l_flags & L_ENGINEER)
+       if (lchr[land.lnd_type].l_flags & L_ENGINEER)
            ++*a_engineerp;
        if (def->type == EF_SHIP && ++count >= maxland)
            break;
@@ -1246,7 +1251,7 @@ get_ototal(int combat_mode, struct combat *off, struct emp_qelem *olist,
            if (w < 0) {
                lnd_print(player->cnum, llp,
                          "can't attack from this sector now");
-               lnd_delete(llp);
+               lnd_put_one(llp);
                continue;
            }
            ototal += attack_val(combat_mode, &llp->unit.land) *
@@ -1312,7 +1317,7 @@ get_oland(int combat_mode, struct ulist *llp)
        sprintf(buf, "was destroyed and is no longer a part of the %s",
                att_mode[combat_mode]);
        lnd_print(player->cnum, llp, buf);
-       lnd_delete(llp);
+       lnd_put_one(llp);
        return 0;
     }
     if (lp->lnd_x != llp->x || lp->lnd_y != llp->y) {
@@ -1320,7 +1325,7 @@ get_oland(int combat_mode, struct ulist *llp)
                "left to fight another battle and is no longer a part of the %s",
                att_mode[combat_mode]);
        lnd_print(player->cnum, llp, buf);
-       lnd_delete(llp);
+       lnd_put_one(llp);
        return 0;
     }
     if (lp->lnd_effic < llp->eff) {
@@ -1344,13 +1349,13 @@ get_dland(struct combat *def, struct ulist *llp)
     if (lp->lnd_effic < LAND_MINEFF) {
        sprintf(buf, "was destroyed and is no longer a part of the defense");
        lnd_print(llp->unit.land.lnd_own, llp, buf);
-       lnd_delete(llp);
+       lnd_put_one(llp);
        return 0;
     }
     if (lp->lnd_x != def->x || lp->lnd_y != def->y) {
        lnd_print(llp->unit.land.lnd_own, llp,
                  "left to go fight another battle and is no longer a part of the defense");
-       lnd_delete(llp);
+       lnd_put_one(llp);
        return 0;
     }
 
@@ -1371,7 +1376,7 @@ kill_land(struct emp_qelem *list)
            llp->unit.land.lnd_effic = 0;
            lnd_print(player->cnum, llp,
                      "cannot return to the ship, and dies!");
-           lnd_delete(llp);
+           lnd_put_one(llp);
        }
     }
 }
@@ -1542,8 +1547,7 @@ get_osupport(char *outs, struct combat *def, int fort_sup, int ship_sup,
        ap = dam / 100.0;
        osupport += ap;
     }
-    sprintf(outs, "attacker\t%1.2f\t%1.2f\t%1.2f\t%1.2f\n", af, as, au,
-           ap);
+    sprintf(outs, "attacker\t%1.2f\t%1.2f\t%1.2f\t%1.2f", af, as, au, ap);
     return osupport;
 }
 
@@ -1590,8 +1594,8 @@ get_dsupport(char *outs, struct emp_qelem *list, struct combat *def,
     if (good)
        *outs = '\0';
     else
-       sprintf(outs, "defender\t%1.2f\t%1.2f\t%1.2f\t%1.2f\n\n", df, ds,
-               du, dp);
+       sprintf(outs, "defender\t%1.2f\t%1.2f\t%1.2f\t%1.2f",
+               df, ds, du, dp);
     if (def->own) {
        if (good < 0)
            wu(0, def->own,
@@ -1675,16 +1679,18 @@ att_get_support(int combat_mode, int ofort, int oship, int oland,
        pr("\n\t\tsupport values\n");
        pr("\t\tforts\tships\tunits\tplanes\n");
        if (*osupportp != 1.0)
-           pr("%s", osupports);
+           pr("%s\n", osupports);
        if (*dsupportp != 1.0)
-           pr("%s", dsupports);
+           pr("%s\n", dsupports);
+       pr("\n");
        if (def->own) {
            wu(0, def->own, "\n\t\tsupport values\n");
            wu(0, def->own, "\t\tforts\tships\tunits\tplanes\n");
            if (*osupportp != 1.0)
-               wu(0, def->own, "%s", osupports);
+               wu(0, def->own, "%s\n", osupports);
            if (*dsupportp != 1.0)
-               wu(0, def->own, "%s", dsupports);
+               wu(0, def->own, "%s\n", dsupports);
+           wu(0, def->own, "\n");
        }
     }
 
@@ -2110,7 +2116,7 @@ send_reacting_units_home(struct emp_qelem *list)
            llp->unit.land.lnd_x = llp->x;
            llp->unit.land.lnd_y = llp->y;
            lnd_print(llp->unit.land.lnd_own, llp, buf);
-           lnd_delete(llp);
+           lnd_put_one(llp);
        }
     }
 }
@@ -2190,7 +2196,7 @@ take_def(int combat_mode, struct emp_qelem *list, struct combat *off,
                sprintf(buf, "moves in to occupy %s",
                        xyas(def->x, def->y, player->cnum));
                lnd_print(player->cnum, llp, buf);
-               lnd_delete(llp);
+               lnd_put_one(llp);
            }
        }
     }
@@ -2212,7 +2218,7 @@ take_def(int combat_mode, struct emp_qelem *list, struct combat *off,
        putland(land.lnd_uid, &land);
     }
     if (delete_me)
-       lnd_delete(delete_me);
+       lnd_put_one(delete_me);
     att_get_combat(def, 0);
     return 1;
 }
@@ -2272,7 +2278,7 @@ ask_move_in(struct combat *off, struct emp_qelem *olist,
                xyas(llp->unit.land.lnd_x, llp->unit.land.lnd_y,
                     player->cnum));
        lnd_print(player->cnum, llp, buf);
-       lnd_delete(llp);
+       lnd_put_one(llp);
     }
     if (QEMPTY(olist))
        return;
@@ -2286,7 +2292,7 @@ ask_move_in(struct combat *off, struct emp_qelem *olist,
                    xyas(llp->unit.land.lnd_x, llp->unit.land.lnd_y,
                         player->cnum));
            lnd_print(player->cnum, llp, buf);
-           lnd_delete(llp);
+           lnd_put_one(llp);
        }
        return;
     }
@@ -2488,7 +2494,7 @@ take_move_in_mob(int combat_mode, struct ulist *llp, struct combat *off,
         * Set mobcost to basic assault cost, moblim to maximum
         * mobility to keep when assaulting from non-landing ship
         */
-       if (((struct lchrstr *)llp->chrp)->l_flags & L_MARINE) {
+       if (lchr[llp->unit.land.lnd_type].l_flags & L_MARINE) {
            mobcost = gain / 2.0;
            moblim = 0;
        } else {
@@ -2500,7 +2506,7 @@ take_move_in_mob(int combat_mode, struct ulist *llp, struct combat *off,
            mobcost = MAX(mobcost, mob - moblim);
        break;
     case A_BOARD:
-       if (((struct lchrstr *)llp->chrp)->l_flags & L_MARINE)
+       if (lchr[llp->unit.land.lnd_type].l_flags & L_MARINE)
            mobcost = 10;
        else
            mobcost = 40;