wider terrain
This commit is contained in:
parent
6b8564cb0c
commit
7fc4e9cd3c
4 changed files with 52 additions and 23 deletions
|
|
@ -23,7 +23,7 @@ typedef int socklen_t;
|
|||
#define CLOSESOCK close
|
||||
#endif
|
||||
|
||||
#define PROTOCOL_VERSION 5
|
||||
#define PROTOCOL_VERSION 67
|
||||
#define SERVER_PORT 27015
|
||||
#define MAX_PLAYERS 16
|
||||
#define USERNAME_MAX 16
|
||||
|
|
@ -238,6 +238,7 @@ typedef struct PlayerStateNet {
|
|||
float x, y, z, yaw, pitch;
|
||||
uint8_t weapon;
|
||||
int16_t pistolMag, rifleMag, pistolAmmo, rifleAmmo, medkits;
|
||||
int16_t reloadTimeLeft;
|
||||
char username[USERNAME_MAX];
|
||||
} PlayerStateNet;
|
||||
|
||||
|
|
@ -283,6 +284,8 @@ typedef struct Player {
|
|||
double lastShotTime;
|
||||
int shotsInBurst;
|
||||
uint32_t rng;
|
||||
float reloadTimer;
|
||||
int reloadWeapon;
|
||||
dBodyID body;
|
||||
dGeomID geom;
|
||||
} Player;
|
||||
|
|
@ -656,20 +659,9 @@ int main(void) {
|
|||
p->weapon = WEAPON_RIFLE;
|
||||
|
||||
if (m->buttons & BTN_RELOAD) {
|
||||
if (p->weapon == WEAPON_PISTOL) {
|
||||
int need = 12 - p->pistolMag;
|
||||
if (need > 0 && p->pistolAmmo > 0) {
|
||||
int take = (p->pistolAmmo < need) ? p->pistolAmmo : need;
|
||||
p->pistolAmmo -= take;
|
||||
p->pistolMag += take;
|
||||
}
|
||||
} else {
|
||||
int need = 30 - p->rifleMag;
|
||||
if (need > 0 && p->rifleAmmo > 0) {
|
||||
int take = (p->rifleAmmo < need) ? p->rifleAmmo : need;
|
||||
p->rifleAmmo -= take;
|
||||
p->rifleMag += take;
|
||||
}
|
||||
if (p->reloadTimer <= 0.0f) {
|
||||
p->reloadTimer = 2.0f; // 2 second reload time
|
||||
p->reloadWeapon = p->weapon;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -730,6 +722,9 @@ int main(void) {
|
|||
if (now - sh->lastShotTime > 0.18)
|
||||
sh->shotsInBurst = 0;
|
||||
|
||||
if (sh->reloadTimer > 0.0f)
|
||||
continue;
|
||||
|
||||
int *mag =
|
||||
(sh->weapon == WEAPON_PISTOL) ? &sh->pistolMag : &sh->rifleMag;
|
||||
if (*mag <= 0)
|
||||
|
|
@ -801,6 +796,35 @@ int main(void) {
|
|||
dWorldQuickStep(gWorld, DT);
|
||||
dJointGroupEmpty(gContactGroup);
|
||||
|
||||
// Handle reload timers
|
||||
for (int i = 0; i < MAX_PLAYERS; i++) {
|
||||
Player *p = &players[i];
|
||||
if (!p->inUse || !p->alive)
|
||||
continue;
|
||||
if (p->reloadTimer > 0.0f) {
|
||||
p->reloadTimer -= DT;
|
||||
if (p->reloadTimer <= 0.0f) {
|
||||
p->reloadTimer = 0.0f;
|
||||
// Perform reload
|
||||
if (p->reloadWeapon == WEAPON_PISTOL) {
|
||||
int need = 12 - p->pistolMag;
|
||||
if (need > 0 && p->pistolAmmo > 0) {
|
||||
int take = (p->pistolAmmo < need) ? p->pistolAmmo : need;
|
||||
p->pistolAmmo -= take;
|
||||
p->pistolMag += take;
|
||||
}
|
||||
} else {
|
||||
int need = 30 - p->rifleMag;
|
||||
if (need > 0 && p->rifleAmmo > 0) {
|
||||
int take = (p->rifleAmmo < need) ? p->rifleAmmo : need;
|
||||
p->rifleAmmo -= take;
|
||||
p->rifleMag += take;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < MAX_PLAYERS; i++) {
|
||||
Player *p = &players[i];
|
||||
if (!p->inUse || !p->alive)
|
||||
|
|
@ -847,6 +871,7 @@ int main(void) {
|
|||
ps->pistolAmmo = (int16_t)players[i].pistolAmmo;
|
||||
ps->rifleAmmo = (int16_t)players[i].rifleAmmo;
|
||||
ps->medkits = (int16_t)players[i].medkits;
|
||||
ps->reloadTimeLeft = (int16_t)(players[i].reloadTimer * 1000.0f);
|
||||
strncpy(ps->username, players[i].username, USERNAME_MAX - 1);
|
||||
}
|
||||
broadcast(sock, players, &snap, (int)sizeof(snap));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue