]> git.pond.sub.org Git - empserver/blobdiff - src/lib/update/revolt.c
Get rid of the need to fix up lchr[].
[empserver] / src / lib / update / revolt.c
index e6f27d826036c7a2468a7e7cd6e750497c50c895..8684eaa2a00d8d07823056adfb5270ef461fa0d1 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2000, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *  Copyright (C) 1986-2008, Dave Pare, Jeff Bailey, Thomas Ruschak,
  *                           Ken Stevens, Steve McClure
  *
  *  This program is free software; you can redistribute it and/or modify
@@ -19,9 +19,9 @@
  *
  *  ---
  *
- *  See the "LEGAL", "LICENSE", "CREDITS" and "README" files for all the
- *  related information and legal notices. It is expected that any future
- *  projects/authors will amend these files as needed.
+ *  See files README, COPYING and CREDITS in the root of the source
+ *  tree for related information and legal notices.  It is expected
+ *  that future projects/authors will amend these files as needed.
  *
  *  ---
  *
  *     Steve McClure, 1997-2000
  */
 
-#include "misc.h"
-#include "var.h"
-#include "sect.h"
-#include "nat.h"
-#include "news.h"
-#include "var.h"
-#include "file.h"
-#include "path.h"
-#include "xy.h"
+#include <config.h>
+
 #include "land.h"
+#include "lost.h"
+#include "news.h"
 #include "nsc.h"
+#include "path.h"
 #include "plane.h"
 #include "update.h"
-#include "common.h"
-#include "gen.h"
-#include "lost.h"
-#include "subs.h"
 
 static void take_casualties(struct sctstr *, int);
 
@@ -148,7 +140,6 @@ guerrilla(struct sctstr *sp)
     int convert;
     natid actor;
     natid victim;
-    int vec[I_MAX + 1];
     int tmp;
     int min_mil;
     int val;
@@ -162,37 +153,32 @@ guerrilla(struct sctstr *sp)
     move = 0;
     if (!sp->sct_che)
        return;
-    if (getvec(VT_ITEM, vec, (s_char *)sp, EF_SECTOR) <= 0)
-       return;
-    civ = vec[I_CIVIL];
-
-    uw = vec[I_UW];
+    civ = sp->sct_item[I_CIVIL];
+    uw = sp->sct_item[I_UW];
     victim = sp->sct_own;
     actor = sp->sct_oldown;
     che = sp->sct_che;
+    mil = sp->sct_item[I_MILIT];
 
-    mil = vec[I_MILIT];
     snxtitem_xy(&ni, EF_LAND, sp->sct_x, sp->sct_y);
 
-    while (NULL != (lp = (struct lndstr *)nxtitemp(&ni, 0))) {
+    while (NULL != (lp = nxtitemp(&ni))) {
        if (lp->lnd_own != sp->sct_own)
            continue;
 
-       mil += lnd_getmil(lp);
+       mil += lp->lnd_item[I_MILIT];
 
-       /* Security troops can now kill up to 1/2 their complement each
+       if (sp->sct_che_target != sp->sct_own)
+           continue;
+
+       /* Security troops can now kill up to 1/5 their complement each
           update, before doing anything else. */
        if (lchr[(int)lp->lnd_type].l_flags & L_SECURITY) {
            int che_kill, r;
-           struct lchrstr *lcp;
-
-           lcp = &lchr[(int)lp->lnd_type];
-           mil += lnd_getmil(lp);
-           r = (((float)(lp->lnd_effic / 100) * (float)(lnd_getmil(lp))) /
-                2);
-           if (r < 2)
-               r = 2;
-           che_kill = (roll(r) - 1);
+
+           mil += lp->lnd_item[I_MILIT];
+           r = (lp->lnd_item[I_MILIT] * lp->lnd_effic) / 500;
+           che_kill = r < 1 ? 0 : roll(r);
            if (che_kill > che)
                che_kill = che;
            if (che_kill) {
@@ -212,17 +198,15 @@ guerrilla(struct sctstr *sp)
     }
 
     target = sp->sct_che_target;
-    if (target == 0) {
-       /* the deity can't be a target! */
+    if (CANT_HAPPEN(target == 0))
        return;
-    }
     tnat = getnatp(target);
-    if ((tnat->nat_stat & STAT_INUSE) == 0) {
+    if (tnat->nat_stat == STAT_UNUSED) {
        /* target nation has dissolved: che's retire.  */
        logerror("%d Che targeted at country %d retiring", che, target);
        sp->sct_che = 0;
        sp->sct_che_target = 0;
-       sp->sct_item[I_CIVIL] = min(civ + che, ITEM_MAX);
+       sp->sct_item[I_CIVIL] = MIN(civ + che, ITEM_MAX);
        return;
     }
 
@@ -305,11 +289,6 @@ guerrilla(struct sctstr *sp)
         */
        if (chance(ratio * 0.10)) {
            n = (mil / 5) + 1;
-           if ((n + che) == 0) {
-               logerror("n=%d che=%d\n", n, che);
-               if (che == 0)
-                   return;
-           }
            odds = (double)che / (n + che);
            odds /= hap_fact(tnat, getnatp(sp->sct_oldown));
            while (che > 0 && n > 0) {
@@ -327,7 +306,7 @@ guerrilla(struct sctstr *sp)
        }
     }
     if (convert && sp->sct_loyal >= 50) {
-       register int n;
+       int n;
        /* new owner gets to keep the mobility there */
        oldmob = sp->sct_mobil;
        /* che won, and sector converts. */
@@ -338,16 +317,10 @@ guerrilla(struct sctstr *sp)
        sp->sct_mobil = oldmob;
        civ += uw;
        uw = 0;
-       /*
-        * so we can't keep losing money by having
-        * our cap retaken
-        */
-       if (sp->sct_type == SCT_CAPIT && sp->sct_newtype == SCT_CAPIT)
-           sp->sct_newtype = SCT_AGRI;
        n = civ / 20;
        civ -= n;
        if (civ > ITEM_MAX) {
-           uw = ITEM_MAX - civ;
+           uw = civ - ITEM_MAX;
            civ = ITEM_MAX;
        }
        sp->sct_item[I_CIVIL] = civ;
@@ -396,7 +369,7 @@ guerrilla(struct sctstr *sp)
        for (n = 1; n <= 6; n++) {
            nsp = getsectp(sp->sct_x + diroff[n][0],
                           sp->sct_y + diroff[n][1]);
-           if (dchr[nsp->sct_type].d_mcst == 0)
+           if (dchr[nsp->sct_type].d_mob0 < 0)
                continue;
            if (nsp->sct_own != target)
                continue;
@@ -432,13 +405,19 @@ guerrilla(struct sctstr *sp)
        sp->sct_che_target = 0;
     }
     if (mc > 0 || cc > 0) {
-       /* don't tell who won just to be mean */
        wu(0, target,
           "Guerrilla warfare in %s\n",
           xyas(sp->sct_x, sp->sct_y, target));
-       wu(0, target, "  body count: troops: %d, rebels: %d\n", mc, cc);
+       if (sp->sct_own == target)
+           wu(0, target, "  body count: troops: %d, rebels: %d\n", mc, cc);
+       else
+           wu(0, target,
+              "  rebels murder %d military\n", mc);
        nreport(actor, N_FREEDOM_FIGHT, victim, 1);
     }
+    if (sp->sct_own != victim)
+       wu(0, victim, "Partisans take over %s!\n",
+          xyas(sp->sct_x, sp->sct_y, victim));
 }
 
 static void
@@ -469,7 +448,7 @@ take_casualties(struct sctstr *sp, int mc)
      * Try not to kill any unit.
      */
     snxtitem_xy(&ni, EF_LAND, sp->sct_x, sp->sct_y);
-    while (NULL != (lp = (struct lndstr *)nxtitemp(&ni, 0))) {
+    while (NULL != (lp = nxtitemp(&ni))) {
        nunits++;
        if (lchr[(int)lp->lnd_type].l_flags & L_SECURITY)
            nunits++;
@@ -482,30 +461,24 @@ take_casualties(struct sctstr *sp, int mc)
 
     /* kill some security troops */
     snxtitem_xy(&ni, EF_LAND, sp->sct_x, sp->sct_y);
-    while (NULL != (lp = (struct lndstr *)nxtitemp(&ni, 0))) {
+    while (NULL != (lp = nxtitemp(&ni))) {
        if (!(lchr[(int)lp->lnd_type].l_flags & L_SECURITY))
            continue;
 
-       cantake = (((float)(lp->lnd_effic - 40) / 100.0) *
-                  (float)lnd_getmil(lp)) * 2;
-       /*                              (float)lchr[lp->lnd_type].l_mil)*2; */
+       cantake = ((lp->lnd_effic - 40) / 100.0) * lp->lnd_item[I_MILIT];
 
        if (cantake >= each) {
-           /*                  deq = (((float)each/(float)(lchr[lp->lnd_type].l_mil*2)) */
-           deq = (((float)each / (float)(lnd_getmil(lp) * 2))
-                  * 100.0);
-           mc -= each;
+           deq = ((double)each / lp->lnd_item[I_MILIT]) * 100.0;
+           mc -= 2 * each;
        } else if (cantake > 0) {
-           deq = (((float)cantake / (float)(lnd_getmil(lp) * 2)) * 100.0);
-           /*                          (float)(lchr[lp->lnd_type].l_mil*2)) * 100.0); */
-           mc -= (((float)deq / 100.0) * (float)lnd_getmil(lp)) * 2;
-           /*                          (float)lchr[lp->lnd_type].l_mil)*2; */
+           deq = ((double)cantake / lp->lnd_item[I_MILIT]) * 100.0;
+           mc -= 2 * cantake;
        } else
            deq = 0;
 
        lp->lnd_effic -= deq;
        lp->lnd_mobil -= deq / 2;
-       deq = (double)lchr[(int)lp->lnd_type].l_mil * (deq / 100.0);
+       deq = lchr[(int)lp->lnd_type].l_item[I_MILIT] * (deq / 100.0);
        lnd_submil(lp, deq);
        if (mc <= 0)
            return;
@@ -513,26 +486,24 @@ take_casualties(struct sctstr *sp, int mc)
 
     /* kill some normal troops */
     snxtitem_xy(&ni, EF_LAND, sp->sct_x, sp->sct_y);
-    while (NULL != (lp = (struct lndstr *)nxtitemp(&ni, 0))) {
+    while (NULL != (lp = nxtitemp(&ni))) {
        if (lchr[(int)lp->lnd_type].l_flags & L_SECURITY)
            continue;
 
-       cantake = (((float)(lp->lnd_effic - 40) / 100.0) *
-                  (float)lnd_getmil(lp));
+       cantake = ((lp->lnd_effic - 40) / 100.0) * lp->lnd_item[I_MILIT];
 
        if (cantake >= each) {
-           deq = (((float)each / (float)(lnd_getmil(lp) * 2))
-                  * 100.0);
+           deq = ((double)each / lp->lnd_item[I_MILIT]) * 100.0;
            mc -= each;
        } else if (cantake > 0) {
-           deq = (((float)cantake / (float)lnd_getmil(lp))
-                  * 100.0);
-           mc -= (((float)deq / 100.0) * (float)lnd_getmil(lp));
+           deq = ((double)cantake / lp->lnd_item[I_MILIT]) * 100.0;
+           mc -= cantake;
        } else
            deq = 0;
+
        lp->lnd_effic -= deq;
        lp->lnd_mobil -= deq / 2;
-       deq = (double)lchr[(int)lp->lnd_type].l_mil * (deq / 100.0);
+       deq = lchr[(int)lp->lnd_type].l_item[I_MILIT] * (deq / 100.0);
        lnd_submil(lp, deq);
        if (mc <= 0)
            return;
@@ -541,11 +512,11 @@ take_casualties(struct sctstr *sp, int mc)
     /* Hmm.. still some left.. kill off units now */
     /* kill some normal troops */
     snxtitem_xy(&ni, EF_LAND, sp->sct_x, sp->sct_y);
-    while (NULL != (lp = (struct lndstr *)nxtitemp(&ni, 0))) {
+    while (NULL != (lp = nxtitemp(&ni))) {
        if (lchr[(int)lp->lnd_type].l_flags & L_SECURITY)
            continue;
 
-       mc -= (((float)lp->lnd_effic / 100.0) * (float)lnd_getmil(lp));
+       mc -= (lp->lnd_effic / 100.0) * lp->lnd_item[I_MILIT];
        lp->lnd_effic = 0;
        lnd_submil(lp, 1000);   /* Remove 'em all */
        wu(0, lp->lnd_own, "%s dies fighting guerrillas in %s\n",
@@ -559,11 +530,11 @@ take_casualties(struct sctstr *sp, int mc)
     /* Hmm.. still some left.. kill off units now */
     /* kill some security troops */
     snxtitem_xy(&ni, EF_LAND, sp->sct_x, sp->sct_y);
-    while (NULL != (lp = (struct lndstr *)nxtitemp(&ni, 0))) {
+    while (NULL != (lp = nxtitemp(&ni))) {
        if (!(lchr[(int)lp->lnd_type].l_flags & L_SECURITY))
            continue;
 
-       mc -= (((float)lp->lnd_effic / 100.0) * (float)lnd_getmil(lp)) * 2;
+       mc -= (lp->lnd_effic / 100.0) * lp->lnd_item[I_MILIT] * 2.0;
        lp->lnd_effic = 0;
        lnd_submil(lp, 1000);   /* Kill 'em all */
        wu(0, lp->lnd_own, "%s dies fighting guerrillas in %s\n",