Timer iznogoud.

This commit is contained in:
MarcEricMartel
2023-12-06 11:16:39 -05:00
parent 9c1cd885cf
commit c975265901
12 changed files with 118 additions and 54 deletions

View File

@@ -200,8 +200,8 @@ void Server::Run() {
m_world->BuildWorld();
for (auto& [key, conn] : m_conns) { // Creation des instances de joueurs et premier sync.
int x = (rand() % (CHUNK_SIZE_X * WORLD_SIZE_X - 1)) - (CHUNK_SIZE_X * WORLD_SIZE_X / 2),
y = (rand() % (CHUNK_SIZE_Y * WORLD_SIZE_Y - 1)) - (CHUNK_SIZE_Y * WORLD_SIZE_Y / 2);
int x = 0,// (rand() % (CHUNK_SIZE_X * WORLD_SIZE_X - 1)),// -(CHUNK_SIZE_X * WORLD_SIZE_X / 2),
y = 0;// (rand() % (CHUNK_SIZE_Y * WORLD_SIZE_Y - 1));// -(CHUNK_SIZE_Y * WORLD_SIZE_Y / 2);
conn->player = new Player(Vector3f(x + .5f, CHUNK_SIZE_Y + 1.8f, y + .5f));
m_players[key] = conn->player;
Sync sync;
@@ -270,8 +270,10 @@ void Server::Run() {
if (conn->player->AmIDead()) {
Chat chat;
chat.dest_id = chat.dest_team_id = chat.src_id = 0;
std::string killer = m_conns.at(key)->player->GetUsername();
strcpy(chat.mess, getDeathMessage(conn->player->GetUsername()).c_str());
strcpy(chat.mess, getDeathMessage(conn->player->GetUsername(), killer).c_str());
m_chatlog[tstamp] = chat;
@@ -285,9 +287,10 @@ void Server::Run() {
for (auto& bull : conn->Bullets) {
bullets.emplace_back(bull);
Log("POW!", false, false);
BulletAdd* nbul = new BulletAdd();
nbul->pos = conn->player->GetPosition();
nbul->dir = conn->player->GetDirection();
nbul->pos = bull->getPos();
nbul->dir = bull->getVel();
nbul->id = key;
nbul->tstamp = tstamp;
@@ -300,10 +303,10 @@ void Server::Run() {
conn->sendPacks(m_sock_udp, m_conns, timer);
}
if (deadplayers == players - 1 || timer <= 0)
endgame = true;
//if (/*(deadplayers == players - 1 && deadplayers != 0) || */timer <= 0)
//endgame = true;
}
for (auto& bull : netbull)
for (auto& [key, conn] : m_conns)
if (bull->id != conn->GetHash(false)) // Pour pas repitcher au joueur sa propre balle.
@@ -319,9 +322,11 @@ void Server::Run() {
}
}
for (auto& chat : chatlog)
for (auto& [key, conn] : m_conns)
for (auto& chat : chatlog) {
Log(chat.mess, false, false);
for (auto& [key, conn] : m_conns)
sendPackTo<Chat>(m_sock_udp, &chat, &m_buf, conn->getAddr());
}
for (auto& chmo : chunkdiffs) {
for (auto& [key, conn] : m_conns)
@@ -420,13 +425,26 @@ uint64_t Server::getUniqueId() {
return id;
}
std::string Server::getDeathMessage(std::string username) const {
std::string Server::getDeathMessage(std::string username, std::string killer) const {
std::string mess;
std::string temp = DEATHMESSAGES.at(rand() % DEATHMESSAGES.size());
size_t ind = temp.find('@');
mess.append(temp.substr(0, ind));
mess.append(username));
mess.append(temp.substr(ind + 1));
size_t indk = temp.find('$');
if (ind < indk) {
mess.append(temp.substr(0, ind));
mess.append(username);
mess.append(temp.substr(ind + 1, indk));
mess.append(killer);
mess.append(temp.substr(indk + 1));
}
else {
mess.append(temp.substr(0, indk));
mess.append(killer);
mess.append(temp.substr(indk + 1, ind));
mess.append(username);
mess.append(temp.substr(ind + 1));
}
return mess;
}