I am trying some code that hacker posted some time back but for some odd reason my AI units just head to the top corner. I tried changing fighters.AddGuardedRect(MAP_RECT(99,99,99,99));
to another place but it does not change a thing?
here is the code
Unit VF;
TethysGame::CreateUnit(VF, mapVehicleFactory, LOCATION(57,22), 1, mapNone, 0); FightGroup fighters = CreateFightGroup(Player[1]);
BuildingGroup producer = CreateBuildingGroup(Player[1]);
producer.TakeUnit(VF); producer.RecordVehReinforceGroup(fighters, 0); fighters.SetTargCount(mapLynx, mapMicrowave, 2);
fighters.AddGuardedRect(MAP_RECT(99,99,99,99));
fighters.DoGuardRect(); // guard
I tried making it like this fighters.SetRect(0, 0, 0, 0);
but it told me my favorite error :P
'FightGroup::SetRect' : function does not take 4 arguments
what do you suggest I do?
It takes a RECT struct/class as an argument, not the four corners of the rect. Just need extra parentheses and a class name.
fighters.SetRect(MAP_RECT(0, 0, 0, 0));
The problem is not the SetRect. - If you define a SetRect of (99,99,99,99) the created unit(s) should start moving towards that point, and keep circling around it, coz it's an empty region. If you want it to be 1 point, use (99,99,100,100), as the bottom and right edges are not included in the rect. If you create more than 1 unit, you still have the same problem, as all those units will want to stay on that 1 spot. I found it to work better to assign a region, that is AT LEAST large enough to fit all units of the group. In this case you are creating a group of 2 lynx so make the region at least 2 tiles. SetRect(MAP_RECT(99,99,101,101)) creates a 2x2 region at location (68,100), remember the (31,-1) offset!
But, as i said: this is not your problem. The real 'bug' of your code is in the group handling. The way you have your BuildingGroup set up, the new units are not assigned to a default group. Change your code to this:
Unit VF;
TethysGame::CreateUnit(VF, mapVehicleFactory, LOCATION(57,22), 1, mapNone, 0);
FightGroup fighters = CreateFightGroup(Player[1]);
BuildingGroup producer = CreateBuildingGroup(Player[1]);
producer.TakeUnit(VF);
producer.RecordVehReinforceGroup(fighters, 0);
fighters.SetTargCount(mapLynx, mapMicrowave, 2);
// modification:
fighters.DoGuardRect();
fighters.SetRect(MAP_RECT(99,99,101,101));
fighters.AddGuardedRect(MAP_RECT(80,80,120,120)); // just added as example, see below
The "bug" in Outpost 2 group coding, is that when calling DoGuardRect ALL previously stored Rects are removed (in essence: it calls ClearGuarderdRects).
Also, if the region to be guarded is the same as the SetRect region, you do not explicitly have to add it, because SetRect implicitly calls AddGuardedRect to add itself to the list of rects.
Reply if it still doesn't work.
See also: http://wiki.opu.org.uk/AI_Coding (http://wiki.opu.org.uk/AI_Coding)