Changeset 8493 for code/branches/dockingsystem2/src/modules/docking
- Timestamp:
- May 16, 2011, 6:21:05 PM (14 years ago)
- Location:
- code/branches/dockingsystem2/src/modules/docking
- Files:
-
- 6 added
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/dockingsystem2/src/modules/docking/CMakeLists.txt
r8434 r8493 2 2 DockingTarget.cc 3 3 DockingEffect.cc 4 DockingAnimation.cc 4 5 DockToShip.cc 6 MoveToDockingTarget.cc 7 DockingController.cc 5 8 Dock.cc 6 9 ) -
code/branches/dockingsystem2/src/modules/docking/Dock.cc
r8434 r8493 57 57 { 58 58 RegisterObject(Dock); 59 COUT(0) << "Registering dock..." << std::endl;60 59 } 61 60 … … 70 69 71 70 XMLPortObject(Dock, DockingEffect, "effects", addEffect, getEffect, xmlelement, mode); 71 XMLPortObject(Dock, DockingAnimation, "animations", addAnimation, getAnimation, xmlelement, mode); 72 72 XMLPortEventSink(Dock, BaseObject, "execute", execute, xmlelement, mode); 73 74 COUT(0) << "Dock created.." << std::endl;75 73 } 76 74 … … 96 94 } 97 95 pawn = pTrigger->getTriggeringPlayer(); 98 } else { 96 } 97 else 98 { 99 99 COUT(2) << "Docking::execute Not a player trigger, can't extract pawn from it.." << std::endl; 100 100 return false; … … 110 110 if(player == NULL) 111 111 { 112 COUT(2) << "The PlayerInfo* is NULL." << std::endl; 113 return false; 114 } 115 116 COUT(0) << "Dock triggered by player: " << player->getName() << ".." << std::endl; 112 COUT(2) << "Docking::execute The PlayerInfo* is NULL." << std::endl; 113 return false; 114 } 117 115 118 116 if(bTriggered) … … 123 121 // Show docking dialog 124 122 GUIManager::showGUI("DockingDialog"); 125 //DockingEffect::invokeEffect(docking::DOCKING, player, effects_);126 123 } 127 124 else … … 129 126 // Remove player from candidates list 130 127 candidates.erase(player); 131 132 //DockingEffect::invokeEffect(docking::RELEASE, player, effects_);133 128 } 134 129 … … 163 158 if(candidates.find(player) == candidates.end()) 164 159 { 165 COUT(0) << "Player is not a candidate!" << std::endl; 166 return false; 167 } 168 169 // Remove player from candidates, add to docked players and invoke docking effect 160 COUT(0) << "Dock::dock Player is not a candidate!" << std::endl; 161 return false; 162 } 163 170 164 candidates.erase(player); 171 165 docked.insert(player); 172 DockingEffect::invokeEffect(docking::ATTACH, player, effects); 166 167 if (animations.empty()) 168 return dockingAnimationFinished(player); 169 else 170 DockingAnimation::invokeAnimation(true, player, animations); 171 172 return true; 173 } 174 175 bool Dock::dockingAnimationFinished(PlayerInfo* player) 176 { 177 if(docked.find(player) == docked.end()) 178 { 179 COUT(0) << "Dock::dockingAnimationFinished Player is not currently docked." << std::endl; 180 return false; 181 } 182 183 DockingEffect::invokeEffect(true, player, effects); 173 184 return true; 174 185 } … … 179 190 if(docked.find(player) == docked.end()) 180 191 { 181 COUT(0) << "Player is not docked to this Dock." << std::endl; 182 return false; 183 } 184 185 // Remove player from docked, add to candidates and reverse DockingEffect 192 COUT(0) << "Dock::undock Player is not docked to this Dock." << std::endl; 193 return false; 194 } 195 186 196 docked.erase(player); 187 197 candidates.insert(player); 188 DockingEffect::invokeEffect(docking::RELEASE, player, effects); 198 199 DockingEffect::invokeEffect(false, player, effects); 200 201 if (animations.empty()) 202 return undockingAnimationFinished(player); 203 else 204 DockingAnimation::invokeAnimation(false, player, animations); 205 206 return true; 207 } 208 209 bool Dock::undockingAnimationFinished(PlayerInfo* player) { 210 COUT(0) << "Dock::undockingAnimationFinished executed" << std::endl; 189 211 return true; 190 212 } … … 226 248 } 227 249 228 const DockingEffect* Dock::getEffect(unsigned int index) const 229 { 230 int i = index; 250 const DockingEffect* Dock::getEffect(unsigned int i) const 251 { 231 252 for (std::list<DockingEffect*>::const_iterator effect = this->effects.begin(); effect != this->effects.end(); ++effect) 232 253 { … … 237 258 return NULL; 238 259 } 260 261 bool Dock::addAnimation(DockingAnimation* animation) 262 { 263 assert(animation); 264 animation->setParent(this); 265 animations.push_back(animation); 266 return true; 267 } 268 269 const DockingAnimation* Dock::getAnimation(unsigned int i) const 270 { 271 for (std::list<DockingAnimation*>::const_iterator animation = this->animations.begin(); animation != this->animations.end(); ++animation) 272 { 273 if(i == 0) 274 return *animation; 275 i--; 276 } 277 return NULL; 278 } 239 279 } -
code/branches/dockingsystem2/src/modules/docking/Dock.h
r8434 r8493 46 46 47 47 #include "DockingEffect.h" 48 #include "DockingAnimation.h" 48 49 #include "DockingPrereqs.h" 49 50 … … 58 59 virtual ~Dock(); 59 60 61 // Trigger interface 62 bool execute(bool bTriggered, BaseObject* trigger); 63 64 // XML interface 60 65 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 61 66 virtual void XMLEventPort(Element& xmlelement, XMLPort::Mode mode); 62 67 63 bool execute(bool bTriggered, BaseObject* trigger); 64 68 // XML functions 65 69 bool addEffect(DockingEffect* effect); //!< Add a DockingEffect to the Dock. 66 70 const DockingEffect* getEffect(unsigned int index) const; //!< Get the DockingEffect at a given index. 71 bool addAnimation(DockingAnimation* animation); //!< Add a DockingAnimation to the Dock. 72 const DockingAnimation* getAnimation(unsigned int index) const; //!< Get the DockingAnimation at a given index. 67 73 74 // Docking/undocking logic, checks conditions and invokes the DockingAnimations 68 75 bool dock(PlayerInfo* player); //!< Returns true if given player docked successfully (player must be a candidate) 69 76 bool undock(PlayerInfo* player); //!< Undocks a player (player must be docked) 70 77 78 // Animation logic 79 bool dockingAnimationFinished(PlayerInfo* player); //!< Called when a docking animation finished 80 bool undockingAnimationFinished(PlayerInfo* player); //!< Called when a undocking animation finished 81 82 // LUA interface 71 83 void dock() { this->dock(HumanController::getLocalControllerSingleton()->getPlayer()); } // tolua_export 72 84 static unsigned int getNumberOfActiveDocks(); // tolua_export 73 85 static Dock* getActiveDockAtIndex(unsigned int index); // tolua_export 74 86 87 // Console commands 75 88 static void cmdDock(); 76 89 static void cmdUndock(); … … 79 92 std::set<PlayerInfo*> candidates; //!< A set of all players which are allowed to dock using the console command. 80 93 std::set<PlayerInfo*> docked; //!< A set of all docked players 94 81 95 std::list<DockingEffect*> effects; //!< The list of DockingEffects to be executed when a player docks. 96 std::list<DockingAnimation*> animations; //!< The list of DockingAnimations to be executed before a player docks 82 97 }; // tolua_export 83 98 } // tolua_export -
code/branches/dockingsystem2/src/modules/docking/DockToShip.cc
r8382 r8493 21 21 * 22 22 * Author: 23 * Damian 'Mozork' Frick23 * Sven Stucki 24 24 * Co-authors: 25 25 * ... … … 69 69 bool DockToShip::docking(PlayerInfo* player) 70 70 { 71 COUT(0) << "DockToShip::docking" << endl;72 return true;73 }74 75 bool DockToShip::attach(PlayerInfo* player)76 {77 71 COUT(0) << "DockToShip::attach" << endl; 78 72 -
code/branches/dockingsystem2/src/modules/docking/DockToShip.h
r8257 r8493 61 61 62 62 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 63 v irtual void setTargetId(std::string str);64 virtualstd::string getTargetId();63 void setTargetId(std::string str); 64 std::string getTargetId(); 65 65 66 66 virtual bool docking(PlayerInfo* player); //!< Called when docking starts 67 virtual bool attach(PlayerInfo* player); //!< Called after docking animation68 67 virtual bool release(PlayerInfo* player); //!< Called when player wants undock 69 70 68 private: 71 69 std::string target; -
code/branches/dockingsystem2/src/modules/docking/DockingEffect.cc
r8487 r8493 21 21 * 22 22 * Author: 23 * Damian 'Mozork' Frick23 * Sven Stucki 24 24 * Co-authors: 25 25 * ... … … 46 46 } 47 47 48 bool DockingEffect::invokeEffect( docking::event event, PlayerInfo* player, std::list<DockingEffect*> & effects)48 bool DockingEffect::invokeEffect(bool dock, PlayerInfo* player, std::list<DockingEffect*> & effects) 49 49 { 50 50 bool check = true; 51 51 52 COUT(4) << "Invoking DockingEffects on player: " << player << " ." << std::endl;53 54 52 for (std::list<DockingEffect*>::iterator effect = effects.begin(); effect != effects.end(); effect++) 55 53 { 56 switch(event) 57 { 58 case docking::DOCKING: 59 check &= (*effect)->docking(player); 60 break; 61 case docking::RELEASE: 62 check &= (*effect)->release(player); 63 break; 64 default: 65 assert(0); 66 } 54 if (dock) 55 check &= (*effect)->docking(player); 56 else 57 check &= (*effect)->release(player); 67 58 } 68 59 -
code/branches/dockingsystem2/src/modules/docking/DockingEffect.h
r8487 r8493 49 49 namespace orxonox 50 50 { 51 namespace docking {52 enum event {53 DOCKING,54 RELEASE55 };56 }57 51 58 52 /** … … 74 68 virtual bool release(PlayerInfo* player) = 0; //!< Called when player wants to undock 75 69 76 static bool invokeEffect( docking::event event, PlayerInfo* player, std::list<DockingEffect*> & effects); //!< Invokes the event specific method of all DockingEffects in the list70 static bool invokeEffect(bool dock, PlayerInfo* player, std::list<DockingEffect*> & effects); //!< Invokes the event specific method of all DockingEffects in the list 77 71 static DockingTarget *findTarget(std::string name); //!< Iterates through all DockingTarget objects to find the one with name=target 78 72 }; -
code/branches/dockingsystem2/src/modules/docking/DockingPrereqs.h
r8257 r8493 66 66 { 67 67 class Dock; 68 class DockingAnimation; 68 69 class DockingTarget; 69 70 class DockingEffect; 70 71 class DockToShip; 72 class MoveToDockingTarget; 71 73 } 72 74
Note: See TracChangeset
for help on using the changeset viewer.