Debian Codegraph @

test-scripting/species/species_macros/population.py

raw
1 from macros.priorities import (
2 POPULATION_FIRST_PRIORITY,
3 TARGET_POPULATION_AFTER_SCALING_PRIORITY,
4 TARGET_POPULATION_BEFORE_SCALING_PRIORITY,
5 TARGET_POPULATION_LAST_BEFORE_OVERRIDE_PRIORITY,
6 TARGET_POPULATION_OVERRIDE_PRIORITY,
7 TARGET_POPULATION_SCALING_PRIORITY,
8 )
9
10 try:
11 from focs._effects import (
12 Abs,
13 AnyEmpire,
14 BlackHole,
15 Blue,
16 Contains,
17 CurrentTurn,
18 EffectsGroup,
19 EmpireHasAdoptedPolicy,
20 Focus,
21 GasGiantType,
22 Good,
23 HasSpecies,
24 HasTag,
25 Homeworld,
26 Hostile,
27 IsSource,
28 IsTarget,
29 LocalCandidate,
30 MaxOf,
31 MinOf,
32 Neutron,
33 NoStar,
34 Orange,
35 OwnedBy,
36 Planet,
37 Poor,
38 Red,
39 ResourceSupplyConnected,
40 SetPopulation,
41 SetStarType,
42 SetTargetPopulation,
43 Source,
44 Star,
45 StatisticIf,
46 Target,
47 TargetPopulation,
48 Turn,
49 Uninhabitable,
50 Value,
51 White,
52 Yellow,
53 )
54 except ModuleNotFoundError:
55 pass
56
57 from species.species_macros.advanced_focus import ADVANCED_FOCUS_EFFECTS
58 from species.species_macros.general import (
59 FOCUS_CHANGE_PENALTY,
60 STANDARD_CONSTRUCTION,
61 STANDARD_METER_GROWTH,
62 )
63
64 GROWTH_RATE_FACTOR = (
65 0.1
66 * (
67 1 - StatisticIf(float, condition=IsTarget & EmpireHasAdoptedPolicy(name="PLC_NO_GROWTH"))
68 ) # no growth with no-growth policy
69 * (
70 1 + 0.5 * StatisticIf(float, condition=IsTarget & EmpireHasAdoptedPolicy(name="PLC_POPULATION"))
71 ) # +50% growth with population policy
72 * (
73 1
74 + StatisticIf(float, condition=IsTarget & EmpireHasAdoptedPolicy(name="PLC_AUGMENTATION"))
75 # slower growth with augmentation on low-infrastructure planets
76 * MinOf(
77 float,
78 1.2,
79 MaxOf(
80 float,
81 0.5,
82 Target.Construction / 40.0,
83 ),
84 )
85 )
86 )
87
88 HOMEWORLD_BONUS_POPULATION = EffectsGroup(
89 scope=IsSource & Homeworld(name=[Source.Species]),
90 activation=Planet(),
91 stackinggroup="HOMEWORLD_STACK",
92 accountinglabel="HOMEWORLD_BONUS",
93 priority=TARGET_POPULATION_AFTER_SCALING_PRIORITY,
94 effects=SetTargetPopulation(value=Value + 2 * Target.HabitableSize),
95 )
96
97 # Implements environmental modifiers from Growth techs.
98 # Changes to the growth tree should take this into account.
99
100 ENVIRONMENT_MODIFIER = [
101 EffectsGroup(
102 scope=IsSource,
103 activation=Planet() & Planet(environment=[Uninhabitable]),
104 accountinglabel="UNINHABTIABLE_ENVIRONMENT_LABEL",
105 priority=TARGET_POPULATION_OVERRIDE_PRIORITY,
106 effects=SetTargetPopulation(value=-999),
107 ),
108 EffectsGroup(
109 scope=IsSource,
110 activation=Planet() & Planet(environment=[Hostile]),
111 accountinglabel="HOSTILE_ENVIRONMENT_LABEL",
112 priority=TARGET_POPULATION_BEFORE_SCALING_PRIORITY,
113 effects=SetTargetPopulation(value=Value - 4 * Source.HabitableSize),
114 ),
115 EffectsGroup(
116 scope=IsSource,
117 activation=Planet() & Planet(environment=[Poor]),
118 accountinglabel="POOR_ENVIRONMENT_LABEL",
119 priority=TARGET_POPULATION_BEFORE_SCALING_PRIORITY,
120 effects=SetTargetPopulation(value=Value - 2 * Source.HabitableSize),
121 ),
122 # EffectsGroup
123 # scope = Source
124 # activation = And [
125 # Planet
126 # Planet environment = Adequate
127 # ]
128 # accountinglabel = "ADEQUATE_ENVIRONMENT_LABEL"
129 # priority = [[TARGET_POPULATION_BEFORE_SCALING_PRIORITY]]
130 # effects = SetTargetPopulation value = Value + 0 * Source.HabitableSize
131 EffectsGroup(
132 scope=IsSource,
133 activation=Planet(environment=[Good]),
134 accountinglabel="GOOD_ENVIRONMENT_LABEL",
135 priority=TARGET_POPULATION_BEFORE_SCALING_PRIORITY,
136 effects=SetTargetPopulation(value=Value + 3 * Target.HabitableSize),
137 ),
138 ]
139
140 # This is dependent on current placement in population effects calc,
141 # just after Homeworld and Environment
142 SELF_SUSTAINING_BONUS = EffectsGroup(
143 scope=IsSource,
144 activation=Planet(environment=[Good]) & HasTag(name="SELF_SUSTAINING"),
145 accountinglabel="SELF_SUSTAINING_LABEL",
146 priority=TARGET_POPULATION_AFTER_SCALING_PRIORITY,
147 effects=SetTargetPopulation(value=Value + 3 * Target.HabitableSize), # Gets the same bonus as three growth specials
148 )
149
150 PHOTOTROPHIC_BONUS = [
151 EffectsGroup(
152 scope=Contains(IsSource),
153 activation=Planet()
154 & (
155 OwnedBy(affiliation=AnyEmpire)
156 | Star(type=[BlackHole, NoStar]) # Natives are allowed to have bright or dim stars
157 )
158 & HasTag(name="PHOTOTROPHIC")
159 & Turn(high=0)
160 & ~Star(type=[Orange]),
161 effects=SetStarType(type=Yellow), # start with a normal star to be balanced
162 ),
163 EffectsGroup(
164 scope=IsSource,
165 activation=Planet() & HasTag(name="PHOTOTROPHIC") & Star(type=[Blue]) & TargetPopulation(low=0),
166 accountinglabel="VERY_BRIGHT_STAR",
167 priority=TARGET_POPULATION_LAST_BEFORE_OVERRIDE_PRIORITY,
168 effects=SetTargetPopulation(value=Value + 3 * Source.HabitableSize),
169 ),
170 EffectsGroup(
171 scope=IsSource,
172 activation=Planet() & HasTag(name="PHOTOTROPHIC") & Star(type=[White]) & TargetPopulation(low=0),
173 accountinglabel="BRIGHT_STAR",
174 priority=TARGET_POPULATION_LAST_BEFORE_OVERRIDE_PRIORITY,
175 effects=SetTargetPopulation(value=Value + 1.5 * Source.HabitableSize),
176 ),
177 EffectsGroup(
178 scope=IsSource,
179 activation=Planet() & HasTag(name="PHOTOTROPHIC") & Star(type=[Red, Neutron]),
180 accountinglabel="DIM_STAR",
181 priority=TARGET_POPULATION_LAST_BEFORE_OVERRIDE_PRIORITY,
182 effects=SetTargetPopulation(value=Value - 1 * Source.HabitableSize),
183 ),
184 EffectsGroup(
185 scope=IsSource,
186 activation=Planet() & HasTag(name="PHOTOTROPHIC") & Star(type=[BlackHole, NoStar]),
187 accountinglabel="NO_STAR",
188 priority=TARGET_POPULATION_LAST_BEFORE_OVERRIDE_PRIORITY,
189 effects=SetTargetPopulation(value=Value - 10 * Source.HabitableSize),
190 ),
191 ]
192
193 GASEOUS_BONUS = EffectsGroup(
194 scope=IsSource,
195 activation=Planet(type=[GasGiantType]) & HasTag(name="GASEOUS"),
196 accountinglabel="GASEOUS_LABEL",
197 priority=TARGET_POPULATION_SCALING_PRIORITY,
198 effects=SetTargetPopulation(value=Value - 0.5 * Abs(float, Value)),
199 )
200
201 HOMEWORLD_GROWTH_FOCUS_BOOST = EffectsGroup(
202 scope=Planet()
203 & OwnedBy(empire=Source.Owner)
204 & HasSpecies(name=[Source.Species])
205 & ~Homeworld(name=[Source.Species])
206 & ResourceSupplyConnected(empire=Source.Owner, condition=IsSource),
207 activation=Planet() & Focus(type=["FOCUS_GROWTH"]) & Homeworld(),
208 stackinggroup="HOMEWORLD_STACK",
209 accountinglabel="HOMEWORLD_SUPPLY",
210 priority=TARGET_POPULATION_AFTER_SCALING_PRIORITY,
211 effects=SetTargetPopulation(value=Value + 1 * Target.HabitableSize),
212 )
213
214
215 BASIC_POPULATION = [
216 HOMEWORLD_BONUS_POPULATION,
217 *ENVIRONMENT_MODIFIER,
218 SELF_SUSTAINING_BONUS,
219 *PHOTOTROPHIC_BONUS,
220 GASEOUS_BONUS,
221 HOMEWORLD_GROWTH_FOCUS_BOOST,
222 # population growth or decay towards to target population
223 EffectsGroup(
224 scope=IsSource,
225 activation=Planet() & (LocalCandidate.LastTurnConquered < CurrentTurn),
226 priority=POPULATION_FIRST_PRIORITY,
227 effects=SetPopulation(
228 # growth is GROWTH_RATE_FACTOR * population * (maximum + 1 - population) / maximum
229 # which gives factor for population 1, best growth around half full and aproaching
230 # factor again when almost full
231 value=(
232 (Value < Value(Target.TargetPopulation))
233 * MinOf(
234 float,
235 Value(Target.TargetPopulation),
236 Value + Value * GROWTH_RATE_FACTOR * (1 + (1 - Value) / Value(Target.TargetPopulation)),
237 )
238 )
239 # shrink if overpopulated
240 + (
241 (Value >= Value(Target.TargetPopulation))
242 * MaxOf(float, Value(Target.TargetPopulation), Value - 0.1 * (Value - Value(Target.TargetPopulation)))
243 )
244 ),
245 ),
246 # Since all species have the same advanced focus effects and
247 # infrastructure, the macros are stashed here, where they don't
248 # need to be manually included in each species' macros.
249 *FOCUS_CHANGE_PENALTY,
250 *ADVANCED_FOCUS_EFFECTS,
251 *STANDARD_CONSTRUCTION,
252 *STANDARD_METER_GROWTH,
253 ]
254
255 AVERAGE_POPULATION = BASIC_POPULATION
256
257 # EXTREMELY_BAD_POPULATION
258 # ''' [[BASIC_POPULATION]]
259 #
260 # EffectsGroup
261 # description = "EXTREMELY_BAD_POPULATION_DESC"
262 # scope = Source
263 # activation = Planet
264 # accountinglabel = "EXTREMELY_BAD_POPULATION_LABEL"
265 # priority = [[TARGET_POPULATION_SCALING_PRIORITY]]
266 # effects = SetTargetPopulation value = Value -0.75*abs(Value)
267 # '''
268
269 # VERY_BAD_POPULATION
270 # ''' [[BASIC_POPULATION]]
271 #
272 # EffectsGroup
273 # description = "VERY_BAD_POPULATION_DESC"
274 # scope = Source
275 # activation = Planet
276 # accountinglabel = "VERY_BAD_POPULATION_LABEL"
277 # priority = [[TARGET_POPULATION_SCALING_PRIORITY]]
278 # effects = SetTargetPopulation value = Value -0.5*abs(Value)
279 # '''
280
281 # BAD_POPULATION
282 # ''' [[BASIC_POPULATION]]
283 #
284 # EffectsGroup
285 # description = "BAD_POPULATION_DESC"
286 # scope = Source
287 # activation = Planet
288 # accountinglabel = "BAD_POPULATION_LABEL"
289 # priority = [[TARGET_POPULATION_SCALING_PRIORITY]]
290 # effects = SetTargetPopulation value = Value -0.25*abs(Value)
291 # '''
292
293 # GOOD_POPULATION
294 # ''' [[BASIC_POPULATION]]
295
296 # EffectsGroup
297 # description = "GOOD_POPULATION_DESC"
298 # scope = Source
299 # activation = Planet
300 # accountinglabel = "GOOD_POPULATION_LABEL"
301 # priority = [[TARGET_POPULATION_SCALING_PRIORITY]]
302 # effects = SetTargetPopulation value = Value +0.25*abs(Value)
303 # '''
304
305 # // reduces max population in systems with bright stars
306 # LIGHT_SENSITIVE
307 # '''
308 # EffectsGroup
309 # description = "LIGHT_SENSITIVE_DESC"
310 # scope = Source
311 # activation = And [
312 # Planet
313 # Star type = [Blue]
314 # ]
315 # accountinglabel = "VERY_BRIGHT_STAR"
316 # priority = [[TARGET_POPULATION_AFTER_SCALING_PRIORITY]]
317 # effects = SetTargetPopulation value = Value - 2 * Source.HabitableSize
318
319 # EffectsGroup
320 # scope = Source
321 # activation = And [
322 # Planet
323 # Star type = [White]
324 # ]
325 # accountinglabel = "BRIGHT_STAR"
326 # priority = [[TARGET_POPULATION_AFTER_SCALING_PRIORITY]]
327 # effects = SetTargetPopulation value = Value - Source.HabitableSize
328 # '''
329
330
331 # // @1@ Species key
332 # LIFECYCLE_MANIP_POPULATION_EFFECTS
333 # '''
334 # EffectsGroup
335 # scope = And [
336 # Object id = Source.PlanetID
337 # Planet
338 # ]
339 # activation = And [
340 # Not OwnerHasTech name = "GRO_LIFECYCLE_MAN"
341 # Turn low = LocalCandidate.CreationTurn + 1 high = LocalCandidate.CreationTurn + 1
342 # ]
343 # priority = [[POPULATION_DEFAULT_PRIORITY]]
344 # effects = [
345 # SetSpecies name = @1@
346 # SetPopulation value = 1
347 # ]
348 #
349 # EffectsGroup
350 # scope = And [
351 # Object id = Source.PlanetID
352 # Planet
353 # ]
354 # activation = And [
355 # OwnerHasTech name = "GRO_LIFECYCLE_MAN"
356 # Turn low = LocalCandidate.CreationTurn + 1 high = LocalCandidate.CreationTurn + 1
357 # ]
358 # priority = [[POPULATION_DEFAULT_PRIORITY]]
359 # effects = [
360 # SetSpecies name = @1@
361 # SetPopulation value = [[MIN_RECOLONIZING_SIZE]]
362 # ]
363 # '''
364
365 # #include "macros/advanced_focus.macros"
366 # #include "macros/focus.macros"
367 # #include "macros/general.macros"