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
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.
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.
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
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.
28 * takeover.c: Take over from another country
30 * Known contributors to this file:
32 * Steve McClure, 1996-2000
46 #include "prototypes.h"
50 takeover(struct sctstr *sp, natid newown)
62 /* Wipe all the distribution info */
63 memset(sp->sct_dist, 0, sizeof(sp->sct_dist));
64 memset(sp->sct_del, 0, sizeof(sp->sct_del));
69 sp->sct_dist_x = sp->sct_x;
70 sp->sct_dist_y = sp->sct_y;
73 /* Take over planes */
74 snxtitem_dist(&ni, EF_PLANE, sp->sct_x, sp->sct_y, 0);
75 while (nxtitem(&ni, pp)) {
76 if (pp->pln_own != sp->sct_own)
78 takeover_plane(pp, newown);
81 /* Take over land units */
83 snxtitem_dist(&ni, EF_LAND, sp->sct_x, sp->sct_y, 0);
84 while (nxtitem(&ni, lp)) {
85 if ((lp->lnd_own == newown) || (lp->lnd_own == 0))
87 if (lp->lnd_own != sp->sct_own)
89 if (lp->lnd_ship >= 0 || lp->lnd_land >= 0)
91 /* Spies get a chance to hide */
92 if (lchr[(int)lp->lnd_type].l_flags & L_SPY) {
93 if (!(chance(LND_SPY_DETECT_CHANCE(lp->lnd_effic))))
96 n = lp->lnd_effic - (30 + (random() % 100));
100 if (lp->lnd_effic < LAND_MINEFF) {
102 mpr(newown, "%s blown up by the crew!\n", prland(lp));
104 "%s blown up by the crew when %s took %s!\n",
106 cname(newown), xyas(lp->lnd_x, lp->lnd_y, lp->lnd_own));
108 mpr(newown, "We have captured %s!\n", prland(lp));
110 "%s captured when %s took %s!\n",
112 cname(newown), xyas(lp->lnd_x, lp->lnd_y, lp->lnd_own));
114 takeover_land(lp, newown, 1);
118 civ = sp->sct_item[I_CIVIL];
119 oldche = sp->sct_che;
121 * create guerrillas from civilians
122 * how spunky are these guys?
123 * n: random number from -25:75 + (50 - loyalty)
125 n = (50 - sp->sct_loyal) + ((random() % 100) - 25);
127 if (n > 0 && sp->sct_own == sp->sct_oldown) {
128 che_count = (civ * n / 3000) + 5;
129 if (che_count * 2 > civ)
131 che_count /= hap_fact(getnatp(newown), getnatp(sp->sct_own));
132 if (che_count + oldche > CHE_MAX)
133 che_count = CHE_MAX - oldche;
141 sp->sct_che = che_count;
142 if (newown != sp->sct_oldown)
143 sp->sct_che_target = newown;
144 sp->sct_item[I_CIVIL] = civ;
145 if (sp->sct_oldown == newown || civ == 0) {
147 * taking over one of your old sectors
150 sp->sct_oldown = newown;
153 * taking over someone else's sector
157 makelost(EF_SECTOR, sp->sct_own, 0, sp->sct_x, sp->sct_y);
158 makenotlost(EF_SECTOR, newown, 0, sp->sct_x, sp->sct_y);
159 sp->sct_own = newown;
160 if (opt_MOB_ACCESS) {
161 time(&sp->sct_access);
162 sp->sct_mobil = -(etu_per_update / sect_mob_neg_factor);
169 takeover_plane(struct plnstr *pp, natid newown)
173 if ((pp->pln_own == newown) || (pp->pln_own == 0))
175 if (pp->pln_flags & PLN_LAUNCHED)
177 if (pp->pln_ship >= 0 || pp->pln_land >= 0)
180 * XXX If this was done right, planes could escape,
181 * flying to a nearby friendly airport.
183 n = pp->pln_effic - (30 + (random() % 100));
187 if (pp->pln_effic < PLANE_MINEFF || pp->pln_harden > 0) {
189 mpr(newown, "%s blown up by the crew!\n", prplane(pp));
191 "%s blown up by the crew to avoid capture by %s at %s!\n",
193 cname(newown), xyas(pp->pln_x, pp->pln_y, pp->pln_own));
195 mpr(newown, "We have captured %s!\n", prplane(pp));
197 "%s captured by %s at %s!\n",
199 cname(newown), xyas(pp->pln_x, pp->pln_y, pp->pln_own));
202 trdswitchown(EF_PLANE, pp, newown);
203 if (pp->pln_mobil > 0)
205 makelost(EF_PLANE, pp->pln_own, pp->pln_uid, pp->pln_x, pp->pln_y);
206 pp->pln_own = newown;
207 makenotlost(EF_PLANE, pp->pln_own, pp->pln_uid, pp->pln_x, pp->pln_y);
210 putplane(pp->pln_uid, pp);
214 takeover_ship(struct shpstr *sp, natid newown, int hostile)
223 trdswitchown(EF_SHIP, sp, newown);
224 makelost(EF_SHIP, sp->shp_own, sp->shp_uid, sp->shp_x, sp->shp_y);
225 sp->shp_own = newown;
226 makenotlost(EF_SHIP, sp->shp_own, sp->shp_uid, sp->shp_x, sp->shp_y);
230 /* Keep track of when this was taken over */
231 time(&sp->shp_access);
232 memset(sp->shp_rpath, 0, sizeof(sp->shp_rpath));
235 /* Take over planes */
236 snxtitem_all(&ni, EF_PLANE);
237 while (nxtitem(&ni, pp)) {
238 if (pp->pln_ship != sp->shp_uid)
240 if (pp->pln_own == 0)
243 if (pp->pln_effic > PLANE_MINEFF)
244 pp->pln_effic = PLANE_MINEFF;
247 /* Keep track of when this was taken over */
248 time(&pp->pln_access);
250 trdswitchown(EF_PLANE, pp, newown);
252 makelost(EF_PLANE, pp->pln_own, pp->pln_uid, pp->pln_x, pp->pln_y);
253 pp->pln_own = newown;
254 makenotlost(EF_PLANE, pp->pln_own, pp->pln_uid,
255 pp->pln_x, pp->pln_y);
256 putplane(pp->pln_uid, pp);
258 /* Take over land units */
259 snxtitem_all(&ni, EF_LAND);
260 while (nxtitem(&ni, lp)) {
261 if (lp->lnd_ship != sp->shp_uid)
263 if (lp->lnd_own == 0)
265 takeover_land(lp, newown, hostile);
267 putship(sp->shp_uid, sp);
271 takeover_land(struct lndstr *landp, natid newown, int hostile)
279 if (landp->lnd_effic < LAND_MINEFF) {
280 putland(landp->lnd_uid, landp);
284 landp->lnd_mobil = 0;
285 landp->lnd_harden = 0;
286 /* Keep track of when this was taken over */
287 time(&landp->lnd_access);
289 trdswitchown(EF_LAND, landp, newown);
290 landp->lnd_mission = 0;
291 makelost(EF_LAND, landp->lnd_own, landp->lnd_uid,
292 landp->lnd_x, landp->lnd_y);
293 landp->lnd_own = newown;
294 makenotlost(EF_LAND, landp->lnd_own, landp->lnd_uid,
295 landp->lnd_x, landp->lnd_y);
298 /* Take over planes */
299 snxtitem_all(&ni, EF_PLANE);
300 while (nxtitem(&ni, pp)) {
301 if (pp->pln_land != landp->lnd_uid)
303 if (pp->pln_own == 0)
306 if (pp->pln_effic > PLANE_MINEFF)
307 pp->pln_effic = PLANE_MINEFF;
310 /* Keep track of when this was taken over */
311 time(&pp->pln_access);
313 trdswitchown(EF_PLANE, pp, newown);
315 makelost(EF_PLANE, pp->pln_own, pp->pln_uid, pp->pln_x, pp->pln_y);
316 pp->pln_own = newown;
317 makenotlost(EF_PLANE, pp->pln_own, pp->pln_uid,
318 pp->pln_x, pp->pln_y);
319 putplane(pp->pln_uid, pp);
321 /* Take over land units */
322 snxtitem_all(&ni, EF_LAND);
323 while (nxtitem(&ni, lp)) {
324 if (lp->lnd_land != landp->lnd_uid)
326 if (lp->lnd_own == 0)
328 takeover_land(lp, newown, hostile);
330 putland(landp->lnd_uid, landp);