"Alert" unit immune to backstab

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.
User avatar
beetlenaut
Developer
Posts: 2825
Joined: December 8th, 2007, 3:21 am
Location: Washington State
Contact:

Re: "Alert" unit immune to backstab

Post by beetlenaut »

Helmet wrote: December 24th, 2020, 3:09 pm The way the Alert ability works is to permit the damage to be doubled, then divide it in half.
Doing it that way makes it invisible to the AI, so it can't be grayed out. Also, the AI can't use it in its own calculations when deciding which unit to attack.

There is a better way to do it though: You can create your own version of backstab (with the same name but different id). You could copy the code from the core->macros->abilities file and add an [and] to the [filter_opponent] tag in that code. Filter for "alert" in the [and]. Then use a "unit placed" event to give an object to every unit that has backstab, which removes the normal backstab and adds your custom one. This will make it visible to the AI, so it should be grayed out when appropriate.
Campaigns: Dead Water,
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide
User avatar
Helmet
Posts: 641
Joined: December 19th, 2006, 5:28 pm
Location: Florida, USA

Re: "Alert" unit immune to backstab

Post by Helmet »

Nifty solution, beetlenaut. Thank you.

Does and go inside the filter_opponent, like I wrote below?

Code: Select all

#define WEAPON_SPECIAL_BACKSTAB_CUSTOM2

    [damage]
        id=backstab_custom2
        name= _ "backstab"
        description= _ "When used offensively..."
        multiply=2
        active_on=offense
        [filter_opponent]
            formula="
                enemy_of(self, flanker) and not flanker.petrified
            where
                flanker = unit_at(direction_from(loc, other.facing))
            "
			[and]
				[filter]
					ability=alert
				[/filter]
			[/and]
 
        [/filter_opponent]
    [/damage]
#enddef
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
beetlenaut
Developer
Posts: 2825
Joined: December 8th, 2007, 3:21 am
Location: Washington State
Contact:

Re: "Alert" unit immune to backstab

Post by beetlenaut »

Yes, but don't use [filter] inside the [and]. Inside an SUF, an [and] tag creates another SUF, and [filter] isn't allowed there.
Campaigns: Dead Water,
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide
User avatar
Helmet
Posts: 641
Joined: December 19th, 2006, 5:28 pm
Location: Florida, USA

Re: "Alert" unit immune to backstab

Post by Helmet »

beetlenaut wrote: December 25th, 2020, 1:14 am Yes, but don't use [filter] inside the [and]. Inside an SUF, an [and] tag creates another SUF, and [filter] isn't allowed there.
It's working!

Well, it wasn't working at first. The backstab wasn't being grayed-out, just like before. But then I changed the ands to nots and that fixed it. I figured that's what you meant to write, since Alert was being excluded.

And instead of giving objects, I updated the unit_types for the two types of units who can backstab a side 2 unit. So instead of
{WEAPON_SPECIAL_BACKSTAB}, they now have {WEAPON_SPECIAL_BACKSTAB_CUSTOM}.

Thanks again, beetlenaut.
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
Celtic_Minstrel
Developer
Posts: 2211
Joined: August 3rd, 2012, 11:26 pm
Location: Canada
Contact:

Re: "Alert" unit immune to backstab

Post by Celtic_Minstrel »

beetlenaut wrote: December 24th, 2020, 10:25 pm
Helmet wrote: December 24th, 2020, 3:09 pm The way the Alert ability works is to permit the damage to be doubled, then divide it in half.
Doing it that way makes it invisible to the AI, so it can't be grayed out. Also, the AI can't use it in its own calculations when deciding which unit to attack.
I'm fairly sure that's not true? I'm pretty sure the AI has the same view of the game that the player has. It doesn't know how to tactically set up a backstab, but if by chance it's given a situation where it can backstab, then it knows the backstab will double the damage dealt and can factor that into its decision. Similarly, I'm pretty sure it would be able to detect in this case that the backstab gets cancelled out by the other ability and thus doesn't provide a boost to the damage, but it wouldn't have the understanding to tactically set up (or avoid) a situation where this is the case.
Author of The Black Cross of Aleron campaign and Default++ era.
Former maintainer of Steelhive.
User avatar
Helmet
Posts: 641
Joined: December 19th, 2006, 5:28 pm
Location: Florida, USA

Re: "Alert" unit immune to backstab

Post by Helmet »

I can't figure-out how to remove the custom backstab special upon AMLA advancement. This is what I'm trying to do: When the unit advances via AMLA, I want its damage to be doubled all the time, regardless of the whether or not the opponent is flanked. Basically, I want to remove the custom backstab and increase damage 100% in an AMLA.

I know the AMLA works, because the unit becomes a little blue via the use of BLEND in the AMLA code.

I tried value=backstab_custom2, id=backstab_custom2, remove=backstab_custom2. I even tried removing the custom backstab via remove_abilty, just in case I'm totally confused about specials. Nothing works.

Also the damage is not doubling and the attack name is not changing from "sting" to "precision sting."

Thanks for your help.

Code: Select all

	[effect]
		apply_to=image_mod
		add="BLEND(180,0,0,20%)" # (r,g,b,o) # make AMLA unit blue
	[/effect]
		
	[effect]
		apply_to=remove_specials 		# remove backstab because damage is always doubled
		remove_specials=backstab_custom2 	# value=backstab_custom2 # id=backstab_custom2 # remove=backstab_custom2
	[/effect]
	
        [effect]
            apply_to=attack
            name=precision sting
            increase_damage=100%
        [/effect]
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
WhiteWolf
Forum Moderator
Posts: 769
Joined: September 22nd, 2009, 7:48 pm
Location: Hungary

Re: "Alert" unit immune to backstab

Post by WhiteWolf »

Helmet wrote: January 2nd, 2021, 2:10 pm Also the damage is not doubling and the attack name is not changing from "sting" to "precision sting."

Code: Select all

        [effect]
            apply_to=attack
            name=precision sting
            increase_damage=100%
        [/effect]
I think here's the problem: name in an attack effect is a filter for which attack to modify, and it's currently looking for "precision sting", which, based on your description, doesn't exist yet.

You should use name for sting and set the new name to precision sting instead:

Code: Select all

[effect]
    apply_to=attack
    name=sting
    set_name="precision sting"
    increase_damage=100%
[/effect]
Also keep in mind that name is like an id for the attack, the shown ingame text is the description, you might want to set that one accordingly as well.
Main UMC campaigns: The Ravagers - now for 1.16, with new bugs!
Old UMC works: The Underness Series, consisting of 5 parts: The Desolation of Karlag, The Blind Sentinel, The Stone of the North, The Invasion Of The Western Cavalry, Fingerbone of Destiny
User avatar
beetlenaut
Developer
Posts: 2825
Joined: December 8th, 2007, 3:21 am
Location: Washington State
Contact:

Re: "Alert" unit immune to backstab

Post by beetlenaut »

Each apply_to value has its own set of keys and tags. If you use apply_to=attack, you then have access to remove_specials. (The indentation on the wiki showing this relationship may be a little too subtle, but it's there.) So, to remove the special, it's

Code: Select all

[effect]
	apply_to=attack
	remove_specials=backstab_custom2
[/effect]
WhiteWolf wrote: January 2nd, 2021, 2:40 pm You should use name for sting and set the new name to precision sting instead
If it were me, I don't think I would bother changing the name in the first place. I would just use set_description to change what the player sees. (Don't forget that descriptions should be translatable strings.)
Campaigns: Dead Water,
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide
User avatar
Helmet
Posts: 641
Joined: December 19th, 2006, 5:28 pm
Location: Florida, USA

Re: "Alert" unit immune to backstab

Post by Helmet »

WhiteWolf wrote: January 2nd, 2021, 2:40 pm I think here's the problem: name in an attack effect is a filter for which attack to modify, and it's currently looking for "precision sting", which, based on your description, doesn't exist yet...
That worked on the damage and the name problems. Thanks, WhiteWolf. My major mistake was thinking that name was just a name, like in a unit tag.
beetlenaut wrote: January 2nd, 2021, 3:17 pm Each apply_to value has its own set of keys and tags. If you use apply_to=attack, you then have access to remove_specials. (The indentation on the wiki showing this relationship may be a little too subtle, but it's there.) So, to remove the special, it's

Code: Select all

[effect]
	apply_to=attack
	remove_specials=backstab_custom2
[/effect]
The solution seems simple, but I couldn't get it to work. Custom backstab refused to go away. I'm not sure what I was doing wrong. Anyhow, I ended up removing the attack and adding a new one without backstab. It works great now.
beetlenaut wrote: January 2nd, 2021, 3:17 pm If it were me, I don't think I would bother changing the name in the first place. I would just use set_description to change what the player sees. (Don't forget that descriptions should be translatable strings.)
In the end, that's what I decided to do. Thanks.

Code: Select all

		[effect]
			apply_to=new_attack
			name="sting"
			description= _ "precision sting"
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.
newfrenchy83
Code Contributor
Posts: 172
Joined: October 6th, 2017, 12:57 pm

Re: "Alert" unit immune to backstab

Post by newfrenchy83 »

The gray-out the word backstab is really important like for poison with undead? instead to put "immune to backstab" perhaps must you rewrite description if you want use this new feature like"reduce backstab damage to base damage value" for player undestand what backstab word not greyed out.
Post Reply