How to implement a ranged attack greater than 1 hex

The place to post your WML questions and answers.

Moderator: Forum Moderators

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
arobinson
Posts: 208
Joined: June 6th, 2010, 12:05 am

How to implement a ranged attack greater than 1 hex

Post by arobinson »

I am working on a single unit RPG like campaign for 1.9. In this I would like to implement area of effect spells that have a range of over 1 hex. For example, one spell I am toying with is a chained lightning attack. This attack would cast an initial lightning bolt from the attacker to the defender. If it hits, and based on a chance to leap, then the lightning will proceed, an possibly fork to adjacent enemy units.

Using the new harm_unit tag in 1.9, I can easily write the WML to perform the correct logic to deal the damage. The problem is the animation. Since wesnoth is made for neighboring hexes to battle, it would be very difficult to get the animation to start from the target hex and extend to an adjacent hex. If I kept it to one hex chain only it would be easier, but it still would have a lot of variations. So for example, if the initial bolt is nw from the attacker, and the adjacent enemies are n and nw of the defender, then I would need to trigger an animation from the attacker, starting with an offset to start from the defenders x,y co-ordinate and extend to the correct hex from there. So I would need to have animations in many directions to support each possible compass direction and subsequent compass direction.

Any ideas on an easier way to implement this?
Running Wesnoth 1.12.4 on Mac OSX 10.10
Campaigns:
blueknight1758
Posts: 252
Joined: March 30th, 2011, 8:38 pm
Location: The UK

Re: How to implement a ranged attack greater than 1 hex

Post by blueknight1758 »

You might be able to filter_adjacent do the Ramon chance and if it succeeds store the unit your going to electrocute and play an electric animation and start over again.
User avatar
arobinson
Posts: 208
Joined: June 6th, 2010, 12:05 am

Re: How to implement a ranged attack greater than 1 hex

Post by arobinson »

Yeah, I think what I can do is generate a random number and set it on the unit as a variable. Then, during the attack begin and after each hit/miss, I can filter out what adjacent targets will be hit, and set those as variables. Then using animations, I played around with the fireball as a test and got it to work by using offset=1 and then using the x and y to change the location of the missile. I then set the start time to 0 of the missile and for 1ms show a blank hex. That way the image is not visible until the animation begins. I then apply fractions and my own flipping as needed.

For example here is what I did for the ne fireball on the 2nd hit (first 40ms):

Code: Select all

        [missile2_frame]
            duration=1
            halo="projectiles/blank.png"
            offset=1
        [/missile2_frame]
        [missile2_frame]
            duration=39
            image="projectiles/fireball-nw-1.png"
            halo_mod="~FL(horiz)"
            offset=1
            halo_x=0~-5
            halo_y=0~-3
            auto_hflip=no
            auto_vflip=no
        [/missile2_frame]
Then I just make the animate go to 90% of 54px to the x co-ordinate and 90% of 32 px for the y co-ordinate. It is not as convenient as the offset in a normal animation, but suffices just as well. Then I just need to have animations for each combination of adjacent units. Going to be quite heavy on the macros, but it should work.
Running Wesnoth 1.12.4 on Mac OSX 10.10
Campaigns:
Post Reply