Initial work towards the NSWeapon class. Testing will happen in base/ under the NEW_INVENTORY define.

Comitting this early to ensure nothing breaks and it'll co-exist.
This commit is contained in:
Marco Cawthorne 2022-07-25 09:27:19 -07:00
parent bda01e0f0f
commit ff17dea01f
Signed by: eukara
GPG Key ID: CE2032F0A2882A22
23 changed files with 540 additions and 10 deletions

View File

@ -3,6 +3,7 @@
#define CSQC
#define CLIENT
#define NEW_INVENTORY
#includelist
/* first the engine, then nuclide headers for client/shared */

View File

@ -97,7 +97,7 @@ Player_UseUp(void) {
}
}
void Weapons_Draw(player);
void Weapons_Draw(NSClientPlayer);
void
CSEv_PlayerSwitchWeapon_i(int w)

View File

@ -3,6 +3,7 @@
#define QWSSQC
#define SERVER
#define NEW_INVENTORY
#includelist
/* engine, then nuclide headers & functions */

View File

@ -14,6 +14,7 @@
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#ifndef NEW_INVENTORY
/* for AI identification purposes */
typedef enum
{
@ -72,7 +73,7 @@ vector Weapons_GetCameraPos(player pl);
void Weapons_ViewAnimation(player pl, int);
void Weapons_ViewPunchAngle(player pl, vector);
int Weapons_IsPresent(player, int);
void Weapons_UpdateAmmo(NSClientPlayer, int, int, int);
void Weapons_UpdateAmmo(player, int, int, int);
int Weapons_GetAnimation(player pl);
void Weapons_EnableModel(void);
void Weapons_DisableModel(void);
@ -94,3 +95,5 @@ void Weapons_Sound(entity, float, string);
string Weapons_GetPlayermodel(player, int);
void Weapons_HUDPic(player, int, int, vector, float);
#endif
#else
#endif

View File

@ -14,6 +14,7 @@
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#ifndef NEW_INVENTORY
var int g_weapon_weights[g_weapons.length];
#ifdef CLIENT
@ -436,7 +437,7 @@ Sets .a_ammoX fields and clamps them so they can be networked as a single byte.
=================
*/
void
Weapons_UpdateAmmo(NSClientPlayer pl, int a1, int a2, int a3)
Weapons_UpdateAmmo(player pl, int a1, int a2, int a3)
{
/* no change */
if (a1 == -1)
@ -471,3 +472,4 @@ Weapons_Sound(entity pl, float channel, string snd)
#endif
#endif
}
#endif

View File

@ -14,7 +14,9 @@
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#ifndef NEW_INVENTORY
weapon_t w_null = {};
weapon_t g_weapons[] = {
w_null
};
#endif

View File

@ -513,12 +513,14 @@ bot::PreFrame(void)
void
bot::PostFrame(void)
{
#ifndef NEW_INVENTORY
/* we've picked something new up */
if (m_iOldItems != g_items) {
Weapons_SwitchBest(this);
print(sprintf("%s is now using %s (%d)\n", netname, g_weapons[activeweapon].name, activeweapon));
m_iOldItems = g_items;
}
#endif
}
void

41
src/client/NSView.h Normal file
View File

@ -0,0 +1,41 @@
/* The job of a NSView is to contain a single player seat.
Boxing is important for splitscreen etc. play.
The NSView has a target, which may or may not have prediction
run on them. Things such as stair smoothing and viewmodel handling
is done in the NSView.
*/
class
NSView
{
int m_iSeat;
/* the dimensions of our view */
vector m_vecPosition;
vector m_vecSize;
float m_flFieldOfView;
/* the entity we're targetting */
NSEntity m_viewTarget;
NSClient m_client;
void(void) NSView;
virtual void(void) SetupView;
virtual void(void) RenderView;
virtual void(vector) SetViewPosition;
virtual void(vector) SetViewSize;
virtual void(NSEntity) SetViewTarget;
virtual void(NSClient) SetClientOwner;
virtual void(vector) SetCameraOrigin;
virtual void(vector) SetCameraAngle;
virtual void(int) SetSeatID;
virtual void(float) SetAFOV;
};
NSView g_viewSeats[4];
NSView g_view;

83
src/client/NSView.qc Normal file
View File

@ -0,0 +1,83 @@
void
NSView::SetupView(void)
{
setproperty(VF_DRAWENGINESBAR, 0);
setproperty(VF_DRAWCROSSHAIR, 0);
setproperty(VF_DRAWWORLD, 1);
setproperty(VF_ACTIVESEAT, m_iSeat);
setproperty(VF_MIN, m_vecPosition);
setproperty(VF_SIZE, m_vecSize);
setproperty(VF_AFOV, m_flFieldOfView);
/* this will hide said entity */
setproperty(VF_VIEWENTITY, num_for_edict(m_viewTarget));
setproperty(VF_ORIGIN, origin);
//setproperty(VF_CL_VIEWANGLES, angles);
setproperty(VF_ANGLES, angles);
}
void
NSView::RenderView(void)
{
renderscene();
}
void
NSView::SetViewPosition(vector new_pos)
{
m_vecPosition = new_pos;
}
void
NSView::SetViewSize(vector new_size)
{
m_vecSize = new_size;
}
void
NSView::SetViewTarget(NSEntity new_target)
{
m_viewTarget = new_target;
}
void
NSView::SetCameraOrigin(vector new_origin)
{
origin = new_origin;
}
void
NSView::SetCameraAngle(vector new_angle)
{
angles = new_angle;
}
void
NSView::SetSeatID(int new_id)
{
m_iSeat = new_id;
}
void
NSView::SetClientOwner(NSClient new_owner)
{
m_client = new_owner;
}
void
NSView::SetAFOV(float new_fov)
{
m_flFieldOfView = new_fov;
}
void
NSView::NSView(void)
{
m_viewTarget = __NULL__;
m_vecPosition = [0,0];
m_vecSize = [0,0];
m_iSeat = 0;
m_flFieldOfView = 90.0f;
m_client = __NULL__;
}

View File

@ -105,7 +105,11 @@ CSQC_RendererRestarted(string rstr)
/* View */
Chat_Init();
#ifndef NEW_INVENTORY
Weapons_Init();
#endif
Scores_Init();
View_Init();
ClientGame_RendererRestart(rstr);

View File

@ -623,6 +623,13 @@ ConsoleCmd(string cmd)
t.Trigger(self, TRIG_TOGGLE);
}
break;
case "goto_ent":
static entity finder;
finder = find(finder, ::classname, argv(1));
if (finder)
setorigin(pl, finder.origin);
break;
case "respawn_ents":
for (entity a = world; (a = findfloat(a, ::identity, 1));) {
NSEntity ent = (NSEntity)a;
@ -630,7 +637,6 @@ ConsoleCmd(string cmd)
}
break;
case "spawn":
entity unit = spawn();
unit.classname = strcat("spawnfunc_", argv(1));
self = unit;
@ -644,8 +650,6 @@ ConsoleCmd(string cmd)
}
traceline(pl.origin, pl.origin + (v_forward * 1024), MOVE_NORMAL, pl);
setorigin(unit, trace_endpos);
break;
#ifdef BOT_INCLUDED
case "way":

View File

@ -20,7 +20,6 @@ void Weapons_SwitchBest(NSClientPlayer pl, optional float skip);
int Weapons_AddItem(NSClientPlayer pl, int w, int startammo);
void Weapons_RemoveItem(NSClientPlayer pl, int w);
void Weapons_InitItem(int w);
void Weapons_UpdateAmmo(NSClientPlayer pl, int a1, int a2, int a3);
void Weapons_ReloadWeapon(NSClientPlayer pl, .int mag, .int ammo, int max);
void Weapon_DropCurrentWeapon(NSClientPlayer pl);
int Weapon_GetCount();

View File

@ -14,6 +14,7 @@
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#ifndef NEW_INVENTORY
/* force the drawing of the first weapon that's picked up */
var int autocvar_sv_forceweapondraw = TRUE;
@ -372,3 +373,4 @@ CSEv_DropWeapon(void)
player pl = (player)self;
Weapon_DropCurrentWeapon(pl);
}
#endif

View File

@ -45,6 +45,11 @@ NSClientPlayer:NSClientSpectator
PREDICTED_INT(g_items);
PREDICTED_FLOAT(activeweapon);
#ifdef NEW_INVENTORY
NSWeapon m_weapons[MAX_WEAPONS];
NSWeapon m_activeweapon;
#endif
/* vehicle info */
PREDICTED_ENT(vehicle);

View File

@ -14,8 +14,6 @@
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
const int CONTENTBITS_MONSTER = CONTENTBIT_SOLID|CONTENTBIT_BODY|CONTENTBIT_MONSTERCLIP|CONTENTBIT_BOTCLIP;
#ifdef SERVER
int
NSMonster::GetTriggerCondition(void)

View File

@ -139,6 +139,11 @@ class NSRenderableEntity:NSEntity
nonvirtual void(float) SetRenderMode;
nonvirtual void(float) SetRenderAmt;
nonvirtual void(vector) SetRenderColor;
nonvirtual void(float) SetBoneControl1;
nonvirtual void(float) SetBoneControl2;
nonvirtual void(float) SetBoneControl3;
nonvirtual void(float) SetBoneControl4;
nonvirtual void(float) SetBoneControl5;
#ifdef CLIENT
nonvirtual void(void) RenderFXPass;

56
src/shared/NSWeapon.h Normal file
View File

@ -0,0 +1,56 @@
#define MAX_WEAPONS 32
class
NSWeapon:NSRenderableEntity
{
entity m_owner;
string m_strName; /* Full character name */
int m_iSlot;
int m_iSlotPos;
bool m_bAllowDropping;
int m_iWeight;
/* generic info */
int m_iClip1;
int m_iClip2;
float m_flPrimaryNext;
float m_flSecondaryNext;
float m_flLastFired;
/* inspired by GMOD API https://wiki.facepunch.com/gmod/Weapon */
virtual string(void) GetPlayerModel;
virtual string(void) GetWorldModel;
virtual string(void) GetPrintName;
virtual bool(void) AllowDropping;
virtual int(void) GetPlayerAnim; /* aim anim */
virtual string(void) GetObituaryMessage;
virtual int(void) GetType;
virtual entity(void) GetOwner;
virtual int(void) GetClip1; /* returns primary attack clip */
virtual int(void) GetClip2; /* returns secondary attack clip */
virtual int(void) GetMaxClip1; /* returns primary max clip size */
virtual int(void) GetMaxClip2; /* returns secondary max clip size */
virtual float(void) GetNextPrimaryFire; /* gets next time the primary can fire */
virtual float(void) GetNextSecondaryFire;/* gets next time the secondary can fire */
virtual bool(void) HasAmmo;
virtual int(void) GetSlot;
virtual int(void) GetSlotPos;
virtual int(void) GetWeight;
virtual float(void) LastFireTime; /* returns absolute time at which the weapon was last fired */
virtual void(int) SetClip1; /* sets the primary ammo clip */
virtual void(int) SetClip2; /* sets the secondary ammo clip */
virtual bool(void) AllowsAutoSwitchFrom; /* whether the weapon allows to being switched from when a better weighted weapon is picked up */
virtual bool(void) AllowsAutoSwitchTo; /* whether the weapon allows to being switched to when a better weighted weapon is picked up */
/* calls */
virtual void(void) Precache;
virtual void(void) Draw;
virtual void(void) Holster;
virtual void(void) Primary;
virtual void(void) Secondary;
virtual void(void) Reload;
virtual void(void) Release;
virtual void(void) ClientPredraw;
virtual void(void) ClientPostdraw;
};

196
src/shared/NSWeapon.qc Normal file
View File

@ -0,0 +1,196 @@
/* calls */
void
NSWeapon::Precache(void)
{
}
void
NSWeapon::Draw(void)
{
}
void
NSWeapon::Holster(void)
{
}
void
NSWeapon::Primary(void)
{
}
void
NSWeapon::Secondary(void)
{
}
void
NSWeapon::Reload(void)
{
}
void
NSWeapon::Release(void)
{
}
void
NSWeapon::ClientPredraw(void)
{
}
void
NSWeapon::ClientPostdraw(void)
{
}
/* get */
string
NSWeapon::GetPlayerModel(void)
{
return "models/error.vvm";
}
string
NSWeapon::GetWorldModel(void)
{
return "models/error.vvm";
}
string
NSWeapon::GetPrintName(void)
{
return m_strName;
}
int
NSWeapon::GetSlot(void)
{
return m_iSlot;
}
int
NSWeapon::GetSlotPos(void)
{
return m_iSlotPos;
}
bool
NSWeapon::AllowDropping(void)
{
return false;
}
int
NSWeapon::GetWeight(void)
{
return 0;
}
int
NSWeapon::GetPlayerAnim(void)
{
return 0;
}
bool
NSWeapon::IsEmpty(void)
{
return false;
}
string
NSWeapon::GetObituaryMessage(void)
{
return "%s killed %s with Unknown";
}
int
NSWeapon::GetType(void)
{
return 0;
}
entity
NSWeapon::GetOwner(void)
{
return m_owner;
}
int
NSWeapon::GetClip1(void)
{
return 0;
}
int
NSWeapon::GetClip2(void)
{
return 0;
}
int
NSWeapon::GetMaxClip1(void)
{
return 0;
}
int
NSWeapon::GetMaxClip2(void)
{
return 0;
}
float
NSWeapon::GetNextPrimaryFire(void)
{
return m_flPrimaryNext;
}
float
NSWeapon::GetNextSecondaryFire(void)
{
return m_flSecondaryNext;
}
float
NSWeapon::LastFireTime(void)
{
return m_flLastFired;
}
void
NSWeapon::SetClip1(int new_clip)
{
m_iClip1 = new_clip;
}
void
NSWeapon::SetClip2(int new_clip)
{
m_iClip1 = new_clip;
}
bool
NSWeapon::AllowsAutoSwitchFrom(void)
{
}
bool
NSWeapon::AllowsAutoSwitchTo(void)
{
}
bool
NSWeapon::HasAmmo(void)
{
return false;
}
void
NSWeapon::NSWeapon(void)
{
}

View File

@ -61,6 +61,7 @@ string __fullspawndata;
#include "../xr/defs.h"
#include "NSClient.h"
#include "NSClientSpectator.h"
#include "NSWeapon.h"
#include "NSClientPlayer.h"
#include "NSVehicle.h"
@ -80,6 +81,7 @@ string __fullspawndata;
#include "propdata.h"
#include "surfaceproperties.h"
#include "colors.h"
#include "weapons.h"
#define BSPVER_PREREL 28
#define BSPVER_Q1 29

View File

@ -8,6 +8,7 @@ NSSurfacePropEntity.qc
NSPhysicsEntity.qc
NSBrushTrigger.qc
NSPointTrigger.qc
NSWeapon.qc
NSVehicle.qc
NSNavAI.qc
NSMonster.qc
@ -26,6 +27,8 @@ propdata.qc
surfaceproperties.qc
NSMaterial.qc
util.qc
weapons.qc
../xr/include.src
../materials/include.src
#endlist

View File

@ -208,7 +208,9 @@ const int CONTENTBIT_UNUSED15 = 0x10000000i;
const int CONTENTBIT_Q2LADDER = 0x20000000i; /* Q2BSP climbables */
const int CONTENTBIT_UNUSED16 = 0x40000000i;
const int CONTENTBIT_SKY = 0x80000000i; /* Q1BSP only! */
/* a bit content group */
const int CONTENTBITS_MONSTER = CONTENTBIT_SOLID|CONTENTBIT_BODY|CONTENTBIT_MONSTERCLIP|CONTENTBIT_BOTCLIP;
/* this is used for material-lookups using the external materials.txt file
* method used in Half-Life. In that environment we have to strip any

27
src/shared/weapons.h Normal file
View File

@ -0,0 +1,27 @@
#ifdef NEW_INVENTORY
/* for AI identification purposes */
typedef enum
{
WPNTYPE_INVALID, /* no logic */
WPNTYPE_RANGED, /* will want to keep their distance mostly */
WPNTYPE_THROW, /* has to keep some distance, but not too far */
WPNTYPE_CLOSE, /* have to get really close */
WPNTYPE_FULLAUTO, /* for things that need to be held down */
WPNTYPE_SEMI /* semi automatic */
} weapontype_t;
void Weapons_Draw(NSClientPlayer);
void Weapons_Release(NSClientPlayer);
void Weapons_Primary(NSClientPlayer);
void Weapons_Secondary(NSClientPlayer);
void Weapons_Reload(NSClientPlayer);
void Weapons_Init(void);
string Weapons_GetWorldmodel(int);
weapontype_t Weapons_GetType(NSClientPlayer, int);
int Weapons_IsEmpty(NSClientPlayer, int);
void Weapons_UpdateAmmo(NSClientPlayer, int, int, int);
#ifdef CLIENT
void Weapons_SetGeomset(string);
#endif
#endif

92
src/shared/weapons.qc Normal file
View File

@ -0,0 +1,92 @@
#ifdef NEW_INVENTORY
void
Weapons_Init(void)
{
}
string
Weapons_GetWorldmodel(int)
{
return "";
}
void
Weapons_Draw(NSClientPlayer pl)
{
if (pl.m_activeweapon)
pl.m_activeweapon.Draw();
}
void
Weapons_Release(NSClientPlayer pl)
{
if (pl.m_activeweapon)
pl.m_activeweapon.Release();
}
void
Weapons_Primary(NSClientPlayer pl)
{
if (pl.m_activeweapon)
pl.m_activeweapon.Primary();
}
void
Weapons_Secondary(NSClientPlayer pl)
{
if (pl.m_activeweapon)
pl.m_activeweapon.Secondary();
}
void
Weapons_Reload(NSClientPlayer pl)
{
if (pl.m_activeweapon)
pl.m_activeweapon.Reload();
}
void
Weapons_SetGeomset(string foo)
{
}
weapontype_t
Weapons_GetType(NSClientPlayer pl, int w)
{
if (pl.m_activeweapon)
return pl.m_activeweapon.GetType();
return WPNTYPE_INVALID;
}
void
Weapons_UpdateAmmo(NSClientPlayer pl, int a1, int a2, int a3)
{
/* no change */
if (a1 == -1)
a1 = pl.a_ammo1;
if (a2 == -1)
a2 = pl.a_ammo2;
if (a3 == -1)
a3 = pl.a_ammo3;
/* networked as bytes, since we don't need more. Clamp to avoid errors */
pl.a_ammo1 = a1;
pl.a_ammo2 = a2;
pl.a_ammo3 = a3;
}
void Weapons_PickupNotify(NSClientPlayer pl, int w) {}
void Weapons_RefreshAmmo(NSClientPlayer pl) {}
void Weapons_SwitchBest(NSClientPlayer pl, optional float skip) {}
int Weapons_AddItem(NSClientPlayer pl, int w, int startammo) {}
void Weapons_RemoveItem(NSClientPlayer pl, int w) {}
void Weapons_InitItem(int w) {}
void Weapons_ReloadWeapon(NSClientPlayer pl, .int mag, .int ammo, int max) {}
void Weapon_DropCurrentWeapon(NSClientPlayer pl) {}
int Weapon_GetCount() {}
int Weapon_GetBitID(int) {}
int Weapons_IsEmpty(NSClientPlayer, int) {}
#endif