Пример #1
0
//shows the strength of a tower
int TowerRules::GetStrength(Ref & t)
{
    Tower * to = (Tower*) &t;
    
    int a;
    
    // 1 second / inbetweenAttacksPeriod 
    if(to->GetElement() == ElementalAffinity::Fire)
    {
        //return ((to->attackPoints + this->addFireDamage) * (1/to->inbetweenAttacksPeriod)) / 50;
        a = ((this->elementsAmplifier * to->attackPoints) + this->addFireDamage) + (1/to->inbetweenAttacksPeriod) / 1000;
        //std::cout << "\n\n test strength test: " << a << "\n\n";
        return a;
    }
    else if(to->GetElement() == ElementalAffinity::Earth)
    {
        a = ((this->elementsAmplifier * to->attackPoints) + this->addEarthDamage) + (1/to->inbetweenAttacksPeriod) / 1000;
        //std::cout << "\n\n test strength test: " << a << "\n\n";
        return a;
    }
    else if(to->GetElement() == ElementalAffinity::Water)
    {
        a = ((this->elementsAmplifier * to->attackPoints) + this->addWaterDamage) + (1/to->inbetweenAttacksPeriod) / 1000;
        //std::cout << "\n\n test strength test: " << a << "\n\n";
        return a;
    }
    else if(to->GetElement() == ElementalAffinity::Shock)
    {
        a = ((this->elementsAmplifier * to->attackPoints) + this->addShockDamage) + (1/to->inbetweenAttacksPeriod) / 1000;
        //std::cout << "\n\n test strength test: " << a << "\n\n";
        return a;
    }
    else // element == none
    {
        //return ((to->attackPoints) * (1/to->inbetweenAttacksPeriod)) /50 ;
        a = ((this->elementsAmplifier * to->attackPoints) ) + (1/to->inbetweenAttacksPeriod) / 1000;
        //std::cout << "\n\n test strength test: " << a << "\n\n";
        return a;
    }
}
Пример #2
0
bool TowerRules::UpgradeToEarth(Ref* p, Ref & u)
{
    Tower *t = (Tower*)&u;
    if( t->GetElement() == ElementalAffinity::None && ((Player*)p)->GetCurrency() >= this->earthUpgradeCost )
    {
        t->SetElement(ElementalAffinity::Earth);
        ((Player*)p)->RemoveCoins(this->earthUpgradeCost);
        return true;
    }
    else
    {
        return false;
    }
}
Пример #3
0
void GeneticAlgorithmProfile1::SimulationForward(ThreadData* td, AdditionalTowers& at)
{
    GameScene* gs = ((GameScene*)td->_sc);
    
    std::cout << "\n@@@@@@@@@@@@@@@@@@@@@@@";
    std::cout << "\nADDITIONAL TOWERS DBG";
    
    td->bkCurrency = gs->playerHandler->GetCurrency();
    
    std::cout << "\nplayerMoney : " << gs->playerHandler->GetCurrency();
    
    //AI -> forward
    for ( int i = 0; i < 20; i++ )
    {
        //FIRST CASE : enough money for placing tower and upgrading it to an element
        if(gs->playerHandler->GetCurrency() >= (50 + 500))
        {
            Tower* n1 = new Tower(*gs, Settings::towerTexture, ((GameScene*)td->_sc)->playerHandler->tw);
            n1->setPosition(gs->getMapInfo()->GetRandomPointMidByType(MapInfoType::SimTowerPlace));
            
            n1->SetHitPositions(gs->getMapInfo());
            n1->SetStartingStats(Settings::towerAttackRange, Settings::towerAttackPoints, Settings::towerInbetweenAttacksPeriod, Settings::towerCost);
            
            at.additionalTowers.push_back(n1);
            
            gs->playerHandler->RemoveCoins(Settings::towerCost);
            
            
            if(gs->playerHandler->GetCurrency() >= 500) //element can be upgraded
            {
                int numOfFire, numOfWater, numOfEarth, numOfShock = 0;
                for(int a = 0; a < at.additionalTowers.size(); a++ )
                {
                    if(at.additionalTowers[a]->GetElement() == ElementalAffinity::Fire)
                    {
                        numOfFire++;
                    }
                    else if(at.additionalTowers[a]->GetElement() == ElementalAffinity::Water)
                    {
                        numOfWater++;
                    }
                    else if(at.additionalTowers[a]->GetElement() == ElementalAffinity::Earth)
                    {
                        numOfEarth++;
                    }
                    else if(at.additionalTowers[a]->GetElement() == ElementalAffinity::Shock)
                    {
                        numOfShock++;
                    }
                }
                for ( std::list<Tower*>::iterator tower = gs->towerslist.begin(); tower != gs->towerslist.end(); ++tower )
                {
                    Tower* t = *tower;
                    if(t->GetElement() == ElementalAffinity::Fire)
                    {
                        numOfFire++;
                    }
                    else if(t->GetElement() == ElementalAffinity::Water)
                    {
                        numOfWater++;
                    }
                    else if(t->GetElement() == ElementalAffinity::Earth)
                    {
                        numOfEarth++;
                    }
                    else if(t->GetElement() == ElementalAffinity::Shock)
                    {
                        numOfShock++;
                    }
                }
                
                
                if(numOfEarth < numOfFire && numOfEarth < numOfWater && numOfEarth < numOfShock)
                {
                    if(n1->UpgradeToEarth(gs->playerHandler))
                    {
                        gs->playerHandler->RemoveCoins(n1->toweRules->GetEarthUpgradeCost());
                        //now upgrade atk spd
                        while ( gs->playerHandler->GetCurrency() >= n1->toweRules->GetAttackUpgradeCost(*n1) ||
                               gs->playerHandler->GetCurrency() >= n1->toweRules->GetSpeedUpgradeCost(*n1) )
                        {
                            
                            if(n1->UpgradeAttackPower(gs->playerHandler))
                            {
                                gs->playerHandler->RemoveCoins(n1->toweRules->GetAttackUpgradeCost(*n1));
                            }
                            
                            if(n1->UpgradeAttackSpeed(gs->playerHandler))
                            {
                                gs->playerHandler->RemoveCoins(n1->toweRules->GetSpeedUpgradeCost(*n1));
                            }
                        }
                        
                    }
                    
                }
                else if(numOfFire < numOfEarth && numOfFire < numOfWater && numOfFire < numOfShock)
                {
                    if(n1->UpgradeToFire(gs->playerHandler))
                    {
                        gs->playerHandler->RemoveCoins(n1->toweRules->GetEarthUpgradeCost());
                        //now upgrade atk spd
                        while ( gs->playerHandler->GetCurrency() >= n1->toweRules->GetAttackUpgradeCost(*n1) ||
                               gs->playerHandler->GetCurrency() >= n1->toweRules->GetSpeedUpgradeCost(*n1) )
                        {
                            
                            if(n1->UpgradeAttackPower(gs->playerHandler))
                            {
                                gs->playerHandler->RemoveCoins(n1->toweRules->GetAttackUpgradeCost(*n1));
                            }
                            
                            if(n1->UpgradeAttackSpeed(gs->playerHandler))
                            {
                                gs->playerHandler->RemoveCoins(n1->toweRules->GetSpeedUpgradeCost(*n1));
                            }
                        }
                        
                    }
                }
                else if(numOfWater < numOfFire && numOfWater < numOfEarth && numOfWater < numOfShock)
                {
                    if(n1->UpgradeToWater(gs->playerHandler))
                    {
                        gs->playerHandler->RemoveCoins(n1->toweRules->GetEarthUpgradeCost());
                        //now upgrade atk spd
                        while ( gs->playerHandler->GetCurrency() >= n1->toweRules->GetAttackUpgradeCost(*n1) ||
                               gs->playerHandler->GetCurrency() >= n1->toweRules->GetSpeedUpgradeCost(*n1) )
                        {
                            
                            if(n1->UpgradeAttackPower(gs->playerHandler))
                            {
                                gs->playerHandler->RemoveCoins(n1->toweRules->GetAttackUpgradeCost(*n1));
                            }
                            
                            if(n1->UpgradeAttackSpeed(gs->playerHandler))
                            {
                                gs->playerHandler->RemoveCoins(n1->toweRules->GetSpeedUpgradeCost(*n1));
                            }
                        }
                        
                    }
                    
                }
                else if(numOfShock < numOfFire && numOfShock < numOfWater && numOfShock < numOfEarth)
                {
                    if(n1->UpgradeToShock(gs->playerHandler))
                    {
                        gs->playerHandler->RemoveCoins(n1->toweRules->GetEarthUpgradeCost());
                        //now upgrade atk spd
                        while ( gs->playerHandler->GetCurrency() >= n1->toweRules->GetAttackUpgradeCost(*n1) ||
                               gs->playerHandler->GetCurrency() >= n1->toweRules->GetSpeedUpgradeCost(*n1) )
                        {
                            
                            if(n1->UpgradeAttackPower(gs->playerHandler))
                            {
                                gs->playerHandler->RemoveCoins(n1->toweRules->GetAttackUpgradeCost(*n1));
                            }
                            
                            if(n1->UpgradeAttackSpeed(gs->playerHandler))
                            {
                                gs->playerHandler->RemoveCoins(n1->toweRules->GetSpeedUpgradeCost(*n1));
                            }
                        }
                        
                    }
                    
                }
                
            }
            
        }
        
        /////////////////////////////////////////
        
        //SECOND CASE : upgrade an existing tower, priortize element upgrades
        if(gs->playerHandler->GetCurrency() >= 500)
        {
            int numOfFire, numOfWater, numOfEarth, numOfShock = 0;
            for(int a = 0; a < at.additionalTowers.size(); a++ )
            {
                if(at.additionalTowers[a]->GetElement() == ElementalAffinity::Fire)
                {
                    numOfFire++;
                }
                else if(at.additionalTowers[a]->GetElement() == ElementalAffinity::Water)
                {
                    numOfWater++;
                }
                else if(at.additionalTowers[a]->GetElement() == ElementalAffinity::Earth)
                {
                    numOfEarth++;
                }
                else if(at.additionalTowers[a]->GetElement() == ElementalAffinity::Shock)
                {
                    numOfShock++;
                }
            }
            for ( std::list<Tower*>::iterator tower = gs->towerslist.begin(); tower != gs->towerslist.end(); ++tower )
            {
                Tower* t = *tower;
                if(t->GetElement() == ElementalAffinity::Fire)
                {
                    numOfFire++;
                }
                else if(t->GetElement() == ElementalAffinity::Water)
                {
                    numOfWater++;
                }
                else if(t->GetElement() == ElementalAffinity::Earth)
                {
                    numOfEarth++;
                }
                else if(t->GetElement() == ElementalAffinity::Shock)
                {
                    numOfShock++;
                }
            }
            
            
            for ( std::list<Tower*>::iterator tower = gs->towerslist.begin(); tower != gs->towerslist.end(); ++tower )
            {
                Tower* n1 = *tower;
                
                if(numOfEarth < numOfFire && numOfEarth < numOfWater && numOfEarth < numOfShock)
                {
                    if(n1->UpgradeToEarth(gs->playerHandler))
                    {
                        gs->playerHandler->RemoveCoins(n1->toweRules->GetEarthUpgradeCost());
                        //now upgrade atk spd
                        while ( gs->playerHandler->GetCurrency() >= n1->toweRules->GetAttackUpgradeCost(*n1) ||
                               gs->playerHandler->GetCurrency() >= n1->toweRules->GetSpeedUpgradeCost(*n1) )
                        {
                            
                            if(n1->UpgradeAttackPower(gs->playerHandler))
                            {
                                gs->playerHandler->RemoveCoins(n1->toweRules->GetAttackUpgradeCost(*n1));
                            }
                            
                            if(n1->UpgradeAttackSpeed(gs->playerHandler))
                            {
                                gs->playerHandler->RemoveCoins(n1->toweRules->GetSpeedUpgradeCost(*n1));
                            }
                        }
                        
                    }
                    
                }
                else if(numOfFire < numOfEarth && numOfFire < numOfWater && numOfFire < numOfShock)
                {
                    if(n1->UpgradeToFire(gs->playerHandler))
                    {
                        gs->playerHandler->RemoveCoins(n1->toweRules->GetEarthUpgradeCost());
                        //now upgrade atk spd
                        while ( gs->playerHandler->GetCurrency() >= n1->toweRules->GetAttackUpgradeCost(*n1) ||
                               gs->playerHandler->GetCurrency() >= n1->toweRules->GetSpeedUpgradeCost(*n1) )
                        {
                            
                            if(n1->UpgradeAttackPower(gs->playerHandler))
                            {
                                gs->playerHandler->RemoveCoins(n1->toweRules->GetAttackUpgradeCost(*n1));
                            }
                            
                            if(n1->UpgradeAttackSpeed(gs->playerHandler))
                            {
                                gs->playerHandler->RemoveCoins(n1->toweRules->GetSpeedUpgradeCost(*n1));
                            }
                        }
                        
                    }
                }
                else if(numOfWater < numOfFire && numOfWater < numOfEarth && numOfWater < numOfShock)
                {
                    if(n1->UpgradeToWater(gs->playerHandler))
                    {
                        gs->playerHandler->RemoveCoins(n1->toweRules->GetEarthUpgradeCost());
                        //now upgrade atk spd
                        while ( gs->playerHandler->GetCurrency() >= n1->toweRules->GetAttackUpgradeCost(*n1) ||
                               gs->playerHandler->GetCurrency() >= n1->toweRules->GetSpeedUpgradeCost(*n1) )
                        {
                            
                            if(n1->UpgradeAttackPower(gs->playerHandler))
                            {
                                gs->playerHandler->RemoveCoins(n1->toweRules->GetAttackUpgradeCost(*n1));
                            }
                            
                            if(n1->UpgradeAttackSpeed(gs->playerHandler))
                            {
                                gs->playerHandler->RemoveCoins(n1->toweRules->GetSpeedUpgradeCost(*n1));
                            }
                        }
                        
                    }
                    
                }
                else if(numOfShock < numOfFire && numOfShock < numOfWater && numOfShock < numOfEarth)
                {
                    if(n1->UpgradeToShock(gs->playerHandler))
                    {
                        gs->playerHandler->RemoveCoins(n1->toweRules->GetEarthUpgradeCost());
                        //now upgrade atk spd
                        while ( gs->playerHandler->GetCurrency() >= n1->toweRules->GetAttackUpgradeCost(*n1) ||
                               gs->playerHandler->GetCurrency() >= n1->toweRules->GetSpeedUpgradeCost(*n1) )
                        {
                            
                            if(n1->UpgradeAttackPower(gs->playerHandler))
                            {
                                gs->playerHandler->RemoveCoins(n1->toweRules->GetAttackUpgradeCost(*n1));
                            }
                            
                            if(n1->UpgradeAttackSpeed(gs->playerHandler))
                            {
                                gs->playerHandler->RemoveCoins(n1->toweRules->GetSpeedUpgradeCost(*n1));
                            }
                        }
                        
                    }
                    
                }
                
            }
        }
        
        // THIRD CASE : additional upgrades , attack power and speed
        for ( std::list<Tower*>::iterator tower = gs->towerslist.begin(); tower != gs->towerslist.end(); ++tower )
        {
            Tower* n1 = *tower;
            
            if(n1->GetElement() > 0) //not worth it with out element
            {
                
                while ( gs->playerHandler->GetCurrency() >= n1->toweRules->GetAttackUpgradeCost(*n1) ||
                       gs->playerHandler->GetCurrency() >= n1->toweRules->GetSpeedUpgradeCost(*n1) )
                {
                    
                    if(n1->UpgradeAttackPower(gs->playerHandler))
                    {
                        gs->playerHandler->RemoveCoins(n1->toweRules->GetAttackUpgradeCost(*n1));
                    }
                    
                    if(n1->UpgradeAttackSpeed(gs->playerHandler))
                    {
                        gs->playerHandler->RemoveCoins(n1->toweRules->GetSpeedUpgradeCost(*n1));
                    }
                }
                
            }
            
        }
    }
    
    gs->playerHandler->SetCurrency(td->bkCurrency);
    
    std::cout << "\n@@@@@@@@@@@@@@@@@@@@@@@";

}