]> git.pond.sub.org Git - empserver/commitdiff
Units no longer die from lack of maintenance
authorMarkus Armbruster <armbru@pond.sub.org>
Tue, 5 Jul 2011 19:29:03 +0000 (21:29 +0200)
committerMarkus Armbruster <armbru@pond.sub.org>
Sun, 10 Jul 2011 19:08:50 +0000 (21:08 +0200)
Damage due to lack of maintenance is now limited by the unit's minimum
efficiency.

Before, units could die.  Unfortunately, the update left any embarked
units on their dead carrier.  Should have seen this when I fixed a
related bug in commit c2c0d1ff, v4.3.22.  Broken for ships and land
units when Empire 2 added their maintenance cost, and for planes when
commit 2e40a4bb (v4.3.4) replaced nuclear stockpiles by nuke units.
The common root cause of these bugs is the update bypassing pre-write
functions (bug#1010856).

If another unit with the same number got built, it picked up the stuck
cargo, triggering the oops from commit 6fb5caf6, which see.

In "stuck on dead carrier" state, units pretty much behave as if their
carrier was still alive, with additional protection from the fact that
a dead carrier can't be damaged or boarded.

The server detects this state on startup since commit 7da9aab5, and
refuses to start.

Only a deity can take units off a dead carrier.

info/Maintenance.t
src/lib/update/land.c
src/lib/update/plane.c
src/lib/update/ship.c

index 141836eb8bc9503b0926ef699ef559f56b8ac6ee..3b265a24cf32cbcf66e702c82ecb5eb30da22ff9 100644 (file)
@@ -23,9 +23,10 @@ Also note that engineering land units costs 3 times what
 normal units cost, after the tech is figured in.
 .s1
 If you can not afford to pay maintenance costs then your unit will
-lose ETU/5 points of
-efficiency.  Thus, if you were playing in a 60 ETU game, and you did
-not pay your maintenance costs for a 50% frigate, then the frigate
-would drop to 38% efficiency.
+lose ETU/5 points of efficiency.  It won't go below its minimum
+efficiency, though.  Thus, if you were playing in a 60 ETU game, and
+you did not pay your maintenance costs for a 40% frigate, then the
+frigate would drop to 28% efficiency at the first update, and to 20%
+at the second update.
 .s1
 .SA "Unit-types, Ship-types, Plane-types, Ships, LandUnits, Planes, Updates"
index 669b732f9046c20a7739260173b3c707b554d69a..09c975d5549c7d82396150fb23eea70a5b28c719 100644 (file)
@@ -94,11 +94,8 @@ upd_land(struct lndstr *lp, int etus,
 {
     struct lchrstr *lcp;
     int pstage, ptime;
-    int n;
     int min = morale_base - (int)np->nat_level[NAT_HLEV];
-    int mult;
-    int cost;
-    int eff;
+    int n, mult, cost, eff_lost;
 
     if (!player->simulation)
        if (lp->lnd_retreat < min)
@@ -118,19 +115,14 @@ upd_land(struct lndstr *lp, int etus,
            mult *= 3;
        cost = -(mult * etus * MIN(0.0, money_land * lcp->l_cost));
        if (np->nat_money < cost && !player->simulation) {
-           if ((eff = lp->lnd_effic - etus / 5) < LAND_MINEFF) {
-               wu(0, lp->lnd_own,
-                  "%s lost to lack of maintenance\n", prland(lp));
-               makelost(EF_LAND, lp->lnd_own, lp->lnd_uid,
-                        lp->lnd_x, lp->lnd_y);
-               lp->lnd_own = 0;
-               lp->lnd_ship = lp->lnd_land = -1;
-               return;
+           eff_lost = etus / 5;
+           if (lp->lnd_effic - eff_lost < LAND_MINEFF)
+               eff_lost = lp->lnd_effic - LAND_MINEFF;
+           if (eff_lost > 0) {
+               wu(0, lp->lnd_own, "%s lost %d%% to lack of maintenance\n",
+                  prland(lp), eff_lost);
+               lp->lnd_effic -= eff_lost;
            }
-           wu(0, lp->lnd_own,
-              "%s lost %d%% to lack of maintenance\n",
-              prland(lp), lp->lnd_effic - eff);
-           lp->lnd_effic = eff;
        } else {
            np->nat_money -= cost;
        }
index 88c5381826163e56e06d2ac1ffa776c28ef093c6..acf0fc192cf3149b924c0c52dce84121a62a4234 100644 (file)
@@ -29,7 +29,7 @@
  *  Known contributors to this file:
  *     Dave Pare, 1986
  *     Steve McClure, 1998
- *     Markus Armbruster, 2006-2010
+ *     Markus Armbruster, 2006-2011
  */
 
 #include <config.h>
@@ -90,7 +90,7 @@ upd_plane(struct plnstr *pp, int etus,
          struct natstr *np, struct bp *bp, int build)
 {
     struct plchrstr *pcp = &plchr[(int)pp->pln_type];
-    int mult, cost, eff;
+    int mult, cost, eff_lost;
 
     if (build == 1) {
        if (!pp->pln_off && np->nat_money >= 0)
@@ -103,19 +103,14 @@ upd_plane(struct plnstr *pp, int etus,
            mult = 2;
        cost = -(mult * etus * MIN(0.0, pcp->pl_cost * money_plane));
        if (np->nat_money < cost && !player->simulation) {
-           if ((eff = pp->pln_effic - etus / 5) < PLANE_MINEFF) {
-               wu(0, pp->pln_own,
-                  "%s lost to lack of maintenance\n", prplane(pp));
-               makelost(EF_PLANE, pp->pln_own, pp->pln_uid,
-                        pp->pln_x, pp->pln_y);
-               pp->pln_own = 0;
-               pp->pln_ship = pp->pln_land = -1;
-               return;
+           eff_lost = etus / 5;
+           if (pp->pln_effic - eff_lost < PLANE_MINEFF)
+               eff_lost = pp->pln_effic - PLANE_MINEFF;
+           if (eff_lost > 0) {
+               wu(0, pp->pln_own, "%s lost %d%% to lack of maintenance\n",
+                  prplane(pp), eff_lost);
+               pp->pln_effic -= eff_lost;
            }
-           wu(0, pp->pln_own,
-              "%s lost %d%% to lack of maintenance\n",
-              prplane(pp), pp->pln_effic - eff);
-           pp->pln_effic = eff;
        } else {
            np->nat_money -= cost;
        }
index 108ebf5db6966f49471b6cf2d6a292bf73688948..ec206873af5883185ae251a1082078e7b13766e1 100644 (file)
@@ -30,7 +30,7 @@
  *     Dave Pare, 1986
  *     Steve McClure, 1996
  *     Ron Koenderink, 2004
- *     Markus Armbruster, 2006-2010
+ *     Markus Armbruster, 2006-2011
  */
 
 #include <config.h>
@@ -104,10 +104,7 @@ upd_ship(struct shpstr *sp, int etus,
     struct pchrstr *product;
     unsigned char *resource;
     int dep;
-    int n;
-    int mult;
-    int cost;
-    int eff;
+    int n, mult, cost, eff_lost;
 
     mp = &mchr[(int)sp->shp_type];
     if (build == 1) {
@@ -121,18 +118,14 @@ upd_ship(struct shpstr *sp, int etus,
            mult = 2;
        cost = -(mult * etus * MIN(0.0, money_ship * mp->m_cost));
        if (np->nat_money < cost && !player->simulation) {
-           if ((eff = sp->shp_effic - etus / 5) < SHIP_MINEFF) {
-               wu(0, sp->shp_own,
-                  "%s lost to lack of maintenance\n", prship(sp));
-               makelost(EF_SHIP, sp->shp_own, sp->shp_uid,
-                        sp->shp_x, sp->shp_y);
-               sp->shp_own = 0;
-               return;
+           eff_lost = etus / 5;
+           if (sp->shp_effic - eff_lost < SHIP_MINEFF)
+               eff_lost = sp->shp_effic - SHIP_MINEFF;
+           if (eff_lost > 0) {
+               wu(0, sp->shp_own, "%s lost %d%% to lack of maintenance\n",
+                  prship(sp), eff_lost);
+               sp->shp_effic -= eff_lost;
            }
-           wu(0, sp->shp_own,
-              "%s lost %d%% to lack of maintenance\n",
-              prship(sp), sp->shp_effic - eff);
-           sp->shp_effic = eff;
        } else {
            np->nat_money -= cost;
        }