2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2004, 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 the "LEGAL", "LICENSE", "CREDITS" and "README" files for all the
23 * related information and legal notices. It is expected that any future
24 * 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
45 #include "prototypes.h"
49 takeover(register struct sctstr *sp, natid newown)
61 /* Wipe all the distribution info */
62 memset(sp->sct_dist, 0, sizeof(sp->sct_dist));
63 memset(sp->sct_del, 0, sizeof(sp->sct_del));
68 sp->sct_dist_x = sp->sct_x;
69 sp->sct_dist_y = sp->sct_y;
72 /* Take over planes */
73 snxtitem_dist(&ni, EF_PLANE, sp->sct_x, sp->sct_y, 0);
74 while (nxtitem(&ni, pp)) {
75 if (pp->pln_own != sp->sct_own)
77 takeover_plane(pp, newown);
80 /* Take over land units */
82 snxtitem_dist(&ni, EF_LAND, sp->sct_x, sp->sct_y, 0);
83 while (nxtitem(&ni, lp)) {
84 if ((lp->lnd_own == newown) || (lp->lnd_own == 0))
86 if (lp->lnd_own != sp->sct_own)
88 if (lp->lnd_ship >= 0 || lp->lnd_land >= 0)
90 /* Spies get a chance to hide */
91 if (lchr[(int)lp->lnd_type].l_flags & L_SPY) {
92 if (!(chance(LND_SPY_DETECT_CHANCE(lp->lnd_effic))))
95 n = lp->lnd_effic - (30 + (random() % 100));
99 if (lp->lnd_effic < LAND_MINEFF) {
101 mpr(newown, "%s blown up by the crew!\n", prland(lp));
103 "%s blown up by the crew when %s took %s!\n",
105 cname(newown), xyas(lp->lnd_x, lp->lnd_y, lp->lnd_own));
107 mpr(newown, "We have captured %s!\n", prland(lp));
109 "%s captured when %s took %s!\n",
111 cname(newown), xyas(lp->lnd_x, lp->lnd_y, lp->lnd_own));
113 takeover_land(lp, newown, 1);
117 civ = sp->sct_item[I_CIVIL];
118 oldche = sp->sct_che;
120 * create guerrillas from civilians
121 * how spunky are these guys?
122 * n: random number from -25:75 + (50 - loyalty)
124 n = (50 - sp->sct_loyal) + ((random() % 100) - 25);
126 if (n > 0 && sp->sct_own == sp->sct_oldown) {
127 che_count = (civ * n / 3000) + 5;
128 if (che_count * 2 > civ)
130 che_count /= hap_fact(getnatp(newown), getnatp(sp->sct_own));
131 if (che_count + oldche > CHE_MAX)
132 che_count = CHE_MAX - oldche;
140 sp->sct_che = che_count;
141 if (newown != sp->sct_oldown)
142 sp->sct_che_target = newown;
143 sp->sct_item[I_CIVIL] = civ;
144 if (sp->sct_oldown == newown || civ == 0) {
146 * taking over one of your old sectors
149 sp->sct_oldown = newown;
152 * taking over someone else's sector
156 makelost(EF_SECTOR, sp->sct_own, 0, sp->sct_x, sp->sct_y);
157 makenotlost(EF_SECTOR, newown, 0, sp->sct_x, sp->sct_y);
158 sp->sct_own = newown;
159 if (opt_MOB_ACCESS) {
160 time(&sp->sct_access);
161 sp->sct_mobil = -(etu_per_update / sect_mob_neg_factor);
168 takeover_plane(register struct plnstr *pp, natid newown)
172 if ((pp->pln_own == newown) || (pp->pln_own == 0))
174 if (pp->pln_flags & PLN_LAUNCHED)
176 if (pp->pln_ship >= 0 || pp->pln_land >= 0)
179 * XXX If this was done right, planes could escape,
180 * flying to a nearby friendly airport.
182 n = pp->pln_effic - (30 + (random() % 100));
186 if (pp->pln_effic < PLANE_MINEFF || pp->pln_harden > (s_char)0) {
188 mpr(newown, "%s blown up by the crew!\n", prplane(pp));
190 "%s blown up by the crew to avoid capture by %s at %s!\n",
192 cname(newown), xyas(pp->pln_x, pp->pln_y, pp->pln_own));
194 mpr(newown, "We have captured %s!\n", prplane(pp));
196 "%s captured by %s at %s!\n",
198 cname(newown), xyas(pp->pln_x, pp->pln_y, pp->pln_own));
201 trdswitchown(EF_PLANE, (int *)pp, newown);
202 if (pp->pln_mobil > (s_char)0)
204 makelost(EF_PLANE, pp->pln_own, pp->pln_uid, pp->pln_x, pp->pln_y);
205 pp->pln_own = newown;
206 makenotlost(EF_PLANE, pp->pln_own, pp->pln_uid, pp->pln_x, pp->pln_y);
208 putplane(pp->pln_uid, pp);
212 takeover_ship(register struct shpstr *sp, natid newown, int hostile)
214 register struct plnstr *pp;
215 register struct lndstr *lp;
221 trdswitchown(EF_SHIP, (int *)sp, newown);
222 makelost(EF_SHIP, sp->shp_own, sp->shp_uid, sp->shp_x, sp->shp_y);
223 sp->shp_own = newown;
224 makenotlost(EF_SHIP, sp->shp_own, sp->shp_uid, sp->shp_x, sp->shp_y);
228 /* Keep track of when this was taken over */
229 time(&sp->shp_access);
230 memset(sp->shp_rpath, 0, sizeof(sp->shp_rpath));
233 /* Take over planes */
234 snxtitem_all(&ni, EF_PLANE);
235 while (nxtitem(&ni, pp)) {
236 if (pp->pln_ship != sp->shp_uid)
238 if (pp->pln_own == 0)
241 if (pp->pln_effic > PLANE_MINEFF)
242 pp->pln_effic = PLANE_MINEFF;
245 /* Keep track of when this was taken over */
246 time(&pp->pln_access);
248 trdswitchown(EF_PLANE, (int *)pp, newown);
250 makelost(EF_PLANE, pp->pln_own, pp->pln_uid, pp->pln_x, pp->pln_y);
251 pp->pln_own = newown;
252 makenotlost(EF_PLANE, pp->pln_own, pp->pln_uid, pp->pln_x,
254 putplane(pp->pln_uid, pp);
256 /* Take over land units */
257 snxtitem_all(&ni, EF_LAND);
258 while (nxtitem(&ni, lp)) {
259 if (lp->lnd_ship != sp->shp_uid)
261 if (lp->lnd_own == 0)
263 takeover_land(lp, newown, hostile);
265 putship(sp->shp_uid, sp);
269 takeover_land(register struct lndstr *landp, natid newown, int hostile)
271 register struct plnstr *pp;
272 register struct lndstr *lp;
277 if (landp->lnd_effic < LAND_MINEFF) {
278 putland(landp->lnd_uid, landp);
281 landp->lnd_army = ' ';
282 landp->lnd_mobil = 0;
283 landp->lnd_harden = 0;
284 /* Keep track of when this was taken over */
285 time(&landp->lnd_access);
287 trdswitchown(EF_LAND, (int *)landp, newown);
288 landp->lnd_mission = 0;
289 makelost(EF_LAND, landp->lnd_own, landp->lnd_uid, landp->lnd_x,
291 landp->lnd_own = newown;
292 makenotlost(EF_LAND, landp->lnd_own, landp->lnd_uid, landp->lnd_x,
296 /* Take over planes */
297 snxtitem_all(&ni, EF_PLANE);
298 while (nxtitem(&ni, pp)) {
299 if (pp->pln_land != landp->lnd_uid)
301 if (pp->pln_own == 0)
304 if (pp->pln_effic > PLANE_MINEFF)
305 pp->pln_effic = PLANE_MINEFF;
308 /* Keep track of when this was taken over */
309 time(&pp->pln_access);
311 trdswitchown(EF_PLANE, (int *)pp, newown);
313 makelost(EF_PLANE, pp->pln_own, pp->pln_uid, pp->pln_x, pp->pln_y);
314 pp->pln_own = newown;
315 makenotlost(EF_PLANE, pp->pln_own, pp->pln_uid, pp->pln_x,
317 putplane(pp->pln_uid, pp);
319 /* Take over land units */
320 snxtitem_all(&ni, EF_LAND);
321 while (nxtitem(&ni, lp)) {
322 if (lp->lnd_land != landp->lnd_uid)
324 if (lp->lnd_own == 0)
326 takeover_land(lp, newown, hostile);
328 putland(landp->lnd_uid, landp);