]> git.pond.sub.org Git - empserver/blob - src/lib/common/bridgefall.c
40eed68dde2b20a1f708e4de01efda106419489c
[empserver] / src / lib / common / bridgefall.c
1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2006, Dave Pare, Jeff Bailey, Thomas Ruschak,
4  *                           Ken Stevens, Steve McClure
5  *
6  *  This program is free software; you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation; either version 2 of the License, or
9  *  (at your option) any later version.
10  *
11  *  This program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with this program; if not, write to the Free Software
18  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  *
20  *  ---
21  *
22  *  See files README, COPYING and CREDITS in the root of the source
23  *  tree for related information and legal notices.  It is expected
24  *  that future projects/authors will amend these files as needed.
25  *
26  *  ---
27  *
28  *  bridgefall.c: Knock a bridge down
29  * 
30  *  Known contributors to this file:
31  *     Steve McClure, 1998
32  */
33
34 #include <config.h>
35
36 #include "file.h"
37 #include "land.h"
38 #include "lost.h"
39 #include "misc.h"
40 #include "nat.h"
41 #include "nsc.h"
42 #include "nuke.h"
43 #include "optlist.h"
44 #include "path.h"
45 #include "plague.h"
46 #include "plane.h"
47 #include "prototypes.h"
48 #include "sect.h"
49 #include "xy.h"
50
51 void
52 bridgefall(struct sctstr *sp, struct emp_qelem *list)
53 {
54     int i;
55     int j;
56     struct sctstr sect;
57     struct sctstr bh_sect;
58     int nx;
59     int ny;
60     int nnx;
61     int nny;
62
63     for (i = 1; i <= 6; i++) {
64         nx = sp->sct_x + diroff[i][0];
65         ny = sp->sct_y + diroff[i][1];
66         getsect(nx, ny, &sect);
67         if (sect.sct_type != SCT_BSPAN)
68             continue;
69         for (j = 1; j <= 6; j++) {
70             nnx = nx + diroff[j][0];
71             nny = ny + diroff[j][1];
72             if (nnx == sp->sct_x && nny == sp->sct_y)
73                 continue;
74             getsect(nnx, nny, &bh_sect);
75             if (bh_sect.sct_type == SCT_BHEAD &&
76                 bh_sect.sct_newtype == SCT_BHEAD)
77                 break;
78             if (bh_sect.sct_type == SCT_BTOWER)
79                 break;
80             /* With EASY_BRIDGES, it just has to be next to any
81                land */
82             if (opt_EASY_BRIDGES) {
83                 if (bh_sect.sct_type != SCT_WATER &&
84                     bh_sect.sct_type != SCT_BSPAN)
85                     break;
86             }
87         }
88         if (j > 6) {
89             knockdown(&sect, list);
90             putsect(&sect);
91         }
92     }
93 }
94
95 /* Knock down a bridge span.  Note that this does NOT write the
96  * sector out to the database, it's up to the caller to do that. */
97 void
98 knockdown(struct sctstr *sp, struct emp_qelem *list)
99 {
100     struct lndstr land;
101     struct plnstr plane;
102     struct nukstr nuke;
103     struct nstr_item ni;
104     struct natstr *np;
105
106     mpr(sp->sct_own,
107         "Crumble... SCREEEECH!  Splash! Bridge%s falls at %s!\n",
108         sp->sct_type == SCT_BTOWER ? " tower" : "",
109         xyas(sp->sct_x, sp->sct_y, sp->sct_own));
110     sp->sct_type = SCT_WATER;
111     sp->sct_newtype = SCT_WATER;
112     makelost(EF_SECTOR, sp->sct_own, 0, sp->sct_x, sp->sct_y);
113     sp->sct_own = 0;
114     sp->sct_oldown = 0;
115     sp->sct_mobil = 0;
116     sp->sct_effic = 0;
117
118     /* Sink all the units */
119     snxtitem_xy(&ni, EF_LAND, sp->sct_x, sp->sct_y);
120     while (nxtitem(&ni, &land)) {
121         if (land.lnd_own == 0)
122             continue;
123         if (land.lnd_ship >= 0)
124             continue;
125         np = getnatp(land.lnd_own);
126         if (np->nat_flags & NF_BEEP)
127             mpr(land.lnd_own, "\07");
128         mpr(land.lnd_own, "     AARGH! %s tumbles to its doom!\n",
129             prland(&land));
130         land.lnd_effic = 0;
131         putland(land.lnd_uid, &land);
132     }
133     /* Sink all the planes */
134     snxtitem_xy(&ni, EF_PLANE, sp->sct_x, sp->sct_y);
135     while (nxtitem(&ni, &plane)) {
136         if (plane.pln_own == 0)
137             continue;
138         if (plane.pln_flags & PLN_LAUNCHED)
139             continue;
140         if (plane.pln_ship >= 0)
141             continue;
142         /* Is this plane flying in this list? */
143         if (ac_isflying(&plane, list))
144             continue;
145         np = getnatp(plane.pln_own);
146         if (np->nat_flags & NF_BEEP)
147             mpr(plane.pln_own, "\07");
148         mpr(plane.pln_own, "     AARGH! %s tumbles to its doom!\n",
149             prplane(&plane));
150         plane.pln_effic = 0;
151         putplane(plane.pln_uid, &plane);
152     }
153     /* Sink all the nukes */
154     snxtitem_xy(&ni, EF_NUKE, sp->sct_x, sp->sct_y);
155     while (nxtitem(&ni, &nuke)) {
156         if (nuke.nuk_own == 0)
157             continue;
158         if (nuke.nuk_plane >= 0)
159             continue;
160         np = getnatp(nuke.nuk_own);
161         if (np->nat_flags & NF_BEEP)
162             mpr(nuke.nuk_own, "\07");
163         mpr(nuke.nuk_own, "     %s sinks to the bottom of the sea!\n",
164             prnuke(&nuke));
165         nuke.nuk_effic = 0;
166         putnuke(nuke.nuk_uid, &nuke);
167     }
168     memset(sp->sct_item, 0, sizeof(sp->sct_item));
169     memset(sp->sct_del, 0, sizeof(sp->sct_del));
170     memset(sp->sct_dist, 0, sizeof(sp->sct_dist));
171     sp->sct_pstage = PLG_HEALTHY;
172     sp->sct_ptime = 0;
173     sp->sct_che = 0;
174     sp->sct_che_target = 0;
175 }