Author Topic: Second Ai Colony  (Read 11676 times)

Offline Ecke100

  • Newbie
  • *
  • Posts: 36
Second Ai Colony
« on: June 06, 2010, 07:47:11 AM »
Hi can somebody give me a code example of Second Ai Colony.  :)

Eke100

Offline Sirbomber

  • Hero Member
  • *****
  • Posts: 3236
Second Ai Colony
« Reply #1 on: June 06, 2010, 10:17:30 AM »
I'm not sure what you're asking for...  Could you clarify a bit please?
"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 Ecke100

  • Newbie
  • *
  • Posts: 36
Second Ai Colony
« Reply #2 on: June 06, 2010, 11:06:56 AM »
Take two ConVec's from the main base and build a new base with Command Center and Structure Factory
« Last Edit: June 06, 2010, 11:08:17 AM by Eke100 »

Offline Sirbomber

  • Hero Member
  • *****
  • Posts: 3236
Second Ai Colony
« Reply #3 on: June 06, 2010, 02:29:56 PM »
Oh, an AI that will build a second colony.

I've never done it myself.  Maybe somebody else has and can help you sooner, but I'll need to think about it for awhile.
"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 Ecke100

  • Newbie
  • *
  • Posts: 36
Second Ai Colony
« Reply #4 on: June 06, 2010, 02:41:29 PM »
Quote
Oh, an AI that will build a second colony.

I've never done it myself.  Maybe somebody else has and can help you sooner, but I'll need to think about it for awhile.
Thanks :)  

Offline Hooman

  • Administrator
  • Hero Member
  • *****
  • Posts: 4952
Second Ai Colony
« Reply #5 on: June 06, 2010, 03:06:36 PM »
I've been looking at ces1.dll a bit, but I'll have to answer this later.

I imagine you start by creating a building group and record the buildings you want in the second base. Then somehow assign a convec to the group in such a way that it's fill with stuff from another building group. You might have to transfer the convec to the new group once it's loaded? I don't really know yet.
 

Offline Sirbomber

  • Hero Member
  • *****
  • Posts: 3236
Second Ai Colony
« Reply #6 on: June 06, 2010, 10:28:43 PM »
Alternatively, you could do it the hard way by ordering a Structure Factory to build the desired structure kits, loading those kits into a ConVec, and deploying those structure kits at the desired locations.  Of course, you'll need a metric ton of triggers and AIProc checks to ensure all of this actually happens and restart the entire process if something goes wrong.
"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 Hidiot

  • Hero Member
  • *****
  • Posts: 1018
Second Ai Colony
« Reply #7 on: June 07, 2010, 01:33:31 AM »
I've done it once, although the bases were in close range, so I just used the first SF to record the second CC+SF set. This method ensures the second base will get rebuilt if it's destroyed and the first base is still alive, but might indispose a couple of ConVecs for a while if the distance between bases is big.

The other methods pointed out here work too.
"Nothing from nowhere, I'm no one at all"

Offline Ecke100

  • Newbie
  • *
  • Posts: 36
Second Ai Colony
« Reply #8 on: June 08, 2010, 08:19:58 AM »
I have code so they build Command and Structure Factory, but i don't how i code so they will take the new Structure Factory and build new buildings.
Here is a code i have done with time trigger.

Code: [Select]
buildGroup2 = CreateBuildingGroup(Player[1]);
buildGroup2.SetRect(MAP_RECT(12+31, 108-1, 28+31, 114-1));
buildGroup2.TakeUnit(ConVec3);
buildGroup2.TakeUnit(ConVec4);

CreateTimeTrigger(1, 0, 28000, "Base2");

SCRIPT_API void Base2()
{
    buildGroup2b = CreateBuildingGroup(Player[1]);
    buildGroup2b.SetRect(MAP_RECT(185+31, 19-1, 194+31, 28-1));
    buildGroup2b.TakeAllUnits(buildGroup2);
    buildGroup2b.TakeUnit(SF);
    buildGroup2b.RecordBuilding(LOCATION(191+31, 23-1), mapCommandCenter, mapNone);
    buildGroup2b.RecordBuilding(LOCATION(191+31, 26-1), mapStructureFactory, mapNone);
    buildGroup2b.RecordBuilding(LOCATION(197+31, 22-1), mapVehicleFactory, mapNone);
}
« Last Edit: May 17, 2018, 09:46:47 PM by leeor_net »

Offline Sirbomber

  • Hero Member
  • *****
  • Posts: 3236
Second Ai Colony
« Reply #9 on: June 08, 2010, 11:29:08 AM »
Create a time trigger that fires every 10 ticks that checks if the AI Player has a Structure Factory at the specified location and assigns it to the Build Group if found.

Code: [Select]
/* Assuming you have some kind of Save Data struct */
struct SaveData()
{
    Unit AI_SF2;

    Trigger CheckSecondSF;
    ...

};
SaveData SD;

...

/* In the Base2 callback function */
{
    SD.CheckSecondSF = CreateTimeTrigger(1, 0, 10, "AI_SFCheck");
}

...

SCRIPT_API void AI_SFCheck()
{
    /* Let's use an enumerator */
    Unit curUnit;
    PlayerBuildingEnum unitEnum(AI Player Number, mapNone);
    while (unitEnum.GetNext(curUnit) )
    {
        /* Check if this is the unit we want (make sure it's an SF and in the right spot) */
        if ( (curUnit.GetType() == mapStructureFactory) && (curUnit.Location() == LOCATION(191+31, 26-1) ) )
        {
            /* We've found it!  Record it and destroy this trigger. */
            SD.AI_SF2 = curUnit;
            SD.CheckSecondSF.Destroy();
        }
    }
}

This is the part where I mention I just wrote that and it's completely untested.  It probably should work, but let me know if you need help with it.
« Last Edit: May 17, 2018, 09:47:50 PM by leeor_net »
"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 Ecke100

  • Newbie
  • *
  • Posts: 36
Second Ai Colony
« Reply #10 on: June 09, 2010, 01:26:43 PM »
I got this problem when i try to complie, i have not done a Save Date struct before

Quote
1>.\Main.cpp(771) : error C2447: '{' : missing function header (old-style formal list?)
1>.\Main.cpp(784) : error C2678: binary '==' : no operator found which takes a left-hand operand of type 'LOCATION' (or there is no acceptable conversion)
1>        D:\Program Files\Microsoft SDKs\Windows\v6.0A\\include\guiddef.h(192): could be 'int operator ==(const GUID &,const GUID &)'
1>        while trying to match the argument list '(LOCATION, LOCATION)'
« Last Edit: May 17, 2018, 09:48:09 PM by leeor_net »

Offline Sirbomber

  • Hero Member
  • *****
  • Posts: 3236
Second Ai Colony
« Reply #11 on: June 09, 2010, 03:42:07 PM »
Oh.  Oops.

Code: [Select]
/* Replace this line */
if ( (curUnit.GetType() == mapStructureFactory) && (curUnit.Location() == LOCATION(191+31, 26-1) ) )

/* With this line */
if ( (curUnit.GetType() == mapStructureFactory) && (curUnit.Location().x == 191+31) && (curUnit.Location().y == 26-1) )

Tell me if it works now.

As for the SaveData struct, check out my tutorials for more info.
« Last Edit: May 17, 2018, 09:48:34 PM by leeor_net »
"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 Ecke100

  • Newbie
  • *
  • Posts: 36
Second Ai Colony
« Reply #12 on: June 09, 2010, 04:08:01 PM »
Quote
Oh.  Oops.

Code: [Select]
/* Replace this line */
if ( (curUnit.GetType() == mapStructureFactory) && (curUnit.Location() == LOCATION(191+31, 26-1) ) )

/* With this line */
if ( (curUnit.GetType() == mapStructureFactory) && (curUnit.Location().x == 191+31) && (curUnit.Location().y == 26-1) )

Tell me if it works now.

As for the SaveData struct, check out my tutorials for more info.
Here is my code i have done

Code: [Select]
/* Generic Example */

/* Define the struct */
struct structType
{
   /* Stuff goes here */

};  /* NOTE: You MUST have that semi-colon after the struct definition */

/* Declare the struct */
structType structName;

/* OP2-specific Example */
struct SaveData
{
   /* Triggers */
   Trigger Meteor,  /* Meteor time trigger */
   CheckSecondSF,
           Vortex;  /* Vortex time trigger */

   /* AI Units */
   Unit AI_CC,   /* AI Command Center */
        AI_SF2,   /* AI Structure Factory */
        AI_VF;   /* AI Vehicle Factory */

   /* AI FightGroups */
   FightGroup LynxRush, /* Microwave Lynx Rush attack group */
              Defenses; /* Base defense group */

   /* Misc. Data */
   int numAI; /* AI player number */
};

SaveData SD;

/* In the Base2 callback function */
{
   SD.CheckSecondSF = CreateTimeTrigger(1, 0, 10, "AI_SFCheck");
}

/* Usage */
SCRIPT_API void AI_SFCheck()
{
   /* Let's use an enumerator */
   Unit curUnit;
   PlayerBuildingEnum unitEnum(1, mapNone);
   while (unitEnum.GetNext(curUnit) )
   {
       /* Check if this is the unit we want (make sure it's an SF and in the right spot) */
       if ( (curUnit.GetType() == mapStructureFactory) && (curUnit.Location().x == 191+31) && (curUnit.Location().y == 26-1) )
       {
           /* We've found it!  Record it and destroy this trigger. */
           SD.AI_SF2 = curUnit;
           SD.CheckSecondSF.Destroy();
       }
   }

i got two error

Quote
1>.\Main.cpp(772) : error C2447: '{' : missing function header (old-style formal list?)
1>.\Main.cpp(804) : fatal error C1075: end of file found before the left brace '{' at '.\Main.cpp(778)' was matched

What do I have wrong here?
« Last Edit: May 17, 2018, 09:51:55 PM by leeor_net »

Offline Sirbomber

  • Hero Member
  • *****
  • Posts: 3236
Second Ai Colony
« Reply #13 on: June 09, 2010, 04:22:56 PM »
Your compiler is telling you to check Line 772...
"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 Ecke100

  • Newbie
  • *
  • Posts: 36
Second Ai Colony
« Reply #14 on: June 09, 2010, 05:35:35 PM »
Dont understand what i need to change in this code

SaveData SD;

Code: [Select]
...

/* In the Base2 callback function */
{
   SD.CheckSecondSF = CreateTimeTrigger(1, 0, 10, "AI_SFCheck");
}

...

 :o

(...?)
« Last Edit: May 17, 2018, 09:52:25 PM by leeor_net »

Offline Sirbomber

  • Hero Member
  • *****
  • Posts: 3236
Second Ai Colony
« Reply #15 on: June 09, 2010, 05:38:56 PM »
How about you post the code around Line 772, which is where your compiler says the error is?
"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 Ecke100

  • Newbie
  • *
  • Posts: 36
Second Ai Colony
« Reply #16 on: June 09, 2010, 05:50:37 PM »
Dont know i have change code so i don't got the 772 error

Offline Sirbomber

  • Hero Member
  • *****
  • Posts: 3236
Second Ai Colony
« Reply #17 on: June 09, 2010, 06:48:40 PM »
Well, you're posting two lines of code and asking why it's not working.  That's nowhere near enough information for me to help you.
"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 Ecke100

  • Newbie
  • *
  • Posts: 36
Second Ai Colony
« Reply #18 on: June 10, 2010, 07:22:55 AM »
I have delete the code i have done and copy your text again.

Code: [Select]
/* Assuming you have some kind of Save Data struct */
struct SaveData()
{
   Unit AI_SF2;

   Trigger CheckSecondSF;
   ...

};
SaveData SD;

...

/* In the Base2 callback function */
{
   SD.CheckSecondSF = CreateTimeTrigger(1, 0, 10, "AI_SFCheck");
}

...

SCRIPT_API void AI_SFCheck()
{
   /* Let's use an enumerator */
   Unit curUnit;
   PlayerBuildingEnum unitEnum(AI Player Number, mapNone);
   while (unitEnum.GetNext(curUnit) )
   {
       /* Check if this is the unit we want (make sure it's an SF and in the right spot) */
       if ( (curUnit.GetType() == mapStructureFactory) && (curUnit.Location().x == 191+31) && (curUnit.Location().y == 26-1) )
       {
           /* We've found it!  Record it and destroy this trigger. */
           SD.AI_SF2 = curUnit;
           SD.CheckSecondSF.Destroy();
       }
   }
}


And got all this errors in Visual C++ 2008 Express Edition

Quote
1>.\Main.cpp(735) : error C2059: syntax error : ')'
1>.\Main.cpp(736) : error C2143: syntax error : missing ';' before '{'
1>.\Main.cpp(736) : error C2447: '{' : missing function header (old-style formal list?)
1>.\Main.cpp(743) : error C2079: 'SD' uses undefined struct 'SaveData'
1>.\Main.cpp(745) : error C2059: syntax error : '...'
1>.\Main.cpp(748) : error C2143: syntax error : missing ';' before '{'
1>.\Main.cpp(748) : error C2447: '{' : missing function header (old-style formal list?)
1>.\Main.cpp(752) : error C2059: syntax error : '...'
1>.\Main.cpp(755) : error C2143: syntax error : missing ';' before '{'
1>.\Main.cpp(755) : error C2447: '{' : missing function header (old-style formal list?)

 
« Last Edit: May 17, 2018, 09:53:36 PM by leeor_net »

Offline Hidiot

  • Hero Member
  • *****
  • Posts: 1018
Second Ai Colony
« Reply #19 on: June 10, 2010, 07:43:15 AM »
Eke, you don't have such a good understanding of programming, do you?


What Sirbomber gave you is a sketch of how your code should look, not something you can just copy&paste and hope it works.
"Nothing from nowhere, I'm no one at all"

Offline Ecke100

  • Newbie
  • *
  • Posts: 36
Second Ai Colony
« Reply #20 on: June 10, 2010, 02:48:30 PM »
Quote
Eke, you don't have such a good understanding of programming, do you?
I have not programming before

Offline Ecke100

  • Newbie
  • *
  • Posts: 36
Second Ai Colony
« Reply #21 on: June 10, 2010, 02:56:35 PM »
Quote
What Sirbomber gave you is a sketch of how your code should look, not something you can just copy&paste and hope it works.
Can understand that, but i need to know what i need write at all lines with three dots in Sirbomber's Sketch.

Offline Sirbomber

  • Hero Member
  • *****
  • Posts: 3236
Second Ai Colony
« Reply #22 on: June 10, 2010, 03:38:38 PM »
The "..." means "your own code goes here".  I don't want to write
Code: [Select]
int InitProc()
{
    Player[0].GoEden();
}

Since that implies the only thing that should be in InitProc is the GoEden call, whereas this
Code: [Select]
int InitProc()
{
    ...
    Player[0].GoEden();
    ...
}

implies that you need to put some of your own code in there.
"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 jcj94

  • Sr. Member
  • ****
  • Posts: 407
    • http://techfusion-279.com
Second Ai Colony
« Reply #23 on: June 10, 2010, 04:00:33 PM »
Quote
I've done it once, although the bases were in close range, so I just used the first SF to record the second CC+SF set. This method ensures the second base will get rebuilt if it's destroyed and the first base is still alive...
That sounds (by base description) like Eden in Plymouth mission 10.. the two basses with 2 CC's kept rebulding eachother...

Offline Ecke100

  • Newbie
  • *
  • Posts: 36
Second Ai Colony
« Reply #24 on: September 09, 2010, 07:31:36 AM »
Damn i want the Ai build more bases, but i can not get it work :S