More fixes.

This commit is contained in:
Marco Cawthorne 2024-07-11 15:24:33 -07:00
parent 8ace54224c
commit a852f887e2
Signed by: eukara
GPG key ID: CE2032F0A2882A22
18 changed files with 214 additions and 33 deletions

View file

@ -1 +0,0 @@
Documentation/ReadMe.md

18
README.md Normal file
View file

@ -0,0 +1,18 @@
# Nuclide
Nuclide is a cross-platform game development kit. It is powered by FTE QuakeWorld and intended for developers.
For more information, [visit the online manual](https://developer.vera-visions.com).
## Trying the Latest
Ensure you have FTE QuakeWorld, or are comfortable building it yourself.
You can build a copy of FTEQW using the command `make engine`.
*If that is a lot to bootstrap, you can use any recent binary version.*
Run the engine in the root of this repository, after having issued `make progs GAME=base`.
## Building Documentation
You can build your own offline version of the online manual by running `doxygen` in the root of this repository. The output will be under **Documentation/html/index.html**.

View file

@ -273,8 +273,13 @@ trigger_hurt::Touch(entity eToucher)
EntLog("Hurting %S (%d) with %i.", eToucher.classname, num_for_edict(eToucher), m_iDamage);
vector center = WorldSpaceCenter();
string dmgDef = sprintf("\"damage\" \"%i\"", m_iDamage);
entityDamage(eToucher, this, eToucher, dmgDef, "", center, g_vec_null, eToucher.origin);
/* this is kinda ugly, but worth the price */
NSDict damageDecl = spawn(NSDict);
damageDecl.AddKey("damage", itos(m_iDamage));
damageDecl.AddKey("flags", itos(type));
entityDamage(eToucher, this, eToucher, damageDecl.GetDeclBody(), "", center, g_vec_null, eToucher.origin);
remove(damageDecl);
/* shut it down if used once */
if (HasSpawnFlags(SF_HURT_ONCE)) {

View file

@ -162,7 +162,7 @@ Nodes_BuildFromEnts(void)
if (g_iNodes) {
NSLog("saving nodes nodes for %s", mapname);
NodeEdit_SaveFile(g_pNodes, g_iNodes, sprintf("%s.way", mapname));
NodeEdit_SaveFile(sprintf("%s.way", mapname));
} else {
NSLog("no node data found for %s", mapname);
}

View file

@ -485,7 +485,7 @@ NSClientPlayer::UpdateAliveCam(void)
{
vector cam_pos = GetEyePos();
#if defined(VALVE) || defined(CSTRIKE) || defined(GEARBOX)
#if defined(VALVE) || defined(CSTRIKE) || defined(GEARBOX) || defined(TFC)
//view_angles = Camera_RunBob(view_angles);
//view_angles = Camera_StrafeRoll(view_angles);
cam_pos += CalculateLean(view_angles);
@ -1576,6 +1576,9 @@ NSClientPlayer::Footsteps_Update(void)
void
NSClientPlayer::Damage(entity inflictor, entity attacker, string damageDef, float damageScale, vector dmgDir, vector hitLocation)
{
#ifdef SERVER
super::Damage(inflictor, attacker, damageDef, damageScale, dmgDir, hitLocation);
#if 0
bool isFriendlyFire = false;
@ -1730,4 +1733,5 @@ NSClientPlayer::Damage(entity inflictor, entity attacker, string damageDef, floa
}
}
#endif
#endif
}

37
src/shared/NSDict.h Normal file
View file

@ -0,0 +1,37 @@
/*
* Copyright (c) 2024 Vera Visions LLC.
*
* 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.
*/
class
NSDict
{
public:
void NSDict(void);
nonvirtual float GetFloat(string);
nonvirtual string GetString(string);
nonvirtual vector GetVector(string);
nonvirtual bool GetBool(string);
nonvirtual void SetDeclBody(string);
nonvirtual string GetDeclBody(void);
nonvirtual void AddKey(string, string);
nonvirtual void RemoveKey(string);
private:
nonvirtual void _AddRemoveKey(string, string, bool);
string m_strBody;
};

96
src/shared/NSDict.qc Normal file
View file

@ -0,0 +1,96 @@
/*
* Copyright (c) 2024 Vera Visions LLC.
*
* 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.
*/
void
NSDict::NSDict(void)
{
m_strBody = "";
}
string
NSDict::GetDeclBody(void)
{
return (m_strBody);
}
void
NSDict::SetDeclBody(string textBody)
{
m_strBody = textBody;
}
float
NSDict::GetFloat(string keyName)
{
return stof(GetString(keyName));
}
string
NSDict::GetString(string keyName)
{
int spawnWords = (int)tokenize_console(m_strBody);
/* iterate over our own spawnkeys first */
for (int c = 0i; c < spawnWords; c+= 2i) {
if (argv(c) == keyName) {
return argv(c+1);
}
}
}
vector
NSDict::GetVector(string keyName)
{
return stov(GetString(keyName));
}
bool
NSDict::GetBool(string keyName)
{
return stof(GetString(keyName)) ? true : false;
}
void
NSDict::_AddRemoveKey(string keyName, string setValue, bool delete)
{
string newBody = "";
int spawnWords = (int)tokenize_console(m_strBody);
/* collect all existing key (except the one we wanna add, if it exists */
for (int c = 0i; c < spawnWords; c+= 2i) {
if (argv(c) != keyName) {
newBody = sprintf("%s%S %S\n", newBody, argv(c), argv(c+1));
}
}
if (delete == false) {
newBody = sprintf("%s%S %S\n", newBody, keyName, setValue);
}
m_strBody = newBody;
}
void
NSDict::AddKey(string keyName, string setValue)
{
_AddRemoveKey(keyName, setValue, false);
}
void
NSDict::RemoveKey(string keyName)
{
_AddRemoveKey(keyName, "", true);
}

View file

@ -201,7 +201,7 @@ public:
void
_NSEntLog(string className, string functionName, float edictNum, string warnMessage)
{
if (autocvar_g_developerTimestamps)
if (autocvar_g_logTimestamps)
print(sprintf("^9%f ^7%s (%d)^7: %s\n", time, className, edictNum, warnMessage));
else
print(sprintf("^7%s (%d)^7: %s\n", className, edictNum, warnMessage));
@ -210,7 +210,7 @@ _NSEntLog(string className, string functionName, float edictNum, string warnMess
void
_NSEntWarning(string className, string functionName, float edictNum, string warnMessage)
{
if (autocvar_g_developerTimestamps)
if (autocvar_g_logTimestamps)
print(sprintf("^9%f ^3%s (%d)^7: %s\n", time, functionName, edictNum, warnMessage));
else
print(sprintf("^3%s (%d)^7: %s\n", functionName, edictNum, warnMessage));
@ -219,7 +219,7 @@ _NSEntWarning(string className, string functionName, float edictNum, string warn
void
_NSEntError(string className, string functionName, float edictNum, string warnMessage)
{
if (autocvar_g_developerTimestamps)
if (autocvar_g_logTimestamps)
print(sprintf("^9%f ^1%s (id: %d)^7: %s\n", time, functionName, edictNum, warnMessage));
else
print(sprintf("^1%s (id: %d)^7: %s\n", functionName, edictNum, warnMessage));
@ -228,16 +228,16 @@ _NSEntError(string className, string functionName, float edictNum, string warnMe
The console variable `entity_developer` has to be `1` for them to be visible.
@param description(...) contains a formatted string containing a description. */
#define EntLog(...) if (autocvar_g_developer) _NSEntLog(classname, __FUNC__, num_for_edict(this), sprintf(__VA_ARGS__))
#define EntLog(...) if (autocvar_g_logLevel >= LOGLEVEL_DEBUG) _NSEntLog(classname, __FUNC__, num_for_edict(this), sprintf(__VA_ARGS__))
/** Logs an entity class specific warning message, with detailed info.
The console variable `entity_developer` has to be `1` for them to be visible.
@param description(...) contains a formatted string containing a description. */
#define EntWarning(...) _NSEntWarning(classname, __FUNC__, num_for_edict(this), sprintf(__VA_ARGS__))
#define EntWarning(...) if (autocvar_g_logLevel >= LOGLEVEL_WARNINGS) _NSEntWarning(classname, __FUNC__, num_for_edict(this), sprintf(__VA_ARGS__))
/** Logs an entity class specific error message, with detailed info.
The console variable `entity_developer` has to be `1` for them to be visible.
@param description(...) contains a formatted string containing a description. */
#define EntError(...) _NSEntError(classname, __FUNC__, num_for_edict(this), sprintf(__VA_ARGS__))
#define EntError(...) if (autocvar_g_logLevel >= LOGLEVEL_ERRORS) _NSEntError(classname, __FUNC__, num_for_edict(this), sprintf(__VA_ARGS__))

View file

@ -18,7 +18,7 @@ var bool autocvar_ai_debugLogic = false;
void
_NSMonster_Log(string className, string functionName, float edictNum, string warnMessage)
{
if (autocvar_g_developerTimestamps)
if (autocvar_g_logTimestamps)
printf("^9%f ^5%s (%d) ^7: %s\n", time, functionName, edictNum, warnMessage);
else
printf("^5%s (%d) ^7: %s\n", functionName, edictNum, warnMessage);

View file

@ -18,7 +18,7 @@ var bool autocvar_ai_debugNav = false;
void
_NSNavAI_Log(string className, string functionName, float edictNum, string warnMessage)
{
if (autocvar_g_developerTimestamps)
if (autocvar_g_logTimestamps)
printf("^9%f ^5%s (%d) ^7: %s\n", time, functionName, edictNum, warnMessage);
else
printf("^5%s (%d) ^7: %s\n", functionName, edictNum, warnMessage);

View file

@ -243,7 +243,17 @@ NSSurfacePropEntity::ParentUpdate(void)
void
NSSurfacePropEntity::Damage(entity inflictor, entity attacker, string damageDef, float damageScale, vector dmgDir, vector hitLocation)
{
string damageString = EntityDef_GetKeyValue(damageDef, "damage");
bool defBody = EntityDef_IDFromName(damageDef) == -1i : true : false;
string damageString;
if (defBody == true) {
NSDict damageDecl = spawn(NSDict);
damageDecl.SetDeclBody(damageDef);
damageString = damageDecl.GetString("damage");
} else {
damageString = EntityDef_GetKeyValue(damageDef, "damage");
}
float damagePoints = (float)rint(stof(damageString) * damageScale);
NSSurfacePropEntity ourAttacker = (NSSurfacePropEntity)attacker;
@ -808,6 +818,7 @@ entityDamage(entity targetEnt, entity inflictingEnt, entity attackingEnt, string
if (targetEnt.takedamage == DAMAGE_NO) {
return;
}
if (isGodMode(targetEnt) == true) {
return;
}

View file

@ -18,7 +18,7 @@ var bool autocvar_vehicle_developer = false;
void
_NSVehicle_Log(string className, string functionName, float edictNum, string warnMessage)
{
if (autocvar_g_developerTimestamps)
if (autocvar_g_logTimestamps)
printf("^9%f ^2%s (%d) ^7: %s\n", time, functionName, edictNum, warnMessage);
else
printf("^2%s (%d) ^7: %s\n", functionName, edictNum, warnMessage);

View file

@ -91,6 +91,7 @@ string __fullspawndata;
#include "sentences.h"
#include "NSIO.h"
#include "NSDict.h"
#include "NSTrigger.h"
#include "NSEntity.h"
#include "NSTimer.h"

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2023 Vera Visions LLC.
* Copyright (c) 2023-2024 Vera Visions LLC.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
@ -125,4 +125,4 @@ bool EntityDef_Precache(string);
NSEntity Entity_CreateClass(string className);
#endif
/** @} */ // end of entitydef
/** @} */ // end of entitydef

View file

@ -46,4 +46,3 @@
#define VFL_NOATTACK (1<<10) /**< Entity is not allowed to fire. */
#define VFL_PRIMEDFUSE (1<<11) /**< Entity is not allowed to fire. */
#define VFL_REDRAW (1<<12) /**< Entity is not allowed to fire. */

View file

@ -14,8 +14,18 @@
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
var bool autocvar_g_developer = false;
var bool autocvar_g_developerTimestamps = false;
var bool autocvar_g_logTimestamps = false;
typedef enum
{
LOGLEVEL_NONE,
LOGLEVEL_ERRORS,
LOGLEVEL_WARNINGS,
LOGLEVEL_DEBUG,
} logLevel_t;
#define LOGLEVEL_DEFAULT LOGLEVEL_WARNINGS
var logLevel_t autocvar_g_logLevel = LOGLEVEL_DEFAULT;
#define printf(...) print(sprintf(__VA_ARGS__))
@ -27,7 +37,7 @@ var bool autocvar_g_developerTimestamps = false;
void
_NSLog(string msg)
{
if (autocvar_g_developerTimestamps)
if (autocvar_g_logTimestamps)
print(sprintf("^9%f ^7%s\n", time, msg));
else
print(sprintf("^7%s\n", msg));
@ -36,7 +46,7 @@ _NSLog(string msg)
void
_NSError(string functionName, string msg)
{
if (autocvar_g_developerTimestamps)
if (autocvar_g_logTimestamps)
print(sprintf("^9%f ^1%s^7: %s\n", time, functionName, msg));
else
print(sprintf("^1%s^7: %s\n", functionName, msg));
@ -45,7 +55,7 @@ _NSError(string functionName, string msg)
void
_NSWarning(string functionName, string msg)
{
if (autocvar_g_developerTimestamps)
if (autocvar_g_logTimestamps)
print(sprintf("^9%f ^3%s^7: %s\n", time, functionName, msg));
else
print(sprintf("^3%s^7: %s\n", functionName, msg));
@ -66,19 +76,19 @@ _NSAssert(bool condition, string function, string descr)
The console variable `g_developer` has to be `1` for them to be visible.
@param description(...) contains a formatted string containing a description. */
#define NSLog(...) if (autocvar_g_developer) _NSLog(sprintf(__VA_ARGS__))
#define NSLog(...) if (autocvar_g_logLevel >= LOGLEVEL_DEBUG) _NSLog(sprintf(__VA_ARGS__))
/** Logs an error message, with timestamp.
The console variable `g_developer` has to be `1` for them to be visible.
@param description(...) contains a formatted string containing a description. */
#define NSError(...) _NSError(__FUNC__, sprintf(__VA_ARGS__))
#define NSError(...) if (autocvar_g_logLevel >= LOGLEVEL_ERRORS) _NSError(__FUNC__, sprintf(__VA_ARGS__))
/** Logs a warning message, with timestamp.
The console variable `g_developer` has to be `1` for them to be visible.
@param description(...) contains a formatted string containing a description. */
#define NSWarning(...) _NSWarning(__FUNC__, sprintf(__VA_ARGS__))
#define NSWarning(...) if (autocvar_g_logLevel >= LOGLEVEL_WARNINGS) _NSWarning(__FUNC__, sprintf(__VA_ARGS__))
/** Generates an assertion, if a given condition is false.
The console variable `g_developer` has to be `1` for them to be visible.
@ -86,7 +96,7 @@ _NSAssert(bool condition, string function, string descr)
@param condition is the expression to be evaluated.
@param description(...) contains a formatted string containing an error description. */
#define NSAssert(condition, ...) if (autocvar_g_developer) _NSAssert(condition, __FUNC__, sprintf(__VA_ARGS__))
#define NSAssert(condition, ...) if (autocvar_g_logLevel >= LOGLEVEL_ERRORS) _NSAssert(condition, __FUNC__, sprintf(__VA_ARGS__))
typedef enumflags
{

View file

@ -1,5 +1,6 @@
#includelist
NSIO.qc
NSDict.qc
NSTrigger.qc
NSEntity.qc
NSTimer.qc

View file

@ -112,11 +112,11 @@ possibilities are endless!
.float maxspeed;
.float flags;
var bool autocvar_s_developer = false;
var logLevel_t autocvar_s_logLevel = LOGLEVEL_DEFAULT;
void
_SndLog(string functionName, string msg)
{
if (autocvar_g_developerTimestamps)
if (autocvar_g_logTimestamps)
print(sprintf("^9%f ^xF50%s^7: %s\n", time, functionName, msg));
else
print(sprintf("^xF50%s^7: %s\n", functionName, msg));
@ -126,12 +126,12 @@ _SndLog(string functionName, string msg)
The console variable `s_developer` has to be `1` for them to be visible.
@param description(...) contains a formatted string containing a description. */
#define SndLog(...) if (autocvar_s_developer) _SndLog(__FUNC__, sprintf(__VA_ARGS__))
#define SndLog(...) if (autocvar_s_logLevel >= LOGLEVEL_DEBUG) _SndLog(__FUNC__, sprintf(__VA_ARGS__))
void
_SndEntLog(string className, string functionName, float edictNum, string warnMessage)
{
if (autocvar_g_developerTimestamps)
if (autocvar_g_logTimestamps)
print(sprintf("^9%f ^xF50%s (id: %d)^7: %s\n", time, functionName, edictNum, warnMessage));
else
print(sprintf("^xF50%s (id: %d)^7: %s\n", functionName, edictNum, warnMessage));
@ -141,7 +141,7 @@ _SndEntLog(string className, string functionName, float edictNum, string warnMes
The console variable `s_developer` has to be `1` for them to be visible.
@param description(...) contains a formatted string containing a description. */
#define SndEntLog(...) if (autocvar_s_developer) _SndEntLog(classname, __FUNC__, num_for_edict(this), sprintf(__VA_ARGS__))
#define SndEntLog(...) if (autocvar_s_logLevel >= LOGLEVEL_DEBUG) _SndEntLog(classname, __FUNC__, num_for_edict(this), sprintf(__VA_ARGS__))
/** Global hash table for name > soundDef id lookup. */
var hashtable g_hashsounds;

View file

@ -96,4 +96,4 @@ Util_ChatFormat(float playerNum, float teamNum, string chatMessage)
} else {
return sprintf("%s %s(%s)^7: %s", playerName, teamColorString, teamName, chatMessage);
}
}
}