]> git.pond.sub.org Git - empserver/blob - src/lib/common/bridgefall.c
Update copyright notice.
[empserver] / src / lib / common / bridgefall.c
1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2004, 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 the "LEGAL", "LICENSE", "CREDITS" and "README" files for all the
23  *  related information and legal notices. It is expected that any future
24  *  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 "misc.h"
35 #include "var.h"
36 #include "sect.h"
37 #include "path.h"
38 #include "file.h"
39 #include "xy.h"
40 #include "plane.h"
41 #include "land.h"
42 #include "nsc.h"
43 #include "common.h"
44 #include "subs.h"
45 #include "lost.h"
46 #include "optlist.h"
47
48 void
49 bridgefall(struct sctstr *sp, struct emp_qelem *list)
50 {
51     register int i;
52     register int j;
53     struct sctstr sect;
54     struct sctstr bh_sect;
55     int nx;
56     int ny;
57     int nnx;
58     int nny;
59
60     for (i = 1; i <= 6; i++) {
61         nx = sp->sct_x + diroff[i][0];
62         ny = sp->sct_y + diroff[i][1];
63         getsect(nx, ny, &sect);
64         if (sect.sct_type != SCT_BSPAN)
65             continue;
66         for (j = 1; j <= 6; j++) {
67             nnx = nx + diroff[j][0];
68             nny = ny + diroff[j][1];
69             if (nnx == sp->sct_x && nny == sp->sct_y)
70                 continue;
71             getsect(nnx, nny, &bh_sect);
72             if (bh_sect.sct_type == SCT_BHEAD &&
73                 bh_sect.sct_newtype == SCT_BHEAD)
74                 break;
75             if (bh_sect.sct_type == SCT_BTOWER)
76                 break;
77             /* With EASY_BRIDGES, it just has to be next to any
78                land */
79             if (opt_EASY_BRIDGES) {
80                 if (bh_sect.sct_type != SCT_WATER &&
81                     bh_sect.sct_type != SCT_BSPAN)
82                     break;
83             }
84         }
85         if (j > 6) {
86             knockdown(&sect, list);
87             putsect(&sect);
88         }
89     }
90 }
91
92 /* Knock down a bridge span.  Note that this does NOT write the
93  * sector out to the database, it's up to the caller to do that. */
94 void
95 knockdown(struct sctstr *sp, struct emp_qelem *list)
96 {
97     struct lndstr land;
98     struct plnstr plane;
99     struct nstr_item ni;
100     struct natstr *np;
101
102     if (sp->sct_type == SCT_BTOWER)
103         mpr(sp->sct_own,
104             "Crumble... SCREEEECH!  Splash! Bridge tower falls at %s!\n",
105             xyas(sp->sct_x, sp->sct_y, sp->sct_own));
106     else
107         mpr(sp->sct_own,
108             "Crumble... SCREEEECH!  Splash! Bridge falls at %s!\n",
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, (s_char *)&land)) {
121         if (land.lnd_own == 0)
122             continue;
123         if (land.lnd_x != sp->sct_x || land.lnd_y != sp->sct_y)
124             continue;
125         if (land.lnd_ship >= 0)
126             continue;
127         np = getnatp(land.lnd_own);
128         if (np->nat_flags & NF_BEEP)
129             mpr(land.lnd_own, "\07");
130         mpr(land.lnd_own, "     AARGH! %s tumbles to its doom!\n",
131             prland(&land));
132         makelost(EF_LAND, land.lnd_own, land.lnd_uid, land.lnd_x,
133                  land.lnd_y);
134         land.lnd_own = 0;
135         land.lnd_effic = 0;
136         putland(land.lnd_uid, &land);
137     }
138     /* Sink all the planes */
139     snxtitem_xy(&ni, EF_PLANE, sp->sct_x, sp->sct_y);
140     while (nxtitem(&ni, (s_char *)&plane)) {
141         if (plane.pln_own == 0)
142             continue;
143         if (plane.pln_x != sp->sct_x || plane.pln_y != sp->sct_y)
144             continue;
145         if (plane.pln_flags & PLN_LAUNCHED)
146             continue;
147         if (plane.pln_ship >= 0)
148             continue;
149         /* Is this plane flying in this list? */
150         if (ac_isflying(&plane, list))
151             continue;
152         np = getnatp(plane.pln_own);
153         if (np->nat_flags & NF_BEEP)
154             mpr(plane.pln_own, "\07");
155         mpr(plane.pln_own, "     AARGH! %s tumbles to its doom!\n",
156             prplane(&plane));
157         makelost(EF_PLANE, plane.pln_own, plane.pln_uid, plane.pln_x,
158                  plane.pln_y);
159         plane.pln_own = 0;
160         plane.pln_effic = 0;
161         putplane(plane.pln_uid, &plane);
162     }
163     memset(sp->sct_item, 0, sizeof(sp->sct_item));
164     memset(sp->sct_del, 0, sizeof(sp->sct_del));
165     memset(sp->sct_dist, 0, sizeof(sp->sct_dist));
166     sp->sct_pstage = PLG_HEALTHY;
167     sp->sct_ptime = 0;
168     sp->sct_che = 0;
169     sp->sct_che_target = 0;
170 }