UserAgent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.6) Gecko/20050403 
Galeon/1.3.20
IP: 128.83.113.38
URI: http://wesnoth.slack.it/?BranchOnVillageType
 - - - - -
Suppose you capture a village and want the logic of the resulting event to 
branch on the basis of of the village type.
At present there is no way to directly query for the village type, so here's a 
crude workaround. It just sets a variable
on the basis of what type of village it is, and then you can branch on the 
basis of that variable's value. Here I use
village_type for the variable to be set:

The logic is hacked from the predefined {STARTING_VILLAGES SIDE RADIUS}.

||Example of Use||

The macro assigns a value to village_type. Unfortunately we have to probe all 
the types to set it:

 # Set a default value for safety (e.g., if you forget to probe for one of the 
possible types)
 {VARIABLE village_type ordinary}
 # Now step through the known types, telling the macro what value you want 
stored for each type:
 {SET_VILLAGE_TYPE v  ordinary}
 {SET_VILLAGE_TYPE t  woods}
 {SET_VILLAGE_TYPE aA hill}      # notice the use of two types, 'a' and 'A'
 {SET_VILLAGE_TYPE b  mountain}
 {SET_VILLAGE_TYPE BU desert}
 {SET_VILLAGE_TYPE L  tropical}
 {SET_VILLAGE_TYPE V  snowy}
 {SET_VILLAGE_TYPE D  underground}
 {SET_VILLAGE_TYPE Y  swamp}
 {SET_VILLAGE_TYPE Z  water}

Now you have one of the values 'ordinary', 'woods', 'hill', etc. in the 
variable $village_type, and you can branch on it
with pseudo-case logic such as the macro shown at CaseBasedReasoningA.

||The Macro Definition||

 
#===============================================================================
 # Set the variable $village_type to VARIABLE_VALUE iff the village at $x1,$y1
 # matches one of the types in VILLAGE_CODES.
 #define SET_VILLAGE_TYPE VILLAGE_CODES VARIABLE_VALUE
    [store_locations]
       x,y=$x1,$y1 # x1 and y1 were defined by the event triggered when you 
captured the village
       radius=0    # don't want to catch any other villages
       variable=probe_village  # temporary where [store_locations] stores the 
village
       terrain={VILLAGE_CODES} # define village_type if-and-only-if the village 
is one of these types
    [/store_locations]
    {FOREACH probe_village i}
       # This won't execute if there are no villages in the list:
       {VARIABLE village_type {VARIABLE_VALUE}}
       {NEXT i}
    {CLEAR_VARIABLE probe_village}
    {CLEAR_VARIABLE i}
 #enddef

Alternatively, you could put your own logic directly into SET_VILLAGE_TYPE, 
where the variable is defined, and save the
extra case-based branching logic. The tradeoff is that you could then use the 
macro only for that one thing.

||See Also||

* CaseBasedReasoningA
* UsefulWMLFragments




_______________________________________________
Wesnoth-wiki-changes mailing list
[email protected]
http://lists.nongnu.org/mailman/listinfo/wesnoth-wiki-changes

Reply via email to