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