Revise and fix LIMIT_RECRUITS.

This commit is contained in:
Lari Nieminen 2008-01-29 11:02:54 +00:00
parent af0bdd6c0d
commit 19d42b9914

View file

@ -98,61 +98,71 @@
[/event]
#enddef
#define LIMIT_RECRUITS SIDE FILTER LIMIT
#define LIMIT_RECRUITS SIDE TYPE LIMIT
# Limit the total number of units passing a specified filter that a given
# side can recruit in the scenario.
#
# Allow side 2 no more than 1 Draug in the entire scenario
#! {LIMIT_RECRUITS 2 type=Draug 1}
[+variables]
side_{SIDE}_limited_recruits_length=-1
[/variables]
#! {LIMIT_RECRUITS 2 Draug 1}
[event]
name=prestart
# the array holding the recruit-limited types is cleared here, because
# it could hold values carried over from the previous scenario
{CLEAR_VARIABLE side_{SIDE}_limited_recruits}
{VARIABLE side_{SIDE}_limited_recruits_length -1}
[/event]
# when the side recruits this given type for the first time, it's recorded
# in an array that holds info on all the recruit-limited types for this side
[event]
name=recruit
first_time_only=yes
[filter]
side={SIDE}
{FILTER}
type={TYPE}
[/filter]
{VARIABLE_OP side_{SIDE}_limited_recruits_length add 1}
{VARIABLE_OP LIMIT_RECRUITS_temp1 format "side_{SIDE}_limited_recruits[$side_{SIDE}_limited_recruits_length|].type"}
{VARIABLE $LIMIT_RECRUITS_temp1 {TYPE}}
{CLEAR_VARIABLE LIMIT_RECRUITS_temp1}
{VARIABLE side_{SIDE}_limited_recruits[$side_{SIDE}_limited_recruits_length|].type $unit.type}
[/event]
# and every time when the side recruits this given type, we increment a
# counter, and if it matches or exceeds the limit, we disallow recruiting
# more of those units
[event]
name=recruit
first_time_only=no
[filter]
side={SIDE}
{FILTER}
type={TYPE}
[/filter]
{VARIABLE_OP LIMIT_RECRUITS_temp2 format "side_{SIDE}_limited_recruits[$side_{SIDE}_limited_recruits_length|].recruited"}
{VARIABLE_OP $LIMIT_RECRUITS_temp2 add 1}
{CLEAR_VARIABLE LIMIT_RECRUITS_temp2}
{VARIABLE_OP side_{SIDE}_limited_recruits[$side_{SIDE}_limited_recruits_length|].number_recruited add 1}
{FOREACH side_{SIDE}_limited_recruits i}
[if]
[variable]
name=side_{SIDE}_limited_recruits[$i].type
equals={TYPE}
equals=$unit.type
[/variable]
[variable]
name=side_{SIDE}_limited_recruits[$i].recruited
equals={LIMIT}
name=side_{SIDE}_limited_recruits[$i].number_recruited
greater_than_equal_to={LIMIT}
[/variable]
[then]
[disallow_recruit]
side={SIDE}
{FILTER}
type={TYPE}
[/disallow_recruit]
[/then]
[/if]