Outpost Universe Forums

Projects & Development => Outpost 2 Programming & Development => Topic started by: Ecke100 on June 06, 2010, 07:47:11 AM

Title: Second Ai Colony
Post by: Ecke100 on June 06, 2010, 07:47:11 AM
Hi can somebody give me a code example of Second Ai Colony.  :)

Eke100
Title: Second Ai Colony
Post by: Sirbomber on June 06, 2010, 10:17:30 AM
I'm not sure what you're asking for...  Could you clarify a bit please?
Title: Second Ai Colony
Post by: Ecke100 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
Title: Second Ai Colony
Post by: Sirbomber 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.
Title: Second Ai Colony
Post by: Ecke100 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 :)  
Title: Second Ai Colony
Post by: Hooman 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.
 
Title: Second Ai Colony
Post by: Sirbomber 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.
Title: Second Ai Colony
Post by: Hidiot 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.
Title: Second Ai Colony
Post by: Ecke100 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);
}
Title: Second Ai Colony
Post by: Sirbomber 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.
Title: Second Ai Colony
Post by: Ecke100 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)'
Title: Second Ai Colony
Post by: Sirbomber 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.
Title: Second Ai Colony
Post by: Ecke100 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?
Title: Second Ai Colony
Post by: Sirbomber on June 09, 2010, 04:22:56 PM
Your compiler is telling you to check Line 772...
Title: Second Ai Colony
Post by: Ecke100 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

(...?)
Title: Second Ai Colony
Post by: Sirbomber 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?
Title: Second Ai Colony
Post by: Ecke100 on June 09, 2010, 05:50:37 PM
Dont know i have change code so i don't got the 772 error
Title: Second Ai Colony
Post by: Sirbomber 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.
Title: Second Ai Colony
Post by: Ecke100 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?)

 
Title: Second Ai Colony
Post by: Hidiot 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.
Title: Second Ai Colony
Post by: Ecke100 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
Title: Second Ai Colony
Post by: Ecke100 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.
Title: Second Ai Colony
Post by: Sirbomber 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.
Title: Second Ai Colony
Post by: jcj94 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...
Title: Second Ai Colony
Post by: Ecke100 on September 09, 2010, 07:31:36 AM
Damn i want the Ai build more bases, but i can not get it work :S
Title: Second Ai Colony
Post by: Sirbomber on September 09, 2010, 08:08:29 AM
Set up a new Building Group once the new SF is running.  Make sure to assign it ConVecs and a build list.
Title: Second Ai Colony
Post by: Ecke100 on September 09, 2010, 11:38:33 AM
Here is my code.

Code: [Select]
Unit ConVec3, ConVec4;

TethysGame::CreateUnit(ConVec3, mapConVec, LOCATION(15+31, 113-1), 1, mapCommandCenter, 3);
x.DoSetLights(1);
TethysGame::CreateUnit(ConVec4, mapConVec, LOCATION(17+31, 113-1), 1, mapStructureFactory, 3);
x.DoSetLights(1);

First, they wait in the main base

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

Then after, they will go to the next area.

Code: [Select]
SCRIPT_API void Base2()
{
    buildGroup2b = CreateBuildingGroup(Player[1]);
    buildGroup2b.SetRect(MAP_RECT(185+31, 19-1, 194+31, 28-1));
    buildGroup2b.TakeAllUnits(buildGroup2);
    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);
}

They build Command Center and Structure Factory, but ConVecs will not record Structure Factory and build next building on the list.
Title: Second Ai Colony
Post by: Sirbomber on September 09, 2010, 05:55:56 PM
I don't trust TakeAllUnits.  Try doing that manually somehow.  Also make sure to remove the units from the old group first.

On second thought, why are you even making a "group 2b"?  Just change group 2 as needed.
Title: Second Ai Colony
Post by: Ecke100 on April 22, 2011, 08:13:01 AM
Someone who has been running the AI ​​to build more separate bases?
Title: Second Ai Colony
Post by: Ecke100 on June 28, 2011, 07:26:46 AM
Now i got it, it works now at last! :D

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

CreateTimeTrigger(1, 1, 1000, "Base2a");
CreateTimeTrigger(1, 1, 13000, "Base2");

SD.CheckSecondSF = CreateTimeTrigger(1, 0, 10, "AI_SFCheck");

SCRIPT_API void Base2a()
{
Unit ConVec3 ,ConVec4, SF2;
SD.buildGroup2b = CreateBuildingGroup(Player[1]);
SD.buildGroup2b.SetRect(MAP_RECT(185+31, 19-1, 194+31, 28-1));
SD.buildGroup2b.RecordBuilding(LOCATION(191+31, 23-1), mapCommandCenter, mapNone);
SD.buildGroup2b.RecordBuilding(LOCATION(191+31, 26-1), mapStructureFactory, mapNone);
SD.buildGroup2b.TakeAllUnits(SD.buildGroup2);
SD.buildGroup2b.TakeUnit(SD.SF2);
}

SCRIPT_API void Base2()
{
Unit ConVec3 ,ConVec4, SF2;
SD.buildGroup2c = CreateBuildingGroup(Player[1]);
SD.buildGroup2c.SetRect(MAP_RECT(185+31, 19-1, 194+31, 28-1));
SD.buildGroup2c.TakeAllUnits(SD.buildGroup2b);
SD.buildGroup2c.TakeUnit(SD.SF2);
SD.buildGroup2c.RecordBuilding(LOCATION(196+31, 22-1), mapVehicleFactory, mapNone);
}

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

You need to Create a group after the StructureFactory is done with a TimeTrigger.
Title: Second Ai Colony
Post by: Hidiot on June 28, 2011, 10:49:41 AM
What?

You should be able to create a group anywhere before first being used. Only the record unit part needs to assign a handle to an actually existing entity.
Title: Second Ai Colony
Post by: Ecke100 on August 18, 2011, 05:05:09 PM
Here is my map :) Beta 1.1
Title: Second Ai Colony
Post by: Ecke100 on August 18, 2011, 05:06:40 PM
Map file
Title: Second Ai Colony
Post by: Highlander on August 19, 2011, 01:15:31 AM
I get an error message when trying your game - "Game could not initialize"
Title: Second Ai Colony
Post by: Flashy on August 19, 2011, 07:06:32 PM
Same with me.
Title: Second Ai Colony
Post by: Savant_Ace on August 20, 2011, 12:06:42 AM
+1 (Could not Initialize)
Title: Second Ai Colony
Post by: Ecke100 on August 21, 2011, 12:05:22 PM
Can not understand why you get the error, did not find anything wrong yet
Title: Second Ai Colony
Post by: Hooman on August 22, 2011, 03:03:14 AM
The mapName field of the DescBlock points to the string "bad allocation". There are also similar problems with the levelDesc and techTreeName fields not pointing to valid strings.
 
Title: Second Ai Colony
Post by: Ecke100 on August 24, 2011, 07:24:39 PM
I can play the map with no problems.
Title: Second Ai Colony
Post by: Savant_Ace on August 24, 2011, 08:18:29 PM
That much seems obvious. Try making a fresh installation of OP2 in a different directory and installing your map there, then see if you run into the same problem that we do.
Title: Second Ai Colony
Post by: Ecke100 on November 19, 2011, 09:28:39 AM
Now i have installed on a another computer and it work.

Note: I use (Outpost 2 Version 1.35 Beta 2) and when you download the map, remove the underscore in Bana_2.map and write it to Bana 2.map (Scenario 2.map in English) :)

Sorry i dont try test download my map from this site, i should have seen it but i dont.
Title: Second Ai Colony
Post by: Ecke100 on May 25, 2013, 03:09:26 PM
Quote
What?

You should be able to create a group anywhere before first being used. Only the record unit part needs to assign a handle to an actually existing entity.
Has found a way that you meant, a code that works that way, thx to Sirbomber, Flashy and more. from various topics i got a combination of codes that works.  :)

Here is the solution.

Code: [Select]
SCRIPT_API void Red_SFCheck()
{
    // Let's use an enumerator
    IUnit RSF1;
    PlayerBuildingEnum unitEnum(2, mapNone);
    while (unitEnum.GetNext(RSF1) )
    {
        // Check if this is the unit we want (make sure it's an SF and in the right spot)
        if ( (RSF1.GetType() == mapStructureFactory) && (RSF1.Location().x == 28+31) && (RSF1.Location().y == 31-1) )
              {
             switch(RSF1.GetBusy())
                {
                    case ctMoDevelop:
                    case ctMoUnDevelop:
                    case ctMoDismantle:
                        break;
                default:
                // We've found it!  Record it and destroy this trigger.
                SD.RSF1 = RSF1;
                CreateTimeTrigger(1, 1, 50, "RedBase1");
                SD.CheckFirstSF.Destroy();
            }
        }
    }
}
Title: Second Ai Colony
Post by: Ecke100 on June 14, 2013, 01:35:57 PM
Beta 1.4
Title: Second Ai Colony
Post by: Ecke100 on June 14, 2013, 01:37:17 PM
Map file