Moved the SCATTER_UNITS macro to core.

This commit is contained in:
Lari Nieminen 2008-10-30 13:54:38 +00:00
parent dc36208145
commit 1eecbeb8e9
2 changed files with 96 additions and 65 deletions

View file

@ -197,68 +197,3 @@
type={LIST_VALUE}
[/allow_recruit]
#enddef
#define SCATTER_UNITS NUMBER TYPES PADDING_RADIUS SLF UNIT
[store_locations]
{SLF}
variable=possible_unit_locations
[/store_locations]
[set_variables]
name=unit_type_table
[split]
list={TYPES}
key=type
separator=,
[/split]
[/set_variables]
{VARIABLE unit_type_table_i 0}
{VARIABLE units_to_place {NUMBER}}
[while]
[variable]
name=units_to_place
greater_than=0
[/variable]
[do]
{RANDOM 1..$possible_unit_locations.length}
{VARIABLE_OP random add -1}
[unit]
type=$unit_type_table[$unit_type_table_i].type
x,y=$possible_unit_locations[$random].x,$possible_unit_locations[$random].y
{UNIT}
[/unit]
[store_locations]
find_in=possible_unit_locations
[not]
x,y=$possible_unit_locations[$random].x,$possible_unit_locations[$random].y
radius={PADDING_RADIUS}
[/not]
variable=possible_unit_locations
[/store_locations]
{VARIABLE_OP unit_type_table_i add 1}
[if]
[variable]
name=unit_type_table_i
numerical_equals=$unit_type_table.length
[/variable]
[then]
{VARIABLE unit_type_table_i 0}
[/then]
[/if]
{VARIABLE_OP units_to_place add -1}
[/do]
[/while]
{CLEAR_VARIABLE unit_type_table,unit_type_table_i,possible_unit_locations}
#enddef

View file

@ -628,3 +628,99 @@
[/if]
[/event]
#enddef
#define SCATTER_UNITS NUMBER TYPES PADDING_RADIUS SLF UNIT
# Scatters the given kind of units randomly on a given area on the map.
#
# An example which scatters some loyal elves on forest hexes in
# x,y=10-30,20-40, at a minimum of three hexes apart from each other and
# never on top of or adjacent to any already existing units:
#! {SCATTER_UNITS 20 "Elvish Fighter,Elvish Archer,Elvish Shaman" 3 (
#! terrain=Gs^Fp
#! x=10-30
#! y=20-40
#!
#! [not]
#! [filter]
#! [/filter]
#! [/not]
#!
#! [not]
#! [filter_adjacent_location]
#! [filter]
#! [/filter]
#! [/filter_adjacent_location]
#! [/not]
#! ) (
#! side=2
#! generate_name=yes
#! random_traits=yes
#!
#! [modifications]
#! {TRAIT_LOYAL}
#! [/modifications]
#! )}
[store_locations]
{SLF}
variable=possible_unit_locations
[/store_locations]
[set_variables]
name=unit_type_table
[split]
list={TYPES}
key=type
separator=,
[/split]
[/set_variables]
{VARIABLE unit_type_table_i 0}
{VARIABLE units_to_place {NUMBER}}
[while]
[variable]
name=units_to_place
greater_than=0
[/variable]
[do]
{RANDOM 1..$possible_unit_locations.length}
{VARIABLE_OP random add -1}
[unit]
type=$unit_type_table[$unit_type_table_i].type
x,y=$possible_unit_locations[$random].x,$possible_unit_locations[$random].y
{UNIT}
[/unit]
[store_locations]
find_in=possible_unit_locations
[not]
x,y=$possible_unit_locations[$random].x,$possible_unit_locations[$random].y
radius={PADDING_RADIUS}
[/not]
variable=possible_unit_locations
[/store_locations]
{VARIABLE_OP unit_type_table_i add 1}
[if]
[variable]
name=unit_type_table_i
numerical_equals=$unit_type_table.length
[/variable]
[then]
{VARIABLE unit_type_table_i 0}
[/then]
[/if]
{VARIABLE_OP units_to_place add -1}
[/do]
[/while]
{CLEAR_VARIABLE unit_type_table,unit_type_table_i,possible_unit_locations}
#enddef