//=========================================================
// Crea un hijo en un nodo candidato.
//=========================================================
void CDirector_Manager::AddChild()
{
	// Actualizamos los nodos candidatos para la creación.
	UpdateNodes();

	// ¡No hay nodos!
	if ( SpawnNodes.Count() <= 0 )
		return;

	// Intentamos crear al hijo.
	for ( int i = 0; i < MAX_TRIES; ++i )
	{
		// Seleccionamos un nodo candidato al azar.
		CAI_Node *pNode	= GetRandomNode();

		// El nodo no existe.
		if ( !pNode )
			continue;

		// Obtenemos la ubicación del nodo e intentamos crear al hijo.
		Vector vecOrigin	= pNode->GetPosition(HULL_HUMAN);
		bool bSpawn			= AddChild(vecOrigin);

		// El hijo no se ha podido crear.
		if ( !bSpawn )
			continue;

		// Un hijo menos en la cola.
		Director()->SpawnQueue = Director()->SpawnQueue - 1;
		break;
	}
}
void TurretManager::UpdateTurrets(float deltaTime, EnemyManager* enemyManager)
{
	std::vector<std::shared_ptr<uth::GameObject>> nearbyEnemies;

	UpdateNodes();
	
	for (int i = turrets.size() - 1; i >= 0; i--)
	{
		auto& turret = *turrets[i];
		auto& c = *turret.GetComponent<Turret>();

		if (c.GetOrbit() == 1)
			turret.transform.SetPosition(cosf(orbit01Angle + c.GetOrbitPos()*(pmath::pi / 3 / c.GetOrbit())) * 115 * c.GetOrbit(), sinf(orbit01Angle + c.GetOrbitPos()*(pmath::pi / 3 / c.GetOrbit())) * 115 * c.GetOrbit());
		else if (c.GetOrbit() == 2)
			turret.transform.SetPosition(cosf(orbit02Angle + c.GetOrbitPos()*(pmath::pi / 3 / c.GetOrbit())) * 115 * c.GetOrbit(), sinf(orbit02Angle + c.GetOrbitPos()*(pmath::pi / 3 / c.GetOrbit())) * 115 * c.GetOrbit());

		float turretPositionX = turret.transform.GetPosition().x;
		float turretPositionY = turret.transform.GetPosition().y;
		c.SetCooldown(c.GetCooldown() + deltaTime);
		nearbyEnemies = EnemyWithinRange(enemyManager, turretPositionX, turretPositionY, c.GetRange());

		if (nearbyEnemies.size() > 0)
		{
			turret.transform.SetRotation(pmath::radiansToDegrees(atan2f(nearbyEnemies[0]->transform.GetPosition().y - turretPositionY, nearbyEnemies[0]->transform.GetPosition().x - turretPositionX)));
			if (c.CanShoot())
			{
				//ShootBullet(turretPositionX, turretPositionY, atan2f(nearbyEnemies[0]->transform.GetPosition().y - turretPositionY, nearbyEnemies[0]->transform.GetPosition().x - turretPositionX), c.GetBulletSpeed(), c.GetDamage(), c.GetRange(), c.GetAoe(),c.GetPenetrate(),c.GetSlowAmount(),c.GetCrit(),c.GetPenetrate(),c.GetTexture());
				ShootBullet(turretPositionX, turretPositionY, atan2f(nearbyEnemies[0]->transform.GetPosition().y - turretPositionY, nearbyEnemies[0]->transform.GetPosition().x - turretPositionX), c);
			}
		}
	}
}
//=========================================================
// Crea un jefe.
//=========================================================
void CDirector_Manager::SpawnBoss()
{
	// Actualizamos los nodos candidatos para la creación.
	UpdateNodes();

	// ¡No hay nodos!
	if ( SpawnNodes.Count() <= 0 )
		return;

	for ( int i = 0; i < MAX_TRIES; ++i )
	{
		// Seleccionamos un nodo candidato al azar.
		CAI_Node *pNode	= GetRandomNode();

		// El nodo no existe.
		if ( !pNode )
			continue;

		// Obtenemos la ubicación del nodo.
		Vector vecOrigin	= pNode->GetPosition(HULL_MEDIUM_TALL);
		bool bSpawn			= AddBoss(vecOrigin);

		// El hijo no se ha podido crear.
		if ( !bSpawn )
			continue;
		
		return;
	}

	// No se pudo crear al Jefe, intentarlo en otro momento.
	Director()->BossPendient = true;
}
void CAnimationGroupEditImp::ActiveNode( CRenderNode* pNode )
{
	if (IsNodesChanged())
	{
		UpdateNodes();
		CCtrlBase::Update();
	}
	else if (m_pModel != EDITMODEL)
	{
		m_pModel = EDITMODEL;
		if (!m_strCurAgpName.empty())
		{
			m_CurAni = NULL;
			m_pSkeletalFrame = NULL;
			m_pAnimateGroup = NULL;
			AddAgp(m_strCurAgpName);
		}
	}
}
//=========================================================
// Crea un bonche de hijos en un nodo candidato.
//=========================================================
void CDirector_Manager::AddHorde(int pMount)
{
	// Actualizamos los nodos candidatos para la creación.
	UpdateNodes();

	// ¡No hay nodos!
	if ( SpawnNodes.Count() <= 0 )
		return;

	for ( int i = 0; i < MAX_TRIES; ++i )
	{
		// Seleccionamos un nodo candidato al azar.
		CAI_Node *pNode	= GetRandomNode();

		// El nodo no existe.
		if ( !pNode )
			continue;

		// Obtenemos la ubicación del nodo.
		Vector vecOrigin = pNode->GetPosition(HULL_HUMAN);

		ConVarRef director_debug("director_debug");

		if ( director_debug.GetBool() )
			NDebugOverlay::Cross3D(vecOrigin, 50.0f, 255, 128, 0, true, 20.0f);

		// Creamos varios hijos en este nodo.
		// Con las colisiones especiales (No colisionan con los otros hijos)
		for ( int h = 0; h < pMount; ++h )
		{
			for ( int s = 0; s < MAX_TRIES; ++s )
			{
				bool pSpawn = AddChild(vecOrigin, SPAWN_NO_COLLISION_AND_POWERFUL);

				if ( pSpawn )
					break;
			}
		}

		break;
	}
}
Esempio n. 6
0
void CTopClauses::NewClause(CClauseNode* pNode1, CClauseNode* pNode2, SClauseFuncArg& arg)
{
    //try
    {
        CClause* clause1 = pNode1->GetMainClause();
        CClause* clause2 = pNode2->GetMainClause();

        bool clause1WordsCountZero = (clause1->m_ClauseWords.size() == 0);
        bool clause2WordsCountZero = (clause2->m_ClauseWords.size() == 0);

        bool bIncludeOp = clause1WordsCountZero || clause2WordsCountZero;

        CClauseNode* pClonedNode1 = NULL;
        CClauseNode* pClonedNode2 = NULL;

        if (!bIncludeOp) {
            int size1 = pNode1->m_outNodes.size();
            int size2 = pNode2->m_inNodes.size();

            if (size1 > 1)
                pClonedNode1 = pNode1->Clone();

            if (size2 > 1)
                pClonedNode2 = pNode2->Clone();

            if (arg.m_iClause2TypeNum != -1)
                clause2->AddValsToType(arg.m_NewValencies2, arg.m_iClause2TypeNum);
        }

        if (clause1WordsCountZero) {
            arg.m_bMainFirst = true;
            IncludeClause(pNode1, pNode2, arg);
            pNode1->GetMainClause()->RunSynAn();
            return;
        }

        if (clause2WordsCountZero) {
            arg.m_bMainFirst = false;
            IncludeClause(pNode1, pNode2, arg);
            pNode2->GetMainClause()->RunSynAn();
            return;
        }

        CClause* pNewClause = CClause::Create(m_Words);
        pNewClause->SetPair(clause1->FirstWord(), clause2->LastWord());

        if (arg.m_bMainFirst)
            pNewClause->m_Types = clause1->m_Types;
        else
            pNewClause->m_Types = clause2->m_Types;

        pNewClause->AddBadWeight(arg.m_BadWeight);
        pNewClause->m_Conjs = clause1->m_Conjs;

        //if( arg.m_BadWeightForCommas > 0 )
        //    pNewClause->m_BadCommas.push_back(SBadComma(clause1->LastWord(), arg.m_BadWeightForCommas) );
        //MultiplyBadCommaWeight(*pNewClause, arg.m_PairForBadCoef, arg.m_CoefficientToIncreaseBadWeightForCommas);
        pNewClause->AddBadComma(clause1->LastWord(),arg.m_BadWeightForCommas,  arg.m_PairForBadCoef, arg.m_CoefficientToIncreaseBadWeightForCommas);
        //pNewClause->m_BadWeightForCommas += arg.m_BadWeightForCommas;
        //pNewClause->m_BadWeightForCommas *= arg.m_CoefficientToIncreaseBadWeightForCommas;
        pNode1->m_pClauseTree->AddSubClauses(pNode2->m_pClauseTree, pNewClause);
        pNode1->GetMainClause()->RunSynAn();

        UpdateNodes(pNode1, pNode2, pClonedNode1, pClonedNode2, true);
    }
    /*catch(...)
    {
        ythrow yexception() << "Error in \"CTopClauses::NewClause\"";
    }*/
}
Esempio n. 7
0
void CTopClauses::IncludeClause(CClauseNode* pNode1, CClauseNode* pNode2, SClauseFuncArg& arg)
{
    //try
    {
        CClause* clause1 = pNode1->GetMainClause();
        CClause* clause2 = pNode2->GetMainClause();

        CClauseNode* pClonedNode1 = NULL;
        CClauseNode* pClonedNode2 = NULL;

        int size1 = pNode1->m_outNodes.size();
        int size2 = pNode2->m_inNodes.size();

        if (size1 > 1)
            pClonedNode1 = pNode1->Clone();

        if (size2 > 1)
            pClonedNode2 = pNode2->Clone();

        if (arg.m_iClause2TypeNum != -1) //если вызывается из NewClause
            AddValsToSubClauses(pNode2, arg);
            //clause2->AddValsToType(arg.m_NewValencies2, arg.m_iClause2TypeNum);

        if (arg.m_bMainFirst) {
            pNode1->m_pClauseTree->EraseMainClause();

            clause1->SetLastWord(clause2->LastWord());
            if (arg.m_ConjSupValency.IsValid() && (arg.m_iConj != -1))
                clause2->m_Conjs[arg.m_iConj].m_SupVal = arg.m_ConjSupValency;
            if (arg.m_NodeSupValency.IsValid() && (arg.m_iClause2TypeNum != -1))
                clause2->GetType(arg.m_iClause2TypeNum).m_SupVal = arg.m_NodeSupValency;

            clause1->AddBadWeight(arg.m_BadWeight);
            //if( arg.m_BadWeightForCommas > 0 )
            //    clause1->m_BadCommas.push_back(SBadComma(clause1->LastWord(), arg.m_BadWeightForCommas) );
            //MultiplyBadCommaWeight(*clause1, arg.m_PairForBadCoef, arg.m_CoefficientToIncreaseBadWeightForCommas);
            clause1->AddBadComma(clause1->LastWord(),arg.m_BadWeightForCommas,  arg.m_PairForBadCoef, arg.m_CoefficientToIncreaseBadWeightForCommas);
            //clause1->m_BadWeightForCommas += arg.m_BadWeightForCommas;
            //clause1->m_BadWeightForCommas *= arg.m_CoefficientToIncreaseBadWeightForCommas;
            pNode1->m_pClauseTree->AddSubClauses(pNode2->m_pClauseTree, clause1);
        } else {
            clause2->AddBadWeight(arg.m_BadWeight);
            pNode2->m_pClauseTree->EraseMainClause();
            clause2->SetFirstWord(clause1->FirstWord());
            /*if( arg.m_ConjSupValency.IsValid() && (arg.m_iConj != -1) )
                clause2->m_Conjs[arg.m_iConj].m_Sup
                Val = arg.m_ConjSupValency;*/

            //if( arg.m_BadWeightForCommas > 0 )
            //    clause2->m_BadCommas.push_back(SBadComma(clause1->LastWord(), arg.m_BadWeightForCommas) );
            //MultiplyBadCommaWeight(*clause2, arg.m_PairForBadCoef, arg.m_CoefficientToIncreaseBadWeightForCommas);
            clause2->AddBadComma(clause1->LastWord(),arg.m_BadWeightForCommas,  arg.m_PairForBadCoef, arg.m_CoefficientToIncreaseBadWeightForCommas);
            //clause2->m_BadWeightForCommas += arg.m_BadWeightForCommas;
            //clause2->m_BadWeightForCommas *= arg.m_CoefficientToIncreaseBadWeightForCommas;
            pNode2->m_pClauseTree->AddSubClauses(pNode1->m_pClauseTree, clause2);
        }

        UpdateNodes(pNode1, pNode2, pClonedNode1, pClonedNode2, arg.m_bMainFirst);
    }
    /*catch(...)
    {
        ythrow yexception() << "Error in \"CTopClauses::IncludeClause\"";
    }*/
}
Esempio n. 8
0
void CTopClauses::UniteClause(CClauseNode* pNode1, CClauseNode* pNode2, SClauseFuncArg& arg)
{
    CClause* pCl1 = pNode1->GetMainClause();
    CClause* pCl2 = pNode2->GetMainClause();

    Stroka strStage = "Stage0 ";

    //try
    {
        CClauseNode* pClonedNode1 = NULL;
        CClauseNode* pClonedNode2 = NULL;

        int size1 = pNode1->m_outNodes.size();
        int size2 = pNode2->m_inNodes.size();

        if (size1 > 1)
            pClonedNode1 = pNode1->Clone();

        if (size2 > 1)
            pClonedNode2 = pNode2->Clone();

        if (!arg.m_bMainFirst) {
            strStage = "Stage1 ";
            pNode2->m_pClauseTree->EraseMainClause();

            pCl2->AddClauseWords(*pCl1, false);

            strStage = "Stage2 ";
            pCl1->ClearConjs();

            if (arg.m_iClause2TypeNum != -1)
                pCl2->AddValsToType(arg.m_NewValencies, arg.m_iClause2TypeNum);

            strStage = "Stage3 ";
            if (arg.m_NewType.m_Type != UnknownClause)
                pCl2->DelAllTypesAndAdd(arg.m_NewType);

            if (!arg.m_bRefreshClauseInfo) {
                strStage = "Stage3.1 ";
                pCl2->RunSynAn();
                strStage = "Stage3.2 ";
                pCl2->RefreshConjInfo();
                strStage = "Stage3.3 ";
                pCl2->RefreshValencies();
                strStage = "Stage3.4 ";
            } else {
                strStage = "Stage3.5 ";
                pCl2->RefreshClauseInfo();
                strStage = "Stage3.6 ";
            }

            strStage = "Stage4 ";
            pCl2->AddBadWeight(arg.m_BadWeight);
            pCl2->AddBadWeight(pCl1->m_BadWeight);
            pCl2->AddBadComma(pCl1->LastWord(),arg.m_BadWeightForCommas,  arg.m_PairForBadCoef,
                              arg.m_CoefficientToIncreaseBadWeightForCommas);
            strStage = "Stage5 ";
            //if( arg.m_BadWeightForCommas > 0 )
            //    pCl2->m_BadCommas.push_back(SBadComma(pCl1->LastWord(), arg.m_BadWeightForCommas) );//m_BadWeightForCommas += arg.m_BadWeightForCommas;
            //MultiplyBadCommaWeight(*pCl2, arg.m_PairForBadCoef, arg.m_CoefficientToIncreaseBadWeightForCommas);
            //pCl2->m_BadWeightForCommas += pCl1->m_BadWeightForCommas;
            //pCl2->m_BadWeightForCommas *= arg.m_CoefficientToIncreaseBadWeightForCommas;

            pNode1->m_pClauseTree->EraseMainClause();
            strStage = "Stage6 ";
            delete pCl1;/**/
            strStage = "Stage7 ";
            pNode2->m_pClauseTree->AddSubClauses(pNode1->m_pClauseTree, pCl2);
            strStage = "Stage8 ";
        } else {

            pNode1->m_pClauseTree->EraseMainClause();
            pCl1->AddClauseWords(*pCl2);

            if (arg.m_iClause1TypeNum != -1)
                pCl1->AddValsToType(arg.m_NewValencies, arg.m_iClause1TypeNum);

            if (arg.m_NewType.m_Type != UnknownClause)
                pCl1->DelAllTypesAndAdd(arg.m_NewType);

            if (!arg.m_bRefreshClauseInfo) {
                pCl1->RunSynAn();
                pCl1->RefreshConjInfo();
            } else
                pCl1->RefreshClauseInfo();

            pCl1->AddBadWeight(arg.m_BadWeight);
            pCl1->AddBadWeight(pCl2->m_BadWeight);

            //if( arg.m_BadWeightForCommas > 0 )
            //    pCl1->m_BadCommas.push_back(SBadComma(pCl1->LastWord(), arg.m_BadWeightForCommas) );
            pCl1->m_BadCommas.insert(pCl1->m_BadCommas.begin(),pCl2->m_BadCommas.begin(), pCl2->m_BadCommas.end());
            pCl1->AddBadComma(pCl1->LastWord(),arg.m_BadWeightForCommas,  arg.m_PairForBadCoef, arg.m_CoefficientToIncreaseBadWeightForCommas);
            //MultiplyBadCommaWeight(*pCl1, arg.m_PairForBadCoef, arg.m_CoefficientToIncreaseBadWeightForCommas);

            //pCl1->m_BadWeightForCommas += arg.m_BadWeightForCommas;
            //pCl1->m_BadWeightForCommas *= arg.m_CoefficientToIncreaseBadWeightForCommas;
            pNode2->m_pClauseTree->EraseMainClause();

            delete pCl2;/**/

            pNode1->m_pClauseTree->AddSubClauses(pNode2->m_pClauseTree, pCl1);

        }

        UpdateNodes(pNode1, pNode2, pClonedNode1, pClonedNode2, arg.m_bMainFirst);
    }
    /*catch(yexception& e)
    {
        throw e;
    }
    catch(...)
    {
        ythrow yexception() << "Error in \"CTopClauses::UniteClause\"";
    }*/
}