]> git.pond.sub.org Git - empserver/commitdiff
update: Rearrange code to pay non-sector military
authorMarkus Armbruster <armbru@pond.sub.org>
Wed, 22 Jun 2016 18:49:57 +0000 (20:49 +0200)
committerMarkus Armbruster <armbru@pond.sub.org>
Sun, 6 Aug 2017 18:08:30 +0000 (20:08 +0200)
Split upd_slmilcosts() into prep_ships() and prep_lands().  Move the
sanity check for dead ships and land units from prod_ships() and
prod_lands() there.  Move their call from prepare_sects() to its
caller, along with pay_reserve().

Create prep_planes() for symmetry.  Pilots are now paid at the same
time as other military.  Can matter only when the country goes broke
during the update.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
include/update.h
src/lib/commands/budg.c
src/lib/update/land.c
src/lib/update/main.c
src/lib/update/plane.c
src/lib/update/prepare.c
src/lib/update/ship.c

index 387ca76910b79d221d5f46433d8a6542cbeee50a..c7b6161954cff0e75edb1d3d6fd87f976b215b8a 100644 (file)
@@ -98,6 +98,7 @@ extern int feed_people(short *, int);
 extern double food_needed(short *, int);
 extern int famine_victims(short *, int);
 /* land.c */
+extern void prep_lands(int, natid);
 extern void prod_land(int, int, struct bp *, int);
 /* main.c */
 /* in server.h */
@@ -121,6 +122,7 @@ extern void do_plague(struct sctstr *, int);
 extern int plague_people(struct natstr *, short *, int *, int *, int);
 extern void plague_report(natid, int, int, int, int, char *, char *);
 /* plane.c */
+extern void prep_planes(int, natid);
 extern void prod_plane(int, int, struct bp *, int);
 /* populace.c */
 extern void populace(struct sctstr *, int);
@@ -128,7 +130,6 @@ extern int total_work(int, int, int, int, int, int);
 /* prepare.c */
 extern void prepare_sects(int);
 extern void tax(struct sctstr *, int);
-extern void upd_slmilcosts(int, natid);
 extern void bank_income(struct sctstr *, int);
 extern void pay_reserve(struct natstr *, int);
 /* produce.c */
@@ -149,6 +150,7 @@ extern void spread_fallout(struct sctstr *, int);
 extern void decay_fallout(struct sctstr *, int);
 extern void produce_sect(struct natstr *, int, struct bp *);
 /* ship.c */
+extern void prep_ships(int, natid);
 extern void prod_ship(int, int, struct bp *, int);
 
 #endif
index 10f0433107420e8d5c012a4e11f4cd77bbe90832..d9cecf2c3d35697730e1fbb4534359582a968b75 100644 (file)
@@ -163,7 +163,9 @@ calc_all(void)
                bank_income(sp, etu);
        }
     }
-    upd_slmilcosts(etu, player->cnum);
+    prep_ships(etu, player->cnum);
+    prep_planes(etu, player->cnum);
+    prep_lands(etu, player->cnum);
     pay_reserve(np, etu);
 
     /* Maintain ships, planes and land units */
index ea2e7d08a8ff45ac83781b43a102f5c1cf2fdb02..23d3f228002b4e83c63bc9b4fd09afc4c9ef6bbd 100644 (file)
@@ -54,26 +54,45 @@ static void landrepair(struct lndstr *, struct natstr *, struct bp *,
                       int, struct budget *);
 static int feed_land(struct lndstr *, int);
 
-void
-prod_land(int etus, int natnum, struct bp *bp, int build)
-               /* build = 1, maintain = 0 */
+void prep_lands(int etus, natid natnum)
 {
+    int mil, i;
+    double mil_pay;
     struct lndstr *lp;
-    struct sctstr *sp;
-    int i;
 
     for (i = 0; (lp = getlandp(i)); i++) {
        if (lp->lnd_own == 0)
            continue;
        if (lp->lnd_own != natnum)
            continue;
-       if (lp->lnd_effic < LAND_MINEFF) {
+       if (CANT_HAPPEN(lp->lnd_effic < LAND_MINEFF)) {
            makelost(EF_LAND, lp->lnd_own, lp->lnd_uid,
                     lp->lnd_x, lp->lnd_y);
            lp->lnd_own = 0;
            continue;
        }
 
+       mil = lp->lnd_item[I_MILIT];
+       mil_pay = mil * etus * money_mil;
+       nat_budget[natnum].mil.count += mil;
+       nat_budget[natnum].mil.money += mil_pay;
+       nat_budget[natnum].money += mil_pay;
+    }
+}
+
+void
+prod_land(int etus, int natnum, struct bp *bp, int build)
+               /* build = 1, maintain = 0 */
+{
+    struct lndstr *lp;
+    struct sctstr *sp;
+    int i;
+
+    for (i = 0; (lp = getlandp(i)); i++) {
+       if (lp->lnd_own == 0)
+           continue;
+       if (lp->lnd_own != natnum)
+           continue;
        sp = getsectp(lp->lnd_x, lp->lnd_y);
        if (sp->sct_type == SCT_SANCT)
            continue;
index 459232c83ca17739af2ad56bb9fecd01ae52ef65..7ece6dab19f534dacf52efbd314179e7cd98189a 100644 (file)
@@ -94,6 +94,13 @@ update_main(void)
     logerror("preparing sectors...");
     prepare_sects(etu);
     logerror("done preparing sectors.");
+    for (i = 0; i < MAXNOC; i++) {
+       prep_ships(etu, i);
+       prep_planes(etu, i);
+       prep_lands(etu, i);
+       pay_reserve(getnatp(i), etu);
+    }
+
     logerror("producing for countries...");
     for (i = 0; i < MAXNOC; i++) {
        if (!(np = getnatp(i)))
index 16210437324cc96da8b29fbdd54b074a2c140308..689fd8f22189799732183aac6e05528e328a3c09 100644 (file)
@@ -49,12 +49,11 @@ static void upd_plane(struct plnstr *, int, struct bp *, int);
 static void planerepair(struct plnstr *, struct natstr *, struct bp *,
                        int, struct budget *);
 
-void
-prod_plane(int etus, int natnum, struct bp *bp, int buildem)
-                /* Build = 1, maintain =0 */
+void prep_planes(int etus, natid natnum)
 {
+    int mil, i;
+    double mil_pay;
     struct plnstr *pp;
-    int i;
 
     for (i = 0; (pp = getplanep(i)); i++) {
        if (pp->pln_own == 0)
@@ -68,6 +67,26 @@ prod_plane(int etus, int natnum, struct bp *bp, int buildem)
            continue;
        }
 
+       mil = plchr[pp->pln_type].pl_mat[I_MILIT];
+       /* flight pay is 5x the pay received by other military */
+       mil_pay = mil * etus * money_mil * 5;
+       nat_budget[natnum].bm[BUDG_PLN_MAINT].money += mil_pay;
+       nat_budget[natnum].money += mil_pay;
+    }
+}
+
+void
+prod_plane(int etus, int natnum, struct bp *bp, int buildem)
+                /* Build = 1, maintain =0 */
+{
+    struct plnstr *pp;
+    int i;
+
+    for (i = 0; (pp = getplanep(i)); i++) {
+       if (pp->pln_own == 0)
+           continue;
+       if (pp->pln_own != natnum)
+           continue;
        upd_plane(pp, etus, bp, buildem);
     }
 }
@@ -105,10 +124,6 @@ upd_plane(struct plnstr *pp, int etus, struct bp *bp, int build)
            budget->bm[BUDG_PLN_MAINT].money -= cost;
            budget->money -= cost;
        }
-       /* flight pay is 5x the pay received by other military */
-       cost = etus * pcp->pl_mat[I_MILIT] * -money_mil * 5;
-       budget->bm[BUDG_PLN_MAINT].money -= cost;
-       budget->money -= cost;
 
        if (pln_is_in_orbit(pp) && !(pp->pln_flags & PLN_SYNCHRONOUS)) {
            if (!player->simulation)
index 3ce126c3f1e9c593aa0b8168d9baa5a6ed954451..e7c6603e68f850cc2da55b2d70537f959acab5f4 100644 (file)
 #include "chance.h"
 #include "file.h"
 #include "item.h"
-#include "land.h"
 #include "nat.h"
 #include "optlist.h"
 #include "player.h"
 #include "prototypes.h"
-#include "ship.h"
 #include "update.h"
 
 void
 prepare_sects(int etu)
 {
     struct sctstr *sp;
-    struct natstr *np;
     int n;
 
 /* Process all the fallout. */
@@ -96,10 +93,6 @@ prepare_sects(int etu)
        if (sp->sct_type == SCT_BANK)
            bank_income(sp, etu);
     }
-    for (n = 0; NULL != (np = getnatp(n)); n++) {
-       upd_slmilcosts(etu, np->nat_cnum);
-       pay_reserve(np, etu);
-    }
 }
 
 void
@@ -128,34 +121,6 @@ tax(struct sctstr *sp, int etu)
     budget->money += mil_pay;
 }
 
-void
-upd_slmilcosts(int etu, natid n)
-{
-    struct shpstr *sp;
-    struct lndstr *lp;
-    int mil, i;
-    double mil_pay;
-
-    mil = 0;
-
-    for (i = 0; (sp = getshipp(i)); i++) {
-       if (!sp->shp_own || sp->shp_own != n)
-           continue;
-       mil += sp->shp_item[I_MILIT];
-    }
-
-    for (i = 0; (lp = getlandp(i)); i++) {
-       if (!lp->lnd_own || lp->lnd_own != n)
-           continue;
-       mil += lp->lnd_item[I_MILIT];
-    }
-
-    mil_pay = mil * etu * money_mil;
-    nat_budget[n].mil.count += mil;
-    nat_budget[n].mil.money += mil_pay;
-    nat_budget[n].money += mil_pay;
-}
-
 void
 bank_income(struct sctstr *sp, int etu)
 {
index 54bb5fb86e0faec49dc4de91dad264719bccd1b7..2315c761a3dea003f62e855807e4f89339172054 100644 (file)
@@ -57,25 +57,44 @@ static void shiprepair(struct shpstr *, struct natstr *, struct bp *,
 static void ship_produce(struct shpstr *, int, struct budget *);
 static int feed_ship(struct shpstr *, int);
 
-void
-prod_ship(int etus, int natnum, struct bp *bp, int build)
-               /* build = 1, maintain = 0 */
+void prep_ships(int etus, natid natnum)
 {
+    int mil, i;
+    double mil_pay;
     struct shpstr *sp;
-    int i;
 
     for (i = 0; (sp = getshipp(i)); i++) {
        if (sp->shp_own == 0)
            continue;
        if (sp->shp_own != natnum)
            continue;
-       if (sp->shp_effic < SHIP_MINEFF) {
+       if (CANT_HAPPEN(sp->shp_effic < SHIP_MINEFF)) {
            makelost(EF_SHIP, sp->shp_own, sp->shp_uid,
                     sp->shp_x, sp->shp_y);
            sp->shp_own = 0;
            continue;
        }
 
+       mil = sp->shp_item[I_MILIT];
+       mil_pay = mil * etus * money_mil;
+       nat_budget[natnum].mil.count += mil;
+       nat_budget[natnum].mil.money += mil_pay;
+       nat_budget[natnum].money += mil_pay;
+    }
+}
+
+void
+prod_ship(int etus, int natnum, struct bp *bp, int build)
+               /* build = 1, maintain = 0 */
+{
+    struct shpstr *sp;
+    int i;
+
+    for (i = 0; (sp = getshipp(i)); i++) {
+       if (sp->shp_own == 0)
+           continue;
+       if (sp->shp_own != natnum)
+           continue;
        upd_ship(sp, etus, bp, build);
     }
 }