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 * revolt.c: Have disloyal populace revolt!
30 * Known contributors to this file:
32 * Steve McClure, 1997-2000
53 static void take_casualties(struct sctstr *, int);
56 revolt(struct sctstr *sp)
66 if (che != 0 && (sp->sct_che_target != sp->sct_own || che >= CHE_MAX))
68 civ = sp->sct_item[I_CIVIL];
69 uw = sp->sct_item[I_UW];
70 if (che > (civ + uw) * 3)
74 /* che due to civilian unrest */
75 n = 10 - (random() % 20);
76 che_civ = 3 + (civ * n / 500);
79 else if (che_civ * 3 > civ)
81 if (che + che_civ > CHE_MAX)
82 che_civ = CHE_MAX - che;
85 /* che due to uw unrest */
86 n = 10 + (random() % 30);
87 che_uw = 5 + (uw * n / 500);
90 if (che + che_uw > CHE_MAX)
91 che_uw = CHE_MAX - che_uw;
94 if (che_civ + che_uw > 0) {
97 sp->sct_che_target = sp->sct_own;
100 sp->sct_item[I_CIVIL] = civ;
102 sp->sct_item[I_UW] = uw;
104 logerror("(#%d) %d che fired up in %s",
105 sp->sct_own, che, ownxy(sp));
111 * summary of effects.
112 * if there are no military in the sector, che recruit from
113 * populace if pop loyalty is > 10. They spread subversion otherwise,
114 * trying to lower pop loyalty.
115 * if che outnumber military, they stay and shoot it out, kill the
117 * if che are outnumbered by less than 5 to 1, they blow up stuff,
118 * killing innocent civilians (never uw's) and damaging commodities.
119 * if che are outnumbered by more than 5 to 1, they try to leave the
120 * sector for a nearby sector with fewer military.
122 * if the military lose any attacks, the pop loyalty in the sector
123 * gets worse, representing military defeat.
124 * military can "catch" che's after bombing attacks, or after they move.
125 * If military catch them, then they get to shoot it out with a portion
126 * of the che's depending on the # of mil in the sector. Chance to contact
127 * is around 10% per every equal number of mil:che ratio in the sector.
128 * "contact" is by 20% of the military in the sector, and odds are equal.
130 * Without a doubt this routine should be broken up, if only for readabilty.
133 guerrilla(struct sctstr *sp)
165 if (getvec(VT_ITEM, vec, (s_char *)sp, EF_SECTOR) <= 0)
170 victim = sp->sct_own;
171 actor = sp->sct_oldown;
175 snxtitem_xy(&ni, EF_LAND, sp->sct_x, sp->sct_y);
177 while (NULL != (lp = (struct lndstr *)nxtitemp(&ni, 0))) {
178 if (lp->lnd_own != sp->sct_own)
181 mil += lnd_getmil(lp);
183 /* Security troops can now kill up to 1/2 their complement each
184 update, before doing anything else. */
185 if (lchr[(int)lp->lnd_type].l_flags & L_SECURITY) {
189 lcp = &lchr[(int)lp->lnd_type];
190 mil += lnd_getmil(lp);
191 r = (((float)(lp->lnd_effic / 100) * (float)(lnd_getmil(lp))) /
195 che_kill = (roll(r) - 1);
200 "%s kills %d guerrilla%s in raid at %s!\n",
201 prland(lp), che_kill, splur(che_kill), ownxy(sp));
207 /* Security forces killed all the che */
210 sp->sct_che_target = 0;
214 target = sp->sct_che_target;
216 /* the deity can't be a target! */
219 tnat = getnatp(target);
220 if ((tnat->nat_stat & STAT_INUSE) == 0) {
221 /* target nation has dissolved: che's retire. */
222 logerror("%d Che targeted at country %d retiring", che, target);
225 sp->sct_che_target = 0;
226 sp->sct_item[I_CIVIL] = civ;
230 if (sp->sct_own != target) {
231 /*logerror("own %d != target %d", sp->sct_own, target); */
237 odds = (double)che / (mil + che);
238 odds /= hap_fact(tnat, getnatp(sp->sct_oldown));
240 wu(0, sp->sct_own, "Revolutionary subversion reported in %s!\n",
244 } else if (che > mil && mil > 0) {
245 /*logerror("guerrilla shootout with military"); */
247 * shoot it out with the military, and kill them off.
248 * If loyalty bad enough, then take the sector over,
249 * and enlist 5% of civ as military force.
251 while (che > 0 && mil > 0) {
262 n = sp->sct_loyal - (random() % 15);
266 /*logerror("(#%d) mil beat che in %s", sp->sct_own, */
271 /*logerror("(#%d) che beat mil in %s", sp->sct_own, */
274 take_casualties(sp, mc);
275 } else if (ratio < 5) {
277 * guerrillas have to resort to blowing things up.
278 * Note this disrupts work in the sector.
281 n = (random() % 10) + (random() % che);
284 tmp = sp->sct_work - n;
289 "Production %s disrupted by terrorists in %s\n",
290 effadv(n), ownxy(sp));
291 sect_damage(sp, n / 10, 0);
292 /*logerror("(#%d) che blew up %s for %d", sp->sct_own, */
297 /*logerror("(#%d) %d che fleeing %d mil in %s", sp->sct_own, */
298 /*che, mil, ownxy(sp)); */
301 if (mil > 0 && che > 0) {
303 * we only get here if we haven't had combat previously.
304 * Chance to catch them.
305 * 20% of mil involved in attacking the che's.
307 if (chance(ratio * 0.10)) {
309 if ((n + che) == 0) {
310 logerror("n=%d che=%d\n", n, che);
314 odds = (double)che / (n + che);
315 odds /= hap_fact(tnat, getnatp(sp->sct_oldown));
316 while (che > 0 && n > 0) {
325 take_casualties(sp, mc);
327 /*logerror("Caught che; mc: %d, cc: %d", cc, mc); */
330 if (convert && sp->sct_loyal >= 50) {
332 /* new owner gets to keep the mobility there */
333 oldmob = sp->sct_mobil;
334 /* che won, and sector converts. */
335 if (sp->sct_own == sp->sct_oldown)
338 takeover(sp, sp->sct_oldown);
339 sp->sct_mobil = oldmob;
343 * so we can't keep losing money by having
346 if (sp->sct_type == SCT_CAPIT && sp->sct_newtype == SCT_CAPIT)
347 sp->sct_newtype = SCT_AGRI;
350 sp->sct_item[I_CIVIL] = civ;
351 sp->sct_item[I_UW] = uw;
352 sp->sct_item[I_MILIT] = n;
356 wu(0, sp->sct_own, "Sector %s has been retaken!\n",
357 xyas(sp->sct_x, sp->sct_y, sp->sct_own));
359 if (recruit && che > 0) {
360 /* loyalty drops during recruitment efforts */
363 n += (random() % 5) + 1;
365 n += (random() % 10) + 4;
369 if (sp->sct_oldown != sp->sct_own || n > 100) {
370 n = civ * (random() % 3) / 200;
371 n /= hap_fact(tnat, getnatp(sp->sct_oldown));
372 if (n + che > CHE_MAX)
376 sp->sct_item[I_CIVIL] = civ;
378 n = uw * (random() % 3) / 200;
379 if (n + che > CHE_MAX)
383 sp->sct_item[I_UW] = uw;
386 if (move && che > 0) {
387 struct sctstr *nicest_sp = 0;
392 /* search adjacent sectors for a nice one */
393 for (n = 1; n <= 6; n++) {
394 nsp = getsectp(sp->sct_x + diroff[n][0],
395 sp->sct_y + diroff[n][1]);
396 if (dchr[nsp->sct_type].d_mcst == 0)
398 if (nsp->sct_own != target)
400 if (nsp->sct_che > 0) {
401 if (nsp->sct_che_target != target)
403 if (nsp->sct_che + che > CHE_MAX)
406 val = nsp->sct_item[I_MILIT];
407 /* don't give che more precise info than spy */
408 val = roundintby(val, 10);
409 /* inject a modicum of indeterminism; also
410 * avoids che preferring certain directions */
411 val += random() % 10 - 5;
417 /* if we found a nice sector, go there */
418 if (nicest_sp != 0) {
419 nicest_sp->sct_che += che;
420 nicest_sp->sct_che_target = target;
426 sp->sct_che_target = target;
429 sp->sct_che_target = 0;
431 if (mc > 0 || cc > 0) {
432 /* don't tell who won just to be mean */
434 "Guerrilla warfare in %s\n",
435 xyas(sp->sct_x, sp->sct_y, target));
436 wu(0, target, " body count: troops: %d, rebels: %d\n", mc, cc);
437 nreport(actor, N_FREEDOM_FIGHT, victim, 1);
442 take_casualties(struct sctstr *sp, int mc)
446 int nunits = 0, each, deq;
450 /* casualties come out of mil first */
451 orig_mil = sp->sct_item[I_MILIT];
453 if (mc <= orig_mil) {
454 sp->sct_item[I_MILIT] = orig_mil - mc;
457 sp->sct_item[I_MILIT] = 0;
459 /* remaining casualites */
463 * Need to take total_casualties and divide
464 * them amongst the land units in the sector
465 * Do security troops first, then others.
466 * Try not to kill any unit.
468 snxtitem_xy(&ni, EF_LAND, sp->sct_x, sp->sct_y);
469 while (NULL != (lp = (struct lndstr *)nxtitemp(&ni, 0))) {
471 if (lchr[(int)lp->lnd_type].l_flags & L_SECURITY)
478 each = (mc / nunits) + 2;
480 /* kill some security troops */
481 snxtitem_xy(&ni, EF_LAND, sp->sct_x, sp->sct_y);
482 while (NULL != (lp = (struct lndstr *)nxtitemp(&ni, 0))) {
483 if (!(lchr[(int)lp->lnd_type].l_flags & L_SECURITY))
486 cantake = (((float)(lp->lnd_effic - 40) / 100.0) *
487 (float)lnd_getmil(lp)) * 2;
488 /* (float)lchr[lp->lnd_type].l_mil)*2; */
490 if (cantake >= each) {
491 /* deq = (((float)each/(float)(lchr[lp->lnd_type].l_mil*2)) */
492 deq = (((float)each / (float)(lnd_getmil(lp) * 2))
495 } else if (cantake > 0) {
496 deq = (((float)cantake / (float)(lnd_getmil(lp) * 2)) * 100.0);
497 /* (float)(lchr[lp->lnd_type].l_mil*2)) * 100.0); */
498 mc -= (((float)deq / 100.0) * (float)lnd_getmil(lp)) * 2;
499 /* (float)lchr[lp->lnd_type].l_mil)*2; */
503 lp->lnd_effic -= deq;
504 lp->lnd_mobil -= deq / 2;
505 deq = (double)lchr[(int)lp->lnd_type].l_mil * (deq / 100.0);
511 /* kill some normal troops */
512 snxtitem_xy(&ni, EF_LAND, sp->sct_x, sp->sct_y);
513 while (NULL != (lp = (struct lndstr *)nxtitemp(&ni, 0))) {
514 if (lchr[(int)lp->lnd_type].l_flags & L_SECURITY)
517 cantake = (((float)(lp->lnd_effic - 40) / 100.0) *
518 (float)lnd_getmil(lp));
520 if (cantake >= each) {
521 deq = (((float)each / (float)(lnd_getmil(lp) * 2))
524 } else if (cantake > 0) {
525 deq = (((float)cantake / (float)lnd_getmil(lp))
527 mc -= (((float)deq / 100.0) * (float)lnd_getmil(lp));
530 lp->lnd_effic -= deq;
531 lp->lnd_mobil -= deq / 2;
532 deq = (double)lchr[(int)lp->lnd_type].l_mil * (deq / 100.0);
538 /* Hmm.. still some left.. kill off units now */
539 /* kill some normal troops */
540 snxtitem_xy(&ni, EF_LAND, sp->sct_x, sp->sct_y);
541 while (NULL != (lp = (struct lndstr *)nxtitemp(&ni, 0))) {
542 if (lchr[(int)lp->lnd_type].l_flags & L_SECURITY)
545 mc -= (((float)lp->lnd_effic / 100.0) * (float)lnd_getmil(lp));
547 lnd_submil(lp, 1000); /* Remove 'em all */
548 wu(0, lp->lnd_own, "%s dies fighting guerrillas in %s\n",
549 prland(lp), xyas(lp->lnd_x, lp->lnd_y, lp->lnd_own));
550 makelost(EF_LAND, lp->lnd_own, lp->lnd_uid, lp->lnd_x, lp->lnd_y);
556 /* Hmm.. still some left.. kill off units now */
557 /* kill some security troops */
558 snxtitem_xy(&ni, EF_LAND, sp->sct_x, sp->sct_y);
559 while (NULL != (lp = (struct lndstr *)nxtitemp(&ni, 0))) {
560 if (!(lchr[(int)lp->lnd_type].l_flags & L_SECURITY))
563 mc -= (((float)lp->lnd_effic / 100.0) * (float)lnd_getmil(lp)) * 2;
565 lnd_submil(lp, 1000); /* Kill 'em all */
566 wu(0, lp->lnd_own, "%s dies fighting guerrillas in %s\n",
567 prland(lp), xyas(lp->lnd_x, lp->lnd_y, lp->lnd_own));
568 makelost(EF_LAND, lp->lnd_own, lp->lnd_uid, lp->lnd_x, lp->lnd_y);
574 /* Hmm.. everyone dead.. too bad */