2019-12-11 12:06 CET

View Issue Details Jump to Notes ]
IDProjectCategoryView StatusLast Update
0000225Spring engineGeneralpublic2006-07-06 15:46
ReporterRafal99 
Assigned Totvo 
PrioritynormalSeveritytweakReproducibilityalways
StatusresolvedResolutionfixed 
Product Version 
Target VersionFixed in Version 
Summary0000225: [Patch] Some additions and fixes to the AI interface
Description1. Adds PlayerCommandEvent to CGlobalAI::HandleEvent() function. It is called when player gives an order to units controlled by globalAI (when player shares com with an AI for example).

struct PlayerCommandEvent {
    std::vector<int> units;
    Command command;
    int player;
};
 
2. Adds AIVAL_SCRIPT_FILENAME to CGlobalAI::HandleEvent(). It gives AI's possibility to know name of script file if it is file other then script.txt. It will be useful for AI's which reads information about game setup from script file.

3. Fixes problem with CB->GetUnitPos(unit) called inside CGlobalAI::EnemyEnterRadar(unit) always giving 0 value. It happened because EnemyEnterRadar function was called before unit's radar status was being changed. So inside CGlobalAI::EnemyEnterRadar unit was still outside radar.

4. Fixes similar problem with CB->GetUnitDef(unit) inside CGlobalAI::EnemyEnterLOS(unit).

5. Fixes crash happening when globalAI dll tried to call CB->CreateGroup() (and probably other group commands). It happened because CGlobalAI::CGlobalAI() initializes callback before initializing gh (grouphandler), so callback->ai->gh stays being uninitialized.

6. Fixes error message "AI has modified spring components(possible cheat)" appearing when player tries to assign groupAI to units controlled by globalAI. Although i haven't tested it in multiplayer games with AI, so i am not sure if it won't still happen in that games.

Everythink was compiled and tested (but only in single player), so shouldn't cause problems.
TagsNo tags attached.
Checked infolog.txt for Errors
Attached Files
  • patch file icon 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);
     }
     
    
    patch file icon AiInterfaceFixes.patch (8,466 bytes) 2006-07-02 00:13 +

-Relationships
+Relationships

-Notes

~0000279

tvo (reporter)

committed, thanks
+Notes

-Issue History
Date Modified Username Field Change
2006-07-02 00:12 Rafal99 New Issue
2006-07-02 00:13 Rafal99 File Added: AiInterfaceFixes.patch
2006-07-06 15:46 tvo Status new => resolved
2006-07-06 15:46 tvo Resolution open => fixed
2006-07-06 15:46 tvo Assigned To => tvo
2006-07-06 15:46 tvo Note Added: 0000279
2006-07-06 15:46 tvo Status resolved => assigned
2006-07-06 15:46 tvo Status assigned => resolved
+Issue History