UtBS S2: Rewrite ghosts placement event

Just shortens the code, splits ghosts appearence and
disappearence into two different events and renames a
variable in order to make its purpose clearer
This commit is contained in:
DisherProject 2019-03-04 12:20:23 +01:00
parent 83a06bc106
commit b345123921

View file

@ -330,6 +330,7 @@
# setup ghost difficulty
{VARIABLE max_ghosts {ON_DIFFICULTY 6 7 8} }
{VARIABLE ghosts_to_kill "$(ceil($($max_ghosts / 3.0)))"}
[/event]
# Special Encounter events
@ -1680,7 +1681,7 @@
{CLEAR_VARIABLE ghosts_already_spawned}
{CLEAR_VARIABLE ghosts_killed}
{CLEAR_VARIABLE max_ghosts}
{CLEAR_VARIABLE to_kill}
{CLEAR_VARIABLE ghosts_to_kill}
[/event]
#time over defeat event
@ -1701,158 +1702,119 @@
# spawn a number of ghosts each turn depending on how "exposed"
# the player units are. Only units in the middle of the desert attract
# ghosts.
# LOST SOUL DISAPPEARANCE at first daylight
[event]
name=new turn
first_time_only=no
{VARIABLE turn_temp $turn_number}
{VARIABLE_OP turn_temp modulo 15}
# LOST SOUL DISAPPEARANCE at first daylight
[if]
[variable]
name=turn_temp
numerical_equals=1
[/variable]
[or]
[variable]
name=turn_temp
numerical_equals=7
[/variable]
[/or]
[then]
# reset the ghosts' counters
{VARIABLE ghosts_already_spawned 0}
{VARIABLE ghosts_killed 0}
[kill]
role=LostSoul
animate=no
fire_event=no
[/kill]
[/then]
[/if]
[if]
[filter_condition]
[have_location]
time_of_day_id=dawn1,dawn2
[/have_location]
[/filter_condition]
# reset the ghosts' counters
{VARIABLE ghosts_already_spawned 0}
{VARIABLE ghosts_killed 0}
[kill]
role=LostSoul
animate=no
fire_event=no
[/kill]
[/event]
[event]
name=new turn
first_time_only=no
[filter_condition]
[have_location]
time_of_day_id=dusk1,dusk2
[or]
time_of_day=chaotic
[/or]
[/have_location]
[variable]
name=ghosts_already_spawned
less_than=$max_ghosts
[/variable]
[/filter_condition]
# store "exposed" units - those surrounded by a lot of desert
[store_locations]
variable=ghost_spawn_locs
[filter]
side=1
[/filter]
terrain=Hd, Dd, Rr
[filter_adjacent_location]
count="5,6"
adjacent="n,ne,se,s,sw,nw"
terrain=Hd, Dd, Rr
[/filter_adjacent_location]
[/store_locations]
[if]
[variable]
name=turn_temp
not_equals=1
[/variable]
[variable]
name=turn_temp
not_equals=7
name=ghost_spawn_locs.length
greater_than=0
[/variable]
[then]
# store "exposed" units - those surrounded by a lot of desert
# 1 ghost per 4/3/2 exposed units (roughly) per turn
{VARIABLE ghosts_per_unit "$($ghost_spawn_locs.length / {ON_DIFFICULTY 4 3 2})"}
# spawn more rapidly as time goes by
{VARIABLE ghosts_per_turn "$(($turn_number / 21) + {ON_DIFFICULTY 1 2 3})"}
{VARIABLE ghost_limit "$($max_ghosts - $ghosts_already_spawned)"}
{VARIABLE ghosts "$(min([$ghosts_per_unit, $ghosts_per_turn, $ghost_limit]))"}
{CLEAR_VARIABLE ghosts_per_unit,ghosts_per_turn,ghost_limit}
# store all possible spawn locations in range
# pick one random ghost_spawn from which
# to store all locations in range
{RANDOM "0..$($ghost_spawn_locs.length - 1)"}
[store_locations]
variable=ghost_spawn
[filter]
side=1
[/filter]
[not]
time_of_day=lawful
[/not]
variable=spawn
x=$ghost_spawn_locs[$random].x
y=$ghost_spawn_locs[$random].y
radius=8
terrain=Hd, Dd, Rr
[filter_adjacent_location]
count="5,6"
adjacent="n,ne,se,s,sw,nw"
terrain=Hd, Dd, Rr
[filter]
side=1
[/filter]
[/filter_adjacent_location]
[/store_locations]
{VARIABLE ghosts $ghost_spawn.length}
{CLEAR_VARIABLE ghost_spawn_locs}
[if]
[variable]
name=ghosts
greater_than=0
[/variable]
[then]
# spawn more rapidly as time goes by
{VARIABLE ghosts_per_turn $turn_number}
{VARIABLE_OP ghosts_per_turn divide 21}
{VARIABLE_OP ghosts_per_turn add {ON_DIFFICULTY 1 2 3}}
[repeat]
times=$ghosts
# 1 ghost per 4/3/2 exposed units (roughly) per turn
{VARIABLE_OP ghosts divide {ON_DIFFICULTY 4 3 2}}
[do]
{RANDOM "0..$($spawn.length - 1)"}
# limit ghost appearance rate
[if]
[variable]
name=ghosts
greater_than=$ghosts_per_turn
[/variable]
[then]
{VARIABLE ghosts $ghosts_per_turn}
[/then]
[/if]
{CLEAR_VARIABLE ghosts_per_turn}
# deduct already spawned ghosts - whether still alive or not
{VARIABLE ghost_limit $max_ghosts}
{VARIABLE_OP ghost_limit sub $ghosts_already_spawned}
[if]
[variable]
name=ghosts
greater_than=$ghost_limit
[/variable]
[then]
{VARIABLE ghosts $ghost_limit}
[/then]
[/if]
{CLEAR_VARIABLE ghost_limit}
# wmlindent: start ignoring
{NAMED_UNIT 4 "Ghost" $spawn[$random].x $spawn[$random].y () ( _ "Lost Soul") (
animate=yes
role="LostSoul")}
# wmlindent: stop ignoring
# store all possible spawn locations in range
# pick one random ghost_spawn from which
# to store all locations in range
{RANDOM 1..$ghost_spawn.length}
{VARIABLE_OP random sub 1}
[store_locations]
variable=spawn
x=$ghost_spawn[$random].x
y=$ghost_spawn[$random].y
radius=8
terrain=Hd, Dd, Rr
[filter_adjacent_location]
[filter]
side=1
[/filter]
[/filter_adjacent_location]
[/store_locations]
{VARIABLE_OP ghosts_already_spawned add 1}
[/do]
[/repeat]
{CLEAR_VARIABLE ghost_spawn}
{CLEAR_VARIABLE spawn,random}
[while]
[variable]
name=ghosts
greater_than=0
[/variable]
[do]
{RANDOM 1..$spawn.length}
{VARIABLE_OP random sub 1}
# wmlindent: start ignoring
{NAMED_UNIT 4 "Ghost" $spawn[$random].x $spawn[$random].y () ( _ "Lost Soul") (
animate=yes
role="LostSoul")}
# wmlindent: stop ignoring
{VARIABLE_OP ghosts_already_spawned add 1}
[set_variable]
name=ghosts
sub=1
[/set_variable]
[/do]
[/while]
{CLEAR_VARIABLE spawn}
# some ghosts dialogue
[fire_event]
name=ghosts_talk
[/fire_event]
[/then]
[/if]
# some ghosts dialogue
[fire_event]
name=ghosts_talk
[/fire_event]
[/then]
[/if]
{CLEAR_VARIABLE turn_temp}
[/event]
[event]
@ -1879,21 +1841,14 @@
role=LostSoul
[/filter]
{VARIABLE to_kill $max_ghosts}
{VARIABLE_OP to_kill divide 3}
{VARIABLE_OP to_kill round ceil}
[if]
[variable]
name=ghosts_killed
numerical_not_equals=$to_kill
numerical_not_equals=$ghosts_to_kill
[/variable]
[then]
[set_variable]
name=ghosts_killed
add=1
[/set_variable]
{VARIABLE_OP ghosts_killed add 1}
[/then]
[else]