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/?CaseBasedReasoningA
 - - - - -
Use this to make deeply nested if-then-else logic look slightly more like a 
case statement. (If you can figure out a way
to get rid of all the CLOSEs, replace this code with yours!)

||Example of Use||

The unit drinks an unidentified potion, and it's effect is...
 {RANDOM 
Strength,Agility,Haste,Experience,Health,Nightstealth,Sloth,Poison,Petrification}
 {IF_RANDOM_EQ Strength}
    {QUAFF_POTION_OF_STRENGTH {LEVEL}}
 {ELSE_IF_RANDOM_EQ Agility}
    {QUAFF_POTION_OF_AGILITY {LEVEL}}
 {ELSE_IF_RANDOM_EQ Haste}
    {QUAFF_POTION_OF_HASTE {LEVEL}}
 {ELSE_IF_RANDOM_EQ Experience}
    {QUAFF_POTION_OF_EXPERIENCE {LEVEL}}
 {ELSE_IF_RANDOM_EQ Health}
    {QUAFF_POTION_OF_HEALTH {LEVEL}}
 {ELSE_IF_RANDOM_EQ Nightstealth}
    {QUAFF_POTION_OF_NIGHTSTEALTH {LEVEL}}
 {ELSE_IF_RANDOM_EQ Sloth}
    {QUAFF_POTION_OF_SLOTH {LEVEL}}
 {ELSE_IF_RANDOM_EQ Poison}
    {QUAFF_POISON {LEVEL}}
 {ELSE_IF_RANDOM_EQ Petrification}
    {QUAFF_POTION_OF_PETRIFICATION {LEVEL}}
 [/then] # I suppose you could use a macro here, but it's only
 [/if]   # two lines, no matter how many cases you have.
 {CLOSE_ELSE_IF}
 {CLOSE_ELSE_IF}
 {CLOSE_ELSE_IF}
 {CLOSE_ELSE_IF}
 {CLOSE_ELSE_IF}
 {CLOSE_ELSE_IF}
 {CLOSE_ELSE_IF}
 {CLOSE_ELSE_IF}

This could have been named CASE or such, but contrast its logic with 
CaseBasedReasoningB.

||The Macro Definitions||

 
#===============================================================================
 # Macros to make deep-nested if statements clearer:
 
#-------------------------------------------------------------------------------
 # For testing equal-to:
 #define IF_RANDOM_EQ VALUE
    [if]
       [variable]
          name=random
          equals={VALUE}
       [/variable]
    [then]
 #enddef
 #define ELSE_IF_RANDOM_EQ VALUE
    [/then]
    [else]
    [if]
       [variable]
          name=random
          equals={VALUE}
       [/variable]
    [then]
 #enddef
 
#-------------------------------------------------------------------------------
 #define CLOSE_ELSE_IF
    [/else]
    [/if]
 #enddef

N.B. - The CLOSE_ELSE_IF macro is also used in the macros for 
CaseBasedReasoningB, so if you use them both you don't
want to define it twice.

||See Also||

* CaseBasedReasoningB
* UsefulWMLFragments




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

Reply via email to