280 lines
6.1 KiB
Plaintext
280 lines
6.1 KiB
Plaintext
/*
|
|
* Copyright (c) 2016-2021 Marco Cawthorne <marco@icculus.org>
|
|
*
|
|
* Permission to use, copy, modify, and distribute this software for any
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
* copyright notice and this permission notice appear in all copies.
|
|
*
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
|
|
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
|
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
*/
|
|
|
|
#include "../../../valve/src/shared/skeleton.h"
|
|
|
|
/* all potential SendFlags bits we can possibly send */
|
|
enumflags
|
|
{
|
|
PLAYER_KEEPALIVE,
|
|
PLAYER_MODELINDEX,
|
|
PLAYER_ORIGIN,
|
|
PLAYER_ORIGIN_Z,
|
|
PLAYER_ANGLES_X,
|
|
PLAYER_ANGLES_Y,
|
|
PLAYER_COLORMAP,
|
|
PLAYER_VELOCITY,
|
|
PLAYER_VELOCITY_Z,
|
|
PLAYER_FLAGS,
|
|
PLAYER_WEAPON,
|
|
PLAYER_ITEMS,
|
|
PLAYER_HEALTH,
|
|
PLAYER_ARMOR,
|
|
PLAYER_MOVETYPE,
|
|
PLAYER_VIEWOFS,
|
|
PLAYER_TOPFRAME,
|
|
PLAYER_BOTTOMFRAME,
|
|
PLAYER_AMMO1,
|
|
PLAYER_AMMO2,
|
|
PLAYER_AMMO3,
|
|
PLAYER_UNUSED1,
|
|
PLAYER_UNUSED2
|
|
};
|
|
|
|
class player:NSClientPlayer
|
|
{
|
|
PREDICTED_INT(anim_top)
|
|
PREDICTED_FLOAT(anim_top_time)
|
|
PREDICTED_FLOAT(anim_top_delay)
|
|
PREDICTED_INT(anim_bottom)
|
|
PREDICTED_FLOAT(anim_bottom_time)
|
|
|
|
PREDICTED_INT(ammo_forks)
|
|
PREDICTED_INT(ammo_knives)
|
|
PREDICTED_INT(ammo_legogrenade)
|
|
PREDICTED_INT(ammo_legos)
|
|
PREDICTED_INT(ammo_soda)
|
|
PREDICTED_INT(ammo_spray)
|
|
|
|
PREDICTED_INT(soda_choice)
|
|
|
|
#ifdef CLIENT
|
|
virtual void(float,float) ReceiveEntity;
|
|
virtual void(void) PredictPreFrame;
|
|
virtual void(void) PredictPostFrame;
|
|
#else
|
|
float powerup_time;
|
|
|
|
virtual void(void) EvaluateEntity;
|
|
virtual float(entity, float) SendEntity;
|
|
#endif
|
|
};
|
|
|
|
#ifdef CLIENT
|
|
void Weapons_AmmoUpdate(entity);
|
|
/*
|
|
=================
|
|
player::ReceiveEntity
|
|
=================
|
|
*/
|
|
void
|
|
player::ReceiveEntity(float new, float fl)
|
|
{
|
|
NSClientPlayer::ReceiveEntity(new, fl);
|
|
|
|
/* animation */
|
|
if (fl & PLAYER_TOPFRAME) {
|
|
anim_top = readbyte();
|
|
anim_top_time = readfloat();
|
|
anim_top_delay = readfloat();
|
|
}
|
|
if (fl & PLAYER_BOTTOMFRAME) {
|
|
anim_bottom = readbyte();
|
|
anim_bottom_time = readfloat();
|
|
}
|
|
|
|
if (fl & PLAYER_AMMO1) {
|
|
}
|
|
|
|
if (fl & PLAYER_AMMO2) {
|
|
ammo_forks = readbyte();
|
|
ammo_knives = readbyte();
|
|
ammo_legogrenade = readbyte();
|
|
ammo_legos = readbyte();
|
|
ammo_soda = readbyte();
|
|
ammo_spray = readbyte();
|
|
}
|
|
|
|
if (fl & PLAYER_AMMO3) {
|
|
soda_choice = readbyte();
|
|
}
|
|
|
|
if (fl & PLAYER_AMMO1 || fl & PLAYER_AMMO2 || fl & PLAYER_AMMO3)
|
|
Weapons_AmmoUpdate(this);
|
|
|
|
setorigin(this, origin);
|
|
}
|
|
|
|
/*
|
|
=================
|
|
player::PredictPostFrame
|
|
|
|
Save the last valid server values away in the _net variants of each field
|
|
so we can roll them back later.
|
|
=================
|
|
*/
|
|
void
|
|
player::PredictPreFrame(void)
|
|
{
|
|
NSClientPlayer::PredictPreFrame();
|
|
|
|
SAVE_STATE(anim_top);
|
|
SAVE_STATE(anim_top_time);
|
|
SAVE_STATE(anim_top_delay);
|
|
SAVE_STATE(anim_bottom);
|
|
SAVE_STATE(anim_bottom_time);
|
|
|
|
SAVE_STATE(ammo_forks);
|
|
SAVE_STATE(ammo_knives);
|
|
SAVE_STATE(ammo_legogrenade);
|
|
SAVE_STATE(ammo_legos);
|
|
SAVE_STATE(ammo_soda);
|
|
SAVE_STATE(ammo_spray);
|
|
|
|
SAVE_STATE(soda_choice);
|
|
}
|
|
|
|
/*
|
|
=================
|
|
player::PredictPostFrame
|
|
|
|
Where we roll back our values to the ones last sent/verified by the server.
|
|
=================
|
|
*/
|
|
void
|
|
player::PredictPostFrame(void)
|
|
{
|
|
NSClientPlayer::PredictPostFrame();
|
|
|
|
ROLL_BACK(anim_top);
|
|
ROLL_BACK(anim_top_time);
|
|
ROLL_BACK(anim_top_delay);
|
|
ROLL_BACK(anim_bottom);
|
|
ROLL_BACK(anim_bottom_time);
|
|
|
|
ROLL_BACK(ammo_forks);
|
|
ROLL_BACK(ammo_knives);
|
|
ROLL_BACK(ammo_legogrenade);
|
|
ROLL_BACK(ammo_legos);
|
|
ROLL_BACK(ammo_soda);
|
|
ROLL_BACK(ammo_spray);
|
|
|
|
ROLL_BACK(soda_choice);
|
|
}
|
|
|
|
#else
|
|
void
|
|
player::EvaluateEntity(void)
|
|
{
|
|
NSClientPlayer::EvaluateEntity();
|
|
|
|
/* animation */
|
|
if (ATTR_CHANGED(anim_bottom) || ATTR_CHANGED(anim_bottom_time))
|
|
SendFlags |= PLAYER_BOTTOMFRAME;
|
|
if (ATTR_CHANGED(anim_top) || ATTR_CHANGED(anim_top_time) || ATTR_CHANGED(anim_top_delay))
|
|
SendFlags |= PLAYER_TOPFRAME;
|
|
|
|
if (ATTR_CHANGED(ammo_forks))
|
|
SendFlags |= PLAYER_AMMO2;
|
|
if (ATTR_CHANGED(ammo_knives))
|
|
SendFlags |= PLAYER_AMMO2;
|
|
if (ATTR_CHANGED(ammo_legogrenade))
|
|
SendFlags |= PLAYER_AMMO2;
|
|
if (ATTR_CHANGED(ammo_legos))
|
|
SendFlags |= PLAYER_AMMO2;
|
|
if (ATTR_CHANGED(ammo_soda))
|
|
SendFlags |= PLAYER_AMMO2;
|
|
if (ATTR_CHANGED(ammo_spray))
|
|
SendFlags |= PLAYER_AMMO2;
|
|
|
|
if (ATTR_CHANGED(soda_choice))
|
|
SendFlags |= PLAYER_AMMO3;
|
|
|
|
SAVE_STATE(anim_top);
|
|
SAVE_STATE(anim_top_time);
|
|
SAVE_STATE(anim_top_delay);
|
|
SAVE_STATE(anim_bottom);
|
|
SAVE_STATE(anim_bottom_time);
|
|
|
|
SAVE_STATE(ammo_forks);
|
|
SAVE_STATE(ammo_knives);
|
|
SAVE_STATE(ammo_legogrenade);
|
|
SAVE_STATE(ammo_legos);
|
|
SAVE_STATE(ammo_soda);
|
|
SAVE_STATE(ammo_spray);
|
|
|
|
SAVE_STATE(soda_choice);
|
|
}
|
|
|
|
/*
|
|
=================
|
|
player::SendEntity
|
|
=================
|
|
*/
|
|
float
|
|
player::SendEntity(entity ePEnt, float fChanged)
|
|
{
|
|
/* don't broadcast invisible players */
|
|
if (IsFakeSpectator() && ePEnt != this)
|
|
return (0);
|
|
if (!GetModelindex() && ePEnt != this)
|
|
return (0);
|
|
|
|
if (ePEnt != self) {
|
|
fChanged &= ~PLAYER_ITEMS;
|
|
fChanged &= ~PLAYER_HEALTH;
|
|
fChanged &= ~PLAYER_ARMOR;
|
|
fChanged &= ~PLAYER_VIEWOFS;
|
|
fChanged &= ~PLAYER_AMMO1;
|
|
fChanged &= ~PLAYER_AMMO2;
|
|
fChanged &= ~PLAYER_AMMO3;
|
|
}
|
|
|
|
WriteByte(MSG_ENTITY, ENT_PLAYER);
|
|
WriteFloat(MSG_ENTITY, fChanged);
|
|
|
|
NSClientPlayer::SendEntity(ePEnt, fChanged);
|
|
|
|
if (fChanged & PLAYER_TOPFRAME) {
|
|
WriteByte(MSG_ENTITY, anim_top);
|
|
WriteFloat(MSG_ENTITY, anim_top_time);
|
|
WriteFloat(MSG_ENTITY, anim_top_delay);
|
|
}
|
|
if (fChanged & PLAYER_BOTTOMFRAME) {
|
|
WriteByte(MSG_ENTITY, anim_bottom);
|
|
WriteFloat(MSG_ENTITY, anim_bottom_time);
|
|
}
|
|
|
|
if (fChanged & PLAYER_AMMO1) {
|
|
}
|
|
|
|
if (fChanged & PLAYER_AMMO2) {
|
|
WriteByte(MSG_ENTITY, ammo_forks);
|
|
WriteByte(MSG_ENTITY, ammo_knives);
|
|
WriteByte(MSG_ENTITY, ammo_legogrenade);
|
|
WriteByte(MSG_ENTITY, ammo_legos);
|
|
WriteByte(MSG_ENTITY, ammo_soda);
|
|
WriteByte(MSG_ENTITY, ammo_spray);
|
|
}
|
|
|
|
if (fChanged & PLAYER_AMMO3) {
|
|
WriteByte(MSG_ENTITY, soda_choice);
|
|
}
|
|
|
|
return (1);
|
|
}
|
|
#endif
|