🔫
This commit is contained in:
parent
5e09305398
commit
a85c5cc626
@ -12,7 +12,7 @@ Bullet::~Bullet() {}
|
|||||||
|
|
||||||
bool Bullet::Update(World* world, float elapsedtime, int perframe, std::unordered_map<uint64_t, Player*> mapPlayer, netprot::ChunkMod** chunkmod) {
|
bool Bullet::Update(World* world, float elapsedtime, int perframe, std::unordered_map<uint64_t, Player*> mapPlayer, netprot::ChunkMod** chunkmod) {
|
||||||
int max = 100 / perframe;
|
int max = 100 / perframe;
|
||||||
float damage = 0.057f;
|
float damage = 0.098f;
|
||||||
for (int x = 0; x < max; ++x) {
|
for (int x = 0; x < max; ++x) {
|
||||||
m_currentpos += m_velocity * elapsedtime;
|
m_currentpos += m_velocity * elapsedtime;
|
||||||
|
|
||||||
@ -40,15 +40,17 @@ bool Bullet::Update(World* world, float elapsedtime, int perframe, std::unordere
|
|||||||
if (!world->ChunkAt(m_currentpos))
|
if (!world->ChunkAt(m_currentpos))
|
||||||
return true;
|
return true;
|
||||||
else if (world->BlockAt(m_currentpos) != BTYPE_AIR) {
|
else if (world->BlockAt(m_currentpos) != BTYPE_AIR) {
|
||||||
if (chunkmod) {
|
if (m_canhurt) {
|
||||||
using namespace netprot;
|
if (chunkmod) {
|
||||||
*chunkmod = new ChunkMod();
|
using namespace netprot;
|
||||||
(*chunkmod)->old_b_type = world->BlockAt(m_currentpos);
|
*chunkmod = new ChunkMod();
|
||||||
(*chunkmod)->b_type = BTYPE_AIR;
|
(*chunkmod)->old_b_type = world->BlockAt(m_currentpos);
|
||||||
(*chunkmod)->pos = m_currentpos;
|
(*chunkmod)->b_type = BTYPE_AIR;
|
||||||
}
|
(*chunkmod)->pos = m_currentpos;
|
||||||
|
}
|
||||||
|
|
||||||
world->ChangeBlockAtPosition(BTYPE_AIR, m_currentpos);
|
world->ChangeBlockAtPosition(BTYPE_AIR, m_currentpos);
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else if ((m_currentpos - m_startpos).Length() > VIEW_DISTANCE) return true;
|
else if ((m_currentpos - m_startpos).Length() > VIEW_DISTANCE) return true;
|
||||||
|
@ -37,8 +37,8 @@
|
|||||||
#define STRENGTH_SPEED_BOOST 10 //Pourcentage
|
#define STRENGTH_SPEED_BOOST 10 //Pourcentage
|
||||||
#define BULLET_TIME .1
|
#define BULLET_TIME .1
|
||||||
|
|
||||||
#define SYNC_ACC 200
|
#define SYNC_ACC 200 // ms
|
||||||
#define CMOD_ACC 1500
|
#define CMOD_ACC 1500 // ms
|
||||||
|
|
||||||
typedef uint8_t BlockType;
|
typedef uint8_t BlockType;
|
||||||
enum BLOCK_TYPE { BTYPE_AIR, BTYPE_DIRT, BTYPE_GRASS, BTYPE_METAL, BTYPE_ICE, BTYPE_GREENGRASS, BTYPE_LAST };
|
enum BLOCK_TYPE { BTYPE_AIR, BTYPE_DIRT, BTYPE_GRASS, BTYPE_METAL, BTYPE_ICE, BTYPE_GREENGRASS, BTYPE_LAST };
|
||||||
|
@ -45,6 +45,8 @@ public:
|
|||||||
std::string m_username;
|
std::string m_username;
|
||||||
bool m_hit = false;
|
bool m_hit = false;
|
||||||
|
|
||||||
|
bool Eulogy = false;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
uint64_t getId() const;
|
uint64_t getId() const;
|
||||||
|
|
||||||
|
@ -77,8 +77,10 @@ void Connection::getPacks(SOCKET sock) {
|
|||||||
void Connection::sendPacks(SOCKET sock, std::unordered_map<uint64_t, Connection*> conns, const uint32_t timer) {
|
void Connection::sendPacks(SOCKET sock, std::unordered_map<uint64_t, Connection*> conns, const uint32_t timer) {
|
||||||
static int outs = 0;
|
static int outs = 0;
|
||||||
static Timestamp last = 0;
|
static Timestamp last = 0;
|
||||||
|
|
||||||
while (!m_output_vector.empty()) {
|
while (!m_output_vector.empty()) {
|
||||||
Output out = m_output_vector.front();
|
Output out = m_output_vector.front();
|
||||||
|
|
||||||
for (auto& [key, conn] : conns) {
|
for (auto& [key, conn] : conns) {
|
||||||
if (m_playinfo.id == conn->GetHash(false))
|
if (m_playinfo.id == conn->GetHash(false))
|
||||||
continue;
|
continue;
|
||||||
@ -91,8 +93,8 @@ void Connection::sendPacks(SOCKET sock, std::unordered_map<uint64_t, Connection*
|
|||||||
|
|
||||||
outs += out.timestamp + last;
|
outs += out.timestamp + last;
|
||||||
|
|
||||||
if (outs >= 50) {
|
if (outs >= SYNC_ACC) {
|
||||||
outs -= 50;
|
outs -= SYNC_ACC;
|
||||||
Sync sync;
|
Sync sync;
|
||||||
sync.hp = player->GetHP();
|
sync.hp = player->GetHP();
|
||||||
sync.timestamp = out.timestamp;
|
sync.timestamp = out.timestamp;
|
||||||
@ -114,27 +116,33 @@ Timestamp Connection::Run(World* world) {
|
|||||||
Timestamp tstamp = 0;
|
Timestamp tstamp = 0;
|
||||||
float el;
|
float el;
|
||||||
|
|
||||||
|
bool dead = player->AmIDead();
|
||||||
|
|
||||||
if (m_input_manifest.size() < 2)
|
if (m_input_manifest.size() < 2)
|
||||||
return tstamp;
|
return tstamp;
|
||||||
|
|
||||||
while (m_last_in < m_input_vector.size() - 1) {
|
while (m_last_in < m_input_vector.size() - 1 || dead) {
|
||||||
in = m_input_vector.at(m_last_in + 1);
|
if (!dead) {
|
||||||
last = m_input_vector.at(m_last_in);
|
in = m_input_vector.at(m_last_in + 1);
|
||||||
|
last = m_input_vector.at(m_last_in);
|
||||||
if (in.timestamp <= m_tstamp) {
|
if (in.timestamp <= m_tstamp) {
|
||||||
++m_last_in;
|
++m_last_in;
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
el = (double)(in.timestamp - last.timestamp) / 1000.;
|
||||||
|
if (m_shoot_acc > 0.) {
|
||||||
|
m_shoot_acc -= el;
|
||||||
|
if (m_shoot_acc < 0.)
|
||||||
|
m_shoot_acc = 0.;
|
||||||
|
}
|
||||||
|
player->SetDirection(in.direction);
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
el = (double)(in.timestamp - last.timestamp) / 1000.;
|
el = 1. / 60.;
|
||||||
|
in = Input();
|
||||||
if (m_shoot_acc > 0.) {
|
|
||||||
m_shoot_acc -= el;
|
|
||||||
if (m_shoot_acc < 0.)
|
|
||||||
m_shoot_acc = 0.;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
player->SetDirection(in.direction);
|
|
||||||
player->ApplyPhysics(player->GetInput(in.keys.forward,
|
player->ApplyPhysics(player->GetInput(in.keys.forward,
|
||||||
in.keys.backward,
|
in.keys.backward,
|
||||||
in.keys.left,
|
in.keys.left,
|
||||||
@ -147,7 +155,10 @@ Timestamp Connection::Run(World* world) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
out.states.jumping = player->GetIsAirborne();
|
out.states.jumping = player->GetIsAirborne();
|
||||||
out.states.running = player->GetVelocity().Length() > .2f;
|
|
||||||
|
Vector3f horSpeed = player->GetVelocity();
|
||||||
|
horSpeed.y = 0;
|
||||||
|
out.states.running = horSpeed.Length() > .2f;
|
||||||
out.states.still = !out.states.running && !out.states.jumping;
|
out.states.still = !out.states.running && !out.states.jumping;
|
||||||
out.states.hit = player->m_hit;
|
out.states.hit = player->m_hit;
|
||||||
player->m_hit = false;
|
player->m_hit = false;
|
||||||
@ -192,7 +203,8 @@ Timestamp Connection::Run(World* world) {
|
|||||||
m_output_vector.push_back(out);
|
m_output_vector.push_back(out);
|
||||||
m_tstamp = tstamp = out.timestamp;
|
m_tstamp = tstamp = out.timestamp;
|
||||||
|
|
||||||
++m_last_in;
|
if (!dead)
|
||||||
|
++m_last_in;
|
||||||
}
|
}
|
||||||
|
|
||||||
return tstamp;
|
return tstamp;
|
||||||
|
@ -217,7 +217,7 @@ void Server::Run() {
|
|||||||
sendPackTo<Sync>(m_sock_udp, &sync, &m_buf, conn->getAddr());
|
sendPackTo<Sync>(m_sock_udp, &sync, &m_buf, conn->getAddr());
|
||||||
}
|
}
|
||||||
|
|
||||||
int timer = m_game.countdown, sync_acc = 0, deadplayers = 0;
|
int timer = m_game.countdown, timer_acc = 0, deadplayers = 0;
|
||||||
std::chrono::high_resolution_clock::time_point start = std::chrono::high_resolution_clock::now();
|
std::chrono::high_resolution_clock::time_point start = std::chrono::high_resolution_clock::now();
|
||||||
Timestamp last = 0;
|
Timestamp last = 0;
|
||||||
std::vector<Chat*> chatlog;
|
std::vector<Chat*> chatlog;
|
||||||
@ -241,10 +241,10 @@ void Server::Run() {
|
|||||||
|
|
||||||
if (last == 0)
|
if (last == 0)
|
||||||
last = tstamp;
|
last = tstamp;
|
||||||
sync_acc += tstamp - last;
|
timer_acc += tstamp - last;
|
||||||
if (sync_acc >= SYNC_ACC) {
|
if (timer_acc >= 1000) {
|
||||||
while (sync_acc >= SYNC_ACC)
|
while (timer_acc >= 1000)
|
||||||
sync_acc -= SYNC_ACC;
|
timer_acc -= 1000;
|
||||||
--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);
|
||||||
@ -280,22 +280,26 @@ void Server::Run() {
|
|||||||
/* Process */
|
/* Process */
|
||||||
|
|
||||||
if (conn->m_nsync) {
|
if (conn->m_nsync) {
|
||||||
if (conn->player->AmIDead())
|
|
||||||
conn->m_nsync = false;
|
|
||||||
|
|
||||||
Timestamp tstamp = conn->Run(m_world);
|
Timestamp tstamp = conn->Run(m_world);
|
||||||
|
|
||||||
if (conn->player->AmIDead()) {
|
if (conn->player->AmIDead() && !conn->player->Eulogy) {
|
||||||
Chat* chat = new Chat();
|
Chat* chat = new Chat();
|
||||||
chat->dest_id = chat->dest_team_id = chat->src_id = 0;
|
chat->dest_id = chat->dest_team_id = chat->src_id = 0;
|
||||||
|
|
||||||
std::string killer = m_conns.at(conn->player->Killer)->player->GetUsername();
|
Player* murderer = m_conns.at(conn->player->Killer)->player;
|
||||||
|
|
||||||
|
murderer->addPoint();
|
||||||
|
|
||||||
|
std::string killer = murderer->GetUsername();
|
||||||
|
|
||||||
std::string mess = getDeathMessage(conn->player->GetUsername(), killer);
|
std::string mess = getDeathMessage(conn->player->GetUsername(), killer);
|
||||||
|
|
||||||
strcpy(chat->mess, 140, mess.c_str());
|
strcpy(chat->mess, 140, mess.c_str());
|
||||||
chatlog.emplace_back(chat);
|
chatlog.emplace_back(chat);
|
||||||
++deadplayers;
|
++deadplayers;
|
||||||
|
|
||||||
|
conn->player->Eulogy = true;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
for (auto& chmo : conn->ChunkDiffs)
|
for (auto& chmo : conn->ChunkDiffs)
|
||||||
@ -367,8 +371,7 @@ void Server::Run() {
|
|||||||
|
|
||||||
for (auto& [key, conn] : m_conns) {
|
for (auto& [key, conn] : m_conns) {
|
||||||
std::string str = conn->player->GetUsername();
|
std::string str = conn->player->GetUsername();
|
||||||
Log(str.append(" ").append(std::to_string(conn->player->GetHP())), false, false);
|
Log(str.append(" ").append(std::to_string(conn->player->getScore())), false, false);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto& [key, conn] : m_conns)
|
for (auto& [key, conn] : m_conns)
|
||||||
|
Loading…
Reference in New Issue
Block a user