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

Dig ability

Post by ChaosRider »

Hi i wish to do ability which will allow unit to dig in cave walls and change them to cave terrain :P. I should filter unit with this ability, but whats next? How to set menu which will show up by right click on near cave wall terrain, and when unit have atleast 3 mp left?
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 »

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.
Velensk
Multiplayer Contributor
Posts: 4002
Joined: January 24th, 2007, 12:56 am

Re: Dig ability

Post by Velensk »

I don't know how you were planning to use this but a potentially easy solution is that you can give the unit 3mp through impassable and then make an event which then changes it to cave. The problem is that this will give your unit access to all impassable hexes not just cave walls.
"There are two kinds of old men in the world. The kind who didn't go to war and who say that they should have lived fast died young and left a handsome corpse and the old men who did go to war and who say that there is no such thing as a handsome corpse."
User avatar
Dugi
Posts: 4961
Joined: July 22nd, 2010, 10:29 am
Location: Carpathian Mountains
Contact:

Re: Dig ability

Post by Dugi »

The cave can be a custom terrain with identical graphics, but an entirely new terrain type, passable only by that single unit. But if the digger somehow got 6 movement points, he would crash through one cave terrain without changing it and only change the one where he lands (on 1.11, it might be doable with enter_hex event, but not on 1.10).
User avatar
Adamant14
Posts: 968
Joined: April 24th, 2010, 1:14 pm

Re: Dig ability

Post by Adamant14 »

In the UMC 'Return to Noelren' made by pyrophorus you can find such a code.
Author of Antar, Son of Rheor ( SP Campaign) | Development Thread + Feedback Thread + Replays of ASoR
User avatar
trewe
Translator
Posts: 122
Joined: December 24th, 2012, 5:37 pm
Location: Portugal
Contact:

Re: Dig ability

Post by trewe »

Instead of those awfull ton of filter_wml tags replace them all by:

Code: Select all

    formula="unit.moves >= 3"
And you may restrict it to the current side, or you can dig with enemy units ...
User avatar
Dugi
Posts: 4961
Joined: July 22nd, 2010, 10:29 am
Location: Carpathian Mountains
Contact:

Re: Dig ability

Post by Dugi »

@trewe
Really, I didn't think of that possibility. It should work.
User avatar
ChaosRider
Posts: 846
Joined: April 15th, 2012, 1:15 pm

Re: Dig ability

Post by ChaosRider »

In wc and same in mwc (campaign) sometimes are created places unnable for most units (only 0 lvl ghosts can go by cave walls). Now i want add ability for Mwc_Dwarvish Miner, i can filter them by ability or unit code :P. I want them to lose 3 mp after digging. They have in unit code 4 mp, so with speedy trait its max 5 :P. One dwarvish miner wont dig more than 1 terrain in 1 turn. Also i think im gonna do randomly picked new terrain for this changed cave wall.
Edit:
I found such a code in campaign earlier written:
Spoiler:
Definition of this ability looks like units are able to move on cave wall (in my ability i want them to change near terrain, not this one on which they stay), and i dont want them (dwarvish miners) to change them to terrain :P.
Spoiler:
Last edited by ChaosRider on November 27th, 2013, 11:03 pm, edited 1 time in total.
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 »

In that case, Velensk's idea is the best, supposing that you create a custom copy of the cave terrain as I suggested above.
User avatar
ChaosRider
Posts: 846
Joined: April 15th, 2012, 1:15 pm

Re: Dig ability

Post by ChaosRider »

I created some code, but as for now its not works as i want it :D... I was basing on summon code from era of magic :P.
Option is seen able, my units can dig even when they have 0 moves (3 or more i want :D), with this formula didnt work :P, also if we have 2 dwarvish miners near some wall and last clicked by us dwarv is this on the left and after this we click on wall which was near this on right then this on left get xp not this on right which is also not good.

ability:
Spoiler:
set_menu_item:
Spoiler:
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
pyrophorus
Posts: 533
Joined: December 1st, 2010, 12:54 pm

Re: Dig ability

Post by pyrophorus »

ChaosRider wrote: Definition of this ability looks like units are able to move on cave wall (in my ability i want them to change near terrain, not this one on which they stay), and i dont want them (dwarvish miners) to change them to terrain.
No, it allows not the dwarf to move on cave wall. It allows him to dig only in earthy cave walls, and it costs some move points as well.
I think this code is very near to what you need, but, maybe you should play the scenario to see exactly how it works (it's possible to enter directly the scenario without playing all the campaign, if you're interested, I'll tell you how to).

Friendly,
User avatar
trewe
Translator
Posts: 122
Joined: December 24th, 2012, 5:37 pm
Location: Portugal
Contact:

Re: Dig ability

Post by trewe »

Some problems I see there:
select event is not multiplayer safe
no need to define the menu N times just once in a side turn event (or any other synchronized one) is enough
my mistake, formula does not need to be given 'unit', it is already implicit

Working example, modify at will:

Code: Select all

    [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
                            type=Mwc Dwarvish Miner
                            formula="moves >= 3"
                            ability=dig
                        [/filter]
                    [/filter_adjacent_location]
                [/have_location]
            [/show_if]
            id=dig_cavewall
            description= _ "smash this cave wall"
            [command]
                [sound]
                    sound=explosion.ogg
                [/sound]

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

                # teleport the miner to the newly created cave
                [store_unit]
                    [filter]
                        ability=dig
                        side=$side_number
                        formula="moves >= 3"
                        [filter_location]
                            [filter_adjacent_location]
                                x,y=$x1,$y1
                            [/filter_adjacent_location]
                        [/filter_location]
                    [/filter]
                    variable=miner
                    kill=yes
                [/store_unit]

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

                # prevent the miner to be used twice this turn
                {VARIABLE miner.status.digged yes}

                # 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]

    [event]
        name=side turn end
        first_time_only=no

        [modify_unit]
            [filter]
                [filter_wml]
                    [status]
                        digged=yes
                    [/status]
                [/filter_wml]
            [/filter]
            [status]
                digged=no
            [/status]
        [/modify_unit]
    [/event]
User avatar
pyrophorus
Posts: 533
Joined: December 1st, 2010, 12:54 pm

Re: Dig ability

Post by pyrophorus »

trewe wrote:

Code: Select all

                # prevent the miner to be used twice this turn
                {VARIABLE miner.status.digged yes}

How ? You don't use this flag in any filter.
BTW, the really difficult problem (finding at the same time who shall dig and where) is avoided. :D

Friendly,
User avatar
ChaosRider
Posts: 846
Joined: April 15th, 2012, 1:15 pm

Re: Dig ability

Post by ChaosRider »

I think you guys could see already one place which is a problem, what when near such a cavewall are 2 dwarvish miners, they dont have to be near same hex (x,y) which is a cave wall. To fix this problem i think it will be better to filter last selected unit (and if it a dwarvish miner with this ability and with 3 mp or more then show up this menu near this last selected unit :P).
edit:
units with 3 or more mp cant go by this part in filter:
"formula="moves >= 3""

edit 2:

Why the hell code which is working ok (for summoners to summon) dont work after changing name of variables (to dont have same as in summoners code), deleting part of creating new unit on hex on which in my code i change terrain? Even without changing filters to make this ability able for units with 3 or more mp (in summoners code to work it is required max movement points and attack left) filter dont work well. Units pass first filter but in next one is problem cause unit who just digged dont have decreased mp and dont get 1 xp...

Spoiler:
Spoiler:
Spoiler:
edit 3:

Fixed :P, with a bit help of Dugi, this formula dont work :P when its in filter units cant go by this filter...
Spoiler:
Spoiler:
Spoiler:
Last edited by ChaosRider on November 29th, 2013, 10:12 am, edited 1 time in total.
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
pyrophorus
Posts: 533
Joined: December 1st, 2010, 12:54 pm

Re: Dig ability

Post by pyrophorus »

Actually, what you want is:
- first select a digger.
- right-click a cave wall to dig it ?
If so, I think I can do something for you...

Friendly,
Post Reply