Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 10888


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

started working on pickups

Location:
code/branches/campaignHS15
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • code/branches/campaignHS15/data/levels/AITest.oxw

    r10886 r10888  
    1818  include("templates/spaceshipRing.oxt")
    1919  include("templates/spaceshipSwallow.oxt")
     20  include("templates/pickupRepresentationTemplates.oxt")
    2021?>
     22
    2123
    2224<Level>
     
    3032    skybox       = "Orxonox/Starbox"
    3133  >
    32 
     34    <?lua
     35      include("includes/pickups.oxi")
     36    ?>
    3337    <Light type=directional position="0,0,0" direction="0.253, 0.593, -0.765" diffuse="1.0, 0.9, 0.9, 1.0" specular="1.0, 0.9, 0.9, 1.0"/>
    34     <TeamSpawnPoint team=0 position="3000, -1500, 1000" lookat="1,1,-1" spawnclass=SpaceShip pawndesign=spaceshipassff />
     38    <TeamSpawnPoint team=1 position="1500, 1500, 1500" lookat="1,1,-1" spawnclass=SpaceShip pawndesign=spaceshipassff />
    3539   
     40<!--     
     41    <PickupSpawner pickup=largedamageboostpickup position="0,0,0" triggerDistance="20" respawnTime="30" maxSpawnedItems="10" />
     42<PickupSpawner pickup=crazyhealthpickup position="0,0,0" triggerDistance="50" respawnTime="30" maxSpawnedItems="10" />
     43<PickupSpawner pickup=hugeshieldpickup position="4000,4500, 4500" triggerDistance="10" respawnTime="5" maxSpawnedItems="10" />
     44<PickupSpawner pickup=smalljumppickup position="6500,6500, 6000" triggerDistance="20" respawnTime="10" maxSpawnedItems="99" />
     45<PickupSpawner pickup=largedamageboostpickup position="9500,9500, 9500" triggerDistance="20" respawnTime="30" maxSpawnedItems="10" />
     46<PickupSpawner pickup=largedamageboostpickup position="13000,13000,13000" triggerDistance="10" respawnTime="30" maxSpawnedItems="10" />
     47 -->
    3648<!-- HERE STARTS DEMO FOR THE "WAYPOINTS" -->
    3749      <!--
     50    <SpaceShip position="-1500, -1500, -1500" lookat="0,0,0" team=0 name="ss1">
     51      <templates>
     52        <Template link=spaceshipassff />
     53      </templates>
     54      <controller>
     55        <DivisionController team=0 formationMode="finger4">
     56          <actionpoints>
     57            <Model mesh="cube.mesh" scale=8 position="  0,2000,-600" />
     58            <Model mesh="cube.mesh" scale=8 position="  0,2000,-1000" />
     59            <Model mesh="cube.mesh" scale=8 position="400,2000,-1000" />
     60            <Model mesh="cube.mesh" scale=8 position="400,2000,-600" />
     61          </actionpoints>
     62        </DivisionController>
     63      </controller>
     64    </SpaceShip>
     65 -->
     66    <!-- those two are same -->
     67
     68 <!--   
    3869    <Model mesh="cube.mesh" scale=8 position="  0,2000,-600" />
    39     <Model mesh="cube.mesh" scale=8 position="  0,2000,-800" />
    40     <Model mesh="cube.mesh" scale=8 position="200,2000,-800" />
    41     <Model mesh="cube.mesh" scale=8 position="200,2000,-600" />
    42     <Model mesh="cube.mesh" scale=8 position="0,0,0" />
    43 
     70    <Model mesh="cube.mesh" scale=8 position="  0,2000,-1000" />
     71    <Model mesh="cube.mesh" scale=8 position="400,2000,-1000" />
     72    <Model mesh="cube.mesh" scale=8 position="400,2000,-600" />
    4473    <SpaceShip position="-1500, 1500, -1000" lookat="0,0,0" team=0 name="ss1">
    4574      <templates>
     
    5079          <actionpoints>
    5180            <Actionpoint position="  0,2000,-600" action="FLY" loopStart=true/>
    52             <Actionpoint position="  0,2000,-800" action="FLY"  />
    53             <Actionpoint position="200,2000,-800" action="FLY" />
    54             <Actionpoint position="200,2000,-600" action="FLY" loopEnd=true />
     81            <Actionpoint position="  0,2000,-1000" action="FLY"  />
     82            <Actionpoint position="400,2000,-1000" action="FLY" />
     83            <Actionpoint position="400,2000,-600" action="FLY" loopEnd=true />
    5584          </actionpoints>
    5685        </DivisionController>
    5786      </controller>
    58     </SpaceShip>
    59     -->
     87    </SpaceShip>  -->
     88   
    6089<!-- HERE ENDS DEMO FOR THE "WAYPOINTS" -->
    6190
    6291<!-- HERE STARTS DEMO FOR THE ACTIONPOINTS.
    6392P.S. Never set protectMe in the first actionpoint: if human didn't spawn, that actionpoint will be skipped -->
    64        
     93       <!--
    6594    <Model mesh="cube.mesh" scale=8 position="0,0,0" />
    6695
     
    124153    </SpaceShip>
    125154 
    126    
     155    -->
    127156<!-- HERE ENDS DEMO FOR THE ACTIONPOINTS -->
    128157<!-- HERE STARTS DEMO FOR FIGHTING -->
    129     <!--
     158   
     159
    130160    <SpaceShip position="-4000, 1500, -1000" lookat="0,0,0" team=0 name="ss2">
    131161      <templates>
     
    242272      </controller>
    243273    </SpaceShip>
    244  -->
     274
    245275   
    246276<!-- HERE ENDS DEMO FOR FIGHTING -->
  • 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}
  • code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.h

    r10885 r10888  
    3333#include "tools/Timer.h"
    3434#include "tools/interfaces/Tickable.h"
     35#include "../modules/pickup/PickupSpawner.h"
     36#include <map>
    3537
    3638namespace orxonox
     
    5153        bool inLoop;
    5254    } ;
     55    namespace PickupType
     56    {
     57        enum Value
     58        { 
     59            NONE, DAMAGE, HEALTH, SPEED, PORTAL
     60        };
     61    }
    5362
    5463    class _OrxonoxExport ActionpointController : public FightingController, public Tickable
     
    118127                bool bFirstTick_;
    119128
     129                void setSpawners();
     130                Vector3 bestHealthPickup (float searchRadius);
     131                // Point closestPickup(PickupType::Value pickupType);
     132                std::multimap <int, std::pair<PickupSpawner*, bool> > healthSpawners_;
     133                std::multimap <int, std::pair<PickupSpawner*, bool> > damageSpawners_;
     134                std::multimap <int, std::pair<PickupSpawner*, bool> > speedSpawners_;
     135
    120136        private:
    121137           
  • code/branches/campaignHS15/src/orxonox/controllers/FightingController.cc

    r10886 r10888  
    172172        }
    173173    }
    174    
     174    void FightingController::dodgeTowards (Vector3& position)
     175    {
     176        Vector3 thisPosition = this->getControllableEntity()->getPosition();
     177        Vector3 diff = (position - thisPosition);
     178        float diffLength = diff.length();
     179        Vector3 diffUnit = diff/diffLength;
     180        float factor = 300.0f;
     181        if (diffLength < 300)
     182        {
     183            this->setTargetPosition(position);
     184            return;   
     185        }
     186        else if (diffLength < 600)
     187            factor = 400.0f;
     188        else if (diffLength < 1000)
     189            factor = 700.0f;
     190        else
     191            factor = 1000.0f;
     192        float x = CommonController::randomInRange (400, 800) * (CommonController::randomInRange(0,1) <= 0.5 ? 1 : -1);
     193        float y = CommonController::randomInRange (400, 800) * (CommonController::randomInRange(0,1) <= 0.5 ? 1 : -1);
     194        float z = diffUnit.z == 0 ? 0 : (1/diffUnit.z) * (-x * diffUnit.x - y * diffUnit.y);
     195        this->setTargetPosition(thisPosition + Vector3(x,y,z) + diffUnit * factor);
     196        // orxout(internal_error) << "Dodging towards " << Vector3(x,y,z)  << endl;
     197        this->boostControl();
     198    }
    175199    void FightingController::dodge(const Vector3& thisPosition, Vector3& diffUnit)
    176200    {
     
    179203        float x = CommonController::randomInRange (100, 800) * (CommonController::randomInRange(0,1) <= 0.5 ? 1 : -1);
    180204        float y = CommonController::randomInRange (100, 800) * (CommonController::randomInRange(0,1) <= 0.5 ? 1 : -1);
    181         float z = (1/diffUnit.z) * (-x * diffUnit.x - y * diffUnit.y);
     205        float z = diffUnit.z == 0 ? 0 : (1/diffUnit.z) * (-x * diffUnit.x - y * diffUnit.y);
    182206        this->setTargetPosition(thisPosition + Vector3(x,y,z) + (this->deltaHp < 0 ? -diffUnit * 450.0f : diffUnit * 100.0f));
    183207        this->boostControl();
  • code/branches/campaignHS15/src/orxonox/controllers/FightingController.h

    r10886 r10888  
    6262            void maneuver();
    6363            void dodge(const Vector3& thisPosition, Vector3& diffUnit);
     64            void dodgeTowards (Vector3& position);
    6465            bool canFire();
    6566            void doFire();
  • code/branches/campaignHS15/src/orxonox/controllers/FlyingController.cc

    r10886 r10888  
    4242        this->rotationProgress_ = 0;
    4343        this->spread_ = 200;
    44         this->tolerance_ = 100;
     44        this->tolerance_ = 80;
    4545    }
    4646    FlyingController::~FlyingController()
  • code/branches/campaignHS15/src/orxonox/controllers/SectionController.cc

    r10886 r10888  
    126126                {
    127127                    this->maneuver();
    128                     this->bShooting_ = this->canFire();               
     128                    this->bShooting_ = this->canFire();
     129                    // Vector3 healthPosition = bestHealthPickup((this->target_->getWorldPosition() - this->getControllableEntity()->getWorldPosition()).length());
     130                    // if ((this->getControllableEntity()->getWorldPosition() - healthPosition).length() < this->tolerance_)
     131                    // {
     132                    //     //----choose where to go----
     133                    //     this->maneuver();
     134                    // }
     135                    // else
     136                    // {
     137                    //     this->dodgeTowards(healthPosition);
     138                    // }
     139                    // //----fire if you can----
     140                    // this->bShooting_ = this->canFire();               
    129141                }
    130142            }
  • code/branches/campaignHS15/src/orxonox/controllers/WingmanController.cc

    r10886 r10888  
    112112                if (this->hasTarget())
    113113                {
    114                     //----choose where to go----
    115114                    this->maneuver();
    116                     //----fire if you can----
    117                     this->bShooting_ = this->canFire();               
     115                    this->bShooting_ = this->canFire();
     116                    // Vector3 healthPosition = bestHealthPickup((this->target_->getWorldPosition() - this->getControllableEntity()->getWorldPosition()).length());
     117                    // if ((this->getControllableEntity()->getWorldPosition() - healthPosition).length() < this->tolerance_)
     118                    // {
     119                    //     //----choose where to go----
     120                    //     this->maneuver();
     121                    // }
     122                    // else
     123                    // {
     124                    //     this->dodgeTowards(healthPosition);
     125                    // }
     126                    // //----fire if you can----
     127                    // this->bShooting_ = this->canFire();               
    118128                }
    119129            }
  • code/branches/campaignHS15/src/orxonox/worldentities/Actionpoint.h

    r10885 r10888  
    9090        </SpaceShip>
    9191       
     92        One can also use other Worldentities instead of Actionpoints just like Waypoints, but those points
     93        will be included in loop.
    9294        For more information read descriptions of the methods.
    9395    */
Note: See TracChangeset for help on using the changeset viewer.