Changeset 7163 for code/trunk/src/orxonox
- Timestamp:
- Aug 11, 2010, 8:55:13 AM (14 years ago)
- Location:
- code/trunk
- Files:
-
- 2 deleted
- 87 edited
- 18 copied
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
-
code/trunk/src/orxonox/CMakeLists.txt
r6711 r7163 32 32 PlayerManager.cc 33 33 Radar.cc 34 ChatHistory.cc 35 ChatInputHandler.cc 36 # Test.cc 34 37 COMPILATION_BEGIN SceneCompilation.cc 35 38 CameraManager.cc … … 55 58 FIND_HEADER_FILES 56 59 TOLUA_FILES 60 ChatInputHandler.h 57 61 LevelManager.h 58 62 MoodManager.h 59 63 controllers/HumanController.h 60 interfaces/PickupCarrier.h 64 interfaces/Pickupable.h 65 infos/PlayerInfo.h 61 66 sound/SoundManager.h 62 DEFINE_SYMBOL63 "ORXONOX_SHARED_BUILD"64 67 PCH_FILE 65 68 OrxonoxPrecompiledHeaders.h … … 75 78 ${VORBIS_LIBRARY} 76 79 ${OGG_LIBRARY} 77 tinyxml ++_orxonox78 tolua ++_orxonox80 tinyxml_orxonox 81 tolua_orxonox 79 82 bullet_orxonox 80 83 util -
code/trunk/src/orxonox/Level.cc
r6746 r7163 49 49 RegisterObject(Level); 50 50 51 51 52 this->registerVariables(); 52 53 this->xmlfilename_ = this->getFilename(); … … 73 74 XMLPortParam(Level, "gametype", setGametypeString, getGametypeString, xmlelement, mode).defaultValues("Gametype"); 74 75 76 XMLPortObject(Level, MeshLodInformation, "lodinformation", addLodInfo, getLodInfo, xmlelement, mode); 75 77 XMLPortObjectExtended(Level, BaseObject, "", addObject, getObject, xmlelement, mode, true, false); 76 78 } 77 79 78 80 void Level::registerVariables() 79 81 { 80 registerVariable(this->xmlfilename_, VariableDirection::ToClient, new NetworkCallback<Level>(this, &Level::networkcallback_applyXMLFile)); 81 registerVariable(this->name_, VariableDirection::ToClient, new NetworkCallback<Level>(this, &Level::changedName)); 82 registerVariable(this->description_, VariableDirection::ToClient); 82 registerVariable(this->xmlfilename_, VariableDirection::ToClient, new NetworkCallback<Level>(this, &Level::networkcallback_applyXMLFile)); 83 registerVariable(this->name_, VariableDirection::ToClient, new NetworkCallback<Level>(this, &Level::changedName)); 84 registerVariable(this->description_, VariableDirection::ToClient); 85 registerVariable(this->networkTemplateNames_, VariableDirection::ToClient, new NetworkCallback<Level>(this, &Level::networkCallbackTemplatesChanged)); 83 86 } 84 87 … … 95 98 96 99 Loader::open(this->xmlfile_); 100 } 101 102 void Level::networkCallbackTemplatesChanged() 103 { 104 for( std::set<std::string>::iterator it = this->networkTemplateNames_.begin(); it!=this->networkTemplateNames_.end(); ++it ) 105 { 106 assert(Template::getTemplate(*it)); 107 Template::getTemplate(*it)->applyOn(this); 108 } 97 109 } 98 110 … … 125 137 this->objects_.push_back(object); 126 138 object->setGametype(this->getGametype()); 139 object->setLevel(this); 127 140 } 128 141 … … 136 149 ++i; 137 150 } 151 return 0; 152 } 153 154 void Level::addLodInfo(MeshLodInformation* lodInformation) 155 { 156 std::string meshName = lodInformation->getMeshName(); 157 // this->lodInformation_.insert(std::make_pair(meshName,lodInformation)); 158 if( this->lodInformation_.find(meshName) != this->lodInformation_.end()) 159 CCOUT(4) << "replacing lod information for " << meshName << endl; 160 this->lodInformation_[meshName] = lodInformation; 161 } 162 163 MeshLodInformation* Level::getLodInfo(std::string meshName) const 164 { 165 if(this->lodInformation_.find(meshName)!=this->lodInformation_.end()) 166 return this->lodInformation_.find(meshName)->second; 167 138 168 return 0; 139 169 } -
code/trunk/src/orxonox/Level.h
r5929 r7163 34 34 #include <list> 35 35 #include <string> 36 #include <map> 36 37 #include "core/BaseObject.h" 37 38 #include "network/synchronisable/Synchronisable.h" 39 #include "graphics/MeshLodInformation.h" 38 40 39 41 namespace orxonox … … 46 48 47 49 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 48 void registerVariables();49 50 50 51 inline void setDescription(const std::string& description) … … 56 57 void playerLeft(PlayerInfo* player); 57 58 59 MeshLodInformation* getLodInfo(std::string meshName) const; 60 61 58 62 private: 63 void registerVariables(); 59 64 void addObject(BaseObject* object); 60 65 BaseObject* getObject(unsigned int index) const; 66 67 void addLodInfo(MeshLodInformation* object); 68 void networkCallbackTemplatesChanged(); 69 // const MeshLodInformation* getLodInfo(std::string meshName) const; 70 // MeshLodInformation* getLodInfo(unsigned int index) const; 61 71 62 72 void setGametypeString(const std::string& gametype); … … 66 76 void networkcallback_applyXMLFile(); 67 77 68 std::string description_; 69 std::string gametype_; 70 std::string xmlfilename_; 71 XMLFile* xmlfile_; 72 std::list<BaseObject*> objects_; 78 std::string description_; 79 std::string gametype_; 80 std::string xmlfilename_; 81 XMLFile* xmlfile_; 82 std::list<BaseObject*> objects_; 83 std::map<std::string,MeshLodInformation*> lodInformation_; 73 84 }; 74 85 } -
code/trunk/src/orxonox/LevelManager.cc
r6501 r7163 70 70 void LevelManager::requestActivity(Level* level) 71 71 { 72 assert( std::find(this->levels_s.begin(), this->levels_s.end(), level)==this->levels_s.end() ); 73 if( std::find(this->levels_s.begin(), this->levels_s.end(), level)!=this->levels_s.end() ) 74 return; // level is already in list 72 75 this->levels_s.push_back(level); 73 76 if (this->levels_s.size() == 1) -
code/trunk/src/orxonox/Main.cc
r6105 r7163 40 40 #include "core/LuaState.h" 41 41 #include "ToluaBindOrxonox.h" 42 #include "ToluaBindNetwork.h" 42 43 #include "Main.h" 43 44 … … 51 52 52 53 DeclareToluaInterface(Orxonox); 54 DeclareToluaInterface(Network); 53 55 54 56 namespace orxonox -
code/trunk/src/orxonox/MoodManager.cc
r6417 r7163 32 32 #include "core/CoreIncludes.h" 33 33 #include "core/ScopedSingletonManager.h" 34 #include "core/Resource.h" 34 35 35 36 namespace orxonox … … 37 38 ManageScopedSingleton(MoodManager, ScopeID::Root, false); 38 39 40 // Note: I'm (Kevin Young) not entirely sure whether that's good code style: 41 const std::string MoodManager::defaultMood_ = "default"; 42 39 43 MoodManager::MoodManager() 40 44 { 41 45 RegisterRootObject(MoodManager); 42 46 this->setConfigValues(); 47 48 // Need to use a variable to store old data because ResetConfigValues() doesn't seem to work. 49 oldMood_ = MoodManager::defaultMood_; 50 51 // Checking for the existence of the folder for the default mood 52 const std::string& path = "ambient/" + MoodManager::defaultMood_ + "/."; 53 if (!Resource::exists(path)) 54 { 55 // TODO: Non-fatal error handling (non-critical resource missing) 56 COUT(2) << "Mood Warning: Folder for default mood (" << MoodManager::defaultMood_ << ") does not exist!" << std::endl; 57 } 43 58 } 44 59 45 60 void MoodManager::setConfigValues() 46 61 { 47 SetConfigValue(mood_, "default")62 SetConfigValue(mood_, MoodManager::defaultMood_) 48 63 .description("Sets the mood for the current level.") 49 64 .callback(this, &MoodManager::checkMoodValidity); 50 65 } 51 66 52 /** Sets the mood 53 @note 54 TODO: Inform dependent classes of mood change 55 */ 67 /** Set a new mood 68 */ 56 69 void MoodManager::setMood(const std::string& mood) 57 70 { 71 oldMood_ = mood_; 58 72 ModifyConfigValue(mood_, set, mood); 59 73 } … … 61 75 void MoodManager::checkMoodValidity() 62 76 { 63 // TODO: Insert new moods here & make this generic 64 if (mood_ != "default" && mood_ != "dnb") 77 // Generic mood validation 78 const std::string& path = "ambient/" + mood_ + "/."; 79 if (!Resource::exists(path)) 65 80 { 66 ResetConfigValue(mood_); 81 COUT(3) << "Mood " << mood_ << " does not exist. Will not change." << std::endl; 82 this->setMood(oldMood_); 67 83 } 68 84 else -
code/trunk/src/orxonox/MoodManager.h
r6417 r7163 38 38 namespace orxonox 39 39 { 40 /* 41 @brief 42 The MoodListener class is aware of a change in themes and directs that info to dependent classes. 43 */ 40 44 class _OrxonoxExport MoodListener : virtual public OrxonoxClass 41 45 { … … 55 59 }; 56 60 61 /* 62 @brief 63 The MoodManager class serves to allow for different musical themes in the game. 64 */ 57 65 class _OrxonoxExport MoodManager : public Singleton<MoodManager>, public OrxonoxClass 58 66 { … … 74 82 // config values 75 83 std::string mood_; 84 std::string oldMood_; 85 static const std::string defaultMood_; 76 86 77 87 static MoodManager* singletonPtr_s; -
code/trunk/src/orxonox/OrxonoxPrereqs.h
r6524 r7163 82 82 class ArtificialController; 83 83 class Controller; 84 class DroneController; 84 85 class HumanController; 85 86 class ScriptController; … … 90 91 class Asteroids; 91 92 class Deathmatch; 93 class Dynamicmatch; 92 94 class Gametype; 93 95 class TeamBaseMatch; … … 135 137 class OrxonoxOverlay; 136 138 class OverlayGroup; 137 139 138 140 // pickup 139 141 class PickupIdentifier; … … 161 163 class CameraPosition; 162 164 class ControllableEntity; 165 class Drone; 163 166 class EffectContainer; 164 167 class ExplosionChunk; -
code/trunk/src/orxonox/Radar.cc
r6417 r7163 77 77 } 78 78 79 void Radar::addRadarObject(RadarViewable* rv) 80 { 81 assert( this->radarObjects_.find(rv) == this->radarObjects_.end() ); 82 this->radarObjects_.insert(rv); 83 // iterate through all radarlisteners and notify them 84 for (ObjectList<RadarListener>::iterator itListener = ObjectList<RadarListener>::begin(); itListener; ++itListener) 85 { 86 (*itListener)->addObject(rv); 87 } 88 } 89 90 void Radar::removeRadarObject(RadarViewable* rv) 91 { 92 assert( this->radarObjects_.find(rv) != this->radarObjects_.end() ); 93 this->radarObjects_.erase(rv); 94 // iterate through all radarlisteners and notify them 95 for (ObjectList<RadarListener>::iterator itListener = ObjectList<RadarListener>::begin(); itListener; ++itListener) 96 { 97 (*itListener)->removeObject(rv); 98 } 99 } 100 79 101 const RadarViewable* Radar::getFocus() 80 102 { … … 109 131 { 110 132 (*itListener)->radarTick(dt); 111 112 for (ObjectList<RadarViewable>::iterator itElement = ObjectList<RadarViewable>::begin(); itElement; ++itElement)113 {114 if ((*itElement)->getRadarVisibility())115 if ((*itListener)->getRadarSensitivity() > (*itElement)->getRadarObjectCamouflage())116 (*itListener)->displayObject(*itElement, *itElement == this->focus_);117 }118 133 } 119 134 } … … 188 203 } 189 204 } 205 206 void Radar::radarObjectChanged(RadarViewable* rv) 207 { 208 for (ObjectList<RadarListener>::iterator itListener = ObjectList<RadarListener>::begin(); itListener; ++itListener) 209 { 210 (*itListener)->objectChanged(rv); 211 } 212 } 190 213 } -
code/trunk/src/orxonox/Radar.h
r6417 r7163 38 38 39 39 #include <map> 40 #include <set> 40 41 #include <string> 41 42 … … 48 49 class _OrxonoxExport Radar : public Tickable 49 50 { 51 friend class RadarViewable; 50 52 public: 51 53 Radar(); … … 58 60 59 61 void listObjects() const; 62 const std::set<RadarViewable*>& getRadarObjects() const 63 { return this->radarObjects_; } 60 64 61 65 void releaseFocus(); … … 66 70 67 71 void updateFocus(); 72 void addRadarObject(RadarViewable* rv); 73 void removeRadarObject(RadarViewable* rv); 74 void radarObjectChanged(RadarViewable* rv); 68 75 69 76 ObjectListIterator<RadarViewable> itFocus_; 70 77 RadarViewable* focus_; 71 78 std::map<std::string, RadarViewable::Shape> objectTypes_; 79 std::set<RadarViewable*> radarObjects_; 72 80 int objectTypeCounter_; 73 81 }; -
code/trunk/src/orxonox/Scene.cc
r6417 r7163 47 47 #include "Radar.h" 48 48 #include "worldentities/WorldEntity.h" 49 #include "Level.h" 49 50 50 51 namespace orxonox … … 133 134 registerVariable(this->bHasPhysics_, VariableDirection::ToClient, new NetworkCallback<Scene>(this, &Scene::networkcallback_hasPhysics)); 134 135 registerVariable(this->bShadows_, VariableDirection::ToClient, new NetworkCallback<Scene>(this, &Scene::networkcallback_applyShadows)); 136 registerVariable(this->getLevel(), VariableDirection::ToClient, new NetworkCallback<Scene>(this, &Scene::changedLevel)); 135 137 } 136 138 -
code/trunk/src/orxonox/Test.cc
r6417 r7163 88 88 void Test::registerVariables() 89 89 { 90 registerVariable ( u1, VariableDirection::ToClient, new NetworkCallback<Test> ( this, &Test::checkU1 )); 91 registerVariable ( u2, VariableDirection::ToServer, new NetworkCallback<Test> ( this, &Test::checkU2 )); 92 registerVariable ( u3, Bidirectionality::ServerMaster, new NetworkCallback<Test> ( this, &Test::checkU3 ), true ); 93 registerVariable ( u4, Bidirectionality::ClientMaster, new NetworkCallback<Test> ( this, &Test::checkU4 ), true ); 90 registerVariable ( this->mySet_, VariableDirection::ToClient ); 91 92 // registerVariable ( u1, VariableDirection::ToClient, new NetworkCallback<Test> ( this, &Test::checkU1 )); 93 // registerVariable ( u2, VariableDirection::ToServer, new NetworkCallback<Test> ( this, &Test::checkU2 )); 94 // registerVariable ( u3, Bidirectionality::ServerMaster, new NetworkCallback<Test> ( this, &Test::checkU3 ), true ); 95 // registerVariable ( u4, Bidirectionality::ClientMaster, new NetworkCallback<Test> ( this, &Test::checkU4 ), true ); 94 96 95 registerVariable ( s1, VariableDirection::ToClient, new NetworkCallback<Test> ( this, &Test::checkS1 ));96 registerVariable ( s2, VariableDirection::ToServer, new NetworkCallback<Test> ( this, &Test::checkS2 ));97 registerVariable ( s3, Bidirectionality::ServerMaster, new NetworkCallback<Test> ( this, &Test::checkS3 ), true );98 registerVariable ( s4, Bidirectionality::ClientMaster, new NetworkCallback<Test> ( this, &Test::checkS4 ), true );97 // registerVariable ( s1, VariableDirection::ToClient, new NetworkCallback<Test> ( this, &Test::checkS1 )); 98 // registerVariable ( s2, VariableDirection::ToServer, new NetworkCallback<Test> ( this, &Test::checkS2 )); 99 // registerVariable ( s3, Bidirectionality::ServerMaster, new NetworkCallback<Test> ( this, &Test::checkS3 ), true ); 100 // registerVariable ( s4, Bidirectionality::ClientMaster, new NetworkCallback<Test> ( this, &Test::checkS4 ), true ); 99 101 100 registerVariable ( pointer_, VariableDirection::ToClient, new NetworkCallback<Test> ( this, &Test::printPointer ) );102 // registerVariable ( pointer_, VariableDirection::ToClient, new NetworkCallback<Test> ( this, &Test::printPointer ) ); 101 103 } 102 104 -
code/trunk/src/orxonox/Test.h
r6417 r7163 35 35 #include "tools/interfaces/Tickable.h" 36 36 37 #include <set> 37 38 38 39 typedef int TYPE; … … 49 50 50 51 void setConfigValues(); 51 void registerVariables();52 52 53 53 static void call(unsigned int clientID); … … 78 78 void printPointer(); 79 79 80 static void printV1(){ instance_-> checkU1(); }81 static void printV2(){ instance_-> checkU2(); }80 static void printV1(){ instance_->blub(); } 81 static void printV2(){ instance_->blub2(); } 82 82 static void printV3(){ instance_->checkU3(); } 83 83 static void printV4(){ instance_->checkU4(); } … … 86 86 87 87 private: 88 void registerVariables(); 89 88 90 UTYPE u1; 89 91 UTYPE u2; … … 97 99 98 100 Test* pointer_; 101 102 std::set<uint32_t> mySet_; 99 103 100 104 static Test* instance_; 105 106 void blub() 107 { mySet_.insert(2); } 108 109 void blub2() 110 { for( std::set<uint32_t>::iterator it=mySet_.begin(); it!=mySet_.end(); ++it ) COUT(0) << *it << endl; } 101 111 }; 102 112 } -
code/trunk/src/orxonox/collisionshapes/CollisionShape.h
r5781 r7163 45 45 46 46 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 47 void registerVariables();48 47 49 48 inline void setPosition(const Vector3& position) … … 88 87 89 88 private: 89 void registerVariables(); 90 90 91 Vector3 position_; 91 92 Quaternion orientation_; -
code/trunk/src/orxonox/controllers/AIController.cc
r5929 r7163 23 23 * Fabian 'x3n' Landau 24 24 * Co-authors: 25 * ...25 * Dominik Solenicki 26 26 * 27 27 */ … … 33 33 #include "core/Executor.h" 34 34 #include "worldentities/ControllableEntity.h" 35 #include "worldentities/pawns/Pawn.h" 35 36 36 37 namespace orxonox … … 56 57 float maxrand = 100.0f / ACTION_INTERVAL; 57 58 58 // search enemy 59 random = rnd(maxrand); 60 if (random < 15 && (!this->target_)) 61 this->searchNewTarget(); 62 63 // forget enemy 64 random = rnd(maxrand); 65 if (random < 5 && (this->target_)) 66 this->forgetTarget(); 67 68 // next enemy 69 random = rnd(maxrand); 70 if (random < 10 && (this->target_)) 71 this->searchNewTarget(); 72 73 // fly somewhere 74 random = rnd(maxrand); 75 if (random < 50 && (!this->bHasTargetPosition_ && !this->target_)) 76 this->searchRandomTargetPosition(); 77 78 // stop flying 79 random = rnd(maxrand); 80 if (random < 10 && (this->bHasTargetPosition_ && !this->target_)) 81 this->bHasTargetPosition_ = false; 82 83 // fly somewhere else 84 random = rnd(maxrand); 85 if (random < 30 && (this->bHasTargetPosition_ && !this->target_)) 86 this->searchRandomTargetPosition(); 87 88 // shoot 89 random = rnd(maxrand); 90 if (random < 75 && (this->target_ && !this->bShooting_)) 91 this->bShooting_ = true; 92 93 // stop shooting 94 random = rnd(maxrand); 95 if (random < 25 && (this->bShooting_)) 96 this->bShooting_ = false; 59 if (this->state_ == FREE) 60 { 61 62 if (this->formationFlight_) 63 { 64 // return to Master after being forced free 65 if (this->freedomCount_ == 1) 66 { 67 this->state_ = SLAVE; 68 this->freedomCount_ = 0; 69 } 70 71 random = rnd(maxrand); 72 if (random < 90 && (((!this->target_) || (random < 50 && this->target_)) && !this->forcedFree())) 73 this->searchNewMaster(); 74 } 75 76 // search enemy 77 random = rnd(maxrand); 78 if (random < 15 && (!this->target_)) 79 this->searchNewTarget(); 80 81 // forget enemy 82 random = rnd(maxrand); 83 if (random < 5 && (this->target_)) 84 this->forgetTarget(); 85 86 // next enemy 87 random = rnd(maxrand); 88 if (random < 10 && (this->target_)) 89 this->searchNewTarget(); 90 91 // fly somewhere 92 random = rnd(maxrand); 93 if (random < 50 && (!this->bHasTargetPosition_ && !this->target_)) 94 this->searchRandomTargetPosition(); 95 96 // stop flying 97 random = rnd(maxrand); 98 if (random < 10 && (this->bHasTargetPosition_ && !this->target_)) 99 this->bHasTargetPosition_ = false; 100 101 // fly somewhere else 102 random = rnd(maxrand); 103 if (random < 30 && (this->bHasTargetPosition_ && !this->target_)) 104 this->searchRandomTargetPosition(); 105 106 // shoot 107 random = rnd(maxrand); 108 if (!(this->passive_) && random < 75 && (this->target_ && !this->bShooting_)) 109 this->bShooting_ = true; 110 111 // stop shooting 112 random = rnd(maxrand); 113 if (random < 25 && (this->bShooting_)) 114 this->bShooting_ = false; 115 116 } 117 118 if (this->state_ == SLAVE) 119 { 120 121 } 122 123 if (this->state_ == MASTER) 124 { 125 126 127 this->commandSlaves(); 128 129 if (this->specificMasterAction_ != NONE) 130 this->specificMasterActionHold(); 131 132 else { 133 134 // make 180 degree turn - a specific Master Action 135 random = rnd(1000.0f); 136 if (random < 5) 137 this->turn180Init(); 138 139 // spin around - a specific Master Action 140 random = rnd(1000.0f); 141 if (random < 5) 142 this->spinInit(); 143 144 // follow a randomly chosen human - a specific Master Action 145 random = rnd(1000.0f); 146 if (random < 1) 147 this->followRandomHumanInit(); 148 149 // lose master status (only if less than 4 slaves in formation) 150 random = rnd(maxrand); 151 if(random < 15/(this->slaves_.size()+1) && this->slaves_.size() < 4 ) 152 this->loseMasterState(); 153 154 // look out for outher masters if formation is small 155 random = rnd(maxrand); 156 if(this->slaves_.size() < 3 && random < 20) 157 this->searchNewMaster(); 158 159 // search enemy 160 random = rnd(maxrand); 161 if (random < 15 && (!this->target_)) 162 this->searchNewTarget(); 163 164 // forget enemy 165 random = rnd(maxrand); 166 if (random < 5 && (this->target_)) 167 this->forgetTarget(); 168 169 // next enemy 170 random = rnd(maxrand); 171 if (random < 10 && (this->target_)) 172 this->searchNewTarget(); 173 174 // fly somewhere 175 random = rnd(maxrand); 176 if (random < 50 && (!this->bHasTargetPosition_ && !this->target_)) 177 this->searchRandomTargetPosition(); 178 179 180 // fly somewhere else 181 random = rnd(maxrand); 182 if (random < 30 && (this->bHasTargetPosition_ && !this->target_)) 183 this->searchRandomTargetPosition(); 184 185 // shoot 186 random = rnd(maxrand); 187 if (!(this->passive_) && random < 9 && (this->target_ && !this->bShooting_)) 188 { 189 this->bShooting_ = true; 190 this->forceFreeSlaves(); 191 } 192 193 // stop shooting 194 random = rnd(maxrand); 195 if (random < 25 && (this->bShooting_)) 196 this->bShooting_ = false; 197 198 } 199 } 200 97 201 } 98 202 … … 102 206 return; 103 207 104 if (this->target_) 105 this->aimAtTarget(); 106 107 if (this->bHasTargetPosition_) 108 this->moveToTargetPosition(); 109 110 if (this->getControllableEntity() && this->bShooting_ && this->isCloseAtTarget(1000) && this->isLookingAtTarget(Ogre::Math::PI / 20.0f)) 111 this->getControllableEntity()->fire(0); 208 if (this->state_ == MASTER) 209 { 210 if (this->specificMasterAction_ == NONE) 211 { 212 if (this->target_) 213 { 214 if (!this->target_->getRadarVisibility()) /* So AI won't shoot invisible Spaceships */ 215 this->forgetTarget(); 216 else this->aimAtTarget(); 217 } 218 219 if (this->bHasTargetPosition_) 220 this->moveToTargetPosition(); 221 222 if (this->getControllableEntity() && this->bShooting_ && this->isCloseAtTarget(1000) && this->isLookingAtTarget(Ogre::Math::PI / 20.0f)) 223 this->getControllableEntity()->fire(0); 224 } 225 226 if (this->specificMasterAction_ == TURN180) 227 this->turn180(); 228 229 if (this->specificMasterAction_ == SPIN) 230 this->spin(); 231 if (this->specificMasterAction_ == FOLLOW) 232 this->follow(); 233 } 234 235 if (this->state_ == SLAVE) 236 { 237 238 if (this->bHasTargetPosition_) 239 this->moveToTargetPosition(); 240 241 } 242 243 if (this->state_ == FREE) 244 { 245 if (this->target_) 246 { 247 if (!this->target_->getRadarVisibility()) /* So AI won't shoot invisible Spaceships */ 248 this->forgetTarget(); 249 else this->aimAtTarget(); 250 } 251 252 if (this->bHasTargetPosition_) 253 this->moveToTargetPosition(); 254 255 if (this->getControllableEntity() && this->bShooting_ && this->isCloseAtTarget(1000) && this->isLookingAtTarget(Ogre::Math::PI / 20.0f)) 256 this->getControllableEntity()->fire(0); 257 } 112 258 113 259 SUPER(AIController, tick, dt); -
code/trunk/src/orxonox/controllers/ArtificialController.cc
r6502 r7163 23 23 * Fabian 'x3n' Landau 24 24 * Co-authors: 25 * ...25 * Dominik Solenicki 26 26 * 27 27 */ … … 29 29 #include "ArtificialController.h" 30 30 31 #include <vector> 32 #include <climits> 33 34 #include "util/Math.h" 35 #include "core/ConsoleCommand.h" 31 36 #include "core/CoreIncludes.h" 37 #include "core/XMLPort.h" 32 38 #include "worldentities/ControllableEntity.h" 33 39 #include "worldentities/pawns/Pawn.h" 34 40 #include "worldentities/pawns/TeamBaseMatchBase.h" 35 41 #include "gametypes/TeamDeathmatch.h" 42 #include "gametypes/Dynamicmatch.h" 36 43 #include "controllers/WaypointPatrolController.h" 44 #include "controllers/NewHumanController.h" 45 #include "controllers/DroneController.h" 37 46 38 47 namespace orxonox 39 48 { 49 SetConsoleCommand(ArtificialController, formationflight, true); 50 SetConsoleCommand(ArtificialController, masteraction, true); 51 SetConsoleCommand(ArtificialController, followme, true); 52 SetConsoleCommand(ArtificialController, passivebehaviour, true); 53 SetConsoleCommand(ArtificialController, formationsize, true); 54 55 static const unsigned int STANDARD_MAX_FORMATION_SIZE = 7; 56 static const int RADIUS_TO_SEARCH_FOR_MASTERS = 5000; 57 static const int FORMATION_LENGTH = 130; 58 static const int FORMATION_WIDTH = 110; 59 static const int FREEDOM_COUNT = 4; //seconds the slaves in a formation will be set free when master attacks an enemy 60 static const float SPEED_MASTER = 0.6f; 61 static const float ROTATEFACTOR_MASTER = 0.2f; 62 static const float SPEED_FREE = 0.8f; 63 static const float ROTATEFACTOR_FREE = 0.8f; 64 65 40 66 ArtificialController::ArtificialController(BaseObject* creator) : Controller(creator) 41 67 { … … 43 69 44 70 this->target_ = 0; 71 this->formationFlight_ = true; 72 this->passive_ = false; 73 this->maxFormationSize_ = STANDARD_MAX_FORMATION_SIZE; 74 this->myMaster_ = 0; 75 this->freedomCount_ = 0; 76 this->team_ = -1; 77 this->state_ = FREE; 78 this->specificMasterAction_ = NONE; 79 this->specificMasterActionHoldCount_ = 0; 45 80 this->bShooting_ = false; 46 81 this->bHasTargetPosition_ = false; 82 this->speedCounter_ = 0.2f; 47 83 this->targetPosition_ = Vector3::ZERO; 48 84 … … 52 88 ArtificialController::~ArtificialController() 53 89 { 90 if (this->isInitialized()) 91 { 92 this->removeFromFormation(); 93 94 for (ObjectList<ArtificialController>::iterator it = ObjectList<ArtificialController>::begin(); it; ++it) 95 { 96 if (*it != this) 97 { 98 if (it->myMaster_ == this) 99 { 100 COUT(1) << "error: " << this << " is still master in " << (*it) << std::endl; 101 it->myMaster_ = 0; 102 } 103 104 while (true) 105 { 106 std::vector<ArtificialController*>::iterator it2 = std::find(it->slaves_.begin(), it->slaves_.end(), this); 107 if (it2 != it->slaves_.end()) 108 { 109 COUT(1) << "error: " << this << " is still slave in " << (*it) << std::endl; 110 it->slaves_.erase(it2); 111 } 112 else 113 break; 114 } 115 } 116 } 117 } 118 } 119 120 void ArtificialController::XMLPort(Element& xmlelement, XMLPort::Mode mode) 121 { 122 SUPER(ArtificialController, XMLPort, xmlelement, mode); 123 124 XMLPortParam(ArtificialController, "team", setTeam, getTeam, xmlelement, mode).defaultValues(-1); 125 XMLPortParam(ArtificialController, "formationFlight", setFormationFlight, getFormationFlight, xmlelement, mode).defaultValues(false); 126 XMLPortParam(ArtificialController, "formationSize", setFormationSize, getFormationSize, xmlelement, mode).defaultValues(STANDARD_MAX_FORMATION_SIZE); 127 XMLPortParam(ArtificialController, "passive", setPassive, getPassive, xmlelement, mode).defaultValues(false); 128 } 129 130 // Documentation only here to get a faster overview for creating a useful documentation... 131 132 /** 133 @brief Activates / deactivates formationflight behaviour 134 @param form activate formflight if form is true 135 */ 136 void ArtificialController::formationflight(const bool form) 137 { 138 for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it) 139 { 140 Controller* controller = 0; 141 142 if (it->getController()) 143 controller = it->getController(); 144 else if (it->getXMLController()) 145 controller = it->getXMLController(); 146 147 if (!controller) 148 continue; 149 150 ArtificialController *aiController = orxonox_cast<ArtificialController*>(controller); 151 152 if (aiController) 153 { 154 aiController->formationFlight_ = form; 155 if (!form) 156 { 157 aiController->removeFromFormation(); 158 } 159 } 160 } 161 } 162 163 /** 164 @brief Get all masters to do a "specific master action" 165 @param action which action to perform (integer, so it can be called with a console command (tmp solution)) 166 */ 167 void ArtificialController::masteraction(const int action) 168 { 169 for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it) 170 { 171 Controller* controller = 0; 172 173 if (it->getController()) 174 controller = it->getController(); 175 else if (it->getXMLController()) 176 controller = it->getXMLController(); 177 178 if (!controller) 179 continue; 180 181 ArtificialController *aiController = orxonox_cast<ArtificialController*>(controller); 182 183 if(aiController && aiController->state_ == MASTER) 184 { 185 if (action == 1) 186 aiController->spinInit(); 187 if (action == 2) 188 aiController->turn180Init(); 189 } 190 } 191 } 192 193 /** 194 @brief A human player gets followed by its nearest master. Initiated by console command, so far intended for demonstration puproses (possible future pickup). 195 */ 196 void ArtificialController::followme() 197 { 198 199 Pawn *humanPawn = NULL; 200 NewHumanController *currentHumanController = NULL; 201 std::vector<ArtificialController*> allMasters; 202 203 for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it) 204 { 205 Controller* controller = 0; 206 207 if (it->getController()) 208 controller = it->getController(); 209 else if (it->getXMLController()) 210 controller = it->getXMLController(); 211 212 if (!controller) 213 continue; 214 215 currentHumanController = orxonox_cast<NewHumanController*>(controller); 216 217 if(currentHumanController) humanPawn = *it; 218 219 ArtificialController *aiController = orxonox_cast<ArtificialController*>(controller); 220 221 if(aiController && aiController->state_ == MASTER) 222 allMasters.push_back(aiController); 223 224 } 225 226 if((humanPawn != NULL) && (allMasters.size() != 0)) 227 { 228 float posHuman = humanPawn->getPosition().length(); 229 float distance = 0.0f; 230 float minDistance = FLT_MAX; 231 int index = 0; 232 int i = 0; 233 234 for(std::vector<ArtificialController*>::iterator it = allMasters.begin(); it != allMasters.end(); it++, i++) 235 { 236 if (!ArtificialController::sameTeam((*it)->getControllableEntity(), humanPawn, (*it)->getGametype())) continue; 237 distance = posHuman - (*it)->getControllableEntity()->getPosition().length(); 238 if(distance < minDistance) index = i; 239 } 240 allMasters[index]->followInit(humanPawn); 241 } 242 243 } 244 245 /** 246 @brief Sets shooting behaviour of pawns. 247 @param passive if true, bots won't shoot. 248 */ 249 void ArtificialController::passivebehaviour(const bool passive) 250 { 251 for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it) 252 { 253 Controller* controller = 0; 254 255 if (it->getController()) 256 controller = it->getController(); 257 else if (it->getXMLController()) 258 controller = it->getXMLController(); 259 260 if (!controller) 261 continue; 262 263 ArtificialController *aiController = orxonox_cast<ArtificialController*>(controller); 264 265 if(aiController) 266 { 267 aiController->passive_ = passive; 268 } 269 } 270 } 271 272 273 /** 274 @brief Sets maximal formation size 275 @param size maximal formation size. 276 */ 277 void ArtificialController::formationsize(const int size) 278 { 279 for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it) 280 { 281 Controller* controller = 0; 282 283 if (it->getController()) 284 controller = it->getController(); 285 else if (it->getXMLController()) 286 controller = it->getXMLController(); 287 288 if (!controller) 289 continue; 290 291 ArtificialController *aiController = orxonox_cast<ArtificialController*>(controller); 292 293 if(aiController) 294 { 295 aiController->maxFormationSize_ = size; 296 } 297 } 298 } 299 300 /** 301 @brief Gets called when ControllableEntity is being changed. Resets the bot when it dies. 302 */ 303 void ArtificialController::changedControllableEntity() 304 { 305 if (!this->getControllableEntity()) 306 this->removeFromFormation(); 307 } 308 309 void ArtificialController::removeFromFormation() 310 { 311 if (this->state_ == SLAVE || this->myMaster_) // slaves can also be temporary free, so check if myMaster_ is set 312 this->unregisterSlave(); 313 else if (this->state_ == MASTER) 314 this->setNewMasterWithinFormation(); 54 315 } 55 316 … … 59 320 return; 60 321 322 // Slave uses special movement if its master is in FOLLOW mode 323 if(this->state_ == SLAVE && this->myMaster_ && this->myMaster_->specificMasterAction_ == FOLLOW) 324 { 325 // this->followForSlaves(target); 326 // return; 327 } 328 61 329 Vector2 coord = get2DViewdirection(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, target); 62 330 float distance = (target - this->getControllableEntity()->getPosition()).length(); 63 331 64 if (this->target_ || distance > 10) 65 { 66 // Multiply with 0.8 to make them a bit slower 67 this->getControllableEntity()->rotateYaw(-0.8f * sgn(coord.x) * coord.x*coord.x); 68 this->getControllableEntity()->rotatePitch(0.8f * sgn(coord.y) * coord.y*coord.y); 69 } 70 71 if (this->target_ && distance < 200 && this->getControllableEntity()->getVelocity().squaredLength() > this->target_->getVelocity().squaredLength()) 72 this->getControllableEntity()->moveFrontBack(-0.5f); // They don't brake with full power to give the player a chance 332 333 if(this->state_ == FREE) 334 { 335 if (this->target_ || distance > 10) 336 { 337 // Multiply with ROTATEFACTOR_FREE to make them a bit slower 338 this->getControllableEntity()->rotateYaw(-1.0f * ROTATEFACTOR_FREE * sgn(coord.x) * coord.x*coord.x); 339 this->getControllableEntity()->rotatePitch(ROTATEFACTOR_FREE * sgn(coord.y) * coord.y*coord.y); 340 } 341 342 if (this->target_ && distance < 200 && this->getControllableEntity()->getVelocity().squaredLength() > this->target_->getVelocity().squaredLength()) 343 { 344 this->getControllableEntity()->moveFrontBack(-0.05f); // They don't brake with full power to give the player a chance 345 } else this->getControllableEntity()->moveFrontBack(SPEED_FREE); 346 } 347 348 349 350 if(this->state_ == MASTER) 351 { 352 if (this->target_ || distance > 10) 353 { 354 this->getControllableEntity()->rotateYaw(-1.0f * ROTATEFACTOR_MASTER * sgn(coord.x) * coord.x*coord.x); 355 this->getControllableEntity()->rotatePitch(ROTATEFACTOR_MASTER * sgn(coord.y) * coord.y*coord.y); 356 } 357 358 if (this->target_ && distance < 200 && this->getControllableEntity()->getVelocity().squaredLength() > this->target_->getVelocity().squaredLength()) 359 { 360 this->getControllableEntity()->moveFrontBack(-0.05f); 361 } else this->getControllableEntity()->moveFrontBack(SPEED_MASTER); 362 } 363 364 365 366 if(this->state_ == SLAVE) 367 { 368 369 this->getControllableEntity()->rotateYaw(-2.0f * ROTATEFACTOR_MASTER * sgn(coord.x) * coord.x*coord.x); 370 this->getControllableEntity()->rotatePitch(2.0f * ROTATEFACTOR_MASTER * sgn(coord.y) * coord.y*coord.y); 371 372 if (distance < 300) 373 { 374 if (distance < 40) 375 { 376 this->getControllableEntity()->moveFrontBack(0.8f*SPEED_MASTER); 377 } else this->getControllableEntity()->moveFrontBack(1.2f*SPEED_MASTER); 378 379 } else { 380 this->getControllableEntity()->moveFrontBack(1.2f*SPEED_MASTER + distance/300.0f); 381 } 382 } 383 } 384 385 void ArtificialController::moveToTargetPosition() 386 { 387 this->moveToPosition(this->targetPosition_); 388 } 389 390 391 /** 392 @brief Unregisters a slave from its master. Initiated by a slave. 393 */ 394 void ArtificialController::unregisterSlave() 395 { 396 if (this->myMaster_) 397 { 398 std::vector<ArtificialController*>::iterator it = std::find(this->myMaster_->slaves_.begin(), this->myMaster_->slaves_.end(), this); 399 if (it != this->myMaster_->slaves_.end()) 400 this->myMaster_->slaves_.erase(it); 401 } 402 403 this->myMaster_ = 0; 404 this->state_ = FREE; 405 } 406 407 void ArtificialController::searchNewMaster() 408 { 409 410 if (!this->getControllableEntity()) 411 return; 412 413 this->targetPosition_ = this->getControllableEntity()->getPosition(); 414 this->forgetTarget(); 415 int teamSize = 0; 416 //go through all pawns 417 for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it) 418 { 419 //same team? 420 if (!ArtificialController::sameTeam(this->getControllableEntity(), static_cast<ControllableEntity*>(*it), this->getGametype())) 421 continue; 422 423 //has it an ArtificialController? 424 Controller* controller = 0; 425 426 if (it->getController()) 427 controller = it->getController(); 428 else if (it->getXMLController()) 429 controller = it->getXMLController(); 430 431 if (!controller) 432 continue; 433 434 //is pawn oneself? 435 if (orxonox_cast<ControllableEntity*>(*it) == this->getControllableEntity()) 436 continue; 437 438 teamSize++; 439 440 ArtificialController *newMaster = orxonox_cast<ArtificialController*>(controller); 441 442 //is it a master? 443 if (!newMaster || newMaster->state_ != MASTER) 444 continue; 445 446 float distance = (it->getPosition() - this->getControllableEntity()->getPosition()).length(); 447 448 // is pawn in range? 449 if (distance < RADIUS_TO_SEARCH_FOR_MASTERS) 450 { 451 if(newMaster->slaves_.size() > this->maxFormationSize_) continue; 452 453 for(std::vector<ArtificialController*>::iterator itSlave = this->slaves_.begin(); itSlave != this->slaves_.end(); itSlave++) 454 { 455 (*itSlave)->myMaster_ = newMaster; 456 newMaster->slaves_.push_back(*itSlave); 457 } 458 this->slaves_.clear(); 459 this->state_ = SLAVE; 460 461 this->myMaster_ = newMaster; 462 newMaster->slaves_.push_back(this); 463 464 break; 465 } 466 } 467 468 if (this->state_ != SLAVE && teamSize != 0) 469 { 470 this->state_ = MASTER; 471 this->myMaster_ = 0; 472 } 473 } 474 475 /** 476 @brief Commands the slaves of a master into a formation. Sufficiently fast not to be called within tick. Initiated by a master. 477 */ 478 void ArtificialController::commandSlaves() 479 { 480 if(this->state_ != MASTER) return; 481 482 Quaternion orient = this->getControllableEntity()->getOrientation(); 483 Vector3 dest = this->getControllableEntity()->getPosition(); 484 485 // 1 slave: follow 486 if (this->slaves_.size() == 1) 487 { 488 dest += 4*orient*WorldEntity::BACK; 489 this->slaves_.front()->setTargetPosition(dest); 490 } 73 491 else 74 this->getControllableEntity()->moveFrontBack(0.8f); 75 } 76 77 void ArtificialController::moveToTargetPosition() 78 { 79 this->moveToPosition(this->targetPosition_); 80 } 492 { 493 dest += 1.0f*orient*WorldEntity::BACK; 494 Vector3 pos = Vector3::ZERO; 495 int i = 1; 496 497 for(std::vector<ArtificialController*>::iterator it = slaves_.begin(); it != slaves_.end(); it++) 498 { 499 pos = Vector3::ZERO; 500 if (i <= 1) pos += dest + FORMATION_WIDTH*(orient*WorldEntity::LEFT); 501 if (i == 2) pos += dest + FORMATION_WIDTH*(orient*WorldEntity::RIGHT); 502 if (i == 3) pos += dest + FORMATION_WIDTH*(orient*WorldEntity::UP); 503 if (i >= 4) 504 { 505 pos += dest + FORMATION_WIDTH*(orient*WorldEntity::DOWN); 506 i = 1; 507 dest += FORMATION_LENGTH*(orient*WorldEntity::BACK); 508 (*it)->setTargetPosition(pos); 509 continue; 510 } 511 i++; 512 (*it)->setTargetPosition(pos); 513 } 514 } 515 } 516 517 /** 518 @brief Sets a new master within the formation. Called by a master. 519 */ 520 void ArtificialController::setNewMasterWithinFormation() 521 { 522 if(this->state_ != MASTER) return; 523 524 if (!this->slaves_.empty()) 525 { 526 ArtificialController *newMaster = this->slaves_.back(); 527 this->slaves_.pop_back(); 528 529 newMaster->state_ = MASTER; 530 newMaster->slaves_ = this->slaves_; 531 newMaster->myMaster_ = 0; 532 533 for(std::vector<ArtificialController*>::iterator it = newMaster->slaves_.begin(); it != newMaster->slaves_.end(); it++) 534 { 535 (*it)->myMaster_ = newMaster; 536 } 537 } 538 539 this->slaves_.clear(); 540 this->specificMasterAction_ = NONE; 541 this->state_ = FREE; 542 } 543 544 /** 545 @brief Frees all slaves form a master. Initiated by a master. 546 */ 547 void ArtificialController::freeSlaves() 548 { 549 if(this->state_ != MASTER) return; 550 551 for(std::vector<ArtificialController*>::iterator it = slaves_.begin(); it != slaves_.end(); it++) 552 { 553 (*it)->state_ = FREE; 554 (*it)->myMaster_ = 0; 555 } 556 this->slaves_.clear(); 557 } 558 559 /** 560 @brief Master sets its slaves free for @var FREEDOM_COUNT seconds. 561 */ 562 void ArtificialController::forceFreeSlaves() 563 { 564 if(this->state_ != MASTER) return; 565 566 for(std::vector<ArtificialController*>::iterator it = slaves_.begin(); it != slaves_.end(); it++) 567 { 568 (*it)->state_ = FREE; 569 (*it)->forceFreedom(); 570 (*it)->targetPosition_ = this->targetPosition_; 571 (*it)->bShooting_ = true; 572 // (*it)->getControllableEntity()->fire(0);// fire once for fun 573 } 574 } 575 576 void ArtificialController::loseMasterState() 577 { 578 this->freeSlaves(); 579 this->state_ = FREE; 580 } 581 582 583 void ArtificialController::forceFreedom() 584 { 585 this->freedomCount_ = FREEDOM_COUNT; 586 } 587 588 /** 589 @brief Checks wether caller has been forced free, decrements time to stay forced free. 590 @return true if forced free. 591 */ 592 bool ArtificialController::forcedFree() 593 { 594 if(this->freedomCount_ > 0) 595 { 596 this->freedomCount_--; 597 return true; 598 } else return false; 599 } 600 601 /** 602 @brief Used to continue a "specific master action" for a certain time and resuming normal behaviour after. 603 */ 604 void ArtificialController::specificMasterActionHold() 605 { 606 if(this->state_ != MASTER) return; 607 608 if (specificMasterActionHoldCount_ == 0) 609 { 610 this->specificMasterAction_ = NONE; 611 this->searchNewTarget(); 612 } 613 else specificMasterActionHoldCount_--; 614 } 615 616 /** 617 @brief Master initializes a 180 degree turn. Leads to a "specific master action". 618 */ 619 void ArtificialController::turn180Init() 620 { 621 if(this->state_ != MASTER) return; 622 623 Quaternion orient = this->getControllableEntity()->getOrientation(); 624 625 this->setTargetPosition(this->getControllableEntity()->getPosition() + 1000.0f*orient*WorldEntity::BACK); 626 627 this->specificMasterActionHoldCount_ = 4; 628 629 this->specificMasterAction_ = TURN180; 630 } 631 632 /** 633 @brief Execute the 180 degree turn. Called within tick. 634 */ 635 void ArtificialController::turn180() 636 { 637 Vector2 coord = get2DViewdirection(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, this->targetPosition_); 638 639 this->getControllableEntity()->rotateYaw(-2.0f * sgn(coord.x) * coord.x*coord.x); 640 this->getControllableEntity()->rotatePitch(2.0f * sgn(coord.y) * coord.y*coord.y); 641 642 this->getControllableEntity()->moveFrontBack(SPEED_MASTER); 643 } 644 645 /** 646 @brief Master initializes a spin around its looking direction axis. Leads to a "specific master action". 647 */ 648 void ArtificialController::spinInit() 649 { 650 if(this->state_ != MASTER) return; 651 this->specificMasterAction_ = SPIN; 652 this->specificMasterActionHoldCount_ = 10; 653 } 654 655 /** 656 @brief Execute the spin. Called within tick. 657 */ 658 void ArtificialController::spin() 659 { 660 this->moveToTargetPosition(); 661 this->getControllableEntity()->rotateRoll(0.8f); 662 } 663 664 /** 665 @brief Master begins to follow a pawn. Is a "specific master action". 666 @param pawn pawn to follow. 667 @param alaways follows pawn forever if true (false if omitted). 668 @param secondsToFollow seconds to follow the pawn if always is false. Will follow pawn 100 seconds if omitted (set in header). 669 */ 670 void ArtificialController::followInit(Pawn* pawn, const bool always, const int secondsToFollow) 671 { 672 if (pawn == NULL || this->state_ != MASTER) 673 return; 674 this->specificMasterAction_ = FOLLOW; 675 676 this->setTarget(pawn); 677 if (!always) 678 this->specificMasterActionHoldCount_ = secondsToFollow; 679 else 680 this->specificMasterActionHoldCount_ = INT_MAX; //for now... 681 682 } 683 684 685 /** 686 @brief Master begins to follow a randomly chosen human player of the same team. Is a "specific master action". 687 */ 688 void ArtificialController::followRandomHumanInit() 689 { 690 691 Pawn *humanPawn = NULL; 692 NewHumanController *currentHumanController = NULL; 693 694 for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it) 695 { 696 if (!it->getController()) 697 continue; 698 699 currentHumanController = orxonox_cast<NewHumanController*>(it->getController()); 700 if(currentHumanController) 701 { 702 if (!ArtificialController::sameTeam(this->getControllableEntity(), *it, this->getGametype())) continue; 703 humanPawn = *it; 704 break; 705 } 706 } 707 708 if((humanPawn != NULL)) 709 this->followInit(humanPawn); 710 } 711 712 /** 713 @brief Master follows target with adjusted speed. Called within tick. 714 */ 715 void ArtificialController::follow() 716 { 717 if (this->target_) 718 this->moveToPosition(this->target_->getPosition()); 719 else 720 this->specificMasterActionHoldCount_ = 0; 721 /* 722 if (!this->getControllableEntity()) 723 return; 724 725 float distance = (this->target_->getPosition() - this->getControllableEntity()->getPosition()).length(); 726 727 Vector2 coord = get2DViewdirection(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, this->target_->getPosition()); 728 729 730 this->getControllableEntity()->rotateYaw(-0.8f * sgn(coord.x) * coord.x*coord.x); 731 this->getControllableEntity()->rotatePitch(0.8f * sgn(coord.y) * coord.y*coord.y); 732 733 float speedDiv = this->getControllableEntity()->getVelocity().squaredLength() - this->target_->getVelocity().squaredLength(); 734 735 COUT(0) << "~follow distance: " << distance << "SpeedCounter: " << this->speedCounter_ << "~speedDiv: " << speedDiv << std::endl; 736 if (distance < 800) 737 { 738 if (distance < 200) 739 { 740 this->speedCounter_ -= 0.5f; 741 if(this->speedCounter_ < 0) this->speedCounter_ = 0.0f; 742 this->getControllableEntity()->moveFrontBack(speedCounter_); 743 } else { 744 if(speedDiv < 0) 745 this->speedCounter_ += 0.01f; 746 else 747 this->speedCounter_ -= 0.05f; 748 this->getControllableEntity()->moveFrontBack(speedCounter_); 749 } 750 751 } else { 752 this->speedCounter_ += 0.05f; 753 this->getControllableEntity()->moveFrontBack(speedCounter_ + distance/300.0f); 754 } 755 // if (this->getControllableEntity()->getVelocity().squaredLength() > 50.0f) this->speedCounter_ = 0; 756 757 */ 758 } 759 760 761 /** 762 @brief Slave moving behaviour when master is following a pawn, gets redirected from moveToPosition(const Vector3& target)). Called within tick. 763 */ 764 void ArtificialController::followForSlaves(const Vector3& target) 765 { 766 767 /* 768 if (!this->getControllableEntity() && !this->myMaster_ && this->myMaster_->state_ != FOLLOW && !this->myMaster_->target_) 769 return; 770 771 float distance = (target - this->getControllableEntity()->getPosition()).length(); 772 773 Vector2 coord = get2DViewdirection(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, target); 774 775 776 this->getControllableEntity()->rotateYaw(-0.8f * sgn(coord.x) * coord.x*coord.x); 777 this->getControllableEntity()->rotatePitch(0.8f * sgn(coord.y) * coord.y*coord.y); 778 779 780 float speedDiv = this->getControllableEntity()->getVelocity().squaredLength() - this->myMaster_->target_->getVelocity().squaredLength(); 781 782 783 if (distance < 800) 784 { 785 if (distance < 200) 786 { 787 this->speedCounter_ -= 5.0f; 788 if(this->speedCounter_ < 0) this->speedCounter_ = 0.0f; 789 this->getControllableEntity()->moveFrontBack(speedCounter_); 790 } else { 791 if(speedDiv < 0) 792 this->speedCounter_ += 0.01f; 793 else 794 this->speedCounter_ -= 0.05f; 795 this->getControllableEntity()->moveFrontBack(speedCounter_); 796 } 797 798 } else { 799 this->speedCounter_ += 0.05f; 800 this->getControllableEntity()->moveFrontBack(speedCounter_ + distance/300.0f); 801 } 802 // if (this->getControllableEntity()->getVelocity().squaredLength() > 50.0f) this->speedCounter_ = 0; 803 */ 804 } 805 81 806 82 807 void ArtificialController::setTargetPosition(const Vector3& target) … … 111 836 { 112 837 if (ArtificialController::sameTeam(this->getControllableEntity(), static_cast<ControllableEntity*>(*it), this->getGametype())) 838 continue; 839 840 /* So AI won't choose invisible Spaceships as target */ 841 if (!it->getRadarVisibility()) 113 842 continue; 114 843 … … 144 873 this->bHasTargetPosition_ = (this->targetPosition_ != Vector3::ZERO); 145 874 146 Pawn* pawn = dynamic_cast<Pawn*>(this->getControllableEntity());875 Pawn* pawn = orxonox_cast<Pawn*>(this->getControllableEntity()); 147 876 if (pawn) 148 877 pawn->setAimPosition(this->targetPosition_); … … 188 917 int team2 = -1; 189 918 190 if (entity1->getXMLController()) 191 { 192 WaypointPatrolController* wpc = orxonox_cast<WaypointPatrolController*>(entity1->getXMLController()); 193 if (wpc) 194 team1 = wpc->getTeam(); 195 } 196 if (entity2->getXMLController()) 197 { 198 WaypointPatrolController* wpc = orxonox_cast<WaypointPatrolController*>(entity2->getXMLController()); 199 if (wpc) 200 team2 = wpc->getTeam(); 919 Controller* controller = 0; 920 if (entity1->getController()) 921 controller = entity1->getController(); 922 else 923 controller = entity1->getXMLController(); 924 if (controller) 925 { 926 ArtificialController* ac = orxonox_cast<ArtificialController*>(controller); 927 if (ac) 928 team1 = ac->getTeam(); 929 } 930 931 if (entity2->getController()) 932 controller = entity2->getController(); 933 else 934 controller = entity2->getXMLController(); 935 if (controller) 936 { 937 ArtificialController* ac = orxonox_cast<ArtificialController*>(controller); 938 if (ac) 939 team2 = ac->getTeam(); 201 940 } 202 941 … … 245 984 } 246 985 986 DroneController* droneController = 0; 987 droneController = orxonox_cast<DroneController*>(entity1->getController()); 988 if (droneController && static_cast<ControllableEntity*>(droneController->getOwner()) == entity2) 989 return true; 990 droneController = orxonox_cast<DroneController*>(entity2->getController()); 991 if (droneController && static_cast<ControllableEntity*>(droneController->getOwner()) == entity1) 992 return true; 993 DroneController* droneController1 = orxonox_cast<DroneController*>(entity1->getController()); 994 DroneController* droneController2 = orxonox_cast<DroneController*>(entity2->getController()); 995 if (droneController1 && droneController2 && droneController1->getOwner() == droneController2->getOwner()) 996 return true; 997 998 Dynamicmatch* dynamic = orxonox_cast<Dynamicmatch*>(gametype); 999 if (dynamic) 1000 { 1001 if (dynamic->notEnoughPigs||dynamic->notEnoughKillers||dynamic->notEnoughChasers) {return false;} 1002 1003 if (entity1->getPlayer()) 1004 team1 = dynamic->getParty(entity1->getPlayer()); 1005 1006 if (entity2->getPlayer()) 1007 team2 = dynamic->getParty(entity2->getPlayer()); 1008 1009 if (team1 ==-1 ||team2 ==-1 ) {return false;} 1010 else if (team1 == dynamic->chaser && team2 != dynamic->chaser) {return false;} 1011 else if (team1 == dynamic->piggy && team2 == dynamic->chaser) {return false;} 1012 else if (team1 == dynamic->killer && team2 == dynamic->chaser) {return false;} 1013 else return true; 1014 } 1015 247 1016 return (team1 == team2 && team1 != -1); 248 1017 } -
code/trunk/src/orxonox/controllers/ArtificialController.h
r6417 r7163 23 23 * Fabian 'x3n' Landau 24 24 * Co-authors: 25 * ...25 * Dominik Solenicki 26 26 * 27 27 */ … … 32 32 #include "OrxonoxPrereqs.h" 33 33 34 #include <vector> 35 34 36 #include "util/Math.h" 35 37 #include "Controller.h" 38 #include "controllers/NewHumanController.h" 36 39 37 40 namespace orxonox … … 43 46 virtual ~ArtificialController(); 44 47 48 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 49 45 50 void abandonTarget(Pawn* target); 46 51 52 inline void setTeam(int team) 53 { this->team_ = team; } 54 inline int getTeam() const 55 { return this->team_; } 56 57 inline void setFormationFlight(bool formation) 58 { this->formationFlight_ = formation; } 59 inline bool getFormationFlight() const 60 { return this->formationFlight_; } 61 62 inline void setFormationSize(int size) 63 { this->maxFormationSize_ = size; } 64 inline int getFormationSize() const 65 { return this->maxFormationSize_; } 66 67 inline void setPassive(bool passive) 68 { this->passive_ = passive; } 69 inline bool getPassive() const 70 { return this->passive_; } 71 72 virtual void changedControllableEntity(); 73 74 static void formationflight(const bool form); 75 static void masteraction(const int action); 76 static void followme(); 77 static void passivebehaviour(const bool passive); 78 static void formationsize(const int size); 79 47 80 protected: 48 void targetDied(); 81 82 int team_; 83 bool formationFlight_; 84 bool passive_; 85 unsigned int maxFormationSize_; 86 int freedomCount_; 87 enum State {SLAVE, MASTER, FREE}; 88 State state_; 89 std::vector<ArtificialController*> slaves_; 90 ArtificialController *myMaster_; 91 enum SpecificMasterAction {NONE, HOLD, SPIN, TURN180, FOLLOW}; 92 SpecificMasterAction specificMasterAction_; 93 int specificMasterActionHoldCount_; 94 float speedCounter_; //for speed adjustment when following 49 95 50 96 void moveToPosition(const Vector3& target); 51 97 void moveToTargetPosition(); 98 99 void removeFromFormation(); 100 void unregisterSlave(); 101 void searchNewMaster(); 102 void commandSlaves(); 103 void setNewMasterWithinFormation(); 104 105 void freeSlaves(); 106 void forceFreeSlaves(); 107 void loseMasterState(); 108 void forceFreedom(); 109 bool forcedFree(); 110 111 void specificMasterActionHold(); 112 void turn180Init(); 113 void turn180(); 114 void spinInit(); 115 void spin(); 116 void followInit(Pawn* pawn, const bool always = false, const int secondsToFollow = 100); 117 void followRandomHumanInit(); 118 void follow(); 119 void followForSlaves(const Vector3& target); 52 120 53 121 void setTargetPosition(const Vector3& target); … … 61 129 bool isCloseAtTarget(float distance) const; 62 130 bool isLookingAtTarget(float angle) const; 131 132 void targetDied(); 63 133 64 134 static bool sameTeam(ControllableEntity* entity1, ControllableEntity* entity2, Gametype* gametype); // hack -
code/trunk/src/orxonox/controllers/CMakeLists.txt
r6417 r7163 8 8 WaypointController.cc 9 9 WaypointPatrolController.cc 10 DroneController.cc 10 11 ) -
code/trunk/src/orxonox/controllers/HumanController.cc
r6417 r7163 35 35 #include "gametypes/Gametype.h" 36 36 #include "infos/PlayerInfo.h" 37 #include "overlays/Map.h"38 37 #include "Radar.h" 39 38 #include "Scene.h" … … 116 115 void HumanController::yaw(const Vector2& value) 117 116 { 118 //Hack to enable mouselook in map119 if ( Map::getSingletonPtr() && Map::getSingletonPtr()->getVisibility() && HumanController::localController_s->controllableEntity_->isInMouseLook() )120 {121 Map::getSingletonPtr()->rotateYaw(value);122 return;123 }124 117 if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) 125 118 HumanController::localController_s->controllableEntity_->rotateYaw(value); … … 128 121 void HumanController::pitch(const Vector2& value) 129 122 { 130 //Hack to enable mouselook in map131 if ( Map::getSingletonPtr() && Map::getSingletonPtr()->getVisibility() && HumanController::localController_s->controllableEntity_->isInMouseLook() )132 {133 Map::getSingletonPtr()->rotatePitch(value);134 return;135 }136 123 if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) 137 124 HumanController::localController_s->controllableEntity_->rotatePitch(value); -
code/trunk/src/orxonox/controllers/NewHumanController.cc
r6598 r7163 217 217 if (this->getControllableEntity() && (this->getControllableEntity()->isExactlyA(ClassByString("SpaceShip")) || this->getControllableEntity()->isExactlyA(ClassByString("Rocket")))) 218 218 this->showOverlays(); 219 else if (this->getControllableEntity() && this->getControllableEntity()->isExactlyA(ClassByString("FpsPlayer"))) 220 { 221 this->showOverlays(); 222 this->hideArrows(); 223 } 219 224 220 225 this->crossHairOverlay_->setPosition(Vector2(static_cast<float>(this->currentYaw_)/2*-1+.5f-overlaySize_/2, static_cast<float>(this->currentPitch_)/2*-1+.5f-overlaySize_/2)); … … 364 369 Ogre::RaySceneQueryResult& result = rsq->execute(); 365 370 Pawn* pawn = orxonox_cast<Pawn*>(this->getControllableEntity()); 371 WorldEntity* myWe = static_cast<WorldEntity*>(this->getControllableEntity()); 366 372 367 373 Ogre::RaySceneQueryResult::iterator itr; 368 374 for (itr = result.begin(); itr != result.end(); ++itr) 369 375 { 370 if (itr->movable->isInScene() && itr->movable->getMovableType() == "Entity" && itr->distance > 500) 376 // CCOUT(0) << "testing object as target" << endl; 377 if (itr->movable->isInScene() && itr->movable->getMovableType() == "Entity" /*&& itr->distance > 500*/) 371 378 { 372 379 // Try to cast the user pointer 373 WorldEntity* wePtr = dynamic_cast<WorldEntity*>(Ogre::any_cast<OrxonoxClass*>(itr->movable->getUserAny())); 380 WorldEntity* wePtr; 381 try 382 { 383 wePtr = dynamic_cast<WorldEntity*>(Ogre::any_cast<OrxonoxClass*>(itr->movable->getUserAny())); 384 } 385 catch (...) 386 { 387 continue; 388 } 389 390 // make sure we don't shoot ourselves 391 if( wePtr==myWe ) 392 continue; 393 374 394 if (wePtr) 375 395 { … … 379 399 while (parent) 380 400 { 381 if (this->targetMask_.isExcluded(parent->getIdentifier()) )401 if (this->targetMask_.isExcluded(parent->getIdentifier()) || parent==myWe) 382 402 { 383 403 parent = parent->getParent(); … … 430 450 HumanController::yaw(value); 431 451 432 this->currentYaw_ = value.x; 452 if (this->getControllableEntity() && !this->getControllableEntity()->isExactlyA(ClassByString("FpsPlayer"))) 453 this->currentYaw_ = value.x; 433 454 } 434 455 … … 439 460 HumanController::pitch(value); 440 461 441 this->currentPitch_ = value.x; 462 if (this->getControllableEntity() && !this->getControllableEntity()->isExactlyA(ClassByString("FpsPlayer"))) 463 this->currentPitch_ = value.x; 442 464 } 443 465 … … 579 601 } 580 602 } 603 604 605 606 607 581 608 } -
code/trunk/src/orxonox/controllers/NewHumanController.h
r6417 r7163 67 67 virtual void doResumeControl(); 68 68 69 69 70 protected: 70 71 void updateTarget(); -
code/trunk/src/orxonox/controllers/WaypointPatrolController.cc
r6502 r7163 42 42 RegisterObject(WaypointPatrolController); 43 43 44 this->team_ = 0;44 //this->team_ = 0; 45 45 this->alertnessradius_ = 500; 46 46 … … 53 53 54 54 XMLPortParam(WaypointPatrolController, "alertnessradius", setAlertnessRadius, getAlertnessRadius, xmlelement, mode).defaultValues(500.0f); 55 XMLPortParam(WaypointPatrolController, "team", setTeam, getTeam, xmlelement, mode).defaultValues(0);55 // XMLPortParam(WaypointPatrolController, "team", setTeam, getTeam, xmlelement, mode).defaultValues(0); 56 56 } 57 57 -
code/trunk/src/orxonox/controllers/WaypointPatrolController.h
r5929 r7163 46 46 virtual void tick(float dt); 47 47 48 inline void setTeam(int team)48 /* inline void setTeam(int team) 49 49 { this->team_ = team; } 50 50 inline int getTeam() const 51 { return this->team_; } 51 { return this->team_; } */ 52 52 53 53 inline void setAlertnessRadius(float radius) … … 59 59 void searchEnemy(); 60 60 61 int team_;61 //int team_; 62 62 float alertnessradius_; 63 63 Timer patrolTimer_; -
code/trunk/src/orxonox/gamestates/GSClient.cc
r6426 r7163 40 40 DeclareGameState(GSClient, "client", false, false); 41 41 42 SetCommandLineArgument( ip, "127.0.0.1").information("Sever IP as string in the form #.#.#.#");42 SetCommandLineArgument(dest, "127.0.0.1").information("Server hostname/IP (IP in the form of #.#.#.#)"); 43 43 44 44 GSClient::GSClient(const GameStateInfo& info) 45 45 : GameState(info) 46 , client_(0)47 46 { 48 47 } … … 56 55 GameMode::setIsClient(true); 57 56 58 this->client_ = new Client(CommandLineParser::getValue("ip").getString(), CommandLineParser::getValue("port")); 57 // this->client_ = new Client(); 58 // this->client_->setDestination(CommandLineParser::getValue("dest").getString(), CommandLineParser::getValue("port") ); 59 59 60 if( !client_->establishConnection())60 if( !Client::getInstance()->establishConnection() ) 61 61 { 62 delete this->client_;63 62 ThrowException(InitialisationFailed, "Could not establish connection with server."); 64 63 } 65 64 66 client_->update(Game::getInstance().getGameClock());65 Client::getInstance()->update(Game::getInstance().getGameClock()); 67 66 } 68 67 69 68 void GSClient::deactivate() 70 69 { 71 client_->closeConnection();70 Client::getInstance()->closeConnection(); 72 71 73 72 // destroy client 74 delete this->client_;73 // delete this->client_; 75 74 76 75 GameMode::setIsClient(false); … … 79 78 void GSClient::update(const Clock& time) 80 79 { 81 client_->update(time);80 Client::getInstance()->update(time); 82 81 } 83 82 } -
code/trunk/src/orxonox/gamestates/GSClient.h
r5929 r7163 46 46 void deactivate(); 47 47 void update(const Clock& time); 48 49 private:50 Client* client_;51 48 }; 52 49 } -
code/trunk/src/orxonox/gamestates/GSGraphics.cc
r6417 r7163 39 39 #include "core/Game.h" 40 40 #include "core/GUIManager.h" 41 // HACK:42 #include "overlays/Map.h"43 41 44 42 namespace orxonox … … 73 71 void GSGraphics::deactivate() 74 72 { 75 // HACK: (destroys a resource smart pointer) 76 Map::hackDestroyMap(); 73 77 74 } 78 75 -
code/trunk/src/orxonox/gametypes/CMakeLists.txt
r5781 r7163 6 6 UnderAttack.cc 7 7 Asteroids.cc 8 Dynamicmatch.cc 8 9 ) -
code/trunk/src/orxonox/gametypes/Gametype.cc
r6417 r7163 309 309 if (this->spawnpoints_.size() > 0) 310 310 { 311 SpawnPoint* fallbackSpawnPoint = NULL; 311 312 unsigned int randomspawn = static_cast<unsigned int>(rnd(static_cast<float>(this->spawnpoints_.size()))); 312 313 unsigned int index = 0; 314 std::set<SpawnPoint*> activeSpawnPoints = this->spawnpoints_; 313 315 for (std::set<SpawnPoint*>::const_iterator it = this->spawnpoints_.begin(); it != this->spawnpoints_.end(); ++it) 316 { 317 if (index == randomspawn) 318 fallbackSpawnPoint = (*it); 319 320 if (!(*it)->isActive()) 321 activeSpawnPoints.erase(*it); 322 323 ++index; 324 } 325 326 randomspawn = static_cast<unsigned int>(rnd(static_cast<float>(this->spawnpoints_.size()))); 327 index = 0; 328 for (std::set<SpawnPoint*>::const_iterator it = activeSpawnPoints.begin(); it != activeSpawnPoints.end(); ++it) 314 329 { 315 330 if (index == randomspawn) … … 318 333 ++index; 319 334 } 335 336 return fallbackSpawnPoint; 320 337 } 321 338 return 0; -
code/trunk/src/orxonox/gametypes/TeamDeathmatch.cc
r6417 r7163 137 137 } 138 138 139 SpawnPoint* fallbackSpawnPoint = NULL; 139 140 if (teamSpawnPoints.size() > 0) 140 141 { 141 142 unsigned int randomspawn = static_cast<unsigned int>(rnd(static_cast<float>(teamSpawnPoints.size()))); 142 143 unsigned int index = 0; 144 // Get random fallback spawnpoint in case there is no active SpawnPoint. 145 for (std::set<SpawnPoint*>::const_iterator it = teamSpawnPoints.begin(); it != teamSpawnPoints.end(); ++it) 146 { 147 if (index == randomspawn) 148 { 149 fallbackSpawnPoint = (*it); 150 break; 151 } 152 153 ++index; 154 } 155 156 // Remove all inactive SpawnPoints from the list. 157 for (std::set<SpawnPoint*>::const_iterator it = teamSpawnPoints.begin(); it != teamSpawnPoints.end(); ) 158 { 159 if(!(*it)->isActive()) 160 { 161 teamSpawnPoints.erase(it++); 162 continue; 163 } 164 165 ++it; 166 } 167 168 randomspawn = static_cast<unsigned int>(rnd(static_cast<float>(teamSpawnPoints.size()))); 169 index = 0; 143 170 for (std::set<SpawnPoint*>::const_iterator it = teamSpawnPoints.begin(); it != teamSpawnPoints.end(); ++it) 144 171 { … … 148 175 ++index; 149 176 } 177 178 return fallbackSpawnPoint; 150 179 } 151 180 -
code/trunk/src/orxonox/graphics/Backlight.h
r5781 r7163 45 45 46 46 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 47 void registerVariables();48 47 49 48 virtual void tick(float dt); … … 81 80 82 81 private: 82 void registerVariables(); 83 83 virtual void startturnonoff(); 84 84 virtual void stopturnonoff(); -
code/trunk/src/orxonox/graphics/Billboard.h
r5781 r7163 46 46 47 47 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 48 void registerVariables();49 48 50 49 virtual void changedVisibility(); … … 78 77 79 78 private: 79 void registerVariables(); 80 80 void changedMaterial(); 81 81 // void changedRotation(); -
code/trunk/src/orxonox/graphics/BlinkingBillboard.cc
r6417 r7163 66 66 void BlinkingBillboard::registerVariables() 67 67 { 68 // registerVariable(this->amplitude_, VariableDirection::ToClient); 69 // registerVariable(this->frequency_, VariableDirection::ToClient); 70 // registerVariable(this->phase_, VariableDirection::ToClient); 68 unregisterVariable(this->getScale3D()); 69 registerVariable(this->amplitude_, VariableDirection::ToClient); 70 registerVariable(this->frequency_, VariableDirection::ToClient); 71 registerVariable(this->phase_, VariableDirection::ToClient); 72 registerVariable(this->bQuadratic_, VariableDirection::ToClient); 71 73 } 72 74 … … 75 77 SUPER(BlinkingBillboard, tick, dt); 76 78 77 if ( GameMode::isMaster() &&this->isActive())79 if (this->isActive()) 78 80 { 79 81 this->time_ += dt; -
code/trunk/src/orxonox/graphics/BlinkingBillboard.h
r5781 r7163 45 45 46 46 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 47 void registerVariables();48 47 49 48 virtual void tick(float dt); … … 70 69 71 70 private: 71 void registerVariables(); 72 72 73 float amplitude_; 73 74 float frequency_; -
code/trunk/src/orxonox/graphics/CMakeLists.txt
r5929 r7163 4 4 FadingBillboard.cc 5 5 GlobalShader.cc 6 MeshLodInformation.cc 6 7 Model.cc 8 AnimatedModel.cc 7 9 ParticleEmitter.cc 8 10 ParticleSpawner.cc -
code/trunk/src/orxonox/graphics/Camera.cc
r6501 r7163 111 111 SUPER(Camera, tick, dt); 112 112 113 if (this->bDrag_ )113 if (this->bDrag_ && this->getTimeFactor() != 0) 114 114 { 115 115 // this stuff here may need some adjustments -
code/trunk/src/orxonox/graphics/FadingBillboard.h
r5929 r7163 46 46 47 47 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 48 void registerVariables();49 48 50 49 virtual void tick(float dt); … … 66 65 67 66 protected: 67 void registerVariables(); 68 68 virtual void startturnonoff(); 69 69 virtual void stopturnonoff(); -
code/trunk/src/orxonox/graphics/GlobalShader.h
r5781 r7163 45 45 46 46 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 47 void registerVariables();48 47 49 48 virtual void changedVisibility(); … … 53 52 54 53 private: 54 void registerVariables(); 55 55 void changedCompositor(); 56 56 -
code/trunk/src/orxonox/graphics/Light.h
r5781 r7163 57 57 58 58 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 59 void registerVariables();60 59 61 60 virtual void changedVisibility(); … … 132 131 133 132 private: 133 void registerVariables(); 134 134 void setTypeString(const std::string& type); 135 135 std::string getTypeString() const; -
code/trunk/src/orxonox/graphics/Model.cc
r5781 r7163 35 35 #include "core/XMLPort.h" 36 36 #include "Scene.h" 37 #include "graphics/MeshLodInformation.h" 38 #include "Level.h" 37 39 38 40 namespace orxonox … … 40 42 CreateFactory(Model); 41 43 42 Model::Model(BaseObject* creator) : StaticEntity(creator) 44 Model::Model(BaseObject* creator) : 45 StaticEntity(creator), bCastShadows_(true), lodLevel_(5), bLodEnabled_(true), numLodLevels_(10), lodReductionRate_(.15) 43 46 { 44 47 RegisterObject(Model); 45 46 this->bCastShadows_ = true;47 48 48 49 this->registerVariables(); … … 59 60 SUPER(Model, XMLPort, xmlelement, mode); 60 61 62 XMLPortParam(Model, "lodLevel", setLodLevel, getLodLevel, xmlelement, mode); 63 61 64 XMLPortParam(Model, "mesh", setMeshSource, getMeshSource, xmlelement, mode); 62 65 XMLPortParam(Model, "shadow", setCastShadows, getCastShadows, xmlelement, mode).defaultValues(true); … … 67 70 registerVariable(this->meshSrc_, VariableDirection::ToClient, new NetworkCallback<Model>(this, &Model::changedMesh)); 68 71 registerVariable(this->bCastShadows_, VariableDirection::ToClient, new NetworkCallback<Model>(this, &Model::changedShadows)); 72 } 73 74 float Model::getBiggestScale(Vector3 scale3d) 75 { 76 float scaleFactor = scale3d.x; 77 if(scale3d.y>scaleFactor) 78 scaleFactor = scale3d.y; 79 if(scale3d.z>scaleFactor) 80 scaleFactor = scale3d.z; 81 return scaleFactor; 69 82 } 70 83 … … 83 96 this->mesh_.getEntity()->setCastShadows(this->bCastShadows_); 84 97 this->mesh_.setVisible(this->isVisible()); 98 99 100 //LOD 101 if( this->mesh_.getEntity()->getMesh()->getNumLodLevels()==1 ) 102 { 103 Level* level = this->getLevel(); 104 105 assert( level != 0 ); 106 107 MeshLodInformation* lodInfo = level->getLodInfo(this->meshSrc_); 108 if( lodInfo ) 109 { 110 setLodLevel(lodInfo->getLodLevel()); 111 this->bLodEnabled_ = lodInfo->getEnabled(); 112 this->numLodLevels_ = lodInfo->getNumLevels(); 113 this->lodReductionRate_ = lodInfo->getReductionRate(); 114 } 115 if( this->numLodLevels_>10 ) 116 { 117 CCOUT(2) << "More than 10 LoD levels requested. Creating only 10." << endl; 118 this->numLodLevels_ = 10; 119 } 120 if( this->bLodEnabled_ ) 121 { 122 float volume = this->mesh_.getEntity()->getBoundingBox().volume(); 123 // float scaleFactor = 1; 124 125 // BaseObject* creatorPtr = this; 126 // 127 // while(creatorPtr!=NULL&&orxonox_cast<WorldEntity*>(creatorPtr)) 128 // { 129 // scaleFactor *= getBiggestScale(((WorldEntity*) creatorPtr)->getScale3D()); 130 // creatorPtr = creatorPtr->getCreator(); 131 // } 132 // COUT(0) << "name: " << this->meshSrc_ << "scaleFactor: " << scaleFactor << ", volume: " << volume << endl; 133 134 COUT(4) << "Setting lodLevel for " << this->meshSrc_<< " with lodLevel_: " << this->lodLevel_ <<" and volume: "<< volume << ":" << std::endl; 135 136 #if OGRE_VERSION >= 0x010700 137 Ogre::Mesh::LodValueList distList; 138 #else 139 Ogre::Mesh::LodDistanceList distList; 140 #endif 141 142 if( lodLevel_>0 ) 143 { 144 // float factor = scaleFactor*5/lodLevel_; 145 float factor = pow(volume, 2.0f / 3.0f) * 15.0f / lodLevel_; 146 147 COUT(4) << "LodLevel set with factor: " << factor << endl; 148 149 distList.push_back(70.0f*factor); 150 distList.push_back(140.0f*factor); 151 distList.push_back(170.0f*factor); 152 distList.push_back(200.0f*factor); 153 distList.push_back(230.0f*factor); 154 distList.push_back(250.0f*factor); 155 distList.push_back(270.0f*factor); 156 distList.push_back(290.0f*factor); 157 distList.push_back(310.0f*factor); 158 distList.push_back(330.0f*factor); 159 while(distList.size()>this->numLodLevels_) 160 distList.pop_back(); 161 162 163 //Generiert LOD-Levels 164 this->mesh_.getEntity()->getMesh()->generateLodLevels(distList, Ogre::ProgressiveMesh::VRQ_PROPORTIONAL, this->lodReductionRate_); 165 } 166 else 167 { 168 std::string what; 169 if(lodLevel_>5) 170 what = ">5"; 171 else 172 what = "<0"; 173 174 COUT(4)<<"LodLevel not set because lodLevel("<<lodLevel_<<") was "<<what<<"." << endl; 175 } 176 } 177 else 178 COUT(4) << "LodLevel for " << this->meshSrc_ << " not set because is disabled." << endl; 179 } 85 180 } 86 181 } -
code/trunk/src/orxonox/graphics/Model.h
r5781 r7163 45 45 46 46 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 47 void registerVariables();48 47 49 48 virtual void changedVisibility(); … … 62 61 { return this->bCastShadows_; } 63 62 64 private: 63 protected: 64 void registerVariables(); 65 65 void changedMesh(); 66 66 void changedShadows(); 67 68 //LoD 69 inline void setLodLevel(float lodLevel) 70 { this->lodLevel_ = lodLevel; } 71 inline float getLodLevel() const 72 { return this->lodLevel_; } 73 float getBiggestScale(Vector3 scale3d); 67 74 68 75 std::string meshSrc_; 69 76 Mesh mesh_; 70 77 bool bCastShadows_; 78 79 //LoD 80 float lodLevel_; 81 bool bLodEnabled_; 82 unsigned int numLodLevels_; 83 float lodReductionRate_; 84 71 85 }; 72 86 } -
code/trunk/src/orxonox/graphics/ParticleEmitter.h
r5781 r7163 44 44 45 45 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 46 void registerVariables();47 46 48 47 virtual void changedVisibility(); … … 74 73 std::string source_; 75 74 LODParticle::Value LOD_; 75 76 private: 77 void registerVariables(); 76 78 }; 77 79 } -
code/trunk/src/orxonox/infos/GametypeInfo.cc
r5781 r7163 42 42 registerMemberNetworkFunction(GametypeInfo, dispatchKillMessage); 43 43 registerMemberNetworkFunction(GametypeInfo, dispatchDeathMessage); 44 registerMemberNetworkFunction(GametypeInfo, dispatchStaticMessage); 45 registerMemberNetworkFunction(GametypeInfo, dispatchFadingMessage); 44 46 45 47 GametypeInfo::GametypeInfo(BaseObject* creator) : Info(creator) … … 110 112 } 111 113 114 void GametypeInfo::sendStaticMessage(const std::string& message, unsigned int clientID, const ColourValue& colour) 115 { 116 if (GameMode::isMaster()) 117 { 118 if (clientID == CLIENTID_SERVER) 119 this->dispatchStaticMessage(message, colour); 120 else 121 callMemberNetworkFunction(GametypeInfo, dispatchStaticMessage, this->getObjectID(), clientID, message, colour); 122 } 123 } 124 125 void GametypeInfo::sendFadingMessage(const std::string& message, unsigned int clientID) 126 { 127 if (GameMode::isMaster()) 128 { 129 if (clientID == CLIENTID_SERVER) 130 this->dispatchFadingMessage(message); 131 else 132 callMemberNetworkFunction(GametypeInfo, dispatchFadingMessage, this->getObjectID(), clientID, message); 133 } 134 } 135 112 136 void GametypeInfo::dispatchAnnounceMessage(const std::string& message) 113 137 { … … 127 151 it->deathmessage(this, message); 128 152 } 153 154 void GametypeInfo::dispatchStaticMessage(const std::string& message, const ColourValue& colour) 155 { 156 for (ObjectList<GametypeMessageListener>::iterator it = ObjectList<GametypeMessageListener>::begin(); it != ObjectList<GametypeMessageListener>::end(); ++it) 157 it->staticmessage(this, message, colour); 158 } 159 160 void GametypeInfo::dispatchFadingMessage(const std::string& message) 161 { 162 for (ObjectList<GametypeMessageListener>::iterator it = ObjectList<GametypeMessageListener>::begin(); it != ObjectList<GametypeMessageListener>::end(); ++it) 163 it->fadingmessage(this, message); 164 } 129 165 } -
code/trunk/src/orxonox/infos/GametypeInfo.h
r5781 r7163 45 45 virtual ~GametypeInfo(); 46 46 47 void registerVariables();48 49 47 inline bool hasStarted() const 50 48 { return this->bStarted_; } … … 64 62 void sendKillMessage(const std::string& message, unsigned int clientID); 65 63 void sendDeathMessage(const std::string& message, unsigned int clientID); 64 void sendStaticMessage(const std::string& message, unsigned int clientID, const ColourValue& colour); 65 void sendFadingMessage(const std::string& message, unsigned int clientID); 66 66 67 67 void dispatchAnnounceMessage(const std::string& message); 68 68 void dispatchKillMessage(const std::string& message); 69 69 void dispatchDeathMessage(const std::string& message); 70 void dispatchStaticMessage(const std::string& message,const ColourValue& colour); 71 void dispatchFadingMessage(const std::string& message); 70 72 71 73 private: 74 void registerVariables(); 75 72 76 bool bStarted_; 73 77 bool bEnded_; -
code/trunk/src/orxonox/infos/HumanPlayer.h
r5781 r7163 43 43 virtual ~HumanPlayer(); 44 44 45 void registerVariables();46 45 void setConfigValues(); 47 46 … … 101 100 std::string gametypeHudTemplate_; 102 101 OverlayGroup* gametypeHud_; 102 private: 103 void registerVariables(); 103 104 }; 104 105 } -
code/trunk/src/orxonox/infos/PlayerInfo.cc
r6417 r7163 177 177 return; 178 178 179 // assert( this->temporaryControllableEntity_==0 );179 assert( this->oldControllableEntity_==0 ); 180 180 181 181 this->oldControllableEntity_ = this->controllableEntity_; … … 184 184 185 185 entity->setPlayer(this); 186 entity->setController(this->controller_); 186 187 187 188 if (this->controller_) … … 222 223 return; 223 224 225 this->controllableEntity_->setController(0); 226 224 227 this->controllableEntity_ = this->oldControllableEntity_; 225 228 this->controllableEntityID_ = this->controllableEntity_->getObjectID(); -
code/trunk/src/orxonox/infos/PlayerInfo.h
r6417 r7163 35 35 #include "core/SubclassIdentifier.h" 36 36 37 namespace orxonox 38 { 39 class _OrxonoxExport PlayerInfo : public Info 40 { 37 namespace orxonox // tolua_export 38 { // tolua_export 39 class _OrxonoxExport PlayerInfo // tolua_export 40 : public Info 41 { // tolua_export 41 42 public: 42 43 PlayerInfo(BaseObject* creator); 43 44 virtual ~PlayerInfo(); 44 45 void registerVariables();46 45 47 46 virtual void changedName(); … … 91 90 92 91 private: 92 void registerVariables(); 93 93 void networkcallback_changedcontrollableentityID(); 94 94 void networkcallback_changedgtinfoID(); … … 103 103 const GametypeInfo* gtinfo_; 104 104 unsigned int gtinfoID_; 105 }; 106 } 105 }; // tolua_export 106 } // tolua_export 107 107 108 108 #endif /* _PlayerInfo_H__ */ -
code/trunk/src/orxonox/interfaces/GametypeMessageListener.h
r5781 r7163 44 44 virtual void killmessage(const GametypeInfo* gtinfo, const std::string& message) {} 45 45 virtual void deathmessage(const GametypeInfo* gtinfo, const std::string& message) {} 46 virtual void staticmessage(const GametypeInfo* gtinfo, const std::string& message, const ColourValue& colour) {} 47 virtual void fadingmessage(const GametypeInfo* gtinfo, const std::string& message) {} 46 48 }; 47 49 } -
code/trunk/src/orxonox/interfaces/InterfaceCompilation.cc
r6711 r7163 52 52 RegisterRootObject(GametypeMessageListener); 53 53 } 54 54 55 55 //---------------------------- 56 56 // PickupCarrier … … 59 59 { 60 60 RegisterRootObject(PickupCarrier); 61 62 this->setCarrierName("PickupCarrier");63 61 } 64 62 65 63 PickupCarrier::~PickupCarrier() 66 64 { 65 66 } 67 68 void PickupCarrier::preDestroy(void) 69 { 67 70 std::set<Pickupable*>::iterator it = this->pickups_.begin(); 71 std::set<Pickupable*>::iterator temp; 68 72 while(it != this->pickups_.end()) 69 73 { 70 (*(it++))->destroy(); 74 (*it)->carrierDestroyed(); 75 temp = it; 76 it = this->pickups_.begin(); 77 if(it == temp) // Infinite loop avoidance, in case the pickup wasn't removed from the carrier somewhere in the carrierDestroy() procedure. 78 { 79 COUT(2) << "Oops. In a PickupCarrier, while cleaning up, a Pickupable (&" << (*temp) << ") didn't unregister itself as it should have." << std::endl;; 80 it++; 81 } 71 82 } 72 83 … … 84 95 this->isForPlayer_ = true; 85 96 } 86 97 87 98 //---------------------------- 88 99 // RadarListener -
code/trunk/src/orxonox/interfaces/NotificationListener.h
r5929 r7163 47 47 class Notification; 48 48 49 /** 50 @brief 51 NotificationListener interface. 52 @author 53 Fabian 'x3n' Landau 54 */ 49 55 class _OrxonoxExport NotificationListener : virtual public OrxonoxClass 50 56 { -
code/trunk/src/orxonox/interfaces/PickupCarrier.h
- Property svn:eol-style set to native
r6711 r7163 45 45 #include "core/OrxonoxClass.h" 46 46 47 namespace orxonox // tolua_export48 { // tolua_export47 namespace orxonox 48 { 49 49 50 50 //! Forward-declarations. … … 54 54 class InvisiblePickup; 55 55 class MetaPickup; 56 class DronePickup; 56 57 class SpeedPickup; 57 58 … … 62 63 Damian 'Mozork' Frick 63 64 */ 64 class _OrxonoxExport PickupCarrier // tolua_export 65 : virtual public OrxonoxClass 66 { // tolua_export 65 class _OrxonoxExport PickupCarrier : virtual public OrxonoxClass 66 { 67 67 //! So that the different Pickupables have full access to their PickupCarrier. 68 68 friend class Pickupable; 69 69 friend class PickupManager; 70 //! Friends. 70 //! Friends. 71 71 friend class Pickup; 72 72 friend class HealthPickup; 73 73 friend class InvisiblePickup; 74 74 friend class MetaPickup; 75 friend class DronePickup; 75 76 friend class SpeedPickup; 76 77 … … 78 79 PickupCarrier(); //!< Constructor. 79 80 virtual ~PickupCarrier(); //!< Destructor. 80 81 /** 82 @brief Can be called to pick up a Pickupable. 83 @param pickup A pointer to the Pickupable. 84 @return Returns true if the Pickupable was picked up, false if not. 85 */ 86 bool pickup(Pickupable* pickup) 87 { 88 bool pickedUp = this->pickups_.insert(pickup).second; 89 if(pickedUp) 90 { 91 COUT(4) << "Picked up Pickupable " << pickup->getIdentifier()->getName() << "(&" << pickup << ")." << std::endl; 92 pickup->pickedUp(this); 93 } 94 return pickedUp; 95 } 96 97 /** 98 @brief Can be called to drop a Pickupable. 99 @param pickup A pointer to the Pickupable. 100 @param drop If the Pickupable should just be removed from the PickupCarrier without further action, this can be set to false. true is default. 101 @return Returns true if the Pickupable has been dropped, false if not. 102 */ 103 bool drop(Pickupable* pickup, bool drop = true) 104 { 105 bool dropped = this->pickups_.erase(pickup) == 1; 106 if(dropped && drop) 107 { 108 COUT(4) << "Dropping Pickupable " << pickup->getIdentifier()->getName() << "(&" << pickup << ")." << std::endl; 109 pickup->dropped(); 110 } 111 return dropped; 112 } 81 void preDestroy(void); 113 82 114 83 /** … … 169 138 */ 170 139 virtual const Vector3& getCarrierPosition(void) = 0; 171 172 /** 173 @brief Get the name of this PickupCarrier. 174 @return Returns the name as a string. 175 */ 176 const std::string& getCarrierName(void) { return this->carrierName_; } // tolua_export 177 178 protected: 140 141 protected: 179 142 /** 180 143 @brief Get all direct children of this PickupSpawner. … … 197 160 std::set<Pickupable*>& getPickups(void) 198 161 { return this->pickups_; } 199 200 /** 201 @brief Set the name of this PickupCarrier. 202 The name needs to be set in the constructor of every class inheriting from PickupCarrier, by calling setCarrierName(). 203 @param name The name to be set. 204 */ 205 void setCarrierName(const std::string& name) 206 { this->carrierName_ = name; } 207 162 208 163 private: 209 164 std::set<Pickupable*> pickups_; //!< The list of Pickupables carried by this PickupCarrier. 210 std::string carrierName_; //!< The name of the PickupCarrier, as displayed in the PickupInventory. 211 165 212 166 /** 213 @brief Get the number of carrier children this PickupCarrier has. 214 @return Returns the number of carrier children. 167 @brief Adds a Pickupable to the list of pickups that are carried by this PickupCarrier. 168 @param pickup A pointer to the pickup to be added. 169 @return Returns true if successfull, false if the Pickupable was already present. 215 170 */ 216 unsigned int getNumCarrierChildren(void)171 bool addPickup(Pickupable* pickup) 217 172 { 218 std::vector<PickupCarrier*>* list = this->getCarrierChildren(); 219 unsigned int size = list->size(); 220 delete list; 221 return size; 173 COUT(4) << "Adding Pickupable (&" << pickup << ") to PickupCarrier (&" << this << ")" << std::endl; 174 return this->pickups_.insert(pickup).second; 222 175 } 223 176 224 177 /** 225 @brief Get the index-th child of thisPickupCarrier.226 @param index The index of the child to return.227 @return Returns t he index-th child.178 @brief Removes a Pickupable from the list of pickups that are carried by thsi PickupCarrier. 179 @param pickup A pointer to the pickup to be removed. 180 @return Returns true if successfull, false if the Pickupable was not present in the list. 228 181 */ 229 PickupCarrier* getCarrierChild(unsigned int index)182 bool removePickup(Pickupable* pickup) 230 183 { 231 std::vector<PickupCarrier*>* list = this->getCarrierChildren(); 232 if(list->size() < index) 233 return NULL; 234 PickupCarrier* carrier = (*list)[index]; 235 delete list; 236 return carrier; 184 COUT(4) << "Removing Pickupable (&" << pickup << ") from PickupCarrier (&" << this << ")" << std::endl; 185 return this->pickups_.erase(pickup) == 1; 237 186 } 238 239 /** 240 @brief Get the number of Pickupables this PickupCarrier carries. 241 @return returns the number of pickups. 242 */ 243 unsigned int getNumPickups(void) 244 { return this->pickups_.size(); } 245 246 /** 247 @brief Get the index-th Pickupable of this PickupCarrier. 248 @param index The index of the Pickupable to return. 249 @return Returns the index-th pickup. 250 */ 251 Pickupable* getPickup(unsigned int index) 252 { 253 std::set<Pickupable*>::iterator it; 254 for(it = this->pickups_.begin(); index != 0 && it != this->pickups_.end(); it++) 255 index--; 256 if(it == this->pickups_.end()) 257 return NULL; 258 return *it; 259 } 260 261 }; // tolua_export 262 } // tolua_export 187 188 }; 189 } 263 190 264 191 #endif /* _PickupCarrier_H__ */ -
code/trunk/src/orxonox/interfaces/Pickupable.cc
- Property svn:eol-style set to native
r6901 r7163 34 34 #include "Pickupable.h" 35 35 36 #include "core/LuaState.h" 37 #include "core/GUIManager.h" 36 38 #include "core/Identifier.h" 37 39 #include "core/CoreIncludes.h" 40 #include "util/Convert.h" 41 #include "infos/PlayerInfo.h" 38 42 #include "pickup/PickupIdentifier.h" 43 #include "worldentities/pawns/Pawn.h" 39 44 #include "PickupCarrier.h" 40 45 41 46 namespace orxonox 42 47 { 43 48 44 49 /** 45 50 @brief … … 47 52 */ 48 53 Pickupable::Pickupable() : pickupIdentifier_(NULL), used_(false), pickedUp_(false) 49 { 54 { 50 55 RegisterRootObject(Pickupable); 51 56 52 57 this->carrier_ = NULL; 53 58 54 59 this->pickupIdentifier_ = new PickupIdentifier(this); 55 } 56 57 /** 58 @brief 59 Destructor. 60 this->beingDestroyed_ = false; 61 this->enabled_ = true; 62 } 63 64 /** 65 @brief 66 Destructor. 60 67 */ 61 68 Pickupable::~Pickupable() 62 69 { 63 if(this->isUsed()) 64 this->setUsed(false); 65 66 if(this->isPickedUp() && this->getCarrier() != NULL) 67 { 68 this->getCarrier()->drop(this, false); 69 this->setCarrier(NULL); 70 } 71 70 COUT(4) << "Pickupable (" << this->getIdentifier()->getName() << ") (&" << this << ") destroyed." << std::endl; 72 71 if(this->pickupIdentifier_ != NULL) 73 72 this->pickupIdentifier_->destroy(); 74 73 } 75 74 75 /** 76 @brief 77 A method that is called by OrxonoxClass::destroy() before the object is actually destroyed. 78 */ 79 void Pickupable::preDestroy(void) 80 { 81 this->beingDestroyed_ = true; 82 83 if(this->isPickedUp()) 84 this->drop(false); // Drops the pickup without creating a PickupSpawner. 85 } 86 87 /** 88 @brief 89 Is called internally within the pickup module to destroy pickups. 90 */ 91 void Pickupable::destroy(void) 92 { 93 this->destroyPickup(); 94 } 95 96 /** 97 @brief 98 Destroys a Pickupable. 99 If the Pickupable is already in the process of being destroyed a warning is displayed and this method is skipped. 100 */ 101 void Pickupable::destroyPickup(void) 102 { 103 if(!this->beingDestroyed_) 104 this->OrxonoxClass::destroy(); 105 else 106 COUT(2) << this->getIdentifier()->getName() << " may be unsafe. " << std::endl; 107 } 108 76 109 /** 77 110 @brief … … 84 117 bool Pickupable::setUsed(bool used) 85 118 { 86 if(this->used_ == used) 87 return false; 88 119 if(this->used_ == used || !this->isPickedUp()) // If either the used status of the Pickupable doesn't change or it isn't picked up. 120 return false; 121 122 if((!this->isUsable() && used) || (!this->isUnusable() && !used)) // If either the Pickupable is requested to be used but it is not usable or the Pickupable is requested to be unused, while it is not unusable. 123 return false; 124 89 125 COUT(4) << "Pickupable (&" << this << ") set to used " << used << "." << std::endl; 90 126 91 127 this->used_ = used; 92 128 this->changedUsed(); 93 return true; 94 } 95 129 130 GUIManager::getInstance().getLuaState()->doString("PickupInventory.update()"); 131 return true; 132 } 133 96 134 /** 97 135 @brief … … 106 144 if(carrier == NULL) 107 145 return false; 146 108 147 return this->isTarget(carrier->getIdentifier()); 109 148 } 110 149 111 150 /** 112 151 @brief … … 125 164 return true; 126 165 } 166 127 167 return false; 128 168 } 129 169 130 170 /** 131 171 @brief … … 140 180 return this->addTarget(target->getIdentifier()); 141 181 } 142 182 143 183 /** 144 184 @brief … … 153 193 if(this->isTarget(target)) //!< If the input target is already present in the list of targets. 154 194 return false; 155 195 156 196 COUT(4) << "Target " << target->getName() << " added to Pickupable (&" << this << ")." << std::endl; 157 197 this->targets_.push_back(target); 158 198 return true; 159 199 } 160 161 /** 162 @brief 163 Sets the Pickupable to picked up. 164 This method will be called by the PickupCarrier picking the Pickupable up. 200 201 /** 202 @brief 203 Can be called to pick up a Pickupable. 165 204 @param carrier 166 The PickupCarrier that picked the Pickupable up. 167 @return 168 Returns false if, for some reason, the pickup could not be picked up, e.g. it was picked up already. 169 */ 170 bool Pickupable::pickedUp(PickupCarrier* carrier) 171 { 172 if(this->isPickedUp()) //!< If the Pickupable is already picked up. 173 return false; 205 A pointer to the PickupCarrier that picks up the Pickupable. 206 @return 207 Returns true if the Pickupable was picked up, false if not. 208 */ 209 bool Pickupable::pickup(PickupCarrier* carrier) 210 { 211 if(carrier == NULL || this->isPickedUp()) //!< If carrier is NULL or the Pickupable is already picked up. 212 return false; 213 214 if(!this->setCarrier(carrier)) 215 { 216 COUT(3) << "A Pickupable (&" << this << ") was trying to be added to a PickupCarrier, but was already present." << std::endl; 217 return false; 218 } 174 219 220 this->setPickedUp(true); 175 221 COUT(4) << "Pickupable (&" << this << ") got picked up by a PickupCarrier (&" << carrier << ")." << std::endl; 176 this->setCarrier(carrier); 177 this->setPickedUp(true); 178 return true; 179 } 180 222 return true; 223 } 224 225 /** 226 @brief 227 Can be called to drop a Pickupable. 228 @param createSpawner 229 If true a spawner is to be created for the dropped Pickupable. True is default. 230 @return 231 Returns true if the Pickupable has been dropped, false if not. 232 */ 233 bool Pickupable::drop(bool createSpawner) 234 { 235 if(!this->isPickedUp()) // If the Pickupable is not picked up. 236 return false; 237 238 assert(this->getCarrier()); // The Carrier cannot be NULL at this point. 239 if(!this->getCarrier()->removePickup(this)) //TODO Shouldn't this be a little later? 240 COUT(2) << "Pickupable (&" << this << ", " << this->getIdentifier()->getName() << ") is being dropped, but it was not present in the PickupCarriers list of pickups." << std::endl; 241 242 COUT(4) << "Pickupable (&" << this << ") got dropped up by a PickupCarrier (&" << this->getCarrier() << ")." << std::endl; 243 this->setUsed(false); 244 this->setPickedUp(false); 245 246 bool created = false; 247 if(createSpawner) 248 created = this->createSpawner(); 249 250 this->setCarrier(NULL); 251 252 if(!created && createSpawner) // If a PickupSpawner should have been created but wasn't. 253 this->destroy(); 254 255 return true; 256 } 257 181 258 /** 182 259 @brief … … 189 266 bool Pickupable::setPickedUp(bool pickedUp) 190 267 { 191 if(this->pickedUp_ == pickedUp) 192 return false; 193 268 if(this->pickedUp_ == pickedUp) // If the picked up status has not changed. 269 return false; 270 194 271 COUT(4) << "Pickupable (&" << this << ") set to pickedUp " << pickedUp << "." << std::endl; 195 272 196 273 this->pickedUp_ = pickedUp; 274 if(!pickedUp) // if the Pickupable has been dropped it unregisters itself with its PickupCarrier. 275 this->getCarrier()->removePickup(this); 197 276 this->changedPickedUp(); 198 return true; 199 } 200 277 GUIManager::getInstance().getLuaState()->doString("PickupInventory.update()"); 278 return true; 279 } 280 201 281 /** 202 282 @brief … … 204 284 @param carrier 205 285 Sets the input PickupCarrier as the carrier of the pickup. 206 */ 207 inline bool Pickupable::setCarrier(PickupCarrier* carrier) 208 { 209 if(this->carrier_ == carrier) 210 return false; 211 286 @param tell 287 If true (default) the pickup is added to the list of pickups in the PickupCarrier. 288 @return 289 Returns true if successful, false if not. 290 */ 291 bool Pickupable::setCarrier(orxonox::PickupCarrier* carrier, bool tell) 292 { 293 if(this->carrier_ == carrier) // If the PickupCarrier doesn't change. 294 return false; 295 212 296 COUT(4) << "Pickupable (&" << this << ") changed Carrier (& " << carrier << ")." << std::endl; 297 298 if(carrier != NULL && tell) 299 { 300 if(!carrier->addPickup(this)) 301 return false; 302 } 213 303 214 304 this->carrier_ = carrier; … … 216 306 return true; 217 307 } 218 219 /** 220 @brief 221 Sets the Pickupable to not picked up or dropped. 222 This method will be called by the PickupCarrier dropping the Pickupable. 223 @return 224 Returns false if the pickup could not be dropped. 225 */ 226 bool Pickupable::dropped(void) 227 { 228 if(!this->isPickedUp()) //!< If the Pickupable is not picked up. 229 return false; 230 231 COUT(4) << "Pickupable (&" << this << ") got dropped up by a PickupCarrier (&" << this->getCarrier() << ")." << std::endl; 232 this->setUsed(false); 233 this->setPickedUp(false); 234 235 bool created = this->createSpawner(); 236 237 this->setCarrier(NULL); 238 239 if(!created) 240 { 241 this->destroy(); 242 } 243 244 return true; 245 } 246 308 309 /** 310 @brief 311 Is called by the PickupCarrier when it is being destroyed. 312 */ 313 void Pickupable::carrierDestroyed(void) 314 { 315 this->destroy(); 316 } 317 247 318 /** 248 319 @brief … … 255 326 OrxonoxClass* item = NULL; 256 327 this->clone(item); 257 328 258 329 Pickupable* pickup = dynamic_cast<Pickupable*>(item); 259 330 260 331 COUT(4) << "Pickupable (&" << this << ") cloned. Clone is new Pickupable (&" << pickup << ")." << std::endl; 261 332 return pickup; 262 333 } 263 334 264 335 /** 265 336 @brief … … 273 344 SUPER(Pickupable, clone, item); 274 345 } 275 346 347 /** 348 @brief 349 Method to transcribe a Pickupable as a Rewardable to the player. 350 @param player 351 A pointer to the PlayerInfo, do whatever you want with it. 352 @return 353 Return true if successful. 354 */ 355 bool Pickupable::reward(PlayerInfo* player) 356 { 357 ControllableEntity* entity = player->getControllableEntity(); 358 Pawn* pawn = static_cast<Pawn*>(entity); 359 PickupCarrier* carrier = static_cast<PickupCarrier*>(pawn); 360 return this->pickup(carrier); 361 } 362 276 363 } -
code/trunk/src/orxonox/interfaces/Pickupable.h
- Property svn:eol-style set to native
r6901 r7163 41 41 42 42 #include "core/OrxonoxClass.h" 43 #include "Rewardable.h" 43 44 44 namespace orxonox 45 { 46 45 namespace orxonox // tolua_export 46 { // tolua_export 47 47 48 /** 48 49 @brief … … 51 52 Damian 'Mozork' Frick 52 53 */ 53 class _OrxonoxExport Pickupable : virtual public OrxonoxClass 54 { 54 class _OrxonoxExport Pickupable // tolua_export 55 : virtual public OrxonoxClass, public Rewardable 56 { // tolua_export 55 57 protected: 56 58 Pickupable(); //!< Default constructor. 57 59 58 60 public: 59 61 virtual ~Pickupable(); //!< Default destructor. 60 62 61 63 /** 62 64 @brief Get whether the pickup is currently in use or not. 63 65 @return Returns true if the pickup is currently in use. 64 66 */ 65 inline bool isUsed(void) 66 { return this->used_; } 67 inline bool isUsed(void) { return this->used_; } // tolua_export 67 68 /** 68 69 @brief Should be called when the pickup has transited from used to unused or the other way around. … … 70 71 */ 71 72 virtual void changedUsed(void) {} 72 73 73 74 /** 74 75 @brief Get the carrier of the pickup. … … 82 83 */ 83 84 virtual void changedCarrier(void) {} 84 85 85 86 /** 86 87 @brief Returns whether the Pickupable is currently picked up. 87 88 @return Returns true if the Pickupable is currently picked up, false if not. 88 89 */ 89 inline bool isPickedUp(void) 90 { return this->pickedUp_; } 90 inline bool isPickedUp(void) { return this->pickedUp_; } // tolua_export 91 91 /** 92 92 @brief Should be called when the pickup has transited from picked up to dropped or the other way around. … … 94 94 */ 95 95 virtual void changedPickedUp(void) {} 96 97 /** 98 @brief Returns whether the Pickupable can be used. 99 @return Returns true if it can be used. 100 */ 101 inline bool isUsable(void) { return this->enabled_; } // tolua_export 96 102 97 bool pickedUp(PickupCarrier* carrier); //!< Sets the Pickupable to picked up. 98 bool dropped(void); //!< Sets the Pickupable to not picked up or dropped. 99 103 /** 104 @brief Returns whether the Pickupable can be unused. 105 @return Returns true if it can be unused. 106 */ 107 inline bool isUnusable(void) { return this->enabled_; } // tolua_export 108 109 /** 110 @brief Returns whether the Pickupable is enabled. 111 Once a Pickupable is disabled it cannot be enabled again. A Pickupable that is disabled can neither be used nor unused. 112 @return Returns true if the Pickupable is enabled. 113 */ 114 inline bool isEnabled(void) 115 { return this->enabled_; } 116 117 bool pickup(PickupCarrier* carrier); //!< Can be called to pick up a Pickupable. 118 bool drop(bool createSpawner = true); //!< Can be called to drop a Pickupable. 119 100 120 virtual bool isTarget(PickupCarrier* carrier) const; //!< Get whether the given PickupCarrier is a target of this pickup. 101 121 bool isTarget(const Identifier* identifier) const; //!< Get whether a given class, represented by the input Identifier, is a target of this Pickupable. 102 122 bool addTarget(PickupCarrier* target); //!< Add a PickupCarrier as target of this pickup. 103 123 bool addTarget(Identifier* identifier); //!< Add a class, representetd by the input Identifier, as target of this pickup. 104 124 105 125 Pickupable* clone(void); //!< Creates a duplicate of the Pickupable. 106 126 virtual void clone(OrxonoxClass*& item); //!< Creates a duplicate of the input OrxonoxClass. 107 127 108 128 /** 109 129 @brief Get the PickupIdentifier of this Pickupable. … … 112 132 virtual const PickupIdentifier* getPickupIdentifier(void) 113 133 { return this->pickupIdentifier_; } 114 134 115 135 bool setUsed(bool used); //!< Sets the Pickupable to used or unused, depending on the input. 116 136 bool setPickedUp(bool pickedUp); //!< Helper method to set the Pickupable to either picked up or not picked up. 117 bool setCarrier(PickupCarrier* carrier); //!< Sets the carrier of the pickup. 118 137 //TODO: private? 138 bool setCarrier(PickupCarrier* carrier, bool tell = true); //!< Sets the carrier of the pickup. 139 140 //TODO: private? 141 virtual void carrierDestroyed(void); //!< Is called by the PickupCarrier when it is being destroyed. 142 143 void destroy(void); //!< Is called internally within the pickup module to destroy pickups. 144 119 145 protected: 120 146 /** … … 122 148 */ 123 149 void initializeIdentifier(void) {} 124 150 151 virtual void preDestroy(void); //!< A method that is called by OrxonoxClass::destroy() before the object is actually destroyed. 152 virtual void destroyPickup(void); //!< Destroys a Pickupable. 153 154 /** 155 @brief Sets the Pickuapble to disabled. 156 */ 157 inline void setDisabled(void) 158 { this->enabled_ = false; } 159 125 160 /** 126 161 @brief Facilitates the creation of a PickupSpawner upon dropping of the Pickupable. … … 131 166 */ 132 167 virtual bool createSpawner(void) = 0; 133 168 134 169 PickupIdentifier* pickupIdentifier_; //!< The PickupIdentifier of this Pickupable. 135 170 136 171 private: 137 138 bool used_; //!< Whether the pickup is currently in use or not.139 bool pickedUp_; //!< Whether the pickup is currently picked up or not.140 141 PickupCarrier* carrier_; //!< The carrier of the pickup.142 std::list<Identifier*> targets_; //!< The possible targets of this pickup.143 172 144 }; 145 173 bool used_; //!< Whether the Pickupable is currently in use or not. 174 bool pickedUp_; //!< Whether the Pickupable is currently picked up or not. 175 176 bool enabled_; //!< Whether the Pickupable is enabled or not. 177 178 PickupCarrier* carrier_; //!< The PickupCarrier of the Pickupable. 179 std::list<Identifier*> targets_; //!< The possible targets of this Pickupable. 180 181 bool beingDestroyed_; //!< Is true if the Pickupable is in the process of being destroyed. 182 183 // For implementing the Rewardable interface: 184 public: 185 virtual bool reward(PlayerInfo* player); //!< Method to transcribe a Pickupable as a Rewardable to the player. 186 187 }; // tolua_export 188 146 189 SUPER_FUNCTION(10, Pickupable, changedUsed, false); 147 190 SUPER_FUNCTION(12, Pickupable, changedCarrier, false); 148 191 SUPER_FUNCTION(13, Pickupable, changedPickedUp, false); 149 } 192 } // tolua_export 150 193 151 194 #endif /* _Pickupable_H__ */ -
code/trunk/src/orxonox/interfaces/RadarListener.h
r5781 r7163 41 41 virtual ~RadarListener() { } 42 42 43 virtual void displayObject(RadarViewable* viewable, bool bIsMarked) = 0; 43 virtual void addObject(RadarViewable* viewable) = 0; 44 virtual void removeObject(RadarViewable* viewable) = 0; 45 virtual void objectChanged(RadarViewable* viewable) = 0; 44 46 virtual float getRadarSensitivity() const = 0; 45 47 virtual void radarTick(float dt) = 0; -
code/trunk/src/orxonox/interfaces/RadarViewable.cc
r6417 r7163 29 29 #include "RadarViewable.h" 30 30 31 #include <OgreSceneManager.h>32 #include <OgreSceneNode.h>33 #include <OgreEntity.h>34 35 31 #include "util/StringUtils.h" 36 32 #include "core/CoreIncludes.h" 37 #include " tools/DynamicLines.h"33 #include "core/GameMode.h" 38 34 #include "worldentities/WorldEntity.h" 39 35 #include "Radar.h" 40 36 #include "Scene.h" 41 #include "overlays/Map.h"42 37 43 38 namespace orxonox … … 46 41 @brief Constructor. 47 42 */ 48 RadarViewable::RadarViewable() 49 : MapNode_(NULL) 50 , MapEntity_(NULL) 51 , line_(NULL) 52 , LineNode_(NULL) 53 , isHumanShip_(false) 43 RadarViewable::RadarViewable(BaseObject* creator, const WorldEntity* wePtr) 44 : isHumanShip_(false) 54 45 , bVisibility_(true) 46 , bInitialized_(false) 47 , creator_(creator) 48 , wePtr_(wePtr) 55 49 , radarObjectCamouflage_(0.0f) 56 50 , radarObjectShape_(Dot) … … 60 54 61 55 this->uniqueId_=getUniqueNumberString(); 62 /* 63 if(Map::getSingletonPtr() && Map::getSingletonPtr()->getMapSceneManagerPtr()) 56 if( GameMode::showsGraphics() ) 64 57 { 65 this->addEntity(); 58 this->radar_ = this->creator_->getScene()->getRadar(); 59 this->radar_->addRadarObject(this); 66 60 } 67 68 */ 61 this->bInitialized_ = true; 69 62 } 70 63 … … 72 65 RadarViewable::~RadarViewable() 73 66 { 74 if (this->isHumanShip_ && MapNode_)75 MapNode_->removeAllChildren();76 67 77 if (MapNode_) 78 delete MapNode_; 79 80 if (MapEntity_) 81 delete MapEntity_; 82 83 if (line_) 84 delete line_; 85 86 if (LineNode_) 87 delete LineNode_; 88 } 89 90 void RadarViewable::addMapEntity() 91 { //TODO Check shape and add accordantly 92 if( this->MapNode_ && !this->MapEntity_ && Map::getSingletonPtr() && Map::getSingletonPtr()->getMapSceneManagerPtr() ) 68 if( this->bInitialized_ ) 93 69 { 94 COUT(0) << "Adding " << this->uniqueId_ << " to Map.\n"; 95 this->MapEntity_ = Map::getSingletonPtr()->getMapSceneManagerPtr()->createEntity( this->uniqueId_, "drone.mesh"); 96 /*this->line_ = Map::getSingletonPtr()->getMapSceneManagerPtr()->createManualObject(this->uniqueId_ + "_l"); 97 this->line_->begin("Map/line_", Ogre::RenderOperation::OT_LINE_STRIP); 98 //line_->position(0, -it->getRVWorldPosition().y, 0); 99 //this->line_->position(0, -20, 0); 100 this->line_->position(0, 0, -10); //Front Arrow 101 this->line_->position(0, 0, 0); 102 103 this->line_->end(); */ 104 this->line_ = new Ogre::DynamicLines(Ogre::RenderOperation::OT_LINE_LIST); 105 this->line_->addPoint( Vector3(0,0,0) ); 106 this->line_->addPoint( Vector3(0,0,0) ); 107 108 this->MapNode_->attachObject( this->MapEntity_ ); 109 110 this->LineNode_ = this->MapNode_->createChildSceneNode(); 111 this->LineNode_->attachObject( this->line_ ); 112 } 113 else 114 { 115 COUT(0) << "Unable to load " << this->uniqueId_ << " to Map.\n"; 70 if( GameMode::showsGraphics() ) 71 { 72 this->radar_->removeRadarObject(this); 73 } 116 74 } 117 75 } 118 76 119 void RadarViewable::updateMapPosition() 120 { 121 if( this->MapNode_ ) 122 { 123 this->MapNode_->setPosition( this->getRVWorldPosition() ); 124 this->MapNode_->translate( this->getRVOrientedVelocity(), static_cast<Ogre::Node::TransformSpace>(3) ); 125 this->MapNode_->setOrientation( this->getWorldEntity()->getOrientation() ); 126 //Vector3 v = this->getRVWorldPosition(); 127 //this->line_->setPoint(1, Vector3(0,v.y,0) ); 128 this->line_->setPoint(1, Vector3( 0, static_cast<float>(static_cast<int>( -Map::getSingletonPtr()->movablePlane_->getDistance( this->getRVWorldPosition() ) ) ) ,0 )); 129 this->line_->update(); 130 if( Map::getSingletonPtr()->playerShipNode_ ) 131 this->LineNode_->setDirection( Map::getSingletonPtr()->playerShipNode_->getLocalAxes().GetColumn(1) ,Ogre::Node::TS_WORLD,Vector3::UNIT_Y); 132 } 133 } 134 135 void RadarViewable::setRadarObjectDescription(const std::string& str) 136 { 137 Radar* radar = this->getWorldEntity()->getScene()->getRadar(); 138 if (radar) 139 this->radarObjectShape_ = radar->addObjectDescription(str); 140 else 141 { 142 CCOUT(2) << "Attempting to access the radar, but the radar is non existent." << std::endl; 143 } 144 this->radarObjectDescription_ = str; 145 } 77 // void RadarViewable::setRadarObjectDescription(const std::string& str) 78 // { 79 // Radar* radar = this->getWorldEntity()->getScene()->getRadar(); 80 // if (radar) 81 // this->radarObjectShape_ = radar->addObjectDescription(str); 82 // else 83 // { 84 // CCOUT(2) << "Attempting to access the radar, but the radar is non existent." << std::endl; 85 // } 86 // this->radarObjectDescription_ = str; 87 // } 146 88 147 89 const Vector3& RadarViewable::getRVWorldPosition() const … … 167 109 } 168 110 } 111 112 void RadarViewable::settingsChanged() 113 { 114 if( GameMode::showsGraphics() ) 115 { 116 this->radar_->radarObjectChanged(this); 117 } 118 } 169 119 } -
code/trunk/src/orxonox/interfaces/RadarViewable.h
r5781 r7163 36 36 37 37 #include "util/Math.h" 38 #include "util/OgreForwardRefs.h"39 38 #include "core/OrxonoxClass.h" 39 #include "core/SmartPtr.h" 40 40 41 41 namespace orxonox 42 42 { 43 class BaseObject; 44 43 45 /** 44 46 @brief Interface for receiving window events. … … 56 58 57 59 public: 58 RadarViewable( );60 RadarViewable(BaseObject* creator, const WorldEntity* wePtr); 59 61 virtual ~RadarViewable(); 60 62 61 63 inline void setRadarObjectCamouflage(float camouflage) 62 { this->radarObjectCamouflage_ = camouflage; } 64 { 65 if( this->radarObjectCamouflage_ != camouflage ) 66 { 67 this->radarObjectCamouflage_ = camouflage; 68 this->settingsChanged(); 69 } 70 } 63 71 inline float getRadarObjectCamouflage() const 64 72 { return this->radarObjectCamouflage_; } 65 73 66 74 inline void setRadarObjectColour(const ColourValue& colour) 67 { this->radarObjectColour_ = colour; } 75 { 76 if(this->radarObjectColour_ != colour) 77 { 78 this->radarObjectColour_ = colour; 79 this->settingsChanged(); 80 } 81 } 68 82 inline const ColourValue& getRadarObjectColour() const 69 83 { return this->radarObjectColour_; } 70 84 71 void setRadarObjectDescription(const std::string& str);72 inline const std::string& getRadarObjectDescription() const73 { return this->radarObjectDescription_; }85 // void setRadarObjectDescription(const std::string& str); 86 // inline const std::string& getRadarObjectDescription() const 87 // { return this->radarObjectDescription_; } 74 88 75 89 inline void setRadarVisibility(bool b) 76 { this->bVisibility_ = b; } 90 { 91 if(b!=this->bVisibility_) 92 { 93 this->bVisibility_ = b; 94 this->settingsChanged(); 95 } 96 } 77 97 inline bool getRadarVisibility() const 78 98 { return this->bVisibility_; } 79 99 80 virtual const WorldEntity* getWorldEntity() const = 0;100 virtual const WorldEntity* getWorldEntity() const{ return this->wePtr_; } 81 101 82 102 const Vector3& getRVWorldPosition() const; … … 84 104 85 105 inline void setRadarObjectShape(Shape shape) 86 { this->radarObjectShape_ = shape; } 106 { 107 if( this->radarObjectShape_ != shape ) 108 { 109 this->radarObjectShape_ = shape; 110 this->settingsChanged(); 111 } 112 } 87 113 inline Shape getRadarObjectShape() const 88 114 { return this->radarObjectShape_; } 115 void settingsChanged(); 89 116 90 /* 91 inline void setMapNode(Ogre::SceneNode * node) 92 { this->MapNode_ = node; } 93 inline Ogre::SceneNode * getMapNode() const 94 { return this->MapNode_; } 95 inline void setMapEntity(Ogre::Entity * ent) 96 { this->MapEntity_ = ent; } 97 inline Ogre::Entity * getMapEntity() const 98 { return this->MapEntity_; } 99 */ 100 //Used for Map 101 Ogre::SceneNode * MapNode_; 102 Ogre::Entity * MapEntity_; 103 Ogre::DynamicLines* line_; 104 Ogre::SceneNode * LineNode_; 105 void addMapEntity(); 106 void updateMapPosition(); 117 107 118 bool isHumanShip_; 108 119 inline const std::string& getUniqueId() … … 115 126 void validate(const WorldEntity* object) const; 116 127 bool bVisibility_; 128 bool bInitialized_; 117 129 //Map 118 130 std::string uniqueId_; 131 BaseObject* creator_; 119 132 120 133 121 134 //Radar 135 const WorldEntity* wePtr_; 136 SmartPtr<Radar> radar_; 122 137 float radarObjectCamouflage_; 123 138 Shape radarObjectShape_; -
code/trunk/src/orxonox/interfaces/Rewardable.h
r6417 r7163 48 48 Damian 'Mozork' Frick 49 49 */ 50 class _OrxonoxExport Rewardable : public OrxonoxClass50 class _OrxonoxExport Rewardable : virtual public OrxonoxClass 51 51 { 52 52 public: … … 59 59 Must be implemented by every class inheriting from Rewardable. 60 60 @param player 61 A pointer to the ControllableEntity, do whatever you want with it.61 A pointer to the PlayerInfo, do whatever you want with it. 62 62 @return 63 63 Return true if successful. -
code/trunk/src/orxonox/items/Engine.cc
r6711 r7163 64 64 this->boostBlur_ = 0; 65 65 66 this->setCarrierName("Engine");67 66 this->speedAdd_ = 0.0; 68 67 this->speedMultiply_ = 1.0; -
code/trunk/src/orxonox/items/Engine.h
r6711 r7163 46 46 47 47 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 48 void registerVariables();49 48 void setConfigValues(); 50 49 … … 127 126 128 127 private: 128 void registerVariables(); 129 129 void networkcallback_shipID(); 130 130 -
code/trunk/src/orxonox/items/MultiStateEngine.h
r6417 r7163 53 53 54 54 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 55 void registerVariables();56 55 57 56 virtual void tick(float dt); … … 68 67 69 68 private: 69 void registerVariables(); 70 70 71 int state_; 71 72 int oldState_; -
code/trunk/src/orxonox/overlays/CMakeLists.txt
r6746 r7163 4 4 OverlayGroup.cc 5 5 6 COMPILATION_BEGIN OverlayCompilation.cc6 #COMPILATION_BEGIN OverlayCompilation.cc 7 7 InGameConsole.cc 8 Map.cc 9 COMPILATION_END 8 #COMPILATION_END 10 9 ) -
code/trunk/src/orxonox/overlays/GUISheet.cc
r6746 r7163 32 32 #include "core/GUIManager.h" 33 33 #include "core/XMLPort.h" 34 #include "core/GameMode.h" 34 35 35 36 namespace orxonox -
code/trunk/src/orxonox/pickup/PickupIdentifier.cc
- Property svn:eol-style set to native
r6725 r7163 39 39 namespace orxonox 40 40 { 41 41 42 42 /** 43 43 @brief … … 47 47 { 48 48 RegisterRootObject(PickupIdentifier); 49 49 50 50 if(pickup == NULL) 51 51 COUT(1) << "Error, PickupIdentifier was created without a valid Pickupable." << std::endl; 52 52 53 53 this->pickup_ = pickup; 54 54 } 55 55 56 56 PickupIdentifier::~PickupIdentifier() 57 57 { 58 58 59 59 } 60 60 61 61 /** 62 62 @brief … … 74 74 COUT(1) << "Error in PickupIdentifier::compare: Input Identifier is NULL." << std::endl; 75 75 } 76 76 77 77 if(identifier->pickup_ == NULL && this->pickup_ == NULL) 78 78 { … … 80 80 COUT(1) << "Error in PickupIdentifier::compare: Pickup stored by Identifier is NULL." << std::endl; 81 81 } 82 82 83 83 if(identifier->pickup_ == NULL) 84 84 { … … 86 86 COUT(1) << "Error in PickupIdentifier::compare: Pickup stored by Identifier is NULL." << std::endl; 87 87 } 88 88 89 89 if(this->pickup_ == NULL) 90 90 { … … 92 92 COUT(1) << "Error in PickupIdentifier::compare: Pickup stored by Identifier is NULL." << std::endl; 93 93 } 94 94 95 95 //! If the classIdentifiers are not the same (meaning the PickupIdentifiers identify different classes), the obviously the two Pickupables identified by the PickupIdentifiers cannot be the same. An ordering is established through the alphabetical ordering of the respective classnames. 96 96 if(!identifier->pickup_->getIdentifier()->isExactlyA(this->pickup_->getIdentifier())) 97 97 return this->pickup_->getIdentifier()->getName().compare(identifier->pickup_->getIdentifier()->getName()); 98 98 99 99 //! If the class is the same for both PickupIdentifiers we go on to check the parameters of the class. 100 100 //! If the two have a different number of parameters then obviusly something is very wrong. … … 104 104 return this->parameters_.size()-identifier->parameters_.size(); 105 105 } 106 107 //! We iterate through all parameters and compar their values (which are strings). The first parameter is the most significant. The ordering is once again established by the alphabetical comparison of the two value strings.106 107 //! We iterate through all parameters and compare their values (which are strings). The first parameter is the most significant. The ordering is once again established by the alphabetical comparison of the two value strings. 108 108 for(std::map<std::string, std::string>::const_iterator it = this->parameters_.begin(); it != this->parameters_.end(); it++) 109 109 { … … 117 117 return it->second.compare(identifier->parameters_.find(it->first)->second); 118 118 } 119 119 120 120 return 0; 121 121 } 122 122 123 123 /** 124 124 @brief … … 134 134 { 135 135 COUT(4) << "PickupIdentifier " << name << ", " << value << std::endl; 136 136 137 137 if(!(this->parameters_.find(name) == this->parameters_.end())) 138 138 { … … 140 140 return false; 141 141 } 142 142 143 143 this->parameters_[name] = value; 144 144 145 145 return true; 146 146 } 147 147 148 148 } -
code/trunk/src/orxonox/pickup/PickupIdentifier.h
- Property svn:eol-style set to native
r6540 r7163 41 41 #include "core/Identifier.h" 42 42 43 #include "core/OrxonoxClass.h" 43 #include "core/OrxonoxClass.h" 44 44 45 45 namespace orxonox 46 46 { 47 47 48 48 /** 49 49 @brief … … 57 57 class _OrxonoxExport PickupIdentifier : virtual public OrxonoxClass 58 58 { 59 59 60 60 public: 61 61 PickupIdentifier(Pickupable* pickup); //!< Constructor. 62 62 ~PickupIdentifier(); //!< Destructor. 63 63 64 64 virtual int compare(const PickupIdentifier* identifier) const; //!< Compares two PickupIdentifiers and returns 0 if a == b, <0 if a < b and >0 if a > b for a.compare(b). 65 65 66 66 bool addParameter(std::string & name, std::string & value); //!< Add a parameter to the PickupIdentifier. 67 67 68 68 private: 69 69 Pickupable* pickup_; //!< The Pickupable the PickupIdentififer is for. 70 70 std::map<std::string, std::string> parameters_; //!< The parameters identifying the type of the pickup beyond the class. 71 71 72 72 }; 73 73 74 74 /** 75 75 @brief … … 81 81 { return lhs->compare(rhs) < 0; } 82 82 }; 83 83 84 84 } 85 85 -
code/trunk/src/orxonox/sound/BaseSound.cc
r6502 r7163 33 33 #include <al.h> 34 34 35 #include "util/Math.h" 35 36 #include "core/CoreIncludes.h" 36 37 #include "core/GameMode.h" … … 248 249 else // No source acquired so far, but might be set to playing or paused 249 250 { 250 State state = this->state_; // save251 State state = static_cast<State>(this->state_); // save 251 252 if (this->isPlaying() || this->isPaused()) 252 253 doPlay(); -
code/trunk/src/orxonox/sound/BaseSound.h
r6417 r7163 112 112 float volume_; 113 113 bool bLooping_; 114 State state_;114 uint8_t state_; // This Variable is actually of type State 115 115 float pitch_; 116 116 -
code/trunk/src/orxonox/sound/SoundStreamer.cc
- Property svn:eol-style set to native
-
code/trunk/src/orxonox/sound/SoundStreamer.h
- Property svn:eol-style set to native
-
code/trunk/src/orxonox/sound/WorldSound.cc
r6417 r7163 58 58 registerVariable(bLooping_, ObjectDirection::ToClient, new NetworkCallback<WorldSound>(this, &WorldSound::loopingChanged)); 59 59 registerVariable(pitch_, ObjectDirection::ToClient, new NetworkCallback<WorldSound>(this, &WorldSound::pitchChanged)); 60 registerVariable(( int&)(BaseSound::state_), ObjectDirection::ToClient, new NetworkCallback<WorldSound>(this, &WorldSound::stateChanged));60 registerVariable((uint8_t&)(BaseSound::state_), ObjectDirection::ToClient, new NetworkCallback<WorldSound>(this, &WorldSound::stateChanged)); 61 61 } 62 62 -
code/trunk/src/orxonox/weaponsystem/WeaponMode.cc
r6417 r7163 274 274 return BLANKSTRING; 275 275 } 276 277 void WeaponMode::setDefaultSoundWithVolume(const std::string& soundPath, const float soundVolume){ 278 if (this->defSndWpnFire_) { 279 this->defSndWpnFire_->setSource(soundPath); 280 this->defSndWpnFire_->setVolume(soundVolume); 281 } 282 } 283 276 284 } -
code/trunk/src/orxonox/weaponsystem/WeaponMode.h
r6417 r7163 55 55 void setDefaultSound(const std::string& soundPath); 56 56 const std::string& getDefaultSound(); 57 57 void setDefaultSoundWithVolume(const std::string& soundPath, const float soundVolume); 58 58 59 59 // Munition -
code/trunk/src/orxonox/weaponsystem/WeaponSystem.cc
r6417 r7163 214 214 Weapon* weapon = 0; 215 215 while ((weapon = wPack->getWeapon(i++))) 216 weapon->getWeaponSlot()->removeWeapon(); 216 if (weapon->getWeaponSlot()) 217 weapon->getWeaponSlot()->removeWeapon(); 217 218 218 219 // Remove all added links from the WeaponSets -
code/trunk/src/orxonox/worldentities/BigExplosion.cc
r5929 r7163 101 101 this->debrisEntity3_ = new MovableEntity(this); 102 102 this->debrisEntity4_ = new MovableEntity(this); 103 104 this->debrisEntity1_->setSyncMode(0); 105 this->debrisEntity2_->setSyncMode(0); 106 this->debrisEntity3_->setSyncMode(0); 107 this->debrisEntity4_->setSyncMode(0); 103 108 104 109 this->debris1_ = new Model(this); … … 106 111 this->debris3_ = new Model(this); 107 112 this->debris4_ = new Model(this); 113 114 this->debris1_->setSyncMode(0); 115 this->debris2_->setSyncMode(0); 116 this->debris3_->setSyncMode(0); 117 this->debris4_->setSyncMode(0); 108 118 109 119 this->explosion_ = new StaticEntity(this); 120 this->explosion_->setSyncMode(0); 110 121 111 122 this->debrisSmoke1_ = new ParticleInterface(this->getScene()->getSceneManager(), "Orxonox/smoke7", this->LOD_); … … 158 169 effect->setSource("Orxonox/explosion2b"); 159 170 effect->setLifetime(4.0f); 171 effect->setSyncMode(0); 160 172 161 173 ParticleSpawner* effect2 = new ParticleSpawner(this->getCreator()); … … 163 175 effect2->setSource("Orxonox/smoke6"); 164 176 effect2->setLifetime(4.0f); 177 effect2->setSyncMode(0); 165 178 166 179 this->explosion_->attach(effect); … … 181 194 MovableEntity* partEntity1 = new MovableEntity(this); 182 195 MovableEntity* partEntity2 = new MovableEntity(this); 196 197 part1->setSyncMode(0); 198 part2->setSyncMode(0); 199 partEntity1->setSyncMode(0); 200 partEntity2->setSyncMode(0); 183 201 184 202 partEntity1->setVelocity(Vector3(rnd(-1, 1), rnd(-1, 1), rnd(-1, 1))*rnd(10,100)); -
code/trunk/src/orxonox/worldentities/BigExplosion.h
r5929 r7163 45 45 46 46 virtual void tick(float dt); 47 void registerVariables();48 47 49 48 inline void setLOD(LODParticle::Value level) … … 53 52 54 53 private: 54 void registerVariables(); 55 55 56 56 void LODchanged(); -
code/trunk/src/orxonox/worldentities/CMakeLists.txt
r6417 r7163 5 5 MobileEntity.cc 6 6 ControllableEntity.cc 7 7 Drone.cc 8 8 BigExplosion.cc 9 9 EffectContainer.cc -
code/trunk/src/orxonox/worldentities/ControllableEntity.h
r6417 r7163 49 49 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 50 50 virtual void tick(float dt); 51 void registerVariables();52 51 void setConfigValues(); 53 52 … … 137 136 inline float getMouseLookSpeed() const 138 137 { return this->mouseLookSpeed_; } 138 inline CameraPosition* getCurrentCameraPosition() 139 { return this->currentCameraPosition_; } 139 140 140 141 inline Controller* getXMLController() const … … 162 163 { this->hudtemplate_ = name; } 163 164 165 Ogre::SceneNode* cameraPositionRootNode_; 166 164 167 private: 168 void registerVariables(); 165 169 void setXMLController(Controller* controller); 166 170 … … 208 212 bool bMouseLook_; 209 213 float mouseLookSpeed_; 210 Ogre::SceneNode* cameraPositionRootNode_;211 214 std::list<SmartPtr<CameraPosition> > cameraPositions_; 212 215 CameraPosition* currentCameraPosition_; -
code/trunk/src/orxonox/worldentities/ExplosionChunk.h
r5929 r7163 44 44 45 45 virtual void tick(float dt); 46 void registerVariables();47 46 48 47 inline void setLOD(LODParticle::Value level) … … 52 51 53 52 private: 53 void registerVariables(); 54 54 void LODchanged(); 55 55 void checkStop(); -
code/trunk/src/orxonox/worldentities/MobileEntity.cc
r5781 r7163 46 46 this->angularAcceleration_ = Vector3::ZERO; 47 47 this->angularVelocity_ = Vector3::ZERO; 48 49 this->registerVariables();50 48 } 51 49 -
code/trunk/src/orxonox/worldentities/MovableEntity.h
r6417 r7163 48 48 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 49 49 virtual bool collidesAgainst(WorldEntity* otherObject, btManifoldPoint& contactPoint); 50 void registerVariables();51 50 52 51 using WorldEntity::setPosition; … … 79 78 80 79 private: 80 void registerVariables(); 81 81 void clientConnected(unsigned int clientID); 82 82 void clientDisconnected(unsigned int clientID); -
code/trunk/src/orxonox/worldentities/StaticEntity.h
r5781 r7163 42 42 virtual ~StaticEntity(); 43 43 44 void registerVariables();45 46 44 using WorldEntity::setPosition; 47 45 using WorldEntity::setOrientation; … … 51 49 52 50 private: 51 void registerVariables(); 53 52 bool isCollisionTypeLegal(CollisionType type) const; 54 53 -
code/trunk/src/orxonox/worldentities/WorldEntity.cc
r6524 r7163 81 81 this->node_->setPosition(Vector3::ZERO); 82 82 this->node_->setOrientation(Quaternion::IDENTITY); 83 83 84 84 // Activity and visibility memory. 85 85 this->bActiveMem_ = true; … … 205 205 registerVariable(this->parentID_, VariableDirection::ToClient, new NetworkCallback<WorldEntity>(this, &WorldEntity::networkcallback_parentChanged)); 206 206 } 207 207 208 208 /** 209 209 @brief … … 213 213 { 214 214 SUPER(WorldEntity, changedActivity); 215 215 216 216 for (std::set<WorldEntity*>::const_iterator it = this->getAttachedObjects().begin(); it != this->getAttachedObjects().end(); it++) 217 217 { … … 227 227 } 228 228 } 229 229 230 230 /** 231 231 @brief … … 235 235 { 236 236 SUPER(WorldEntity, changedVisibility); 237 237 238 238 for (std::set<WorldEntity*>::const_iterator it = this->getAttachedObjects().begin(); it != this->getAttachedObjects().end(); it++) 239 239 { -
code/trunk/src/orxonox/worldentities/WorldEntity.h
r6524 r7163 94 94 95 95 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 96 void registerVariables();97 96 98 97 inline const Ogre::SceneNode* getNode() const … … 105 104 static const Vector3 DOWN; 106 105 static const Vector3 UP; 107 106 108 107 virtual void changedActivity(void); 109 108 virtual void changedVisibility(void); … … 214 213 215 214 private: 215 void registerVariables(); 216 216 217 inline void lookAt_xmlport(const Vector3& target) 217 218 { this->lookAt(target); } … … 234 235 std::set<WorldEntity*> children_; 235 236 bool bDeleteWithParent_; 236 237 237 238 bool bActiveMem_; 238 239 bool bVisibleMem_; -
code/trunk/src/orxonox/worldentities/pawns/CMakeLists.txt
r5781 r7163 1 1 ADD_SOURCE_FILES(ORXONOX_SRC_FILES 2 FpsPlayer.cc 2 3 Spectator.cc 3 4 Pawn.cc -
code/trunk/src/orxonox/worldentities/pawns/Pawn.cc
r6864 r7163 53 53 CreateFactory(Pawn); 54 54 55 Pawn::Pawn(BaseObject* creator) : ControllableEntity(creator) 55 Pawn::Pawn(BaseObject* creator) 56 : ControllableEntity(creator) 57 , RadarViewable(creator, static_cast<WorldEntity*>(this)) 56 58 { 57 59 RegisterObject(Pawn); … … 64 66 this->maxHealth_ = 0; 65 67 this->initialHealth_ = 0; 68 this->shieldHealth_ = 0; 69 this->shieldAbsorption_ = 0.5; 66 70 67 71 this->lastHitOriginator_ = 0; … … 78 82 else 79 83 this->weaponSystem_ = 0; 80 81 this->setCarrierName("Pawn");82 84 83 85 this->setRadarObjectColour(ColourValue::Red); … … 105 107 XMLPortParam(Pawn, "maxhealth", setMaxHealth, getMaxHealth, xmlelement, mode).defaultValues(200); 106 108 XMLPortParam(Pawn, "initialhealth", setInitialHealth, getInitialHealth, xmlelement, mode).defaultValues(100); 109 110 XMLPortParam(Pawn, "shieldhealth", setShieldHealth, getShieldHealth, xmlelement, mode).defaultValues(0); 111 XMLPortParam(Pawn, "shieldabsorption", setShieldAbsorption, getShieldAbsorption, xmlelement, mode).defaultValues(0); 112 107 113 XMLPortParam(Pawn, "spawnparticlesource", setSpawnParticleSource, getSpawnParticleSource, xmlelement, mode); 108 114 XMLPortParam(Pawn, "spawnparticleduration", setSpawnParticleDuration, getSpawnParticleDuration, xmlelement, mode).defaultValues(3.0f); … … 116 122 void Pawn::registerVariables() 117 123 { 118 registerVariable(this->bAlive_, VariableDirection::ToClient); 119 registerVariable(this->health_, VariableDirection::ToClient); 120 registerVariable(this->initialHealth_, VariableDirection::ToClient); 121 registerVariable(this->bReload_, VariableDirection::ToServer); 122 registerVariable(this->aimPosition_, Bidirectionality::ServerMaster, 0, true); 124 registerVariable(this->bAlive_, VariableDirection::ToClient); 125 registerVariable(this->health_, VariableDirection::ToClient); 126 registerVariable(this->initialHealth_, VariableDirection::ToClient); 127 registerVariable(this->shieldHealth_, VariableDirection::ToClient); 128 registerVariable(this->shieldAbsorption_, VariableDirection::ToClient); 129 registerVariable(this->bReload_, VariableDirection::ToServer); 130 registerVariable(this->aimPosition_, VariableDirection::ToServer); // For the moment this variable gets only transfered to the server 123 131 } 124 132 … … 162 170 if (this->getGametype() && this->getGametype()->allowPawnDamage(this, originator)) 163 171 { 164 this->setHealth(this->health_ - damage); 172 //share the dealt damage to the shield and the Pawn. 173 float shielddamage = damage*this->shieldAbsorption_; 174 float healthdamage = damage*(1-this->shieldAbsorption_); 175 176 // In case the shield can not take all the shield damage. 177 if (shielddamage > this->getShieldHealth()) 178 { 179 healthdamage += shielddamage-this->getShieldHealth(); 180 this->setShieldHealth(0); 181 } 182 183 this->setHealth(this->health_ - healthdamage); 184 185 if (this->getShieldHealth() > 0) 186 { 187 this->setShieldHealth(this->shieldHealth_ - shielddamage); 188 } 189 165 190 this->lastHitOriginator_ = originator; 166 191 … … 336 361 { 337 362 if (this->weaponSystem_) 363 { 338 364 this->weaponSystem_->addWeaponPack(wPack); 365 this->addedWeaponPack(wPack); 366 } 339 367 } 340 368 … … 342 370 { 343 371 if (this->weaponSystem_) 372 { 344 373 if (!this->weaponSystem_->addWeaponPack(wPack)) 345 374 wPack->destroy(); 375 else 376 this->addedWeaponPack(wPack); 377 } 346 378 } 347 379 -
code/trunk/src/orxonox/worldentities/pawns/Pawn.h
r6711 r7163 50 50 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 51 51 virtual void tick(float dt); 52 void registerVariables();53 52 54 53 inline bool isAlive() const … … 73 72 { return this->initialHealth_; } 74 73 74 inline void setShieldHealth(float shieldHealth) 75 { this->shieldHealth_ = shieldHealth; } 76 inline float getShieldHealth() 77 { return this->shieldHealth_; } 78 79 inline void setShieldAbsorption(float shieldAbsorption) 80 { this->shieldAbsorption_ = shieldAbsorption; } 81 inline float getShieldAbsorption() 82 { return this->shieldAbsorption_; } 83 75 84 inline ControllableEntity* getLastHitOriginator() const 76 85 { return this->lastHitOriginator_; } … … 91 100 void addWeaponPackXML(WeaponPack * wPack); 92 101 WeaponPack * getWeaponPack(unsigned int index) const; 102 103 virtual void addedWeaponPack(WeaponPack* wPack) {} 93 104 94 105 inline const WorldEntity* getWorldEntity() const … … 116 127 Vector3 getAimPosition() 117 128 { return this->aimPosition_; } 118 129 119 130 virtual const Vector3& getCarrierPosition(void) 120 131 { return this->getWorldPosition(); }; … … 141 152 float maxHealth_; 142 153 float initialHealth_; 154 float shieldHealth_; 155 float shieldAbsorption_; // Has to be between 0 and 1 143 156 144 157 Pawn* lastHitOriginator_; … … 152 165 153 166 private: 167 void registerVariables(); 154 168 inline void setWeaponSystem(WeaponSystem* weaponsystem) 155 169 { this->weaponSystem_ = weaponsystem; } -
code/trunk/src/orxonox/worldentities/pawns/SpaceShip.h
r6711 r7163 47 47 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 48 48 virtual void tick(float dt); 49 void registerVariables();50 49 void setConfigValues(); 51 50 … … 99 98 100 99 private: 100 void registerVariables(); 101 101 virtual bool isCollisionTypeLegal(WorldEntity::CollisionType type) const; 102 102 103 private:104 103 void loadEngineTemplate(); 105 104 -
code/trunk/src/orxonox/worldentities/pawns/Spectator.h
r6417 r7163 44 44 45 45 void setConfigValues(); 46 void registerVariables();47 46 virtual void tick(float dt); 48 47 … … 63 62 64 63 private: 64 void registerVariables(); 65 65 void changedGreeting(); 66 66 void changedFlareVisibility();
Note: See TracChangeset
for help on using the changeset viewer.