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/CommonController.cc

    r10885 r10946  
    99 *   modify it under the terms of the GNU General Public License
    1010 *   as published by the Free Software Foundation; either version 2
    11  *   of the License, or ( at your option )any later version.
     11 *   of the License, or (at your option)any later version.
    1212 *
    1313 *   This program is distributed in the hope that it will be useful,
     
    2828#include "controllers/CommonController.h"
    2929
    30 //stuff for sameTeam function
     30//here starts stuff for sameTeam function copied from FormationController
    3131#include "gametypes/TeamDeathmatch.h"
    3232#include "gametypes/Gametype.h"
     
    3939{
    4040
    41     RegisterClass( CommonController );
    42 
    43     CommonController::CommonController( Context* context ): Controller( context )
    44     {
    45         RegisterObject( CommonController );
     41    RegisterClass(CommonController);
     42
     43    CommonController::CommonController(Context* context): Controller(context)
     44    {
     45        RegisterObject(CommonController);
    4646    }
    4747    CommonController::~CommonController()
    4848    {
    49        
    50     }
    51 
    52     float CommonController::randomInRange( float a, float b )
     49        //no member variables - nothing to destroy
     50    }
     51    /**
     52    @brief
     53      PRE: a < b.
     54      returns random float between a and b.
     55    */
     56    float CommonController::randomInRange(float a, float b)
    5357    {
    5458        return a + rnd(1.0f) * (b - a);
    5559    }
    56     float CommonController::distance (ControllableEntity* entity1, ControllableEntity* entity2)
     60    /**
     61    @brief
     62      returns distance between two entities, if either is zero pointer, returns infinity
     63    */   
     64    float CommonController::distance (const ControllableEntity* entity1, const ControllableEntity* entity2)
    5765    {
    5866        if (!entity1 || !entity2)
    5967            return std::numeric_limits<float>::infinity();
    60         return ( entity1->getPosition() - entity2->getPosition() ).length();
    61     }
     68        return (entity1->getPosition() - entity2->getPosition()).length();
     69    }
     70    /**
     71    @brief
     72      bad function from FormationController that returns true if both entities have same team
     73    */   
    6274    bool CommonController::sameTeam (ControllableEntity* entity1, ControllableEntity* entity2, Gametype* gametype)
    6375    {
     76        //uncomment following code if functions stops working due to being a hack
    6477        /*if (!entity1 || !entity2)
    6578            return false;
    6679        return entity1->getTeam() == entity2->getTeam();*/
     80        if (!entity1 || !entity2)
     81            return false;
    6782        if (entity1 == entity2)
    6883            return true;
     
    161176                team2 = dynamic->getParty(entity2->getPlayer());
    162177
    163             if (team1 ==-1 ||team2 ==-1 ) {return false;}
     178            if (team1 ==-1 ||team2 ==-1) {return false;}
    164179            else if (team1 == dynamic->chaser && team2 != dynamic->chaser) {return false;}
    165180            else if (team1 == dynamic->piggy && team2 == dynamic->chaser) {return false;}
     
    170185        return (team1 == team2 && team1 != -1);
    171186    }
    172     bool CommonController::isLooking( ControllableEntity* entityThatLooks, ControllableEntity* entityBeingLookedAt, float angle )
    173     {
    174         if ( !entityThatLooks || !entityBeingLookedAt )
     187    /**
     188    @brief
     189      returns true if entityThatLooks does look at entityBeingLookeAt with a tolerance of angle.
     190    */   
     191    bool CommonController::isLooking(const ControllableEntity* entityThatLooks, const ControllableEntity* entityBeingLookedAt, float angle)
     192    {
     193        if (!entityThatLooks || !entityBeingLookedAt)
    175194            return false;
    176         return ( getAngle( entityThatLooks ->getPosition() ,
     195        return (getAngle(entityThatLooks ->getPosition() ,
    177196            entityThatLooks->getOrientation()  * WorldEntity::FRONT,
    178             entityBeingLookedAt->getWorldPosition() ) < angle );
    179     }
    180     std::string CommonController::getName(Pawn* entity)
     197            entityBeingLookedAt->getWorldPosition()) < angle);
     198    }
     199    /**
     200    @brief
     201      returns a name of a Pawn entity, if no name set, returns string representing address of the Pawn.
     202    */   
     203    std::string CommonController::getName(const Pawn* entity)
    181204    {
    182205        std::string name = entity->getName();
Note: See TracChangeset for help on using the changeset viewer.