]> git.pond.sub.org Git - empserver/blobdiff - src/lib/update/revolt.c
Update copyright notice
[empserver] / src / lib / update / revolt.c
index 95acd20e5ec8d8d32c885fb378aa874571e07757..995f5b5ecfed05f4bd0caa3f1a591a1949921156 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2011, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *  Copyright (C) 1986-2015, Dave Pare, Jeff Bailey, Thomas Ruschak,
  *                Ken Stevens, Steve McClure, Markus Armbruster
  *
  *  Empire is free software: you can redistribute it and/or modify
  *  Known contributors to this file:
  *     Dave Pare, 1986
  *     Steve McClure, 1997-2000
+ *     Markus Armbruster, 2004-2012
  */
 
 #include <config.h>
 
+#include "chance.h"
 #include "land.h"
 #include "lost.h"
 #include "news.h"
 #include "nsc.h"
+#include "nuke.h"
 #include "path.h"
 #include "plane.h"
 #include "update.h"
 
 static void take_casualties(struct sctstr *, int);
+static void lnd_dies_fighting_che(struct lndstr *);
 
 void
 revolt(struct sctstr *sp)
@@ -62,7 +66,7 @@ revolt(struct sctstr *sp)
        return;
     che_uw = 0;
     /* che due to civilian unrest */
-    n = 10 - (random() % 20);
+    n = 10 - roll0(20);
     che_civ = 3 + (civ * n / 500);
     if (che_civ < 0)
        che_civ = 0;
@@ -73,7 +77,7 @@ revolt(struct sctstr *sp)
     che += che_civ;
     if (che < CHE_MAX) {
        /* che due to uw unrest */
-       n = 10 + (random() % 30);
+       n = 9 + roll(30);
        che_uw = 5 + (uw * n / 500);
        if (che_uw > uw)
            che_uw = uw;
@@ -159,7 +163,7 @@ guerrilla(struct sctstr *sp)
     while (NULL != (lp = nxtitemp(&ni))) {
        if (lp->lnd_own != sp->sct_own)
            continue;
-       if (lp->lnd_ship >= 0 || lp->lnd_land >= 0)
+       if (lp->lnd_ship >= 0)
            continue;
 
        mil += lp->lnd_item[I_MILIT];
@@ -236,7 +240,7 @@ guerrilla(struct sctstr *sp)
        }
        if (mil > 0) {
            /* military won.  */
-           n = sp->sct_loyal - (random() % 15);
+           n = sp->sct_loyal - roll0(15);
            if (n < 0)
                n = 0;
            sp->sct_loyal = n;
@@ -250,7 +254,7 @@ guerrilla(struct sctstr *sp)
         * guerrillas have to resort to blowing things up.
         * Note this disrupts work in the sector.
         */
-       n = (random() % 10) + (random() % che);
+       n = roll0(10) + roll0(che);
        if (n > 100)
            n = 100;
        tmp = sp->sct_work - n;
@@ -323,14 +327,14 @@ guerrilla(struct sctstr *sp)
        /* loyalty drops during recruitment efforts */
        n = sp->sct_loyal;
        if (n < 30)
-           n += (random() % 5) + 1;
+           n += roll(5);
        else if (n < 70)
-           n += (random() % 10) + 4;
+           n += roll(10) + 3;
        if (n > 127)
            n = 127;
        sp->sct_loyal = n;
        if (sp->sct_oldown != sp->sct_own || n > 100) {
-           n = civ * (random() % 3) / 200;
+           n = civ * roll0(3) / 200;
            n /= hap_fact(tnat, getnatp(sp->sct_oldown));
            if (n + che > CHE_MAX)
                n = CHE_MAX - che;
@@ -338,7 +342,7 @@ guerrilla(struct sctstr *sp)
            civ -= n;
            sp->sct_item[I_CIVIL] = civ;
        }
-       n = uw * (random() % 3) / 200;
+       n = uw * roll0(3) / 200;
        if (n + che > CHE_MAX)
            n = CHE_MAX - che;
        che += n;
@@ -371,7 +375,7 @@ domove:
            val = roundintby(val, 10);
            /* inject a modicum of indeterminism; also
             * avoids che preferring certain directions */
-           val += random() % 10 - 5;
+           val += roll(10) - 6;
            if (val >= min_mil)
                continue;
            nicest_sp = nsp;
@@ -437,7 +441,7 @@ take_casualties(struct sctstr *sp, int mc)
     while (NULL != (lp = nxtitemp(&ni))) {
        if (lp->lnd_own != sp->sct_own)
            continue;
-       if (lp->lnd_ship >= 0 || lp->lnd_land >= 0)
+       if (lp->lnd_ship >= 0)
            continue;
        nunits++;
        if (lchr[(int)lp->lnd_type].l_flags & L_SECURITY)
@@ -454,7 +458,7 @@ take_casualties(struct sctstr *sp, int mc)
     while (NULL != (lp = nxtitemp(&ni))) {
        if (lp->lnd_own != sp->sct_own)
            continue;
-       if (lp->lnd_ship >= 0 || lp->lnd_land >= 0)
+       if (lp->lnd_ship >= 0)
            continue;
        if (!(lchr[(int)lp->lnd_type].l_flags & L_SECURITY))
            continue;
@@ -483,7 +487,7 @@ take_casualties(struct sctstr *sp, int mc)
     while (NULL != (lp = nxtitemp(&ni))) {
        if (lp->lnd_own != sp->sct_own)
            continue;
-       if (lp->lnd_ship >= 0 || lp->lnd_land >= 0)
+       if (lp->lnd_ship >= 0)
            continue;
        if (lchr[(int)lp->lnd_type].l_flags & L_SECURITY)
            continue;
@@ -513,18 +517,13 @@ take_casualties(struct sctstr *sp, int mc)
     while (NULL != (lp = nxtitemp(&ni))) {
        if (lp->lnd_own != sp->sct_own)
            continue;
-       if (lp->lnd_ship >= 0 || lp->lnd_land >= 0)
+       if (lp->lnd_ship >= 0)
            continue;
        if (lchr[(int)lp->lnd_type].l_flags & L_SECURITY)
            continue;
 
        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",
-          prland(lp), xyas(lp->lnd_x, lp->lnd_y, lp->lnd_own));
-       makelost(EF_LAND, lp->lnd_own, lp->lnd_uid, lp->lnd_x, lp->lnd_y);
-       lp->lnd_own = 0;
+       lnd_dies_fighting_che(lp);
        if (mc <= 0)
            return;
     }
@@ -535,21 +534,73 @@ take_casualties(struct sctstr *sp, int mc)
     while (NULL != (lp = nxtitemp(&ni))) {
        if (lp->lnd_own != sp->sct_own)
            continue;
-       if (lp->lnd_ship >= 0 || lp->lnd_land >= 0)
+       if (lp->lnd_ship >= 0)
            continue;
        if (!(lchr[(int)lp->lnd_type].l_flags & L_SECURITY))
            continue;
 
        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",
-          prland(lp), xyas(lp->lnd_x, lp->lnd_y, lp->lnd_own));
-       makelost(EF_LAND, lp->lnd_own, lp->lnd_uid, lp->lnd_x, lp->lnd_y);
-       lp->lnd_own = 0;
+       lnd_dies_fighting_che(lp);
        if (mc <= 0)
            return;
     }
 
     /* Hmm.. everyone dead.. too bad */
 }
+
+static void
+lnd_dies_fighting_che(struct lndstr *lp)
+{
+    int i, j;
+    struct lndstr *clp;
+    struct plnstr *cpp;
+    struct nukstr *cnp;
+
+    lp->lnd_effic = 0;
+    lnd_submil(lp, 1000);      /* Remove 'em all */
+    wu(0, lp->lnd_own, "%s dies fighting guerrillas in %s\n",
+       prland(lp), xyas(lp->lnd_x, lp->lnd_y, lp->lnd_own));
+    makelost(EF_LAND, lp->lnd_own, lp->lnd_uid, lp->lnd_x, lp->lnd_y);
+    lp->lnd_own = 0;
+
+    /* Take dead lp off its carrier */
+    if (lp->lnd_land >= 0) {
+       lnd_carrier_change(lp, EF_LAND, lp->lnd_land, -1);
+       lp->lnd_land = -1;
+    }
+
+    /* Unload lp's land unit cargo */
+    for (i = lnd_first_on_land(lp); i >= 0; i = lnd_next_on_unit(i)) {
+       clp = getlandp(i);
+       if (CANT_HAPPEN(!clp))
+           continue;
+       lnd_carrier_change(clp, EF_LAND, clp->lnd_land, -1);
+       clp->lnd_land = -1;
+    }
+
+    /* Destroy lp's plane cargo */
+    for (i = pln_first_on_land(lp); i >= 0; i = pln_next_on_unit(i)) {
+       cpp = getplanep(i);
+       if (CANT_HAPPEN(!cpp))
+           continue;
+       pln_carrier_change(cpp, EF_LAND, cpp->pln_land, -1);
+       makelost(EF_PLANE, cpp->pln_own, i, cpp->pln_x, cpp->pln_y);
+       wu(0, cpp->pln_own, "%s lost!\n", prplane(cpp));
+       cpp->pln_own = 0;
+       cpp->pln_effic = 0;
+       cpp->pln_land = -1;
+
+       j = nuk_on_plane(cpp);
+       if (j >= 0) {
+           cnp = getnukep(j);
+           if (CANT_HAPPEN(!cnp))
+               continue;
+           nuk_carrier_change(cnp, EF_PLANE, cnp->nuk_plane, -1);
+           makelost(EF_NUKE, cnp->nuk_own, j, cnp->nuk_x, cnp->nuk_y);
+           wu(0, cnp->nuk_own, "%s lost!\n", prnuke(cnp));
+           cnp->nuk_own = 0;
+           cnp->nuk_effic = 0;
+           cnp->nuk_plane = -1;
+       }
+    }
+}