Debian Codegraph @

test-scripting/species/species_macros/troops.py

raw
1 from macros.base_prod import TROOPS_PER_POP
2 from macros.priorities import (
3 AFTER_ALL_TARGET_MAX_METERS_PRIORITY,
4 TARGET_AFTER_2ND_SCALING_PRIORITY,
5 TARGET_EARLY_BEFORE_SCALING_PRIORITY,
6 TARGET_SCALING_PRIORITY,
7 )
8
9 try:
10 from focs._effects import (
11 Abs,
12 Adequate,
13 Capital,
14 CurrentTurn,
15 EffectsGroup,
16 EmpireStockpile,
17 Focus,
18 GalaxyMaxAIAggression,
19 Happiness,
20 HasEmpireStockpile,
21 HasSpecies,
22 Homeworld,
23 Hostile,
24 Influence,
25 IsHuman,
26 IsSource,
27 LocalCandidate,
28 MaxOf,
29 MinOf,
30 NamedReal,
31 OwnedBy,
32 Planet,
33 Poor,
34 SetMaxTroops,
35 SetRebelTroops,
36 SetTargetHappiness,
37 SetTargetInfluence,
38 SetTroops,
39 Source,
40 StatisticCount,
41 Target,
42 Unowned,
43 Value,
44 )
45 except ModuleNotFoundError:
46 pass
47
48
49 UNSTABLE_REBEL_TROOPS = [
50 EffectsGroup(
51 scope=IsSource,
52 activation=~Unowned & ~Happiness(low=0),
53 accountinglabel="INSTABILITY_REBELLION",
54 priority=TARGET_EARLY_BEFORE_SCALING_PRIORITY,
55 # more negative stability and more population generates more rebels each turn
56 # TODO: scale with some species trait?
57 effects=SetRebelTroops(value=Value + Abs(float, Target.Happiness) * (Target.Population / 5.0) ** 0.5),
58 ),
59 EffectsGroup(
60 scope=IsSource,
61 activation=Planet() & ~Unowned & ~HasEmpireStockpile(empire=Source.Owner, resource=Influence, low=0) & ~Capital
62 # TODO: some species trait?
63 ,
64 accountinglabel="PARTISANS_REBELLION",
65 priority=TARGET_EARLY_BEFORE_SCALING_PRIORITY,
66 effects=SetTargetHappiness(
67 value=Value - 0.5 * Abs(float, EmpireStockpile(empire=Source.Owner, resource=Influence)) ** 0.5
68 ),
69 ),
70 EffectsGroup(
71 scope=IsSource,
72 activation=Planet() & ~Unowned & ~HasEmpireStockpile(empire=Source.Owner, resource=Influence, low=0) & ~Capital,
73 accountinglabel="INFLUENCE_DEBT_DECAY",
74 priority=TARGET_EARLY_BEFORE_SCALING_PRIORITY,
75 effects=SetTargetInfluence(
76 value=Value
77 + 0.5
78 * Abs(float, EmpireStockpile(empire=Source.Owner, resource=Influence)) ** 0.5
79 / MaxOf(float, 1.0, StatisticCount(float, condition=Planet() & HasSpecies() & OwnedBy(empire=Source.Owner)))
80 ),
81 ),
82 EffectsGroup(
83 scope=IsSource,
84 activation=Planet(environment=[Adequate]),
85 accountinglabel="DEPENDENCE_ON_IMPERIAL_SUPPORT_DUE_TO_ENVIRONMENT",
86 priority=TARGET_SCALING_PRIORITY,
87 effects=SetRebelTroops(value=MaxOf(float, 0.0, Abs(float, Value / 1.5))),
88 ),
89 EffectsGroup(
90 scope=IsSource,
91 activation=Planet(environment=[Poor]),
92 accountinglabel="DEPENDENCE_ON_IMPERIAL_SUPPORT_DUE_TO_ENVIRONMENT",
93 priority=TARGET_SCALING_PRIORITY,
94 effects=SetRebelTroops(value=MaxOf(float, 0.0, Abs(float, Value / 2.0))),
95 ),
96 EffectsGroup(
97 scope=IsSource,
98 activation=Planet(environment=[Hostile]),
99 accountinglabel="DEPENDENCE_ON_IMPERIAL_SUPPORT_DUE_TO_ENVIRONMENT",
100 priority=TARGET_SCALING_PRIORITY,
101 effects=SetRebelTroops(value=MaxOf(float, 0.0, Abs(float, Value / 4.0))),
102 ),
103 ]
104
105 BASIC_DEFENSE_TROOPS = [
106 EffectsGroup(
107 scope=IsSource,
108 activation=Homeworld() & ~Unowned,
109 stackinggroup="HOMEWORLD_TROOPS_STACK",
110 priority=TARGET_EARLY_BEFORE_SCALING_PRIORITY,
111 effects=SetMaxTroops(value=Value + 4),
112 # accountinglabel="HOMEWORLD_LABEL",
113 ),
114 EffectsGroup(
115 scope=IsSource,
116 activation=Planet() & ~Unowned,
117 accountinglabel="IMPERIAL_GARRISON_LABEL",
118 priority=TARGET_EARLY_BEFORE_SCALING_PRIORITY,
119 effects=SetMaxTroops(value=Value + 6),
120 ),
121 EffectsGroup(
122 scope=IsSource,
123 activation=Planet() & Unowned,
124 stackinggroup="BASIC_TROOPS_STACK",
125 accountinglabel="INDEPENDENT_TROOP_LABEL",
126 priority=TARGET_EARLY_BEFORE_SCALING_PRIORITY,
127 effects=SetMaxTroops(value=Value + 10),
128 ),
129 EffectsGroup(
130 scope=IsSource,
131 activation=Planet(),
132 stackinggroup="POPULATION_TROOPS_STACK",
133 accountinglabel="DEF_ROOT_DEFENSE",
134 priority=TARGET_EARLY_BEFORE_SCALING_PRIORITY,
135 effects=SetMaxTroops(
136 value=Value
137 + Target.Population * NamedReal(name="BASIC_DEFENSE_TROOPS_MAX_TROOPS_PERPOP", value=1.0 * TROOPS_PER_POP)
138 ),
139 ),
140 EffectsGroup( # gives human bonuses when AI Aggression set to Beginner
141 scope=IsSource,
142 activation=IsHuman & (GalaxyMaxAIAggression == 0) & Planet(), # human player, not human species
143 accountinglabel="DIFFICULTY",
144 effects=SetMaxTroops(value=MaxOf(float, 6, Value * 2)),
145 ),
146 EffectsGroup( # base troops regeneration
147 scope=IsSource,
148 activation=Planet()
149 & (LocalCandidate.LastTurnConquered < CurrentTurn)
150 & (LocalCandidate.LastTurnAttackedByShip < CurrentTurn),
151 priority=AFTER_ALL_TARGET_MAX_METERS_PRIORITY,
152 effects=SetTroops(
153 value=MinOf(
154 float, Value(Target.MaxTroops), Value + NamedReal(name="BASIC_DEFENSE_TROOPS_TROOPREGEN_FLAT", value=1)
155 )
156 ),
157 ),
158 ]
159
160 PROTECTION_FOCUS_TROOPS = [
161 EffectsGroup( # double max troops
162 scope=IsSource,
163 activation=Planet() & Focus(type=["FOCUS_PROTECTION"]),
164 stackinggroup="FOCUS_PROTECTION_TROOPS_STACK",
165 priority=TARGET_AFTER_2ND_SCALING_PRIORITY,
166 effects=SetMaxTroops(value=MaxOf(float, Value, Value * 2)),
167 # accountinglabel="FOCUS_PROTECTION_LABEL",
168 ),
169 EffectsGroup( # increase troop growth rate
170 scope=IsSource,
171 activation=Planet()
172 & Focus(type=["FOCUS_PROTECTION"])
173 & (LocalCandidate.LastTurnConquered < CurrentTurn)
174 & (LocalCandidate.LastTurnAttackedByShip < CurrentTurn),
175 accountinglabel="FOCUS_PROTECTION_LABEL",
176 priority=AFTER_ALL_TARGET_MAX_METERS_PRIORITY,
177 effects=SetTroops(
178 value=MinOf(
179 float, Value(Target.MaxTroops), Value + MaxOf(float, Target.MaxTroops, Target.Population) ** 0.5
180 )
181 ),
182 ),
183 ]
184
185
186 # NO_DEFENSE_TROOPS
187 # ''' EffectsGroup
188 # description = "NO_DEFENSE_TROOPS_DESC"
189 # scope = Source
190 # activation = None
191 # effects = SetMaxTroops value = 0
192
193 # [[UNSTABLE_REBEL_TROOPS]]
194 # '''
195
196 BAD_DEFENSE_TROOPS = [
197 *BASIC_DEFENSE_TROOPS,
198 EffectsGroup(
199 description="BAD_DEFENSE_TROOPS_DESC",
200 scope=IsSource,
201 activation=Planet(),
202 effects=SetMaxTroops(value=Value * 0.5),
203 # accountinglabel="BAD_TROOPS_LABEL",
204 ),
205 *UNSTABLE_REBEL_TROOPS,
206 *PROTECTION_FOCUS_TROOPS,
207 ]
208
209 # AVERAGE_DEFENSE_TROOPS
210 # '''[[BASIC_DEFENSE_TROOPS]]
211
212 # [[UNSTABLE_REBEL_TROOPS]]
213
214 # [[PROTECTION_FOCUS_TROOPS]]
215 # '''
216
217 # GOOD_DEFENSE_TROOPS
218 # '''[[BASIC_DEFENSE_TROOPS]]
219
220 # EffectsGroup
221 # description = "GOOD_DEFENSE_TROOPS_DESC"
222 # scope = Source
223 # activation = Planet
224 # effects = SetMaxTroops value = Value * 1.5
225 # accountinglabel = "GOOD_TROOPS_LABEL"
226
227 # [[UNSTABLE_REBEL_TROOPS]]
228
229 # [[PROTECTION_FOCUS_TROOPS]]
230 # '''
231
232 # GREAT_DEFENSE_TROOPS
233 # '''[[BASIC_DEFENSE_TROOPS]]
234
235 # EffectsGroup
236 # description = "GREAT_DEFENSE_TROOPS_DESC"
237 # scope = Source
238 # activation = Planet
239 # effects = SetMaxTroops value = Value * 2
240 # accountinglabel = "GREAT_TROOPS_LABEL"
241
242 # [[UNSTABLE_REBEL_TROOPS]]
243
244 # [[PROTECTION_FOCUS_TROOPS]]
245 # '''
246
247 # ULTIMATE_DEFENSE_TROOPS
248 # '''[[BASIC_DEFENSE_TROOPS]]
249
250 # EffectsGroup
251 # description = "ULTIMATE_DEFENSE_TROOPS_DESC"
252 # scope = Source
253 # activation = Planet
254 # effects = SetMaxTroops value = Value * 3
255 # accountinglabel = "ULTIMATE_TROOPS_LABEL"
256
257 # [[UNSTABLE_REBEL_TROOPS]]
258
259 # [[PROTECTION_FOCUS_TROOPS]]
260 # '''
261
262 # NO_OFFENSE_TROOPS
263 # '''EffectsGroup
264 # description = "NO_OFFENSE_TROOPS_DESC"
265 # scope = Source
266 # activation = And [
267 # Ship
268 # Or [
269 # DesignHasPart name = "GT_TROOP_POD"
270 # DesignHasPart name = "GT_TROOP_POD_2"
271 # ]
272 # ]
273 # stackinggroup = "NO_OFFENSIVE_TROOPS_STACK"
274 # accountinglabel = "NO_OFFENSIVE_TROOPS_LABEL"
275 # effects = [
276 # SetCapacity partname = "GT_TROOP_POD" value = 0
277 # SetCapacity partname = "GT_TROOP_POD_2" value = 0
278 # ]
279 # '''
280
281 # BAD_OFFENSE_TROOPS
282 # '''EffectsGroup
283 # description = "BAD_OFFENSE_TROOPS_DESC"
284 # scope = Source
285 # activation = And [
286 # Ship
287 # Or [
288 # DesignHasPart name = "GT_TROOP_POD"
289 # DesignHasPart name = "GT_TROOP_POD_2"
290 # ]
291 # ]
292 # stackinggroup = "BAD_OFFENSIVE_TROOPS_STACK"
293 # accountinglabel = "BAD_OFFENSIVE_TROOPS_LABEL"
294 # effects = [
295 # SetCapacity partname = "GT_TROOP_POD" value = (PartCapacity name = "GT_TROOP_POD") * 0.5
296 # SetCapacity partname = "GT_TROOP_POD_2" value = (PartCapacity name = "GT_TROOP_POD_2") * 0.5
297 # ]
298 # '''
299
300 # //AVERAGE_OFFENSE_TROOPS has no effects
301
302 # GOOD_OFFENSE_TROOPS
303 # '''EffectsGroup
304 # description = "GOOD_OFFENSE_TROOPS_DESC"
305 # scope = Source
306 # activation = And [
307 # Ship
308 # Or [
309 # DesignHasPart name = "GT_TROOP_POD"
310 # DesignHasPart name = "GT_TROOP_POD_2"
311 # ]
312 # ]
313 # stackinggroup = "GOOD_OFFENSIVE_TROOPS_STACK"
314 # accountinglabel = "GOOD_OFFENSIVE_TROOPS_LABEL"
315 # effects = [
316 # SetCapacity partname = "GT_TROOP_POD" value = (PartCapacity name = "GT_TROOP_POD") * 1.5
317 # SetCapacity partname = "GT_TROOP_POD_2" value = (PartCapacity name = "GT_TROOP_POD_2") * 1.5
318 # ]
319 # '''
320
321 # GREAT_OFFENSE_TROOPS
322 # '''EffectsGroup
323 # description = "GREAT_OFFENSE_TROOPS_DESC"
324 # scope = Source
325 # activation = And [
326 # Ship
327 # Or [
328 # DesignHasPart name = "GT_TROOP_POD"
329 # DesignHasPart name = "GT_TROOP_POD_2"
330 # ]
331 # ]
332 # stackinggroup = "GREAT_OFFENSIVE_TROOPS_STACK"
333 # accountinglabel = "GREAT_OFFENSIVE_TROOPS_LABEL"
334 # effects = [
335 # SetCapacity partname = "GT_TROOP_POD" value = (PartCapacity name = "GT_TROOP_POD") * 2
336 # SetCapacity partname = "GT_TROOP_POD_2" value = (PartCapacity name = "GT_TROOP_POD_2") * 2
337 # ]
338 # '''
339
340 # ULTIMATE_OFFENSE_TROOPS
341 # '''EffectsGroup
342 # description = "ULTIMATE_OFFENSE_TROOPS_DESC"
343 # scope = Source
344 # activation = And [
345 # Ship
346 # Or [
347 # DesignHasPart name = "GT_TROOP_POD"
348 # DesignHasPart name = "GT_TROOP_POD_2"
349 # ]
350 # ]
351 # stackinggroup = "ULTIMATE_OFFENSIVE_TROOPS_STACK"
352 # accountinglabel = "ULTIMATE_OFFENSIVE_TROOPS_LABEL"
353 # effects = [
354 # SetCapacity partname = "GT_TROOP_POD" value = (PartCapacity name = "GT_TROOP_POD") * 3
355 # SetCapacity partname = "GT_TROOP_POD_2" value = (PartCapacity name = "GT_TROOP_POD_2") * 3
356 # ]
357 # '''