explosive damage

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
hermestrismi
Posts: 607
Joined: February 6th, 2016, 11:28 pm
Location: Tunisia
Contact:

explosive damage

Post by hermestrismi »

Hi wesnothians,
after some months awway, it seems that I forget some basics. I want to give a special weapon the ability to attack multiply units (explosion).
I tried both LotI code and the wiki code, they didn't work with me (the LotI code contain parts coded in many .cfg and I didn't find the missing part, as for the wiki it seems outdated for 1.16, I think)
Anyway , this is my try

Code: Select all

[event]
    name=attacker_hits
    first_time_only=no
   
    [filter_weapon]
        special_id=area_of_effect
    [/filter_weapon]
		    [harm_unit]
			[filter]
			    [filter_adjacent]
				x,y=$x2,$y2
			    [/filter_adjacent]
			    [not]
				x,y=$x2,$y2
			    [/not]
				[filter_side]
					[enemy_of]
						side=$unit.side
					[/enemy_of]
				[/filter_side]
			[/filter]
			[filter_second]
				x,y=$x1,$y1
			[/filter_second]
		    amount=$weapon.damage
			damage_type=$weapon.type
			fire_event=yes
			experience=no
		      [/harm_unit] 
	[if]
		[variable]
			name=damage
			greater_than=24
		[/variable]
		[then]
			[harm_unit]
			    [filter]
				[filter_location]
				    [not]
				        x,y=$x2,$y2
				        radius=1
				    [/not]
				    [and]
				        x,y=$x2,$y2
				        radius=2
				        [filter_radius]
				            terrain=!,X*,X*^*,*^X*
				        [/filter_radius]
				    [/and]
				[/filter_location]
				[filter_side]
					[enemy_of]
						side=$unit.side
					[/enemy_of]
				[/filter_side]
			    [/filter]
			    [filter_second]
				x,y=$x1,$y1
			    [/filter_second]

			    amount=$($weapon.damage*2)
			    damage_type=$weapon.type
			    fire_event=yes
			    experience=no
			    animate=no
			[/harm_unit]
		[/then]
	[/if]
[/event]


#define WEAPON_SPECIAL_AREA_OF_EFFECT
    [damage]
        id=area_of_effect
        name= _ "area of effect"
        description= _ "When this attack is used, all units adjacent the attacker take the damage, and cannot be countered."
    [/damage]
#enddef
dwarftough
Posts: 478
Joined: August 4th, 2019, 5:27 pm

Re: explosive damage

Post by dwarftough »

Have you tried LotI code with [harm_unit_loti] replace with [harm_unit]? [harm_unit_loti] is defined in lua/main.go and needed only for different XP calculation logic. LotI's event for explosive defined here https://github.com/Dugy/Legend_of_the_I ... .cfg#L3841 (and INCORPORATE_EFFECTS defined in the beginning of the same file). You'll need to have this event in every scenario where the special is supposed to work
Co-founder and current maintainer of IsarFoundation, Afterlife Rated and overall Wesnoth Autohost Project
Developer and maintainer of my fork of World Conquest, Invincibles Conquest II
User avatar
Helmet
Posts: 641
Joined: December 19th, 2006, 5:28 pm
Location: Florida, USA

Re: explosive damage

Post by Helmet »

hermestrismi wrote: November 22nd, 2022, 8:26 pmAnyway , this is my try...
I would've gone with harm_unit as well. Did it work?

I don't recall ever seeing a filter like this...
I'm not saying it's wrong, but I don't understand what it does.

Code: Select all

[filter]
	[filter_adjacent]
		x,y=$x2,$y2
		[/filter_adjacent]
			    [not]
				x,y=$x2,$y2
			    [/not]
Author of:
DIY Campaign, Confederacy of Swamp Creatures: Big Battle 1, Confederacy of Swamp Creatures: Big Battle 2, Frogfolk Delivery Service, The Pool of Ek.
User avatar
hermestrismi
Posts: 607
Joined: February 6th, 2016, 11:28 pm
Location: Tunisia
Contact:

Re: explosive damage

Post by hermestrismi »

Helmet wrote: November 23rd, 2022, 4:48 am
hermestrismi wrote: November 22nd, 2022, 8:26 pmAnyway , this is my try...
I would've gone with harm_unit as well. Did it work?

I don't recall ever seeing a filter like this...
I'm not saying it's wrong, but I don't understand what it does.

Code: Select all

[filter]
	[filter_adjacent]
		x,y=$x2,$y2
		[/filter_adjacent]
			    [not]
				x,y=$x2,$y2
			    [/not]
It's supposed to exclude the enemy from taking damage twice. Any suggestion to replace is welcomed
User avatar
hermestrismi
Posts: 607
Joined: February 6th, 2016, 11:28 pm
Location: Tunisia
Contact:

Re: explosive damage

Post by hermestrismi »

dwarftough wrote: November 23rd, 2022, 3:33 am Have you tried LotI code with [harm_unit_loti] replace with [harm_unit]? [harm_unit_loti] is defined in lua/main.go and needed only for different XP calculation logic. LotI's event for explosive defined here https://github.com/Dugy/Legend_of_the_I ... .cfg#L3841 (and INCORPORATE_EFFECTS defined in the beginning of the same file). You'll need to have this event in every scenario where the special is supposed to work
I tried it. The problem was that it contains many fragments (

Code: Select all

damage
,

Code: Select all

resistance 
...) coded elsewhere which means that I need to copy/past a lot of things without any modifications while I want something more simple
dwarftough
Posts: 478
Joined: August 4th, 2019, 5:27 pm

Re: explosive damage

Post by dwarftough »

hermestrismi wrote: November 23rd, 2022, 7:22 am I tried it. The problem was that it contains many fragments (

Code: Select all

damage
,

Code: Select all

resistance 
...) coded elsewhere which means that I need to copy/past a lot of things without any modifications while I want something more simple
If you are talking about variables damage and resistance, they are defined in INCORPORATE_EFFECTS macro here https://github.com/Dugy/Legend_of_the_I ... nts.cfg#L3

So I don't quite understand what you need to copypaste about it, just macro and event should be fine, what do I miss?
Co-founder and current maintainer of IsarFoundation, Afterlife Rated and overall Wesnoth Autohost Project
Developer and maintainer of my fork of World Conquest, Invincibles Conquest II
User avatar
Helmet
Posts: 641
Joined: December 19th, 2006, 5:28 pm
Location: Florida, USA

Re: explosive damage

Post by Helmet »

hermestrismi wrote: November 23rd, 2022, 7:18 am It's supposed to exclude the enemy from taking damage twice. Any suggestion to replace is welcomed
Oh, I see. That's a clever solution to the problem. But if the enemy was taking damage twice, another approach might be to stop the repetition of damage problem from happening in the first place. I don't completely understand your code, but I don't see any reason why damage would happen twice.
hermestrismi wrote: November 23rd, 2022, 7:22 am...I want something more simple
I like simpler solutions also.

Here's an idea. Maybe you could create a status called blasted, and assign it to everyone in the blast radius. And then filter for the status, and every unit with the status takes $weapon.damage. And then the blasted status is removed from everyone.
Author of:
DIY Campaign, Confederacy of Swamp Creatures: Big Battle 1, Confederacy of Swamp Creatures: Big Battle 2, Frogfolk Delivery Service, The Pool of Ek.
User avatar
lhybrideur
Posts: 355
Joined: July 9th, 2019, 1:46 pm

Re: explosive damage

Post by lhybrideur »

Helmet wrote: November 23rd, 2022, 1:34 pm
hermestrismi wrote: November 23rd, 2022, 7:18 am It's supposed to exclude the enemy from taking damage twice. Any suggestion to replace is welcomed
Oh, I see. That's a clever solution to the problem. But if the enemy was taking damage twice, another approach might be to stop the repetition of damage problem from happening in the first place. I don't completely understand your code, but I don't see any reason why damage would happen twice.
The enemy takes the normal damage of the attack, and then the damage caused by this event.
User avatar
Helmet
Posts: 641
Joined: December 19th, 2006, 5:28 pm
Location: Florida, USA

Re: explosive damage

Post by Helmet »

hermestrismi wrote: November 22nd, 2022, 8:26 pm Anyway , this is my try
What parts of your code are working and what parts aren't?

Perhaps break it into 2 specials, area_of_effect_small and area_of_effect_big, and see if the bug reveals itself.
lhybrideur wrote: November 23rd, 2022, 2:37 pm The enemy takes the normal damage of the attack, and then the damage caused by this event.
Oh, thanks for explaining. The attack is like a barrel of TNT exploding. The target gets damaged once, and then the surrounding units also get damaged.
Author of:
DIY Campaign, Confederacy of Swamp Creatures: Big Battle 1, Confederacy of Swamp Creatures: Big Battle 2, Frogfolk Delivery Service, The Pool of Ek.
User avatar
Ravana
Forum Moderator
Posts: 2933
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: explosive damage

Post by Ravana »

[filter_adjacent]
x,y=$x2,$y2
[/filter_adjacent]
[not]
x,y=$x2,$y2
[/not]
I think unit is not adjacent to itself. This check is needed when you are harming additionally around attacker.
User avatar
hermestrismi
Posts: 607
Joined: February 6th, 2016, 11:28 pm
Location: Tunisia
Contact:

Re: explosive damage

Post by hermestrismi »

Hi everybody , I am back
first thing's first, I want to thank alll of you
dwarftough wrote: November 23rd, 2022, 11:17 am If you are talking about variables damage and resistance, they are defined in INCORPORATE_EFFECTS macro here https://github.com/Dugy/Legend_of_the_I ... nts.cfg#L3
So I don't quite understand what you need to copypaste about it, just macro and event should be fine, what do I miss?
I meant that some variables like

Code: Select all

    {VARIABLE damage $damage_inflicted}
    {VARIABLE_OP damage multiply 100}
        [get_unit_resistance]
            find_in=second_unit
            damage_type=$weapon.type
            to_variable=resistance
        [/get_unit_resistance]
are coded elsewhere. you can't just copy past it without copying other macro that explain what is [get_unit_resistance] for example
Helmet wrote: November 23rd, 2022, 1:34 pm Oh, I see. That's a clever solution to the problem. But if the enemy was taking damage twice, another approach might be to stop the repetition of damage problem from happening in the first place. I don't completely understand your code, but I don't see any reason why damage would happen twice.
I like simpler solutions also.
Here's an idea. Maybe you could create a status called blasted, and assign it to everyone in the blast radius. And then filter for the status, and every unit with the status takes $weapon.damage. And then the blasted status is removed from everyone.
the first part was answered thanks to lhybrideur . As for the second, I followed your suggestions and it worked. thank you.
lhybrideur wrote: November 23rd, 2022, 2:37 pm The enemy takes the normal damage of the attack, and then the damage caused by this event.
Exactly. An area of damage that make any other special attack (not only the damage quantity but also poison, slow, ...) explode.
Ravana wrote: November 23rd, 2022, 10:06 pm [filter_adjacent]
x,y=$x2,$y2
[/filter_adjacent]
[not]
x,y=$x2,$y2
[/not]
I think unit is not adjacent to itself. This check is needed when you are harming additionally around attacker.
exactly, the attack hit the enemy then anyone around him then anyone within radius=2. without the exempt, the original enemy will be damaged twice because he is adjacent to another unit who will pass the damage.
Anyway, this is my final result. I tested it and I hope there is no bugs...

Code: Select all

#define WEAPON_SPECIAL_AREA_OF_EFFECT
    [damage]
        id=area_of_effect
        name= _ "area of effect"
        description= _ "When this attack is used, all units adjacent the attacker take the damage, and cannot be countered."
		active_on=offense
		apply_to=self
    [/damage]
#enddef

    [event]
        name=attacker_hits
        first_time_only=no
		[filter_attacker]
                    special_id=area_of_effect
		[/filter_attacker]
		[harm_unit]
			[filter]
			    [filter_adjacent]
					x,y=$x2,$y2
			    [/filter_adjacent]
			    [not]
					x,y=$x2,$y2
			    [/not]
				[filter_side]
					[enemy_of]
						side=$unit.side
					[/enemy_of]
				[/filter_side]
			[/filter]
			[filter_second]
				x,y=$x1,$y1
			[/filter_second]
			    amount=$weapon.damage
			    damage_type=$weapon.type
			    fire_event=yes
			    experience=no
		[/harm_unit] 
		[if]
		[variable]
			name=weapon.damage
			greater_than=12
		[/variable]
		[then]
			[harm_unit]
			    [filter]
				[filter_location]
				    [not]
				        x,y=$x2,$y2
				        radius=1
				    [/not]
				    [and]
				        x,y=$x2,$y2
				        radius=2
				        [filter_radius]
				            terrain_type=!,X*,X*^*,*^X*
				        [/filter_radius]
				    [/and]
				[/filter_location]
				[filter_side]
					[enemy_of]
						side=$unit.side
					[/enemy_of]
				[/filter_side]
			    [/filter]
			    [filter_second]
					x,y=$x1,$y1
			    [/filter_second]

			    amount=$($weapon.damage/2)
			    damage_type=$weapon.type
			    fire_event=yes
			    experience=no
			    animate=no
			[/harm_unit]
		[/then]
		[/if]
    [/event]
    
Post Reply