AiInterfaceFixes.patch (8,466 bytes)
2006-07-02 00:13
Index: D:/xxxxx/TA Spring Source/trunk Source/rts/ExternalAI/IGlobalAI.h
===================================================================
--- D:/xxxxx/TA Spring Source/trunk Source/rts/ExternalAI/IGlobalAI.h (revision 1552)
+++ D:/xxxxx/TA Spring Source/trunk Source/rts/ExternalAI/IGlobalAI.h (working copy)
@@ -10,11 +10,6 @@
#define GLOBAL_AI_INTERFACE_VERSION 15
-// Both use ChangeTeamEvent for data
-#define AI_EVENT_UNITGIVEN 1
- struct ChangeTeamEvent {
- int unit, newteam, oldteam;
- };
struct WeaponFireEvent {
int unit;
WeaponDef* def;
@@ -19,8 +14,13 @@
int unit;
WeaponDef* def;
};
+
+#define AI_EVENT_UNITGIVEN 1
#define AI_EVENT_UNITCAPTURED 2
+// Both use ChangeTeamEvent for data
+
#define AI_EVENT_WEAPON_FIRED 3
+#define AI_EVENT_PLAYER_COMMAND 4
class SPRING_API IGlobalAI
{
@@ -28,6 +28,11 @@
struct ChangeTeamEvent {
int unit, newteam, oldteam;
};
+ struct PlayerCommandEvent {
+ std::vector<int> units;
+ Command command;
+ int player;
+ };
virtual void InitAI(IGlobalAICallback* callback, int team)=0;
Index: D:/xxxxx/TA Spring Source/trunk Source/rts/ExternalAI/GlobalAIHandler.h
===================================================================
--- D:/xxxxx/TA Spring Source/trunk Source/rts/ExternalAI/GlobalAIHandler.h (revision 1552)
+++ D:/xxxxx/TA Spring Source/trunk Source/rts/ExternalAI/GlobalAIHandler.h (working copy)
@@ -9,6 +9,7 @@
class CUnit;
class CGlobalAI;
struct WeaponDef;
+struct Command;
class CGlobalAIHandler :
public CObject
@@ -35,6 +36,7 @@
void UnitTaken(CUnit* unit, int newteam);
void UnitGiven(CUnit* unit, int oldteam);
void WeaponFired(CUnit* unit,WeaponDef* def);
+ void PlayerCommandGiven(std::vector<int>& selectedunits,Command& c,int player);
CGlobalAI* ais[MAX_TEAMS];
bool hasAI;
Index: D:/xxxxx/TA Spring Source/trunk Source/rts/ExternalAI/GlobalAIHandler.cpp
===================================================================
--- D:/xxxxx/TA Spring Source/trunk Source/rts/ExternalAI/GlobalAIHandler.cpp (revision 1552)
+++ D:/xxxxx/TA Spring Source/trunk Source/rts/ExternalAI/GlobalAIHandler.cpp (working copy)
@@ -7,6 +7,7 @@
#include "Game/GameHelper.h"
#include "TimeProfiler.h"
#include "Platform/errorhandler.h"
+#include "Game/Player.h"
#include "mmgr.h"
CGlobalAIHandler* globalAI=0;
@@ -301,3 +302,17 @@
HANDLE_EXCEPTION;
}
+void CGlobalAIHandler::PlayerCommandGiven(std::vector<int>& selectedunits,Command& c,int player)
+{
+ if(ais[gs->players[player]->team]){
+ try {
+ IGlobalAI::PlayerCommandEvent pce;
+ pce.units = selectedunits;
+ pce.player = player;
+ pce.command = c;
+ ais[gs->players[player]->team]->ai->HandleEvent(AI_EVENT_PLAYER_COMMAND,&pce);
+ //shouldn't "delete pce" be here??
+ }
+ HANDLE_EXCEPTION;
+ }
+}
Index: D:/xxxxx/TA Spring Source/trunk Source/rts/Game/SelectedUnits.cpp
===================================================================
--- D:/xxxxx/TA Spring Source/trunk Source/rts/Game/SelectedUnits.cpp (revision 1559)
+++ D:/xxxxx/TA Spring Source/trunk Source/rts/Game/SelectedUnits.cpp (working copy)
@@ -12,6 +12,7 @@
#include "Net.h"
#include "ExternalAI/GroupHandler.h"
#include "ExternalAI/Group.h"
+#include "ExternalAI/GlobalAIHandler.h"
#include "UI/InfoConsole.h"
#include "Camera.h"
#include "Rendering/UnitModels/3DOParser.h"
@@ -343,6 +344,9 @@
{
selectedUnitsAI.GiveCommandNet(c,player);
+ if (netSelected[player].size() > 0)
+ globalAI->PlayerCommandGiven(netSelected[player],c,player);
+
/* if(!(c.options & CONTROL_KEY) && c.params.size()==3) {//fix: some better way to detect if its a map position
float3 oldPos(0,0,0);
vector<int>::iterator ui;
Index: D:/xxxxx/TA Spring Source/trunk Source/rts/ExternalAI/IAICallback.h
===================================================================
--- D:/xxxxx/TA Spring Source/trunk Source/rts/ExternalAI/IAICallback.h (revision 1552)
+++ D:/xxxxx/TA Spring Source/trunk Source/rts/ExternalAI/IAICallback.h (working copy)
@@ -14,7 +14,8 @@
// GetValue() constants
#define AIVAL_NUMDAMAGETYPES 1 // int
-#define AI_EXCEPTION_HANDLING 2
+#define AI_EXCEPTION_HANDLING 2 // bool
+#define AIVAL_SCRIPT_FILENAME 3 // string
struct PointMarker
{
Index: D:/xxxxx/TA Spring Source/trunk Source/rts/ExternalAI/AICallback.cpp
===================================================================
--- D:/xxxxx/TA Spring Source/trunk Source/rts/ExternalAI/AICallback.cpp (revision 1552)
+++ D:/xxxxx/TA Spring Source/trunk Source/rts/ExternalAI/AICallback.cpp (working copy)
@@ -78,7 +78,7 @@
void CAICallback::verify()
{
CGlobalAI *gai = globalAI->ais [team];
- if (gai && (((group && gai->gh != group->handler) || gai->team != team))) {
+ if (gai && (((group && group->handler != gai->gh && group->handler != grouphandler) || gai->team != team))) {
handleerror (0, "AI has modified spring components(possible cheat)", "Spring is closing:", MBF_OK | MBF_EXCL);
exit (-1);
}
@@ -857,10 +857,13 @@
case AIVAL_NUMDAMAGETYPES:
*((int*)data) = DamageArray::numTypes;
return true;
- case AI_EXCEPTION_HANDLING:{
+ case AI_EXCEPTION_HANDLING:
*(bool*)data = CGlobalAIHandler::CatchException();
return true;
- }
+ case AIVAL_SCRIPT_FILENAME:
+ if (gameSetup) *((std::string*)data) = gameSetup->setupFileName;
+ else *((std::string*)data) = "";
+ return true;
default:
return false;
}
Index: D:/xxxxx/TA Spring Source/trunk Source/rts/Game/GameSetup.h
===================================================================
--- D:/xxxxx/TA Spring Source/trunk Source/rts/Game/GameSetup.h (revision 1552)
+++ D:/xxxxx/TA Spring Source/trunk Source/rts/Game/GameSetup.h (working copy)
@@ -15,6 +15,7 @@
bool Draw(void);
TdfParser file;
+ std::string setupFileName;
int myPlayer;
int numPlayers; //the expected amount of players
std::string mapname;
Index: D:/xxxxx/TA Spring Source/trunk Source/rts/Game/GameSetup.cpp
===================================================================
--- D:/xxxxx/TA Spring Source/trunk Source/rts/Game/GameSetup.cpp (revision 1552)
+++ D:/xxxxx/TA Spring Source/trunk Source/rts/Game/GameSetup.cpp (working copy)
@@ -45,6 +45,7 @@
bool CGameSetup::Init(std::string setupFile)
{
+ setupFileName = setupFile;
if(setupFile.empty())
return false;
CFileHandler fh(setupFile);
Index: D:/xxxxx/TA Spring Source/trunk Source/rts/Sim/Units/Unit.cpp
===================================================================
--- D:/xxxxx/TA Spring Source/trunk Source/rts/Sim/Units/Unit.cpp (revision 1552)
+++ D:/xxxxx/TA Spring Source/trunk Source/rts/Sim/Units/Unit.cpp (working copy)
@@ -306,11 +306,8 @@
if(losStatus[a] & LOS_INTEAM){
} else if(loshandler->InLos(this,a)){
if(!(losStatus[a]&LOS_INLOS)){
- if(!(losStatus[a]&LOS_INRADAR)){
- globalAI->UnitEnteredRadar(this,a);
- }
- globalAI->UnitEnteredLos(this,a);
-
+ int prevLosStatus = losStatus[a];
+
if(mobility || beingBuilt){
losStatus[a]|=(LOS_INLOS | LOS_INRADAR);
} else {
@@ -316,6 +313,11 @@
} else {
losStatus[a]|=(LOS_INLOS | LOS_INRADAR | LOS_PREVLOS | LOS_CONTRADAR);
}
+
+ if(!(prevLosStatus&LOS_INRADAR)){
+ globalAI->UnitEnteredRadar(this,a);
+ }
+ globalAI->UnitEnteredLos(this,a);
}
} else if(radarhandler->InRadar(this,a)){
if((losStatus[a] & LOS_INLOS)){
@@ -322,8 +324,8 @@
globalAI->UnitLeftLos(this,a);
losStatus[a]&= ~LOS_INLOS;
} else if(!(losStatus[a] & LOS_INRADAR)){
+ losStatus[a]|= LOS_INRADAR;
globalAI->UnitEnteredRadar(this,a);
- losStatus[a]|= LOS_INRADAR;
}
} else {
if((losStatus[a]&LOS_INRADAR)){
Index: D:/xxxxx/TA Spring Source/trunk Source/rts/ExternalAI/GlobalAI.cpp
===================================================================
--- D:/xxxxx/TA Spring Source/trunk Source/rts/ExternalAI/GlobalAI.cpp (revision 1552)
+++ D:/xxxxx/TA Spring Source/trunk Source/rts/ExternalAI/GlobalAI.cpp (working copy)
@@ -38,8 +38,8 @@
ReleaseAI = (RELEASEAI)lib->FindAddress("ReleaseAI");
ai=GetNewAI();
+ gh=new CGroupHandler(team);
callback=new CGlobalAICallback(this);
- gh=new CGroupHandler(team);
ai->InitAI(callback,team);
}