- Timestamp:
- Jan 31, 2015, 5:31:23 PM (10 years ago)
- Location:
- code/branches/presentationFS14/src/modules/objects/controllers
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/presentationFS14/src/modules/objects/controllers/TeamTargetProxy.cc
r10072 r10215 33 33 namespace orxonox 34 34 { 35 35 RegisterClass(TeamTargetProxy); 36 36 37 37 /** … … 42 42 The context 43 43 */ 44 45 46 44 TeamTargetProxy::TeamTargetProxy(Context* context) : FormationController(context) 45 { 46 RegisterObject(TeamTargetProxy); 47 47 48 49 48 this->once_ = false; 49 } 50 50 51 51 /** … … 53 53 Destructor. Nothing to see here. 54 54 */ 55 56 57 55 TeamTargetProxy::~TeamTargetProxy() 56 { 57 } 58 58 59 59 /** … … 63 63 That's all there is. 64 64 */ 65 66 67 68 65 void TeamTargetProxy::tick(float dt) 66 { 67 if (!this->isActive() || !this->getControllableEntity()) 68 return; 69 69 70 70 ControllableEntity* parent = orxonox_cast<ControllableEntity*> (this->getControllableEntity()->getParent()); … … 102 102 } 103 103 } 104 104 } 105 105 } -
code/branches/presentationFS14/src/modules/objects/controllers/TeamTargetProxy.h
r10072 r10215 35 35 namespace orxonox 36 36 { 37 38 39 37 /** 38 @brief 39 A controller, that just copies the team and the target of a parent for itself and it's controllable entity. 40 40 41 42 43 44 45 46 47 48 49 50 51 41 Useful for following (and similar) situations: (-> means attached to) 42 turret (rotates) -> some kind of turret base (looks nice) -> spaceship (flies around) 43 The turret has a controller that wants to copy the spaceship's target and team. In this case it doesn't work though, 44 because the turret isn't directly attached to the spaceship. Here's where this controller comes in. Drawback: the base 45 has to be controllable and ticks every second (performance?) 46 */ 47 class _OrxonoxExport TeamTargetProxy : public FormationController, public Tickable 48 { 49 public: 50 TeamTargetProxy(Context* context); 51 virtual ~TeamTargetProxy(); 52 52 53 53 virtual void tick(float dt); 54 54 55 56 57 55 private: 56 bool once_; //!< Flag for executing code in the tick function only once. 57 }; 58 58 } 59 59 -
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 } -
code/branches/presentationFS14/src/modules/objects/controllers/TurretController.h
r10072 r10215 39 39 namespace orxonox 40 40 { 41 42 43 41 /** 42 @brief 43 Controller for turrets. Chooses a target, and makes the turret aim/shoot at it. 44 44 45 46 47 48 49 50 51 45 The controllableEntity gets casted to Turret, so this controller won't work for anything else. 46 */ 47 class _OrxonoxExport TurretController : public ArtificialController, public Tickable 48 { 49 public: 50 TurretController(Context* context); 51 virtual ~TurretController(); 52 52 53 53 virtual void tick(float dt); 54 54 55 55 private: 56 56 57 58 59 57 void searchTarget(); 58 bool isLookingAtTargetNew(float angle) const; 59 float targetScore(Pawn* pawn, float distance) const; 60 60 61 62 61 bool once_; //!< Flag for executing code in the tick function only once. 62 }; 63 63 } 64 64
Note: See TracChangeset
for help on using the changeset viewer.