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"
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 time(&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 /* Keep track of when this was taken over */
235 time(&sp->shp_access);
236 memset(sp->shp_rpath, 0, sizeof(sp->shp_rpath));
239 /* Take over planes */
240 snxtitem_all(&ni, EF_PLANE);
241 while (nxtitem(&ni, pp)) {
242 if (pp->pln_ship != sp->shp_uid)
244 if (pp->pln_own == 0)
247 if (pp->pln_effic > PLANE_MINEFF)
248 pp->pln_effic = PLANE_MINEFF;
251 /* Keep track of when this was taken over */
252 time(&pp->pln_access);
254 trdswitchown(EF_PLANE, pp, newown);
256 makelost(EF_PLANE, pp->pln_own, pp->pln_uid, pp->pln_x, pp->pln_y);
257 pp->pln_own = newown;
258 makenotlost(EF_PLANE, pp->pln_own, pp->pln_uid,
259 pp->pln_x, pp->pln_y);
260 putplane(pp->pln_uid, pp);
262 /* Take over land units */
263 snxtitem_all(&ni, EF_LAND);
264 while (nxtitem(&ni, lp)) {
265 if (lp->lnd_ship != sp->shp_uid)
267 if (lp->lnd_own == 0)
269 takeover_land(lp, newown, hostile);
271 putship(sp->shp_uid, sp);
275 takeover_land(struct lndstr *landp, natid newown, int hostile)
283 if (landp->lnd_effic < LAND_MINEFF) {
284 putland(landp->lnd_uid, landp);
288 landp->lnd_mobil = 0;
289 landp->lnd_harden = 0;
290 /* Keep track of when this was taken over */
291 time(&landp->lnd_access);
293 trdswitchown(EF_LAND, landp, newown);
294 landp->lnd_mission = 0;
295 makelost(EF_LAND, landp->lnd_own, landp->lnd_uid,
296 landp->lnd_x, landp->lnd_y);
297 landp->lnd_own = newown;
298 makenotlost(EF_LAND, landp->lnd_own, landp->lnd_uid,
299 landp->lnd_x, landp->lnd_y);
302 /* Take over planes */
303 snxtitem_all(&ni, EF_PLANE);
304 while (nxtitem(&ni, pp)) {
305 if (pp->pln_land != landp->lnd_uid)
307 if (pp->pln_own == 0)
310 if (pp->pln_effic > PLANE_MINEFF)
311 pp->pln_effic = PLANE_MINEFF;
314 /* Keep track of when this was taken over */
315 time(&pp->pln_access);
317 trdswitchown(EF_PLANE, pp, newown);
319 makelost(EF_PLANE, pp->pln_own, pp->pln_uid, pp->pln_x, pp->pln_y);
320 pp->pln_own = newown;
321 makenotlost(EF_PLANE, pp->pln_own, pp->pln_uid,
322 pp->pln_x, pp->pln_y);
323 putplane(pp->pln_uid, pp);
325 /* Take over land units */
326 snxtitem_all(&ni, EF_LAND);
327 while (nxtitem(&ni, lp)) {
328 if (lp->lnd_land != landp->lnd_uid)
330 if (lp->lnd_own == 0)
332 takeover_land(lp, newown, hostile);
334 putland(landp->lnd_uid, landp);