Changeset 8382 for code/branches/dockingsystem2/src/modules/docking
- Timestamp:
- May 2, 2011, 4:16:27 PM (14 years ago)
- Location:
- code/branches/dockingsystem2/src/modules/docking
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/dockingsystem2/src/modules/docking/Dock.cc
r8257 r8382 33 33 34 34 #include "Dock.h" 35 35 36 #include "infos/HumanPlayer.h" 36 37 #include "worldentities/pawns/Pawn.h" 37 38 #include "interfaces/PlayerTrigger.h" 39 #include "controllers/HumanController.h" 40 #include "core/command/ConsoleCommand.h" 41 38 42 39 43 … … 41 45 { 42 46 CreateFactory(Dock); 47 48 SetConsoleCommand("Dock", "dock", &Dock::cmdDock).addShortcut().setAsInputCommand(); 49 SetConsoleCommand("Dock", "undock", &Dock::cmdUndock).addShortcut().setAsInputCommand(); 43 50 44 51 Dock::Dock(BaseObject* creator) : StaticEntity(creator) … … 80 87 { 81 88 if(!pTrigger->isForPlayer()) { // The PlayerTrigger is not exclusively for Pawns which means we cannot extract one. 82 COUT( 0) << "Docking:execute PlayerTrigger was not triggered by a player.." << std::endl;89 COUT(2) << "Docking:execute PlayerTrigger was not triggered by a player.." << std::endl; 83 90 return false; 84 91 } 85 92 pawn = pTrigger->getTriggeringPlayer(); 86 93 } else { 87 COUT( 0) << "Docking::execute Not a player trigger, can't extract pawn from it.." << std::endl;94 COUT(2) << "Docking::execute Not a player trigger, can't extract pawn from it.." << std::endl; 88 95 return false; 89 96 } 90 97 if(pawn == NULL) 91 98 { 92 COUT( 0) << "Docking::execute Can't retrieve Pawn from Trigger. (" << trigger->getIdentifier()->getName() << ")" << std::endl;99 COUT(2) << "Docking::execute Can't retrieve Pawn from Trigger. (" << trigger->getIdentifier()->getName() << ")" << std::endl; 93 100 return false; 94 101 } … … 98 105 if(player == NULL) 99 106 { 100 COUT( 0) << "The PlayerInfo* is NULL." << std::endl;107 COUT(2) << "The PlayerInfo* is NULL." << std::endl; 101 108 return false; 102 109 } … … 105 112 106 113 if(bTriggered) { 107 DockingEffect::invokeEffect(docking::DOCKING, player, effects_); 108 DockingEffect::invokeEffect(docking::ATTACH, player, effects_); 114 // Add player to this Docks candidates 115 candidates.insert(player); 116 117 //DockingEffect::invokeEffect(docking::DOCKING, player, effects_); 109 118 } else { 110 DockingEffect::invokeEffect(docking::RELEASE, player, effects_); 119 // Remove player from candidates list 120 candidates.erase(player); 121 122 //DockingEffect::invokeEffect(docking::RELEASE, player, effects_); 111 123 } 112 124 … … 115 127 116 128 129 void Dock::cmdDock() { 130 PlayerInfo* player = HumanController::getLocalControllerSingleton()->getPlayer(); 131 for(ObjectList<Dock>::iterator it = ObjectList<Dock>::begin(); it != ObjectList<Dock>::end(); ++it) { 132 if(it->dock(player)) 133 break; 134 } 135 } 136 137 void Dock::cmdUndock() { 138 PlayerInfo* player = HumanController::getLocalControllerSingleton()->getPlayer(); 139 for(ObjectList<Dock>::iterator it = ObjectList<Dock>::begin(); it != ObjectList<Dock>::end(); ++it) { 140 if(it->undock(player)) 141 break; 142 } 143 } 144 145 146 bool Dock::dock(PlayerInfo* player) { 147 // Check if player is a candidate 148 if(candidates.find(player) == candidates.end()) { 149 COUT(0) << "Player is not a candidate!"; 150 return false; 151 } 152 153 // Remove player from candidates, add to docked players and invoke docking effect 154 candidates.erase(player); 155 docked.insert(player); 156 DockingEffect::invokeEffect(docking::ATTACH, player, effects); 157 return true; 158 } 159 160 bool Dock::undock(PlayerInfo* player) { 161 // Check if player is docked to this Dock 162 if(docked.find(player) == docked.end()) { 163 COUT(0) << "Player is not docked to this Dock." << std::endl; 164 return false; 165 } 166 167 // Remove player from docked, add to candidates and reverse DockingEffect 168 docked.erase(player); 169 candidates.insert(player); 170 DockingEffect::invokeEffect(docking::RELEASE, player, effects); 171 return true; 172 } 173 174 117 175 bool Dock::addEffect(DockingEffect* effect) { 118 176 assert(effect); 119 effects _.push_back(effect);177 effects.push_back(effect); 120 178 return true; 121 179 } … … 123 181 const DockingEffect* Dock::getEffect(unsigned int index) const { 124 182 int i = index; 125 for (std::list<DockingEffect*>::const_iterator effect = this->effects_.begin(); effect != this->effects_.end(); ++effect) 126 { 183 for (std::list<DockingEffect*>::const_iterator effect = this->effects.begin(); effect != this->effects.end(); ++effect) { 127 184 if(i == 0) 128 185 return *effect; 129 130 186 i--; 131 187 } -
code/branches/dockingsystem2/src/modules/docking/Dock.h
r8196 r8382 36 36 #define _Dock_H__ 37 37 38 #include <map> 39 38 40 #include "core/CoreIncludes.h" 39 41 #include "core/XMLPort.h" … … 41 43 42 44 #include "worldentities/StaticEntity.h" 45 #include "notifications/NotificationManager.h" 46 43 47 #include "DockingEffect.h" 44 48 #include "DockingPrereqs.h" 45 49 46 namespace orxonox { 47 50 namespace orxonox { 48 51 49 52 class _DockingExport Dock : public StaticEntity { … … 60 63 const DockingEffect* getEffect(unsigned int index) const; //!< Get the DockingEffect at a given index. 61 64 65 bool dock(PlayerInfo* player); //!< Returns true if given player docked successfully (player must be a candidate) 66 bool undock(PlayerInfo* player); //!< Undocks a player (player must be docked) 67 68 static void cmdDock(); 69 static void cmdUndock(); 70 62 71 private: 63 std::list<DockingEffect*> effects_; //!< The list of DockingEffects to be executed when a player docks. 72 std::set<PlayerInfo*> candidates; //!< A set of all players which are allowed to dock using the console command. 73 std::set<PlayerInfo*> docked; //!< A set of all docked players 74 std::list<DockingEffect*> effects; //!< The list of DockingEffects to be executed when a player docks. 64 75 }; 65 76 -
code/branches/dockingsystem2/src/modules/docking/DockToShip.cc
r8257 r8382 89 89 } 90 90 91 // Make sure target isn't removed when undocking 92 dockTo->setDestroyWhenPlayerLeft(false); 91 93 player->startTemporaryControl(dockTo); 92 94 … … 97 99 { 98 100 COUT(0) << "DockToShip::release" << endl; 101 102 player->stopTemporaryControl(); 103 99 104 return true; 100 105 }
Note: See TracChangeset
for help on using the changeset viewer.