Debian Codegraph @

default/scripting/species/species_macros/troops.py

raw
1 from focs._effects import (
2 Abs,
3 Adequate,
4 Capital,
5 CurrentTurn,
6 DesignHasPart,
7 EffectsGroup,
8 EmpireStockpile,
9 Focus,
10 GalaxyMaxAIAggression,
11 Happiness,
12 HasEmpireStockpile,
13 HasSpecies,
14 Homeworld,
15 Hostile,
16 Influence,
17 IsHuman,
18 IsSource,
19 LocalCandidate,
20 MaxOf,
21 MinOf,
22 NamedReal,
23 NamedRealLookup,
24 OwnedBy,
25 PartCapacity,
26 Planet,
27 Poor,
28 SetCapacity,
29 SetMaxTroops,
30 SetRebelTroops,
31 SetTargetHappiness,
32 SetTargetInfluence,
33 SetTroops,
34 Ship,
35 Source,
36 StatisticCount,
37 Target,
38 Unowned,
39 Value,
40 )
41 from macros.base_prod import TROOPS_PER_POP
42 from macros.priorities import (
43 AFTER_ALL_TARGET_MAX_METERS_PRIORITY,
44 TARGET_AFTER_2ND_SCALING_PRIORITY,
45 TARGET_EARLY_BEFORE_SCALING_PRIORITY,
46 TARGET_SCALING_PRIORITY,
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 _PROTECTION_FOCUS_TROOPS = [
106 EffectsGroup( # double max troops
107 scope=IsSource,
108 activation=Planet() & Focus(type=["FOCUS_PROTECTION"]),
109 stackinggroup="FOCUS_PROTECTION_TROOPS_STACK",
110 priority=TARGET_AFTER_2ND_SCALING_PRIORITY,
111 effects=SetMaxTroops(value=MaxOf(float, Value, Value * 2)),
112 # accountinglabel="FOCUS_PROTECTION_LABEL",
113 ),
114 EffectsGroup( # increase troop growth rate
115 scope=IsSource,
116 activation=Planet()
117 & Focus(type=["FOCUS_PROTECTION"])
118 & (LocalCandidate.LastTurnConquered < CurrentTurn)
119 & (LocalCandidate.LastTurnAttackedByShip < CurrentTurn),
120 accountinglabel="FOCUS_PROTECTION_LABEL",
121 priority=AFTER_ALL_TARGET_MAX_METERS_PRIORITY,
122 effects=SetTroops(
123 value=MinOf(
124 float, Value(Target.MaxTroops), Value + MaxOf(float, Target.MaxTroops, Target.Population) ** 0.5
125 )
126 ),
127 ),
128 ]
129
130
131 _BASIC_DEFENSE_TROOPS = [
132 EffectsGroup(
133 scope=IsSource,
134 activation=Homeworld() & ~Unowned,
135 stackinggroup="HOMEWORLD_TROOPS_STACK",
136 priority=TARGET_EARLY_BEFORE_SCALING_PRIORITY,
137 effects=SetMaxTroops(value=Value + 4),
138 # accountinglabel="HOMEWORLD_LABEL",
139 ),
140 EffectsGroup(
141 scope=IsSource,
142 activation=Planet() & ~Unowned,
143 accountinglabel="IMPERIAL_GARRISON_LABEL",
144 priority=TARGET_EARLY_BEFORE_SCALING_PRIORITY,
145 effects=SetMaxTroops(value=Value + NamedRealLookup(name="IMPERIAL_GARRISON_MAX_TROOPS_FLAT")),
146 ),
147 EffectsGroup(
148 scope=IsSource,
149 activation=Planet() & Unowned,
150 stackinggroup="BASIC_TROOPS_STACK",
151 accountinglabel="INDEPENDENT_TROOP_LABEL",
152 priority=TARGET_EARLY_BEFORE_SCALING_PRIORITY,
153 effects=SetMaxTroops(value=Value + 10),
154 ),
155 EffectsGroup(
156 scope=IsSource,
157 activation=Planet(),
158 stackinggroup="POPULATION_TROOPS_STACK",
159 accountinglabel="DEF_ROOT_DEFENSE",
160 priority=TARGET_EARLY_BEFORE_SCALING_PRIORITY,
161 effects=SetMaxTroops(
162 value=Value
163 + Target.Population * NamedReal(name="BASIC_DEFENSE_TROOPS_MAX_TROOPS_PERPOP", value=1.0 * TROOPS_PER_POP)
164 ),
165 ),
166 EffectsGroup( # gives human bonuses when AI Aggression set to Beginner
167 scope=IsSource,
168 activation=IsHuman & (GalaxyMaxAIAggression == 0) & Planet(), # human player, not human species
169 accountinglabel="DIFFICULTY",
170 effects=SetMaxTroops(value=MaxOf(float, 6, Value * 2)),
171 ),
172 EffectsGroup( # base troops regeneration
173 scope=IsSource,
174 activation=Planet()
175 & (LocalCandidate.LastTurnConquered < CurrentTurn)
176 & (LocalCandidate.LastTurnAttackedByShip < CurrentTurn),
177 priority=AFTER_ALL_TARGET_MAX_METERS_PRIORITY,
178 effects=SetTroops(
179 value=MinOf(
180 float, Value(Target.MaxTroops), Value + NamedReal(name="BASIC_DEFENSE_TROOPS_TROOPREGEN_FLAT", value=1)
181 )
182 ),
183 ),
184 ]
185
186 NO_DEFENSE_TROOPS = [
187 EffectsGroup(description="NO_DEFENSE_TROOPS_DESC", scope=IsSource, activation=None, effects=SetMaxTroops(value=0)),
188 *_UNSTABLE_REBEL_TROOPS,
189 ]
190
191
192 BAD_DEFENSE_TROOPS = [
193 *_BASIC_DEFENSE_TROOPS,
194 EffectsGroup(
195 description="BAD_DEFENSE_TROOPS_DESC",
196 scope=IsSource,
197 activation=Planet(),
198 effects=SetMaxTroops(value=Value * 0.5),
199 ),
200 *_UNSTABLE_REBEL_TROOPS,
201 *_PROTECTION_FOCUS_TROOPS,
202 ]
203
204 AVERAGE_DEFENSE_TROOPS = [
205 *_BASIC_DEFENSE_TROOPS,
206 *_UNSTABLE_REBEL_TROOPS,
207 *_PROTECTION_FOCUS_TROOPS,
208 ]
209
210
211 GOOD_DEFENSE_TROOPS = [
212 *_BASIC_DEFENSE_TROOPS,
213 EffectsGroup(
214 description="GOOD_DEFENSE_TROOPS_DESC",
215 scope=IsSource,
216 activation=Planet(),
217 effects=SetMaxTroops(value=Value * 1.5),
218 ),
219 *_UNSTABLE_REBEL_TROOPS,
220 *_PROTECTION_FOCUS_TROOPS,
221 ]
222
223
224 GREAT_DEFENSE_TROOPS = [
225 *_BASIC_DEFENSE_TROOPS,
226 EffectsGroup(
227 description="GREAT_DEFENSE_TROOPS_DESC",
228 scope=IsSource,
229 activation=Planet(),
230 effects=SetMaxTroops(value=Value * 2),
231 ),
232 *_UNSTABLE_REBEL_TROOPS,
233 *_PROTECTION_FOCUS_TROOPS,
234 ]
235
236 ULTIMATE_DEFENSE_TROOPS = [
237 *_BASIC_DEFENSE_TROOPS,
238 EffectsGroup(
239 description="ULTIMATE_DEFENSE_TROOPS_DESC",
240 scope=IsSource,
241 activation=Planet(),
242 effects=SetMaxTroops(value=Value * 3),
243 ),
244 *_UNSTABLE_REBEL_TROOPS,
245 *_PROTECTION_FOCUS_TROOPS,
246 ]
247
248
249 NO_OFFENSE_TROOPS = [
250 EffectsGroup(
251 description="NO_OFFENSE_TROOPS_DESC",
252 scope=IsSource,
253 activation=Ship & (DesignHasPart(name="GT_TROOP_POD") | DesignHasPart(name="GT_TROOP_POD_2")),
254 stackinggroup="NO_OFFENSIVE_TROOPS_STACK",
255 accountinglabel="NO_OFFENSIVE_TROOPS_LABEL",
256 effects=[
257 SetCapacity(partname="GT_TROOP_POD", value=0.0),
258 SetCapacity(partname="GT_TROOP_POD_2", value=0.0),
259 ],
260 )
261 ]
262
263 BAD_OFFENSE_TROOPS = [
264 EffectsGroup(
265 description="BAD_OFFENSE_TROOPS_DESC",
266 scope=IsSource,
267 activation=Ship & (DesignHasPart(name="GT_TROOP_POD") | DesignHasPart(name="GT_TROOP_POD_2")),
268 stackinggroup="BAD_OFFENSIVE_TROOPS_STACK",
269 accountinglabel="BAD_OFFENSIVE_TROOPS_LABEL",
270 effects=[
271 SetCapacity(partname="GT_TROOP_POD", value=PartCapacity(name="GT_TROOP_POD") * 0.5),
272 SetCapacity(partname="GT_TROOP_POD_2", value=PartCapacity(name="GT_TROOP_POD_2") * 0.5),
273 ],
274 )
275 ]
276
277
278 GOOD_OFFENSE_TROOPS = [
279 EffectsGroup(
280 description="GOOD_OFFENSE_TROOPS_DESC",
281 scope=IsSource,
282 activation=Ship & (DesignHasPart(name="GT_TROOP_POD") | DesignHasPart(name="GT_TROOP_POD_2")),
283 stackinggroup="GOOD_OFFENSIVE_TROOPS_STACK",
284 accountinglabel="GOOD_OFFENSIVE_TROOPS_LABEL",
285 effects=[
286 SetCapacity(partname="GT_TROOP_POD", value=PartCapacity(name="GT_TROOP_POD") * 1.5),
287 SetCapacity(partname="GT_TROOP_POD_2", value=PartCapacity(name="GT_TROOP_POD_2") * 1.5),
288 ],
289 )
290 ]
291
292
293 GREAT_OFFENSE_TROOPS = [
294 EffectsGroup(
295 description="GREAT_OFFENSE_TROOPS_DESC",
296 scope=IsSource,
297 activation=Ship & (DesignHasPart(name="GT_TROOP_POD") | DesignHasPart(name="GT_TROOP_POD_2")),
298 stackinggroup="GREAT_OFFENSIVE_TROOPS_STACK",
299 accountinglabel="GREAT_OFFENSIVE_TROOPS_LABEL",
300 effects=[
301 SetCapacity(partname="GT_TROOP_POD", value=PartCapacity(name="GT_TROOP_POD") * 2),
302 SetCapacity(partname="GT_TROOP_POD_2", value=PartCapacity(name="GT_TROOP_POD_2") * 2),
303 ],
304 )
305 ]