Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Nov 29, 2015, 6:36:21 PM (8 years ago)
Author:
gania
Message:

started working on pickups

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.cc

    r10886 r10888  
    3232#include <algorithm>
    3333#include "worldentities/Actionpoint.h"
    34 
    35 
    3634namespace orxonox
    3735{
     
    4543        this->bLoop_ = false;
    4644        this->bEndLoop_ = false;
    47         this->parsedActionpoints_.clear();
     45        loopActionpoints_.clear();
     46        parsedActionpoints_.clear();
     47        actionpoints_.clear();
     48        healthSpawners_.clear();
     49        damageSpawners_.clear();
     50        speedSpawners_.clear();
    4851        this->bTakenOver_ = false;
    4952        this->action_ = Action::NONE;
     
    6467        parsedActionpoints_.clear();
    6568        actionpoints_.clear();
     69        healthSpawners_.clear();
     70        damageSpawners_.clear();
     71        speedSpawners_.clear();
    6672    }
    6773    void ActionpointController::tick(float dt)
     
    97103        }
    98104        if (this->bFirstTick_)
    99         {           
     105        {   
     106            setSpawners();
     107            // orxout(internal_error) << "health spawners size = " << this->healthSpawners_.size() <<
     108            // ", damage spawners size = " << this->damageSpawners_.size() <<
     109            // ", speed spawners size = " << this->speedSpawners_.size() << endl;       
    100110            this->bFirstTick_ = false;
    101111        }
     
    109119        if (!this->getControllableEntity() || !orxonox_cast<Pawn*> (this->getControllableEntity()))
    110120            return;
     121
    111122        this->deltaHp = orxonox_cast<Pawn*> (this->getControllableEntity())->getHealth() - this->previousHp;
    112123        this->previousHp = orxonox_cast<Pawn*> (this->getControllableEntity())->getHealth();
     
    116127        if (this->action_ == Action::NONE || this->bTakenOver_)
    117128        {
     129            // Point point = closestPickup(PickupType::HEALTH);
     130            // if (point.action != Action::NONE)
     131            // {
     132            //     orxout(internal_error) << "found health" << endl;
     133            //     this->parsedActionpoints_.push_back(point);
     134            // }
    118135            if (this->parsedActionpoints_.empty() && this->loopActionpoints_.empty())
    119136            {
     
    142159                    {
    143160                        this->action();
    144                     }       
     161                    }
     162                    else
     163                    {
     164                    }     
    145165                }
    146166            }
     
    214234        if (this->hasTarget())
    215235        {
    216             //----choose where to go----
    217236            this->maneuver();
    218             //----fire if you can----
    219             this->bShooting_ = this->canFire();               
     237            this->bShooting_ = this->canFire();
     238            // Vector3 healthPosition = bestHealthPickup((this->target_->getWorldPosition() - this->getControllableEntity()->getWorldPosition()).length());
     239            // if ((this->getControllableEntity()->getWorldPosition() - healthPosition).length() < this->tolerance_)
     240            // {
     241            //     //----choose where to go----
     242            //     this->maneuver();
     243            // }
     244            // else
     245            // {
     246            //     this->dodgeTowards(healthPosition);
     247            // }
     248            // //----fire if you can----
     249            // this->bShooting_ = this->canFire(); 
    220250        }
    221251        this->actionCounter_ += this->actionCounter_ < 100000 ? 1 : -this->actionCounter_ ;
     252
    222253    }
    223254    void ActionpointController::setProtect (ControllableEntity* protect)
     
    236267        bool inLoop = false;
    237268        Point p;
    238         if (static_cast<Actionpoint*> (actionpoint))
    239         {
    240             Actionpoint* ap = static_cast<Actionpoint*> (actionpoint);
     269        if (actionpoint->getIdentifier()->getName() == "Actionpoint")
     270        {
     271            Actionpoint* ap = orxonox_cast<Actionpoint*> (actionpoint);
    241272            actionName = ap->getActionXML();
    242273            targetName = ap->getName();
     
    277308        else
    278309        {
     310            inLoop = true;
    279311            p.action = Action::FLY; p.name = ""; p.position = actionpoint->getWorldPosition(); p.inLoop = inLoop;
    280312        }
     
    290322    }
    291323
    292       Action::Value ActionpointController::getAction ()
     324    Action::Value ActionpointController::getAction ()
    293325    {
    294326        return this->action_;
     
    593625                        <= this->attackRange_ )
    594626                {
    595                     Point p = { Action::FIGHT, CommonController::getName(newTarget), Vector3::ZERO, false };
    596                     this->parsedActionpoints_.push_back(p);
     627                    if (this->bLoop_)
     628                    {
     629                        Point p = { Action::FIGHT, CommonController::getName(newTarget), Vector3::ZERO, true };
     630                        this->loopActionpoints_.push_back(p);
     631                    }
     632                    else
     633                    {
     634                        Point p = { Action::FIGHT, CommonController::getName(newTarget), Vector3::ZERO, false };
     635                        this->parsedActionpoints_.push_back(p);
     636                    }
    597637                    this->executeActionpoint();
    598638                }
     
    600640        }
    601641    }
     642    Vector3 ActionpointController::bestHealthPickup(float searchRadius)
     643    {
     644
     645        //1000000/distance^2 * 1/index+1
     646        float maxUse = 0;
     647        float tempUse = -1;
     648        int index = 0;
     649        float distance = 0;
     650        Vector3 bestPosition = this->getControllableEntity()->getWorldPosition();
     651
     652        for (std::multimap<int, std::pair<PickupSpawner*, bool> >::iterator it=healthSpawners_.begin(); it!=healthSpawners_.end(); ++it)
     653        {
     654            distance = (this->getControllableEntity()->getWorldPosition() - (*it).second.first->getWorldPosition()).length();
     655            if (distance < this->tolerance_ || !(*it).second.second)
     656            {
     657                (*it).second.second = false;
     658                continue;
     659            }
     660            if (distance > searchRadius)
     661                continue;
     662            index = (*it).first;
     663            tempUse = 1000000*1/(1+distance*distance) * 1/((index/2.0f)+1);
     664            if (tempUse > maxUse)
     665            {
     666                bestPosition = (*it).second.first->getWorldPosition();
     667                maxUse = tempUse;
     668            }
     669        }
     670        //std::multimap<int, std::pair<PickupSpawner*, bool> >::iterator it = this->healthSpawners_.find(index);
     671        //P.S. check if it == ... .end()
     672        //orxout (internal_error) << "best position = " << bestPosition << endl;
     673        return  bestPosition;
     674    }
     675    void ActionpointController::setSpawners()
     676    {
     677        std::vector<std::string> damagePickups;
     678        std::vector<std::string> healthPickups;
     679        std::vector<std::string> speedPickups;       
     680        int index = 0;
     681
     682
     683        damagePickups.push_back("largedamageboostpickup");
     684        damagePickups.push_back("dronepickup");           
     685        damagePickups.push_back("mediumdamageboostpickup");
     686        damagePickups.push_back("smalldamageboostpickup");
     687
     688        healthPickups.push_back("triplehealthspeedinvisibilitypickup");           
     689        healthPickups.push_back("crazyhealthpickup");
     690        healthPickups.push_back("hugehealthpickup");
     691        healthPickups.push_back("hugeshieldpickup");
     692        healthPickups.push_back("hugeinvisiblepickup");
     693        healthPickups.push_back("hugeshrinkpickup");
     694        healthPickups.push_back("mediumhealthpickup");
     695        healthPickups.push_back("mediumshieldpickup");
     696        healthPickups.push_back("mediuminvisiblepickup");
     697        healthPickups.push_back("mediumshrinkpickup"); 
     698        healthPickups.push_back("smallhealthpickup");                   
     699        healthPickups.push_back("smallshieldpickup");
     700        healthPickups.push_back("smallinvisiblepickup");
     701        healthPickups.push_back("smallshrinkpickup");
     702
     703        speedPickups.push_back("triplehealthspeedinvisibilitypickup");
     704        speedPickups.push_back("hugespeedpickup");
     705        speedPickups.push_back("smalljumppickup");
     706        speedPickups.push_back("mediumspeedpickup");
     707        speedPickups.push_back("smallspeedpickup");
     708       
     709
     710
     711        for (ObjectList<WorldEntity>::iterator it = ObjectList<WorldEntity>::begin(); it; ++it)
     712        {
     713            if ((*it)->getIdentifier()->getName() != "PickupSpawner")
     714                continue;
     715            PickupSpawner* spawner = static_cast<PickupSpawner*>(*it);
     716            std::string name = spawner->getPickupTemplateName();
     717            //float distance = ((*it)->getWorldPosition() - this->getControllableEntity()->getWorldPosition()).length();
     718            // if (distance < 50.0f)
     719            //     continue;           
     720            for (unsigned int i = 0; i < healthPickups.size(); ++i)
     721            {
     722                if (name == healthPickups.at(i))
     723                {
     724                    index = i;
     725                    this->healthSpawners_.insert(std::make_pair(index, std::make_pair(spawner, true)));
     726                    break;
     727                }
     728            }
     729            for (unsigned int i = 0; i < damagePickups.size(); ++i)
     730            {
     731                if (name == damagePickups.at(i))
     732                {
     733                    //tempUse = 1000000*1/(1+distance*distance) * 1/((i/2.0f)+1);
     734                    index = i;
     735                    this->damageSpawners_.insert(std::make_pair(index, std::make_pair(spawner, true)));
     736                    break;
     737                }
     738            }
     739            for (unsigned int i = 0; i < speedPickups.size(); ++i)
     740            {
     741                if (name == speedPickups.at(i))
     742                {
     743                    //tempUse = 1000000*1/(1+distance*distance) * 1/((i/2.0f)+1);
     744                    index = i;
     745                    this->speedSpawners_.insert(std::make_pair(index, std::make_pair(spawner, true)));
     746                    break;
     747                }
     748            }
     749            // if (tempUse > maxUse)
     750            // {
     751            //     Point p = { Action::FLY, "", (*it)->getWorldPosition(), false };
     752            //     maxUse = tempUse;
     753            //     maxPoint = p;
     754            // }
     755            // else
     756            // {
     757            //     tempUse = -1;
     758            //     continue;
     759            // }
     760            // orxout(internal_error) << "resp time  = " << static_cast<PickupSpawner*>(*it)->getRespawnTime() << endl;
     761        } 
     762    }
    602763}
Note: See TracChangeset for help on using the changeset viewer.