Debian Codegraph @

test-scripting/species/species_macros/general.py

raw
1 from macros.priorities import (
2 AFTER_ALL_TARGET_MAX_METERS_PRIORITY,
3 END_CLEANUP_PRIORITY,
4 FOCUS_CHANGE_PENALTY_PRIORITY,
5 LATE_AFTER_ALL_TARGET_MAX_METERS_PRIORITY,
6 )
7
8 try:
9 from focs._effects import (
10 Abs,
11 CurrentTurn,
12 EffectsGroup,
13 Focus,
14 IsSource,
15 LocalCandidate,
16 MaxOf,
17 MinOf,
18 Planet,
19 Population,
20 SetConstruction,
21 SetIndustry,
22 SetInfluence,
23 SetResearch,
24 SetStockpile,
25 SetTargetConstruction,
26 SetTargetIndustry,
27 SetTargetInfluence,
28 SetTargetResearch,
29 Ship,
30 Target,
31 TargetPopulation,
32 Value,
33 )
34 except ModuleNotFoundError:
35 pass
36
37 STANDARD_METER_GROWTH = [
38 # increase or decrease towards target meter of planets, when not recently conquered
39 EffectsGroup(
40 scope=IsSource,
41 activation=Planet() & (LocalCandidate.LastTurnConquered < CurrentTurn),
42 priority=AFTER_ALL_TARGET_MAX_METERS_PRIORITY,
43 effects=[
44 SetResearch(
45 value=Value
46 + MinOf(
47 float,
48 1.0, # increase by (at most) 1 / turn up towards target
49 MaxOf(float, 0.0, Value(Target.Happiness)) / 5.0, # limit rate of increase, dependent on Stability
50 MaxOf(
51 float,
52 MinOf(
53 float,
54 -1.0, # decrease by 1 / turn down towards target, or:
55 (Value(Target.TargetResearch) - Value)
56 / 5.0, # when (target>=value), this is larger than -1.0. when (target<<value) this increases the rate of meter decay
57 ),
58 Value(Target.TargetResearch)
59 - Value, # limit increase or decrease to the difference between current and target, to avoid overshooting target
60 ),
61 )
62 ),
63 SetIndustry(
64 value=Value
65 + MinOf(
66 float,
67 1.0,
68 MaxOf(float, 0.0, Value(Target.Happiness)) / 5.0,
69 MaxOf(
70 float,
71 MinOf(float, -1.0, (Value(Target.TargetIndustry) - Value) / 5.0),
72 Value(Target.TargetIndustry) - Value,
73 ),
74 )
75 ),
76 SetInfluence(
77 value=Value
78 + MinOf(
79 float,
80 1.0, # increase by (at most) 1 / turn up towards target
81 MaxOf(
82 float,
83 MinOf(
84 float,
85 -1.0, # decrease by 1 / turn down towards target, or:
86 (Value(Target.TargetInfluence) - Value)
87 / 5.0, # when (target>=value), this is larger than -1.0. when (target<<value) this increases the rate of meter decay
88 ),
89 Value(Target.TargetInfluence)
90 - Value, # limit increase or decrease to the difference between current and target, to avoid overshooting target
91 ),
92 )
93 ),
94 ],
95 ),
96 # increase or decrease towards target meter of ships
97 EffectsGroup(
98 scope=IsSource,
99 activation=Ship,
100 priority=AFTER_ALL_TARGET_MAX_METERS_PRIORITY,
101 effects=[
102 SetResearch(value=Value + MinOf(float, MaxOf(float, Value(Target.TargetResearch) - Value, -1), 1)),
103 SetIndustry(value=Value + MinOf(float, MaxOf(float, Value(Target.TargetIndustry) - Value, -1), 1)),
104 SetInfluence(value=Value + MinOf(float, MaxOf(float, Value(Target.TargetInfluence) - Value, -1), 1)),
105 ],
106 ),
107 # removes residual production from a dead planet
108 EffectsGroup(
109 scope=IsSource,
110 activation=Planet() & TargetPopulation(high=0) & Population(high=0.1),
111 accountinglabel="DYING_POPULATION_LABEL",
112 priority=END_CLEANUP_PRIORITY,
113 effects=[
114 SetResearch(value=0),
115 SetIndustry(value=0),
116 SetTargetIndustry(value=0),
117 SetTargetResearch(value=0),
118 SetTargetInfluence(value=0),
119 ],
120 ),
121 ]
122
123 STANDARD_CONSTRUCTION = [
124 EffectsGroup(
125 scope=IsSource,
126 activation=Planet(),
127 accountinglabel="STANDARD_CONSTRUCTION_LABEL",
128 effects=SetTargetConstruction(value=Value + 20),
129 ),
130 EffectsGroup( # increase or decrease towards target meter, when not recently conquered
131 scope=IsSource,
132 activation=Planet()
133 & (LocalCandidate.LastTurnConquered < CurrentTurn)
134 & (LocalCandidate.LastTurnAttackedByShip < CurrentTurn),
135 priority=AFTER_ALL_TARGET_MAX_METERS_PRIORITY,
136 effects=SetConstruction(
137 value=Value + MinOf(float, MaxOf(float, Value(Target.TargetConstruction) - Value, -1), 1)
138 ),
139 ),
140 EffectsGroup( # always ensure minimum value of one, as this is necessary for being attacked
141 scope=IsSource,
142 activation=Planet(),
143 # has to happen after e.g. FORCE_ENERGY_STRC effects which also happens at AFTER_ALL_TARGET_MAX_METERS_PRIORITY
144 priority=LATE_AFTER_ALL_TARGET_MAX_METERS_PRIORITY,
145 effects=SetConstruction(value=MaxOf(float, Value, 1)),
146 ),
147 ]
148
149
150 FOCUS_CHANGE_PENALTY = [
151 # penalize changing focus by reducing the non-focused resource meters on the turns after the focus change.
152 # these effects reduce the non-focused resource meters by 2 on the turn after a focus change.
153 # eg. if changing to industry focus, if the new research target is 10 and the research is 20, research will
154 # be reduced by 2 to 18. If research is 11, then it will be only reduced to the target (10).
155 EffectsGroup(
156 scope=IsSource,
157 activation=Planet() & ~Focus(type=["FOCUS_INDUSTRY"]) & (LocalCandidate.TurnsSinceFocusChange == 0),
158 priority=FOCUS_CHANGE_PENALTY_PRIORITY,
159 effects=SetIndustry(
160 value=Value
161 - MaxOf(
162 float,
163 0,
164 MinOf(
165 float,
166 MaxOf(float, 2, (Abs(float, Value - Value(Target.TargetIndustry))) ** 0.5),
167 Value - Value(Target.TargetIndustry),
168 ),
169 )
170 ),
171 ),
172 EffectsGroup(
173 scope=IsSource,
174 activation=Planet() & ~Focus(type=["FOCUS_RESEARCH"]) & (0 == LocalCandidate.TurnsSinceFocusChange),
175 priority=FOCUS_CHANGE_PENALTY_PRIORITY,
176 effects=SetResearch(
177 value=Value
178 - MaxOf(
179 float,
180 0,
181 MinOf(
182 float,
183 MaxOf(float, 2, (Abs(float, Value - Value(Target.TargetResearch))) ** 0.5),
184 Value - Value(Target.TargetResearch),
185 ),
186 )
187 ),
188 ),
189 EffectsGroup(
190 scope=IsSource,
191 activation=Planet() & ~Focus(type=["FOCUS_INFLUENCE"]) & (0 == LocalCandidate.TurnsSinceFocusChange),
192 priority=FOCUS_CHANGE_PENALTY_PRIORITY,
193 effects=SetInfluence(
194 value=Value
195 - MaxOf(
196 float,
197 0,
198 MinOf(
199 float,
200 MaxOf(float, 2, (Abs(float, Value - Value(Target.TargetInfluence))) ** 0.5),
201 Value - Value(Target.TargetInfluence),
202 ),
203 )
204 ),
205 ),
206 # TODO Delete this whole Stockpile penalty clause if Stockpile is determined to remain as a Max rather than a Target type meter
207 # If a decision is made to change Stockpile to a Target type meter, then simply change MaxStockpile below to TargetStockpile
208 EffectsGroup(
209 scope=IsSource,
210 activation=Planet() & ~Focus(type=["FOCUS_STOCKPILE"]) & (0 == LocalCandidate.TurnsSinceFocusChange),
211 priority=FOCUS_CHANGE_PENALTY_PRIORITY,
212 effects=SetStockpile(
213 value=Value
214 - MaxOf(float, 0, MinOf(float, 1.0 - Target.TurnsSinceFocusChange, Value - Value(Target.MaxStockpile)))
215 ),
216 ),
217 ]
218
219 # //##### COLONIZATION SPEED #####//
220
221 # // FAST_COLONIZATION and SLOW_COLONIZATION are stubs for applying the
222 # // fast colonization building speed description to a species.
223 # FAST_COLONIZATION
224 # '''[[DESCRIPTION_EFFECTSGROUP_MACRO(FAST_COLONIZATION_DESC)]]'''
225
226 # SLOW_COLONIZATION
227 # '''[[DESCRIPTION_EFFECTSGROUP_MACRO(SLOW_COLONIZATION_DESC)]]'''