Example #1
0
void cCombatManager::UnitIdle(const int& unit, UnitInfo *U)
{
//*l<<"(cui) -eID="<<U->enemyID;
	if( ValidateEnemy(unit,U) && CanAttack(U,U->E,GetEnemyPosition(U->enemyID,U->E)) == 0 )
		U->enemyID=-1;
	float3 fPos=cb->GetUnitPos(unit);
	if( U->enemyID == -1 )
		while( (U->enemyID=GetClosestEnemy(fPos,U)) > 0 && !ValidateEnemy(unit,U) ) {}
	float distance = -1;
	if( U->enemyID >= 0 )
	{
		distance = fPos.distance(GetEnemyPosition(U->enemyID,U->E));
		if( distance == 0 )
			distance = 1;
	}
	if( U->enemyID == -1 || (U->udrBL->task != TASK_ASSAULT && distance > 2.5*8*U->ud->losRadius) )
	{
		U->inCombat=false;
		G->UpdateEventAdd(1,0,unit,U);
		return;
	}
	else if( CommandDGun(unit,U) )
		return;
	else if( U->enemyEff == 0 || (U->udrBL->task != TASK_ASSAULT && distance > 1.75*U->enemyEff->BestRange ) || (U->ud->isCommander && cb->GetUnitHealth(unit)/U->ud->health <= 0.66 ) ) // || G->Enemies.find(U->enemyID)->second.ud->kamikazeDist > distance
	{
		float3 EPos = GetEnemyPosition(U->enemyID,U->E);
		CommandRun(unit,U,EPos);
		return;
	}
	else if( CommandCapture(unit,U,distance) || CommandManeuver(unit,U,distance) )
		return;
	else
	{
		float3 EPos = GetEnemyPosition(U->enemyID,U->E);
		Command c;
		if( U->ud->canAttack && (U->E->inLOS || U->E->inRadar) )
		{
			c.id = CMD_ATTACK;
			c.params.push_back(U->enemyID);
		}
		else if( U->ud->canAttack && (U->udr->IsBomber && U->E->posLocked) )
		{
			c.id = CMD_ATTACK;
			c.params.push_back(EPos.x);
			c.params.push_back(EPos.y);
			c.params.push_back(EPos.z);
		}
		else // cant see enemy or Mod Workaround: Combat Lords - cant be given attack orders
		{
			c.id = CMD_MOVE;
			c.params.push_back(EPos.x -100.0 +rand()%201 );
			c.params.push_back(EPos.y);
			c.params.push_back(EPos.z -100.0 +rand()%201 );
		}

		cb->GiveOrder(unit, &c);
		G->UpdateEventAdd(1,int(GetNextUpdate(distance,U)),unit,U);
	}
}
Example #2
0
void Unit::RunAway()
{

    RenderableObject* runFrom = GetClosestEnemy();
    std::cout << runAwayTimer <<"\n test";
    if(runFrom != NULL){
        Vector2D destination = GetPosition() - runFrom->GetPosition();
        destination = GetPosition() + destination;
        SetDestination(destination.x,destination.y);
    }


}
Example #3
0
Action World::BasicHero() const {
	if (enemies_.empty()) {
		return Action(Position(0, 0));
	}
	if (wolff_.IsSafe(enemies_)) {
		// Shoot.
		int closest_enemy_id = GetClosestEnemy(wolff_.GetPosition(), enemies_)->first;
		return Action(closest_enemy_id);
	}
	else {
		// We need to escape.
		Position escape = wolff_.GetWayToEscape(enemies_);
		return Action(escape);
	}
}
	//! called during the update of the entity		
	void PelletManager::Update()
	{
		VertexBuffer* pVB = GetComponent<GraphicComponent>()->GetVertexBuffer();
		pVB->SetNumVertices(0);

		if(m_Bullets.size())
		{
			u32 bulletIndex = 0;
			for(std::list<Bullet*>::iterator it = m_Bullets.begin(); it != m_Bullets.end();)
			{
				Vector3 vClosestEnemy = Vector3::Zero;
				f32 fDistToClosestEnemy = Math::Epsilon;
				if(GetClosestEnemy((*it)->vPosition, vClosestEnemy, fDistToClosestEnemy))
				{
					f32 fDistFactor = m_fMinDistToEnemy/fDistToClosestEnemy;
					f32 fInterpolator = m_fHomingFactor*fDistFactor*fDistFactor*g_fDeltaTime;
					fInterpolator = Math::Clamp(fInterpolator, 0.0f, 1.0f);
					Vector3 vDirectionToEnemy = (vClosestEnemy-(*it)->vPosition).Normalize();
					(*it)->vDirection = (vDirectionToEnemy-(*it)->vDirection)*fInterpolator + (*it)->vDirection;
				}
				
				(*it)->vPosition += (*it)->vDirection*(*it)->fSpeed*g_fDeltaTime;
				SetupRendering((*it), bulletIndex++, pVB);

				(*it)->fLife -= g_fDeltaTime;
				if((*it)->fLife > 0.0f)
				{
					++it;
				}
				else
				{
					m_Pool->Free((*it));
					it = m_Bullets.erase(it);
				}
			}

			pVB->SetDirty(true);
		}
	}