Dig ability

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
ChaosRider
Posts: 846
Joined: April 15th, 2012, 1:15 pm

Re: Dig ability

Post by ChaosRider »

In edit 3 of my earlier post is fixed version of dig ability.
My code wasnt that bad, i just didnt see why my code cant work... I cant search adjected units to x,y=$x1,$y1 when on this x,y there is no unit. Thats why i creating there some peasant while my code is working, at end of my code im killing this peasant :P. Thats why also summoners code works well, cause there is created new elemental, after what near him is search unit who summoned him.

edit: also this code dont need to know what type of unit have this ability, thx what its easy to add it to MWC campaign as one of items :D (but there i will set 6 mp needed to dig).
Creator of WOTG (+2880 units), MWC (+615 units), SurvivorsArea, RandomColosseum, RC WOTG, RC MWC, ColosseumRandomClonesBattle, BetweenDarknessAndLight, StealingWeapons, MoreUnitsForms, MoreDamageTypes, CanBeOnlyOne, ColosseumOneWinner, BonusSpam, CriticalStrike - available at 1.12 Wesnoth server.
User avatar
ChaosRider
Posts: 846
Joined: April 15th, 2012, 1:15 pm

Re: Dig ability

Post by ChaosRider »

Dugi wrote:I think that there might be one solution, but it is a bit ugly*. Something like this:

Code: Select all

[set_menu_item]
 ...
 [filter]
  [filter_location] # It is a cave terrain
   terrain=Xu
  [/filter_location]
  [and]
   [filter_adjacent]
    ability=dig
    [and]
     [filter_wml]
      moves=3
     [/filter_wml]
     [or]
      [filter_wml]
       moves=4
      [/filter_wml]
     [/or]
     [or]
      [filter_wml]
       moves=5
      [/filter_wml]
     [/or]
    [/and]
    ... etc, until the maximum movement the fastest of your units can have
   [/filter_adjacent]
  [/and]
 [/filter]
 ...
[/set_menu_item]
I am not assuring you that it works, because I am not quite sure if filter_adjacent works if there is no unit on the primary hex. But if it doesn't, then the solution will be extremely ugly.


* You can't use variable compare to check the movement, because the unit is not on the hex that was clicked on and therefore not stored into the unit variable and can't.
When we want to filter units which have more mp than some variable then we have to only set filers for lower movement points than this variable but with [not][/not] :P, example:
Spoiler:
This is to filter units with 4 or more mp.
Creator of WOTG (+2880 units), MWC (+615 units), SurvivorsArea, RandomColosseum, RC WOTG, RC MWC, ColosseumRandomClonesBattle, BetweenDarknessAndLight, StealingWeapons, MoreUnitsForms, MoreDamageTypes, CanBeOnlyOne, ColosseumOneWinner, BonusSpam, CriticalStrike - available at 1.12 Wesnoth server.
User avatar
Dugi
Posts: 4961
Joined: July 22nd, 2010, 10:29 am
Location: Carpathian Mountains
Contact:

Re: Dig ability

Post by Dugi »

When we want to filter units which have more mp than some variable then we have to only set filers for lower movement points than this variable but with [not][/not] , example:
:facepalm:
User avatar
ChaosRider
Posts: 846
Joined: April 15th, 2012, 1:15 pm

Re: Dig ability

Post by ChaosRider »

Cause ?
Creator of WOTG (+2880 units), MWC (+615 units), SurvivorsArea, RandomColosseum, RC WOTG, RC MWC, ColosseumRandomClonesBattle, BetweenDarknessAndLight, StealingWeapons, MoreUnitsForms, MoreDamageTypes, CanBeOnlyOne, ColosseumOneWinner, BonusSpam, CriticalStrike - available at 1.12 Wesnoth server.
User avatar
Dugi
Posts: 4961
Joined: July 22nd, 2010, 10:29 am
Location: Carpathian Mountains
Contact:

Re: Dig ability

Post by Dugi »

That the solution is so simple, but I did not think of it :doh:
User avatar
ChaosRider
Posts: 846
Joined: April 15th, 2012, 1:15 pm

Re: Dig ability

Post by ChaosRider »

I had a similar task with statistics, calculate the sum of probability for many variables from 2 and higher... (max was 400), i dont remember well about what was that, but i remember how we done it:
1 - (P(0)+P(1))...
Creator of WOTG (+2880 units), MWC (+615 units), SurvivorsArea, RandomColosseum, RC WOTG, RC MWC, ColosseumRandomClonesBattle, BetweenDarknessAndLight, StealingWeapons, MoreUnitsForms, MoreDamageTypes, CanBeOnlyOne, ColosseumOneWinner, BonusSpam, CriticalStrike - available at 1.12 Wesnoth server.
gfgtdf
Developer
Posts: 1432
Joined: February 10th, 2013, 2:25 pm

Re: Dig ability

Post by gfgtdf »

ChaosRider wrote: units with 3 or more mp cant go by this part in filter:
"formula="moves >= 3""
you have to write "movement_left >= 3" but from my experience that is not realy reliable.
Scenario with Robots SP scenario (1.11/1.12), allows you to build your units with components, PYR No preperation turn 1.12 mp-mod that allows you to select your units immideately after the game begins.
User avatar
Paulomat4
Moderator Emeritus
Posts: 730
Joined: October 16th, 2012, 3:32 pm
Location: Wesmere library, probably summoning Zhangor

Re: Dig ability

Post by Paulomat4 »

Hey, I'm currently trying to make this ability work in my campaign.
I took the code from trewe's last post and worked on from there. I can successfully dig, but I don't understand why neigboring units are nstored as well in the second part of the code. Does anybody have an idea?

Code: Select all

#define ABILITY_DIG
    [dummy]
        id=dig
        name= _ "dig"
		description= _ "This unit Is able to dig itself through cave walls. For the cost of three mp it can change the terrain of an adjacent cave wall to cave ground."
    [/dummy]
#enddef

#define MOVES_NO_LESS_THAN_3
[and]
	[not]
		[filter_wml]
			moves=3
		[/filter_wml]
	[/not]
[/and]
[and]
	[not]
		[filter_wml]
			moves=2
		[/filter_wml]
	[/not]
[/and]
[and]
	[not]
		[filter_wml]
			moves=1
		[/filter_wml]
	[/not]
[/and]
[and]
	[not]
		[filter_wml]
			moves=0
		[/filter_wml]
	[/not]
[/and]
#enddef


#define ABILITY_DIG_EVENT
    [event]
        name=side turn
        first_time_only=no

        [set_menu_item]
            [show_if]
                [have_location]
                    terrain=Xu*
                    x,y=$x1,$y1
                    [filter_adjacent_location]
                        [filter]
                            side=$side_number
							[and]
								type=Dwarvish Miner
							[/and]
							[and]
								ability=dig
							[/and]
							[and]
								{MOVES_NO_LESS_THAN_3}
							[/and]
                        [/filter]
                    [/filter_adjacent_location]
                [/have_location]
            [/show_if]
            id=dig_cavewall
            description= _ "dig into this cave wall"
			image=misc/shovelicon.png
            [command]
                [sound]
                    name=mace.wav
					repeat=3
                [/sound]

                [terrain]
                    terrain=Uu^Dr
                    x,y=$x1,$y1
                [/terrain]

                # teleport the miner to the newly created cave
                [store_unit]
                    [filter]
                        [filter]
                            side=$side_number
							[and]
								type=Dwarvish Miner
							[/and]
							[and]
								ability=dig
							[/and]
							[and]
								{MOVES_NO_LESS_THAN_3}
							[/and]
                        [/filter]
                        [filter_location]
                            [filter_adjacent_location]
								terrain=Uu^Dr
                                x,y=$x1,$y1
                            [/filter_adjacent_location]
                        [/filter_location]
                    [/filter]
                    variable=miner
                    kill=yes
                [/store_unit]

                {VARIABLE miner.x $x1}
                {VARIABLE miner.y $y1}


                # drain moves ? attacks ? do whatever you want here.
                {VARIABLE miner.moves 0}
                {VARIABLE miner.attacks_left 0}

                # note that if more than one unit was adjacent the first stored is modified and all others just stay where they were
                {FOREACH miner i}
                    [unstore_unit]
                        variable=miner[$i]
                    [/unstore_unit]
                {NEXT i}

                [redraw]
                    clear_shroud=yes
                [/redraw]
            [/command]
        [/set_menu_item]
		
    [/event]
#enddef
Creator of Dawn of Thunder and Global Unitmarkers

"I thought Naga's used semi-automatic crossbows with incendiary thermite arrows . . . my beliefs that this race is awesome are now shattered." - Evil Earl
User avatar
Ravana
Forum Moderator
Posts: 3009
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Dig ability

Post by Ravana »

Yes. It is to deal with cases where more than 1 units can dig into single hex. They however get unstored to their original place.
User avatar
Paulomat4
Moderator Emeritus
Posts: 730
Joined: October 16th, 2012, 3:32 pm
Location: Wesmere library, probably summoning Zhangor

Re: Dig ability

Post by Paulomat4 »

I'm sorry, i expressed myself badly. I understood of course that those are supposed to simply get unstored at their original place. Problem is: They don't.
Imagine following situation:
2 dwarvish miners next to each other and both next to the same cavewall hex.
One with full moves, another one with 0.
Now, miner1 without moves is unable to dig, miner2 with moves is able.
So, I'm digging said hex.
Both miners are stored (while only miner2 should) and miner1 is unstored at said hex.

Normally miner1 shouldn't even get stored thanks to the filter, right? The filter works in

Code: Select all

[filter_adjacent_location]
but it doesn't in

Code: Select all

[store_unit]
.
Creator of Dawn of Thunder and Global Unitmarkers

"I thought Naga's used semi-automatic crossbows with incendiary thermite arrows . . . my beliefs that this race is awesome are now shattered." - Evil Earl
User avatar
Ravana
Forum Moderator
Posts: 3009
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Dig ability

Post by Ravana »

Are you sure [filter][filter][/filter][/filter] is valid structure?
User avatar
Paulomat4
Moderator Emeritus
Posts: 730
Joined: October 16th, 2012, 3:32 pm
Location: Wesmere library, probably summoning Zhangor

Re: Dig ability

Post by Paulomat4 »

Are you sure [filter][filter][/filter][/filter] is valid structure?
Yup, that was it. It works when i remove the inner [filter] tag. Thanks for your help ravana!
Creator of Dawn of Thunder and Global Unitmarkers

"I thought Naga's used semi-automatic crossbows with incendiary thermite arrows . . . my beliefs that this race is awesome are now shattered." - Evil Earl
User avatar
Heindal
Posts: 1360
Joined: August 11th, 2011, 9:25 pm
Location: Germany, Karlsruhe
Contact:

Re: Dig ability

Post by Heindal »

You might want to look into the bomb and pick I've created a while ago for Strange Legacy.
The future belongs to those, who believe in the beauty of their dreams.
Developer of: Trapped, Five Fates, Strange Legacy, Epical, UR Epic Era
Dungeonmasters of Wesnoth, Wild Peasants vs Devouring Corpses, Dwarf Dwarfson Dwarvenminer
Post Reply