From e8451c73436a156c92ecaf74f9cdc035d6ff1134 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Mon, 6 Jun 2016 06:58:07 +0200 Subject: [PATCH] power: Include sector materials and cost in power factor Building sectors can make you rate *lower* on the power chart, because the power factor treats all sectors the same, regardless of build materials and cost. To avoid that, replace the term efficiency / 10.0 by (power value of materials + power value of cost + 9) * efficiency/100.0 The value of ordinary sectors, which take no materials and cost $100, doesn't change. The stock game's fortress is now worth 80% more due to its materials and higher cost. The stock game's wilderness is worth 10% less, because it costs nothing. Signed-off-by: Markus Armbruster --- info/power.t | 3 ++- src/lib/commands/powe.c | 20 +++++++++++++------- tests/smoke/journal.log | 14 +++++++------- tests/update/journal.log | 12 ++++++------ 4 files changed, 28 insertions(+), 21 deletions(-) diff --git a/info/power.t b/info/power.t index d9a5f9ca..5e83556a 100644 --- a/info/power.t +++ b/info/power.t @@ -78,7 +78,8 @@ power factor = ( power value of money .s1 The power value of money is dollars / 100. .s1 -The power value of a sector is efficiency / 10. +The power value of a sector is (the power value of the materials and +money needed to build + 9) * efficiency / 100. .s1 The power value of a ship, plane, land unit or nuke is the power value of the materials and money needed to build * efficiency / 100. diff --git a/src/lib/commands/powe.c b/src/lib/commands/powe.c index f5585552..16381b64 100644 --- a/src/lib/commands/powe.c +++ b/src/lib/commands/powe.c @@ -52,6 +52,7 @@ static void out5(double, int, int); static void gen_power(struct powstr *, int); static int powcmp(const void *, const void *); static void addtopow(short *, struct powstr *); +static float empobj_power(int, short[], int); static float empunit_power(int, int, short[], int); static float money_power(int); static float power_tech_factor(float); @@ -225,6 +226,7 @@ gen_power(struct powstr *powbuf, int save) struct powstr *pow; int i; struct sctstr sect; + struct dchrstr *dcp; struct plnstr plane; struct plchrstr *pcp; struct shpstr ship; @@ -244,10 +246,14 @@ gen_power(struct powstr *powbuf, int save) while (nxtsct(&ns, §)) { if (sect.sct_own == 0) continue; + dcp = &dchr[sect.sct_type]; pow = &powbuf[sect.sct_own]; pow->p_sects += 1.0; pow->p_effic += sect.sct_effic; addtopow(sect.sct_item, pow); + pow->p_power += empobj_power(sect.sct_effic, + dcp->d_mat, dcp->d_cost); + pow->p_power += sect.sct_effic / 100.0 * 9.0; } snxtitem_all(&ni, EF_LAND); while (nxtitem(&ni, &land)) { @@ -304,11 +310,6 @@ gen_power(struct powstr *powbuf, int save) } pow->p_money = natp->nat_money; pow->p_power += money_power(natp->nat_money); - - if (pow->p_sects > 0) - pow->p_power += pow->p_sects - * (pow->p_effic / pow->p_sects / 100.0) - * 10.0; pow->p_power *= power_tech_factor(natp->nat_level[NAT_TLEV]); pow->p_power += upower[i]; /* ack. add this vec to the "world power" element */ @@ -364,11 +365,16 @@ addtopow(short *vec, struct powstr *pow) pow->p_power += item_power(vec); } +static float +empobj_power(int effic, short mat[], int cost) +{ + return (item_power(mat) + money_power(cost)) * (effic / 100.0); +} + static float empunit_power(int effic, int tech, short mat[], int cost) { - return (item_power(mat) + money_power(cost)) * (effic / 100.0) - * power_tech_factor(tech); + return empobj_power(effic, mat, cost) * power_tech_factor(tech); } static float diff --git a/tests/smoke/journal.log b/tests/smoke/journal.log index 22824f44..0c5dad86 100644 --- a/tests/smoke/journal.log +++ b/tests/smoke/journal.log @@ -7167,7 +7167,7 @@ Play#0 output Play#0 1 1 33 87% 22K 48 0 0 0 8.7K 2.5K 788 0 1 0 20K Play#0 output Play#0 1 224.27 Play#0 output Play#0 1 8 29 29% 6.7K 110 0 0 0 5.0K 2.3K 0 0 0 0 30K - Play#0 output Play#0 1 82.11 + Play#0 output Play#0 1 82.10 Play#0 output Play#0 1 6 3 100% 3.0K 110 0 0 0 0 413 0 0 0 0 32K Play#0 output Play#0 1 39.11 Play#0 output Play#0 1 3 3 100% 3.0K 110 0 0 0 0 361 0 0 0 0 32K @@ -7975,7 +7975,7 @@ Play#0 output Play#0 1 1 33 95% 28K 78 51 0 0 9.2K 2.2K 810 0 1 0 23K Play#0 output Play#0 1 294.94 Play#0 output Play#0 1 8 29 38% 8.7K 110 0 0 0 7.4K 2.1K 301 0 0 0 31K - Play#0 output Play#0 1 107.72 + Play#0 output Play#0 1 107.71 Play#0 output Play#0 1 6 3 100% 3.0K 110 0 0 0 0 413 0 0 0 0 33K Play#0 output Play#0 1 42.72 Play#0 output Play#0 1 3 3 100% 3.0K 110 0 0 0 0 361 0 0 0 0 33K @@ -8677,7 +8677,7 @@ Play#0 output Play#0 1 1 33 98% 31K 111 136 5 0 9.3K 1.8K 709 0 4 5 28K Play#0 output Play#0 1 356.59 Play#0 output Play#0 1 8 29 44% 11K 110 0 0 0 10K 1.9K 482 0 0 0 32K - Play#0 output Play#0 1 136.22 + Play#0 output Play#0 1 136.20 Play#0 output Play#0 1 6 3 100% 3.0K 110 0 0 0 0 413 0 0 0 0 33K Play#0 output Play#0 1 46.46 Play#0 output Play#0 1 3 3 100% 3.0K 110 0 0 0 0 361 0 0 0 0 33K @@ -10216,7 +10216,7 @@ Play#0 output Play#0 1 1 33 100% 31K 143 244 11 0 9.6K 1.5K 588 0 2 4 32K Play#0 output Play#0 1 422.02 Play#0 output Play#0 1 8 29 58% 15K 110 0 0 0 12K 1.8K 485 0 0 0 29K - Play#0 output Play#0 1 189.03 + Play#0 output Play#0 1 189.01 Play#0 output Play#0 1 6 3 100% 3.0K 110 0 0 0 0 413 0 0 0 0 34K Play#0 output Play#0 1 50.24 Play#0 output Play#0 1 3 3 100% 3.0K 110 0 0 0 0 361 0 0 0 0 34K @@ -11377,7 +11377,7 @@ Play#0 output Play#0 1 1 33 100% 31K 176 373 18 0 9.6K 1.2K 846 0 3 4 39K Play#0 output Play#0 1 503.55 Play#0 output Play#0 1 8 29 72% 19K 110 0 0 0 13K 2.1K 367 0 0 0 25K - Play#0 output Play#0 1 268.46 + Play#0 output Play#0 1 268.44 Play#0 output Play#0 1 2 30 15% 3.7K 0 0 0 0 0 1.1K 0 0 0 0 34K Play#0 output Play#0 1 70.61 Play#0 output Play#0 1 6 3 100% 3.0K 110 0 0 0 0 413 0 0 0 0 35K @@ -12428,7 +12428,7 @@ Play#0 output Play#0 1 1 33 100% 31K 209 516 26 0 9.9K 851 1.2K 3 5 4 46K Play#0 output Play#0 1 596.32 Play#0 output Play#0 1 8 29 92% 25K 110 101 0 0 14K 2.8K 537 0 0 0 21K - Play#0 output Play#0 1 384.63 + Play#0 output Play#0 1 384.58 Play#0 output Play#0 1 2 30 28% 4.9K 0 0 0 0 1.7K 1.3K 169 0 0 0 35K Play#0 output Play#0 1 92.10 Play#0 output Play#0 1 6 3 100% 3.0K 110 0 0 0 0 413 0 0 0 0 36K @@ -13522,7 +13522,7 @@ Play#0 output Play#0 1 1 33 100% 31K 231 661 34 994 10K 526 1.0K 3 5 4 51K Play#0 output Play#0 1 688.71 Play#0 output Play#0 1 8 29 100% 29K 105 214 5 0 16K 2.4K 545 0 0 0 22K - Play#0 output Play#0 1 485.48 + Play#0 output Play#0 1 486.16 Play#0 output Play#0 1 2 30 33% 6.3K 0 0 0 0 3.2K 1.2K 527 0 0 0 36K Play#0 output Play#0 1 122.83 Play#0 output Play#0 1 6 3 100% 3.0K 110 0 0 0 0 413 0 0 0 0 37K diff --git a/tests/update/journal.log b/tests/update/journal.log index a11a6581..654aad2e 100644 --- a/tests/update/journal.log +++ b/tests/update/journal.log @@ -481,17 +481,17 @@ Play#0 output Play#0 1 Play#0 output Play#0 1 sects eff civ mil shell gun pet iron dust oil pln ship unit money Play#0 output Play#0 1 1 96 62% 28K 1.2K 0 0 0 2.5K 340 580 21 32 16 25K - Play#0 output Play#0 1 890.36 + Play#0 output Play#0 1 896.93 Play#0 output Play#0 1 2 32 22% 7.1K 1.9K 0 0 0 0 1 5 3 3 3 100 - Play#0 output Play#0 1 440.95 + Play#0 output Play#0 1 459.65 Play#0 output Play#0 1 4 64 8% 25K 1.1K 0 0 0 20K 21 4.0K 0 10 10 25K - Play#0 output Play#0 1 284.01 + Play#0 output Play#0 1 285.91 Play#0 output Play#0 1 3 64 14% 17K 170 0 0 0 0 0 0 0 0 0 -100 - Play#0 output Play#0 1 231.59 + Play#0 output Play#0 1 236.15 Play#0 output Play#0 1 6 8 88% 4.0K 168 0 0 0 0 0 0 3 1 3 25K - Play#0 output Play#0 1 193.20 + Play#0 output Play#0 1 199.68 Play#0 output Play#0 1 7 8 88% 4.0K 160 0 0 0 0 0 0 0 3 0 25K - Play#0 output Play#0 1 175.02 + Play#0 output Play#0 1 181.50 Play#0 output Play#0 1 5 0 0% 0 0 0 0 0 0 0 0 0 0 0 25K Play#0 output Play#0 1 60.00 Play#0 output Play#0 1 ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----