Need help with AI developing(VS2005).

Need help with AI developing(VS2005).

Here is where ideas can be collected for the skirmish AI in development

Moderators: hoijui, Moderators

Post Reply
User avatar
conanos
Posts: 4
Joined: 23 Feb 2008, 14:51

Need help with AI developing(VS2005).

Post by conanos »

I have start lern AI coding and i have a question: what is wrong in this code (BOT DLL):

Code: Select all

void TestGlobalAI::EnemyEnterLOS(int enemy)
{
	enemies.insert(enemy);
	enemypos = callback->GetAICallback()->GetUnitPos(enemy);
	enemyspoted = true;
	losid[enemy]=1;
}

void TestGlobalAI::EnemyLeaveLOS(int enemy)
{
	enemies.erase(enemy);
	losid[enemy]=0;
}

void TestGlobalAI::UnitDestroyed(int unit,int attacker)
{
	myUnits.erase(unit);
	
	
		const UnitDef *ud=callback->GetAICallback()->GetUnitDef(unit);
		if(losid[attacker]==1)
		{
				
				const UnitDef *ude=callback->GetAICallback()->GetUnitDef(attacker);
				
				Tbl[ud->id][ude->id]+=1;
				
				sprintf(g,"TBL[%i][%i]: %i",ud->id,ude->id,Tbl[ud->id][ude->id]);
				callback->GetAICallback()->SendTextMsg(g,0);
			
			
		}
		warunit[ud->id]+=1;
		sprintf(g,"warunit[%i]: %i",ud->id,warunit[ud->id]);
		callback->GetAICallback()->SendTextMsg(g,0);
	

	
	
	
}



void TestGlobalAI::EnemyEnterRadar(int enemy)
{
}

void TestGlobalAI::EnemyLeaveRadar(int enemy)
{

}

void TestGlobalAI::EnemyDamaged(int damaged,int attacker,float damage,float3 dir)
{
}

void TestGlobalAI::EnemyDestroyed(int enemy,int attacker)
{
	enemies.erase(enemy);
		const UnitDef *ud=callback->GetAICallback()->GetUnitDef(attacker);
		if(losid[enemy]==1)
		{
				losid[enemy]=0;
				
				const UnitDef *ude=callback->GetAICallback()->GetUnitDef(enemy);
				Tbl[ud->id][ude->id]-=1;
				
				sprintf(g,"TBL[%i][%i]: %i",ud->id,ude->id,Tbl[ud->id][ude->id]);
				callback->GetAICallback()->SendTextMsg(g,0);
			
			
		}
		warunit[ud->id]-=1;
		sprintf(g,"warunit[%i]: %i",ud->id,warunit[ud->id]);
		callback->GetAICallback()->SendTextMsg(g,0);
	
	

}
When i am testing this BOT, game crash
:( . I dont know why.
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Re: Need help with AI developing(VS2005).

Post by AF »

Can you give more information, such as how ti crashes, is it a debug build or a release build, and have you compiled spring using VS2005 or are you attempting to use the spring off of this site with the AI?
User avatar
conanos
Posts: 4
Joined: 23 Feb 2008, 14:51

Re: Need help with AI developing(VS2005).

Post by conanos »

The game crashes during the battle and vs show me unhalted exception.
It's debug build(rts and AI).
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Re: Need help with AI developing(VS2005).

Post by AF »

before you continue, check the ai interface has not returned a null pointer for UnitDef*
User avatar
conanos
Posts: 4
Joined: 23 Feb 2008, 14:51

Re: Need help with AI developing(VS2005).

Post by conanos »

Thx. How can i check it? Sorry for that stiupid question but i want be sure.
User avatar
BrainDamage
Lobby Developer
Posts: 1164
Joined: 25 Sep 2006, 13:56

Re: Need help with AI developing(VS2005).

Post by BrainDamage »

example

Code: Select all

if ( ud == NULL ) return; // not a valid pointer, return before using & segfaulting
User avatar
conanos
Posts: 4
Joined: 23 Feb 2008, 14:51

Re: Need help with AI developing(VS2005).

Post by conanos »

thx but i use somethink like that :

Code: Select all

const UnitDef *ud=callback->GetAICallback()->GetUnitDef(attacker);
	if(ud!=0)
	{...}
and it works :-) .
Thank you AF.
Post Reply

Return to “AI”