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


Menu


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

All times are UTC [ DST ]




Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: Turning a vehicle to the right direction
PostPosted: Tue Jul 14, 2009 2:05 pm 
Offline
Moderator
Moderator
User avatar

Joined: Mon Mar 17, 2008 6:03 pm
Posts: 1129
Location: Denmark
In the General Modding forum I posted the subject 'ComTurnUnit and ComTurnXY [v. 1.10b]' where I complained why vehicles wouldn't turn using those function. The obvious reason was (as gwren1, stucuk and Radzio pointed out) that a vehicle can't turn on the spot - they need to move in order to do turn around. Since then I have experimented a little and finally created this function which can turn a vehicle even if obstacles is in it's way.

Code:
Export Function ComTurnVehicle(vehicle, direction);
     var dir_veh, n1, n2, list_anti_clockwise, x, y, stuck, completely_stuck;
     begin
          If GetDir(vehicle) <> direction and GetType(vehicle) = unit_vehicle and IsOk(vehicle) then
               begin
                    dir_veh = GetDir(vehicle);
                    n1 = dir_veh - 1;
                    n2 = dir_veh - 2;
                    if n1 = - 1 then n1 = 5;
                    if n2 = - 1 then n2 = 5;
                    if n2 = - 2 then n2 = 4;
                    list_anti_clockwise = [n1, n2];

                    x = GetX(vehicle);
                    y = GetY(vehicle);
                    stuck = 0;
                    completely_stuck = 0;

                    repeat
                    if direction in list_anti_clockwise and GetDir(vehicle) <> direction and completely_stuck <= 1 or stuck = 1 and GetDir(vehicle) <> direction and completely_stuck <= 1 then
                         begin
                              repeat
                              if GetDir(vehicle) = 0 then ComMoveXY(vehicle, x-1, y-1);
                              if GetDir(vehicle) = 1 then ComMoveXY(vehicle, x, y-1);
                              if GetDir(vehicle) = 2 then ComMoveXY(vehicle, x+1, y);
                              if GetDir(vehicle) = 3 then ComMoveXY(vehicle, x+1, y+1);
                              if GetDir(vehicle) = 4 then ComMoveXY(vehicle, x, y+1);
                              if GetDir(vehicle) = 5 then ComMoveXY(vehicle, x-1, y);

                              repeat
                              Wait(0$0.1);
                              until IsIdle(vehicle) or Attacks(vehicle) or not IsOk(vehicle);

                              if IsAt(vehicle, x, y) and GetDir(vehicle) <> direction then
                                   begin
                                        stuck = 2;
                                        completely_stuck = completely_stuck + 1
                                   end
                              else
                                   begin
                                        AddComMoveXY(vehicle, x, y);

                                        repeat
                                        Wait(0$0.1);
                                        until IsAt(vehicle, x, y) or Attacks(vehicle) or not IsOK(vehicle);
                                   end;

                              until GetDir(vehicle) = direction or stuck = 2 or Attacks(vehicle) or not IsOk(vehicle);
                         end;
                    if not direction in list_anti_clockwise and GetDir(vehicle) <> direction and completely_stuck <= 1 or stuck = 2 and GetDir(vehicle) <> direction and completely_stuck <= 1 then
                         begin
                              repeat
                              if GetDir(vehicle) = 0 then ComMoveXY(vehicle, x+1, y);
                              if GetDir(vehicle) = 1 then ComMoveXY(vehicle, x+1, y+1);
                              if GetDir(vehicle) = 2 then ComMoveXY(vehicle, x, y+1);
                              if GetDir(vehicle) = 3 then ComMoveXY(vehicle, x-1, y);
                              if GetDir(vehicle) = 4 then ComMoveXY(vehicle, x-1, y-1);
                              if GetDir(vehicle) = 5 then ComMoveXY(vehicle, x, y-1);

                              repeat
                              Wait(0$0.1);
                              until IsIdle(vehicle) or Attacks(vehicle) or not IsOK(vehicle);

                              if IsAt(vehicle, x, y) and GetDir(vehicle) <> direction then
                                   begin
                                        stuck = 1;
                                        completely_stuck = completely_stuck + 1;
                                   end
                              else
                                   begin
                                        AddComMoveXY(vehicle, x, y);

                                        repeat
                                        Wait(0$0.1);
                                        until IsAt(vehicle, x, y) or Attacks(vehicle) or not IsOk(vehicle);
                                   end;

                              until GetDir(vehicle) = direction or stuck = 1 or Attacks(vehicle);
                         end;
                    until GetDir(vehicle) = direction or completely_stuck = 2 or Attacks(vehicle) or not IsOk(vehicle);
               end;
     end;


As you can see it's very long and tortuous but it works! (I have tested it several times). I would appreciate if some1 would take the trouble to clean the code a bit.
You could by the way make the function do something if the vehicle can't turn to the desired direction (if completely_stuck = 2), like displaying a message, but since such requires reference to the texts.txt dokument, I have leaved it out here.


EDIT1: The code will now stop running if the vehicle not IsOk


Last edited by McBenn on Mon Jul 27, 2009 10:45 am, edited 2 times in total.

Top
 Profile  
 
 Post subject: Re: Turning a vehicle to the right direction
PostPosted: Tue Jul 14, 2009 3:09 pm 
Offline
Moderator
Moderator
User avatar

Joined: Fri Jan 13, 2006 6:20 pm
Posts: 2325
Location: Argentina
McBenn wrote:
like displaying a message, but since such requires reference to the texts.txt dokument, I have leaved it out here.


Maybe link it to the "Destination Unreachable" message from Original War's main Messages?

And... IT WORKS! :D
100% Satisfaction Guaranteed.

_________________
-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:
PostPosted: Tue Jul 14, 2009 5:14 pm 
Offline
Soldier level 1
Soldier level 1
User avatar

Joined: Mon Nov 26, 2007 8:07 pm
Posts: 86
Location: Germany
Lol aleph.
Nice reply :)

_________________
MEMORIES, A OWAR MOD, PLEASE TRY OUT


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 14, 2009 7:28 pm 
Offline
Moderator
Moderator
User avatar

Joined: Mon Mar 17, 2008 6:03 pm
Posts: 1129
Location: Denmark
gwren1 wrote:
McBenn wrote:
like displaying a message, but since such requires reference to the texts.txt dokument, I have leaved it out here.



Maybe link it to the "Destination Unreachable" message from Original War's main Messages?


Good idea :) how to do?

And gwren1... since when did you change your avatar :o


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 14, 2009 7:50 pm 
Offline
Moderator
Moderator
User avatar

Joined: Fri Jan 13, 2006 6:20 pm
Posts: 2325
Location: Argentina
McBenn wrote:
And gwren1... since when did you change your avatar :o


Since I posted my last message here :D Does it look handsome? Also btw, I'm Engineer now in OWS (Moderator), so no longer scientist :) (well I was moderator almost since the beginning lol)

=============================================
About how to set that message, I suggest Stu to ask it because I don't know. :wink:

_________________
-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:
PostPosted: Tue Jul 14, 2009 8:24 pm 
Offline
Moderator
Moderator
User avatar

Joined: Mon Mar 17, 2008 6:03 pm
Posts: 1129
Location: Denmark
gwren1 wrote:
McBenn wrote:
And gwren1... since when did you change your avatar


Since I posted my last message here :D Does it look handsome?


Very nice very nice :wink: :D

gwren1 wrote:
Also btw, I'm Engineer now in OWS (Moderator)


Ok - didn't know it worked that way :o Good I chose scientist when I made my avatar then :wink: . Does the other classes mean something as well?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 15, 2009 9:12 am 
Offline
OW Support Owner
OW Support Owner
User avatar

Joined: Wed Dec 28, 2005 11:13 pm
Posts: 5001
Location: UK, Scotland
Everyone that doesn't have a admin/moderator rank is a Soldier. There are 5 levels of soldier based on posts (0 - 5). Admin (Which is only me) has a Scientist class. Moderators have an Engineer class.

Soldier Ranks:
level 0 0 Posts
level 1 50 Posts
level 2 100 Posts
level 3 200 Posts
level 4 300 Posts
level 5 450 Posts

_________________
Image
Free Map Editor - Game Requirements - Stucuk.Net
-Stu


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 15, 2009 2:34 pm 
Offline
Moderator
Moderator
User avatar

Joined: Mon Mar 17, 2008 6:03 pm
Posts: 1129
Location: Denmark
Cool 8) Had almost figured about about the soldier skill and class. What about mechanic :P

Is this information posted anywhere else in the forum? Else I would suggest putting it in the General Discussion as a sticky subject.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 15, 2009 5:34 pm 
Offline
Moderator
Moderator
User avatar

Joined: Fri Jan 13, 2006 6:20 pm
Posts: 2325
Location: Argentina
Mechanics would be cool but only for Technical service people xD or "correctors" of something... xD And special classes? xD

_________________
-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  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 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