]> git.pond.sub.org Git - empserver/blobdiff - src/lib/subs/control.c
Update copyright notice
[empserver] / src / lib / subs / control.c
index 3fc5b1f95ed5d64984ac9159acc0eae3503adc1d..cda971620846129aacf203a26b5845cea3b6b1b9 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2016, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *  Copyright (C) 1986-2020, Dave Pare, Jeff Bailey, Thomas Ruschak,
  *                Ken Stevens, Steve McClure, Markus Armbruster
  *
  *  Empire is free software: you can redistribute it and/or modify
 
 /*
  * Return strength of security detail in @sp.
- * Store number of land units with security capability in @nsecurity.
+ * Store sum of efficiency of land units with security capability in
+ * @seceffp unless it is null.
  */
-int
-security_strength(struct sctstr *sp, int *nsecurity)
+double
+security_strength(struct sctstr *sp, int *seceffp)
 {
-    int strength;
-    int nsec;
+    double strength;
+    int seceff;
     struct nstr_item ni;
     struct lndstr land;
 
     strength = sp->sct_item[I_MILIT];
-    nsec = 0;
+    seceff = 0;
     snxtitem_xy(&ni, EF_LAND, sp->sct_x, sp->sct_y);
     while (nxtitem(&ni, &land)) {
+       if (land.lnd_own != sp->sct_own)
+           continue;
+       if (land.lnd_ship >= 0 || land.lnd_land >= 0)
+           continue;
        strength += land.lnd_item[I_MILIT];
        if (lchr[land.lnd_type].l_flags & L_SECURITY) {
-           strength += land.lnd_item[I_MILIT];
-           nsec++;
+           strength += land.lnd_item[I_MILIT] * land.lnd_effic / 100.0;
+           seceff += land.lnd_effic;
        }
     }
 
-    *nsecurity = nsec;
+    if (seceffp)
+       *seceffp = seceff;
     return strength;
 }
 
@@ -73,17 +79,11 @@ security_strength(struct sctstr *sp, int *nsecurity)
 int
 military_control(struct sctstr *sp)
 {
-    int tot_mil = 0;
-    struct nstr_item ni;
-    struct lndstr land;
+    int tot_mil;
 
     if (sp->sct_oldown != sp->sct_own) {
-       snxtitem_xy(&ni, EF_LAND, sp->sct_x, sp->sct_y);
-       while (nxtitem(&ni, &land)) {
-           if (land.lnd_own == sp->sct_own)
-               tot_mil += land.lnd_item[I_MILIT];
-       }
-       if ((sp->sct_item[I_MILIT] + tot_mil) * 10 < sp->sct_item[I_CIVIL])
+       tot_mil = sp->sct_item[I_MILIT] + security_strength(sp, NULL);
+       if (tot_mil * 10 < sp->sct_item[I_CIVIL])
            return 0;
     }
 
@@ -106,7 +106,7 @@ abandon_askyn(struct sctstr *sp, i_type vtype, int amnt,
 
     /*
      * First, would we be abandoning it?  If not, just return that
-     * it's ok to move out.
+     * it's OK to move out.
      */
     if (!would_abandon(sp, vtype, amnt, land_list))
        return 1;