Author Topic: Scout moving around the map.  (Read 5422 times)

Offline Ecke100

  • Newbie
  • *
  • Posts: 36
Scout moving around the map.
« on: May 17, 2018, 04:52:41 PM »
What code should i use to make a scout move around to specific cordinates to make it work, like in Demo version scenario.

I did like this before, but it will make the game crash after around 699 or earlier marks

Code: [Select]
// Green Scout Start

CreateTimeTrigger(1, 1, 0, "ScoutMove");

// Scout

SCRIPT_API void ScoutMove()
{
// Scout

    FightGroup &GreenScout = CreateFightGroup(Player[1]);

    GreenScout.TakeUnit(SD.Scout);
GreenScout.SetRect(MAP_RECT(33+31, 81-1, 33+31, 81-1));
SD.GreenScout = GreenScout;
CreateTimeTrigger(1, 1, 0, "ScoutMove1");
}

SCRIPT_API void ScoutMove1()
{
FightGroup &GreenScout = CreateFightGroup(Player[1]);

GreenScout.TakeAllUnits(SD.GreenScout);
GreenScout.SetRect(MAP_RECT(12+31, 210-1, 12+31, 210-1));
SD.GreenScout = GreenScout;
CreateTimeTrigger(1, 1, 2100, "ScoutMove2");
}

SCRIPT_API void ScoutMove2()
{
FightGroup &GreenScout = CreateFightGroup(Player[1]);

GreenScout.TakeAllUnits(SD.GreenScout);
GreenScout.SetRect(MAP_RECT(170+31, 250-1, 170+31, 250-1));
SD.GreenScout = GreenScout;
CreateTimeTrigger(1, 1, 3200, "ScoutMove3");
}

SCRIPT_API void ScoutMove3()
{
FightGroup &GreenScout = CreateFightGroup(Player[1]);

GreenScout.TakeAllUnits(SD.GreenScout);
GreenScout.SetRect(MAP_RECT(250+31, 195-1, 250+31, 195-1));
SD.GreenScout = GreenScout;
CreateTimeTrigger(1, 1, 1500, "ScoutMove4");
}

SCRIPT_API void ScoutMove4()
{
FightGroup &GreenScout = CreateFightGroup(Player[1]);

GreenScout.TakeAllUnits(SD.GreenScout);
GreenScout.SetRect(MAP_RECT(250+31, 165-1, 250+31, 165-1));
SD.GreenScout = GreenScout;
CreateTimeTrigger(1, 1, 900, "ScoutMove5");
}

SCRIPT_API void ScoutMove5()
{
FightGroup &GreenScout = CreateFightGroup(Player[1]);

GreenScout.TakeAllUnits(SD.GreenScout);
GreenScout.SetRect(MAP_RECT(250+31, 5-1, 250+31, 5-1));
SD.GreenScout = GreenScout; //7700
CreateTimeTrigger(1, 1, 2930, "ScoutMove6");
}

SCRIPT_API void ScoutMove6()
{
FightGroup &GreenScout = CreateFightGroup(Player[1]);

GreenScout.TakeAllUnits(SD.GreenScout);
GreenScout.SetRect(MAP_RECT(162+31, 49-1, 162+31, 49-1));
SD.GreenScout = GreenScout;
CreateTimeTrigger(1, 1, 1500, "ScoutMove7");
}

SCRIPT_API void ScoutMove7()
{
FightGroup &GreenScout = CreateFightGroup(Player[1]);

GreenScout.TakeAllUnits(SD.GreenScout);
GreenScout.SetRect(MAP_RECT(188+31, 9-1, 188+31, 9-1));
SD.GreenScout = GreenScout;
CreateTimeTrigger(1, 1, 700, "ScoutMove8");
}

SCRIPT_API void ScoutMove8()
{
FightGroup &GreenScout = CreateFightGroup(Player[1]);

GreenScout.TakeAllUnits(SD.GreenScout);
GreenScout.SetRect(MAP_RECT(79+31, 45-1, 79+31, 45-1));
SD.GreenScout = GreenScout;
CreateTimeTrigger(1, 1, 1900, "ScoutMove9");
}

SCRIPT_API void ScoutMove9()
{
FightGroup &GreenScout = CreateFightGroup(Player[1]);

GreenScout.TakeAllUnits(SD.GreenScout);
GreenScout.SetRect(MAP_RECT(61+31, 60-1, 61+31, 60-1));
SD.GreenScout = GreenScout;
CreateTimeTrigger(1, 1, 250, "ScoutMove10");
}

SCRIPT_API void ScoutMove10()
{
// Scout

    FightGroup &GreenScout = CreateFightGroup(Player[1]);

GreenScout.TakeAllUnits(SD.GreenScout);
GreenScout.SetRect(MAP_RECT(33+31, 81-1, 33+31, 81-1));
SD.GreenScout = GreenScout;
CreateTimeTrigger(1, 1, 600, "ScoutMove1");
}


EDIT (leeor_net): added code tag
« Last Edit: May 17, 2018, 09:42:53 PM by leeor_net »

Offline Vagabond

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1015
Re: Scout moving around the map.
« Reply #1 on: May 17, 2018, 09:11:36 PM »
Hi Eke100,

I've seen posts in the forum alluding to a limit on how many triggers that can exist in an Outpost 2 scenario although I'm not sure what the limit it. This could be your problem? If this is actually a problem, you redesign your code to avoid creating so many triggers but I hate to tell you this is the problem without more proof.

Can you narrow it down to exactly which function is executing when the crash occurs?

You can use TethysGame::AddMessage to output debug messages directly in Outpost 2. It might be more efficient to output the debug message directly to your IDE though.

You could output "Executing function: ScoutMoveX." Or you could try counting the number of triggers have been created and outputing that number.

Code: [Select]
void SendDebugMessage(char* message)
{
#if _DEBUG
Unit unit;
TethysGame::AddMessage(unit, message, PlayerNum::Player0, SoundID::sndBeep8);
#endif
}

Offline leeor_net

  • Administrator
  • Hero Member
  • *****
  • Posts: 2352
  • OPHD Lead Developer
    • LairWorks Entertainment
Re: Scout moving around the map.
« Reply #2 on: May 17, 2018, 09:43:59 PM »
Please make sure to use code tags when posting code -- it makes it a lot easier to read.

Thank you!  ;D

Offline Hooman

  • Administrator
  • Hero Member
  • *****
  • Posts: 4955
Re: Scout moving around the map.
« Reply #3 on: May 18, 2018, 07:38:14 AM »
Interesting, you've created a loop of time Triggers. That's a simple and creative way to do it, though a bit code heavy.

I believe the correct way to do this is illustrated in Sirbomber's tutorial, which covers patrol routes in Week 10:
Outpost 2 Coding 101: Week 10


As for why it crashes, I suspect Vagabond is correct, though I also don't know for certain if that is the problem.

You're creating a bunch of TimeTriggers and a bunch of FightGroups. It could be either or a combination of those. The TimeTriggers are set to one-shot use, so they might get destructed after they fire. The FightGroups probably have no way to know if they should be destructed. You might need to call a method to manually destruct them. Though, you could also refactor your code so you're not constantly recreating the FightGroup, but rather re-using the same one each time. Though as I've said above, the correct way to set a patrol route is illustrated in Sirbomber's tutorial.

Also, keep in mind, the TimeTrigger and FightGroup objects as present in the Outpost 2 API are just proxy objects for the internal game objects. Hence the C++ rules for creation and destruction of the proxy objects don't necessarily dictate the creation and destruction of the actual internal game objects.

Anyway, give Sirbomber's code a try, and see how that goes.

If you're the curious explorer type, I'd also be curious to know if the code refactoring to reuse fight groups would eliminate the crashes, or double the time required to reach a crash. Regardless though, I'd still suggest rewriting as in Sirbomber's tutorial.
« Last Edit: May 21, 2018, 03:42:31 AM by Hooman »

Offline Ecke100

  • Newbie
  • *
  • Posts: 36
Re: Scout moving around the map.
« Reply #4 on: May 18, 2018, 11:22:12 AM »
Please make sure to use code tags when posting code -- it makes it a lot easier to read.

Thank you!  ;D
Thx :D

Offline Sirbomber

  • Hero Member
  • *****
  • Posts: 3238
Re: Scout moving around the map.
« Reply #5 on: July 02, 2018, 09:26:31 PM »
It would perhaps be better to store off the unit handle for that Scout and use a series of PointTriggers to call Unit.DoMove(LOCATION) as the Scout arrives at the coordinates you want.
"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