]> git.pond.sub.org Git - empserver/blobdiff - src/lib/subs/detonate.c
Simplify detonate() for nukes falling on water
[empserver] / src / lib / subs / detonate.c
index f92ac6a19b76b1121ed3d668dffbfc0c424f6555..d695917f86c2c30de8a187e0686f6cdf341ddbcd 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2008, 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
  *  ---
  *
  *  detonate.c: Detonate a nuclear device in a sector.
- * 
+ *
  *  Known contributors to this file:
  *     Steve McClure, 1998-2000
+ *     Markus Armbruster, 2004-2009
  */
 
 #include <config.h>
@@ -72,26 +73,23 @@ detonate(struct nukstr *np, coord x, coord y, int airburst)
     int rad;
     struct nstr_sect ns;
     struct nstr_item ni;
-    int issea;
-    int retval;
+
+    mpr(bombown, "Releasing RV's for %s detonation...\n",
+       airburst ? "airburst" : "groundburst");
 
     getsect(x, y, &sect);
-    issea = sect.sct_type == SCT_WATER;
     ncp = &nchr[nuketype];
     kaboom(x, y, ncp->n_blast, bombown);
     rad = ncp->n_blast;
     if (!airburst)
        rad = rad * 2 / 3;
+    if (sect.sct_type == SCT_WATER)
+       rad = 0;     /* Nukes falling on water affect only 1 sector */
     np->nuk_effic = 0;
     putnuke(np->nuk_uid, np);
 
     snxtsct_dist(&ns, x, y, rad);
     while (nxtsct(&ns, &sect)) {
-       /* Nukes falling on water affect only 1 sector */
-       if ((sect.sct_x != x) && issea)
-           continue;
-       if ((sect.sct_y != y) && issea)
-           continue;
        own = sect.sct_own;
        type = sect.sct_type;
        if ((damage = nukedamage(ncp, ns.curdist, airburst)) <= 0)
@@ -103,12 +101,9 @@ detonate(struct nukstr *np, coord x, coord y, int airburst)
            nreport(bombown, N_NUKE, own, 1);
            continue;
        }
-       if (opt_FALLOUT)
-           fallout = sect.sct_fallout;
        sect_damage(&sect, damage);
-       if (sect.sct_x == x && sect.sct_y == y)
-           retval = damage;
        if (opt_FALLOUT) {
+           fallout = sect.sct_fallout;
            if (ncp->n_flags & N_NEUT)
                fallout += damage * 30;
            else
@@ -116,7 +111,6 @@ detonate(struct nukstr *np, coord x, coord y, int airburst)
            sect.sct_fallout = MIN(fallout, FALLOUT_MAX);
        }
        if (damage > 100) {
-           makelost(EF_SECTOR, sect.sct_own, 0, sect.sct_x, sect.sct_y);
            sect.sct_oldown = 0;
            sect.sct_own = 0;
            if (type == SCT_WATER || type == SCT_BSPAN ||
@@ -135,8 +129,6 @@ detonate(struct nukstr *np, coord x, coord y, int airburst)
            sprintf(buf, "did %d%%%% damage in %%s\n", damage);
            bp = buf;
        }
-       if ((type == SCT_CAPIT || type == SCT_MOUNT) && damage >= 100)
-           caploss(&sect, own, "\n%s lost its capital!\n\n");
        (void)putsect(&sect);
        if (type != SCT_WATER)
            nreport(bombown, N_NUKE, own, 1);
@@ -149,11 +141,6 @@ detonate(struct nukstr *np, coord x, coord y, int airburst)
 
     snxtitem_dist(&ni, EF_PLANE, x, y, rad);
     while (nxtitem(&ni, &plane)) {
-       /* Nukes falling on water affect only 1 sector */
-       if ((plane.pln_x != x) && issea)
-           continue;
-       if ((plane.pln_y != y) && issea)
-           continue;
        if ((own = plane.pln_own) == 0)
            continue;
        if (plane.pln_flags & PLN_LAUNCHED)
@@ -199,11 +186,6 @@ detonate(struct nukstr *np, coord x, coord y, int airburst)
 
     snxtitem_dist(&ni, EF_LAND, x, y, rad);
     while (nxtitem(&ni, &land)) {
-       /* Nukes falling on water affect only 1 sector */
-       if ((land.lnd_x != x) && issea)
-           continue;
-       if ((land.lnd_y != y) && issea)
-           continue;
        if ((own = land.lnd_own) == 0)
            continue;
        if ((damage = nukedamage(ncp, ni.curdist, airburst)) <= 0)
@@ -246,11 +228,6 @@ detonate(struct nukstr *np, coord x, coord y, int airburst)
 
     snxtitem_dist(&ni, EF_SHIP, x, y, rad);
     while (nxtitem(&ni, &ship)) {
-       /* Nukes falling on water affect only 1 sector */
-       if ((ship.shp_x != x) && issea)
-           continue;
-       if ((ship.shp_y != y) && issea)
-           continue;
        if ((own = ship.shp_own) == 0)
            continue;
        if ((damage = nukedamage(ncp, ni.curdist, airburst)) <= 0)
@@ -287,11 +264,6 @@ detonate(struct nukstr *np, coord x, coord y, int airburst)
 
     snxtitem_dist(&ni, EF_NUKE, x, y, rad);
     while (nxtitem(&ni, &nuke)) {
-       /* Nukes falling on water affect only 1 sector */
-       if ((nuke.nuk_x != x) && issea)
-           continue;
-       if ((nuke.nuk_y != y) && issea)
-           continue;
        if ((own = nuke.nuk_own) == 0)
            continue;
        if ((damage = nukedamage(ncp, ni.curdist, airburst)) <= 0)
@@ -309,7 +281,7 @@ detonate(struct nukstr *np, coord x, coord y, int airburst)
        putnuke(ni.cur, &nuke);
     }
 
-    return retval;
+    return nukedamage(ncp, 0, airburst);
 }