- Timestamp:
- Dec 7, 2015, 4:06:37 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/campaignHS15/src/orxonox/controllers/CommonController.cc
r10885 r10946 9 9 * modify it under the terms of the GNU General Public License 10 10 * 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. 12 12 * 13 13 * This program is distributed in the hope that it will be useful, … … 28 28 #include "controllers/CommonController.h" 29 29 30 // stuff for sameTeam function30 //here starts stuff for sameTeam function copied from FormationController 31 31 #include "gametypes/TeamDeathmatch.h" 32 32 #include "gametypes/Gametype.h" … … 39 39 { 40 40 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); 46 46 } 47 47 CommonController::~CommonController() 48 48 { 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) 53 57 { 54 58 return a + rnd(1.0f) * (b - a); 55 59 } 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) 57 65 { 58 66 if (!entity1 || !entity2) 59 67 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 */ 62 74 bool CommonController::sameTeam (ControllableEntity* entity1, ControllableEntity* entity2, Gametype* gametype) 63 75 { 76 //uncomment following code if functions stops working due to being a hack 64 77 /*if (!entity1 || !entity2) 65 78 return false; 66 79 return entity1->getTeam() == entity2->getTeam();*/ 80 if (!entity1 || !entity2) 81 return false; 67 82 if (entity1 == entity2) 68 83 return true; … … 161 176 team2 = dynamic->getParty(entity2->getPlayer()); 162 177 163 if (team1 ==-1 ||team2 ==-1 178 if (team1 ==-1 ||team2 ==-1) {return false;} 164 179 else if (team1 == dynamic->chaser && team2 != dynamic->chaser) {return false;} 165 180 else if (team1 == dynamic->piggy && team2 == dynamic->chaser) {return false;} … … 170 185 return (team1 == team2 && team1 != -1); 171 186 } 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) 175 194 return false; 176 return ( getAngle(entityThatLooks ->getPosition() ,195 return (getAngle(entityThatLooks ->getPosition() , 177 196 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) 181 204 { 182 205 std::string name = entity->getName();
Note: See TracChangeset
for help on using the changeset viewer.