2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2000, 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)
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, (caddr_t)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, (caddr_t)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 = get_che_value(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);
128 if (n > 0 && sp->sct_own == sp->sct_oldown) {
129 che_count = (civ * n / 3000) + 5;
130 if (che_count * 2 > civ)
132 che_count /= hap_fact(getnatp(newown), getnatp(sp->sct_own));
133 if (che_count + oldche > CHE_MAX)
134 che_count = CHE_MAX - oldche;
142 set_che_value(che, che_count);
143 if (newown != sp->sct_oldown)
144 set_che_cnum(che, newown);
146 sp->sct_item[I_CIVIL] = civ;
147 if (sp->sct_oldown == newown || civ == 0) {
149 * taking over one of your old sectors
152 sp->sct_oldown = newown;
155 * taking over someone else's sector
159 makelost(EF_SECTOR, sp->sct_own, 0, sp->sct_x, sp->sct_y);
160 makenotlost(EF_SECTOR, newown, 0, sp->sct_x, sp->sct_y);
161 sp->sct_own = newown;
162 if (opt_MOB_ACCESS) {
163 time(&sp->sct_access);
164 sp->sct_mobil = -(etu_per_update / sect_mob_neg_factor);
171 takeover_plane(register 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 > (s_char)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, (int *)pp, newown);
205 if (pp->pln_mobil > (s_char)0)
207 makelost(EF_PLANE, pp->pln_own, pp->pln_uid, pp->pln_x, pp->pln_y);
208 pp->pln_own = newown;
209 makenotlost(EF_PLANE, pp->pln_own, pp->pln_uid, pp->pln_x, pp->pln_y);
211 putplane(pp->pln_uid, pp);
215 takeover_ship(register struct shpstr *sp, natid newown, int hostile)
217 register struct plnstr *pp;
218 register struct lndstr *lp;
224 trdswitchown(EF_SHIP, (int *)sp, newown);
225 makelost(EF_SHIP, sp->shp_own, sp->shp_uid, sp->shp_x, sp->shp_y);
226 sp->shp_own = newown;
227 makenotlost(EF_SHIP, sp->shp_own, sp->shp_uid, sp->shp_x, sp->shp_y);
231 /* Keep track of when this was taken over */
232 time(&sp->shp_access);
233 memset(sp->shp_rpath, 0, sizeof(sp->shp_rpath));
236 /* Take over planes */
237 snxtitem_all(&ni, EF_PLANE);
238 while (nxtitem(&ni, (caddr_t)pp)) {
239 if (pp->pln_ship != sp->shp_uid)
241 if (pp->pln_own == 0)
244 if (pp->pln_effic > PLANE_MINEFF)
245 pp->pln_effic = PLANE_MINEFF;
248 /* Keep track of when this was taken over */
249 time(&pp->pln_access);
251 trdswitchown(EF_PLANE, (int *)pp, newown);
253 makelost(EF_PLANE, pp->pln_own, pp->pln_uid, pp->pln_x, pp->pln_y);
254 pp->pln_own = newown;
255 makenotlost(EF_PLANE, pp->pln_own, pp->pln_uid, pp->pln_x,
257 putplane(pp->pln_uid, pp);
259 /* Take over land units */
260 snxtitem_all(&ni, EF_LAND);
261 while (nxtitem(&ni, (caddr_t)lp)) {
262 if (lp->lnd_ship != sp->shp_uid)
264 if (lp->lnd_own == 0)
266 takeover_land(lp, newown, hostile);
268 putship(sp->shp_uid, sp);
272 takeover_land(register struct lndstr *landp, natid newown, int hostile)
274 register struct plnstr *pp;
275 register struct lndstr *lp;
280 if (landp->lnd_effic < LAND_MINEFF) {
281 putland(landp->lnd_uid, landp);
284 landp->lnd_army = ' ';
285 landp->lnd_mobil = 0;
286 landp->lnd_harden = 0;
287 /* Keep track of when this was taken over */
288 time(&landp->lnd_access);
290 trdswitchown(EF_LAND, (int *)landp, newown);
291 landp->lnd_mission = 0;
292 makelost(EF_LAND, landp->lnd_own, landp->lnd_uid, landp->lnd_x,
294 landp->lnd_own = newown;
295 makenotlost(EF_LAND, landp->lnd_own, landp->lnd_uid, landp->lnd_x,
299 /* Take over planes */
300 snxtitem_all(&ni, EF_PLANE);
301 while (nxtitem(&ni, (caddr_t)pp)) {
302 if (pp->pln_land != landp->lnd_uid)
304 if (pp->pln_own == 0)
307 if (pp->pln_effic > PLANE_MINEFF)
308 pp->pln_effic = PLANE_MINEFF;
311 /* Keep track of when this was taken over */
312 time(&pp->pln_access);
314 trdswitchown(EF_PLANE, (int *)pp, newown);
316 makelost(EF_PLANE, pp->pln_own, pp->pln_uid, pp->pln_x, pp->pln_y);
317 pp->pln_own = newown;
318 makenotlost(EF_PLANE, pp->pln_own, pp->pln_uid, pp->pln_x,
320 putplane(pp->pln_uid, pp);
322 /* Take over land units */
323 snxtitem_all(&ni, EF_LAND);
324 while (nxtitem(&ni, (caddr_t)lp)) {
325 if (lp->lnd_land != landp->lnd_uid)
327 if (lp->lnd_own == 0)
329 takeover_land(lp, newown, hostile);
331 putland(landp->lnd_uid, landp);