!!!!
This commit is contained in:
parent
2c346139d5
commit
9a669acd9c
@ -12,7 +12,9 @@ Bullet::~Bullet() {}
|
||||
|
||||
bool Bullet::Update(World* world, float elapsedtime, int perframe, std::unordered_map<uint64_t, Player*> mapPlayer, netprot::ChunkMod** chunkmod) {
|
||||
int max = 100 / perframe;
|
||||
float damage = 0.098f;
|
||||
Player* shooter = mapPlayer.at(m_shooter_id);
|
||||
float damage = shooter->boostdamage? 0.123f: 0.098f;
|
||||
|
||||
for (int x = 0; x < max; ++x) {
|
||||
m_currentpos += m_velocity * elapsedtime;
|
||||
|
||||
@ -29,7 +31,7 @@ bool Bullet::Update(World* world, float elapsedtime, int perframe, std::unordere
|
||||
hit = true;
|
||||
}
|
||||
if (hit && !player->AmIDead()) {
|
||||
if (m_canhurt)
|
||||
if (m_canhurt && !player->boostinvincible)
|
||||
player->InflictDamage(damage);
|
||||
player->m_hit = true;
|
||||
|
||||
|
@ -212,7 +212,14 @@ void netprot::Serialize(Sync* sync, char* buf[], uint32_t* buflen) {
|
||||
|
||||
memcpy(*buf + sizeof(uint64_t) * 2 + sizeof(uint32_t) * 4 + sizeof(uint16_t) + 1, hp8, sizeof(float));
|
||||
|
||||
*buflen = sizeof(uint64_t) * 2 + sizeof(uint32_t) * 4 + sizeof(uint16_t) + sizeof(float) + 1;
|
||||
Boosts boost = sync->boost;
|
||||
uint8_t boost8 = // Reste 6 bits.
|
||||
(boost.invincible ? 0b10000000 : 0) |
|
||||
(boost.damage ? 0b01000000 : 0);
|
||||
|
||||
memcpy(*buf + sizeof(uint64_t) * 2 + sizeof(uint32_t) * 4 + sizeof(uint16_t) + 2, &boost8, sizeof(uint8_t));
|
||||
|
||||
*buflen = sizeof(uint64_t) * 2 + sizeof(uint32_t) * 4 + sizeof(uint16_t) + sizeof(float) + 2;
|
||||
}
|
||||
|
||||
void netprot::Serialize(TeamInfo* tinfo, char* buf[], uint32_t* buflen) {
|
||||
@ -514,6 +521,53 @@ void netprot::Serialize(BulletAdd* bull, char* buf[], uint32_t* buflen) {
|
||||
*buflen = 1 + sizeof(uint64_t) * 2 + sizeof(uint32_t) * 6;
|
||||
}
|
||||
|
||||
void netprot::Serialize(PickupMod* pmod, char* buf[], uint32_t* buflen) {
|
||||
*buf[0] = (char)netprot::PACKET_TYPE::PICKUPMOD;
|
||||
|
||||
uint64_t id = pmod->id;
|
||||
uint8_t id8[sizeof(uint64_t)] = { (uint8_t)((id >> 56) & 0xFF),
|
||||
(uint8_t)((id >> 48) & 0xFF),
|
||||
(uint8_t)((id >> 40) & 0xFF),
|
||||
(uint8_t)((id >> 32) & 0xFF),
|
||||
(uint8_t)((id >> 24) & 0xFF),
|
||||
(uint8_t)((id >> 16) & 0xFF),
|
||||
(uint8_t)((id >> 8) & 0xFF),
|
||||
(uint8_t)(id & 0xFF) };
|
||||
|
||||
memcpy(*buf + 1, id8, sizeof(uint64_t));
|
||||
|
||||
uint32_t vec[3];
|
||||
memcpy(vec, &pmod->pos, sizeof(Vector3f)); // Pour d<>naturer les floats.
|
||||
|
||||
uint8_t vec8[3 * sizeof(uint32_t)] = {
|
||||
(uint8_t)((vec[0] >> 24) & 0xFF),
|
||||
(uint8_t)((vec[0] >> 16) & 0xFF),
|
||||
(uint8_t)((vec[0] >> 8) & 0xFF),
|
||||
(uint8_t)(vec[0] & 0xFF),
|
||||
(uint8_t)((vec[1] >> 24) & 0xFF),
|
||||
(uint8_t)((vec[1] >> 16) & 0xFF),
|
||||
(uint8_t)((vec[1] >> 8) & 0xFF),
|
||||
(uint8_t)(vec[1] & 0xFF),
|
||||
(uint8_t)((vec[2] >> 24) & 0xFF),
|
||||
(uint8_t)((vec[2] >> 16) & 0xFF),
|
||||
(uint8_t)((vec[2] >> 8) & 0xFF),
|
||||
(uint8_t)(vec[2] & 0xFF) };
|
||||
|
||||
memcpy(*buf + sizeof(uint64_t) + 1, vec8, sizeof(uint32_t) * 3);
|
||||
|
||||
Boosts boost = pmod->boost;
|
||||
uint8_t boost8 = // Reste 5 bits.
|
||||
(boost.invincible ? 0b10000000 : 0) |
|
||||
(boost.damage ? 0b01000000 : 0) |
|
||||
(boost.hp ? 0b00100000 : 0);
|
||||
|
||||
memcpy(*buf + sizeof(uint64_t) + sizeof(uint32_t) * 3 + 1, &boost8, sizeof(uint8_t));
|
||||
|
||||
memcpy(*buf + 2 + sizeof(uint64_t) + sizeof(uint32_t) * 3, &pmod->available, sizeof(bool));
|
||||
|
||||
*buflen = 2 + sizeof(uint64_t) + sizeof(uint32_t) * 3 + 3;
|
||||
}
|
||||
|
||||
void netprot::Serialize(ErrorLog* errlog, char* buf[], uint32_t* buflen) {
|
||||
*buf[0] = (char)netprot::PACKET_TYPE::ERRLOG;
|
||||
|
||||
@ -528,6 +582,7 @@ void netprot::Serialize(ErrorLog* errlog, char* buf[], uint32_t* buflen) {
|
||||
|
||||
|
||||
|
||||
|
||||
bool netprot::Deserialize(Input* in, char* buf, uint32_t* buflen) {
|
||||
if (*buflen <= sizeof(Input))
|
||||
return false;
|
||||
@ -736,7 +791,12 @@ bool netprot::Deserialize(Sync* sync, char* buf, uint32_t* buflen) {
|
||||
|
||||
memcpy(&sync->hp, &hp, sizeof(float));
|
||||
|
||||
*buflen = 1 + sizeof(uint64_t) * 2 + sizeof(uint32_t) * 4 + sizeof(uint16_t) + sizeof(float);
|
||||
uint8_t boost = 0;
|
||||
memcpy(&boost, &buf[2 + sizeof(uint64_t) * 2 + sizeof(uint32_t) * 4 + sizeof(uint16_t)], sizeof(uint8_t));
|
||||
sync->boost.invincible = boost & 0b10000000;
|
||||
sync->boost.damage = boost & 0b01000000;
|
||||
|
||||
*buflen = 2 + sizeof(uint64_t) * 2 + sizeof(uint32_t) * 4 + sizeof(uint16_t) + sizeof(float);
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -1059,6 +1119,53 @@ bool netprot::Deserialize(ErrorLog* errlog, char* buf, uint32_t* buflen) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool netprot::Deserialize(PickupMod* pmod, char* buf, uint32_t* buflen) {
|
||||
if (*buflen <= sizeof(PickupMod))
|
||||
return false;
|
||||
|
||||
uint8_t diff[sizeof(uint64_t)] = { 0,0,0,0,0,0,0,0 };
|
||||
memcpy(diff, &buf[1], sizeof(uint64_t));
|
||||
pmod->id =
|
||||
(uint64_t)diff[0] << 56 |
|
||||
(uint64_t)diff[1] << 48 |
|
||||
(uint64_t)diff[2] << 40 |
|
||||
(uint64_t)diff[3] << 32 |
|
||||
(uint64_t)diff[4] << 24 |
|
||||
(uint64_t)diff[5] << 16 |
|
||||
(uint64_t)diff[6] << 8 |
|
||||
(uint64_t)diff[7];
|
||||
|
||||
uint8_t subvec[3 * sizeof(uint32_t)] = { 0,0,0,0,0,0,0,0,0,0,0,0 };
|
||||
memcpy(subvec, &buf[2 + sizeof(uint64_t)], sizeof(uint8_t) * 12);
|
||||
uint32_t vec[3] = {
|
||||
(uint32_t)subvec[0] << 24 |
|
||||
(uint32_t)subvec[1] << 16 |
|
||||
(uint32_t)subvec[2] << 8 |
|
||||
(uint32_t)subvec[3],
|
||||
(uint32_t)subvec[4] << 24 |
|
||||
(uint32_t)subvec[5] << 16 |
|
||||
(uint32_t)subvec[6] << 8 |
|
||||
(uint32_t)subvec[7],
|
||||
(uint32_t)subvec[8] << 24 |
|
||||
(uint32_t)subvec[9] << 16 |
|
||||
(uint32_t)subvec[10] << 8 |
|
||||
(uint32_t)subvec[11] };
|
||||
|
||||
memcpy(&pmod->pos, vec, sizeof(uint32_t) * 3);
|
||||
|
||||
uint8_t boosts = 0;
|
||||
memcpy(&boosts, &buf[1 + sizeof(uint64_t) + sizeof(uint32_t) * 3], sizeof(uint8_t));
|
||||
pmod->boost.invincible = boosts & 0b10000000;
|
||||
pmod->boost.damage = boosts & 0b01000000;
|
||||
pmod->boost.hp = boosts & 0b00100000;
|
||||
|
||||
memcpy(&pmod->available, &buf[2 + sizeof(uint64_t) + sizeof(uint32_t) * 3], sizeof(bool));
|
||||
|
||||
*buflen = 3 + sizeof(uint64_t) + sizeof(uint32_t) * 3;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
netprot::PACKET_TYPE netprot::getType(char* buf, const uint32_t buflen) {
|
||||
|
@ -58,6 +58,12 @@ namespace netprot {
|
||||
running = false;
|
||||
};
|
||||
|
||||
struct Boosts {
|
||||
bool invincible = false,
|
||||
damage = false,
|
||||
hp = false;
|
||||
};
|
||||
|
||||
/* Structures de paquets */
|
||||
|
||||
struct Input { // cli -> srv UDP ~frame
|
||||
@ -80,10 +86,11 @@ namespace netprot {
|
||||
uint64_t sid = 0;
|
||||
uint32_t timer = 0;
|
||||
uint16_t ammo = 0;
|
||||
Boosts boost;
|
||||
float hp = 0;
|
||||
Vector3f position;
|
||||
Sync() {}
|
||||
Sync(Sync* sync) : timestamp(sync->timestamp), sid(sync->sid), timer(sync->timer), ammo(sync->ammo), hp(sync->hp), position(sync->position) {}
|
||||
Sync(Sync* sync) : timestamp(sync->timestamp), sid(sync->sid), timer(sync->timer), ammo(sync->ammo), hp(sync->hp), position(sync->position), boost(sync->boost) {}
|
||||
};
|
||||
|
||||
struct TeamInfo { // cli <-> srv TCP once
|
||||
@ -121,6 +128,15 @@ namespace netprot {
|
||||
GameInfo(GameInfo* gam) : seed(gam->seed), countdown(gam->countdown), gameType(gam->gameType) {}
|
||||
};
|
||||
|
||||
struct PickupMod {
|
||||
uint64_t id;
|
||||
Vector3f pos;
|
||||
Boosts boost;
|
||||
bool available = true;
|
||||
PickupMod();
|
||||
PickupMod(PickupMod* pmod) : id(pmod->id), pos(pmod->pos), boost(pmod->boost), available(pmod->available) {}
|
||||
};
|
||||
|
||||
struct Chat { // cli <-> srv TCP event
|
||||
uint64_t src_id = 0,
|
||||
dest_id = 0,
|
||||
@ -161,6 +177,7 @@ namespace netprot {
|
||||
void Serialize(GameInfo* ginfo, char* buf[], uint32_t* buflen); // cli/srv
|
||||
void Serialize(Chat* chat, char* buf[], uint32_t* buflen); // cli/srv
|
||||
void Serialize(ChunkMod* chmod, char* buf[], uint32_t* buflen); // srv
|
||||
void Serialize(PickupMod* chmod, char* buf[], uint32_t* buflen); // srv
|
||||
void Serialize(BulletAdd* bull, char* buf[], uint32_t* buflen); // srv
|
||||
void Serialize(ErrorLog* errlog, char* buf[], uint32_t* buflen); // srv
|
||||
|
||||
@ -173,6 +190,7 @@ namespace netprot {
|
||||
bool Deserialize(GameInfo* ginfo, char* buf, uint32_t* buflen); // cli
|
||||
bool Deserialize(Chat* chat, char* buf, uint32_t* buflen); // srv/cli
|
||||
bool Deserialize(ChunkMod* chmod, char* buf, uint32_t* buflen); // cli
|
||||
bool Deserialize(PickupMod* chmod, char* buf, uint32_t* buflen); // cli
|
||||
bool Deserialize(BulletAdd* bull, char* buf, uint32_t* buflen); // cli
|
||||
bool Deserialize(ErrorLog* errlog, char* buf, uint32_t* buflen); // srv
|
||||
|
||||
|
@ -124,7 +124,6 @@ Player::Sound Player::ApplyPhysics(Vector3f input, World* world, float elapsedTi
|
||||
bt2 = world->BlockAt(GetPosition().x + input.x, GetPosition().y - 0.9f, GetPosition().z);
|
||||
bt3 = world->BlockAt(GetPosition().x + input.x, GetPosition().y - 1.7f, GetPosition().z);
|
||||
if (bt1 != BTYPE_AIR || bt2 != BTYPE_AIR || bt3 != BTYPE_AIR) {
|
||||
//input.x = m_velocity.x = 0;
|
||||
m_velocity.y += .04f;
|
||||
m_velocity.z *= .5f;
|
||||
m_velocity.x *= .5f;
|
||||
@ -134,50 +133,17 @@ Player::Sound Player::ApplyPhysics(Vector3f input, World* world, float elapsedTi
|
||||
bt2 = world->BlockAt(GetPosition().x, GetPosition().y - 0.9f, GetPosition().z + input.z);
|
||||
bt3 = world->BlockAt(GetPosition().x, GetPosition().y - 1.7f, GetPosition().z + input.z);
|
||||
if (bt1 != BTYPE_AIR || bt2 != BTYPE_AIR || bt3 != BTYPE_AIR) {
|
||||
//input.z = m_velocity.z = 0;
|
||||
m_velocity.y += .04f;
|
||||
m_velocity.z *= .5f;
|
||||
m_velocity.x *= .5f;
|
||||
}
|
||||
|
||||
//bt1 = world->BlockAt(GetPosition().x + input.x, GetPosition().y, GetPosition().z);
|
||||
//bt2 = world->BlockAt(GetPosition().x + input.x, GetPosition().y - 0.9f, GetPosition().z);
|
||||
//bt3 = world->BlockAt(GetPosition().x + input.x, GetPosition().y - 1.7f, GetPosition().z);
|
||||
//if (bt1 == BTYPE_AIR && bt2 != BTYPE_AIR && bt3 != BTYPE_AIR) {
|
||||
// if (input.x > 0)
|
||||
// input.x = m_velocity.x = 0.5f;
|
||||
// else
|
||||
// input.x = m_velocity.x = -0.5f;
|
||||
// m_velocity.y = 0.3;
|
||||
// m_velocity.z *= .5f;
|
||||
//}
|
||||
//else if (bt1 != BTYPE_AIR || bt2 != BTYPE_AIR || bt3 != BTYPE_AIR) {
|
||||
// input.x = m_velocity.x = 0;
|
||||
// m_velocity.z *= .5f;
|
||||
//}
|
||||
|
||||
//bt1 = world->BlockAt(GetPosition().x, GetPosition().y, GetPosition().z + input.z);
|
||||
//bt2 = world->BlockAt(GetPosition().x, GetPosition().y - 0.9f, GetPosition().z + input.z);
|
||||
//bt3 = world->BlockAt(GetPosition().x, GetPosition().y - 1.7f, GetPosition().z + input.z);
|
||||
//if (bt1 == BTYPE_AIR && bt2 != BTYPE_AIR && bt3 != BTYPE_AIR) {
|
||||
// if (input.z > 0)
|
||||
// input.z = m_velocity.z = 0.5f;
|
||||
// else
|
||||
// input.z = m_velocity.z = -0.5f;
|
||||
// m_velocity.y = 0.3;
|
||||
// m_velocity.x *= .5f;
|
||||
//}
|
||||
//else if (bt1 != BTYPE_AIR || bt2 != BTYPE_AIR || bt3 != BTYPE_AIR) {
|
||||
// input.z = m_velocity.z = 0;
|
||||
// m_velocity.x *= .5f;
|
||||
//}
|
||||
|
||||
/* Fin gestion de collisions */
|
||||
/* Gestion de la friction */
|
||||
|
||||
if (!m_airborne) {
|
||||
m_velocity.x += input.x * 2.f * elapsedTime;
|
||||
m_velocity.z += input.z * 2.f * elapsedTime;
|
||||
m_velocity.x += input.x * (boostspeed ? 2.5f : 2.f) * elapsedTime;
|
||||
m_velocity.z += input.z * (boostspeed ? 2.5f : 2.f) * elapsedTime;
|
||||
|
||||
if (input.x == 0.f)
|
||||
m_velocity.x *= .8f;
|
||||
@ -195,7 +161,7 @@ Player::Sound Player::ApplyPhysics(Vector3f input, World* world, float elapsedTi
|
||||
/* Fin gestion de la friction */
|
||||
|
||||
float vy = m_velocity.y;
|
||||
m_velocity.y = 1.f; // Padding pour limiter le x et z lors du Normalize().
|
||||
m_velocity.y = boostspeed ? 0.f: 1.f; // Padding pour limiter le x et z lors du Normalize().
|
||||
if (m_velocity.Length() >= 1.f) m_velocity.Normalize(); // Limiteur de vitesse en x/z.
|
||||
m_velocity.y = 0;
|
||||
if (m_velocity.Length() < .005f) m_velocity.Zero(); // Threshold en x/z.
|
||||
|
@ -50,6 +50,10 @@ public:
|
||||
|
||||
bool Eulogy = false;
|
||||
|
||||
bool boostspeed;
|
||||
bool boostdamage;
|
||||
bool boostinvincible;
|
||||
|
||||
private:
|
||||
uint64_t getId() const;
|
||||
|
||||
@ -72,9 +76,7 @@ protected:
|
||||
float m_hp;
|
||||
|
||||
bool m_airborne;
|
||||
bool boostspeed;
|
||||
bool boostdamage;
|
||||
bool boostinvincible;
|
||||
|
||||
|
||||
Vector3f InterpolatePosition(const Vector3f& vec1, const Vector3f& vec2, const Timestamp& tim1, const Timestamp& tim2, const Timestamp& now);
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user