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