An effect that changes icons

From The Battle for Wesnoth Wiki
Revision as of 18:41, 26 March 2012 by Dugi (talk | contribs) (Created page with '== An effect that changes icons == Want to make this work? [object] name= _ "Flaming Sword" image=items/flame-sword.png description= _ "This sword …')
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

An effect that changes icons

Want to make this work?

    [object]
       name= _ "Flaming Sword"
        image=items/flame-sword.png
        description= _ "This sword deals 50% more damage than other swords and deals fire damage."
		   [effect]
			apply_to=attack
			name=sword
			set_type=fire
			increase_damage=50%
			set_icon=attacks/sword-flaming.png
		   [/effect]
    [/object]

Place this macro after that the unit takes the object, and also in a global post advance event (in all scenarios, for all units who might have their attack icons altered).

#define UPDATE_ICONS
#It searches through all the effects of all the items, looking for a set_icon tag.
#When it finds one, it finds all attacks with the same name as the name that the
#attack affects, and changes their icons. This works only until the next advancement,
#then it has to be reapplied. It might check for other properties of the attack filter
#of the unit, just needs a little bit of tweaking.
[store_unit]
	[filter]
		x,y=$x1,$y1
	[/filter]
	variable=advanced
	kill=no
[/store_unit]
   {FOREACH advanced.modifications.object i}
   {FOREACH advanced.modifications.object[$i].effect j}
	[if]
		[variable]
			name=advanced.modifications.object[$i].effect[$j].set_icon
			contains="png"
		[/variable]
		[then]
			{VARIABLE attack_name $advanced.modifications.object[$i].effect[$j].name}
		        {FOREACH advanced.attack k}
			[if]
				[variable]
					name=advanced.attack[$k].name
					equals=$attack_name
				[/variable]
				[then]
					{VARIABLE advanced.attack[$k].icon $advanced.modifications.object[$i].effect[$j].set_icon}
				[/then]
			[/if]
		        {NEXT k}
		[/then]
	[/if]
   {NEXT j}
   {NEXT i}
    [unstore_unit]
       variable=advanced
	find_vacant=no
   [/unstore_unit]
{CLEAR_VARIABLE advanced}
#enddef