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);
209 putplane(pp->pln_uid, pp);
213 takeover_ship(struct shpstr *sp, natid newown, int hostile)
222 trdswitchown(EF_SHIP, sp, newown);
223 makelost(EF_SHIP, sp->shp_own, sp->shp_uid, sp->shp_x, sp->shp_y);
224 sp->shp_own = newown;
225 makenotlost(EF_SHIP, sp->shp_own, sp->shp_uid, sp->shp_x, sp->shp_y);
229 /* Keep track of when this was taken over */
230 time(&sp->shp_access);
231 memset(sp->shp_rpath, 0, sizeof(sp->shp_rpath));
234 /* Take over planes */
235 snxtitem_all(&ni, EF_PLANE);
236 while (nxtitem(&ni, pp)) {
237 if (pp->pln_ship != sp->shp_uid)
239 if (pp->pln_own == 0)
242 if (pp->pln_effic > PLANE_MINEFF)
243 pp->pln_effic = PLANE_MINEFF;
246 /* Keep track of when this was taken over */
247 time(&pp->pln_access);
249 trdswitchown(EF_PLANE, pp, newown);
251 makelost(EF_PLANE, pp->pln_own, pp->pln_uid, pp->pln_x, pp->pln_y);
252 pp->pln_own = newown;
253 makenotlost(EF_PLANE, pp->pln_own, pp->pln_uid,
254 pp->pln_x, pp->pln_y);
255 putplane(pp->pln_uid, pp);
257 /* Take over land units */
258 snxtitem_all(&ni, EF_LAND);
259 while (nxtitem(&ni, lp)) {
260 if (lp->lnd_ship != sp->shp_uid)
262 if (lp->lnd_own == 0)
264 takeover_land(lp, newown, hostile);
266 putship(sp->shp_uid, sp);
270 takeover_land(struct lndstr *landp, natid newown, int hostile)
278 if (landp->lnd_effic < LAND_MINEFF) {
279 putland(landp->lnd_uid, landp);
282 landp->lnd_army = ' ';
283 landp->lnd_mobil = 0;
284 landp->lnd_harden = 0;
285 /* Keep track of when this was taken over */
286 time(&landp->lnd_access);
288 trdswitchown(EF_LAND, landp, newown);
289 landp->lnd_mission = 0;
290 makelost(EF_LAND, landp->lnd_own, landp->lnd_uid,
291 landp->lnd_x, landp->lnd_y);
292 landp->lnd_own = newown;
293 makenotlost(EF_LAND, landp->lnd_own, landp->lnd_uid,
294 landp->lnd_x, landp->lnd_y);
297 /* Take over planes */
298 snxtitem_all(&ni, EF_PLANE);
299 while (nxtitem(&ni, pp)) {
300 if (pp->pln_land != landp->lnd_uid)
302 if (pp->pln_own == 0)
305 if (pp->pln_effic > PLANE_MINEFF)
306 pp->pln_effic = PLANE_MINEFF;
309 /* Keep track of when this was taken over */
310 time(&pp->pln_access);
312 trdswitchown(EF_PLANE, pp, newown);
314 makelost(EF_PLANE, pp->pln_own, pp->pln_uid, pp->pln_x, pp->pln_y);
315 pp->pln_own = newown;
316 makenotlost(EF_PLANE, pp->pln_own, pp->pln_uid,
317 pp->pln_x, pp->pln_y);
318 putplane(pp->pln_uid, pp);
320 /* Take over land units */
321 snxtitem_all(&ni, EF_LAND);
322 while (nxtitem(&ni, lp)) {
323 if (lp->lnd_land != landp->lnd_uid)
325 if (lp->lnd_own == 0)
327 takeover_land(lp, newown, hostile);
329 putland(landp->lnd_uid, landp);