Custom Teleportation 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.
Post Reply
aaronwright
Posts: 11
Joined: January 5th, 2023, 8:40 pm

Custom Teleportation Ability

Post by aaronwright »

Hey all, I've been playing around with a custom teleportation ability for a campaign I'm working on. The campaign is big on stealth tactics, and moving units around to different parts of the map via teleportation. Most non-teleporting units move fast enough to not be a hindrance to the play style, but I'm finding that the Wose often get left behind as combat shifts to a new area.

So I've developed a new ability for Wose in my campaign that I think will be balanced enough, and not too OP. The ability grants teleportation between forest hexes. That alone would be too powerful given the maps I'm playing on, so I want to limit it to forest hexes adjacent to another unit of the same side. That way as troops move to a new area (with forest), existing Wose units can teleport there and be part of the combat.

The ability was difficult to create because the target location's [filter_adjacent] subfilter doesn't seem to have access to the teleport_unit variable that is available in the main location filters. Because of this, I can't test the side of an adjacent unit against the side of the teleporting unit. I was able to make it so that the unit can teleport to forest hexes with any unit adjacent, but limiting it to units on my side seems impossible without a hack.

I did finally come up with a hack for what I need, but the UI seems a little sluggish, and understandably so. Below is the functioning code; does anyone more experienced with formulas have any idea how to do this in a more efficient manner?

Code: Select all

#define RO_ABILITY_TRANSPLANT
    # Canned definition of the TRANSPLANT ability to be included in an
    # [abilities] clause.
    [teleport]
        id=ro_transplant
        name= _ "transplant"
        female_name= _ "female^transplant"
        description= _ "This unit may teleport from a forest hex to a different forest hex that has a unit from the same side adjacent to it."
        special_note= _ "This unit may teleport from a forest hex to a different forest hex that has a unit from the same side adjacent to it."
        [tunnel]
            id=ro_transplant
            [source]
                terrain=*^F*
            [/source]

            [target]
                terrain=*^F*
				[filter_adjacent_location]
					[filter]  # included for efficiency, to reduce the tiles being sought by the below formula.
					[/filter] # can't filter by side here because there doesn't seem to be a way to get the teleport_unit variable in this context.
				[/filter_adjacent_location]
				formula="
					debug(teleport_unit.side_number = unit_at(loc(x, y + 1)).side_number) or
					debug(teleport_unit.side_number = unit_at(loc(x, y - 1)).side_number) or
					debug(teleport_unit.side_number = unit_at(loc(x + 1, y)).side_number) or
					debug(teleport_unit.side_number = unit_at(loc(x + 1, y + ydir)).side_number) or
					debug(teleport_unit.side_number = unit_at(loc(x - 1, y)).side_number) or
					debug(teleport_unit.side_number = unit_at(loc(x - 1, y + ydir)).side_number)
				where
					ydir = if (x % 2 = 0, 1, -1)
				"
#				[filter_adjacent_location]
#					[filter]
#						side=$teleport_unit.side_number
#					[/filter]
#				[/filter_adjacent_location]
            [/target]

            [filter]
                ability=ro_transplant
            [/filter]
        [/tunnel]
    [/teleport]
#enddef
User avatar
Pentarctagon
Project Manager
Posts: 5564
Joined: March 22nd, 2009, 10:50 pm
Location: Earth (occasionally)

Re: Custom Teleportation Ability

Post by Pentarctagon »

No idea if it would affect anything, but the debug()s are probably not meant to be present in the final code?
99 little bugs in the code, 99 little bugs
take one down, patch it around
-2,147,483,648 little bugs in the code
User avatar
Helmet
Posts: 641
Joined: December 19th, 2006, 5:28 pm
Location: Florida, USA

Re: Custom Teleportation Ability

Post by Helmet »

aaronwright wrote: January 9th, 2023, 3:19 pmRO_ABILITY_TRANSPLANT
You created a great name for this ability. :lol:

A Wose teleporting to a friendly unit? It seems to me that this has the potential for exploitation. The player only has to move one unit near the enemy leader, then several Wose units could teleport into the area.

Might I suggest a different solution?

Perhaps allow Wose units to teleport to grass terrain with wildflower embellishments, then carefully place those terrain tiles in locations that allow the Wose units to keep-up with the army.

The wildflowers could be "activated" just like villages by the faster units.

Or maybe simply create a new type of Wose unit that moves faster.

Good luck!
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: 3000
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Custom Teleportation Ability

Post by Ravana »

Instead of teleporting next to unit, teleport on top of unit. Then you have access to variable, at the cost of 1 mp more for teleport action. https://github.com/ProditorMagnus/Agele ... ai.cfg#L45
User avatar
egallager
Posts: 583
Joined: November 19th, 2020, 7:27 pm
Location: Concord, New Hampshire
Contact:

Re: Custom Teleportation Ability

Post by egallager »

So, in Genesis, one of Yumi's AMLA abilities gives her an ability to teleport next to friendly units, and it caused a major performance hit for me whenever I tried to use it: https://github.com/nemaara/Genesis/issues/5
aaronwright
Posts: 11
Joined: January 5th, 2023, 8:40 pm

Re: Custom Teleportation Ability

Post by aaronwright »

Great, thanks all for the recommendations and links! @Helmet, thanks for the thoughts on the potential for abuse. I've playtested two scenarios with it today, and while it's sped up the play a few turns, it hasn't broken it. What you're describing is actually the effect I'm going for. The scenarios are weighted strongly against the player, such that you have to do a lot of running and stealth (ambush / submerge etc.) Also, you usually can't recruit at the same rate as the enemy. The way to win these scenarios is basically to run, hide, and then do surgical "drop-in" strikes on the enemy. So the effect with the Wose has actually been perfect, so far.

That said, depending on how the playtesting goes, I might back away and do something like what you're describing. Another option I looked at was using Great Tree tiles as the teleport points for Wose.
User avatar
Celtic_Minstrel
Developer
Posts: 2207
Joined: August 3rd, 2012, 11:26 pm
Location: Canada
Contact:

Re: Custom Teleportation Ability

Post by Celtic_Minstrel »

Just noting that you don't need to manually enumerate the adjacent locations if using a formula. There is a WFL function adjacent_locs(centre) that does it for you and returns a list, so you can iterate through it with functions like map or filter or whatever you need.

There are quite a few undocumented WFL functions like that… I really need to sit down and fix the missing documentation there…
Author of The Black Cross of Aleron campaign and Default++ era.
Former maintainer of Steelhive.
aaronwright
Posts: 11
Joined: January 5th, 2023, 8:40 pm

Re: Custom Teleportation Ability

Post by aaronwright »

Oh that's great information, thanks! I'll give it a try
aaronwright
Posts: 11
Joined: January 5th, 2023, 8:40 pm

Re: Custom Teleportation Ability

Post by aaronwright »

Circling back to this thread. I took Celtic Minstrel's suggestion and refactored the ability to use adjacent_locs, a much more elegant solution. The final code:

Code: Select all

#define RO_ABILITY_TRANSPLANT
    # Canned definition of the TRANSPLANT ability to be included in an
    # [abilities] clause.
    [teleport]
        id=ro_transplant
        name= _ "transplant"
        female_name= _ "female^transplant"
        description= _ "This unit may teleport from a forest hex to a different forest hex that has a unit from the same side adjacent to it."
        special_note= _ "This unit may teleport from a forest hex to a different forest hex that has a unit from the same side adjacent to it."
        [tunnel]
            id=ro_transplant
            [source]
                terrain=*^F*
            [/source]

            [target]
                terrain=*^F*
				[filter_adjacent_location]
					[filter]  # included for efficiency, to reduce the tiles being sought by the below formula.
					[/filter] # can't filter by side here because there doesn't seem to be a way to get the teleport_unit variable in this context.
				[/filter_adjacent_location]
				formula="
					find(adjacent_locs(loc(x, y)), unit_at(self).side_number = teleport_unit.side_number) != null()
				"
            [/target]

            [filter]
                ability=ro_transplant
            [/filter]
        [/tunnel]
    [/teleport]
#enddef
If anyone would like to try it out, the campaign is available for download on the add-on server, under the name "Rogue Order." The ability comes into play with the Wose units in scenario 2, and I think it's turning out to be a lot of fun to teleport Wose around the map :p. Feedback thread for the campaign is here:

viewtopic.php?t=56699

Thanks again for all the help guys!
User avatar
Spannerbag
Posts: 535
Joined: December 18th, 2016, 6:14 pm
Location: Yes

Re: Custom Teleportation Ability

Post by Spannerbag »

Just a thought but Celtic_Minstrel's campaign The Black Cross of Aleron has ABILITY_TREEWALK:

description=_"This unit may teleport between any two living great trees using one of its moves."

The campaign is on the 1.14 server and can be downloaded as a compressed file if you don't have Wesnoth 1.14 installed, though you'll need to decompress it manually.

The advantage is that all you need is the ability and a map with appropriate terrain.
Hope Celtic_Minstrel won't mind but here's the ability code:

Code: Select all

#define ABILITY_TREEWALK
	[teleport]
		id=treewalk
		name=_"treewalk"
		female_name=_"female^treewalk"
		description=_"This unit may teleport between any two living great trees using one of its moves."
		[tunnel]
			id=tree_teleport
			allow_vision=no
			[source]
				terrain=*^Fet
				formula="
					unit = teleport_unit or not unit
				where
					unit = unit_at(loc)
				"
			[/source]

			[target]
				terrain=*^Fet
				formula="not unit_at(loc)"
			[/target]

			[filter]
				ability=treewalk
			[/filter]
		[/tunnel]
	[/teleport]
#enddef
It should work on 1.16 but I haven't tested it.

Hope this helps.

Oh, and if you do use this code, it'd be sporting to credit Celtic_Minstrel :)

Cheers!
-- Spannerbag
SP Campaigns: After EI (v1.14) Leafsea Burning (v1.17, v1.16)
I suspect the universe is simpler than we think and stranger than we can know.
Also, I fear that beyond a certain point more intelligence does not necessarily benefit a species...
aaronwright
Posts: 11
Joined: January 5th, 2023, 8:40 pm

Re: Custom Teleportation Ability

Post by aaronwright »

Nice! I'll definitely consider it.

I actually considered something similar when I was trying to create a tree teleportation ability (focusing on great trees). The problem was that all my scenarios use shroud, and unlike village-driven teleportation, Wose would provide the player with access (and vision) to all great trees and their surrounding hexes at the beginning of the scenario. So I went for a solution that required the user to have a unit beside the teleport destination.

Might be worth adding that ability as a level 3 Sylver Wose thing. If the player sufficiently levels a Wose, it probably wouldn't break things too badly to give them a way to clear shroud near great trees as a reward. I'd need to play through again with that in place though, to make sure it wasn't too powerful. Definitely will credit Minstrel if I do (I need longer campaign credits to keep the final song playing :-))
User avatar
Celtic_Minstrel
Developer
Posts: 2207
Joined: August 3rd, 2012, 11:26 pm
Location: Canada
Contact:

Re: Custom Teleportation Ability

Post by Celtic_Minstrel »

My treewalk is certainly a little different from what he had in mind, and requires a map built to support the unit (with Great Trees scattered across it). If this is for a campaign that's fine, but if it's for a multiplayer era it would probably be a really bad choice.

I don't mind people taking code from my campaign. I'd maybe object if they stole dialogue or that sort of thing, but not code.

For the record, this is not really true:
aaronwright wrote: February 19th, 2023, 5:59 pm unlike village-driven teleportation, Wose would provide the player with access (and vision) to all great trees and their surrounding hexes at the beginning of the scenario.
The treewalk ability in my campaign does not uncover shroud. As far as I know, a teleport ability never uncovers shroud. So, you can only teleport to trees that are visible on the map.

The default behaviour is that it does uncover fog, so if the trees are all visible you'll get vision on the adjacent hexes. In my treewalk ability, the allow_vision=no line disables that, so you won't be able to see what units are near those trees unless you teleport there. (It does allow you to teleport there though.)
Author of The Black Cross of Aleron campaign and Default++ era.
Former maintainer of Steelhive.
aaronwright
Posts: 11
Joined: January 5th, 2023, 8:40 pm

Re: Custom Teleportation Ability

Post by aaronwright »

Okay, thanks for clarifying that. My comments are based off of newer teleport behaviour, which clears shroud at the destination by default, but I forgot there was a toggle (allow_vision) that allows you to turn that off. According to the docs, allow_vision impacts both fog and shroud, so it would solve the shroud issue that I mentioned.
allow_vision: (boolean, default: yes) (Version 1.13.6 and later only) If no, vision through a tunnel is not possible. Note that in that case the tunnel cannot be used if the tunnel exit is under shroud (which previously was always the case).
https://wiki.wesnoth.org/DirectActionsWML#.5Btunnel.5D

Thanks!
Wecth
Posts: 13
Joined: April 14th, 2023, 9:07 am

Re: Custom Teleportation Ability

Post by Wecth »

Could I see the code for your custom teleportation ability as I am trying to do something similar myself
gnombat
Posts: 706
Joined: June 10th, 2010, 8:49 pm

Re: Custom Teleportation Ability

Post by gnombat »

Wecth wrote: April 14th, 2023, 9:09 am Could I see the code for your custom teleportation ability as I am trying to do something similar myself
The add-on is Rogue Order so you can download that and find the latest version of the code in there.
Post Reply