]> git.pond.sub.org Git - empserver/blobdiff - src/lib/subs/detonate.c
Move declarations for chance.c to new chance.h
[empserver] / src / lib / subs / detonate.c
index cc61883a1623522fa7f544604841202c791199bb..4204d2629e2f32d7058020f9b74a80ff044d52cd 100644 (file)
@@ -1,11 +1,11 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2009, Dave Pare, Jeff Bailey, Thomas Ruschak,
- *                           Ken Stevens, Steve McClure
+ *  Copyright (C) 1986-2013, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *                Ken Stevens, Steve McClure, Markus Armbruster
  *
- *  This program is free software; you can redistribute it and/or modify
+ *  Empire is free software: you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
+ *  the Free Software Foundation, either version 3 of the License, or
  *  (at your option) any later version.
  *
  *  This program is distributed in the hope that it will be useful,
@@ -14,8 +14,7 @@
  *  GNU General Public License for more details.
  *
  *  You should have received a copy of the GNU General Public License
- *  along with this program; if not, write to the Free Software
- *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
  *
  *  ---
  *
  *
  *  Known contributors to this file:
  *     Steve McClure, 1998-2000
- *     Markus Armbruster, 2004-2009
+ *     Markus Armbruster, 2004-2012
  */
 
 #include <config.h>
 
+#include "chance.h"
 #include "file.h"
 #include "land.h"
-#include "lost.h"
+#include "map.h"
 #include "misc.h"
 #include "nat.h"
 #include "news.h"
 #include "ship.h"
 #include "xy.h"
 
-static void kaboom(int x, int y, int rad, natid cn);
+static void kaboom(int x, int y, int rad);
 
 int
 detonate(struct nukstr *np, coord x, coord y, int airburst)
 {
     int nuketype = np->nuk_type;
-    natid bombown = np->nuk_own;
     struct nchrstr *ncp;
     struct plnstr plane;
     struct sctstr sect;
     struct shpstr ship;
     struct lndstr land;
     struct nukstr nuke;
-    char *bp;
-    char buf[128];
-    char buf2[128];
     natid own;
     int type;
     int damage;
@@ -73,37 +69,33 @@ detonate(struct nukstr *np, coord x, coord y, int airburst)
     int rad;
     struct nstr_sect ns;
     struct nstr_item ni;
-    int issea;
+    int changed = 0;
 
-    mpr(bombown, "Releasing RV's for %s detonation...\n",
-       airburst ? "airburst" : "groundburst");
+    pr("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);
+    kaboom(x, y, ncp->n_blast);
     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)
            continue;
        if (type == SCT_SANCT) {
-           mpr(bombown, "bounced off %s\n", xyas(ns.x, ns.y, bombown));
+           pr("bounced off %s\n", xyas(ns.x, ns.y, player->cnum));
            mpr(own, "%s nuclear device bounced off %s\n",
-               cname(bombown), xyas(ns.x, ns.y, bombown));
-           nreport(bombown, N_NUKE, own, 1);
+               cname(player->cnum), xyas(ns.x, ns.y, own));
+           nreport(player->cnum, N_NUKE, own, 1);
            continue;
        }
        sect_damage(&sect, damage);
@@ -120,37 +112,45 @@ detonate(struct nukstr *np, coord x, coord y, int airburst)
            sect.sct_own = 0;
            if (type == SCT_WATER || type == SCT_BSPAN ||
                type == SCT_BTOWER) {
-               bp = "left nothing but water in %s\n";
                if (type != SCT_WATER) {
+                   pr("left nothing but water in %s\n",
+                      xyas(ns.x, ns.y, player->cnum));
+                   if (own != player->cnum)
+                       mpr(own,
+                           "%s nuclear device left nothing but water in %s\n",
+                           cname(player->cnum), xyas(ns.x, ns.y, own));
                    sect.sct_newtype = SCT_WATER;
                    sect.sct_type = SCT_WATER;
                }
            } else {
                sect.sct_newtype = SCT_WASTE;
                sect.sct_type = SCT_WASTE;
-               bp = "turned %s into a radioactive wasteland\n";
+               pr("turned %s into a radioactive wasteland\n",
+                  xyas(ns.x, ns.y, player->cnum));
+               if (own != player->cnum)
+                   mpr(own,
+                       "%s nuclear device turned %s into a radioactive wasteland\n",
+                       cname(player->cnum), xyas(ns.x, ns.y, own));
            }
+           changed |= map_set(player->cnum, sect.sct_x, sect.sct_y,
+                              dchr[sect.sct_type].d_mnem, 0);
        } else {
-           sprintf(buf, "did %d%%%% damage in %%s\n", damage);
-           bp = buf;
+           pr("did %d%% damage in %s\n",
+              damage, xyas(ns.x, ns.y, player->cnum));
+           if (own != player->cnum)
+               mpr(own, "%s nuclear device did %d%% damage in %s\n",
+                   cname(player->cnum), damage, xyas(ns.x, ns.y, own));
        }
        (void)putsect(&sect);
        if (type != SCT_WATER)
-           nreport(bombown, N_NUKE, own, 1);
-       mpr(bombown, bp, xyas(ns.x, ns.y, bombown));
-       if (own != bombown && own != 0) {
-           (void)sprintf(buf2, bp, xyas(ns.x, ns.y, own));
-           mpr(own, "%s nuclear device %s\n", cname(bombown), buf2);
-       }
+           nreport(player->cnum, N_NUKE, own, 1);
     }
 
+    if (changed)
+       writebmap(player->cnum);
+
     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)
@@ -182,13 +182,13 @@ detonate(struct nukstr *np, coord x, coord y, int airburst)
            }
        }
        planedamage(&plane, damage);
-       if (own == bombown) {
-           mpr(bombown, "%s at %s reports %d%% damage\n",
-               prplane(&plane),
-               xyas(plane.pln_x, plane.pln_y, own), damage);
+       if (own == player->cnum) {
+           pr("%s at %s reports %d%% damage\n",
+              prplane(&plane),
+              xyas(plane.pln_x, plane.pln_y, player->cnum), damage);
        } else {
            mpr(own, "%s nuclear device did %d%% damage to %s at %s\n",
-               cname(bombown), damage,
+               cname(player->cnum), damage,
                prplane(&plane), xyas(plane.pln_x, plane.pln_y, own));
        }
        putplane(ni.cur, &plane);
@@ -196,11 +196,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)
@@ -230,12 +225,13 @@ detonate(struct nukstr *np, coord x, coord y, int airburst)
            }
        }
        land_damage(&land, damage);
-       if (own == bombown) {
-           mpr(bombown, "%s at %s reports %d%% damage\n",
-               prland(&land), xyas(land.lnd_x, land.lnd_y, own), damage);
+       if (own == player->cnum) {
+           pr("%s at %s reports %d%% damage\n",
+              prland(&land), xyas(land.lnd_x, land.lnd_y, player->cnum),
+              damage);
        } else {
            mpr(own, "%s nuclear device did %d%% damage to %s at %s\n",
-               cname(bombown), damage,
+               cname(player->cnum), damage,
                prland(&land), xyas(land.lnd_x, land.lnd_y, own));
        }
        putland(land.lnd_uid, &land);
@@ -243,11 +239,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)
@@ -271,12 +262,13 @@ detonate(struct nukstr *np, coord x, coord y, int airburst)
            }
        }
        ship_damage(&ship, damage);
-       if (own == bombown) {
-           mpr(bombown, "%s at %s reports %d%% damage\n",
-               prship(&ship), xyas(ship.shp_x, ship.shp_y, own), damage);
+       if (own == player->cnum) {
+           pr("%s at %s reports %d%% damage\n",
+              prship(&ship), xyas(ship.shp_x, ship.shp_y, player->cnum),
+              damage);
        } else {
            mpr(own, "%s nuclear device did %d%% damage to %s at %s\n",
-               cname(bombown), damage, prship(&ship),
+               cname(player->cnum), damage, prship(&ship),
                xyas(ship.shp_x, ship.shp_y, own));
        }
        putship(ship.shp_uid, &ship);
@@ -284,24 +276,20 @@ 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)
            continue;
-       if (roll(100) >= damage)
+       if (roll(100) > damage)
            continue;
        nuke.nuk_effic = 0;
-       if (own == bombown) {
-           mpr(bombown, "%s at %s destroyed\n",
-               prnuke(&nuke), xyas(nuke.nuk_x, nuke.nuk_y, own));
+       if (own == player->cnum) {
+           pr("%s at %s destroyed\n",
+              prnuke(&nuke), xyas(nuke.nuk_x, nuke.nuk_y, player->cnum));
        } else {
-           mpr(own, "%s at %s destroyed\n",
-               prnuke(&nuke), xyas(nuke.nuk_x, nuke.nuk_y, own));
+           mpr(own, "%s nuclear device destroyed %s at %s\n",
+               cname(player->cnum), prnuke(&nuke),
+                     xyas(nuke.nuk_x, nuke.nuk_y, own));
        }
        putnuke(ni.cur, &nuke);
     }
@@ -314,10 +302,10 @@ detonate(struct nukstr *np, coord x, coord y, int airburst)
  * silly to be sure.
  */
 static void
-kaboom(int x, int y, int rad, natid cn)
+kaboom(int x, int y, int rad)
 {
-    mpr(cn, "\n\nK A B O O ");
+    pr("\n\nK A B O O ");
     while (rad-- > 1)
-       mpr(cn, "O O ");
-    mpr(cn, "M ! in %s\n\n", xyas(x, y, cn));
+       pr("O O ");
+    pr("M ! in %s\n\n", xyas(x, y, player->cnum));
 }