SchedulePtr ScheduleBroadcastCmd::GetSchedule() const { if ( m_spContext == NULL ) { return SchedulePtr(); } // Get schedule day const CFoundation::Date& today = m_spContext->GetGame()->GetDate(); ScheduleDay eScheduleDay = SCHEDULE_DAY_END; if ( m_Date == today ) { eScheduleDay = SCHEDULE_DAY_TODAY; } else if ( m_Date == today + 1 ) { eScheduleDay = SCHEDULE_DAY_TOMORROW; } PlayerPtr spPlayer = m_spContext->GetPlayer(); if ( spPlayer == NULL ) { return SchedulePtr(); } // Get schedule SchedulingPtr spScheduling = spPlayer->GetScheduling(); return spScheduling->GetSchedule( eScheduleDay ); }
bool GameService::ProcessMsg(InsideMessage* msg) { if (!msg) return false; CallBackType cbType = _calltype[msg->_msgid]; switch (cbType) { case cbInsideDelegate: _inside_delegate.Call(msg->_msgid, *msg); break; case cbSessionInsideDelegate: { PlayerSessionPtr session = _session_manager->GetSession(msg->_sessionid); std::pair<PlayerSession*, InsideMessage*> arg = std::make_pair(session.get(), msg); _session_inside_delegate.Call(msg->_msgid, arg); } break; case cbPlayerInsideDelegate: { PlayerPtr player = GetPlayer(msg->_sessionid); std::pair<Player*, InsideMessage*> arg = std::make_pair(player.get(), msg); _player_inside_delegate.Call(msg->_msgid, arg); } break; default: break; } return true; }
void ScheduleNewsCmd::Execute() const { if ( m_spContext == NULL ) { return; } PlayerPtr spPlayer = m_spContext->GetPlayer(); if ( spPlayer == NULL ) { return; } // Get news component PlayerCompNewsPtr spCompNews = spPlayer->GetCompNews(); if ( m_spNews != NULL ) { // Pay the news Budget& budget = spPlayer->GetBudget(); budget.Book( CMadTV::ACCOUNT_CASH, CMadTV::ACCOUNT_NEWS_COSTS, m_spNews->GetCurrentPrice(), m_spContext->GetGame()->GetDateTime(), "Bought news" ); } // Schedule spCompNews->SetPlannedNews( m_u32Slot, m_spNews ); }
int Player::Attack(PlayerPtr target, int baseDamage) { int attackDamage = baseDamage; //todo: let level have an effect on this int rd = attackDamage/2 + rand() % (attackDamage + 1 / 2); int causedDamage = rd - rand() % target->GetDP(); target->OnDamage(causedDamage, std::dynamic_pointer_cast<GameObject>(Ptr())); return causedDamage; }
GS2D_API PlayerPtr CreatePlayer(VideoPtr pVideo, const std::wstring& fileName) { PlayerPtr player = PlayerPtr(new DShowPlayer); if (!player->LoadVideo(pVideo, fileName)) { return PlayerPtr(); } return player; }
void Gamefield::onStart(ClientPtr client, PacketPtr packet) { auto p = std::dynamic_pointer_cast<StartPacket >(packet); String color = mOptions.player.color[rand()%mOptions.player.color.size()]; printf("Player %s joind the game\n", p->Name.c_str()); PlayerPtr ply = std::make_shared<Player>(shared_from_this(), client, color, p->Name); mPlayer[client->getId()] = ply; ply->addBall(createBall(ply)); ply->updateClient(); client->emit(std::make_shared<EmptyPacket<PID_Start> >()); }
void PlayerBehavior::update( ) { //何もしなかったら待機 _player_state = PLAYER_STATE_WAIT; CONTROLL controll = makeControll( ); walk( controll ); attack( controll ); AppPtr app = App::getTask( ); if ( _parent->getStatus( ).hp <= 0 ) { _player_state = PLAYER_STATE_DEAD; SoundPtr sound = Sound::getTask( ); sound->playSE( Sound::SE_GAME_OVER ); ClientPtr client = Client::getTask( ); SERVERDATA data; data.command = COMMAND_STATUS_POS; data.value[ 0 ] = _player_id; data.value[ 1 ] = 0; data.value[ 2 ] = 0; client->send( data ); if ( _controll ) { app->setState( App::STATE_DEAD ); } } else { PlayerPtr player = std::dynamic_pointer_cast< Player >( _parent ); player->addSP( 1 ); } _before_state = _player_state; PlayerPtr player = std::dynamic_pointer_cast< Player >( _parent ); int sp = player->getSP( ); //AdventurePtr adventure = app->getAdventure( ); if ( ( !_is_tutorial_sence ) && ( sp == Player::FULL_SP_NUM ) && _controll ) { //adventure->set( Adventure::TYPE_COMMON_TUTORIAL_3 ); _is_tutorial_sence = true; } for ( int i = PLAYER_ETUDE_RED; i <= PLAYER_ETUDE_BLUE; i++ ) { Vector pos = _parent->getPos( ) - app->getPlayer( i )->getPos( ); if ( !_is_conntact_minotaur && ( _player_id < PLAYER_ETUDE_RED ) && ( pos.getLength( ) < CONNTACT_MINOTAUR_LENGTH ) && _controll ) { //adventure->set( Adventure::TYPE_COMMON_CYCLOPS_CONTACT ); //adventure->set( Adventure::TYPE_COMMON_AFTER_MINOTAUR_ENTRY ); _is_conntact_minotaur = true; } } _keep_pos = _parent->getPos( ); }
void App::comparePos(PlayerPtr player) { if (player->getY() > getPos() + 2.5) { speed = 0.15; } else { speed = base_speed; } }
void Transport::Start(utfstring url){ #ifdef _DEBUG std::cerr << "Transport::Start called" << std::endl; #endif // Check if this is already Prepared PlayerPtr player = this->nextPlayer; this->nextPlayer.reset(); #ifdef _DEBUG std::cerr << "Transport: nextPlayer reset" << std::endl; #endif // If the nextPlayer wasn't the same as the one started, lets create a new one if(!player || player->url!=url){ // Or create a new player Player::OutputPtr output; #ifdef _DEBUG std::cerr << "Transport: new output created for player" << std::endl; #endif player = Player::Create(url, &output); player->SetVolume(this->volume); #ifdef _DEBUG std::cerr << "Transport: new player created" << std::endl; #endif } // Add to the players this->players.push_front(player); this->currentPlayer = player; #ifdef _DEBUG std::cerr << "Transport: player added to player list" << std::endl; #endif // Lets connect to the signals of the currentPlayer this->currentPlayer->PlaybackStarted.connect(this,&Transport::OnPlaybackStarted); this->currentPlayer->PlaybackAlmostEnded.connect(this,&Transport::OnPlaybackAlmostEnded); this->currentPlayer->PlaybackEnded.connect(this,&Transport::OnPlaybackEnded); this->currentPlayer->PlaybackError.connect(this, &Transport::OnPlaybackError); #ifdef _DEBUG std::cerr << "Transport: player-Play() about to be called" << std::endl; #endif // Start playing player->Play(); }
void Scene::initPlayer( PlayerPtr player, const std::string& image_filename ) { int ID = player->ID_NUM; // Init Sprite and Info playerSprites[ID] = ci::gl::Texture( loadImage( loadAsset(image_filename) ) ); spriteInfo[ID].sheetWidth = playerSprites[ID].getWidth(); spriteInfo[ID].width = player->getWidth(); playerPtrs[ID] = player; }
void ClearRecentlySubscribedChannelsCmd::Execute() const { if ( m_spContext == NULL ) { return; } PlayerPtr spPlayer = m_spContext->GetPlayer(); if ( spPlayer == NULL ) { return; } // Get news component PlayerCompNewsPtr spCompNews = spPlayer->GetCompNews(); // Clear recently subscribed channels spCompNews->RemoveRecentlySubscribedChannels(); }
void GameEngine::onPlayerAction(GameActionPtr action, PlayerPtr player) { cout << "GameEngine::onPlayerAction(...)" << endl; if (logic.checkPlayerAction(player, action) == true) { std::cout << "Action ist gueltig.\n"; doAction(player, action); std::cout << "Action ausgeführt.\n"; } else { std::cout << "Action von Spieler #" << player->getPlayerIdStr() << " ist ungueltig.\n"; } }
Bomb::Bomb(PlayerPtr owner, Position position, int explosion_range) : m_anim_frame_num(0), m_position(position), m_time_from_last_frame_switch(.0), m_aabb(position+Position(.1,.1), position+Position(.9,.9)), m_owner(owner), m_owner_id(owner->GetId()), m_explision_range(explosion_range), m_living_time(0) { SetAliveFlag(true); }
int main(int argc, char** argv) { Options opts; opts.addOpt("t", "timeout", Options::NeedArg, "5"); opts.addOpt("b", "broadcast"); try { opts.parse(argc, (const char**)argv); } catch(const IceUtilInternal::BadOptException& e) { cerr << argv[0] << ": " << e.reason << endl; return EXIT_FAILURE; } Game game; game.hits = 0; game.state = StateStart; game.broadcast = opts.isSet("b"); game.noise = false; PlayerPtr playerA = new Player(&game, StatePlayerA); playerA->start(); PlayerPtr playerB = new Player(&game, StatePlayerB); playerB->start(); cout << "running spurious wake test (" << ((game.broadcast) ? "broadcast" : "signal") << ")... " << flush; ThreadControl::sleep(Time::seconds(atoi(opts.optArg("t").c_str()))); if(game.broadcast) { { Mutex::Lock sync(game.mutex); game.noise = true; } for(int i =0 ; i < 100000; ++i) { game.cond.broadcast(); } { Mutex::Lock sync(game.mutex); game.noise = false; } } { Mutex::Lock sync(game.mutex); game.state = StateGameOver; game.cond.broadcast(); } playerA->getThreadControl().join(); playerB->getThreadControl().join(); cout << game.hits << " ok" << endl; return 0; }
Unsigned32 ScheduleNewsCmd::Verify() const { if ( m_spContext == NULL ) { return ERROR_NONE; } PlayerPtr spPlayer = m_spContext->GetPlayer(); if ( spPlayer == NULL ) { return ERROR_NONE; } // Get news component PlayerCompNewsPtr spCompNews = spPlayer->GetCompNews(); // Check if slot is valid if ( m_u32Slot >= PlayerCompNews::NUM_PLANNED_NEWS ) { return ERROR_INVALID_SLOT; } // Check if player has news if ( m_spNews != NULL && !spCompNews->HasNews( m_spNews ) ) { return ERROR_NEWS_NOT_AVAILABLE; } // Check if enough money available Budget& budget = spPlayer->GetBudget(); if ( m_spNews != NULL && budget.GetCash() < m_spNews->GetCurrentPrice() ) { return ERROR_INSUFFICIENT_MONEY; } return ERROR_NONE; }
void GeneticOperators::configure( const std::vector<SparCraft::Unit>& fixedBuildings, const std::vector<SparCraft::Unit>& buildings, const std::vector<SparCraft::Unit>& defenders, const std::vector<std::vector<SparCraft::Unit> > attackers, const std::vector<std::pair<Unit, TimeType> > delayedDefenders, const std::vector<std::vector<std::pair<Unit, TimeType> > > delayedAttackers, Map* map, Display* display, PlayerPtr p1, PlayerPtr p2, svv expDesc) { assert(attackers.size()==delayedAttackers.size());//same amount of attack waves _fixedBuildings=fixedBuildings; _buildings=buildings; _defenders=defenders; _attackers=attackers; _delayedAttackers=delayedAttackers; _delayedDefenders=delayedDefenders; _map=map; _display=display; if(p1->getType()==PlayerModels::Assault){ _assaultPlayer=boost::dynamic_pointer_cast<Player_Assault>(p1); _defendPlayer=boost::dynamic_pointer_cast<Player_Defend>(p2); }else{ _assaultPlayer=boost::dynamic_pointer_cast<Player_Assault>(p2); _defendPlayer=boost::dynamic_pointer_cast<Player_Defend>(p1); } _expDesc=expDesc; // Position average; // BOOST_FOREACH(const Unit &u,_fixedBuildings){ // average+=u.pos(); // } // BOOST_FOREACH(const Unit &u,_buildings){ // average+=u.pos(); // } // average.scale(1.0f/(_fixedBuildings.size()+_buildings.size())); // _baseLeft=std::numeric_limits<int>::max(); _baseRight=std::numeric_limits<int>::min(); _baseTop=std::numeric_limits<int>::max(); _baseBottom=std::numeric_limits<int>::min(); BOOST_FOREACH(const Unit &u,_fixedBuildings){ _baseLeft=std::min(_baseLeft,Map::floorDiv((u.x()-u.type().dimensionLeft()),TILE_SIZE)); _baseRight=std::max(_baseRight,Map::ceilDiv((u.x()+u.type().dimensionRight()),TILE_SIZE)); _baseTop=std::min(_baseTop,Map::floorDiv((u.y()-u.type().dimensionUp()),TILE_SIZE)); _baseBottom=std::max(_baseBottom,Map::ceilDiv((u.y()+u.type().dimensionDown()),TILE_SIZE)); }
const Point TriangleGroupShips::get_position_ship(const uint8_t id) const { Point leader_pos = leader_->get_position(); Vector2<float> leader_direction = leader_->get_velocity(); if(leader_->is_current_state(State::ATTACKING)) { leader_direction = player->get_position() - leader_->get_position(); } leader_direction.normalize(); Vector2<float> leader_direction_t = leader_direction.get_normal(); Vector2<float> base_group = -leader_direction; base_group = base_group*75.f; float offset_per_stage = 50.f*(id/2 + 1); return Point(leader_pos + base_group + leader_direction_t*offset_per_stage - leader_direction*(id/2)*75.f - leader_direction_t*(id%2)*2.f*offset_per_stage); }
inline void removePlayer(const PlayerPtr player) { removePlayer(player ? player->getID() : 0); }
int CPlayer::OnPacket(CRecvMsgPacket& msgPack) { //DebugInfo("CPlayer::OnPacket Start PID XYID=%d Len=%d",m_PID,msgPack.m_XYID,msgPack.m_nLen ); int nRet = 0; switch ( msgPack.m_XYID ) { case GameXY::ReqRoomInfo::XY_ID: case GameXY::ReqRoomTableInfo::XY_ID: case GameXY::ReqJoinRoom::XY_ID: case GameXY::ReqLeaveRoom::XY_ID: case GameXY::ReqJoinTable::XY_ID: case GameXY::ReqChangeTable::XY_ID: case GameXY::ReqTailInfo::XY_ID: case GameXY::ChangeUserInfo::XY_ID: case GameXY::ReqPlayerAward::XY_ID: case GameXY::ReqTracePlayer::XY_ID: case GameXY::Game_MsgFlag::XY_ID: case GameXY::Game_Test::XY_ID: { if( m_pServer ) { nRet = m_pServer->OnServerMsg(this,msgPack); } else { DebugError("CPlayer::OnPacket Server=NULL PID=%d AID=%d id=%d len=%d",m_PID,m_AID,msgPack.m_XYID,msgPack.m_nLen); } } break; case GameXY::ClientToServerMessage::XY_ID: case GameXY::ReqPlayerAct::XY_ID: case GameXY::ReqLeaveTable::XY_ID: { if( m_pTable && m_TableID ) { nRet = m_pTable->OnTableMsg(this,msgPack); } else { DebugError("CPlayer::OnPacket PID=%d m_pRoom=%d m_RoomID=%d m_pTable=NULL TableID=%d msgid=%d msglen=%d", m_PID,m_pRoom,m_RoomID,m_TableID,msgPack.m_XYID,msgPack.m_nLen ); if ( msgPack.m_XYID == GameXY::ClientToServerMessage::XY_ID ) { GameXY::ClientToServerMessage CTSMsg; ExplainMsg(msgPack,CTSMsg); DebugError("CPlayer::OnPacket GameMsg XYID=%d XYLEN=%d",CTSMsg.m_MsgID,CTSMsg.m_MsgLen); } else if ( msgPack.m_XYID == GameXY::ReqPlayerAct::XY_ID ) { GameXY::ReqPlayerAct rpa; TransplainMsg(msgPack,rpa); DebugError("PlayerAct Action=%d SitID=%d TableID=%d TakeMoney=%s", rpa.m_Action,rpa.m_SitID,rpa.m_TableID,N2S(rpa.m_nTakeMoney.get()).c_str()); if ( m_pRoom ) { CGameTable* pTable = m_pRoom->GetTableByID(rpa.m_TableID); if ( pTable ) { PlayerPtr pPlayer = pTable->GetTablePlayerByPID(m_PID); if ( pPlayer ) { DebugError("Player In Table PID=%d TableID=%d",pPlayer->GetPID(),pTable->GetTableID() ); } } } GameXY::PlayerLeaveTableInfo lt; lt.m_RoomID = m_RoomID; lt.m_TableID = rpa.m_TableID; lt.m_PID = m_PID; SendMsg(lt); } else if ( msgPack.m_XYID == GameXY::ReqLeaveTable::XY_ID ) { GameXY::ReqLeaveTable rlv; TransplainMsg(msgPack,rlv); DebugError("LeaveTable RoomID=%d TableID=%d pRoom=%d pTable=%d",rlv.m_RoomID,rlv.m_TableID,m_pRoom,m_pTable); if ( m_pRoom ) { CGameTable* pTable = m_pRoom->GetTableByID(rlv.m_TableID); if ( pTable ) { PlayerPtr pPlayer = pTable->GetTablePlayerByPID(m_PID); if ( pPlayer ) { DebugError("Player In Table PID=%d TableID=%d",pPlayer->GetPID(),pTable->GetTableID() ); } } } GameXY::PlayerLeaveTableInfo lt; lt.m_RoomID = rlv.m_RoomID; lt.m_TableID = rlv.m_TableID; lt.m_PID = m_PID; SendMsg(lt); } } } break; default: { DebugError("CPlayer::OnPacket 无法处理协议 id=%d len=%d",msgPack.m_XYID,msgPack.m_nLen); } } //DebugInfo("CPlayer::OnPacket End"); return nRet; }
void Game::Tick( float time ) { if( HandleEvents( *m_window ) ) { m_running = false; } m_networkhandler->Tick(); m_window->clear( sf::Color( 0, 0, 0, 255 ) ); glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); glMatrixMode( GL_PROJECTION ); glPushMatrix(); glLoadIdentity(); glOrtho( 0.0f, m_window->getSize().x, m_window->getSize().y, 0.0f, -512.0f, 512.0f ); PlayerPtr player = GetPlayer(); if( player && player->GetAgent() ) { glTranslatef( static_cast<float>( m_window->getSize().x ) / 2.0f - player->GetAgent()->GetPosition().x, static_cast<float>( m_window->getSize().y ) / 2.0f - player->GetAgent()->GetPosition().y, 0.0f ); } glMatrixMode( GL_MODELVIEW ); if( m_networkhandler->IsAuthenticated() ) { m_objectmanager->Tick( time ); if( m_player ) { m_player->Tick( time ); } if( m_system ) { m_system->Draw( *m_window, time ); } else { m_window->clear( sf::Color( 0, 0, 0, 255 ) ); } m_objectmanager->DrawAll( *m_window ); } else { m_window->clear( sf::Color( 0, 0, 0, 255 ) ); } glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_COLOR_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); m_gui->Draw( *m_window ); glDisableClientState( GL_TEXTURE_COORD_ARRAY ); glDisableClientState( GL_COLOR_ARRAY ); glDisableClientState( GL_VERTEX_ARRAY ); glMatrixMode( GL_PROJECTION ); glPopMatrix(); // Display window contents on screen m_window->display(); }
void Scene::drawPlayers() { for( int i = 0; i < playerPtrs.size(); i++ ) { PlayerPtr player = playerPtrs[i]; gl::Texture &sprite = playerSprites[i]; SpriteInfo &info = spriteInfo[i]; // Draw Player gl::pushMatrices(); gl::translate( player->getPos() ); // Invert y axis to draw the image normally // * Note that this is done after the translation gl::scale(1, -1); gl::enableAlphaBlending(); glEnable(GL_TEXTURE_2D); sprite.enableAndBind(); glBegin(GL_QUADS); float frame = player->getFrame(); glTexCoord2f( (info.width * frame)/info.sheetWidth, 0 ); glVertex2f( 0, 0); glTexCoord2f( (info.width * frame + info.width)/info.sheetWidth, 0 ); glVertex2f( info.width, 0 ); glTexCoord2f( (info.width * frame + info.width)/ info.sheetWidth, 1 ); glVertex2f( info.width, info.width); glTexCoord2f( (info.width * frame)/info.sheetWidth, 1 ); glVertex2f( 0, info.width); glEnd(); sprite.unbind(); glDisable(GL_TEXTURE_2D); gl::disableAlphaBlending(); gl::popMatrices(); // Draw Hit Box for testing purposes if(DRAW_HITBOX) { ci::Vec4f box = player->getHitBox(); if( box.z > 0.0f ) { gl::pushMatrices(); gl::drawSolidCircle( box.xy(), box.z ); gl::popMatrices(); } } if( player->mustServe() ) { gl::pushMatrices(); gl::scale(1, -1); glEnable( GL_TEXTURE_2D ); gl::enableAlphaBlending(); mText->drawString( "PLAYER " + std::to_string(i+1) + " SERVE", Vec2f( WINDOW_WIDTH * (-0.2f/2.0f), -WINDOW_HEIGHT * 0.40f ) ); gl::disableAlphaBlending(); glDisable( GL_TEXTURE_2D ); gl::popMatrices(); } } }
void GameEngine::doAction(PlayerPtr player, GameActionPtr action) { std::cout << "GameEngine::doAction(...).\n"; ARecruit* recruit = dynamic_cast<ARecruit*>(action.get()); AMove* move = dynamic_cast<AMove*>(action.get()); ABuild* build = dynamic_cast<ABuild*>(action.get()); AAttack* attack = dynamic_cast<AAttack*>(action.get()); std::cout << "GameEngine::doAction: checking type.\n"; if (recruit != NULL) { std::cout << "GameEngine::doAction: got a ARecruit.\n"; EUnitPtr unit(recruit->what); // ELocationPtr base(recruit->base); GameRessourcePtr costs(recruit->costs); player->addUnit(unit); } if (move != NULL) { std::cout << "GameEngine::doAction: got a AMove.\n"; map->printMapStatus(); GameEntityPtr what(move->what); coordinates from = what->getCoords(); coordinates to = move->to; map->setArmy(to); map->setWalkable(from); what->setCoords(to); map->printMapStatus(); } if (build != NULL) { std::cout << "GameEngine::doAction: got a ABuild.\n"; EBuildingPtr building(build->what); ELocationPtr where(build->where); where->addBuilding(building); } if (attack != NULL) { std::cout << "GameEngine::doAction: got a AAttack.\n"; GameEntityPtr what(attack->what); coordinates where = attack->where; EArmyPtr enemyarmy; PlayerPtr enemyplayer; for (auto p : *playerlist) { for (auto army : p->armies) { if (army->getCoords().x == where.x && army->getCoords().y == where.y) { EArmyPtr ea(army); PlayerPtr ep(p); enemyarmy = ea; enemyplayer = ep; } } } } std::cout << "------------------------------\n"; //GameNetwork.broadcast(action); }
GS_PLAYER_INFO PlayCutscene(VideoPtr pVideo, const std::wstring& fileName, InputPtr pInput, const GS_KEY escapeKey) { if (!pVideo) { ShowMessage(L"Invalid video handler - gs2d::PlayCutscene", GSMT_ERROR); return GSPI_FAILED; } GS_PLAYER_INFO info = GSPI_FINISHED; //pVideo->TurnLoopManagerOff(); const bool rendering = pVideo->Rendering(); if (rendering) pVideo->EndSpriteScene(); PlayerPtr player = CreatePlayer(pVideo, fileName); if (!player) { ShowMessage(L"Failed while trying to load the video - gs2d::PlayCutscene", GSMT_ERROR); if (rendering) pVideo->BeginSpriteScene(); return GSPI_FAILED; } pVideo->EnableMediaPlaying(true); player->SetFullscreen(); player->Rewind(); player->Play(); while (!player->IsFinished()) { player->UpdateVideo(); const Video::APP_STATUS status = pVideo->HandleEvents(); if (status == Video::APP_QUIT) { info = GSPI_CLOSE_WINDOW; break; } else { if (status == Video::APP_SKIP) continue; } if (pInput) { pInput->Update(); if (pInput->GetKeyState(escapeKey) == GSKS_HIT) { info = GSPI_SKIPPED; break; } } } if (rendering) pVideo->BeginSpriteScene(); pVideo->EnableMediaPlaying(false); return info; }
void MemorySensor::DetectPlayers() { uintptr_t addr = Memory::GetU32(m_ProcessHandle, m_ContBaseAddr + 0xC1AFC); // Starting address addr += 0x127EC; uintptr_t count_addr = addr + 0x1884; uintptr_t players_addr = addr + 0x884; unsigned short count = Memory::GetU32(m_ProcessHandle, count_addr) & 0xFFFF; const unsigned char NameOffset = 0x6D; const unsigned char FreqOffset = 0x58; const unsigned char RotOffset = 0x3C; const unsigned char PosOffset = 0x04; const unsigned char SpeedOffset = 0x10; const unsigned char IDOffset = 0x18; const unsigned char ShipOffset = 0x5C; for (auto kv : m_Players) kv.second->SetInArena(false); for (unsigned short i = 0; i < count; ++i) { uintptr_t player_addr = Memory::GetU32(m_ProcessHandle, players_addr + (i * 4)); if (player_addr == 0) continue; short x = Memory::GetU32(m_ProcessHandle, player_addr + PosOffset) / 1000; short y = Memory::GetU32(m_ProcessHandle, player_addr + PosOffset + 4) / 1000; int xspeed = static_cast<int>(Memory::GetU32(m_ProcessHandle, player_addr + SpeedOffset)) / 10; int yspeed = static_cast<int>(Memory::GetU32(m_ProcessHandle, player_addr + SpeedOffset + 4)) / 10; unsigned short rot = Memory::GetU32(m_ProcessHandle, player_addr + RotOffset) / 1000; unsigned int freq = Memory::GetU32(m_ProcessHandle, player_addr + FreqOffset); unsigned short pid = Memory::GetU32(m_ProcessHandle, player_addr + IDOffset); unsigned short ship = Memory::GetU32(m_ProcessHandle, player_addr + ShipOffset); std::string name = Memory::GetString(m_ProcessHandle, player_addr + NameOffset, 23); name = name.substr(0, strlen(name.c_str())); // trim nulls PlayerPtr player; auto found = m_Players.find(pid); if (found == m_Players.end()) { player = std::make_shared<Player>(); m_Players[pid] = player; } else { player = found->second; } x = (short)std::max(std::min((int)x, 1023 * 16), 0); y = (short)std::max(std::min((int)y, 1023 * 16), 0); player->SetInArena(true); player->SetName(name); player->SetFreq(freq); player->SetRotation(rot); player->SetPosition(Vec2(x, y)); player->SetVelocity(Vec2(xspeed, yspeed)); player->SetPid(pid); player->SetShip(static_cast<Ship>(ship)); } for (auto iter = m_Players.begin(); iter != m_Players.end(); ) { if (!iter->second->InArena()) { //std::cout << "Erasing " << iter->second->GetName() << std::endl; iter = m_Players.erase(iter); } else { ++iter; } } }
inline bool searchPlayer(const PlayerPtr player) const { return (player ? this->searchPlayer(player->getID()) : false); }