diff --git a/Code/Game/GameClient/GameClientState/GameState.cpp b/Code/Game/GameClient/GameClientState/GameState.cpp index c65aa7b4..e00c9d4f 100644 --- a/Code/Game/GameClient/GameClientState/GameState.cpp +++ b/Code/Game/GameClient/GameClientState/GameState.cpp @@ -149,6 +149,11 @@ void GameState::InitiatePlayer( int id, const std::string &modelName, const floa this->privData->camera.UpdateOrientation(); } } + else + { + int i = 0; + // some error loading model + } } GameClientState::ClientState GameState::Update( float deltaTime ) @@ -736,11 +741,20 @@ const GameClientState::NetEvent & GameState::DataRecieved( const GameClientState { //Remove the disconnected player Protocol_ObjectDisconnectPlayer decoded(data); - auto object = this->privData->dynamicObjects->find( decoded.objectID ); - if( object != this->privData->dynamicObjects->end() ) + C_Player *player; + player = (this->privData->players)[decoded.objectID]; + + if( player ) { - object->second = nullptr; - this->privData->dynamicObjects->erase( object ); + if( this->privData->myId == decoded.objectID ) + { + // dont delete my player + } + if( player ) + { + player->SetVisible(false); + (this->privData->players)[decoded.objectID].Release(); + } } } return GameClientState::event_processed; diff --git a/Code/Game/GameLogic/Level.cpp b/Code/Game/GameLogic/Level.cpp index 56c0e21c..6d6c588d 100644 --- a/Code/Game/GameLogic/Level.cpp +++ b/Code/Game/GameLogic/Level.cpp @@ -332,6 +332,9 @@ void Level::AddPlayerToTeam(Player *player, int teamID) } void Level::AddPlayerToGame(Player *player) { + int i = rand() % spawnPoints.Size(); + Float3 spawnPoint = spawnPoints[i]; + player->ResetPlayer(spawnPoint); for(int i = 0; i < (int)this->playerObjects.Size(); i++) { if (!this->playerObjects[i]) @@ -373,28 +376,31 @@ void Level::Update(float deltaTime) for(int i = 0; i < (int)this->playerObjects.Size(); i++) { - if(this->playerObjects[i]->getAffectingPlayer() != NULL) + if(this->playerObjects[i]) { - - } - - if (this->playerObjects[i]->GetState() == PLAYER_STATE::PLAYER_STATE_DEAD) - { - // true when timer reaches 0 - if(this->playerObjects[i]->deathTimerTick(deltaTime)) - RespawnPlayer(this->playerObjects[i]); - } - else if (this->playerObjects[i]->GetState() == PLAYER_STATE::PLAYER_STATE_DIED) - { - this->playerObjects[i]->setDeathTimer(DEATH_TIMER); - // HACK to avoid crasch. affected by tag is NULL - //((Game*)&Game::Instance())->onDeadFnc(this->playerObjects[i], this->playerObjects[i], DEATH_TIMER); // add killer ID - Player* killer = this->playerObjects[i]->getAffectingPlayer(); - if(!killer) //if there is no killer then you commited suicide + if(this->playerObjects[i]->getAffectingPlayer() != NULL) { - killer = this->playerObjects[i]; + + } + + if (this->playerObjects[i]->GetState() == PLAYER_STATE::PLAYER_STATE_DEAD) + { + // true when timer reaches 0 + if(this->playerObjects[i]->deathTimerTick(deltaTime)) + RespawnPlayer(this->playerObjects[i]); + } + else if (this->playerObjects[i]->GetState() == PLAYER_STATE::PLAYER_STATE_DIED) + { + this->playerObjects[i]->setDeathTimer(DEATH_TIMER); + // HACK to avoid crasch. affected by tag is NULL + //((Game*)&Game::Instance())->onDeadFnc(this->playerObjects[i], this->playerObjects[i], DEATH_TIMER); // add killer ID + Player* killer = this->playerObjects[i]->getAffectingPlayer(); + if(!killer) //if there is no killer then you commited suicide + { + killer = this->playerObjects[i]; + } + ((Game*)&Game::Instance())->onDeadFnc(this->playerObjects[i], killer, DEATH_TIMER); // add killer ID } - ((Game*)&Game::Instance())->onDeadFnc(this->playerObjects[i], killer, DEATH_TIMER); // add killer ID } } diff --git a/Code/Game/GameLogic/Player.cpp b/Code/Game/GameLogic/Player.cpp index e8787a1b..407aa2bc 100644 --- a/Code/Game/GameLogic/Player.cpp +++ b/Code/Game/GameLogic/Player.cpp @@ -15,6 +15,8 @@ Player::Player() Player::initPlayerData(); this->weapon = NULL; this->teamID = -1; + this->playerScore.killScore = 0; + this->playerScore.deathScore = 0; } Player::Player(Oyster::Physics::ICustomBody *rigidBody, void (*EventOnCollision)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type, int objectID, int teamID) @@ -23,6 +25,8 @@ Player::Player(Oyster::Physics::ICustomBody *rigidBody, void (*EventOnCollision) this->weapon = new Weapon(2,this); Player::initPlayerData(); this->teamID = teamID; + this->playerScore.killScore = 0; + this->playerScore.deathScore = 0; } Player::Player(Oyster::Physics::ICustomBody *rigidBody, Oyster::Physics::ICustomBody::SubscriptMessage (*EventOnCollision)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type, int objectID, int teamID) @@ -31,6 +35,8 @@ Player::Player(Oyster::Physics::ICustomBody *rigidBody, Oyster::Physics::ICustom this->weapon = new Weapon(2,this); Player::initPlayerData(); this->teamID = teamID; + this->playerScore.killScore = 0; + this->playerScore.deathScore = 0; } Player::~Player(void) @@ -45,8 +51,6 @@ void Player::initPlayerData() { this->playerStats.hp = MAX_HP; this->playerStats.movementSpeed = BASIC_SPEED; - this->playerScore.killScore = 0; - this->playerScore.deathScore = 0; this->playerState = PLAYER_STATE_IDLE; this->lookDir = Oyster::Math::Float3(0,0,-1); @@ -309,7 +313,13 @@ void Player::Inactivate() { //this-> } - +void Player::ResetPlayer( Oyster::Math::Float3 spawnPos) +{ + Player::initPlayerData(); + this->rigidBody->SetPosition(spawnPos); + this->playerScore.killScore = 0; + this->playerScore.deathScore = 0; +} Oyster::Math::Float3 Player::GetPosition() const { return (Oyster::Math::Float3) this->rigidBody->GetState().centerPos; diff --git a/Code/Game/GameLogic/Player.h b/Code/Game/GameLogic/Player.h index edb4cc79..965abfd9 100644 --- a/Code/Game/GameLogic/Player.h +++ b/Code/Game/GameLogic/Player.h @@ -82,6 +82,7 @@ namespace GameLogic bool IsIdle(); void Inactivate(); + void ResetPlayer( Oyster::Math::Float3 spawnPos); Oyster::Math::Float3 GetPosition() const; Oyster::Math::Float3 GetLookDir() const; diff --git a/Code/Game/GameServer/Implementation/GameClient.cpp b/Code/Game/GameServer/Implementation/GameClient.cpp index 74795ce6..0c33ba89 100644 --- a/Code/Game/GameServer/Implementation/GameClient.cpp +++ b/Code/Game/GameServer/Implementation/GameClient.cpp @@ -25,6 +25,10 @@ GameClient::GameClient(Utility::DynamicMemory::SmartPointerplayer) + { + this->player->Inactivate(); + } this->isReady = false; this->character = L"char_orca.dan"; this->alias = L"Unknown";