Goto https://www.stucuk.netGoto https://www.atlanticaonlinewiki.comGoto https://www.game-requirements.com


Menu


It is currently Sun Aug 19, 2018 1:38 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Find turn direction
PostPosted: Tue Feb 23, 2010 2:18 am 
Offline
Moderator
Moderator
User avatar

Joined: Mon Mar 17, 2008 6:03 pm
Posts: 1129
Location: Denmark
When you use ComTurnXY the unit turns to the specified hex but is there a way to predict in what direction the unit will turn? Oh yes there is :P and the algorithm isn't that hard at all.
This function returns the direction a unit on hex [x1,y1] wouldturn to if it was asked to turn to hex [x,y] with ComTurnXY.

Code:
Export Function GetTurnDirection(x1,y1,x,y);
     var dist_1, dist_2, a, temp_dist, dir;
     begin
          dist_1 = GetDistXY(x1,y1,x,y);
          dist_2 = 99999;

          for a = 0 to 5 do
               begin
                    temp_dist = GetDistXY(ShiftX(x1,a,dist_1),ShiftY(y1,a,dist_1),x,y);
                    if temp_dist < dist_2 then
                         begin
                              dist_2 = temp_dist;
                              dir = a;
                         end;
               end;

          result = dir;
     end;

_________________
I have an if that has an else, but that if has another if with an else inside... My question is... If an if has an else, if there is more than one line in that if, should it have a begin and an end?


Top
 Profile  
 
 Post subject: Re: Find turn direction
PostPosted: Mon Mar 08, 2010 1:13 pm 
Offline
Moderator
Moderator
User avatar

Joined: Fri Jan 13, 2006 6:20 pm
Posts: 2325
Location: Argentina
I don't understand why you use the GetDist function... :?

_________________
-Aleph.

THE Very active person

"You can only do well at something if you put the time in. Doesn't matter what subject it is. You can't make a master piece over night."
Wise man Stu-


Top
 Profile  
 
 Post subject: Re: Find turn direction
PostPosted: Mon Mar 08, 2010 3:42 pm 
Offline
Moderator
Moderator
User avatar

Joined: Mon Mar 17, 2008 6:03 pm
Posts: 1129
Location: Denmark
The idea is that you first find the distance bestween the two hexes [x,y] and [x1,y1]. Then you find the hex in that distance away from [x1,y1] in each direction (ShiftX and ShiftY). The one of thoses hexes which is closest to [x,y] is the one the unit on hex [x1,y1] will face if asked to turn to [x,y].

On the image below:
Because the distance "B" is smaller than the distance "A", the soldier in the lower part of the picture will face direction 0 if asked to turn to the hex the other soldier occupies.


Attachments:
GetTurnDirection.JPG
GetTurnDirection.JPG [ 17.81 KiB | Viewed 1133 times ]

_________________
I have an if that has an else, but that if has another if with an else inside... My question is... If an if has an else, if there is more than one line in that if, should it have a begin and an end?
Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group

Original War is an RTS / RPG game by Altar Games
Original War Support is not part of Altar Games but is maintaining Original War for Altar Games

Privacy Policy