Пример #1
0
void CEngineOutHandler::UnitFinished(const CUnit& unit) {
	AI_EVT_MTH();

	const int teamId     = unit.team;
	const int allyTeamId = unit.allyteam;
	const int unitId     = unit.id;

	DO_FOR_TEAM_SKIRMISH_AIS(UnitFinished(unitId), teamId);
	DO_FOR_ENEMY_SKIRMISH_AIS(EnemyFinished(unitId), allyTeamId, unit);
}
Пример #2
0
int CKAIK::HandleEvent(int msg, const void* data) {
	if (ai->Initialized()) {
		switch (msg) {
			case AI_EVENT_UNITGIVEN:
			case AI_EVENT_UNITCAPTURED: {
				const ChangeTeamEvent* cte = (const ChangeTeamEvent*) data;

				const int myAllyTeamId = ai->cb->GetMyAllyTeam();
				const bool oldEnemy = !ai->cb->IsAllied(myAllyTeamId, ai->cb->GetTeamAllyTeam(cte->oldteam));
				const bool newEnemy = !ai->cb->IsAllied(myAllyTeamId, ai->cb->GetTeamAllyTeam(cte->newteam));

				if (oldEnemy && !newEnemy) {
					// unit changed from an enemy to an allied team
					// we got a new friend! :)
					EnemyDestroyed(cte->unit, -1);
				} else if (!oldEnemy && newEnemy) {
					// unit changed from an ally to an enemy team
					// we lost a friend! :(
					EnemyCreated(cte->unit);

					if (!ai->cb->UnitBeingBuilt(cte->unit)) {
						EnemyFinished(cte->unit);
					}
				}

				if (cte->oldteam == ai->cb->GetMyTeam()) {
					// we lost a unit
					UnitDestroyed(cte->unit, -1);

					// FIXME: multiple units given during same frame?
					ai->uh->lastCapturedUnitFrame = ai->cb->GetCurrentFrame();
					ai->uh->lastCapturedUnitID = cte->unit;
				} else if (cte->newteam == ai->cb->GetMyTeam()) {
					// we have a new unit
					UnitCreated(cte->unit, -1);

					if (!ai->cb->UnitBeingBuilt(cte->unit)) {
						UnitFinished(cte->unit);
						ai->uh->IdleUnitAdd(cte->unit, ai->cb->GetCurrentFrame());
					}
				}
			} break;
		}
	}

	return 0;
}
Пример #3
0
int AAI::HandleEvent(int msg, const void* data)
{
	switch (msg)
	{
		case AI_EVENT_UNITGIVEN: // 1
		case AI_EVENT_UNITCAPTURED: // 2
			{
				const IGlobalAI::ChangeTeamEvent* cte = (const IGlobalAI::ChangeTeamEvent*) data;

				const int myAllyTeamId = cb->GetMyAllyTeam();
				const bool oldEnemy = !cb->IsAllied(myAllyTeamId, cb->GetTeamAllyTeam(cte->oldteam));
				const bool newEnemy = !cb->IsAllied(myAllyTeamId, cb->GetTeamAllyTeam(cte->newteam));

				if (oldEnemy && !newEnemy) {
					// unit changed from an enemy to an allied team
					// we got a new friend! :)
					EnemyDestroyed(cte->unit, -1);
				} else if (!oldEnemy && newEnemy) {
					// unit changed from an ally to an enemy team
					// we lost a friend! :(
					EnemyCreated(cte->unit);
					if (!cb->UnitBeingBuilt(cte->unit)) {
						EnemyFinished(cte->unit);
					}
				}

				if (cte->oldteam == cb->GetMyTeam()) {
					// we lost a unit
					UnitDestroyed(cte->unit, -1);
				} else if (cte->newteam == cb->GetMyTeam()) {
					// we have a new unit
					UnitCreated(cte->unit, -1);
					if (!cb->UnitBeingBuilt(cte->unit)) {
						UnitFinished(cte->unit);
						UnitIdle(cte->unit);
					}
				}
				break;
			}
	}
	return 0;
}
Пример #4
0
int cRAI::HandleEvent(int msg,const void* data)
{
	if( RAIDEBUGGING ) *l<<"\nHandleEvent("<<msg<<","<<"~"<<")";
	switch (msg)
	{
	case AI_EVENT_UNITGIVEN:
	case AI_EVENT_UNITCAPTURED:
		{
			const IGlobalAI::ChangeTeamEvent* cte = (const IGlobalAI::ChangeTeamEvent*) data;

			const int myAllyTeamId = cb->GetMyAllyTeam();
			const bool oldEnemy = !cb->IsAllied(myAllyTeamId, cb->GetTeamAllyTeam(cte->oldteam));
			const bool newEnemy = !cb->IsAllied(myAllyTeamId, cb->GetTeamAllyTeam(cte->newteam));

			if ( oldEnemy && !newEnemy ) {
			{
				if( Enemies.find(cte->unit) != Enemies.end() )
					EnemyDestroyed(cte->unit,-1);
				}
			}
			else if( !oldEnemy && newEnemy )
			{
				// unit changed from an ally to an enemy team
				// we lost a friend! :(
				EnemyCreated(cte->unit);
				if (!cb->UnitBeingBuilt(cte->unit)) {
					EnemyFinished(cte->unit);
				}
			}

			if( cte->oldteam == cb->GetMyTeam() )
			{
				UnitDestroyed(cte->unit,-1);
			}
			else if( cte->newteam == cb->GetMyTeam() )
			{
				if( cb->GetUnitHealth(cte->unit) <= 0 ) // ! Work Around:  Spring-Version(v0.74b1-0.75b2)
				{
					*l<<"\nERROR: HandleEvent(AI_EVENT_(UNITGIVEN|UNITCAPTURED)): given unit is dead or does not exist";
					return 0;
				}
				UnitCreated(cte->unit, -1);
				Units.find(cte->unit)->second.AIDisabled=false;
				if( !cb->UnitBeingBuilt(cte->unit) )
				{
					UnitFinished(cte->unit);
					UnitIdle(cte->unit);
				}
			}
		}
		break;
	case AI_EVENT_PLAYER_COMMAND:
		{
			const IGlobalAI::PlayerCommandEvent* pce = (const IGlobalAI::PlayerCommandEvent*) data;
			bool ImportantCommand=false;
			if( pce->command.id < 0 )
				ImportantCommand = true;
			switch( pce->command.id )
			{
			case CMD_MOVE:
			case CMD_PATROL:
			case CMD_FIGHT:
			case CMD_ATTACK:
			case CMD_AREA_ATTACK:
			case CMD_GUARD:
			case CMD_REPAIR:
			case CMD_LOAD_UNITS:
			case CMD_UNLOAD_UNITS:
			case CMD_UNLOAD_UNIT:
			case CMD_RECLAIM:
			case CMD_DGUN:
			case CMD_RESTORE:
			case CMD_RESURRECT:
			case CMD_CAPTURE:
				ImportantCommand = true;
			}

			for( int i=0; i<int(pce->units.size()); i++ )
			{
				if( Units.find(pce->units.at(i)) == Units.end() ) // ! Work Around:  Spring-Version(v0.75b2)
				{
					*l<<"\nERROR: HandleEvent(AI_EVENT_PLAYER_COMMAND): unknown unit id="<<pce->units.at(i);
//					pce->units.erase(pce->units.begin()+i);
//					i--;
				}
				else if( ImportantCommand )
					Units.find(pce->units.at(i))->second.humanCommand = true;
			}
			if( ImportantCommand )
			{
				B->HandleEvent(pce);
			}
			else if( pce->command.id == CMD_SELFD )
			{
				for( vector<int>::const_iterator i=pce->units.begin(); i!=pce->units.end(); ++i )
					UnitDestroyed(*i,-1);
			}
		}
		break;
	}
	if( RAIDEBUGGING ) *l<<"#";
	return 0;
}