home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 July / maximum-cd-2010-07.iso / DiscContents / wesnoth-1.8-win32.exe / data / core / macros / side-utils.cfg < prev    next >
Encoding:
Text File  |  2009-09-28  |  10.5 KB  |  351 lines

  1. #textdomain wesnoth
  2.  
  3. # Side-utils macros for balancing AI behaviour and setting village ownership.
  4. # You can, for example give an AI side the possibility to recruit high
  5. # level units but not to have too many of them at the same time.
  6.  
  7. # Note: These generate events, so they need to be placed directly
  8. # under your [scenario] tag, and not within an event such as start or
  9. # prestart.
  10.  
  11. #define LIMIT_CONTEMPORANEOUS_RECRUITS SIDE TYPE LIMIT_NUMBER
  12.     # Limit the number of units passing a specified filter that a side
  13.     # can have simultaneously. When the number of matching units
  14.     # side has reaches or exceeds LIMIT_NUMBER, that side is prevented from
  15.     # recruiting more until the number of units of that type drops
  16.     # below LIMIT_NUMBER again.
  17.     #
  18.     # Allow side 2 no more than 2 Troll Rocklobbers at a time
  19.     #! {LIMIT_CONTEMPORANEOUS_RECRUITS 2 "Troll Rocklobber" 2}
  20.     [event]
  21.         name=side turn
  22.         first_time_only=no
  23.  
  24.         {VARIABLE LCR_temp {SIDE}}
  25.  
  26.         [if]
  27.             [variable]
  28.                 name=LCR_temp
  29.                 contains=$side_number
  30.             [/variable]
  31.  
  32.             [then]
  33.                 [if]
  34.                     [have_unit]
  35.                         side=$side_number
  36.                         type={TYPE}
  37.                         count="{LIMIT_NUMBER}-99999"
  38.                     [/have_unit]
  39.  
  40.                     [then]
  41.                         [disallow_recruit]
  42.                             side=$side_number
  43.                             type={TYPE}
  44.                         [/disallow_recruit]
  45.                     [/then]
  46.  
  47.                     [else]
  48.                         [allow_recruit]
  49.                             side=$side_number
  50.                             type={TYPE}
  51.                         [/allow_recruit]
  52.                     [/else]
  53.                 [/if]
  54.             [/then]
  55.         [/if]
  56.  
  57.         {CLEAR_VARIABLE LCR_temp}
  58.     [/event]
  59.  
  60.     [event]
  61.         name=recruit
  62.         first_time_only=no
  63.  
  64.         [filter]
  65.             side={SIDE}
  66.             type={TYPE}
  67.         [/filter]
  68.  
  69.         [if]
  70.             [have_unit]
  71.                 side=$side_number
  72.                 type={TYPE}
  73.                 count="{LIMIT_NUMBER}-99999"
  74.             [/have_unit]
  75.  
  76.             [then]
  77.                 [disallow_recruit]
  78.                     side=$side_number
  79.                     type={TYPE}
  80.                 [/disallow_recruit]
  81.             [/then]
  82.         [/if]
  83.     [/event]
  84. #enddef
  85.  
  86. #define LIMIT_RECRUITS SIDE TYPE LIMIT_NUMBER
  87.     # Limit the total number of units passing a specified filter that a given
  88.     # side can recruit in the scenario.
  89.     #
  90.     # Allow side 2 no more than 1 Draug in the entire scenario
  91.     #! {LIMIT_RECRUITS 2 Draug 1}
  92.  
  93.     [event]
  94.         name=prestart
  95.  
  96.         # the array holding the recruit-limited types is cleared here, because
  97.         # it could hold values carried over from the previous scenario
  98.  
  99.         {CLEAR_VARIABLE side_{SIDE}_limited_recruits}
  100.  
  101.         {VARIABLE side_{SIDE}_limited_recruits_length -1}
  102.     [/event]
  103.  
  104.     # when the side recruits this given type for the first time, it's recorded
  105.     # in an array that holds info on all the recruit-limited types for this side
  106.  
  107.     [event]
  108.         name=recruit
  109.         first_time_only=yes
  110.  
  111.         [filter]
  112.             side={SIDE}
  113.             type={TYPE}
  114.         [/filter]
  115.  
  116.         {VARIABLE_OP side_{SIDE}_limited_recruits_length add 1}
  117.  
  118.         {VARIABLE side_{SIDE}_limited_recruits[$side_{SIDE}_limited_recruits_length|].type $unit.type}
  119.     [/event]
  120.  
  121.     # and every time when the side recruits this given type, we increment a
  122.     # counter, and if it matches or exceeds the limit, we disallow recruiting
  123.     # more of those units
  124.  
  125.     [event]
  126.         name=recruit
  127.         first_time_only=no
  128.  
  129.         [filter]
  130.             side={SIDE}
  131.             type={TYPE}
  132.         [/filter]
  133.  
  134.         {FOREACH side_{SIDE}_limited_recruits i}
  135.             [if]
  136.                 [variable]
  137.                     name=side_{SIDE}_limited_recruits[$i].type
  138.                     equals=$unit.type
  139.                 [/variable]
  140.  
  141.                 [then]
  142.                     {VARIABLE_OP side_{SIDE}_limited_recruits[$i].number_recruited add 1}
  143.                     [if]
  144.                         [variable]
  145.                             name=side_{SIDE}_limited_recruits[$i].number_recruited
  146.                             greater_than_equal_to={LIMIT_NUMBER}
  147.                         [/variable]
  148.  
  149.                         [then]
  150.                             [disallow_recruit]
  151.                                 side={SIDE}
  152.                                 type={TYPE}
  153.                             [/disallow_recruit]
  154.                         [/then]
  155.                     [/if]
  156.                 [/then]
  157.             [/if]
  158.         {NEXT i}
  159.     [/event]
  160. #enddef
  161.  
  162. #define CAPTURE_FILTERED_VILLAGES SIDE FILTER
  163.     # Change ownership of villages matching the specified location filter.
  164.     [store_locations]
  165.         {FILTER}
  166.         variable=temp_target_villages
  167.     [/store_locations]
  168.  
  169.     {FOREACH temp_target_villages i}
  170.         [capture_village]
  171.             side={SIDE}
  172.             x,y=$temp_target_villages[$i].x,$temp_target_villages[$i].y
  173.         [/capture_village]
  174.     {NEXT i}
  175.  
  176.     {CLEAR_VARIABLE temp_target_villages}
  177. #enddef
  178.  
  179. #define CAPTURE_VILLAGES_OF_TYPE TERRAIN SIDE X Y RADIUS
  180.     # Change ownership of the villages on a specified terrain type
  181.     # near a specified location.
  182.     {CAPTURE_FILTERED_VILLAGES {SIDE}
  183.     (
  184.         terrain={TERRAIN}
  185.         [and]
  186.             x,y={X},{Y}
  187.             radius={RADIUS}
  188.         [/and] ) }
  189. #enddef
  190.  
  191. #define CAPTURE_VILLAGES SIDE X Y RADIUS
  192.     # Change ownership of all villages near a specified location.
  193.     {CAPTURE_VILLAGES_OF_TYPE (*^V*) {SIDE} {X} {Y} {RADIUS}}
  194. #enddef
  195.  
  196. #define STARTING_VILLAGES SIDE RADIUS
  197.     # Macro to make a side start a scenario with villages.
  198.     # Creates an event, so it must be called from within the
  199.     # toplevel scenario tag.  Also note that this relies on the
  200.     # side having a unit with canrecruit-yes at start; if it
  201.     # doesn't, you should use STARTING_VILLAGES_AREA instead.
  202.     [event]
  203.         name=prestart
  204.  
  205.         [store_starting_location]
  206.             side={SIDE}
  207.             variable=temp_starting_location
  208.         [/store_starting_location]
  209.  
  210.         {CAPTURE_VILLAGES {SIDE} $temp_starting_location.x $temp_starting_location.y {RADIUS}}
  211.         {CLEAR_VARIABLE temp_starting_location}
  212.     [/event]
  213. #enddef
  214.  
  215. #define STARTING_VILLAGES_AREA SIDE X Y RADIUS
  216.     # Make a side start with ownership of villages in a given area.
  217.     # Creates an event, so it must be called from within the
  218.     # toplevel scenario tag.
  219.     [event]
  220.         name=prestart
  221.  
  222.         {CAPTURE_VILLAGES {SIDE} {X} {Y} {RADIUS}}
  223.     [/event]
  224. #enddef
  225.  
  226. #define STARTING_VILLAGES_ALL SIDE
  227.     # Make a side start with ownership of all villages.
  228.     # Creates an event, so it must be called from within the
  229.     # toplevel scenario tag.
  230.     [event]
  231.         name=prestart
  232.  
  233.         {CAPTURE_FILTERED_VILLAGES {SIDE} (terrain=*^V*)}
  234.     [/event]
  235. #enddef
  236.  
  237. #define TRANSFER_VILLAGE_OWNERSHIP FROM_SIDE TO_SIDE
  238.     # Transfers ownership of all villages of one side to another side. Useful
  239.     # when you're for example moving all units of some side to another, and want
  240.     # to transfer the village ownership as well.
  241.     [store_villages]
  242.         owner_side={FROM_SIDE}
  243.         variable=TRANSFER_VILLAGE_OWNERSHIP_villages
  244.     [/store_villages]
  245.  
  246.     {FOREACH TRANSFER_VILLAGE_OWNERSHIP_villages TRANSFER_VILLAGE_OWNERSHIP_i}
  247.         [capture_village]
  248.             x,y=$TRANSFER_VILLAGE_OWNERSHIP_villages[$TRANSFER_VILLAGE_OWNERSHIP_i].x,$TRANSFER_VILLAGE_OWNERSHIP_villages[$TRANSFER_VILLAGE_OWNERSHIP_i].y
  249.             side={TO_SIDE}
  250.         [/capture_village]
  251.     {NEXT TRANSFER_VILLAGE_OWNERSHIP_i}
  252.  
  253.     {CLEAR_VARIABLE TRANSFER_VILLAGE_OWNERSHIP_villages}
  254. #enddef
  255.  
  256. # Persistant macros
  257.  
  258. #define MAKE_AI_SIDE_PERSISTENT SIDE
  259.     #Macro to make a ai controlled side persistent.
  260.     #Needs to be placed below the side definition.
  261.     [+side]
  262.         controller=human
  263.         persistent=yes
  264.     [/side]
  265.  
  266.     [event]
  267.         name=prestart
  268.         [modify_side]
  269.             side={SIDE}
  270.             controller=ai
  271.         [/modify_side]
  272.     [/event]
  273.     [event]
  274.         name=victory
  275.         [modify_side]
  276.             side={SIDE}
  277.             controller=human
  278.         [/modify_side]
  279.     [/event]
  280. #enddef
  281.  
  282. #define RECALL_AI_SIDE SIDE
  283.     #Recalls an ai side that is persistent (MAKE_AI_SIDE_PERSISTENT)
  284.     #Needs to be placed below the side definition.
  285.     {MAKE_AI_SIDE_PERSISTENT {SIDE}}
  286.     [event]
  287.         name=prestart
  288.  
  289.         [store_unit]
  290.             variable=recall_ai_side_units_{SIDE}
  291.             [filter]
  292.                 side={SIDE}
  293.             [/filter]
  294.         [/store_unit]
  295.     [/event]
  296.     [event]
  297.         name=victory
  298.         {CLEAR_VARIABLE recall_ai_side_units_{SIDE}}
  299.     [/event]
  300.     [event]
  301.         name=ai turn
  302.  
  303.         [if]
  304.             [variable]
  305.                 name=side_number
  306.                 equals={SIDE}
  307.             [/variable]
  308.             [and]
  309.                 [have_unit]
  310.                     canrecruit=yes
  311.                     side={SIDE}
  312.                     [filter_location]
  313.                         terrain=K*
  314.                     [/filter_location]
  315.                 [/have_unit]
  316.             [/and]
  317.  
  318.             [then]
  319.                 [store_gold]
  320.                     side={SIDE}
  321.                 [/store_gold]
  322.  
  323.                 [while]
  324.                     [variable]
  325.                         name=gold
  326.                         greater_than=19
  327.                     [/variable]
  328.                     [variable]
  329.                         name=recall_ai_side_units_{SIDE}.length
  330.                         greater_than=0
  331.                     [/variable]
  332.                     [do]
  333.                         [gold]
  334.                             side=2
  335.                             amount=-20
  336.                         [/gold]
  337.                         [store_gold]
  338.                             side={SIDE}
  339.                         [/store_gold]
  340.                         [recall]
  341.                             id=$recall_ai_side_units_{SIDE}[0].id
  342.                         [/recall]
  343.                         {CLEAR_VARIABLE recall_ai_side_units_{SIDE}[0]}
  344.                     [/do]
  345.                 [/while]
  346.                 {CLEAR_VARIABLE gold}
  347.             [/then]
  348.         [/if]
  349.     [/event]
  350. #enddef
  351.