Author: esr
Date: Thu Nov  1 18:36:24 2007
New Revision: 21387

URL: http://svn.gna.org/viewcvs/wesnoth?rev=21387&view=rev
Log:
Add Zookeeper's nifty side-limit macros to the library.

Added:
    trunk/data/core/macros/sidelimit-utils.cfg

Added: trunk/data/core/macros/sidelimit-utils.cfg
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/data/core/macros/sidelimit-utils.cfg?rev=21387&view=auto
==============================================================================
--- trunk/data/core/macros/sidelimit-utils.cfg (added)
+++ trunk/data/core/macros/sidelimit-utils.cfg Thu Nov  1 18:36:24 2007
@@ -1,0 +1,162 @@
+# Side-limit macros for balancing AI behaviour. You can, for example
+# give an AI side the possibility to recruit high level units but not to have
+# too many of them at the same time.  Note: These generate events, so they need
+# to be placed directly under your [scenario] tag, and not within an event
+# such as start or prestart.
+
+#define LIMIT_CONTEMPORANEOUS_RECRUITS SIDE TYPE LIMIT
+    # Limit the number of units of a certain type a side can have
+    # simultaneously. When the number of units of type TYPE the side
+    # has reaches or exceeds LIMIT, that side is prevented from
+    # recruiting more until the number of units of that type drops
+    # below LIMIT again.
+    #
+    # Allow side 2 no more than 2 Troll Rocklobbers at a time
+    #! {LIMIT_CONTEMPORANEOUS_RECRUITS 2 (Troll Rocklobber) 2}
+    [event]
+        name=side turn
+        first_time_only=no
+
+        [if]
+            [variable]
+                name=side_number
+                equals={SIDE}
+            [/variable]
+
+            [then]
+                [store_unit]
+                    [filter]
+                        side={SIDE}
+                        type={TYPE}
+                    [/filter]
+
+                    kill=no
+                    variable=LIMIT_CONTEMPORANEOUS_RECRUITS_temp
+                [/store_unit]
+
+                [if]
+                    [variable]
+                        name=LIMIT_CONTEMPORANEOUS_RECRUITS_temp.length
+                        greater_than_equal_to={LIMIT}
+                    [/variable]
+
+                    [then]
+                        [disallow_recruit]
+                            side={SIDE}
+                            type={TYPE}
+                        [/disallow_recruit]
+                    [/then]
+
+                    [else]
+                        [allow_recruit]
+                            side={SIDE}
+                            type={TYPE}
+                        [/allow_recruit]
+                    [/else]
+                [/if]
+
+                {CLEAR_VARIABLE LIMIT_CONTEMPORANEOUS_RECRUITS_temp}
+            [/then]
+        [/if]
+    [/event]
+
+    [event]
+        name=recruit
+        first_time_only=no
+
+        [filter]
+            side={SIDE}
+            type={TYPE}
+        [/filter]
+
+        [store_unit]
+            [filter]
+                side={SIDE}
+                type={TYPE}
+            [/filter]
+
+            kill=no
+            variable=LIMIT_CONTEMPORANEOUS_RECRUITS_temp
+        [/store_unit]
+
+        [if]
+            [variable]
+                name=LIMIT_CONTEMPORANEOUS_RECRUITS_temp.length
+                greater_than_equal_to={LIMIT}
+            [/variable]
+
+            [then]
+                [disallow_recruit]
+                    side={SIDE}
+                    type={TYPE}
+                [/disallow_recruit]
+            [/then]
+        [/if]
+
+        {CLEAR_VARIABLE LIMIT_CONTEMPORANEOUS_RECRUITS_temp}
+    [/event]
+#enddef
+
+#define LIMIT_RECRUITS SIDE TYPE LIMIT
+    # Limit the total number of units of a given type a given side
+    # can recruit in the scenario.
+    #
+    # Allow side 2 no more than 1 Draug in the entire scenario
+    #! {LIMIT_RECRUITS 2 (Draug) 1}
+    [event]
+        name=prestart
+
+        {VARIABLE side_{SIDE}_limited_recruits_length -1}
+    [/event]
+
+    [event]
+        name=recruit
+        first_time_only=yes
+
+        [filter]
+            side={SIDE}
+            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}
+    [/event]
+
+    [event]
+        name=recruit
+        first_time_only=no
+
+        [filter]
+            side={SIDE}
+            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}
+
+        {FOREACH side_{SIDE}_limited_recruits i}
+        [if]
+            [variable]
+                name=side_{SIDE}_limited_recruits[$i].type
+                equals={TYPE}
+            [/variable]
+
+            [variable]
+                name=side_{SIDE}_limited_recruits[$i].recruited
+                equals={LIMIT}
+            [/variable]
+
+            [then]
+                [disallow_recruit]
+                    side={SIDE}
+                    type={TYPE}
+                [/disallow_recruit]
+            [/then]
+        [/if]
+        {NEXT i}
+    [/event]
+#enddef


_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits

Reply via email to