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_xy(&ni, EF_PLANE, sp->sct_x, sp->sct_y);
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_xy(&ni, EF_LAND, sp->sct_x, sp->sct_y);
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);
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 sp->sct_own = newown;
162 if (opt_MOB_ACCESS) {
163 game_tick_to_now(&sp->sct_access);
164 sp->sct_mobil = -(etu_per_update / sect_mob_neg_factor);
171 takeover_plane(struct plnstr *pp, natid newown)
175 if ((pp->pln_own == newown) || (pp->pln_own == 0))
177 if (pp->pln_flags & PLN_LAUNCHED)
179 if (pp->pln_ship >= 0 || pp->pln_land >= 0)
182 * XXX If this was done right, planes could escape,
183 * flying to a nearby friendly airport.
185 n = pp->pln_effic - (30 + (random() % 100));
189 if (pp->pln_effic < PLANE_MINEFF || pp->pln_harden > 0) {
191 mpr(newown, "%s blown up by the crew!\n", prplane(pp));
193 "%s blown up by the crew to avoid capture by %s at %s!\n",
195 cname(newown), xyas(pp->pln_x, pp->pln_y, pp->pln_own));
197 mpr(newown, "We have captured %s!\n", prplane(pp));
199 "%s captured by %s at %s!\n",
201 cname(newown), xyas(pp->pln_x, pp->pln_y, pp->pln_own));
204 trdswitchown(EF_PLANE, pp, newown);
205 if (pp->pln_mobil > 0)
207 pp->pln_own = newown;
210 putplane(pp->pln_uid, pp);
214 takeover_ship(struct shpstr *sp, natid newown)
223 trdswitchown(EF_SHIP, sp, newown);
224 sp->shp_own = newown;
228 memset(sp->shp_rpath, 0, sizeof(sp->shp_rpath));
231 /* Take over planes */
232 snxtitem_cargo(&ni, EF_PLANE, EF_SHIP, sp->shp_uid);
233 while (nxtitem(&ni, pp)) {
234 if (pp->pln_effic > PLANE_MINEFF)
235 pp->pln_effic = PLANE_MINEFF;
238 game_tick_to_now(&pp->pln_access);
240 trdswitchown(EF_PLANE, pp, newown);
242 pp->pln_own = newown;
243 putplane(pp->pln_uid, pp);
245 /* Take over land units */
246 snxtitem_cargo(&ni, EF_LAND, EF_SHIP, sp->shp_uid);
247 while (nxtitem(&ni, lp))
248 takeover_land(lp, newown);
249 putship(sp->shp_uid, sp);
253 takeover_land(struct lndstr *landp, natid newown)
261 if (landp->lnd_effic < LAND_MINEFF) {
262 putland(landp->lnd_uid, landp);
266 landp->lnd_mobil = 0;
268 game_tick_to_now(&landp->lnd_access);
269 landp->lnd_harden = 0;
271 trdswitchown(EF_LAND, landp, newown);
272 landp->lnd_mission = 0;
273 landp->lnd_own = newown;
276 /* Take over planes */
277 snxtitem_cargo(&ni, EF_PLANE, EF_LAND, landp->lnd_uid);
278 while (nxtitem(&ni, pp)) {
279 if (pp->pln_effic > PLANE_MINEFF)
280 pp->pln_effic = PLANE_MINEFF;
283 game_tick_to_now(&pp->pln_access);
285 trdswitchown(EF_PLANE, pp, newown);
287 pp->pln_own = newown;
288 putplane(pp->pln_uid, pp);
290 /* Take over land units */
291 snxtitem_cargo(&ni, EF_LAND, EF_LAND, landp->lnd_uid);
292 while (nxtitem(&ni, lp))
293 takeover_land(lp, newown);
294 putland(landp->lnd_uid, landp);