Let's all die!
This commit is contained in:
parent
37a86d42a3
commit
49374a7dea
@ -93,16 +93,23 @@ void Connection::sendPacks(SOCKET sock, std::unordered_map<uint64_t, Connection*
|
|||||||
|
|
||||||
outs += out.timestamp + last;
|
outs += out.timestamp + last;
|
||||||
|
|
||||||
if (outs >= SYNC_ACC) {
|
static bool syncdead = false;
|
||||||
outs -= SYNC_ACC;
|
bool dead = player->AmIDead();
|
||||||
|
|
||||||
|
if (outs >= SYNC_ACC || (!syncdead && dead)) {
|
||||||
Sync sync;
|
Sync sync;
|
||||||
sync.hp = player->GetHP();
|
outs -= SYNC_ACC;
|
||||||
sync.timestamp = out.timestamp;
|
sync.timestamp = out.timestamp;
|
||||||
sync.position = out.position;
|
sync.position = out.position;
|
||||||
sync.sid = m_loginfo.sid;
|
sync.sid = m_loginfo.sid;
|
||||||
sync.timer = timer;
|
sync.timer = timer;
|
||||||
sync.timestamp = out.timestamp;
|
sync.timestamp = out.timestamp;
|
||||||
sync.ammo = -1;
|
sync.ammo = -1;
|
||||||
|
sync.hp = player->GetHP();
|
||||||
|
if (dead) {
|
||||||
|
sync.timestamp = m_loginfo.sid;
|
||||||
|
syncdead = true;
|
||||||
|
}
|
||||||
sendPackTo<Sync>(sock, &sync, &m_bufout, &m_addr);
|
sendPackTo<Sync>(sock, &sync, &m_bufout, &m_addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -118,7 +125,7 @@ Timestamp Connection::Run(World* world) {
|
|||||||
|
|
||||||
bool dead = player->AmIDead();
|
bool dead = player->AmIDead();
|
||||||
|
|
||||||
if (m_input_manifest.size() < 2)
|
if (m_input_manifest.size() < 2 && !dead)
|
||||||
return tstamp;
|
return tstamp;
|
||||||
|
|
||||||
while (m_last_in < m_input_vector.size() - 1 || dead) {
|
while (m_last_in < m_input_vector.size() - 1 || dead) {
|
||||||
|
@ -230,12 +230,12 @@ void Server::Run() {
|
|||||||
Chat* startchat = new Chat();
|
Chat* startchat = new Chat();
|
||||||
startchat->src_id = 0;
|
startchat->src_id = 0;
|
||||||
char startmess[] = "How would -YOU- like to die today, motherf-words?";
|
char startmess[] = "How would -YOU- like to die today, motherf-words?";
|
||||||
|
float endtime = 0.;
|
||||||
strcpy(startchat->mess, 140, startmess);
|
strcpy(startchat->mess, 140, startmess);
|
||||||
|
|
||||||
chatlog.emplace_back(startchat);
|
chatlog.emplace_back(startchat);
|
||||||
|
|
||||||
while (!endgame) {
|
while (!endgame && endtime < 1.) {
|
||||||
using namespace std::chrono;
|
using namespace std::chrono;
|
||||||
Timestamp tstamp = duration_cast<milliseconds>(high_resolution_clock::now() - start).count();
|
Timestamp tstamp = duration_cast<milliseconds>(high_resolution_clock::now() - start).count();
|
||||||
|
|
||||||
@ -245,6 +245,7 @@ void Server::Run() {
|
|||||||
if (timer_acc >= 1000) {
|
if (timer_acc >= 1000) {
|
||||||
while (timer_acc >= 1000)
|
while (timer_acc >= 1000)
|
||||||
timer_acc -= 1000;
|
timer_acc -= 1000;
|
||||||
|
if (!endgame)
|
||||||
--timer;
|
--timer;
|
||||||
std::string str = "Timer: ";
|
std::string str = "Timer: ";
|
||||||
Log(str.append(std::to_string(timer)), false, false);
|
Log(str.append(std::to_string(timer)), false, false);
|
||||||
@ -323,8 +324,43 @@ void Server::Run() {
|
|||||||
/* Out */
|
/* Out */
|
||||||
conn->sendPacks(m_sock_udp, m_conns, timer);
|
conn->sendPacks(m_sock_udp, m_conns, timer);
|
||||||
|
|
||||||
if ((deadplayers == players - 1 && deadplayers != 0) || timer < 0)
|
if ((deadplayers == players - 1 && deadplayers != 0) || timer < 0) {
|
||||||
|
if (!endgame) {
|
||||||
|
Chat* gameover = new Chat();
|
||||||
|
gameover->dest_id = gameover->dest_team_id = gameover->src_id = 0;
|
||||||
|
std::string winner, winmess;
|
||||||
|
int score = 0;
|
||||||
|
bool plural = false;
|
||||||
|
for (auto& [key, conn] : m_conns) {
|
||||||
|
if (conn->player->getScore() > score) {
|
||||||
|
winner = conn->player->GetUsername();
|
||||||
|
score = conn->player->getScore();
|
||||||
|
plural = false;
|
||||||
|
}
|
||||||
|
else if (conn->player->getScore() == score) {
|
||||||
|
winner = winner.append(" and ").append(conn->player->GetUsername());
|
||||||
|
plural = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
winmess = "And the winner";
|
||||||
|
if (!plural)
|
||||||
|
winmess = winmess.append(" is ");
|
||||||
|
else winmess = winmess.append("s are ");
|
||||||
|
|
||||||
|
winmess = winmess.append(winner).append(" with ").append(std::to_string(score)).append(" point");
|
||||||
|
|
||||||
|
if (score > 1)
|
||||||
|
winmess = winmess.append("s.");
|
||||||
|
else winmess = winmess.append(".");
|
||||||
|
|
||||||
|
strcpy(gameover->mess, 140, winmess.c_str());
|
||||||
|
|
||||||
|
chatlog.emplace_back(gameover);
|
||||||
|
}
|
||||||
endgame = true;
|
endgame = true;
|
||||||
|
endtime += .001;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto& bull : netbull) {
|
for (auto& bull : netbull) {
|
||||||
@ -338,7 +374,7 @@ void Server::Run() {
|
|||||||
for (auto bull = bullets.begin(); bull != bullets.end(); ++bull) {
|
for (auto bull = bullets.begin(); bull != bullets.end(); ++bull) {
|
||||||
ChunkMod* cmod = nullptr;
|
ChunkMod* cmod = nullptr;
|
||||||
Bullet* bullet = *bull;
|
Bullet* bullet = *bull;
|
||||||
if (bullet->Update(m_world, (1. / 60.), 20, m_players, &cmod)) {
|
if (bullet->Update(m_world, (1. / 60.), 10, m_players, &cmod)) {
|
||||||
if (cmod)
|
if (cmod)
|
||||||
chunkdiffs.emplace_back(cmod);
|
chunkdiffs.emplace_back(cmod);
|
||||||
bullit.push_back(bull);
|
bullit.push_back(bull);
|
||||||
|
@ -1508,6 +1508,9 @@ void Engine::Render(float elapsedTime) {
|
|||||||
SystemNotification("syncsid be no good.");
|
SystemNotification("syncsid be no good.");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
if (sync.timestamp == m_conn.getId()) {
|
||||||
|
m_player.SetHP(sync.hp);
|
||||||
|
}
|
||||||
if (m_syncs.count(sync.timestamp)) {
|
if (m_syncs.count(sync.timestamp)) {
|
||||||
Sync comp = m_syncs[sync.timestamp];
|
Sync comp = m_syncs[sync.timestamp];
|
||||||
m_otherplayerpos = sync.position;
|
m_otherplayerpos = sync.position;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user