Changeset 9526 for code/trunk/src
- Timestamp:
- Feb 19, 2013, 10:25:42 AM (12 years ago)
- Location:
- code/trunk
- Files:
-
- 19 edited
- 6 copied
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
-
code/trunk/src/modules/gametypes/CMakeLists.txt
r9016 r9526 5 5 OldSpaceRace.cc 6 6 OldRaceCheckPoint.cc 7 SpaceRaceBot.cc 8 SpaceRaceController.cc 7 9 ) 8 10 -
code/trunk/src/modules/gametypes/GametypesPrereqs.h
r9016 r9526 67 67 class SpaceRace; 68 68 class OldSpaceRace; 69 class SpaceRaceManager; 70 class SpaceRaceBot; 71 class SpaceRaceController; 69 72 } 70 73 -
code/trunk/src/modules/gametypes/RaceCheckPoint.cc
r9348 r9526 43 43 CreateFactory(RaceCheckPoint); 44 44 45 RaceCheckPoint::RaceCheckPoint(BaseObject* creator): DistanceMultiTrigger(creator), RadarViewable(creator, static_cast<WorldEntity*>(this)) 45 RaceCheckPoint::RaceCheckPoint(BaseObject* creator) : DistanceMultiTrigger(creator), 46 RadarViewable(creator, static_cast<WorldEntity*> (this)) 46 47 { 47 48 RegisterObject(RaceCheckPoint); 48 49 49 this->setDistance(100); 50 50 this->setBeaconMode("off"); … … 60 60 this->bIsLast_ = false; 61 61 this->timeLimit_ = 0; 62 this->player_ = NULL; 63 } 64 65 66 RaceCheckPoint::~RaceCheckPoint() 67 { 68 } 62 //this->players_ = vector<PlayerInfo*>(); 63 64 myPosition_= this->getPosition(); //eingefuegt 65 //orxout(user_status) << "test" << std::endl; 66 } 67 68 RaceCheckPoint::~RaceCheckPoint() 69 { 70 71 } 69 72 70 73 void RaceCheckPoint::XMLPort(Element& xmlelement, XMLPort::Mode mode) … … 86 89 ControllableEntity* entity = orxonox_cast<ControllableEntity*>(originator); 87 90 if (entity) 88 this->player _ = entity->getPlayer();91 this->players_.push_back(entity->getPlayer()); 89 92 } 90 93 } … … 95 98 if (this->timeLimit_ != 0) 96 99 { 97 std::string message = 98 100 std::string message = "You have " + multi_cast<std::string>(this->timeLimit_) 101 + " seconds to reach the check point " + multi_cast<std::string>(this->checkpointIndex_ + 1); 99 102 this->getGametype()->getGametypeInfo()->sendAnnounceMessage(message); 100 103 ChatManager::message(message); … … 102 105 } 103 106 107 //Must not be called before setNextCheckpointsAsVector3 at least once has been called 108 void RaceCheckPoint::setNextVirtualCheckpointsAsVector3(const Vector3& checkpoints){ 109 /*std::set<int> lastcheckpoints=this->nextCheckpoints_; 110 nextCheckpoints_.clear(); 111 std::set<int>::iterator it = lastcheckpoints.begin(); 112 if(checkpoints.x<-1){ 113 virtualToRealCheckPoints_.insert(std::pair<int,int>(checkpoints.x,(*it))); 114 it++; 115 } 116 if(checkpoints.x!=-1) 117 this->nextCheckpoints_.insert(static_cast<int>(checkpoints.x + 0.5)); // the red number has the type double and for the cast (to int) is added 0.5 so that the cast works correctly 118 119 if(checkpoints.y<-1){ 120 virtualToRealCheckPoints_.insert(std::pair<int,int>(checkpoints.y,(*it))); 121 it++; 122 } 123 if(checkpoints.y!=-1) 124 this->nextCheckpoints_.insert(static_cast<int>(checkpoints.y + 0.5)); 125 126 if(checkpoints.z<-1){ 127 virtualToRealCheckPoints_.insert(std::pair<int,int>(checkpoints.z,(*it))); 128 it++; 129 } 130 if(checkpoints.z!=-1) 131 this->nextCheckpoints_.insert(static_cast<int>(checkpoints.z + 0.5));*/ 132 nextCheckpointsVirtual_.clear(); 133 if(checkpoints.x!=-1) 134 nextCheckpointsVirtual_.insert(checkpoints.x); 135 if(checkpoints.y!=-1) 136 nextCheckpointsVirtual_.insert(checkpoints.y); 137 if(checkpoints.z!=-1) 138 nextCheckpointsVirtual_.insert(checkpoints.z); 139 } 140 104 141 void RaceCheckPoint::setNextCheckpointsAsVector3(const Vector3& checkpoints) 105 142 { … … 107 144 108 145 if (checkpoints.x > -1) 109 this->nextCheckpoints_.insert(static_cast<int>(checkpoints.x + 0.5));146 this->nextCheckpoints_.insert(static_cast<int>(checkpoints.x + 0.5)); // the red number has the type double and for the cast (to int) is added 0.5 so that the cast works correctly 110 147 if (checkpoints.y > -1) 111 148 this->nextCheckpoints_.insert(static_cast<int>(checkpoints.y + 0.5)); 112 149 if (checkpoints.z > -1) 113 this->nextCheckpoints_.insert(static_cast<int>(checkpoints.z + 0.5)); 114 } 115 116 Vector3 RaceCheckPoint::getNextCheckpointsAsVector3() const 150 this->nextCheckpoints_.insert(static_cast<int>(checkpoints.z + 0.5)); 151 152 this->nextCheckpointsVirtual_=nextCheckpoints_; 153 } 154 155 PlayerInfo* RaceCheckPoint::getPlayer(unsigned int clientID) const 156 { 157 if (players_.size() > 0) 158 { 159 for (int i = 0; i < players_.size(); i++) 160 { 161 if (this->players_[i]->getClientID() == clientID) 162 { 163 return players_[i]; 164 } 165 } 166 } 167 return NULL; 168 } 169 170 bool RaceCheckPoint::playerWasHere(PlayerInfo* player) const 171 { 172 if (players_.size() > 0) 173 { 174 for (int i = 0; i < players_.size(); i++) 175 { 176 if (this->players_[i] == player) 177 { 178 return true; 179 } 180 } 181 } 182 return false; 183 } 184 185 Vector3 RaceCheckPoint::getNextCheckpointsAsVector3() 186 { 187 Vector3 checkpoints(-1,-1,-1); int count=0; 188 for (std::set<int>::iterator it= nextCheckpoints_.begin();it!=nextCheckpoints_.end(); it++ ){ 189 switch (count) 190 { 191 case 0: checkpoints.x = static_cast<Ogre::Real>(*it); break; 192 case 1: checkpoints.y = static_cast<Ogre::Real>(*it); break; 193 case 2: checkpoints.z = static_cast<Ogre::Real>(*it); break; 194 } 195 ++count; 196 } 197 return checkpoints; 198 //= getVirtualNextCheckpointsAsVector3(); 199 int j[3]; 200 j[0]=changeVirtualToRealCheckPoint(checkpoints.x); 201 j[1]=changeVirtualToRealCheckPoint(checkpoints.y); 202 j[2]=changeVirtualToRealCheckPoint(checkpoints.z); 203 204 205 return Vector3(j[0],j[1],j[2]); 206 207 208 } 209 210 int RaceCheckPoint::changeVirtualToRealCheckPoint(int checkpointID) { 211 int temp=checkpointID; 212 while(temp<-1){ 213 temp = this->virtualToRealCheckPoints_[temp]; 214 } 215 return temp; 216 } 217 218 219 Vector3 RaceCheckPoint::getVirtualNextCheckpointsAsVector3() const 117 220 { 118 221 Vector3 checkpoints = Vector3(-1, -1, -1); 119 222 120 223 size_t count = 0; 121 for (std::set<int>::iterator it = this->nextCheckpoints _.begin(); it != this->nextCheckpoints_.end(); ++it)224 for (std::set<int>::iterator it = this->nextCheckpointsVirtual_.begin(); it != this->nextCheckpointsVirtual_.end(); ++it) 122 225 { 123 226 switch (count) -
code/trunk/src/modules/gametypes/RaceCheckPoint.h
r9263 r9526 37 37 { 38 38 /** 39 @brief 40 The RaceCheckPoint class enables the creation of a check point to use in a SpaceRace level. 41 Don't forget to control the indexes of your check points and to set one last check point 42 */ 43 class _GametypesExport RaceCheckPoint : public DistanceMultiTrigger, public RadarViewable 39 @brief 40 The RaceCheckPoint class enables the creation of a check point to use in a SpaceRace level. 41 Don't forget to control the indexes of your check points and to set one last check point 42 */ 43 class _GametypesExport RaceCheckPoint: public DistanceMultiTrigger, 44 public RadarViewable 44 45 { 45 46 public: … … 50 51 51 52 inline void setCheckpointIndex(int checkpointIndex) 52 { this->checkpointIndex_ = checkpointIndex; } 53 { 54 this->checkpointIndex_ = checkpointIndex; 55 } 53 56 inline int getCheckpointIndex() const 54 { return this->checkpointIndex_; } 57 { 58 return this->checkpointIndex_; 59 } 55 60 56 61 void setNextCheckpointsAsVector3(const Vector3& checkpoints); 57 Vector3 getNextCheckpointsAsVector3() const; 58 const std::set<int>& getNextCheckpoints() const 59 { return this->nextCheckpoints_; } 62 Vector3 getNextCheckpointsAsVector3(); 63 Vector3 getVirtualNextCheckpointsAsVector3() const; 64 void setNextVirtualCheckpointsAsVector3(const Vector3& checkpoints); 65 int changeVirtualToRealCheckPoint(int); 60 66 67 const std::set<int>& getVirtualNextCheckpoints() const 68 { 69 return this->nextCheckpointsVirtual_; 70 } 71 72 const std::set<int>& getNextCheckpoints() 73 { 74 return nextCheckpoints_; 75 std::set<int> temp; 76 std::set<int> temp2=getVirtualNextCheckpoints(); 77 for (std::set<int>::iterator it = temp2.begin(); it!=temp2.end(); ++it){ 78 temp.insert(changeVirtualToRealCheckPoint((*it))); 79 } 80 return temp; 81 } 61 82 inline void setLast(bool isLast) 62 { this->bIsLast_ = isLast; } 83 { 84 this->bIsLast_ = isLast; 85 } 63 86 inline bool isLast() const 64 { return this->bIsLast_; } 87 { 88 return this->bIsLast_; 89 } 65 90 66 91 virtual void setTimelimit(float timeLimit); 67 92 inline float getTimeLimit() const 68 { return this->timeLimit_; } 93 { 94 return this->timeLimit_; 95 } 69 96 70 inline PlayerInfo* getPlayer() const 71 { return this->player_; } 97 PlayerInfo* getPlayer(unsigned int clientID) const; 98 99 bool playerWasHere(PlayerInfo* ) const; 100 72 101 inline void resetPlayer() 73 { this->player_ = NULL; } 102 { 103 this->players_.clear(); 104 } 74 105 75 106 protected: 107 76 108 virtual void fire(bool bIsTriggered, BaseObject* originator); 77 109 78 110 inline const WorldEntity* getWorldEntity() const 79 { return this; } 111 { 112 return this; 113 } 80 114 81 115 private: 82 int checkpointIndex_; ///< The index of this check point. The race starts with the check point with the index 0 116 117 int checkpointIndex_; ///< The index of this check point. The race starts with the check point with the index 0 83 118 std::set<int> nextCheckpoints_; ///< the indexes of the next check points 84 bool bIsLast_; ///< True if this check point is the last of the level. There can be only one last check point for each level and there must be a last check point in the level. 85 float timeLimit_; ///< The time limit (from the start of the level) to reach this check point. If the check point is reached after this time, the game ends and the player looses. 86 PlayerInfo* player_; ///< The player that reached the checkpoint 119 bool bIsLast_; ///< True if this check point is the last of the level. There can be only one last check point for each level and there must be a last check point in the level. 120 float timeLimit_; ///< The time limit (from the start of the level) to reach this check point. If the check point is reached after this time, the game ends and the player looses. 121 std::vector<PlayerInfo*> players_; ///< The player that reached the checkpoint 122 Vector3 myPosition_; 123 std::set<int> nextCheckpointsVirtual_; 124 std::map<int,int> virtualToRealCheckPoints_; // if virtualChepoint was inserted the original can be reconstructed 87 125 }; 88 126 } -
code/trunk/src/modules/gametypes/SpaceRace.cc
r9348 r9526 35 35 #include "util/Convert.h" 36 36 #include "util/Math.h" 37 37 #include "SpaceRaceBot.h" 38 38 #include "items/Engine.h" 39 39 … … 46 46 RegisterObject(SpaceRace); 47 47 48 this->botclass_ = Class(SpaceRaceBot);//ClassByString("") 48 49 this->cantMove_ = false; 49 50 this->bTimeIsUp_ = false; -
code/trunk/src/modules/gametypes/SpaceRaceManager.cc
r9348 r9526 38 38 #include "util/Math.h" 39 39 40 41 42 40 namespace orxonox 43 41 { 44 42 CreateFactory(SpaceRaceManager); 45 43 46 SpaceRaceManager::SpaceRaceManager(BaseObject* creator) : BaseObject(creator) 44 SpaceRaceManager::SpaceRaceManager(BaseObject* creator) : 45 BaseObject(creator) 47 46 { 48 47 RegisterObject(SpaceRaceManager); 49 48 this->race_ = orxonox_cast<SpaceRace*>(this->getGametype().get()); 49 assert(race_); 50 //amountOfPlayers=(race_->getPlayers()).size(); 50 51 this->firstcheckpointvisible_ = false; 51 52 } … … 54 55 { 55 56 for (size_t i = 0; i < this->checkpoints_.size(); ++i) 56 57 this->checkpoints_[i]->destroy(); 57 58 } 58 59 … … 61 62 SUPER(SpaceRaceManager, XMLPort, xmlelement, mode); 62 63 63 XMLPortObject(SpaceRaceManager, RaceCheckPoint, "checkpoints", addCheckpoint, getCheckpoint, 64 XMLPortObject(SpaceRaceManager, RaceCheckPoint, "checkpoints", addCheckpoint, getCheckpoint, xmlelement, mode); 64 65 } 65 66 … … 67 68 { 68 69 SUPER(SpaceRaceManager,tick,dt); 70 71 this->players_ = this->race_->getPlayers(); 69 72 70 73 if (this->checkpoints_[0] != NULL && !this->firstcheckpointvisible_) … … 74 77 } 75 78 76 for ( size_t i = 0; i < this->checkpoints_.size(); ++i)79 for ( std::map< PlayerInfo*, Player>::iterator it = players_.begin(); it != players_.end(); ++it) 77 80 { 78 if (this->checkpoints_[i]->getPlayer() != NULL) 79 this->checkpointReached(this->checkpoints_[i], this->checkpoints_[i]->getPlayer()); 81 82 for (size_t i = 0; i < this->checkpoints_.size(); ++i) 83 { 84 if (this->checkpoints_[i]->playerWasHere(it->first)){ 85 this->checkpointReached(this->checkpoints_[i], it->first /*this->checkpoints_[i]->getPlayer()*/); 86 } 87 } 80 88 } 89 81 90 } 82 91 … … 89 98 { 90 99 if (index < this->checkpoints_.size()) 91 100 return this->checkpoints_[index]; 92 101 else 93 return 0; 102 return 0; 103 } 104 105 std::vector<RaceCheckPoint*> SpaceRaceManager::getAllCheckpoints() 106 { 107 return checkpoints_; 94 108 } 95 109 96 110 /** 97 98 */111 @brief Returns the checkpoint with the given checkpoint-index (@see RaceCheckPoint::getCheckpointIndex). 112 */ 99 113 RaceCheckPoint* SpaceRaceManager::findCheckpoint(int index) const 100 114 { 101 115 for (size_t i = 0; i < this->checkpoints_.size(); ++i) 102 103 116 if (this->checkpoints_[i]->getCheckpointIndex() == index) 117 return this->checkpoints_[i]; 104 118 return 0; 105 119 } … … 107 121 bool SpaceRaceManager::reachedValidCheckpoint(RaceCheckPoint* oldCheckpoint, RaceCheckPoint* newCheckpoint, PlayerInfo* player) const 108 122 { 109 if (oldCheckpoint )123 if (oldCheckpoint != NULL) 110 124 { 111 125 // the player already visited an old checkpoint; see which checkpoints are possible now 112 126 const std::set<int>& possibleCheckpoints = oldCheckpoint->getNextCheckpoints(); 113 127 for (std::set<int>::const_iterator it = possibleCheckpoints.begin(); it != possibleCheckpoints.end(); ++it) 114 115 128 if (this->findCheckpoint(*it) == newCheckpoint) 129 return true; 116 130 return false; 117 131 } … … 128 142 assert(gametype); 129 143 if (!gametype) 130 144 return; 131 145 132 RaceCheckPoint* oldCheckpoint = gametype->getCheckpointReached(player); 146 RaceCheckPoint* oldCheckpoint = gametype->getCheckpointReached(player); // returns the last from player reached checkpoint 133 147 134 148 if (this->reachedValidCheckpoint(oldCheckpoint, newCheckpoint, player)) … … 152 166 // adjust the radarvisibility 153 167 gametype->newCheckpointReached(newCheckpoint, player); 154 this->updateRadarVisibility(oldCheckpoint, newCheckpoint); 168 if(player->isHumanPlayer()) 169 this->updateRadarVisibility(oldCheckpoint, newCheckpoint); 155 170 } 156 171 } 157 172 158 newCheckpoint->resetPlayer();173 // newCheckpoint->resetPlayer(); loescht playerpointer TODO: check if problems occur 159 174 } 160 175 … … 165 180 const std::set<int>& oldVisible = oldCheckpoint->getNextCheckpoints(); 166 181 for (std::set<int>::const_iterator it = oldVisible.begin(); it != oldVisible.end(); ++it) 167 182 this->findCheckpoint(*it)->setRadarVisibility(false); 168 183 } 169 184 … … 174 189 const std::set<int>& newVisible = newCheckpoint->getNextCheckpoints(); 175 190 for (std::set<int>::const_iterator it = newVisible.begin(); it != newVisible.end(); ++it) 176 191 this->findCheckpoint(*it)->setRadarVisibility(true); 177 192 } 178 193 } -
code/trunk/src/modules/gametypes/SpaceRaceManager.h
r9348 r9526 67 67 void checkpointReached(RaceCheckPoint* newCheckpoint, PlayerInfo* player); 68 68 69 std::vector<RaceCheckPoint*> getAllCheckpoints(); 70 69 71 void tick(float dt); 70 72 … … 76 78 std::vector<RaceCheckPoint*> checkpoints_; 77 79 bool firstcheckpointvisible_; ///< true if the first check point is visible. 80 SpaceRace* race_; // needed to get the players 81 //int amountOfPlayers; 82 std::map<PlayerInfo*, Player> players_; 78 83 }; 79 84 } -
code/trunk/src/modules/objects/CMakeLists.txt
r8706 r9526 5 5 Script.cc 6 6 SpaceBoundaries.cc 7 Turret.cc 7 8 ) 8 9 -
code/trunk/src/modules/objects/ObjectsPrereqs.h
r8706 r9526 73 73 class Script; 74 74 class SpaceBoundaries; 75 class Turret; 75 76 76 77 // collisionshapes -
code/trunk/src/modules/overlays/OverlaysPrereqs.h
r9348 r9526 91 91 class HUDBoostBar; 92 92 class HUDTimer; 93 class HUDAimAssistant; 93 94 class KillMessage; 94 95 class LastManStandingInfos; -
code/trunk/src/modules/overlays/hud/HUDNavigation.cc
r9348 r9526 37 37 #include <OgrePanelOverlayElement.h> 38 38 39 #include <typeinfo> 40 39 41 #include "util/Math.h" 40 42 #include "util/Convert.h" 43 #include "core/command/ConsoleCommand.h" 41 44 #include "core/CoreIncludes.h" 42 45 #include "core/XMLPort.h" … … 55 58 namespace orxonox 56 59 { 57 bool compareDistance(std::pair<RadarViewable*, unsigned int> a, std::pair<RadarViewable*, unsigned int> b) 60 61 SetConsoleCommand("HUDNavigation","selectClosest", &HUDNavigation::selectClosestTarget).addShortcut().keybindMode(KeybindMode::OnPress); 62 SetConsoleCommand("HUDNavigation","selectNext", &HUDNavigation::selectNextTarget).addShortcut().keybindMode(KeybindMode::OnPress); 63 64 static bool compareDistance(std::pair<RadarViewable*, unsigned int> a, 65 std::pair<RadarViewable*, unsigned int> b) 58 66 { 59 67 return a.second < b.second; 60 68 } 61 62 69 CreateFactory ( HUDNavigation ); 63 70 64 HUDNavigation::HUDNavigation(BaseObject* creator) : OrxonoxOverlay(creator) 65 { 66 RegisterObject(HUDNavigation); 67 this->setConfigValues(); 71 HUDNavigation* HUDNavigation::localHUD_s = 0; 72 73 HUDNavigation::HUDNavigation(BaseObject* creator) : 74 OrxonoxOverlay(creator) 75 { 76 RegisterObject(HUDNavigation) 77 ; this->setConfigValues(); 68 78 69 79 // Set default values 70 80 this->setFont("Monofur"); 71 81 this->setTextSize(0.05f); 72 this->setNavMarkerSize(0.05f); 82 this->setNavMarkerSize(0.03f); 83 this->setAimMarkerSize(0.02f); 84 73 85 this->setDetectionLimit(10000.0f); 86 this->currentMunitionSpeed_ = 2500.0f; 87 88 this->closestTarget_ = true; 89 this->nextTarget_ = false; 90 HUDNavigation::localHUD_s = this; 74 91 } 75 92 … … 79 96 { 80 97 for (std::map<RadarViewable*, ObjectInfo>::iterator it = this->activeObjectList_.begin(); it != this->activeObjectList_.end();) 81 98 removeObject((it++)->first); 82 99 } 83 100 this->sortedObjectList_.clear(); … … 94 111 SUPER(HUDNavigation, XMLPort, xmlelement, mode); 95 112 96 XMLPortParam(HUDNavigation, "font", setFont, getFont,xmlelement, mode);97 XMLPortParam(HUDNavigation, "textSize", setTextSize, getTextSize,xmlelement, mode);98 XMLPortParam(HUDNavigation, "navMarkerSize", setNavMarkerSize, getNavMarkerSize,xmlelement, mode);113 XMLPortParam(HUDNavigation, "font", setFont, getFont, xmlelement, mode); 114 XMLPortParam(HUDNavigation, "textSize", setTextSize, getTextSize, xmlelement, mode); 115 XMLPortParam(HUDNavigation, "navMarkerSize", setNavMarkerSize, getNavMarkerSize, xmlelement, mode); 99 116 XMLPortParam(HUDNavigation, "detectionLimit", setDetectionLimit, getDetectionLimit, xmlelement, mode); 117 XMLPortParam(HUDNavigation, "aimMarkerSize", setAimMarkerSize, getAimMarkerSize, xmlelement, mode); 100 118 } 101 119 … … 112 130 { 113 131 if (it->second.text_ != NULL) 114 132 it->second.text_->setFontName(this->fontName_); 115 133 } 116 134 } … … 132 150 { 133 151 if (it->second.text_) 134 152 it->second.text_->setCharHeight(size); 135 153 } 136 154 } … … 144 162 { 145 163 if (dist < 600) 146 164 dist = 600; 147 165 return this->getActualSize().x * 900 * this->navMarkerSize_ / dist; 148 166 } … … 151 169 { 152 170 if (dist < 600) 153 171 dist = 600; 154 172 return this->getActualSize().y * 900 * this->navMarkerSize_ / dist; 155 173 } … … 161 179 Camera* cam = CameraManager::getInstance().getActiveCamera(); 162 180 if (cam == NULL) 163 181 return; 164 182 const Matrix4& camTransform = cam->getOgreCamera()->getProjectionMatrix() * cam->getOgreCamera()->getViewMatrix(); 165 183 166 167 184 for (std::list<std::pair<RadarViewable*, unsigned int> >::iterator listIt = this->sortedObjectList_.begin(); listIt != this->sortedObjectList_.end(); ++listIt) 168 185 listIt->second = (int)((listIt->first->getRVWorldPosition() - HumanController::getLocalControllerSingleton()->getControllableEntity()->getWorldPosition()).length() + 0.5f); 169 186 170 187 this->sortedObjectList_.sort(compareDistance); … … 172 189 unsigned int markerCount = 0; 173 190 bool closeEnough = false; // only display objects that are close enough to be relevant for the player 191 192 // if the selected object doesn't exist any more or is now out of range select the closest object 193 std::map<RadarViewable*, ObjectInfo>::iterator selectedActiveObject = this->activeObjectList_.find(this->selectedTarget_); 194 if(selectedActiveObject == this->activeObjectList_.end()) 195 { 196 this->closestTarget_ = true; 197 } 198 else if(this->detectionLimit_ < (this->selectedTarget_->getRVWorldPosition() - HumanController::getLocalControllerSingleton()->getControllableEntity()->getWorldPosition()).length() + 0.5f) 199 { 200 this->closestTarget_ = true; 201 selectedActiveObject->second.selected_ = false; 202 } 203 204 bool nextHasToBeSelected = false; 174 205 175 206 for (std::list<std::pair<RadarViewable*, unsigned int> >::iterator listIt = this->sortedObjectList_.begin(); listIt != this->sortedObjectList_.end(); ++markerCount, ++listIt) … … 178 209 closeEnough = listIt->second < this->detectionLimit_; 179 210 // display radarviewables on HUD if the marker limit and max-distance is not exceeded 180 if (markerCount < this->markerLimit_ && (closeEnough || 211 if (markerCount < this->markerLimit_ && (closeEnough || this->detectionLimit_ < 0)) 181 212 { 182 213 // Get Distance to HumanController and save it in the TextAreaOverlayElement. … … 196 227 textLength = it->first->getRadarName().size() * it->second.text_->getCharHeight() * 0.3f; 197 228 } 229 230 // select the object that aim-assistant indicates 231 if(this->closestTarget_) 232 // select the closest object 233 { 234 if(listIt == this->sortedObjectList_.begin()) 235 { 236 it->second.selected_ = true; 237 this->selectedTarget_ = it->first; 238 } 239 else if(it->second.selected_) 240 { 241 it->second.selected_ = false; 242 } 243 244 } 245 else if(this->nextTarget_) 246 // select the next object in sortedObjectList 247 { 248 if(nextHasToBeSelected){ 249 it->second.selected_ = true; 250 this->selectedTarget_ = it->first; 251 nextHasToBeSelected = false; 252 } 253 else if(it->second.selected_) 254 { 255 nextHasToBeSelected = true; 256 it->second.selected_ = false; 257 258 // check if there's a next object 259 listIt++; 260 if(listIt != this->sortedObjectList_.end()) 261 { 262 // and if the marker limit and max-distance are not exceeded for it 263 if (markerCount + 1 >= this->markerLimit_ || 264 (listIt->second > this->detectionLimit_ && detectionLimit_ >= 0)) 265 { 266 // otherwise select the closest object 267 this->activeObjectList_.find(this->sortedObjectList_.begin()->first)->second.selected_ = true; 268 this->selectedTarget_ = it->first; 269 nextHasToBeSelected = false; 270 } 271 } 272 listIt--; 273 } 274 } 275 198 276 199 277 // Transform to screen coordinates … … 222 300 it->second.panel_->setMaterialName(TextureGenerator::getMaterialName("arrows.png", it->first->getRadarObjectColour())); 223 301 it->second.wasOutOfView_ = true; 302 it->second.target_->hide(); 224 303 } 225 304 … … 284 363 it->second.panel_->setMaterialName(TextureGenerator::getMaterialName("tdc.png", it->first->getRadarObjectColour())); 285 364 it->second.panel_->setDimensions(this->navMarkerSize_ * this->getActualSize().x, this->navMarkerSize_ * this->getActualSize().y); 365 it->second.target_->setDimensions(this->aimMarkerSize_ * this->getActualSize().x, this->aimMarkerSize_ * this->getActualSize().y); 286 366 it->second.wasOutOfView_ = false; 287 367 } … … 295 375 it->second.text_->setLeft((pos.x + 1.0f + it->second.panel_->getWidth()) * 0.5f); 296 376 it->second.text_->setTop((-pos.y + 1.0f + it->second.panel_->getHeight()) * 0.5f); 297 } 298 299 // Make sure the overlays are shown 300 it->second.panel_->show(); 301 it->second.text_->show(); 377 378 // Make sure the overlays are shown 379 it->second.panel_->show(); 380 it->second.text_->show(); 381 382 // Target marker 383 const Pawn* pawn = dynamic_cast<const Pawn*>(it->first->getWorldEntity()); 384 /* Pawn* humanPawn = HumanController::getLocalControllerEntityAsPawn();*/ 385 if(!it->second.selected_ 386 || it->first->getRVVelocity().squaredLength() == 0 387 || pawn == NULL 388 /* TODO : improve getTeam in such a way that it works 389 * || humanPawn == NULL 390 * || pawn->getTeam() == humanPawn->getTeam()*/) 391 { 392 // don't show marker for not selected enemies nor if the selected doesn't move 393 it->second.target_->hide(); 394 } 395 else // object is selected and moves 396 { 397 // get the aim position 398 Vector3* targetPos = this->toAimPosition(it->first); 399 // Transform to screen coordinates 400 Vector3 screenPos = camTransform * (*targetPos); 401 // Check if the target marker is in view too 402 if(screenPos.z > 1 || screenPos.x < -1.0 || screenPos.x > 1.0 403 || screenPos.y < -1.0 || screenPos.y > 1.0) 404 { 405 it->second.target_->hide(); 406 } 407 else 408 { 409 it->second.target_->setLeft((screenPos.x + 1.0f - it->second.target_->getWidth()) * 0.5f); 410 it->second.target_->setTop((-screenPos.y + 1.0f - it->second.target_->getHeight()) * 0.5f); 411 it->second.target_->show(); 412 } 413 delete targetPos; 414 } 415 416 } 302 417 } 303 418 else // do not display on HUD 419 304 420 { 305 421 it->second.panel_->hide(); 306 422 it->second.text_->hide(); 423 it->second.target_->hide(); 307 424 } 308 425 } 426 427 this->closestTarget_ = false; 428 this->nextTarget_ = false; 309 429 } 310 430 311 431 /** Overridden method of OrxonoxOverlay. 312 @details313 314 315 */432 @details 433 Usually the entire overlay scales with scale(). 434 Here we obviously have to adjust this. 435 */ 316 436 void HUDNavigation::sizeChanged() 317 437 { … … 326 446 if (it->second.text_ != NULL) 327 447 it->second.text_->setCharHeight(it->second.text_->getCharHeight() * yScale); 448 if (it->second.target_ != NULL) 449 it->second.target_->setDimensions(this->aimMarkerSize_ * xScale, this->aimMarkerSize_ * yScale); 328 450 } 329 451 } … … 332 454 { 333 455 if (showObject(object) == false) 334 456 return; 335 457 336 458 if (this->activeObjectList_.size() >= this->markerLimit_) 337 338 459 if (object == NULL) 460 return; 339 461 340 462 // Object hasn't been added yet (we know that) … … 349 471 // Create arrow/marker 350 472 Ogre::PanelOverlayElement* panel = static_cast<Ogre::PanelOverlayElement*>( Ogre::OverlayManager::getSingleton() 351 473 .createOverlayElement("Panel", "HUDNavigation_navMarker_" + getUniqueNumberString())); 352 474 //panel->setMaterialName("Orxonox/NavTDC"); 353 475 panel->setMaterialName(TextureGenerator::getMaterialName("tdc.png", object->getRadarObjectColour())); … … 355 477 //panel->setColour(object->getRadarObjectColour()); 356 478 479 // Create target marker 480 Ogre::PanelOverlayElement* target = static_cast<Ogre::PanelOverlayElement*>(Ogre::OverlayManager::getSingleton() 481 .createOverlayElement("Panel", "HUDNavigation_targetMarker_" + getUniqueNumberString())); 482 target->setMaterialName(TextureGenerator::getMaterialName("target.png", object->getRadarObjectColour())); 483 target->setDimensions(this->aimMarkerSize_ * xScale, this->aimMarkerSize_ * yScale); 484 485 // Create text 357 486 Ogre::TextAreaOverlayElement* text = static_cast<Ogre::TextAreaOverlayElement*>( Ogre::OverlayManager::getSingleton() 358 487 .createOverlayElement("TextArea", "HUDNavigation_navText_" + getUniqueNumberString())); 359 488 text->setFontName(this->fontName_); 360 489 text->setCharHeight(text->getCharHeight() * yScale); … … 362 491 363 492 panel->hide(); 493 target->hide(); 364 494 text->hide(); 365 495 366 ObjectInfo tempStruct = {panel, text, false /*, TODO: initialize wasOutOfView_ */}; 496 ObjectInfo tempStruct = 497 { panel, target, text, false, false, false}; 367 498 this->activeObjectList_[object] = tempStruct; 368 499 369 500 this->background_->addChild(panel); 501 this->background_->addChild(target); 370 502 this->background_->addChild(text); 371 503 … … 381 513 // Detach overlays 382 514 this->background_->removeChild(it->second.panel_->getName()); 515 this->background_->removeChild(it->second.target_->getName()); 383 516 this->background_->removeChild(it->second.text_->getName()); 384 517 // Properly destroy the overlay elements (do not use delete!) 385 518 Ogre::OverlayManager::getSingleton().destroyOverlayElement(it->second.panel_); 519 Ogre::OverlayManager::getSingleton().destroyOverlayElement(it->second.target_); 386 520 Ogre::OverlayManager::getSingleton().destroyOverlayElement(it->second.text_); 387 521 // Remove from the list … … 409 543 { 410 544 if (rv == orxonox_cast<RadarViewable*>(this->getOwner())) 411 545 return false; 412 546 assert(rv->getWorldEntity()); 413 547 if (rv->getWorldEntity()->isVisible() == false || rv->getRadarVisibility() == false) 414 548 return false; 415 549 return true; 416 550 } … … 422 556 { 423 557 if (!(*it)->isHumanShip_) 424 this->addObject(*it); 558 this->addObject(*it); 559 } 560 } 561 562 Vector3* HUDNavigation::toAimPosition(RadarViewable* target) const 563 { 564 Vector3 wePosition = HumanController::getLocalControllerSingleton()->getControllableEntity()->getWorldPosition(); 565 Vector3 targetPosition = target->getRVWorldPosition(); 566 Vector3 targetSpeed = target->getRVVelocity(); 567 Vector3 relativePosition = targetPosition - wePosition; //Vector from attacker to target 568 569 float p_half = relativePosition.dotProduct(targetSpeed)/(targetSpeed.squaredLength() - this->currentMunitionSpeed_ * this->currentMunitionSpeed_); 570 float time1 = -p_half + sqrt(p_half * p_half - relativePosition.squaredLength()/(targetSpeed.squaredLength() - this->currentMunitionSpeed_ * this->currentMunitionSpeed_)); 571 572 Vector3* result = new Vector3(targetPosition + targetSpeed * time1); 573 return result; 574 } 575 576 void HUDNavigation::selectClosestTarget() 577 { 578 if(HUDNavigation::localHUD_s) 579 { 580 HUDNavigation::localHUD_s->closestTarget_ = true; 581 } 582 } 583 584 void HUDNavigation::selectNextTarget() 585 { 586 if(HUDNavigation::localHUD_s) 587 { 588 HUDNavigation::localHUD_s->nextTarget_ = true; 425 589 } 426 590 } -
code/trunk/src/modules/overlays/hud/HUDNavigation.h
r9348 r9526 71 71 { return this->markerLimit_; } 72 72 73 static void selectClosestTarget(); 74 static void selectNextTarget(); 75 73 76 private: 74 77 struct ObjectInfo 75 78 { 76 79 Ogre::PanelOverlayElement* panel_; 80 Ogre::PanelOverlayElement* target_; 77 81 Ogre::TextAreaOverlayElement* text_; 78 82 bool outOfView_; 79 83 bool wasOutOfView_; 84 bool selected_; 80 85 }; 81 86 … … 85 90 inline void setNavMarkerSize(float size) 86 91 { 87 navMarkerSize_ = size;92 this->navMarkerSize_ = size; 88 93 this->sizeChanged(); 89 94 } 90 95 inline float getNavMarkerSize() const 91 96 { return navMarkerSize_; } 97 inline void setAimMarkerSize(float size) 98 { 99 this->aimMarkerSize_ = size; 100 this->sizeChanged(); 101 } 102 inline float getAimMarkerSize() const 103 { return aimMarkerSize_; } 92 104 inline void setDetectionLimit(float limit) 93 105 { this->detectionLimit_ = limit; } … … 104 116 float getArrowSizeY(int dist) const; 105 117 118 Vector3* toAimPosition(RadarViewable* target) const; 119 106 120 std::map<RadarViewable*, ObjectInfo> activeObjectList_; 107 121 std::list<std::pair<RadarViewable*, unsigned int> > sortedObjectList_; 108 122 109 123 float navMarkerSize_; 124 float aimMarkerSize_; 110 125 std::string fontName_; 111 126 float textSize_; 112 127 bool showDistance_; 128 129 RadarViewable* selectedTarget_; 130 131 bool closestTarget_; 132 bool nextTarget_; 133 134 static HUDNavigation* localHUD_s; //!< This is used as a filter. Only the local HUD should be influenced by the static Console Command functions. 135 136 137 float currentMunitionSpeed_; 113 138 114 139 unsigned int markerLimit_; -
code/trunk/src/modules/portals/PortalEndPoint.cc
r8767 r9526 28 28 29 29 #include "PortalEndPoint.h" 30 #include "portals/PortalLink.h" 30 31 31 32 #include <ctime> … … 35 36 36 37 #include "worldentities/MobileEntity.h" 37 38 38 #include "objects/triggers/MultiTriggerContainer.h" 39 39 40 #include " portals/PortalLink.h"40 #include "sound/WorldSound.h" 41 41 42 42 namespace orxonox … … 59 59 this->setRadarObjectShape(RadarViewable::Dot); 60 60 this->setRadarVisibility(true); 61 if( GameMode::isMaster() ) 62 { 63 this->portalSound_ = new WorldSound(this); 64 this->portalSound_->setLooping(false); 65 this->attach(this->portalSound_); 66 this->portalSound_->setSource("sounds/Weapon_HsW01.ogg"); //TODO: change sound file 67 } 61 68 } 62 69 … … 158 165 entity->rotate(this->getWorldOrientation()); 159 166 entity->setVelocity(this->getWorldOrientation() * entity->getVelocity()); 167 //play Sound 168 if( this->portalSound_ && !(this->portalSound_->isPlaying())) 169 { 170 this->portalSound_->play(); 171 } 160 172 } 161 173 -
code/trunk/src/modules/portals/PortalEndPoint.h
r8767 r9526 115 115 std::map<MobileEntity *, time_t> jumpOutTimes_; //!< Stores the time at which a certain MobileEntity @ref jumpOut "jumped out" of this PortalEndPoint 116 116 std::set<MobileEntity *> recentlyJumpedOut_; //!< Stores the entities witch recently jumped out of this PortalEndPoint and haven't left the activation radius yet. This is needed in order to prevent them from beeing pulled into the PortalEndPoint they have just come out of. 117 118 WorldSound* portalSound_; 117 119 }; 118 120 -
code/trunk/src/modules/weapons/weaponmodes/HsW01.cc
r8855 r9526 61 61 this->delay_ = 0.0f; 62 62 this->setMunitionName("LaserMunition"); 63 this->mesh_ = "laserbeam.mesh"; 64 this->sound_ = "sounds/Weapon_HsW01.ogg"; 65 63 66 64 67 this->delayTimer_.setTimer(1.0f, false, createExecutor(createFunctor(&HsW01::shot, this))); 65 68 this->delayTimer_.stopTimer(); 66 69 67 this->setDefaultSound( "sounds/Weapon_HsW01.ogg");70 this->setDefaultSound(this->sound_); 68 71 } 69 72 … … 78 81 XMLPortParam(HsW01, "delay", setDelay, getDelay, xmlelement, mode); 79 82 XMLPortParam(HsW01, "material", setMaterial, getMaterial, xmlelement, mode); 83 XMLPortParam(HsW01, "projectileMesh", setMesh, getMesh, xmlelement, mode); 84 XMLPortParam(HsW01, "sound", setSound, getSound, xmlelement, mode); 80 85 } 81 86 … … 108 113 Projectile* projectile = new Projectile(this); 109 114 Model* model = new Model(projectile); 110 model->setMeshSource( "laserbeam.mesh");115 model->setMeshSource(mesh_); 111 116 model->setCastShadows(false); 112 117 projectile->attach(model); -
code/trunk/src/modules/weapons/weaponmodes/HsW01.h
r8855 r9526 61 61 private: 62 62 /** 63 @brief Set the mesh. 64 @param mesh The mesh name. 65 */ 66 void setMesh(const std::string& mesh) 67 { this->mesh_ = mesh; } 68 69 /** 70 @brief Get the mesh. 71 @return Returns the mesh name. 72 */ 73 const std::string& getMesh() const 74 { return this->mesh_; } 75 76 /** 77 @brief Set the sound. 78 @param mesh The Sound name. 79 */ 80 void setSound(const std::string& sound) 81 { this->sound_ = sound; } 82 83 /** 84 @brief Get the sound. 85 @return Returns the sound name. 86 */ 87 const std::string& getSound() const 88 { return this->sound_; } 89 90 /** 63 91 @brief Set the material. 64 92 @param material The material name. … … 85 113 86 114 std::string material_; //!< The material. 115 std::string mesh_; //!< The mesh. 116 std::string sound_; //!< The sound. 117 118 119 87 120 float speed_; //!< The speed of the fired projectile. 88 121 float delay_; //!< The firing delay. -
code/trunk/src/orxonox/interfaces/RadarViewable.cc
r9257 r9526 102 102 } 103 103 104 Vector3 RadarViewable::getRVVelocity() const 105 { 106 const WorldEntity* object = this->getWorldEntity(); 107 validate(object); 108 return object->getVelocity(); 109 } 110 104 111 void RadarViewable::validate(const WorldEntity* object) const 105 112 { -
code/trunk/src/orxonox/interfaces/RadarViewable.h
r9348 r9526 113 113 const Vector3& getRVWorldPosition() const; 114 114 Vector3 getRVOrientedVelocity() const; 115 Vector3 getRVVelocity() const; 115 116 116 117 inline void setRadarObjectShape(Shape shape)
Note: See TracChangeset
for help on using the changeset viewer.