Teleport Formula Help

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.
Scadstorm
Posts: 7
Joined: August 10th, 2022, 9:17 pm

Teleport Formula Help

Post by Scadstorm »

Hi,

I'm trying to figure out a way to make a teleport ability that allows the unit to go anywhere from anywhere. I based it on the original teleport ability but haven't found a way to get the desired results. It currently looks like this:

Code: Select all

    [teleport]
        id=greater teleportation
        name= _ "greater teleportation"
        female_name= _ "female^greater^teleportation"
        description= _ "This unit may teleport between anywhere using one of its moves."
        special_note={INTERNAL:SPECIAL_NOTES_GREATER_TELEPORTATION}
        [tunnel]
            id=anywhere_teleport
            [source]
            [/source]
            [target]
                terrain=*^A*,*^B*,*^C*,*^D*,*^E*,*^F*,*^G*,*^H*,*^I*,*^K*,*^M*,*^R*,*^S*,*^T*,*^U*,*^V*,*^W*
            [/target]

            [filter]
                ability=greater teleportation
            [/filter]
        [/tunnel]
    [/teleport]
User avatar
Celtic_Minstrel
Developer
Posts: 2166
Joined: August 3rd, 2012, 11:26 pm
Location: Canada
Contact:

Re: Teleport Formula Help

Post by Celtic_Minstrel »

Did you try putting terrain=*^* in both source and target?

That said, I think this ability is a very bad idea. A unit that can appear anywhere at any time and vanish just as fast seems very overpowered, and I also suspect there might be an issue with pathfinding when every hex is connected to every other hex. I don't know what kind of restriction could be added to get the same feel without the potential issues, but I think some sort of restriction is needed.

Of course, if making it totally overpowered is the intention, you can ignore what I just said.
Author of The Black Cross of Aleron campaign and Default++ era.
Former maintainer of Steelhive.
Scadstorm
Posts: 7
Joined: August 10th, 2022, 9:17 pm

Re: Teleport Formula Help

Post by Scadstorm »

Thanks!

Actually, one of the earlier versions of this formula included your suggestions but it didn't work so I removed the source just to check if it will work. I agree that the ability is overpowered but to give context, I was actually trying to recreate the protagonist from Overlord anime and one of his ability is "Greater Teleportation" which allowed him to go anywhere for as long as he knows where to go. He did have the ability to also stop time (which gave his opponents an impression that he can blink in and out of their ranks) so I might settle for recreating that instead if editing the teleportation formula will be too troublesome.
User avatar
Celtic_Minstrel
Developer
Posts: 2166
Joined: August 3rd, 2012, 11:26 pm
Location: Canada
Contact:

Re: Teleport Formula Help

Post by Celtic_Minstrel »

That sounds like "teleport to any unshrouded tile" to me, but I don't think there's a way to filter on shroud. Or wait… there's [filter_vision] which might handle it? I think that's more for fog than shroud but it might handle both…

Supposing you do want greater teleportation, you may want to think more carefully on what that actually means. If it's "teleport from any hex to any hex", then on a field of grass the unit can hop all over the map as much as it wants until it enters someone's zone of control and loses all movement points. There's basically no reason for such a unit to have move costs higher than 1 or more than 1 movement point, because it can get anywhere it wants in a single-hex move and the only use-case for hopping around like I described would be exploration. Maybe this isn't quite what you had in mind. If that's true and you can describe more precisely what you want, I may be able to suggest some ideas. On the other hand, if that is what you wanted, I can make different suggestions.

By the way, there's no reason to use an "INTERNAL" macro in your ability. The only reason mainline macros do this is so that the string can be in one place to support both old-style and new-style special notes. You can just put the description right there in the definition.
Author of The Black Cross of Aleron campaign and Default++ era.
Former maintainer of Steelhive.
Scadstorm
Posts: 7
Joined: August 10th, 2022, 9:17 pm

Re: Teleport Formula Help

Post by Scadstorm »

I know that I won't be using fog or shroud should I make a map or campaign with the unit because there's no way to guarantee that there won't be an enemy unit within the fog or shroud.

You're correct that I originally wanted a from any hex to any hex kind of teleportation and the unit did have only one MP. I was actually thinking of giving him separate teleportation abilities per terrain but I feel it will be too much clutter and might not work.

Thank you for letting me know about the internal macro. The last time I made a map and units of my own was more than 10 years ago and only managed because I did a lot of copy pasting and editing.
User avatar
Celtic_Minstrel
Developer
Posts: 2166
Joined: August 3rd, 2012, 11:26 pm
Location: Canada
Contact:

Re: Teleport Formula Help

Post by Celtic_Minstrel »

Okay, for any-hex-to-any-hex, I think the general approach for the filter should be ""an unoccupied hex" as the target. So that ends up looking something like this:

Code: Select all

[source]
[/source]
[target]
	[not]
		[unit]
		[/unit]
	[/not]
[/target]
The target is a standard location filter, and [unit] in a standard location filter means there has to be a unit match that filter on the location (an empty unit filter matches any unit). So, inverting that means there is no unit on that location.

Does that work?

I have no idea if there would be problems arising from the highly-connected map. Maybe it makes pathfinding slower, but it might actually make it faster. It's essentially a complete graph from this unit's point of view, so technically there should be no work needed to find a path.
Author of The Black Cross of Aleron campaign and Default++ era.
Former maintainer of Steelhive.
Scadstorm
Posts: 7
Joined: August 10th, 2022, 9:17 pm

Re: Teleport Formula Help

Post by Scadstorm »

I tried the suggestion but it didn't work. It currently looks like this:

Code: Select all

        [tunnel]
            id=anywhere_teleport
            [source]
            [/source]
            [target]
                [not]
		   [unit]
		   [/unit]
		[/not]
            [/target]

            [filter]
                ability=greater teleportation
            [/filter]
        [/tunnel]
Now it won't even teleport to owned villages but that is no surprise. If all else fails I guess I can substitute either no MP cost or plenty of MP with skirmish to achieve the same results.
User avatar
Ravana
Forum Moderator
Posts: 2949
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Teleport Formula Help

Post by Ravana »

I tested teleport-everywhere with this and for me it worked.

Code: Select all

[remove_event]
	id=Rav_EventLoader_Event_1
[/remove_event]
[event]
	name=side_turn
	first_time_only=no
	# id is needed to not load multiple versions of event at once
	id=Rav_EventLoader_Event_1
	[tunnel]
		[filter]
			side=1
		[/filter]
		[source]
			formula=1
		[/source]
		[target]
			formula=1
		[/target]
		bidirectional=no
	[/tunnel]
	[lua]
		code=<<
wesnoth.message("event loaded")
>>
	[/lua]
[/event]
bidirectional=no is just performance hint. I would never put space in id. There is no need to filter if unit is on target, you cant get on top of it anyways. If you put it in [teleport] then you probably need to leave [filter] empty.
User avatar
Celtic_Minstrel
Developer
Posts: 2166
Joined: August 3rd, 2012, 11:26 pm
Location: Canada
Contact:

Re: Teleport Formula Help

Post by Celtic_Minstrel »

Scadstorm wrote: August 15th, 2022, 2:36 am I tried the suggestion but it didn't work. It currently looks like this:

Code: Select all

        [tunnel]
            id=anywhere_teleport
            [source]
            [/source]
            [target]
                [not]
		   [unit]
		   [/unit]
		[/not]
            [/target]

            [filter]
                ability=greater teleportation
            [/filter]
        [/tunnel]
Now it won't even teleport to owned villages but that is no surprise. If all else fails I guess I can substitute either no MP cost or plenty of MP with skirmish to achieve the same results.
Does it work if you take out the filter and do what Ravana did, putting the tunnel in an event instead of an ability? Leaving target empty as well is also an option (Ravana's formula=1 is equivalent to an empty tag).
Author of The Black Cross of Aleron campaign and Default++ era.
Former maintainer of Steelhive.
User avatar
Ravana
Forum Moderator
Posts: 2949
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Teleport Formula Help

Post by Ravana »

I was not sure which context has empty mean all and which nothing, so generally trying to avoid empty filters.
Scadstorm
Posts: 7
Joined: August 10th, 2022, 9:17 pm

Re: Teleport Formula Help

Post by Scadstorm »

Thank you both. I have tried it but it did not work for me. I'm sure I'm not using it correctly somehow because it worked for you. I think because I put it in the ability but if not there, where can I? It currently looks like this:

Code: Select all

#define ABILITY_GREATER_TELEPORTATION
    # Canned definition of the TELEPORT ability to be included in an
    # [abilities] clause.
    [teleport]
        id=greater teleportation
        name= _ "greater teleportation"
        female_name= _ "female^greater^teleportation"
        description= _ "This unit may teleport between anywhere using one of its moves."
[remove_event]
	id=Rav_EventLoader_Event_1
[/remove_event]
[event]
	name=side_turn
	first_time_only=no
	# id is needed to not load multiple versions of event at once
	id=Rav_EventLoader_Event_1
	[tunnel]
		[filter]
			side=1
		[/filter]
		[source]
			formula=1
		[/source]
		[target]
			formula=1
		[/target]
		bidirectional=no
	[/tunnel]
	[lua]
		code=<<
wesnoth.message("event loaded")
>>
	[/lua]
[/event]
    [/teleport]
#enddef
User avatar
Celtic_Minstrel
Developer
Posts: 2166
Joined: August 3rd, 2012, 11:26 pm
Location: Canada
Contact:

Re: Teleport Formula Help

Post by Celtic_Minstrel »

That's totally and utterly wrong. I'm saying, copy the tunnel from in the ability, and move it into an event in a scenario. If the filters are correct, every unit should be able to teleport. If that works, you know the issue isn't in the tunnel but is something else in the ability definition.

An event or remove_event in an ability does nothing. It's just ignored.
Author of The Black Cross of Aleron campaign and Default++ era.
Former maintainer of Steelhive.
User avatar
Ravana
Forum Moderator
Posts: 2949
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Teleport Formula Help

Post by Ravana »

That means [event]name=start [tunnel definition...][/event].

[remove_event] was just part of my framework used to load new wml without having to refresh wesnoth cache.
Scadstorm
Posts: 7
Joined: August 10th, 2022, 9:17 pm

Re: Teleport Formula Help

Post by Scadstorm »

Then I guess I will also have to create a scenario first to test this. I only have created the unit and some of it's abilities so far and haven't created a scenario/campaign just yet. If it does work as an event rather than an ability, that means the unit's capability to teleport anywhere will depend on the map/scenario it's in and I will have to remove the ability as it won't work on its own anyway?
User avatar
Ravana
Forum Moderator
Posts: 2949
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Teleport Formula Help

Post by Ravana »

If it turns out to need event then you can use +tag syntax to include event in ability file. https://github.com/ProditorMagnus/Agele ... hifter.cfg
Post Reply