ClientStage::ClientStage(const Stage& stage,const STRING gameObjectName):Stage(stage, gameObjectName) { PlayerMap tempPlayerMap = this->m_PlayerMap; MonsterMap tempMonsterMap = this->m_MonsterMap; this->m_PlayerMap.clear(); this->m_MonsterMap.clear(); std::for_each(tempPlayerMap.begin(), tempPlayerMap.end(), [this,&stage](PlayerMap::value_type& playerInfoPair){ Player* player = playerInfoPair.second; ASSERT_DEBUG(player != nullptr); ClientPlayer* clientPlayer = new ClientPlayer(*player); this->AddPlayer(clientPlayer->GetActorID(), clientPlayer); delete player; }); tempPlayerMap.clear(); // NOTE : replacing Monster object to ClientMonster object std::for_each(tempMonsterMap.begin(), tempMonsterMap.end(), [this](MonsterMap::value_type& monsterInfoPair){ Monster* monster = monsterInfoPair.second; ASSERT_DEBUG(monster != nullptr); ClientMonster* clientMonster = new ClientMonster(*monster); this->AddMonster(clientMonster->GetActorID(), clientMonster); delete monster; }); tempMonsterMap.clear(); }
/*! * \brief Get the player associated with id/name in the pool. * * \param idname String value of player's name or integer string of * player's identification. * * \return Reference to ChessPlayer. If player's id is NoPlayerId, then the * player wasn't found. */ ChessPlayer &getPlayer(const string idname) { PlayerMap::iterator pos; // try name first to find the player in the pool if( (pos = m_pool.find(idname)) != m_pool.end() ) { return pos->second; } long val; // convert to long if( str::tolong(idname, val) != OK ) { return ChessPlayer::noplayer(); } ChessPlayerId id = (ChessPlayerId)val; IdToNameMap::iterator idpos; // try to find player's id if( (idpos = m_idToName.find(id)) == m_idToName.end() ) { return ChessPlayer::noplayer(); } // now try again to find player in the pool if( (pos = m_pool.find(idpos->second)) != m_pool.end() ) { return pos->second; } else { return ChessPlayer::noplayer(); } }