[code]// Manipulating the group itself
Disable(); // Disables the group (I'm assuming this prevents it from doing anything or being rebuilt, but I don't know for sure)
Enable(); // Enables the group (Only needed if previously disabled)
IsInitialized(); // No idea, though I'd guess it checks if you've actually created the group/specified what type of group it should be (see below)
Destroy(); // Destroys the group. OP2 can no longer reference this group. The units in the group are freed up and can be put in another group now
// Initializing the group (note: I'll explain what each type of group does below)
CreateBuildingGroup(Player[Owner]); // Initializes this group as a building group
CreateMiningGroup(Player[Owner]): // Initializes this group as a mining group
CreateFightGroup(Player[Owner]): // Initializes this group as a fight group
// Note that each group MUST be one of these three types. There is no "generic" group type.
// Manipulating the units in the group
TakeUnit(Unit Handle); // Takes the specified unit and adds it to the group
TakeAllUnits(Unit Group); // Takes all units in the specified group and adds them to this group
SetLights(0 = off, 1 = on); // Turn on/off lights for all units in the group
SetTargCount(Unit Type, Cargo, Amount); // Used to tell a Vehicle Factory how many units of type X this group needs
ClearTargCount(); // Erases any data set by SetTargCount. Useful for changing the type of units a group uses.
RemoveUnit(Unit Handle); // Removes the specified unit from the group
HasBeenAttacked(); // Checks if the group has been attacked by enemy units
SetDeleteWhenEmpty(0 = false, 1 = true); // Deletes the group if all units in it have been destroyed (assumed?)
// Example
// Create a group to defend our base
FightGroup BaseDefense; // Note: For now, this should be a global variable
...
(in InitProc)
// Initialize it
BaseDefense = CreateFightGroup(Player[playerAI]);
// Create some units for it
Unit Unit1;
TethysGame::CreateUnit(Unit1, mapLynx, ... );
BaseDefense.TakeUnit(Unit1);
TethysGame::CreateUnit(Unit1, mapLynx, ... );
BaseDefense.TakeUnit(Unit1);
TethysGame::CreateUnit(Unit1, mapLynx, ... );
BaseDefense.TakeUnit(Unit1);
// Do some stuff to the group
BaseDefense.SetLights(1);
BaseDefense.SetTargCount(mapLynx, mapLaser, 3);
...
// If we research Rail Gun, replace the Lasers with Rail Guns
SCRIPT_API void RailGunResearched()
{
BaseDefense.ClearTargCount();
BaseDefense.SetTargCount(mapLynx, mapRailGun, 3);
}
...
// If we get Thor's Hammer, destroy this group
SCRIPT_API void ThorsResearched()
{
BaseDefense.Destroy();
}
// Construction
RecordBuilding(LOCATION(x, y), Unit Type, Cargo Type); // Tells the AI what type of building should be at the specified location. More info below.
RecordTube(LOCATION(x, y) ); // Tells the AI that a tube needs to be at the specified location.
RecordWall(LOCATION(x, y), Wall Type); // Tells the AI that a wall of the specified type must be at the specified location.
// Building Vehicles
RecordVehReinforceGroup(Group, Priority); // Tells the VF(s) to build units for the specified group until it's target count is reached
UnRecordVehGroup(Group); // Tells the VF(s) to stop reinforcing the specified group
// Generic functions
SetRect(Region); // Specifies where the units will wait when they're idle.
// Demonstrating how to build a base and setup vehicle rebuilding
BuildingGroup Construction;
BuildingGroup RebuildMines;
BuildingGroup Reinforce;
...
// Create the Construction building group
Construction = CreateBuildingGroup(Player[1]);
// Add the units to the group
MAP_RECT ConVecBox(225+31, 71-1, 232+31, 79-1);
Construction.SetRect(ConVecBox);
Construction.TakeUnit(SFact);
Construction.TakeUnit(ConVec1);
Construction.TakeUnit(ConVec2);
Construction.TakeUnit(ConVec3);
Construction.SetTargCount(mapConVec, mapNone, 3);
// Record buildings to the list
Construction.RecordBuilding(LOCATION(233+31, 74-1), mapCommandCenter, mapNone); // How are we going to rebuild the CC?
Construction.RecordBuilding(LOCATION(229+31, 73-1), mapStructureFactory, mapNone);
...
// New buildings
Construction.RecordBuilding(LOCATION(252+31, 116-1), mapMHDGenerator, mapNone);
// Create the RebuildMines building group
RebuildMines = CreateBuildingGroup(Player[1]);
// Add the units to the group
MAP_RECT MinerBox(240+31, 78-1, 244+31, 81-1);
RebuildMines.SetRect(MinerBox);
RebuildMines.TakeUnit(Miner);
RebuildMines.TakeUnit(COreMine);
RebuildMines.TakeUnit(ROreMine);
RebuildMines.SetTargCount(mapRoboMiner, mapNone, 1);
RebuildMines.SetTargCount(mapCommonOreMine, mapNone, 2);
// Record the mines
RebuildMines.RecordBuilding(LOCATION(241+31, 89-1), mapCommonOreMine, mapNone);
RebuildMines.RecordBuilding(LOCATION(245+31, 112-1), mapCommonOreMine, mapNone);
// Setup the Reinforce building group
Reinforce = CreateBuildingGroup(Player[1]);
// Assign the Vehicle Factories and Arachnid Factory to the group
Reinforce.TakeUnit(VFact1);
Reinforce.TakeUnit(VFact2);
Reinforce.TakeUnit(VFact3);
Reinforce.TakeUnit(AFact);
// Setup the reinforcement info
Reinforce.RecordVehReinforceGroup(CommonMining1, 1500);
Reinforce.RecordVehReinforceGroup(CommonMining2, 1500);
Reinforce.RecordVehReinforceGroup(Construction, 1000);
Reinforce.RecordVehReinforceGroup(EWorker, 500);
Reinforce.RecordVehReinforceGroup(RebuildMines, 3000);
// There are three different Setup functions. Only one is worth using.
Setup(Mine Unit Handle, Smelter Unit Handle, Idle Region); // Grabs the mine and smelter you want to use as well as the region idle trucks should wait (should be near the Smelter or Mine)
// Sets up the first mining group and assigns it to player 1
CommonMining1 = CreateMiningGroup(Player[1]);
// Sets up the mining location and adds the necessary units to the group.
MAP_RECT CommonBox1(230+31, 81-1, 242+31, 90-1);
CommonMining1.Setup(COreMine, COreSmelter1, CommonBox1);
CommonMining1.TakeUnit(CargoTruck1);
CommonMining1.TakeUnit(CargoTruck2);
CommonMining1.SetTargCount(mapCargoTruck, mapNone, 2);
// Mining Group 2
CommonMining2 = CreateMiningGroup(Player[1]);
MAP_RECT CommonBox2(230+31, 81-1, 242+31, 90-1);
CommonMining2.Setup(COreMine, COreSmelter2, CommonBox2);
CommonMining2.TakeUnit(CargoTruck3);
CommonMining2.TakeUnit(CargoTruck4);
CommonMining2.SetTargCount(mapCargoTruck, mapNone, 2);
// Basic Fight Group Stuff
SetRect(Region); // Specifies an area for this group to wait at when idle OR defend.
DoGuardRect(); // Orders the fight group to defend the region designated with SetRect to the bitter end.
SetTargetUnit(Unit Handle); // Specifies a unit for this group to attack or protect.
DoAttackUnit(); // Orders the group to attack the unit specified with SetTargetUnit
DoGuardUnit(); // Orders the group to defend the unit specified with SetTargetUnit
SetAttackType(Unit Type); // Specifies a unit type for this group to target
DoAttackEnemy(); // Orders this group to attack the enemy, paying special attention to all units of the type specified by SetAttackType
// Create a fight group that will Micro Rush the enemy
MicroRush1 = CreateFightGroup(Player[AI]);
MAP_RECT FightIdle(231+31, 60-1, 238+31, 65-1);
MicroRush1.SetRect(FightIdle);
MicroRush1.SetTargCount(mapLynx, mapMicrowave, 14);
...
// If the group is ready, attack
if (MicroRush1.TotalUnitCount() == 14)
{
MicroRush1.SetAttackType(mapCommandCenter);
MicroRush1.DoAttackEnemy();
}
Unit Convec1;
Unit Convec2;
Unit Convec3;
Unit SFactory;
TethysGame::CreateUnit(SFactory, mapStructureFactory, LOCATION(69+31, 64-1), 1, mapNone, 0);
TethysGame::CreateUnit(Convec1, mapConVec, LOCATION(66+31, 68-1), 1, mapNone, 0);
Convec1.DoSetLights(1);
TethysGame::CreateUnit(Convec2, mapConVec, LOCATION(67+31, 68-1), 1, mapNone, 0);
Convec2.DoSetLights(1);
TethysGame::CreateUnit(Convec3, mapConVec, LOCATION(68+31, 68-1), 1, mapNone, 0);
Convec3.DoSetLights(1);
Construction = CreateBuildingGroup(Player[1]);
MAP_RECT ConVecBox(67+31, 66-1, 71+31, 70-1);
Construction.SetRect(ConVecBox);
Construction.TakeUnit(SFactory);
Construction.TakeUnit(Convec1);
Construction.TakeUnit(Convec1);
Construction.TakeUnit(Convec1);
Construction.SetTargCount(mapConVec, mapNone, 3);
Construction.RecordBuilding(LOCATION(61+31, 64-1), mapCommonStorage, mapNone);
I waited for 50 marks. Maybe Visual C++ 2008 Express Edition hates me. :'(I have to say that's odd, as in singleplayer they seem to love rebuilding in front of you.
Edit: Strange, after I destroyed my last starflare lynx, the AI worked! It looks like it doesn't build anything while enemy units are somewhere around the colony. But thank you for looking at the .cpp file.
/* Add the units to the group */
MAP_RECT MinerBox(100+31, 25-1, 103+31, 23-1);
Unit COreMine;
Unit ROreMine;
Unit Miner;
TethysGame::CreateUnit(COreMine, mapCommonOreMine, LOCATION(102+31, 24-1), 1, mapNone, 2);
RebuildMines.SetRect(MinerBox);
RebuildMines.TakeUnit(Miner);
RebuildMines.TakeUnit(COreMine);
RebuildMines.TakeUnit(ROreMine);
RebuildMines.SetTargCount(mapRoboMiner, mapNone, 1);
RebuildMines.SetTargCount(mapCommonOreMine, mapNone, 2);
/* Record the mines */
RebuildMines.RecordBuilding(LOCATION(102+31, 24-1), mapCommonOreMine, mapNone);
RebuildMines.RecordBuilding(LOCATION(97+31, 45-1), mapCommonOreMine, mapNone);
MiningGroup CommonMining1;
/* Sets up the first mining group and assigns it to player 1 */
CommonMining1 = CreateMiningGroup(Player[1]);
/* Sets up the mining location and adds the necessary units to the group. */
MAP_RECT CommonBox1(89+31, 24-1, 98+31, 31-1);
Unit CargoTruck1;
Unit CargoTruck2;
Unit CargoTruck3;
Unit COreSmelter1;
TethysGame::CreateUnit(CargoTruck1, mapCargoTruck, LOCATION(95+31, 25-1), 1, mapNone, 1);
CargoTruck1.DoSetLights(1);
TethysGame::CreateUnit(CargoTruck2, mapCargoTruck, LOCATION(91+31, 25-1), 1, mapNone, 1);
CargoTruck2.DoSetLights(1);
TethysGame::CreateUnit(CargoTruck3, mapCargoTruck, LOCATION(89+31, 27-1), 1, mapNone, 1);
CargoTruck3.DoSetLights(1);
TethysGame::CreateUnit(COreSmelter1, mapCommonOreSmelter, LOCATION(94+31, 29-1), 1, mapNone, 0);
CommonMining1.Setup(COreMine, COreSmelter1, CommonBox1);
CommonMining1.TakeUnit(CargoTruck1);
CommonMining1.TakeUnit(CargoTruck2);
CommonMining1.TakeUnit(CargoTruck3);
CommonMining1.TakeUnit(COreSmelter1);
CommonMining1.SetTargCount(mapCargoTruck, mapNone, 5);
RebuildMines.SetTargCount(mapRoboMiner, mapNone, 1);
/* Setup Enemy Construction Group */
BuildingGroup ebuild;
ebuild = CreateBuildingGroup(Player[1]);
MAP_RECT ConVecBox(123+32, 42-1, 128+32, 43-1);
ebuild.SetRect(ConVecBox);
ebuild.TakeUnit(scriptGlobal.estructf);
ebuild.TakeUnit(scriptGlobal.convec1);
ebuild.TakeUnit(scriptGlobal.convec2);
ebuild.TakeUnit(scriptGlobal.convec3);
ebuild.SetTargCount(mapConVec, mapNone, 3);
ebuild.RecordBuilding(LOCATION(125+32, 24-1), mapVehicleFactory, mapNone);
ebuild.RecordBuilding(LOCATION(117+32, 39-1), mapCommonOreSmelter, mapNone);
ebuild.RecordBuilding(LOCATION(112+32, 39-1), mapCommonOreSmelter, mapNone);
ebuild.RecordBuilding(LOCATION(115+32, 24-1), mapTokamak, mapNone);
ebuild.RecordBuilding(LOCATION(118+32, 24-1), mapTokamak, mapNone);
ebuild.RecordBuilding(LOCATION(116+32, 29-1), mapAgridome, mapNone);
ebuild.RecordBuilding(LOCATION(121+32, 29-1), mapNursery, mapNone);
ebuild.RecordBuilding(LOCATION(116+32, 32-1), mapStandardLab, mapNone);
ebuild.RecordBuilding(LOCATION(121+32, 32-1), mapRobotCommand, mapNone);
ebuild.RecordBuilding(LOCATION(116+32, 35-1), mapAgridome, mapNone);
ebuild.RecordBuilding(LOCATION(121+32, 35-1), mapUniversity, mapNone);
/* Rebuild Mines */
BuildingGroup mine1;
mine1 = CreateBuildingGroup(Player[1]);
MAP_RECT minerbox(110+32, 42-1, 115+32, 43-1);
mine1.SetRect(minerbox);
mine1.TakeUnit(scriptGlobal.robominer1);
mine1.TakeUnit(scriptGlobal.eminer1);
mine1.TakeUnit(scriptGlobal.evecf);
mine1.SetTargCount(mapRoboMiner, mapNone, 1);
mine1.SetTargCount(mapCommonOreMine, mapNone, 1);
mine1.RecordBuilding(LOCATION(120+32, 47-1), mapCommonOreMine, mapNone);
/* Setup Enemy Mining */
MiningGroup emine1;
MiningGroup emine2;
emine1 = CreateMiningGroup(Player[1]);
emine1.Setup(scriptGlobal.eminer1, scriptGlobal.esmelt1, MAP_RECT(119+32, 46-1, 122+32, 48-1));
TethysGame::CreateUnit(scriptGlobal.etruck1, mapCargoTruck, LOCATION(114+32, 42-1), 1, mapNone, 0);
scriptGlobal.etruck1.DoSetLights(1);
emine1.TakeUnit(scriptGlobal.etruck1);
TethysGame::CreateUnit(scriptGlobal.etruck2, mapCargoTruck, LOCATION(116+32, 42-1), 1, mapNone, 0);
scriptGlobal.etruck2.DoSetLights(1);
emine1.TakeUnit(scriptGlobal.etruck2);
emine1.SetTargCount(mapCargoTruck, mapNone, 2);
emine2 = CreateMiningGroup(Player[1]);
emine2.Setup(scriptGlobal.eminer1, scriptGlobal.esmelt2, MAP_RECT(114+32, 40-1, 115+32, 41-1));
TethysGame::CreateUnit(scriptGlobal.etruck3, mapCargoTruck, LOCATION(118+32, 42-1), 1, mapNone, 0);
scriptGlobal.etruck3.DoSetLights(1);
emine2.TakeUnit(scriptGlobal.etruck3);
TethysGame::CreateUnit(scriptGlobal.etruck4, mapCargoTruck, LOCATION(114+32, 42-1), 1, mapNone, 0);
scriptGlobal.etruck4.DoSetLights(1);
emine2.TakeUnit(scriptGlobal.etruck4);
emine2.SetTargCount(mapCargoTruck, mapNone, 2);
/* Rebuild Vehicles */
BuildingGroup Reinforce;
Reinforce = CreateBuildingGroup(Player[1]);
Reinforce.TakeUnit(scriptGlobal.evecf);
Reinforce.RecordVehReinforceGroup(ebuild, 3000);