Skip to content

Commit

Permalink
utbs: use [object] for dehydration implementation
Browse files Browse the repository at this point in the history
this in particular makes it compatible the umc code that uses [remove_object]
It also makes the implementation a bit easier since we don't have to compute
things manually anymore, also duration=scenario takes care of cleanup at
scenario end.
  • Loading branch information
gfgtdf committed Aug 25, 2019
1 parent f4e7f41 commit a86df6c
Showing 1 changed file with 55 additions and 130 deletions.
185 changes: 55 additions & 130 deletions data/campaigns/Under_the_Burning_Suns/utils/dehydration-utils.cfg
Expand Up @@ -54,7 +54,6 @@ Hd, Dd*, Dd^E*, Rd #enddef
[for]
array=dehydrating_units
[do]
{VARIABLE dehydrating_units[$i].resting no}

[if]
[have_unit]
Expand All @@ -72,6 +71,7 @@ Hd, Dd*, Dd^E*, Rd #enddef
[/have_unit]

[then]
{VARIABLE dehydrating_units[$i].resting no}
{VARIABLE dehydrating_units[$i].status.dehydration_slowed_by_healer yes}

[unstore_unit]
Expand All @@ -81,65 +81,40 @@ Hd, Dd*, Dd^E*, Rd #enddef
[/then]

[else]
[for]
array=dehydrating_units[$i].attack
variable=j
[do]
# if dehydrating for the first time, store the original attack stats
[if]
[variable]
name=dehydrating_units[$i].status.dehydrated
not_equals=yes
[/variable]

[then]
{VARIABLE dehydrating_units[$i].variables.original_attack[$j].damage $dehydrating_units[$i].attack[$j].damage}
[/then]
[/if]

# the attack's damage drops by 1 point, but cannot drop to zero
[if]
[variable]
name=dehydrating_units[$i].attack[$j].damage
greater_than=1
[/variable]

[then]
{VARIABLE_OP dehydrating_units[$i].attack[$j].damage sub 1}
[/then]
[/if]
[/do]
[/for]

# unit’s hitpoints drop by $dehydration_loss, but cannot kill it
[if]
[variable]
name=dehydrating_units[$i].hitpoints
greater_than=$dehydration_loss
[/variable]

[then]
{VARIABLE_OP dehydrating_units[$i].hitpoints sub $dehydration_loss}
[/then]

[else]
{VARIABLE dehydrating_units[$i].hitpoints 1}
[/else]
[/if]

{VARIABLE dehydrating_units[$i].status.dehydrated yes}

[unstore_unit]
variable=dehydrating_units[$i]
find_vacant=no
[modify_unit]
[filter]
id=$dehydrating_units[$i].id
[/filter]
## this object might be obtained multiple times, but that shouldn't be a problem.
[object]
duration=scenario
id="dehydration_effect"
[effect]
apply_to=attack
formula="damage>1"
increase_damage=-1
[/effect]
[/object]
[object]
duration=scenario
id="dehydration_overlay"
[effect]
apply_to=overlay
add="misc/dehydration-icon.png"
[/effect]
[/object]
hitpoints="$(max(1, $dehydrating_units[$i].hitpoints - $dehydration_loss))"
resting=no
[status]
dehydrated=yes
[/status]
[/modify_unit]
[floating_text]
x=$dehydrating_units[$i].x
y=$dehydrating_units[$i].y
text= _ "thirst"
{COLOR_HARM}
[/unstore_unit]

[unit_overlay]
x,y=$dehydrating_units[$i].x,$dehydrating_units[$i].y
image=misc/dehydration-icon.png
[/unit_overlay]
[/floating_text]
[/else]
[/if]
[/do]
Expand Down Expand Up @@ -169,29 +144,32 @@ Hd, Dd*, Dd^E*, Rd #enddef
[/variable]

[then]
[for]
array=hydrating_units[$i].attack
variable=j
[do]
{VARIABLE hydrating_units[$i].attack[$j].damage $hydrating_units[$i].variables.original_attack[$j].damage}
[/do]
[/for]
[remove_object]
x,y=$hydrating_units[$i].x,$hydrating_units[$i].y
object_id=dehydration_effect
[/remove_object]
[/then]
[/if]

{VARIABLE hydrating_units[$i].status.dehydrated no}

[unstore_unit]
variable=hydrating_units[$i]
find_vacant=no
[modify_unit]
[filter]
id=$hydrating_units[$i].id
[/filter]
[status]
dehydrated=no
[/status]
[/modify_unit]
[floating_text]
x=$hydrating_units[$i].x
y=$hydrating_units[$i].y
text= _ "refreshed"
{COLOR_HEAL}
[/unstore_unit]
[/floating_text]

[remove_unit_overlay]
[remove_object]
x,y=$hydrating_units[$i].x,$hydrating_units[$i].y
image=misc/dehydration-icon.png
[/remove_unit_overlay]
object_id=dehydration_overlay
[/remove_object]
[/do]
[/for]

Expand Down Expand Up @@ -282,62 +260,9 @@ Hd, Dd*, Dd^E*, Rd #enddef
advance=no
[/unstore_unit]

[remove_unit_overlay]
[remove_object]
x,y=$unit.x,$unit.y
image=misc/dehydration-icon.png
[/remove_unit_overlay]
[/event]

[event]
name=victory

# Rehydrate all units for the next scenario
# Do this more quietly than usual...
[store_unit]
[filter]
side=1
[/filter]

kill=no
variable=hydrating_units
[/store_unit]

[for]
array=hydrating_units
[do]
[if]
[variable]
name=hydrating_units[$i].status.dehydrated
equals=yes
[/variable]

[then]
[for]
array=hydrating_units[$i].attack
variable=j
[do]
{VARIABLE hydrating_units[$i].attack[$j].damage $hydrating_units[$i].variables.original_attack[$j].damage}
[/do]
[/for]
[/then]
[/if]

{VARIABLE hydrating_units[$i].status.dehydrated no}

[unstore_unit]
variable=hydrating_units[$i]
find_vacant=no
[/unstore_unit]

[remove_unit_overlay]
id=$hydrating_units[$i].id
image=misc/dehydration-icon.png
[/remove_unit_overlay]
[/do]
[/for]

# Clear related variables
{CLEAR_VARIABLE hydrating_units}
{CLEAR_VARIABLE dehydration_loss}
object_id=dehydration_overlay
[/remove_object]
[/event]
#enddef

0 comments on commit a86df6c

Please sign in to comment.