Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [event]
- name=player hits blood core
- first_time_only=no
- {BUG_ON ({VARIABLE_NUMERICAL_NOT_EQUALS boss_stage 2}) ("Blood Core handler running not on boss stage 2 ($boss_stage|)")}
- #
- # Shuffle Blood Cores around whenever possible.
- #
- [store_unit]
- [filter]
- type=Blood Core
- [filter_location]
- find_in=core_locs
- [/filter_location]
- [/filter]
- variable=shuffle_stack
- kill=yes
- [/store_unit]
- #
- # This shuffling algorithm should work in every case regardless of the amount
- # of units stored. If there's a single unit stored, it is unstored back with
- # minimal overhead (*) below. If there are no units stored, the loop never
- # runs, and the bugcheck path is not hit.
- #
- {REVERSE_FOREACH shuffle_stack k}
- # k is the position of the primary unit to swap, set by the foreach cycle.
- # r is the position of teh secondary unit to swap, determined by the RNG.
- {VARIABLE r -1}
- [if]
- {VARIABLE_NUMERICAL_GREATER_THAN k 0}
- [then]
- {VARIABLE_RANDOM r "0..$($k - 1)"}
- {LOG_ATS_DBG ("SWAP: $k <-> $r <$shuffle_stack.length>")}
- {VARIABLE swap.x $shuffle_stack[$r].x}
- {VARIABLE swap.y $shuffle_stack[$r].y}
- {LOG_ATS_DBG ("SWAP: ($shuffle_stack[$k].x,$shuffle_stack[$k].y) <-> ($swap.x,$swap.y)")}
- {VARIABLE shuffle_stack[$r].x $shuffle_stack[$k].x}
- {VARIABLE shuffle_stack[$r].y $shuffle_stack[$k].y}
- {VARIABLE shuffle_stack[$k].x $swap.x}
- {VARIABLE shuffle_stack[$k].y $swap.y}
- {LOG_ATS_DBG ("SWAP: ($shuffle_stack[$r].x,$shuffle_stack[$r].y) ($shuffle_stack[$k].x,$shuffle_stack[$k].y)")}
- [unstore_unit]
- variable="shuffle_stack[$r]"
- find_vacant=yes
- check_passability=no
- [/unstore_unit]
- {CLEAR_VARIABLE swap}
- [/then]
- [/if]
- # (*)
- [unstore_unit]
- variable="shuffle_stack[$k]"
- find_vacant=yes
- [/unstore_unit]
- [if]
- {VARIABLE_NUMERICAL_GREATER_THAN r -1}
- [then]
- [floating_text]
- x=$shuffle_stack[$k].x,$shuffle_stack[$r].y
- y=$shuffle_stack[$k].y,$shuffle_stack[$r].y
- text="<span color='#FF7F00'>!</span>" # wmllint: ignore
- [/floating_text]
- {CLEAR_VARIABLE shuffle_stack[$r]}
- {VARIABLE_DEC k}
- [/then]
- [/if]
- {CLEAR_VARIABLE r,shuffle_stack[$k]}
- {REVERSE_NEXT k}
- # We shouldn't hit this unless the shuffling algorithm is broken.
- {BUG_ON ({VARIABLE_NUMERICAL_GREATER_THAN shuffle_stack.length 0}) ("Unit shuffling algorithm postcondition broken")}
- [/event]
Advertisement
Add Comment
Please, Sign In to add comment