A bit of de-bugging

The place to post your WML questions and answers.

Moderators: Forum Moderators, Developers

Forum rules
  • Please use [code] BBCode tags in your posts for embedding WML snippets.
  • To keep your code readable so that others can easily help you, make sure to indent it following our conventions.
Post Reply
User avatar
Casual User
Posts: 475
Joined: March 11th, 2005, 5:05 pm

A bit of de-bugging

Post by Casual User » September 13th, 2007, 5:16 am

As I mentionned in an earlier thread, I have for some time been looking for a way to make an unit that deals double damage on attack and takes double damage from units of equal or higher level.

[filter_opponent] failed miserably to do the task, so I turned to a hack which, while workable, is buggy.

Basic principle

For each unit, there are in fact two distinct units defined: one which has a reverse-leadership, making all adjacent ennemies of lower level deal only half the damage; and one which simply doesn't.

Typically, no unit has the ability. When selecting an unit, it is changed into the unit with the ability activated. If you attack, charge + the ability give the wanted result. When you select any unit that isn't supposed to change, all units with the ability activated are changed back into the variant with the ability latent.

The Code

Abilities and events:

Code: Select all

#define CHG_STRT UNIT UNITTO
[event]
first_time_only=no
name=select
[filter]
type={UNIT}
[/filter]
[store_unit]
[filter]
x,y=$x1,$y1
[/filter]
variable=var
kill=yes
[/store_unit]
[set_variable]
name=var.type
value={UNITTO}
[/set_variable]
[unstore_unit]
variable=var
[/unstore_unit]
[/event]
#enddef

#define CHG_END UNIT UNITTO
[event]
first_time_only=no
name=select
[filter]
[not]
type={UNITTO}
[/not]
[/filter]
[store_unit]
[filter]
type={UNITTO}
[/filter]
variable=rav
kill=yes
[/store_unit]
[set_variable]
name=rav.type
value={UNIT}
[/set_variable]
[unstore_unit]
variable=rav
[/unstore_unit]
[/event]
#enddef

#define ABILITY_FEARSOME_0
[leadership]
id=fearsome
value=0
cumulative=no
name= _ "fearsome"
description= _ "Fearsome:
On attack, this unit takes only half the damage from ennemies of lower level."
affect_self=no
affect_allies=no
affect_enemies=yes
[affect_adjacent]
adjacent=n,ne,se,s,sw,nw
[filter]
level=6
[/filter]
[/affect_adjacent]
[/leadership]
#enddef

#define ABILITY_FEARSOME_1
[leadership]
id=fearsome
value=-50
cumulative=no
name= _ "fearsome"
description= _ "Fearsome:
On attack, this unit takes only half the damage from ennemies of lower level."
affect_self=no
affect_allies=no
affect_enemies=yes
[affect_adjacent]
adjacent=n,ne,se,s,sw,nw
[filter]
level=0
[/filter]
[/affect_adjacent]
[/leadership]
#enddef

#define ABILITY_FEARSOME_2
[leadership]
id=fearsome
value=-50
cumulative=no
name= _ "fearsome"
description= _ "Fearsome:
On attack, this unit takes only half the damage from ennemies of lower level."
affect_self=no
affect_allies=no
affect_enemies=yes
[affect_adjacent]
adjacent=n,ne,se,s,sw,nw
[filter]
level=0
[/filter]
[/affect_adjacent]
[/leadership]
[leadership]
id=fearsome
value=-50
cumulative=no
affect_self=no
affect_allies=no
affect_enemies=yes
[affect_adjacent]
adjacent=n,ne,se,s,sw,nw
[filter]
level=1
[/filter]
[/affect_adjacent]
[/leadership]
#enddef

#define ABILITY_FEARSOME_3
[leadership]
id=fearsome
value=-50
cumulative=no
name= _ "fearsome"
description= _ "Fearsome:
On attack, this unit takes only half the damage from ennemies of lower level."
affect_self=no
affect_allies=no
affect_enemies=yes
[affect_adjacent]
adjacent=n,ne,se,s,sw,nw
[filter]
level=0
[/filter]
[/affect_adjacent]
[/leadership]
[leadership]
id=fearsome
value=-50
cumulative=no
affect_self=no
affect_allies=no
affect_enemies=yes
[affect_adjacent]
adjacent=n,ne,se,s,sw,nw
[filter]
level=1
[/filter]
[/affect_adjacent]
[/leadership]
[leadership]
id=fearsome
value=-50
cumulative=no
affect_self=no
affect_allies=no
affect_enemies=yes
[affect_adjacent]
adjacent=n,ne,se,s,sw,nw
[filter]
level=2
[/filter]
[/affect_adjacent]
[/leadership]
#enddef
And the way it's used, here for a LVL2 unit:

Code: Select all

[unit]
id=D5-2a
name= _ "Dark Knight"
race=human
ignore_race_traits=yes
{TRAIT_STRONG}
{TRAIT_RESILIENT}
{TRAIT_QUICK}
{TRAIT_INTELLIGENT}
image="D5-2a.png"
ellipse="misc/ellipse"
{MAGENTA_IS_THE_TEAM_COLOR}
{CHG_STRT D5-2a D5-2aalter}
{CHG_END D5-2a D5-2aalter}
[abilities]
{ABILITY_FEARSOME_0}
[/abilities]
hitpoints=50
movement_type=mounted
movement=8
experience=100
level=2
[resistance]
cold=80
[/resistance]
alignment=chaotic
advanceto=null
{AMLA_TOUGH 3}
cost=21
usage=fighter
unit_description= _ "..."
die_sound=horse-die.ogg
{DEFENSE_ANIM "D5-2a.png" "D5-2a.png" {SOUND_LIST:HORSE_HIT} }
[attack]
name=spear
type=pierce
range=melee
damage=13
number=2
[specials]
{WEAPON_SPECIAL_CHARGE}
[/specials]
[animation]
[frame]
begin=-100
end=0
image="D5-2a.png"
sound=horse-canter.wav
[/frame]
[frame]
begin=0
end=100
image="D5-2a.png"
sound=spear.wav
[/frame]
[/animation]
[/attack]
[/unit]
The Bugs

While the hack mostly works, two annoying bugs have appeared:

1-After attacking, if you select another unit afterwards, you will sometimes be allowed to attack again.

2-People reported that having multiple knights caused them to disappear at times. I believe this was a coding glitch that has been fixed, but the issue has appeared.

So, does anyone see the problem?

Rhuvaen
Inactive Developer
Posts: 1272
Joined: August 27th, 2004, 8:05 am
Location: Berlin, Germany

Post by Rhuvaen » September 13th, 2007, 5:43 am

There's definitely a problem with CHG_END (by the way, what do you save by abbreviating macro names like this?).

Let's look at this interaction example:

A player has two Dark Knights, A and B.

The player selects DK A (which turns him into... I don't know, you left out that part). So now we have a Fearsome Dark Knight A and DK B.

Now, instead of clicking on another type of unit (which would release FDK A from it's fearsome state), let's say he clicks on DK B.

DK B becomes FDK B. Now he has two Fearsome Dark Knights, A and B.

If now he selects any other unit, both Fearsome Dark Knights get stored but only the first gets unstored. You need to change this:

Code: Select all

#define CHG_END UNIT UNITTO
[event]
first_time_only=no
name=select
[filter]
[not]
type={UNITTO}
[/not]
[/filter]
[store_unit]
[filter]
type={UNITTO}
[/filter]
variable=rav
kill=yes
[/store_unit]
{FOREACH rav i}
  [set_variable]
    name=rav[$i].type
    value={UNIT}
  [/set_variable]
  [unstore_unit]
    variable=rav[$i]
  [/unstore_unit]
{NEXT i}
[/event]
#enddef
Alternatively, you store the changed Dark Knights coordinates in a variable and use that for the select filter:

Code: Select all

#define CHG_END UNIT UNITTO
[event]
first_time_only=no
name=select
[filter]
[not]
x=$fearsome_x
y=$fearsome_y
[/not]
[/filter]
...
That way, you'll only have one DK stored and can leave the rest as-is.

I'm not sure about the first problem, at the moment.

And you definitely want to limit all this unit changing on select to the player's side!!

Post Reply