Changeset 3049 for code/trunk/src/orxonox/objects/controllers
- Timestamp:
- May 25, 2009, 3:26:43 AM (16 years ago)
- Location:
- code/trunk/src/orxonox/objects/controllers
- Files:
-
- 4 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/orxonox/objects/controllers/AIController.cc
r2896 r3049 108 108 109 109 if (this->bHasTargetPosition_) 110 this->moveToTargetPosition( dt);110 this->moveToTargetPosition(); 111 111 112 if (this->getControllableEntity() && this->bShooting_ && this->isCloseAtTarget( 500) && this->isLookingAtTarget(Ogre::Math::PI / 20.0))112 if (this->getControllableEntity() && this->bShooting_ && this->isCloseAtTarget(1000) && this->isLookingAtTarget(Ogre::Math::PI / 20.0)) 113 113 this->getControllableEntity()->fire(WeaponMode::fire); 114 114 -
code/trunk/src/orxonox/objects/controllers/ArtificialController.cc
r2662 r3049 34 34 #include "objects/worldentities/pawns/Pawn.h" 35 35 36 #include "objects/gametypes/TeamDeathmatch.h" 37 #include "objects/controllers/WaypointPatrolController.h" 38 36 39 namespace orxonox 37 40 { … … 50 53 } 51 54 52 void ArtificialController::moveTo TargetPosition(float dt)55 void ArtificialController::moveToPosition(const Vector3& target) 53 56 { 54 57 if (!this->getControllableEntity()) 55 58 return; 56 59 57 Vector2 coord = get2DViewdirection(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, t his->targetPosition_);58 float distance = (t his->targetPosition_- this->getControllableEntity()->getPosition()).length();60 Vector2 coord = get2DViewdirection(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, target); 61 float distance = (target - this->getControllableEntity()->getPosition()).length(); 59 62 60 63 if (this->target_ || distance > 10) … … 71 74 } 72 75 76 void ArtificialController::moveToTargetPosition() 77 { 78 this->moveToPosition(this->targetPosition_); 79 } 80 81 void ArtificialController::setTargetPosition(const Vector3& target) 82 { 83 this->targetPosition_ = target; 84 this->bHasTargetPosition_ = true; 85 } 86 73 87 void ArtificialController::searchRandomTargetPosition() 74 88 { … … 77 91 } 78 92 93 void ArtificialController::setTarget(Pawn* target) 94 { 95 this->target_ = target; 96 97 if (target) 98 this->targetPosition_ = target->getPosition(); 99 } 100 79 101 void ArtificialController::searchNewTarget() 80 102 { … … 87 109 for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it) 88 110 { 89 // if (it->getTeamNr() != this->getTeamNr()) 111 if (ArtificialController::sameTeam(this->getControllableEntity(), static_cast<ControllableEntity*>(*it), this->getGametype())) 112 continue; 113 90 114 if (static_cast<ControllableEntity*>(*it) != this->getControllableEntity()) 91 115 { … … 147 171 } 148 172 } 173 174 bool ArtificialController::sameTeam(ControllableEntity* entity1, ControllableEntity* entity2, Gametype* gametype) 175 { 176 if (entity1 == entity2) 177 return true; 178 179 int team1 = -1; 180 int team2 = -1; 181 182 if (entity1->getXMLController()) 183 { 184 WaypointPatrolController* wpc = dynamic_cast<WaypointPatrolController*>(entity1->getXMLController()); 185 if (wpc) 186 team1 = wpc->getTeam(); 187 } 188 if (entity2->getXMLController()) 189 { 190 WaypointPatrolController* wpc = dynamic_cast<WaypointPatrolController*>(entity2->getXMLController()); 191 if (wpc) 192 team2 = wpc->getTeam(); 193 } 194 195 TeamDeathmatch* tdm = dynamic_cast<TeamDeathmatch*>(gametype); 196 if (tdm) 197 { 198 if (entity1->getPlayer()) 199 team1 = tdm->getTeam(entity1->getPlayer()); 200 201 if (entity2->getPlayer()) 202 team2 = tdm->getTeam(entity2->getPlayer()); 203 } 204 205 return (team1 == team2 && team1 != -1); 206 } 149 207 } -
code/trunk/src/orxonox/objects/controllers/ArtificialController.h
r2662 r3049 47 47 48 48 protected: 49 void moveToTargetPosition(float dt); 49 void moveToPosition(const Vector3& target); 50 void moveToTargetPosition(); 51 52 void setTargetPosition(const Vector3& target); 50 53 void searchRandomTargetPosition(); 54 55 void setTarget(Pawn* target); 51 56 void searchNewTarget(); 52 57 void forgetTarget(); … … 55 60 bool isCloseAtTarget(float distance) const; 56 61 bool isLookingAtTarget(float angle) const; 62 63 static bool sameTeam(ControllableEntity* entity1, ControllableEntity* entity2, Gametype* gametype); // hack 57 64 58 65 bool bHasTargetPosition_; -
code/trunk/src/orxonox/objects/controllers/CMakeLists.txt
r2839 r3049 5 5 AIController.cc 6 6 ScriptController.cc 7 WaypointController.cc 8 WaypointPatrolController.cc 7 9 PongAI.cc 8 10 )
Note: See TracChangeset
for help on using the changeset viewer.