2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2008, 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"
52 takeover(struct sctstr *sp, natid newown)
64 /* Wipe all the distribution info */
65 memset(sp->sct_dist, 0, sizeof(sp->sct_dist));
66 memset(sp->sct_del, 0, sizeof(sp->sct_del));
71 sp->sct_dist_x = sp->sct_x;
72 sp->sct_dist_y = sp->sct_y;
75 /* Take over planes */
76 snxtitem_dist(&ni, EF_PLANE, sp->sct_x, sp->sct_y, 0);
77 while (nxtitem(&ni, pp)) {
78 if (pp->pln_own != sp->sct_own)
80 takeover_plane(pp, newown);
83 /* Take over land units */
85 snxtitem_dist(&ni, EF_LAND, sp->sct_x, sp->sct_y, 0);
86 while (nxtitem(&ni, lp)) {
87 if ((lp->lnd_own == newown) || (lp->lnd_own == 0))
89 if (lp->lnd_own != sp->sct_own)
91 if (lp->lnd_ship >= 0 || lp->lnd_land >= 0)
93 /* Spies get a chance to hide */
94 if (lchr[(int)lp->lnd_type].l_flags & L_SPY) {
95 if (!(chance(LND_SPY_DETECT_CHANCE(lp->lnd_effic))))
98 n = lp->lnd_effic - (30 + (random() % 100));
102 if (lp->lnd_effic < LAND_MINEFF) {
104 mpr(newown, "%s blown up by the crew!\n", prland(lp));
106 "%s blown up by the crew when %s took %s!\n",
108 cname(newown), xyas(lp->lnd_x, lp->lnd_y, lp->lnd_own));
110 mpr(newown, "We have captured %s!\n", prland(lp));
112 "%s captured when %s took %s!\n",
114 cname(newown), xyas(lp->lnd_x, lp->lnd_y, lp->lnd_own));
116 takeover_land(lp, newown, 1);
120 civ = sp->sct_item[I_CIVIL];
121 oldche = sp->sct_che;
123 * create guerrillas from civilians
124 * how spunky are these guys?
125 * n: random number from -25:75 + (50 - loyalty)
127 n = (50 - sp->sct_loyal) + ((random() % 100) - 25);
129 if (n > 0 && sp->sct_own == sp->sct_oldown) {
130 che_count = (civ * n / 3000) + 5;
131 if (che_count * 2 > civ)
133 che_count /= hap_fact(getnatp(newown), getnatp(sp->sct_own));
134 if (che_count + oldche > CHE_MAX)
135 che_count = CHE_MAX - oldche;
143 sp->sct_che = che_count;
144 if (newown != sp->sct_oldown)
145 sp->sct_che_target = newown;
146 if (sp->sct_che_target == 0)
148 sp->sct_item[I_CIVIL] = civ;
149 if (sp->sct_oldown == newown || civ == 0) {
151 * taking over one of your old sectors
154 sp->sct_oldown = newown;
157 * taking over someone else's sector
161 makelost(EF_SECTOR, sp->sct_own, 0, sp->sct_x, sp->sct_y);
162 makenotlost(EF_SECTOR, newown, 0, sp->sct_x, sp->sct_y);
163 sp->sct_own = newown;
164 if (opt_MOB_ACCESS) {
165 game_tick_to_now(&sp->sct_access);
166 sp->sct_mobil = -(etu_per_update / sect_mob_neg_factor);
173 takeover_plane(struct plnstr *pp, natid newown)
177 if ((pp->pln_own == newown) || (pp->pln_own == 0))
179 if (pp->pln_flags & PLN_LAUNCHED)
181 if (pp->pln_ship >= 0 || pp->pln_land >= 0)
184 * XXX If this was done right, planes could escape,
185 * flying to a nearby friendly airport.
187 n = pp->pln_effic - (30 + (random() % 100));
191 if (pp->pln_effic < PLANE_MINEFF || pp->pln_harden > 0) {
193 mpr(newown, "%s blown up by the crew!\n", prplane(pp));
195 "%s blown up by the crew to avoid capture by %s at %s!\n",
197 cname(newown), xyas(pp->pln_x, pp->pln_y, pp->pln_own));
199 mpr(newown, "We have captured %s!\n", prplane(pp));
201 "%s captured by %s at %s!\n",
203 cname(newown), xyas(pp->pln_x, pp->pln_y, pp->pln_own));
206 trdswitchown(EF_PLANE, pp, newown);
207 if (pp->pln_mobil > 0)
209 makelost(EF_PLANE, pp->pln_own, pp->pln_uid, pp->pln_x, pp->pln_y);
210 pp->pln_own = newown;
211 makenotlost(EF_PLANE, pp->pln_own, pp->pln_uid, pp->pln_x, pp->pln_y);
214 putplane(pp->pln_uid, pp);
218 takeover_ship(struct shpstr *sp, natid newown, int hostile)
227 trdswitchown(EF_SHIP, sp, newown);
228 makelost(EF_SHIP, sp->shp_own, sp->shp_uid, sp->shp_x, sp->shp_y);
229 sp->shp_own = newown;
230 makenotlost(EF_SHIP, sp->shp_own, sp->shp_uid, sp->shp_x, sp->shp_y);
234 memset(sp->shp_rpath, 0, sizeof(sp->shp_rpath));
237 /* Take over planes */
238 snxtitem_all(&ni, EF_PLANE);
239 while (nxtitem(&ni, pp)) {
240 if (pp->pln_ship != sp->shp_uid)
242 if (pp->pln_own == 0)
245 if (pp->pln_effic > PLANE_MINEFF)
246 pp->pln_effic = PLANE_MINEFF;
250 game_tick_to_now(&pp->pln_access);
252 trdswitchown(EF_PLANE, pp, newown);
254 makelost(EF_PLANE, pp->pln_own, pp->pln_uid, pp->pln_x, pp->pln_y);
255 pp->pln_own = newown;
256 makenotlost(EF_PLANE, pp->pln_own, pp->pln_uid,
257 pp->pln_x, pp->pln_y);
258 putplane(pp->pln_uid, pp);
260 /* Take over land units */
261 snxtitem_all(&ni, EF_LAND);
262 while (nxtitem(&ni, lp)) {
263 if (lp->lnd_ship != sp->shp_uid)
265 if (lp->lnd_own == 0)
267 takeover_land(lp, newown, hostile);
269 putship(sp->shp_uid, sp);
273 takeover_land(struct lndstr *landp, natid newown, int hostile)
281 if (landp->lnd_effic < LAND_MINEFF) {
282 putland(landp->lnd_uid, landp);
286 landp->lnd_mobil = 0;
288 game_tick_to_now(&landp->lnd_access);
289 landp->lnd_harden = 0;
291 trdswitchown(EF_LAND, landp, newown);
292 landp->lnd_mission = 0;
293 makelost(EF_LAND, landp->lnd_own, landp->lnd_uid,
294 landp->lnd_x, landp->lnd_y);
295 landp->lnd_own = newown;
296 makenotlost(EF_LAND, landp->lnd_own, landp->lnd_uid,
297 landp->lnd_x, landp->lnd_y);
300 /* Take over planes */
301 snxtitem_all(&ni, EF_PLANE);
302 while (nxtitem(&ni, pp)) {
303 if (pp->pln_land != landp->lnd_uid)
305 if (pp->pln_own == 0)
308 if (pp->pln_effic > PLANE_MINEFF)
309 pp->pln_effic = PLANE_MINEFF;
313 game_tick_to_now(&pp->pln_access);
315 trdswitchown(EF_PLANE, pp, newown);
317 makelost(EF_PLANE, pp->pln_own, pp->pln_uid, pp->pln_x, pp->pln_y);
318 pp->pln_own = newown;
319 makenotlost(EF_PLANE, pp->pln_own, pp->pln_uid,
320 pp->pln_x, pp->pln_y);
321 putplane(pp->pln_uid, pp);
323 /* Take over land units */
324 snxtitem_all(&ni, EF_LAND);
325 while (nxtitem(&ni, lp)) {
326 if (lp->lnd_land != landp->lnd_uid)
328 if (lp->lnd_own == 0)
330 takeover_land(lp, newown, hostile);
332 putland(landp->lnd_uid, landp);