Page 1 of 1

Need help with AI developing(VS2005).

Posted: 02 Jul 2008, 16:42
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.

Re: Need help with AI developing(VS2005).

Posted: 02 Jul 2008, 16:59
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?

Re: Need help with AI developing(VS2005).

Posted: 02 Jul 2008, 19:55
by conanos
The game crashes during the battle and vs show me unhalted exception.
It's debug build(rts and AI).

Re: Need help with AI developing(VS2005).

Posted: 02 Jul 2008, 20:41
by AF
before you continue, check the ai interface has not returned a null pointer for UnitDef*

Re: Need help with AI developing(VS2005).

Posted: 02 Jul 2008, 21:03
by conanos
Thx. How can i check it? Sorry for that stiupid question but i want be sure.

Re: Need help with AI developing(VS2005).

Posted: 02 Jul 2008, 21:22
by BrainDamage
example

Code: Select all

if ( ud == NULL ) return; // not a valid pointer, return before using & segfaulting

Re: Need help with AI developing(VS2005).

Posted: 02 Jul 2008, 21:55
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.