[move_unit] exactly one hex back

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
serclino
Posts: 40
Joined: May 18th, 2018, 9:54 pm

[move_unit] exactly one hex back

Post by serclino »

Hello,

how can I set up following: When player's units reached deep forest in my scenario, I want them to turn back and prevent them to go further to the trees. I already wrote this:

Code: Select all

[event]
	name=enter_hex
	first_time_only=no
	[filter]
		side=1
		x=10
		y=1-10
	[/filter]
	
	[message]
		speaker=unit
		message= _ "We should return back to the main path."
	[/message]
	
	[move_unit]
		x=10
		y=1-10
		
		#Here I don't know what I should write, because I would like to return unit EXACTLY one hex back.
		to_x=
		to_y=
	[/move_unit]
[/event]

So again: I would like to return unit EXACTLY one hex back.

Any ideas, please? Thank you.
User avatar
Pentarctagon
Project Manager
Posts: 5564
Joined: March 22nd, 2009, 10:50 pm
Location: Earth (occasionally)

Re: [move_unit] exactly one hex back

Post by Pentarctagon »

You could use the automatically stored variables y1/y2 and x1/x2.

So maybe something like:

Code: Select all

[move_unit]
	x=$x1
	y=$y1
	to_x=$x2
	to_y=$y2
[/move_unit]
based on what those values should be as per the wiki.
99 little bugs in the code, 99 little bugs
take one down, patch it around
-2,147,483,648 little bugs in the code
serclino
Posts: 40
Joined: May 18th, 2018, 9:54 pm

Re: [move_unit] exactly one hex back

Post by serclino »

Pentarctagon: Thank you :) It works.
User avatar
Celtic_Minstrel
Developer
Posts: 2207
Joined: August 3rd, 2012, 11:26 pm
Location: Canada
Contact:

Re: [move_unit] exactly one hex back

Post by Celtic_Minstrel »

In 1.15 the following should also work:

Code: Select all

[move_unit]
	x=$x1
	y=$y1
	dir=-$unit.facing
[/move_unit]
Basically, move the unit one space in the direction opposite the direction it's currently facing. But again, unless you patch in the capability (as I did in Black Cross), you need 1.15 for that to work.
Author of The Black Cross of Aleron campaign and Default++ era.
Former maintainer of Steelhive.
User avatar
octalot
General Code Maintainer
Posts: 786
Joined: July 17th, 2010, 7:40 pm
Location: Austria

Re: [move_unit] exactly one hex back

Post by octalot »

That would need a check for the hex being vacant, as units can move through hexes occupied by other friendly units.
User avatar
Ravana
Forum Moderator
Posts: 3002
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: [move_unit] exactly one hex back

Post by Ravana »

Previously unit.facing was unsynced, is that changed now?
User avatar
josteph
Inactive Developer
Posts: 741
Joined: August 19th, 2017, 6:58 pm

Re: [move_unit] exactly one hex back

Post by josteph »

Pretty sure it's still unsynced, and we should really not have synced and unsynced attributes in the same namespace, it should be something like unit.unsynced_facing, unit.unsynced_controller etc.
User avatar
Celtic_Minstrel
Developer
Posts: 2207
Joined: August 3rd, 2012, 11:26 pm
Location: Canada
Contact:

Re: [move_unit] exactly one hex back

Post by Celtic_Minstrel »

Though it may technically be unsynced, I believe you can at least rely on its value to be effectively synced after a unit has finished moving or attacking?
Author of The Black Cross of Aleron campaign and Default++ era.
Former maintainer of Steelhive.
User avatar
Ravana
Forum Moderator
Posts: 3002
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: [move_unit] exactly one hex back

Post by Ravana »

It was depending on animation settings, so attacking would be one case to get it out of sync.
User avatar
Celtic_Minstrel
Developer
Posts: 2207
Joined: August 3rd, 2012, 11:26 pm
Location: Canada
Contact:

Re: [move_unit] exactly one hex back

Post by Celtic_Minstrel »

I'm pretty sure it's guaranteed to be in sync after an attack? That may not have been the case in 1.12, but I'm fairly sure it's true in 1.14 – otherwise the backstab special probably wouldn't work properly.
Author of The Black Cross of Aleron campaign and Default++ era.
Former maintainer of Steelhive.
gfgtdf
Developer
Posts: 1432
Joined: February 10th, 2013, 2:25 pm

Re: [move_unit] exactly one hex back

Post by gfgtdf »

Hmm yes iirc you changed it to be set before every attack, still it's not set before predictions, this probably also effects the lua wesnoth.simulate_combat function by the way leading to possible oos (although that function is _mostly_ used in the air code where it if course won't cause oos(
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
josteph
Inactive Developer
Posts: 741
Joined: August 19th, 2017, 6:58 pm

Re: [move_unit] exactly one hex back

Post by josteph »

gfgtdf wrote: October 24th, 2019, 2:30 am Hmm yes iirc you changed it to be set before every attack, still it's not set before predictions, this probably also effects the lua wesnoth.simulate_combat function by the way leading to possible oos (although that function is _mostly_ used in the air code where it if course won't cause oos(
"air code"?
User avatar
Celtic_Minstrel
Developer
Posts: 2207
Joined: August 3rd, 2012, 11:26 pm
Location: Canada
Contact:

Re: [move_unit] exactly one hex back

Post by Celtic_Minstrel »

I think he means AI code.
Author of The Black Cross of Aleron campaign and Default++ era.
Former maintainer of Steelhive.
Post Reply