Debian Codegraph @

default/scripting/species/species_macros/population.py

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