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
47 #include "prototypes.h"
53 static void takeover_unit(struct empobj *, natid);
56 takeover(struct sctstr *sp, natid newown)
68 /* Wipe all the distribution info */
69 memset(sp->sct_dist, 0, sizeof(sp->sct_dist));
70 memset(sp->sct_del, 0, sizeof(sp->sct_del));
75 sp->sct_dist_x = sp->sct_x;
76 sp->sct_dist_y = sp->sct_y;
79 /* Take over planes */
80 snxtitem_xy(&ni, EF_PLANE, sp->sct_x, sp->sct_y);
81 while (nxtitem(&ni, pp)) {
82 if (pp->pln_own != sp->sct_own)
84 takeover_plane(pp, newown);
87 /* Take over land units */
89 snxtitem_xy(&ni, EF_LAND, sp->sct_x, sp->sct_y);
90 while (nxtitem(&ni, lp)) {
91 if ((lp->lnd_own == newown) || (lp->lnd_own == 0))
93 if (lp->lnd_own != sp->sct_own)
95 if (lp->lnd_ship >= 0 || lp->lnd_land >= 0)
97 /* Spies get a chance to hide */
98 if (lchr[(int)lp->lnd_type].l_flags & L_SPY) {
99 if (!(chance(LND_SPY_DETECT_CHANCE(lp->lnd_effic))))
102 n = lp->lnd_effic - (30 + (random() % 100));
106 if (lp->lnd_effic < LAND_MINEFF) {
108 mpr(newown, "%s blown up by the crew!\n", prland(lp));
110 "%s blown up by the crew when %s took %s!\n",
112 cname(newown), xyas(lp->lnd_x, lp->lnd_y, lp->lnd_own));
114 mpr(newown, "We have captured %s!\n", prland(lp));
116 "%s captured when %s took %s!\n",
118 cname(newown), xyas(lp->lnd_x, lp->lnd_y, lp->lnd_own));
120 takeover_land(lp, newown);
124 civ = sp->sct_item[I_CIVIL];
125 oldche = sp->sct_che;
127 * create guerrillas from civilians
128 * how spunky are these guys?
129 * n: random number from -25:75 + (50 - loyalty)
131 n = (50 - sp->sct_loyal) + ((random() % 100) - 25);
133 if (n > 0 && sp->sct_own == sp->sct_oldown) {
134 che_count = (civ * n / 3000) + 5;
135 if (che_count * 2 > civ)
137 che_count /= hap_fact(getnatp(newown), getnatp(sp->sct_own));
138 if (che_count + oldche > CHE_MAX)
139 che_count = CHE_MAX - oldche;
147 sp->sct_che = che_count;
148 if (newown != sp->sct_oldown)
149 sp->sct_che_target = newown;
150 if (sp->sct_che_target == 0)
152 sp->sct_item[I_CIVIL] = civ;
153 if (sp->sct_oldown == newown || civ == 0) {
155 * taking over one of your old sectors
158 sp->sct_oldown = newown;
161 * taking over someone else's sector
165 sp->sct_own = newown;
166 if (opt_MOB_ACCESS) {
167 game_tick_to_now(&sp->sct_access);
168 sp->sct_mobil = -(etu_per_update / sect_mob_neg_factor);
175 takeover_plane(struct plnstr *pp, natid newown)
179 if ((pp->pln_own == newown) || (pp->pln_own == 0))
181 if (pp->pln_flags & PLN_LAUNCHED)
183 if (pp->pln_ship >= 0 || pp->pln_land >= 0)
186 * XXX If this was done right, planes could escape,
187 * flying to a nearby friendly airport.
189 n = pp->pln_effic - (30 + (random() % 100));
193 if (pp->pln_effic < PLANE_MINEFF || pp->pln_harden > 0) {
195 mpr(newown, "%s blown up by the crew!\n", prplane(pp));
197 "%s blown up by the crew to avoid capture by %s at %s!\n",
199 cname(newown), xyas(pp->pln_x, pp->pln_y, pp->pln_own));
201 mpr(newown, "We have captured %s!\n", prplane(pp));
203 "%s captured by %s at %s!\n",
205 cname(newown), xyas(pp->pln_x, pp->pln_y, pp->pln_own));
207 takeover_unit((struct empobj *)pp, newown);
211 takeover_ship(struct shpstr *sp, natid newown)
213 takeover_unit((struct empobj *)sp, newown);
217 takeover_land(struct lndstr *landp, natid newown)
219 takeover_unit((struct empobj *)landp, newown);
223 takeover_unit(struct empobj *unit, natid newown)
230 union empobj_storage cargo;
234 trdswitchown(unit->ef_type, unit, newown);
235 unit_wipe_orders(unit);
237 switch (unit->ef_type) {
239 sp = (struct shpstr *)unit;
242 pp = (struct plnstr *)unit;
243 if (pp->pln_mobil > 0)
247 lp = (struct lndstr *)unit;
248 if (lp->lnd_mobil > 0)
258 put_empobj(unit->ef_type, unit->uid, unit);
260 for (type = EF_PLANE; type <= EF_NUKE; type++) {
261 snxtitem_cargo(&ni, type, unit->ef_type, unit->uid);
262 while (nxtitem(&ni, &cargo)) {
263 if (cargo.gen.own == newown)
265 if (type == EF_PLANE)
266 cargo.plane.pln_effic = PLANE_MINEFF;
267 takeover_unit(&cargo.gen, newown);