Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Nov 27, 2017, 4:38:50 PM (7 years ago)
Author:
kohlia
Message:

Pawn killing works too now

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/ScriptableController_HS17/src/orxonox/scriptablecontroller/scriptable_controller.cc

    r11583 r11606  
    44#include "infos/PlayerInfo.h"
    55#include "core/command/Executor.h"
     6#include "worldentities/pawns/Pawn.h"
    67
    78namespace orxonox
     
    6364}
    6465
    65 void ScriptableController::registerControllableEntity(std::string id, ControllableEntity *entity)
     66void ScriptableController::registerPawn(std::string id, Pawn *pawn)
    6667{
    67     this->worldEntities_[id] = entity;
     68    this->worldEntities_[id] = pawn;
     69    this->pawns_[id] = pawn;
     70    this->pawnsReverse_[pawn] = id;
     71}
     72
     73void 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
     89void 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
     105void 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();
    68115}
    69116
     
    77124}
    78125
    79 ControllableEntity *ScriptableController::getControllableEntityByID(std::string id) const
     126Pawn *ScriptableController::getPawnByID(std::string id) const
    80127{
    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;
    86130}
    87131
Note: See TracChangeset for help on using the changeset viewer.