Author Topic: Getting Ai Units To Patrol  (Read 2334 times)

Offline Sirbomber

  • Hero Member
  • *****
  • Posts: 3238
Getting Ai Units To Patrol
« on: July 08, 2009, 11:36:23 PM »
Okay, I've been having this problem for awhile now.  The documentation for AI patrols is so crappy it may as well not exist.

I know I need to call SetPatrolMode(struct PatrolRoute &waypts); on the fight group I want to patrol, but before that I need to setup the PatrolRoute struct:

Code: [Select]
struct OP2 PatrolRoute 
{
int unknown1;
LOCATION *waypoints;
};

What I really want to know is how do I tell OP2 which waypoints I want the units patrolling between?  At first I thought waypoints was an array, but apparently it isn't.  What should I do?
"As usual, colonist opinion is split between those who think the plague is a good idea, and those who are dying from it." - Outpost Evening Star

Outpost 2 Coding 101 Tutorials

Offline Eddy-B

  • Hero Member
  • *****
  • Posts: 1186
    • http://www.eddy-b.com
Getting Ai Units To Patrol
« Reply #1 on: July 09, 2009, 01:02:17 AM »
Quote
Okay, I've been having this problem for awhile now.  The documentation for AI patrols is so crappy it may as well not exist.
Have you checked my coverage of the topic?
Should be somewhere in the coding section..
Rule #1:  Eddy is always right
Rule #2: If you think he's wrong, see rule #1
--------------------

Outpost : Renegades - Eddy-B.com - Electronics Pit[/siz

Offline Sirbomber

  • Hero Member
  • *****
  • Posts: 3238
Getting Ai Units To Patrol
« Reply #2 on: July 09, 2009, 07:10:56 AM »
Yes, it wasn't very helpful.

Someone just tell me how to setup the waypoints and I'll be happy.
"As usual, colonist opinion is split between those who think the plague is a good idea, and those who are dying from it." - Outpost Evening Star

Outpost 2 Coding 101 Tutorials

Offline Eddy-B

  • Hero Member
  • *****
  • Posts: 1186
    • http://www.eddy-b.com
Getting Ai Units To Patrol
« Reply #3 on: July 09, 2009, 11:51:15 AM »
I can look it up in my source, but the struct you posted is pretty self-evident:
create an array of locations:
LOCATION waypoints[]={  waypoint1, waypoint2, waypoint3 };



[EDIT]Ok, looked it up!

here's a small piece of source code, taken directly from Renegades, mission 1. It sets up 3 patrol routes, using waypoints. Study it, and LEARN!

Code: [Select]
EXPORT void SetPatrols()
{
LOCATION scoutRoute1[]=
{
  LOCATION(120, 14),
  LOCATION( 96,  6),
  LOCATION(125, 36),
  LOCATION(142, 41),
  LOCATION(142, 15),
  LOCATION( -1, -1)
};

LOCATION scoutRoute2[]=   // scout right map
{
  LOCATION(136, 47),
  LOCATION( 91, 55),
  LOCATION( 84, 23),
  LOCATION(141, 14),
  LOCATION( -1, -1)
};

LOCATION scoutRoute3[]=   // scout enemy base
{
  LOCATION(138, 24),
  LOCATION( 90, 58),
  LOCATION( 34, 60),
  LOCATION( 49, 26),
  LOCATION( 50,  8),
  LOCATION( 85, 23),
  LOCATION(133, 10),
  LOCATION( -1, -1)
};

PatrolRoute route1,route2,route3;
FightGroup patrol1,patrol2,patrol3;
IUnit u;

patrol1=CreateFightGroup(Player[1]);
route1.waypoints=scoutRoute1;
patrol1.SetPatrolMode(route1);

patrol2=CreateFightGroup(Player[1]);
route2.waypoints=scoutRoute2;
patrol2.SetPatrolMode(route2);

patrol3=CreateFightGroup(Player[1]);
route3.waypoints=scoutRoute3;
patrol3.SetPatrolMode(route3);

TethysGame::CreateUnit(u,mapScout,LOCATION(158,2),1,mapNone,West);
patrol1.TakeUnit(u);
TethysGame::CreateUnit(u,mapScout,LOCATION(158,4),1,mapNone,SouthWest);
patrol2.TakeUnit(u);
TethysGame::CreateUnit(u,mapScout,LOCATION(158,6),1,mapNone,SouthWest);
patrol3.TakeUnit(u);
}
« Last Edit: July 09, 2009, 12:02:21 PM by Eddy-B »
Rule #1:  Eddy is always right
Rule #2: If you think he's wrong, see rule #1
--------------------

Outpost : Renegades - Eddy-B.com - Electronics Pit[/siz

Offline Sirbomber

  • Hero Member
  • *****
  • Posts: 3238
Getting Ai Units To Patrol
« Reply #4 on: July 09, 2009, 12:23:11 PM »
Excellent.  I see what I was doing wrong now.  Thanks.
"As usual, colonist opinion is split between those who think the plague is a good idea, and those who are dying from it." - Outpost Evening Star

Outpost 2 Coding 101 Tutorials

Offline Eddy-B

  • Hero Member
  • *****
  • Posts: 1186
    • http://www.eddy-b.com
Getting Ai Units To Patrol
« Reply #5 on: July 09, 2009, 12:28:44 PM »
forgot the (-1,-1) at the end ?
Rule #1:  Eddy is always right
Rule #2: If you think he's wrong, see rule #1
--------------------

Outpost : Renegades - Eddy-B.com - Electronics Pit[/siz

Offline Sirbomber

  • Hero Member
  • *****
  • Posts: 3238
Getting Ai Units To Patrol
« Reply #6 on: July 09, 2009, 02:43:35 PM »
No, I did the array wrong.  At least I was right about it being an array though...
"As usual, colonist opinion is split between those who think the plague is a good idea, and those who are dying from it." - Outpost Evening Star

Outpost 2 Coding 101 Tutorials