Debian Codegraph @

default/scripting/species/species_macros/stockpile.py

raw
1 from focs._effects import (
2 Abs,
3 CurrentTurn,
4 EffectsGroup,
5 Focus,
6 HasSpecies,
7 Homeworld,
8 IsSource,
9 LocalCandidate,
10 MinOf,
11 OwnedBy,
12 Planet,
13 SetMaxStockpile,
14 SetStockpile,
15 Source,
16 Target,
17 TargetPopulation,
18 Value,
19 )
20 from macros.base_prod import STOCKPILE_PER_POP
21 from macros.priorities import (
22 AFTER_ALL_TARGET_MAX_METERS_PRIORITY,
23 TARGET_EARLY_BEFORE_SCALING_PRIORITY,
24 )
25
26
27 def _stockpile_per_pop_effectsgroup_snip(label: str, value) -> dict:
28 return {
29 "scope": IsSource,
30 "activation": Planet(),
31 "accountinglabel": label + "_STOCKPILE_LABEL",
32 "priority": TARGET_EARLY_BEFORE_SCALING_PRIORITY,
33 "effects": SetMaxStockpile(value=value),
34 }
35
36
37 def _stockpile_per_pop_effectsgroup(label: str, value):
38 return EffectsGroup(description=label + "_STOCKPILE_DESC", **_stockpile_per_pop_effectsgroup_snip(label, value))
39
40
41 NO_STOCKPILE = []
42
43 _STANDARD_STOCKPILE = [
44 EffectsGroup( # increase or decrease towards target meter, when not recently conquered
45 scope=IsSource,
46 activation=Planet()
47 & (LocalCandidate.LastTurnConquered < CurrentTurn)
48 & (LocalCandidate.System.LastTurnBattleHere < CurrentTurn),
49 priority=AFTER_ALL_TARGET_MAX_METERS_PRIORITY,
50 effects=SetStockpile(
51 value=Value
52 + MinOf(float, Abs(float, Value(Target.MaxStockpile) - Value), 1)
53 * (1 - 2 * (Value > Value(Target.MaxStockpile)))
54 ),
55 ),
56 # increase stockpile for species if Homeworld is set to stockpile focus
57 EffectsGroup(
58 scope=Planet()
59 & OwnedBy(empire=Source.Owner)
60 & HasSpecies(name=[Source.Species])
61 & ~Homeworld(name=[Source.Species]),
62 activation=Planet() & Focus(type=["FOCUS_STOCKPILE"]) & Homeworld(),
63 stackinggroup="HOMEWORLD_STOCKPILE_FOCUS_BONUS_LABEL",
64 accountinglabel="HOMEWORLD_STOCKPILE_FOCUS_BONUS_LABEL",
65 effects=SetMaxStockpile(value=(Value + 2 * Target.Population * STOCKPILE_PER_POP)),
66 ),
67 # removes residual stockpile capacity from a dead planet
68 EffectsGroup(scope=IsSource, activation=Planet() & TargetPopulation(high=0), effects=SetStockpile(value=0)),
69 ]
70
71 BAD_STOCKPILE = [
72 _stockpile_per_pop_effectsgroup("BAD", Value + 0.5 * Target.Population * STOCKPILE_PER_POP),
73 *_STANDARD_STOCKPILE,
74 ]
75
76
77 AVERAGE_STOCKPILE = [
78 EffectsGroup(
79 # Skip the AVERAGE_STOCKPILE_DESC, same as for the other *_STOCKPILE macros
80 **_stockpile_per_pop_effectsgroup_snip("AVERAGE", Value + 1 * Target.Population * STOCKPILE_PER_POP)
81 ),
82 *_STANDARD_STOCKPILE,
83 ]
84
85
86 GOOD_STOCKPILE = [
87 _stockpile_per_pop_effectsgroup("GOOD", Value + 3 * Target.Population * STOCKPILE_PER_POP),
88 *_STANDARD_STOCKPILE,
89 ]
90
91
92 GREAT_STOCKPILE = [
93 _stockpile_per_pop_effectsgroup("GREAT", Value + 10 * Target.Population * STOCKPILE_PER_POP),
94 *_STANDARD_STOCKPILE,
95 ]
96
97
98 ULTIMATE_STOCKPILE = [
99 _stockpile_per_pop_effectsgroup("ULTIMATE", Value + 15 * Target.Population * STOCKPILE_PER_POP),
100 *_STANDARD_STOCKPILE,
101 ]