Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 10923


Ignore:
Timestamp:
Dec 7, 2015, 8:34:20 AM (8 years ago)
Author:
gania
Message:

check in

Location:
code/branches/campaignHS15
Files:
9 edited

Legend:

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

    r10915 r10923  
    9292<!-- HERE STARTS DEMO FOR THE ACTIONPOINTS.
    9393P.S. Never set protectMe in the first actionpoint: if human didn't spawn, that actionpoint will be skipped -->
    94       <!--
     94     
    9595    <Model mesh="cube.mesh" scale=8 position="0,0,0" />
    9696
     
    153153      </templates>
    154154    </SpaceShip>
    155   -->
     155 
    156156   
    157157<!-- HERE ENDS DEMO FOR THE ACTIONPOINTS -->
    158158<!-- HERE STARTS DEMO FOR FIGHTING -->
    159    
     159    <!--
    160160
    161161    <SpaceShip position="-4000, 1500, -1000" lookat="0,0,0" team=0 name="d1sd1">
     
    196196      </controller>
    197197    </SpaceShip>
    198     <SpaceShip position="-5000, 1500, -1000" lookat="0,0,0" team=0 name="d1s1d1">
    199       <templates>
    200         <Template link=spaceshipassff />
    201       </templates>
    202       <controller>
    203         <DivisionController team=0 formationMode="WALL">
    204 
    205         </DivisionController>
    206       </controller>
    207     </SpaceShip>
    208     <SpaceShip position="-5000, 1900, -1000" lookat="0,0,0" team=0 name="d1s1s1">
    209       <templates>
    210         <Template link=spaceshipassff />
    211       </templates>
    212       <controller>
    213         <SectionController team=0>
    214         </SectionController>
    215       </controller>
    216     </SpaceShip>
    217     <SpaceShip position="-5000, 2100, -1000" lookat="0,0,0" team=0 name="d1s1w1">
    218       <templates>
    219         <Template link=spaceshipassff />
    220       </templates>
    221       <controller>
    222         <WingmanController team=0>
    223         </WingmanController>
    224       </controller>
    225     </SpaceShip>
    226     <SpaceShip position="-5000, 2400, -1000" lookat="0,0,0" team=0 name="d1s1w2">
    227       <templates>
    228         <Template link=spaceshipassff />
    229       </templates>
    230       <controller>
    231         <WingmanController team=0>
    232         </WingmanController>
    233       </controller>
    234     </SpaceShip>
    235198
    236199    <SpaceShip position="2000, -1500, 1000" lookat="0,0,0" team=1  name="d2sd1">
     
    271234      </controller>
    272235    </SpaceShip>
    273     <SpaceShip position="1000, -1500, 1000" lookat="0,0,0" team=1  name="d2s1d1">
    274       <templates>
    275         <Template link=spaceshipassff />
    276       </templates>
    277       <controller>
    278         <DivisionController team=1 formationMode="WALL">
    279 
    280         </DivisionController>
    281       </controller>
    282     </SpaceShip>
    283     <SpaceShip position="1000, -1900, 1000" lookat="0,0,0" team=1 name="d2s1s1">
    284       <templates>
    285         <Template link=spaceshipassff />
    286       </templates>
    287       <controller>
    288         <SectionController team=1>
    289         </SectionController>
    290       </controller>
    291     </SpaceShip>
    292     <SpaceShip position="1000, -2100, 1000" lookat="0,0,0" team=1 name="d2s1w1">
    293       <templates>
    294         <Template link=spaceshipassff />
    295       </templates>
    296       <controller>
    297         <WingmanController team=1>
    298         </WingmanController>
    299       </controller>
    300     </SpaceShip>
    301     <SpaceShip position="1000, -2400, 1000" lookat="0,0,0" team=1 name="d2s1w2">
    302       <templates>
    303         <Template link=spaceshipassff />
    304       </templates>
    305       <controller>
    306         <WingmanController team=1>
    307         </WingmanController>
    308       </controller>
    309     </SpaceShip>
    310 
     236 -->
    311237<!-- HERE ENDS DEMO FOR FIGHTING -->
    312238<!-- HERE STARTS DEMO FOR FORMATIONS -->
  • code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.cc

    r10915 r10923  
    4040    ActionpointController::ActionpointController(Context* context) : FightingController(context)
    4141    {
     42        this->ticks_ = 0;
    4243        this->bPatrolling_ = false;
    43 
    44         this->actionCounter_ = 0;
     44        this->maneuverCounter_ = 0;
    4545        this->bInLoop_ = false;
    4646        this->bLoop_ = false;
     
    4949        parsedActionpoints_.clear();
    5050        actionpoints_.clear();
    51         healthSpawners_.clear();
    52         damageSpawners_.clear();
    53         speedSpawners_.clear();
     51
    5452        this->bTakenOver_ = false;
    5553        this->action_ = Action::NONE;
     
    9694        parsedActionpoints_.clear();
    9795        actionpoints_.clear();
    98         healthSpawners_.clear();
    99         damageSpawners_.clear();
    100         speedSpawners_.clear();
     96        ActionpointController::nextActionpointControllerId_--;
     97        if (ActionpointController::nextActionpointControllerId_ < 0)
     98            ActionpointController::nextActionpointControllerId_ = 0;
    10199    }
    102100    void ActionpointController::tick(float dt)
    103101    {
    104         if (!this->getControllableEntity())
    105             return;
     102        if (!this || !this->getControllableEntity())
     103            return;
     104        ++this->ticks_;
     105        // orxout (internal_error) << "this id = " << this->actionpointControllerId_ << endl;
     106        if (ActionpointController::sTicks_ < this->ticks_)
     107        {
     108            // orxout (internal_error) << "total id's = " << ActionpointController::nextActionpointControllerId_ << endl;
     109            ++ActionpointController::sTicks_;
     110        }
     111
     112        if (this->ticks_ == 1)
     113        {
     114
     115            this->actionpointControllerId_ = ActionpointController::nextActionpointControllerId_++;
     116            std::reverse(parsedActionpoints_.begin(), parsedActionpoints_.end());
     117            std::reverse(actionpoints_.begin(), actionpoints_.end());
     118            if (this->parsedActionpoints_.empty())
     119            {
     120                this->action_ = Action::FIGHTALL;
     121            }
     122        }
     123        if (this->ticks_ == 1)
     124        {   
     125            this->timeOffset_ = 0.0f;
     126            this->bActionCalled_ = false;
     127           
     128            this->bFirstTick_ = false;
     129        }
     130/*        if (ActionpointController::sTicks_ % (ActionpointController::nextActionpointControllerId_+1) != this->actionpointControllerId_)
     131        {
     132            return;
     133        }*/
     134        if (!this || !this->getControllableEntity())
     135            return;
     136       
     137        if (this->bHasTargetPosition_)
     138        {
     139            this->moveToTargetPosition(dt);
     140        }
     141        else if (this->bLookAtTarget_)
     142        {
     143            this->lookAtTarget(dt);
     144        }
     145        if (this->bShooting_)
     146        {
     147            this->doFire();
     148        }
     149
     150        if (!this || !this->getControllableEntity())
     151            return;
     152       
    106153        if (stop_)
    107154            return;
    108         if (this->timeout_ > 0 && this->bFiredRocket_)
    109         {
    110             this->timeout_ -= dt;
    111         }
    112         if (this->bStartedDodging_)
    113         {
    114             this->timeDodged_ += dt;
    115             if (this->timeDodged_ > 4.0f)
    116             {
    117                 this->bStartedDodging_ = false;
    118                 this->timeDodged_ = 0;
    119             }
    120         }
    121         maneuverCounter_ += dt;
    122         if (maneuverCounter_ > 6.0f)
    123             maneuverCounter_ = 0;
     155       
    124156        this->timeOffset_ += dt;
    125157        if (this->timeOffset_ >= 2.4f)
     
    127159        if (timeout_ <= 0)
    128160            this->bFiredRocket_ = false;
    129 
    130         if (this->bHasTargetPosition_)
    131         {
    132             this->moveToTargetPosition(dt);
    133         }
    134         else if (this->bLookAtTarget_)
    135         {
    136             this->lookAtTarget(dt);
    137         }
    138 
    139         if (!this->getControllableEntity())
    140             return;
    141         if (this->bShooting_)
    142         {
    143             this->doFire();
    144         }
    145         if (this->bFirstTick_)
    146         {
    147             std::reverse(parsedActionpoints_.begin(), parsedActionpoints_.end());
    148             std::reverse(actionpoints_.begin(), actionpoints_.end());
    149             if (this->parsedActionpoints_.empty())
    150             {
    151                 this->action_ = Action::FIGHTALL;
    152             }
    153         }
    154         if (this->bFirstTick_)
    155         {   
    156             this->timeOffset_ = 0.0f;
    157             this->bActionCalled_ = false;
    158             setSpawners();
    159             // orxout(internal_error) << "health spawners size = " << this->healthSpawners_.size() <<
    160             // ", damage spawners size = " << this->damageSpawners_.size() <<
    161             // ", speed spawners size = " << this->speedSpawners_.size() << endl;       
    162             this->bFirstTick_ = false;
    163         }
    164         if (!this->getControllableEntity())
    165             return;
     161        if (!this || !this->getControllableEntity())
     162            return;
     163
     164        if (!this || !this->getControllableEntity())
     165            return;
     166        if (this->timeout_ > 0 && this->bFiredRocket_)
     167            {
     168                this->timeout_ -= dt;
     169            }
     170            if (this->bStartedDodging_)
     171            {
     172                this->timeDodged_ += dt;
     173            }
     174            maneuverCounter_ += dt;
     175
    166176        //maneuver every 0.25 sec ->
    167         if (this->hasTarget() &&
    168             ((this->timeOffset_ >= 0.4f && this->timeOffset_ < 0.8f) ||
    169              (this->timeOffset_ >= 1.2f && this->timeOffset_ < 1.6f) ||
    170              (this->timeOffset_ >= 1.8f && this->timeOffset_ < 2.0f) ||
    171              (this->timeOffset_ >= 2.2f && this->timeOffset_ < 2.4f)) && !this->bManeuverCalled_)
    172         {
    173             this->bManeuverCalled_ = true;
     177        int step =  5;
     178        if (this->hasTarget() && ActionpointController::sTicks_ % 100 == step * (this->actionpointControllerId_) + 3)
     179        {
     180            if (maneuverCounter_ > 6.0f)
     181                maneuverCounter_ = 0;
     182            if (this->bStartedDodging_ &&  this->timeDodged_ > 4.0f)
     183            {
     184                this->bStartedDodging_ = false;
     185                this->timeDodged_ = 0;
     186            }
    174187            this->maneuver();
     188        }
     189        if (ActionpointController::sTicks_ % 100 == step * this->actionpointControllerId_ + 1)
     190        {
     191            this->action();
     192        }
     193        if (!this || !this->getControllableEntity())
     194            return;
     195
     196        if (!this || !this->getControllableEntity())
     197            return;
     198        if (this->hasTarget() &&  ActionpointController::sTicks_ % 100 == step * (this->actionpointControllerId_))
     199        {
    175200            this->bShooting_ = this->canFire();
    176         }
    177         if ((this->timeOffset_ >= 0.0f && this->timeOffset_ < 0.4f) ||
    178              (this->timeOffset_ >= 0.8f && this->timeOffset_ < 1.2f) ||
    179              (this->timeOffset_ >= 1.6f && this->timeOffset_ < 1.8f) ||
    180              (this->timeOffset_ >= 2.0f && this->timeOffset_ < 2.2f))
    181             this->bManeuverCalled_ = false;
     201           
     202        }
     203        if (!this || !this->getControllableEntity())
     204            return;
     205       
     206
    182207        SUPER(ActionpointController, tick, dt);
    183208    }
     
    195220            this->startAttackingEnemiesThatAreClose();
    196221        }
     222        if (!this || !this->getControllableEntity())
     223            return;
     224
    197225        this->deltaHp = orxonox_cast<Pawn*> (this->getControllableEntity())->getHealth() - this->previousHp;
    198226        this->previousHp = orxonox_cast<Pawn*> (this->getControllableEntity())->getHealth();
     227        if (!this || !this->getControllableEntity())
     228            return;
    199229
    200230        // if (this->actionCounter_ % 2 == 0)
     
    202232        if (this->action_ == Action::NONE || this->bTakenOver_)
    203233        {
    204             // Point point = closestPickup(PickupType::HEALTH);
    205             // if (point.action != Action::NONE)
    206             // {
    207             //     orxout(internal_error) << "found health" << endl;
    208             //     this->parsedActionpoints_.push_back(point);
    209             // }
    210 
    211234            if (this->parsedActionpoints_.empty() && this->loopActionpoints_.empty() && this->bDefaultFightAll_)
    212235            {
     
    218241            // this->action();
    219242        }
     243        if (!this || !this->getControllableEntity())
     244            return;
     245
    220246        //Action fightall -> fight till nobody alive
    221247        if (this->action_ == Action::FIGHTALL)
     
    307333        }
    308334
    309             // Vector3 healthPosition = bestHealthPickup((this->target_->getWorldPosition() - this->getControllableEntity()->getWorldPosition()).length());
    310             // if ((this->getControllableEntity()->getWorldPosition() - healthPosition).length() < this->tolerance_)
    311             // {
    312             //     //----choose where to go----
    313             //     this->maneuver();
    314             // }
    315             // else
    316             // {
    317             //     this->dodgeTowards(healthPosition);
    318             // }
    319             // //----fire if you can----
    320             // this->bShooting_ = this->canFire(); 
    321          
    322         this->actionCounter_ += this->actionCounter_ < 100000 ? 1 : -this->actionCounter_ ;
    323335
    324336    }
     
    402414        {
    403415            case Action::FIGHT:
    404             { return "FIGHT"; break; }
     416            { return "FIGHT"; }
    405417            case Action::FLY:
    406             { return "FLY"; break; }
     418            { return "FLY"; }
    407419            case Action::PROTECT:
    408             { return "PROTECT"; break; }
     420            { return "PROTECT"; }
    409421            case Action::NONE:
    410             { return "NONE"; break; }
     422            { return "NONE"; }
    411423            case Action::FIGHTALL:
    412             { return "FIGHTALL"; break; }
     424            { return "FIGHTALL"; }
    413425            case Action::ATTACK:
    414             { return "ATTACK"; break; }
     426            { return "ATTACK"; }
    415427            default:
    416428                return "NONE";
     
    462474    void ActionpointController::executeActionpoint()
    463475    {
     476        if (!this || !this->getControllableEntity())
     477            return;
     478
    464479        Point p;
    465480        if (this->bLoop_ && !loopActionpoints_.empty())
     
    478493        else
    479494        {
     495            if (!this || !this->getControllableEntity())
     496                return;
     497
    480498            this->setTarget(0);
    481499            this->setTargetPosition(this->getControllableEntity()->getWorldPosition());
     
    520538            case Action::PROTECT:
    521539            {
    522                
     540                if (!this || !this->getControllableEntity())
     541                    return;
     542
    523543                std::string protectName = p.name;
    524544                if (protectName == "reservedKeyword:human")
     
    583603    void ActionpointController::stayNearProtect()
    584604    {
     605        if (!this || !this->getControllableEntity())
     606            return;
     607
    585608        Vector3 targetRelativePosition(0, 300, 300);
    586609        if (!this->getProtect())
     
    665688    Pawn* ActionpointController::closestTarget()
    666689    {
    667         if (!this->getControllableEntity())
     690        if (!this || !this->getControllableEntity())
    668691            return 0;
    669692
     
    691714    void ActionpointController::startAttackingEnemiesThatAreClose()
    692715    {
     716        if (!this || !this->getControllableEntity())
     717            return;
     718
    693719        //if (this->action_ != Action::FIGHT && this->action_ != Action::FIGHTALL)
    694720        {
     
    700726                        <= this->attackRange_ )
    701727                {
     728                    if (!this || !this->getControllableEntity())
     729                        return;
    702730                    this->setTarget(newTarget);
    703731                    if (this->bLoop_ && !this->bPatrolling_)
     
    718746        }
    719747    }
    720     Vector3 ActionpointController::bestHealthPickup(float searchRadius)
    721     {
    722 
    723         //1000000/distance^2 * 1/index+1
    724         float maxUse = 0;
    725         float tempUse = -1;
    726         int index = 0;
    727         float distance = 0;
    728         Vector3 bestPosition = this->getControllableEntity()->getWorldPosition();
    729 
    730         for (std::multimap<int, std::pair<PickupSpawner*, bool> >::iterator it=healthSpawners_.begin(); it!=healthSpawners_.end(); ++it)
    731         {
    732             distance = (this->getControllableEntity()->getWorldPosition() - (*it).second.first->getWorldPosition()).length();
    733             if (distance < this->tolerance_ || !(*it).second.second)
    734             {
    735                 (*it).second.second = false;
    736                 continue;
    737             }
    738             if (distance > searchRadius)
    739                 continue;
    740             index = (*it).first;
    741             tempUse = 1000000*1/(1+distance*distance) * 1/((index/2.0f)+1);
    742             if (tempUse > maxUse)
    743             {
    744                 bestPosition = (*it).second.first->getWorldPosition();
    745                 maxUse = tempUse;
    746             }
    747         }
    748         //std::multimap<int, std::pair<PickupSpawner*, bool> >::iterator it = this->healthSpawners_.find(index);
    749         //P.S. check if it == ... .end()
    750         //orxout (internal_error) << "best position = " << bestPosition << endl;
    751         return  bestPosition;
    752     }
    753     void ActionpointController::setSpawners()
    754     {
    755         std::vector<std::string> damagePickups;
    756         std::vector<std::string> healthPickups;
    757         std::vector<std::string> speedPickups;       
    758         int index = 0;
    759 
    760 
    761         damagePickups.push_back("largedamageboostpickup");
    762         damagePickups.push_back("dronepickup");           
    763         damagePickups.push_back("mediumdamageboostpickup");
    764         damagePickups.push_back("smalldamageboostpickup");
    765 
    766         healthPickups.push_back("triplehealthspeedinvisibilitypickup");           
    767         healthPickups.push_back("crazyhealthpickup");
    768         healthPickups.push_back("hugehealthpickup");
    769         healthPickups.push_back("hugeshieldpickup");
    770         healthPickups.push_back("hugeinvisiblepickup");
    771         healthPickups.push_back("hugeshrinkpickup");
    772         healthPickups.push_back("mediumhealthpickup");
    773         healthPickups.push_back("mediumshieldpickup");
    774         healthPickups.push_back("mediuminvisiblepickup");
    775         healthPickups.push_back("mediumshrinkpickup"); 
    776         healthPickups.push_back("smallhealthpickup");                   
    777         healthPickups.push_back("smallshieldpickup");
    778         healthPickups.push_back("smallinvisiblepickup");
    779         healthPickups.push_back("smallshrinkpickup");
    780 
    781         speedPickups.push_back("triplehealthspeedinvisibilitypickup");
    782         speedPickups.push_back("hugespeedpickup");
    783         speedPickups.push_back("smalljumppickup");
    784         speedPickups.push_back("mediumspeedpickup");
    785         speedPickups.push_back("smallspeedpickup");
    786        
    787 
    788 
    789         for (ObjectList<WorldEntity>::iterator it = ObjectList<WorldEntity>::begin(); it; ++it)
    790         {
    791             if ((*it)->getIdentifier()->getName() != "PickupSpawner")
    792                 continue;
    793             PickupSpawner* spawner = static_cast<PickupSpawner*>(*it);
    794             std::string name = spawner->getPickupTemplateName();
    795             //float distance = ((*it)->getWorldPosition() - this->getControllableEntity()->getWorldPosition()).length();
    796             // if (distance < 50.0f)
    797             //     continue;           
    798             for (unsigned int i = 0; i < healthPickups.size(); ++i)
    799             {
    800                 if (name == healthPickups.at(i))
    801                 {
    802                     index = i;
    803                     this->healthSpawners_.insert(std::make_pair(index, std::make_pair(spawner, true)));
    804                     break;
    805                 }
    806             }
    807             for (unsigned int i = 0; i < damagePickups.size(); ++i)
    808             {
    809                 if (name == damagePickups.at(i))
    810                 {
    811                     //tempUse = 1000000*1/(1+distance*distance) * 1/((i/2.0f)+1);
    812                     index = i;
    813                     this->damageSpawners_.insert(std::make_pair(index, std::make_pair(spawner, true)));
    814                     break;
    815                 }
    816             }
    817             for (unsigned int i = 0; i < speedPickups.size(); ++i)
    818             {
    819                 if (name == speedPickups.at(i))
    820                 {
    821                     //tempUse = 1000000*1/(1+distance*distance) * 1/((i/2.0f)+1);
    822                     index = i;
    823                     this->speedSpawners_.insert(std::make_pair(index, std::make_pair(spawner, true)));
    824                     break;
    825                 }
    826             }
    827             // if (tempUse > maxUse)
    828             // {
    829             //     Point p = { Action::FLY, "", (*it)->getWorldPosition(), false };
    830             //     maxUse = tempUse;
    831             //     maxPoint = p;
    832             // }
    833             // else
    834             // {
    835             //     tempUse = -1;
    836             //     continue;
    837             // }
    838             // orxout(internal_error) << "resp time  = " << static_cast<PickupSpawner*>(*it)->getRespawnTime() << endl;
    839         } 
    840     }
    841 }
     748    int ActionpointController::nextActionpointControllerId_ = 0;
     749    int ActionpointController::sTicks_ = 0;
     750}   
  • code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.h

    r10915 r10923  
    3535#include "../modules/pickup/PickupSpawner.h"
    3636#include <map>
    37 
    3837
    3938
     
    246245                bool bFirstTick_;
    247246
    248                 void setSpawners();
     247              /*  void setSpawners();
    249248                Vector3 bestHealthPickup (float searchRadius);
    250249                // Point closestPickup(PickupType::Value pickupType);
     
    252251                std::multimap <int, std::pair<PickupSpawner*, bool> > damageSpawners_;
    253252                std::multimap <int, std::pair<PickupSpawner*, bool> > speedSpawners_;
    254 
     253*/
    255254                float timeOffset_;
    256255                bool bActionCalled_;
     
    262261                bool bDefaultPatrol_;
    263262                bool stop_;
     263                static int sTicks_;
     264                static int nextActionpointControllerId_;
     265                int actionpointControllerId_;
     266                int ticks_;
     267
    264268
    265269        private:
  • code/branches/campaignHS15/src/orxonox/controllers/DivisionController.cc

    r10915 r10923  
    6868            return;   
    6969        SUPER(DivisionController, tick, dt);
    70         if (this->timeOffset_ >= 0.0f && this->timeOffset_ <= 0.8f && !this->bActionCalled_)
     70        /*if (this->timeOffset_ >= 0.0f && this->timeOffset_ <= 0.8f && !this->bActionCalled_)
    7171        {
    7272            this->action();
     
    7676        {
    7777            this->bActionCalled_ = false;
    78         }
     78        }*/
    7979
    8080       
  • code/branches/campaignHS15/src/orxonox/controllers/FightingController.cc

    r10906 r10923  
    6363    void FightingController::lookAtTarget(float dt)
    6464    {
     65        if (!this || !this->getControllableEntity())
     66            return;
    6567        ControllableEntity* entity = this->getControllableEntity();
    6668        if ( !entity )
     
    126128        float diffLength = diffVector.length();
    127129        Vector3 diffUnit = diffVector/diffLength;
    128         bool bTargetIsLookingAtThis = CommonController::isLooking (this->target_, this->getControllableEntity(), math::pi/10.0f)
    129             || this->deltaHp < 0;
     130
     131        if (!this || !this->getControllableEntity())
     132            return;
    130133
    131134        //too far? well, come closer then
     
    139142        }
    140143        else
    141         {
     144        {   
     145            bool bTargetIsLookingAtThis = CommonController::isLooking (this->target_, this->getControllableEntity(), math::pi/10.0f)
     146                || this->deltaHp < 0;
    142147            this->bKeepFormation_ = false;
     148
     149            if (!this || !this->getControllableEntity())
     150                return;
    143151            // if (this->actionCounter_ % 3 == 0)
    144152            if (maneuverCounter_ <= 1.2)
     
    173181            }
    174182        }
    175         /*//too close? How do u expect to dodge anything? Just attack!
    176         else if (diffLength < 1000)
    177         {   
    178             this->bKeepFormation_ = false;
    179 
    180             //at this point, just look and shoot
    181             if (diffLength < 1000)
    182             {
    183                 this->stopMoving();
    184                 this->startLookingAtTarget();
    185 
    186             }
    187             else
    188             {
    189                 this->setTargetPosition(this->positionOfTarget_ - diffUnit * 300.0f);
    190             }
    191         }
    192         //Good distance? Check if target looks at us. It doesn't? Go hunt!
    193         else if (!bTargetIsLookingAtThis)
    194         {
    195             this->bKeepFormation_ = false;
    196             this->setTargetPosition(this->positionOfTarget_ - diffUnit * 900.0f);
    197         }
    198         //That's unfortunate, he is looking and probably shooting... try to dodge what we can... 
    199         else
    200         {   
    201             this->bKeepFormation_ = false;
    202             if (maneuverCounter_ == 0)
    203             {
    204                 this->setTargetPosition(this->positionOfTarget_ - diffUnit * 900.0f);   
    205                 return;
    206             }
    207             if (this->actionCounter_ % 3 == 0)
    208                 dodge(thisPosition, diffLength, diffUnit);
    209         }*/
    210     }
    211     void FightingController::dodgeTowards (Vector3& position)
    212     {
    213         Vector3 thisPosition = this->getControllableEntity()->getPosition();
    214         Vector3 diff = (position - thisPosition);
    215         float diffLength = diff.length();
    216         Vector3 diffUnit = diff/diffLength;
    217         float factor = 300.0f;
    218         if (diffLength < 300)
    219         {
    220             this->setTargetPosition(position);
    221             return;   
    222         }
    223         else if (diffLength < 600)
    224             factor = 400.0f;
    225         else if (diffLength < 1000)
    226             factor = 700.0f;
    227         else
    228             factor = 1000.0f;
    229         float x = CommonController::randomInRange (400, 800) * (CommonController::randomInRange(0,1) <= 0.5 ? 1 : -1);
    230         float y = CommonController::randomInRange (400, 800) * (CommonController::randomInRange(0,1) <= 0.5 ? 1 : -1);
    231         float z = diffUnit.z == 0 ? 0 : (1/diffUnit.z) * (-x * diffUnit.x - y * diffUnit.y);
    232         this->setTargetPosition(thisPosition + Vector3(x,y,z) + diffUnit * factor);
    233         // orxout(internal_error) << "Dodging towards " << Vector3(x,y,z)  << endl;
    234         this->boostControl();
    235     }
     183    }
     184   
    236185    void FightingController::dodge(const Vector3& thisPosition, float diffLength, Vector3& diffUnit)
    237186    {
     
    257206    {
    258207        //no target? why fire?
    259         if (!this->target_)
     208        if (!this->target_ || !this->getControllableEntity())
    260209            return false;
    261210        Vector3 newPositionOfTarget = getPredictedPosition(this->getControllableEntity()->getWorldPosition(),
     
    274223    float FightingController::squaredDistanceToTarget()  const
    275224    {
    276         if (!this->getControllableEntity())
     225        if (!this || !this->getControllableEntity())
    277226            return 0;
    278227        if (!this->target_ || !this->getControllableEntity())
     
    294243    Pawn* FightingController::closestTarget() const
    295244    {
    296         if (!this->getControllableEntity())
     245        if (!this || !this->getControllableEntity())
    297246            return 0;
    298247
  • code/branches/campaignHS15/src/orxonox/controllers/FlyingController.cc

    r10888 r10923  
    2424
    2525 *   Co-authors:
    26  *      Dominik Solenicki
     26 *   ...
    2727 *
    2828 */
     
    4646    FlyingController::~FlyingController()
    4747    {
    48 
    4948    }
    5049
     
    7675        {
    7776            case FormationMode::WALL:
    78             { return "WALL"; break; }
     77            { return "WALL"; }
    7978            case FormationMode::FINGER4:
    80             { return "FINGER4"; break; }
     79            { return "FINGER4"; }
    8180            case FormationMode::DIAMOND:
    82             { return "DIAMOND"; break; }
     81            { return "DIAMOND"; }
    8382            default:
    84                 return "DIAMOND"; break;
     83                return "DIAMOND";
    8584        }
    8685    }
     
    8988        this->bHasTargetPosition_ = false;
    9089    }
    91     void FlyingController::moveToPosition(const Vector3& target, float dt)
    92     {
     90    void FlyingController::moveToPosition(const Vector3& targetPosition, float dt)
     91    {
     92        if (!this->getControllableEntity())
     93            return;
    9394        ControllableEntity* entity = this->getControllableEntity();
    9495
    95         float distance = ( target - entity->getPosition() ).length();
     96        float distance = ( targetPosition - entity->getPosition() ).length();
    9697
    9798        if ( distance >= this->tolerance_ )
     
    101102                entity->getOrientation()  * WorldEntity::FRONT,
    102103                entity->getOrientation()  * WorldEntity::UP,
    103                 target );
     104                targetPosition );
    104105            float rotateX = -clamp( coord.x * 10, -1.0f, 1.0f );
    105106            float rotateY = clamp( coord.y * 10, -1.0f, 1.0f );
     
    107108            entity->rotatePitch( ROTATEFACTOR * rotateY * dt );
    108109         
    109             if (distance > this->tolerance_*1.5f || (rotateX > -0.01 && rotateX < 0.01 && rotateY > -0.01 && rotateY < 0.01))
     110            if (distance > this->tolerance_*1.5f || (rotateX > -0.03 && rotateX < 0.03 && rotateY > -0.03 && rotateY < 0.03))
    110111                entity->moveFrontBack( SPEED * dt );
    111112                copyTargetOrientation(dt);
     
    123124    void FlyingController::copyOrientation(const Quaternion& orient, float dt)
    124125    {
    125         //inspired by
     126        //copied from
    126127        //http://www.ogre3d.org/tikiwiki/tiki-index.php?page=Quaternion+and+Rotation+Primer&structure=Tutorials#Q._How_can_I_make_my_objects_rotate_smoothly_You_mentioned_slerp_etc_
    127128        //how can I make my objects rotate smoothly?
    128        
     129        if (!this->getControllableEntity())
     130            return;
    129131        Quaternion myOrient = this->getControllableEntity()->getOrientation();
    130132        this->rotationProgress_ += dt;
     
    137139        else
    138140        {
    139 
    140             Quaternion delta = Quaternion::Slerp(rotationProgress_, myOrient, orient, true);
     141            Quaternion deltaOrientation = Quaternion::Slerp(rotationProgress_, myOrient, orient, true);
    141142           
    142             //rotate roll builds a Quaternion in roll method of WorldEntity, then it sets orientation.
    143             //it is faster just to set orientation, plus that way there is no need in calculating the roll angle.
    144             //On the downside, however, ship might also yaw and pitch, but this effect is neglectable, as we only call
    145             //copyOrientation after we move our ship, thus it doesn't affect ships's flying direction too much.
    146             //If you don't like the code style, you are welcomed to uncomment the code below
    147             //and comment out setOrientation part, it will work just fine, but it will also be a tiny bit slower.
    148             //P.S. apperantly it did affect ship's direction and did so way too much.
    149             Matrix3 orientMatrix, myMatrix;
    150 
    151             delta.ToRotationMatrix(orientMatrix);
     143            Matrix3 deltaMatrix, myMatrix;
     144
     145            deltaOrientation.ToRotationMatrix(deltaMatrix);
    152146            myOrient.ToRotationMatrix (myMatrix);
    153147
    154             Radian yRad, pRad, rRad, yMy, pMy, rMy;
    155             orientMatrix.ToEulerAnglesYXZ(yRad, pRad, rRad);
    156             myMatrix.ToEulerAnglesYXZ (yMy, pMy, rMy);
    157 
    158             this->getControllableEntity()->rotateRoll ((rRad.valueRadians() - rMy.valueRadians())*ROTATEFACTOR*dt);
    159             // this->getControllableEntity()->setOrientation(delta);
    160         }
    161        
    162        
    163     }
    164     //change log: increased precision, increased rotation speed
     148            Radian yawDelta, pitchDelta, rollDelta, yawMy, pitchMy, rollMy;
     149            deltaMatrix.ToEulerAnglesYXZ(yawDelta, pitchDelta, rollDelta);
     150            myMatrix.ToEulerAnglesYXZ (yawMy, pitchMy, rollMy);
     151
     152            if (!this->getControllableEntity())
     153                return;
     154            this->getControllableEntity()->rotateRoll ((rollDelta.valueRadians() - rollMy.valueRadians())*ROTATEFACTOR*dt);
     155        }
     156    }
     157
    165158    void FlyingController::copyTargetOrientation(float dt)
    166159    {
    167160        if (bHasTargetOrientation_)
    168161        {   
    169             copyOrientation(targetOrientation_, dt);
     162            this->copyOrientation(targetOrientation_, dt);
    170163        }
    171164    }
     
    186179    {
    187180        if (target)
    188             setTargetOrientation(target->getOrientation());
     181            this->setTargetOrientation(target->getOrientation());
    189182    }
    190183    void FlyingController::boostControl()
    191184    {
     185        if (!this->getControllableEntity())
     186            return;
    192187        SpaceShip* ship = orxonox_cast<SpaceShip*>(this->getControllableEntity());
    193188        if(ship == NULL) return;
     
    221216             + (orient* (targetRelativePosition)));
    222217        //let ship finish rotating. also don't call copyOrientation to often as it is a slow function.
    223         if (this->actionCounter_ % 6 == 0 && !this->bHasTargetOrientation_)
     218        if (static_cast<int>(rnd(1.0f) * 100) % 3 == 0)
    224219            this->setTargetOrientation (orient);
    225220        this->setTargetPosition (targetAbsolutePosition);
  • code/branches/campaignHS15/src/orxonox/controllers/FlyingController.h

    r10898 r10923  
    8585            virtual void boostControl(); 
    8686            void keepFormation (const ControllableEntity* leaderEntity, Vector3& targetRelativePosition);     
     87           
    8788            FormationMode::Value formationMode_;
    8889         
    89             float rotationProgress_;
    90             int actionCounter_;
     90            float rotationProgress_;    //<! for slerp
    9191            bool bHasTargetPosition_;
    9292            Vector3 targetPosition_;
  • code/branches/campaignHS15/src/orxonox/controllers/SectionController.cc

    r10915 r10923  
    7474   
    7575        SUPER(SectionController, tick, dt);
    76         if (this->timeOffset_ > 0.8f && this->timeOffset_ <= 1.6f && !this->bActionCalled_)
     76        /*if (this->timeOffset_ > 0.8f && this->timeOffset_ <= 1.6f && !this->bActionCalled_)
    7777        {
    7878            this->action();
     
    8282        {
    8383            this->bActionCalled_ = false;
    84         }
     84        }*/
    8585
    8686    }
     
    9797            this->myDivisionLeader_ = newDivisionLeader;
    9898            //spread copyOrientation called equally among the division
    99             if (this->myDivisionLeader_)
    100             {
    101                 this->actionCounter_ = 5;
    102             }
     99
    103100        }
    104101        //----If have leader----
     
    156153        }
    157154
    158         this->actionCounter_ += this->actionCounter_ < 100000 ? 1 : -this->actionCounter_ ;
    159155    }
    160156
     
    166162        //----If division leader fights, cover him by fighting emenies close to his target----
    167163        Action::Value action = this->myDivisionLeader_->getAction();
    168        
    169         Pawn* target;
     164
    170165        if (action == Action::FIGHT || action == Action::FIGHTALL || action == Action::ATTACK)
    171166        {
     167            Pawn* target;
    172168            //----if he has a target----
    173169            if (this->myDivisionLeader_->hasTarget())
     
    177173                    !( this->hasTarget() && this->getTarget() != this->myDivisionLeader_->getTarget() ) )
    178174                {
    179 
    180175                    bool foundTarget = false;
    181176                    //----new target should be close to division's target----
  • code/branches/campaignHS15/src/orxonox/controllers/WingmanController.cc

    r10915 r10923  
    7070        if (!this->myLeader_)
    7171        {
    72             if (this->actionTime_ == 2.0f)
     72            /*if (this->actionTime_ == 2.0f)
    7373            {
    7474                if (this->timeOffset_ >= 0.0f && this->timeOffset_ <= 0.8f && !this->bActionCalled_)
     
    9393                    this->bActionCalled_ = false;
    9494                }
    95             }
     95            }*/
    9696        }
    9797        else
    9898        {
    99             if (this->timeOffset_ >= this->actionTime_ && this->timeOffset_ <= this->actionTime_ + 0.4f && !this->bActionCalled_)
     99           /* if (this->timeOffset_ >= this->actionTime_ && this->timeOffset_ <= this->actionTime_ + 0.4f && !this->bActionCalled_)
    100100            {
    101101                this->action();
     
    105105            {
    106106                this->bActionCalled_ = false;
    107             }
     107            }*/
    108108        }
    109109       
     
    114114    void WingmanController::action()
    115115    {
    116 
     116        if (!this || !this->getControllableEntity())
     117            return;
    117118        //----If no leader, find one----
    118119        if (!this->myLeader_)
     
    122123            if (this->myLeader_)
    123124            {
    124                 //spread copyOrientation called equally among the division
    125                 if (this->myLeader_->getIdentifier()->getName() == "SectionController")
    126                     this->actionCounter_ = 1;
    127                 else
    128                     this->actionCounter_ = 4;
     125               
    129126            }
    130127        }
     
    137134        {
    138135           ActionpointController::action();
     136            if (!this || !this->getControllableEntity())
     137                return;
     138
    139139        }
    140140        else if (this->myLeader_)
     
    170170            }
    171171        }
    172         this->actionCounter_ += this->actionCounter_ < 100000 ? 1 : -this->actionCounter_ ;
    173172    }
    174173     
Note: See TracChangeset for help on using the changeset viewer.