You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
openmw-tes3coop/apps/openmw-mp/Player.cpp

127 lines
2.1 KiB
C++

//
// Created by koncord on 05.01.16.
//
#include "Player.hpp"
#include "Networking.hpp"
TPlayers Players::players;
TSlots Players::slots;
void Players::DeletePlayer(RakNet::RakNetGUID id)
{
LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Deleting player with guid %s",
id.ToString());
if (players[id] != 0)
{
LOG_APPEND(Log::LOG_INFO, "- Emptying slot %i",
players[id]->GetID());
slots[players[id]->GetID()] = 0;
delete players[id];
players.erase(id);
}
}
void Players::NewPlayer(RakNet::RakNetGUID id)
{
LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Creating new player with guid %s",
id.ToString());
players[id] = new Player(id);
players[id]->GetCell()->blank();
players[id]->Npc()->blank();
players[id]->NpcStats()->blank();
players[id]->CreatureStats()->blank();
players[id]->charClass.blank();
for (int i = 0; i < mwmp::Networking::Get().MaxConnections(); i++)
{
if (slots[i] == 0)
{
LOG_APPEND(Log::LOG_INFO, "- Storing in slot %i",
i);
slots[i] = players[id];
slots[i]->SetID(i);
break;
}
}
}
Player *Players::GetPlayer(RakNet::RakNetGUID id)
{
return players[id];
}
std::map<RakNet::RakNetGUID, Player*> *Players::GetPlayers()
{
return &players;
}
Player::Player(RakNet::RakNetGUID id) : BasePlayer(id)
{
handshake = false;
loaded = false;
lastAttacker = 0;
}
Player::~Player()
{
}
unsigned short Player::GetID()
{
return id;
}
void Player::SetID(unsigned short id)
{
this->id = id;
}
void Player::Handshake()
{
handshake = true;
}
bool Player::isHandshaked()
{
return handshake;
}
void Player::Loaded(int state)
{
loaded = state;
}
int Player::LoadedState()
{
return loaded;
}
Player *Players::GetPlayer(unsigned short id)
{
if (slots.find(id) == slots.end())
return nullptr;
return slots[id];
}
void Player::setLastAttackerID(unsigned short pid)
{
lastAttacker = pid;
}
void Player::resetLastAttacker()
{
lastAttacker = id;
}
unsigned short Player::getLastAttackerID()
{
return lastAttacker;
}