Changeset 10215 for code/branches/presentationFS14/src/modules/objects/controllers/TurretController.cc
- Timestamp:
- Jan 31, 2015, 5:31:23 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/presentationFS14/src/modules/objects/controllers/TurretController.cc
r10072 r10215 33 33 namespace orxonox 34 34 { 35 35 RegisterClass(TurretController); 36 36 37 37 /** … … 42 42 The context 43 43 */ 44 45 46 47 48 49 50 44 TurretController::TurretController(Context* context) : ArtificialController(context) 45 { 46 RegisterObject(TurretController); 47 48 this->once_ = false; 49 50 } 51 51 52 52 /** … … 54 54 Destructor. Nothing to see here. 55 55 */ 56 57 58 59 56 TurretController::~TurretController() 57 { 58 59 } 60 60 61 61 /** … … 69 69 The function that scores the pawns. 70 70 */ 71 72 71 void TurretController::searchTarget() 72 { 73 73 Turret* turret = orxonox_cast<Turret*>(this->getControllableEntity()); 74 74 … … 76 76 if(this->target_ && turret->isInRange(target_) != -1.f && !FormationController::sameTeam(turret, this->target_, this->getGametype())) 77 77 { 78 78 return; 79 79 } 80 80 else 81 81 { 82 83 82 this->forgetTarget(); 83 turret->setTarget(0); 84 84 } 85 85 … … 88 88 if(parent) 89 89 { 90 91 92 93 94 95 96 90 Pawn* parenttarget = orxonox_cast<Pawn*>(parent->getTarget()); 91 if(parenttarget && turret->isInRange(parenttarget)) 92 { 93 this->setTarget(parenttarget); 94 turret->setTarget(parenttarget); 95 return; 96 } 97 97 } 98 98 … … 101 101 Pawn* minScorePawn = 0; 102 102 103 for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it != ObjectList<Pawn>::end(); ++it)104 { 105 103 for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it != ObjectList<Pawn>::end(); ++it) 104 { 105 Pawn* entity = orxonox_cast<Pawn*>(*it); 106 106 if (!entity || FormationController::sameTeam(this->getControllableEntity(), entity, this->getGametype())) 107 107 continue; 108 108 tempScore = turret->isInRange(entity); 109 109 if(tempScore != -1.f) 110 110 { 111 112 113 114 115 116 } 117 111 if(tempScore < minScore) 112 { 113 minScore = tempScore; 114 minScorePawn = entity; 115 } 116 } 117 } 118 118 this->setTarget(minScorePawn); 119 119 turret->setTarget(minScorePawn); 120 120 } 121 121 122 122 /** … … 124 124 Tests, if the turret is looking at the target, with a specified tolerance 125 125 126 127 128 129 126 This uses the world position as opposed to the local position in the old version. 127 128 @param angle 129 The tolerance, in radians 130 130 */ 131 131 bool TurretController::isLookingAtTargetNew(float angle) const … … 140 140 The more health and distance a pawn has, the higher the score. This means lower equals better. 141 141 142 143 144 145 146 142 @param pawn 143 The pawn to score 144 145 @param distance 146 The distance. Can be squared or normed, doesn't matter as long as all are treated the same. 147 147 */ 148 149 150 151 152 153 /** 154 155 156 157 158 159 */ 160 161 162 163 148 float TurretController::targetScore(Pawn* pawn, float distance) const 149 { 150 return pawn->getHealth()/pawn->getMaxHealth() + distance; 151 } 152 153 /** 154 @brief 155 Does all the controlling of the turret. 156 157 If the turret has a parent, copies the team from there, if it's not already set. 158 Other actions are: Search a target. If a target has been found, aim and shoot at it. 159 */ 160 void TurretController::tick(float dt) 161 { 162 if (!this->isActive() || !this->getControllableEntity()) 163 return; 164 164 165 165 … … 171 171 172 172 if(!this->once_) 173 173 this->once_ = true; 174 174 175 175 //Teams aren't set immediately, after creation, so we have to check every tick... … … 188 188 } 189 189 190 191 192 193 194 195 196 197 198 199 200 201 190 this->searchTarget(); 191 if(this->target_) 192 { 193 Turret* turret = orxonox_cast<Turret*> (this->getControllableEntity()); 194 this->aimAtTarget(); 195 turret->aimAtPosition(target_->getWorldPosition()); 196 if(this->isLookingAtTargetNew(Degree(5).valueRadians())) 197 { 198 this->getControllableEntity()->fire(0); 199 } 200 } 201 } 202 202 }
Note: See TracChangeset
for help on using the changeset viewer.