]> git.pond.sub.org Git - empserver/commitdiff
(hap_req): New.
authorMarkus Armbruster <armbru@pond.sub.org>
Sat, 6 May 2006 11:07:35 +0000 (11:07 +0000)
committerMarkus Armbruster <armbru@pond.sub.org>
Sat, 6 May 2006 11:07:35 +0000 (11:07 +0000)
(nati, populace): Use it.

(populace, nati): Change hap, pct from float to double, because they
are used as double.

(nati): Print happiness needed with just two decimals, like the other
levels.

include/prototypes.h
src/lib/commands/nati.c
src/lib/common/hap_fact.c
src/lib/update/populace.c

index 5e193e665d3db13c216f1e16893015b7373abcce..254dc4900af25cd4d10287d1da6beeb1692e4cb8 100644 (file)
@@ -290,6 +290,7 @@ extern int blksize(int);
 extern time_t fdate(int);
 /* hap_fact.c */
 extern double hap_fact(struct natstr *, struct natstr *);
+extern double hap_req(struct natstr *np);
 /* hours.c */
 extern int is_wday_allowed(int, char *);
 extern int is_daytime_allowed(int, char *);
index db8dacf0315de9857b4ead0f5f70c5230f2c67a1..6fdc412cecfc6e9c24a29803075d122f88004b97 100644 (file)
@@ -47,7 +47,7 @@ nati(void)
 {
     struct natstr *natp;
     struct sctstr sect;
-    float hap;
+    double hap;
     int mil;
     int civ;
     int cnum;
@@ -122,11 +122,9 @@ nati(void)
 
     pr("Max safe population for civs/uws: %d/%d\n", safepop, uwpop);
 
-    hap = ((natp->nat_level[NAT_TLEV] - 40) / 40.0 +
-          natp->nat_level[NAT_ELEV] / 3.0);
-
+    hap = hap_req(natp);
     if (hap > 0.0)
-       pr("Happiness needed is %f\n", hap);
+       pr("Happiness needed is %.2f\n", hap);
     else
        pr("No happiness needed\n");
 
index 94efa32eced3551085489adab0877bc65dbed553..112f168b026cf0c8b57fa3bb1554c6b843e46c81 100644 (file)
@@ -62,3 +62,11 @@ hap_fact(struct natstr *tnat, struct natstr *vnat)
        hap_fact = 0.8;
     return hap_fact;
 }
+
+/* Return happiness required to keep NP's citizens happy.  */
+double
+hap_req(struct natstr *np)
+{
+    return (np->nat_level[NAT_TLEV] - 40.0) / 40.0
+       + np->nat_level[NAT_ELEV] / 3.0;
+}
index eadb81bf7b4194e7ea2dda4e9b3411337b7c9ad4..2bb5349a91032da2486d9d16acdb1c3f19ac6690 100644 (file)
 void
 populace(struct natstr *np, struct sctstr *sp, int etu)
 {
-    float hap;
-    float tech;
-    float edu;
-    float pct;
+    double hap, pct;
     int n;
     int civ = sp->sct_item[I_CIVIL];
     int mil = sp->sct_item[I_MILIT];
@@ -74,11 +71,9 @@ populace(struct natstr *np, struct sctstr *sp, int etu)
     }
 
     hap = np->nat_level[NAT_HLEV];
-    edu = np->nat_level[NAT_ELEV];
-    tech = np->nat_level[NAT_TLEV];
-    pct = (double)((tech - 40) / 40.0 + edu / 3.0);
+    pct = hap_req(np);
     if (sp->sct_own == sp->sct_oldown && hap < pct &&
-       chance(((double)pct - (double)hap) / (double)5.0)) {
+       chance((pct - hap) / 5.0)) {
        /*
         * zap the loyalty of unhappy civilians.
         * there is a 20% chance per hap point below the