Changeset 11606 for code/branches/ScriptableController_HS17/src/orxonox/scriptablecontroller/scriptable_controller.cc
- Timestamp:
- Nov 27, 2017, 4:38:50 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/ScriptableController_HS17/src/orxonox/scriptablecontroller/scriptable_controller.cc
r11583 r11606 4 4 #include "infos/PlayerInfo.h" 5 5 #include "core/command/Executor.h" 6 #include "worldentities/pawns/Pawn.h" 6 7 7 8 namespace orxonox … … 63 64 } 64 65 65 void ScriptableController::register ControllableEntity(std::string id, ControllableEntity *entity)66 void ScriptableController::registerPawn(std::string id, Pawn *pawn) 66 67 { 67 this->worldEntities_[id] = entity; 68 this->worldEntities_[id] = pawn; 69 this->pawns_[id] = pawn; 70 this->pawnsReverse_[pawn] = id; 71 } 72 73 void ScriptableController::pawnKilled(Pawn *pawn) 74 { 75 auto pawn_id_iter = this->pawnsReverse_.find(pawn); 76 if(pawn_id_iter == this->pawnsReverse_.end()) 77 { 78 orxout(internal_warning) << "Unregistered pawn reported that it's destroyed" << std::endl; 79 return; 80 } 81 82 for(auto &api : this->apis_) 83 api->pawnKilled(pawn_id_iter->second); 84 85 this->pawns_.erase(pawn_id_iter->second); 86 this->pawnsReverse_.erase(pawn_id_iter); 87 } 88 89 void ScriptableController::pawnHit(Pawn *target, Pawn *source, double new_health, double new_shield) 90 { 91 auto target_id_iter = this->pawnsReverse_.find(target); 92 auto source_id_iter = this->pawnsReverse_.find(source); 93 94 if(target_id_iter == this->pawnsReverse_.end() || 95 source_id_iter == this->pawnsReverse_.end() ) 96 { 97 orxout(internal_warning) << "Unregistered pawn reported that it's hit" << std::endl; 98 return; 99 } 100 101 for(auto &api : this->apis_) 102 api->pawnHit(target_id_iter->second, source_id_iter->second, new_health, new_shield); 103 } 104 105 void ScriptableController::killPawn(std::string id) 106 { 107 auto pawn = this->pawns_.find(id); 108 if(pawn == this->pawns_.end()) 109 { 110 orxout(user_warning) << "Tried to destroy unknown pawn " << id << std::endl; 111 return; 112 } 113 114 pawn->second->kill(); 68 115 } 69 116 … … 77 124 } 78 125 79 ControllableEntity *ScriptableController::getControllableEntityByID(std::string id) const126 Pawn *ScriptableController::getPawnByID(std::string id) const 80 127 { 81 if(id == "player" || id == "Player" || id == "PLAYER") 82 return this->player_->getControllableEntity(); 83 84 auto entity = this->controllabelEntities_.find(id); 85 return entity != this->controllabelEntities_.end() ? entity->second : nullptr; 128 auto pawn = this->pawns_.find(id); 129 return pawn != this->pawns_.end() ? pawn->second : nullptr; 86 130 } 87 131
Note: See TracChangeset
for help on using the changeset viewer.