Relative directional data

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
hyper_cubed
Posts: 33
Joined: March 31st, 2018, 7:52 pm
Location: USA

Relative directional data

Post by hyper_cubed »

I am not sure if there is a better way to do this, but I created a macro that will tell you where the adjacent unit is in relation to the primary unit. I intend to create a 1.12 friendly rotation macro. I use this primarily for events, but I am sure it can be used for other things.

As long as you can provide the x,y coordinates of both the primary and adjacent, you can feed them into this macro and it will deliver a direction stored in variable "i_facing_ii" which once you are done with it, you can clear it. This can be reversed by feeding the secondary into where you would expect the primary and then primary into the other.

Code: Select all

#define i_facing_ii primary_x primary_y secondary_x secondary_y
{VARIABLE test_x {secondary_x}}
{VARIABLE test_y {secondary_y}}
{VARIABLE i_facing_iix {primary_x}}
{VARIABLE i_facing_iiy {primary_y}}
{VARIABLE_OP i_facing_iix sub {secondary_x}}
{VARIABLE_OP i_facing_iiy sub {secondary_y}}
{VARIABLE i_facing_ii ""}
[if]
	[variable]
		name=test_x
		greater_than=1
	[/variable]
	[then]
		{VARIABLE odd $test_x}
		{VARIABLE_OP odd modulo "2"}
	[/then]
	[else]
		{VARIABLE odd "1"}
	[/else]
[/if]
[if]
	[variable]
		name=test_x
		numerical_equals=0
	[/variable]
	[then]
		{VARIABLE odd "0"}
	[/then]
[/if]
[if]
	[variable]
		name=odd
		numerical_equals=0
	[/variable]
	[then]
		[if]
			[variable]
				name=i_facing_iix
				numerical_equals=0
			[/variable]
			[and]
			[variable]
				name=i_facing_iiy
				numerical_equals=1
			[/variable]
			[/and]
			[then]
				{VARIABLE i_facing_ii "n"}
			[/then]
		[/if]
		[if]
			[variable]
				name=i_facing_iix
				numerical_equals=-1
			[/variable]
			[and]
			[variable]
				name=i_facing_iiy
				numerical_equals=1
			[/variable]
			[/and]
			[then]
				{VARIABLE i_facing_ii "ne"}
			[/then]
		[/if]
		[if]
			[variable]
				name=i_facing_iix
				numerical_equals=-1
			[/variable]
			[and]
			[variable]
				name=i_facing_iiy
				numerical_equals=0
			[/variable]
			[/and]
			[then]
				{VARIABLE i_facing_ii "se"}
			[/then]
		[/if]
		[if]
			[variable]
				name=i_facing_iix
				equals=0
			[/variable]
			[and]
			[variable]
				name=i_facing_iiy
				equals=-1
			[/variable]
			[/and]
			[then]
				{VARIABLE i_facing_ii "s"}
			[/then]
		[/if]
		[if]
			[variable]
				name=i_facing_iix
				equals=1
			[/variable]
			[and]
			[variable]
				name=i_facing_iiy
				equals=0
			[/variable]
			[/and]
			[then]
				{VARIABLE i_facing_ii "sw"}
			[/then]
		[/if]
		[if]
			[variable]
				name=i_facing_iix
				equals=1
			[/variable]
			[and]
			[variable]
				name=i_facing_iiy
				equals=1
			[/variable]
			[/and]
			[then]
				{VARIABLE i_facing_ii "nw"}
			[/then]
		[/if]
	[/then]
[/if]
[if]
	[variable]
		name=odd
		numerical_equals=1
	[/variable]
	[then]
		[if]
			[variable]
				name=i_facing_iix
				numerical_equals=0
			[/variable]
			[and]
			[variable]
				name=i_facing_iiy
				numerical_equals=1
			[/variable]
			[/and]
			[then]
				{VARIABLE i_facing_ii "n"}
			[/then]
		[/if]
		[if]
			[variable]
				name=i_facing_iix
				numerical_equals=-1
			[/variable]
			[and]
			[variable]
				name=i_facing_iiy
				numerical_equals=0
			[/variable]
			[/and]
			[then]
				{VARIABLE i_facing_ii "ne"}
			[/then]
		[/if]
		[if]
			[variable]
				name=i_facing_iix
				numerical_equals=-1
			[/variable]
			[and]
			[variable]
				name=i_facing_iiy
				numerical_equals=-1
			[/variable]
			[/and]
			[then]
				{VARIABLE i_facing_ii "se"}
			[/then]
		[/if]
		[if]
			[variable]
				name=i_facing_iix
				equals=0
			[/variable]
			[and]
			[variable]
				name=i_facing_iiy
				equals=-1
			[/variable]
			[/and]
			[then]
				{VARIABLE i_facing_ii "s"}
			[/then]
		[/if]
		[if]
			[variable]
				name=i_facing_iix
				equals=1
			[/variable]
			[and]
			[variable]
				name=i_facing_iiy
				equals=-1
			[/variable]
			[/and]
			[then]
				{VARIABLE i_facing_ii "sw"}
			[/then]
		[/if]
		[if]
			[variable]
				name=i_facing_iix
				equals=1
			[/variable]
			[and]
			[variable]
				name=i_facing_iiy
				equals=0
			[/variable]
			[/and]
			[then]
				{VARIABLE i_facing_ii "nw"}
			[/then]
		[/if]
	[/then]
[/if]
{CLEAR_VARIABLE test_x}
{CLEAR_VARIABLE test_y}
{CLEAR_VARIABLE i_facing_iix}
{CLEAR_VARIABLE i_facing_iiy}
{CLEAR_VARIABLE odd}
#enddef
User avatar
Sapient
Inactive Developer
Posts: 4453
Joined: November 26th, 2005, 7:41 am
Contact:

Re: Relative directional data

Post by Sapient »

I'm sure you are aware of this, but just in case: I would like to remind any readers that there exists [store_relative_direction] for versions 1.13 and greater.
http://www.wesnoth.org/wiki/User:Sapient... "Looks like your skills saved us again. Uh, well at least, they saved Soarin's apple pie."
hyper_cubed
Posts: 33
Joined: March 31st, 2018, 7:52 pm
Location: USA

Re: Relative directional data

Post by hyper_cubed »

Sapient wrote: April 27th, 2018, 8:59 pm I'm sure you are aware of this, but just in case: I would like to remind any readers that there exists [store_relative_direction] for versions 1.13 and greater.
Wow, that is awesome. I was not aware of that. I started building what I was building because I wanted to create a rotate function that would work for 1.12.

Thanks Sapient. And if you are reading this and are only concerned with 1.13, then ignore my code.
Post Reply