src/lib/common/bridgefall.c

Go to the documentation of this file.
00001 /*
00002  *  Empire - A multi-player, client/server Internet based war game.
00003  *  Copyright (C) 1986-2007, Dave Pare, Jeff Bailey, Thomas Ruschak,
00004  *                           Ken Stevens, Steve McClure
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; either version 2 of the License, or
00009  *  (at your option) any later version.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License
00017  *  along with this program; if not, write to the Free Software
00018  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019  *
00020  *  ---
00021  *
00022  *  See files README, COPYING and CREDITS in the root of the source
00023  *  tree for related information and legal notices.  It is expected
00024  *  that future projects/authors will amend these files as needed.
00025  *
00026  *  ---
00027  *
00028  *  bridgefall.c: Knock a bridge down
00029  * 
00030  *  Known contributors to this file:
00031  *     Steve McClure, 1998
00032  */
00033 
00034 #include <config.h>
00035 
00036 #include "file.h"
00037 #include "land.h"
00038 #include "lost.h"
00039 #include "misc.h"
00040 #include "nat.h"
00041 #include "nsc.h"
00042 #include "nuke.h"
00043 #include "optlist.h"
00044 #include "path.h"
00045 #include "plague.h"
00046 #include "plane.h"
00047 #include "prototypes.h"
00048 #include "sect.h"
00049 #include "xy.h"
00050 
00051 void
00052 bridgefall(struct sctstr *sp, struct emp_qelem *list)
00053 {
00054     int i;
00055     int j;
00056     struct sctstr sect;
00057     struct sctstr bh_sect;
00058     int nx;
00059     int ny;
00060     int nnx;
00061     int nny;
00062 
00063     for (i = 1; i <= 6; i++) {
00064         nx = sp->sct_x + diroff[i][0];
00065         ny = sp->sct_y + diroff[i][1];
00066         getsect(nx, ny, &sect);
00067         if (sect.sct_type != SCT_BSPAN)
00068             continue;
00069         for (j = 1; j <= 6; j++) {
00070             nnx = nx + diroff[j][0];
00071             nny = ny + diroff[j][1];
00072             if (nnx == sp->sct_x && nny == sp->sct_y)
00073                 continue;
00074             getsect(nnx, nny, &bh_sect);
00075             if (bh_sect.sct_type == SCT_BHEAD &&
00076                 bh_sect.sct_newtype == SCT_BHEAD)
00077                 break;
00078             if (bh_sect.sct_type == SCT_BTOWER)
00079                 break;
00080             /* With EASY_BRIDGES, it just has to be next to any
00081                land */
00082             if (opt_EASY_BRIDGES) {
00083                 if (bh_sect.sct_type != SCT_WATER &&
00084                     bh_sect.sct_type != SCT_BSPAN)
00085                     break;
00086             }
00087         }
00088         if (j > 6) {
00089             knockdown(&sect, list);
00090             putsect(&sect);
00091         }
00092     }
00093 }
00094 
00095 /* Knock down a bridge span.  Note that this does NOT write the
00096  * sector out to the database, it's up to the caller to do that. */
00097 void
00098 knockdown(struct sctstr *sp, struct emp_qelem *list)
00099 {
00100     struct lndstr land;
00101     struct plnstr plane;
00102     struct nukstr nuke;
00103     struct nstr_item ni;
00104     struct natstr *np;
00105 
00106     mpr(sp->sct_own,
00107         "Crumble... SCREEEECH!  Splash! Bridge%s falls at %s!\n",
00108         sp->sct_type == SCT_BTOWER ? " tower" : "",
00109         xyas(sp->sct_x, sp->sct_y, sp->sct_own));
00110     sp->sct_type = SCT_WATER;
00111     sp->sct_newtype = SCT_WATER;
00112     makelost(EF_SECTOR, sp->sct_own, 0, sp->sct_x, sp->sct_y);
00113     sp->sct_own = 0;
00114     sp->sct_oldown = 0;
00115     sp->sct_mobil = 0;
00116     sp->sct_effic = 0;
00117 
00118     /* Sink all the units */
00119     snxtitem_xy(&ni, EF_LAND, sp->sct_x, sp->sct_y);
00120     while (nxtitem(&ni, &land)) {
00121         if (land.lnd_own == 0)
00122             continue;
00123         if (land.lnd_ship >= 0)
00124             continue;
00125         np = getnatp(land.lnd_own);
00126         if (np->nat_flags & NF_BEEP)
00127             mpr(land.lnd_own, "\07");
00128         mpr(land.lnd_own, "     AARGH! %s tumbles to its doom!\n",
00129             prland(&land));
00130         land.lnd_effic = 0;
00131         putland(land.lnd_uid, &land);
00132     }
00133     /* Sink all the planes */
00134     snxtitem_xy(&ni, EF_PLANE, sp->sct_x, sp->sct_y);
00135     while (nxtitem(&ni, &plane)) {
00136         if (plane.pln_own == 0)
00137             continue;
00138         if (plane.pln_flags & PLN_LAUNCHED)
00139             continue;
00140         if (plane.pln_ship >= 0)
00141             continue;
00142         /* Is this plane flying in this list? */
00143         if (ac_isflying(&plane, list))
00144             continue;
00145         np = getnatp(plane.pln_own);
00146         if (np->nat_flags & NF_BEEP)
00147             mpr(plane.pln_own, "\07");
00148         mpr(plane.pln_own, "     AARGH! %s tumbles to its doom!\n",
00149             prplane(&plane));
00150         plane.pln_effic = 0;
00151         putplane(plane.pln_uid, &plane);
00152     }
00153     /* Sink all the nukes */
00154     snxtitem_xy(&ni, EF_NUKE, sp->sct_x, sp->sct_y);
00155     while (nxtitem(&ni, &nuke)) {
00156         if (nuke.nuk_own == 0)
00157             continue;
00158         if (nuke.nuk_plane >= 0)
00159             continue;
00160         np = getnatp(nuke.nuk_own);
00161         if (np->nat_flags & NF_BEEP)
00162             mpr(nuke.nuk_own, "\07");
00163         mpr(nuke.nuk_own, "     %s sinks to the bottom of the sea!\n",
00164             prnuke(&nuke));
00165         nuke.nuk_effic = 0;
00166         putnuke(nuke.nuk_uid, &nuke);
00167     }
00168     memset(sp->sct_item, 0, sizeof(sp->sct_item));
00169     memset(sp->sct_del, 0, sizeof(sp->sct_del));
00170     memset(sp->sct_dist, 0, sizeof(sp->sct_dist));
00171     sp->sct_pstage = PLG_HEALTHY;
00172     sp->sct_ptime = 0;
00173     sp->sct_che = 0;
00174     sp->sct_che_target = 0;
00175 }

Generated on Fri Mar 28 11:01:13 2008 for empserver by  doxygen 1.5.2