Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 7, 2015, 4:06:37 PM (8 years ago)
Author:
gania
Message:

fix for sigsegv?

File:
1 edited

Legend:

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

    r10935 r10946  
    113113            this->moveToTargetPosition(dt);
    114114        }
     115        if (!this || !this->getControllableEntity())
     116            return;
    115117        else if (this->bLookAtTarget_)
    116118        {
     
    146148            this->bDodge_ = true;
    147149        }
     150        if (!this || !this->getControllableEntity())
     151            return;
    148152        if (ActionpointController::sTicks_ % 100 == step * this->actionpointControllerId_ + 1)
    149153        {
     
    175179                this->doFire();
    176180            }
     181            if (!this || !this->getControllableEntity())
     182                return;
    177183            this->deltaHp = orxonox_cast<Pawn*> (this->getControllableEntity())->getHealth() - this->previousHp;
    178184            this->previousHp = orxonox_cast<Pawn*> (this->getControllableEntity())->getHealth();
     
    202208            if (this->parsedActionpoints_.empty() && this->loopActionpoints_.empty() && this->bDefaultFightAll_)
    203209            {
     210                if (!this || !this->getControllableEntity())
     211                    return;
    204212                Point p = { Action::FIGHTALL, "", Vector3::ZERO, false };
    205213                this->parsedActionpoints_.push_back (p);
    206214            }
     215            if (!this || !this->getControllableEntity())
     216                return;
    207217            this->executeActionpoint();
     218            if (!this || !this->getControllableEntity())
     219                return;
    208220            this->bTakenOver_ = false;
    209221        }
     
    220232                if (newTarget)
    221233                {
     234                    if (!this || !this->getControllableEntity())
     235                        return;
    222236                    this->setAction (Action::FIGHTALL, newTarget);
    223237                }
    224238                else
    225239                {
     240                    if (!this || !this->getControllableEntity())
     241                        return;
    226242                    this->nextActionpoint();
     243                    if (!this || !this->getControllableEntity())
     244                        return;
    227245                    this->executeActionpoint();
    228246   
     
    233251        else if (this->action_ == Action::FIGHT)
    234252        {
    235 
    236253            if (!this->hasTarget() )
    237254            {
    238255                //----find a target----
    239                 ControllableEntity* newTarget = this->closestTarget();   
     256                ControllableEntity* newTarget = this->closestTarget(); 
     257                if (!this || !this->getControllableEntity())
     258                    return; 
    240259                if (newTarget &&
    241260                        CommonController::distance (this->getControllableEntity(), newTarget) < this->attackRange_)
    242261                {
     262                    if (!this || !this->getControllableEntity())
     263                        return;
    243264                    this->setAction (Action::FIGHT, newTarget);
    244265                }
    245266                else
    246267                {
     268                    if (!this || !this->getControllableEntity())
     269                        return;
    247270                    this->nextActionpoint();
     271                    if (!this || !this->getControllableEntity())
     272                        return;
    248273                    this->executeActionpoint();
    249274                }
     
    257282                {
    258283                    ControllableEntity* newTarget = this->closestTarget();
    259                    
     284                    if (!this || !this->getControllableEntity())
     285                        return;
    260286                    if (newTarget &&
    261287                        CommonController::distance (this->getControllableEntity(), newTarget) < this->attackRange_)
    262288                    {
     289                        if (!this || !this->getControllableEntity())
     290                            return;
    263291                        this->setAction (Action::FIGHT, newTarget);
    264292                    }
    265293                    else
    266294                    {
     295                        if (!this || !this->getControllableEntity())
     296                            return;
    267297                        this->nextActionpoint();
     298                        if (!this || !this->getControllableEntity())
     299                            return;
    268300                        this->executeActionpoint();
    269301                    }
     
    275307            if (this->squaredDistanceToTarget() <= this->squaredaccuracy_)
    276308            {
     309                if (!this || !this->getControllableEntity())
     310                    return;
    277311                this->nextActionpoint();   
     312                if (!this || !this->getControllableEntity())
     313                    return;
    278314                this->executeActionpoint();
    279315            }
     
    283319            if (!this->getProtect())
    284320            {
     321                if (!this || !this->getControllableEntity())
     322                    return;
    285323                this->nextActionpoint();
     324                if (!this || !this->getControllableEntity())
     325                    return;
    286326                this->executeActionpoint();
    287327            }
     328            if (!this || !this->getControllableEntity())
     329                return;
    288330            this->stayNearProtect();
    289331        }
    290332        else if (this->action_ == Action::ATTACK)
    291333        {   
    292 
     334            if (!this || !this->getControllableEntity())
     335                return;
    293336            if (!this->hasTarget())
    294337            {
     338                if (!this || !this->getControllableEntity())
     339                    return;
    295340                this->nextActionpoint();
     341                if (!this || !this->getControllableEntity())
     342                    return;
    296343                this->executeActionpoint();
    297344            }
     
    302349    void ActionpointController::setProtect (ControllableEntity* protect)
    303350    {
     351
    304352        this->protect_ = protect;
    305353    }
    306354    ControllableEntity* ActionpointController::getProtect ()
    307355    {
     356
    308357        return this->protect_;
    309358    }
     
    401450    void ActionpointController::setAction (Action::Value action, ControllableEntity* target)
    402451    {
     452        if (!this || !this->getControllableEntity())
     453            return;
    403454        this->action_ = action;
    404455        if (action == Action::FIGHT || action == Action::FIGHTALL || action == Action::ATTACK)
     
    415466    void ActionpointController::setAction (Action::Value action, const Vector3& target)
    416467    {
     468        if (!this || !this->getControllableEntity())
     469            return;
    417470        this->action_ = action;
    418471        if (action == Action::FLY)
     
    423476    void ActionpointController::setAction (Action::Value action, const Vector3& target,  const Quaternion& orient )
    424477    {
     478        if (!this || !this->getControllableEntity())
     479            return;
    425480        this->action_ = action;
    426481        if (action == Action::FLY)
     
    466521            return;
    467522        }
     523        if (!this || !this->getControllableEntity())
     524            return;
    468525        if (!this->bLoop_ && this->parsedActionpoints_.back().inLoop)
    469526        {
    470527            //MOVES all points that are in loop to a loop vector
    471528            this->fillLoop();
     529            if (!this || !this->getControllableEntity())
     530                return;
    472531            this->bLoop_ = true;
    473532            executeActionpoint();
    474533            return;
    475534        }
     535        if (!this || !this->getControllableEntity())
     536            return;
    476537        this->setAction (p.action);
    477538        if (!this || !this->getControllableEntity())
     
    487548                for (ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP)
    488549                {
     550                    if (!this || !this->getControllableEntity())
     551                        return;
    489552                    if (CommonController::getName(*itP) == targetName)
    490553                    {
     
    497560            {
    498561                this->setTargetPosition( p.position );
     562                if (!this || !this->getControllableEntity())
     563                    return;
    499564                if (this->squaredDistanceToTarget() <= this->squaredaccuracy_)
    500565                {
     566                    if (!this || !this->getControllableEntity())
     567                        return;
    501568                    this->nextActionpoint();
     569                    if (!this || !this->getControllableEntity())
     570                        return;
    502571                    this->executeActionpoint();
    503572                }
     
    553622                    if (CommonController::getName(*itP) == targetName)
    554623                    {
     624                        if (!this || !this->getControllableEntity())
     625                            return;
    555626                        this->setTarget (static_cast<ControllableEntity*>(*itP));
    556627                    }
     
    559630                {
    560631                    this->nextActionpoint();
     632                    if (!this || !this->getControllableEntity())
     633                        return;
    561634                    this->executeActionpoint();
    562635                }
     
    648721    void ActionpointController::takeActionpoints (const std::vector<Point>& vector, const std::vector<Point>& loop, bool b)
    649722    {
    650       this->parsedActionpoints_ = vector;
    651       this->loopActionpoints_ = loop;
    652       this->bLoop_ = b;
    653       this->bTakenOver_ = true;
     723        if (!this || !this->getControllableEntity())
     724            return;
     725        this->parsedActionpoints_ = vector;
     726        if (!this || !this->getControllableEntity())
     727            return;
     728        this->loopActionpoints_ = loop;
     729        this->bLoop_ = b;
     730        this->bTakenOver_ = true;
    654731    }
    655732    void ActionpointController::setClosestTarget()
     
    667744        for (ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP)
    668745        {
     746            if (!this || !this->getControllableEntity())
     747                return 0;
    669748            if ( CommonController::sameTeam (this->getControllableEntity(), static_cast<ControllableEntity*>(*itP), gt) )
    670749                continue;
     
    692771            if (!this->target_ || (this->target_ && CommonController::distance (this->getControllableEntity(), this->target_) > this->attackRange_))
    693772            {
     773                if (!this || !this->getControllableEntity())
     774                    return;
    694775                Pawn* newTarget = this->closestTarget();
    695776                if ( newTarget &&
Note: See TracChangeset for help on using the changeset viewer.