Merge pull request #38 from ScatterBox/main

This commit is contained in:
Ian 2023-02-03 18:15:18 -05:00 committed by GitHub
commit 7d842bc720
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 417 additions and 26 deletions

View file

@ -11,6 +11,7 @@
../source/server/nzdparser.qc
../source/server/main.qc
../source/server/utilities/command_parser.qc
../source/server/utilities/math.qc
../source/server/player.qc
../source/server/damage.qc

View file

@ -15,6 +15,7 @@
../source/server/nzdparser.qc
../source/server/main.qc
../source/server/utilities/command_parser.qc
../source/server/utilities/math.qc
../source/server/player.qc
../source/server/damage.qc

View file

@ -15,6 +15,7 @@
../source/server/nzdparser.qc
../source/server/main.qc
../source/server/utilities/command_parser.qc
../source/server/utilities/math.qc
../source/server/player.qc
../source/server/damage.qc

View file

@ -223,32 +223,6 @@ void() place_fire =
self.nextthink = time + random()+0.1;
};
void() place_model =
{
#ifdef HANDHELD
if (self.spawnflags & 2)
remove(self);
#endif // HANDHELD
self.model = convert_old_asset_path(self.model);
precache_model (self.model);
setmodel (self, self.model);
setsize (self, VEC_HULL2_MIN, VEC_HULL2_MAX);
self.angles = self.angles;
self.solid = SOLID_NOT;
self.frame = self.sequence;
if (self.spawnflags & 1)
self.effects = self.effects | EF_FULLBRIGHT;
};
void () buy_weapon_touch =
{
entity oldent;
@ -744,3 +718,206 @@ void() func_ending =
self.touch = touch_ending;
};
//
// ============================================================
// misc_model()
// Entity for prop/other model placement, derived from
// progs_dump. Deprecates place_model.
// ============================================================
// Modifications from stock:
// - Added new spawnflag 64 for fullbright.
// - 'model' is now the preffered model field instead of 'mdl'.
//
// Spawnflags
#define MISC_MODEL_GRAVITY 1
#define MISC_MODEL_SOLID 2
#define MISC_MODEL_BACK_AND_FORTH 4
#define MISC_MODEL_ONLY_ONCE 8
#define MISC_MODEL_PLAY_COUNT 16
#define MISC_MODEL_STARTOFF 32
#define MISC_MODEL_FULLBRIGHT 64
// States
#define STATE_ACTIVE 0
#define STATE_INACTIVE 1
#define STATE_INVISIBLE 8
// Entity fields
.float first_frame; // The starting frame of the animation
.float last_frame; // The ending frame of the animation
.string mdl;
.vector mdlsz;
.vector centeroffset;
.float count; // for counting triggers
.float cnt; // misc flag
void() misc_model_use =
{
// Make invisible
if (self.state == STATE_ACTIVE) {
if (self.spawnflags & MISC_MODEL_SOLID) self.solid = SOLID_NOT;
self.oldmodel = self.model;
self.model = "";
self.state = STATE_INVISIBLE;
setorigin(self, self.origin);
}
// Have it appear again
else {
if (self.spawnflags & MISC_MODEL_SOLID) self.solid = SOLID_BBOX;
self.model = self.oldmodel;
self.state = STATE_ACTIVE;
setorigin(self, self.origin);
}
};
void() misc_model_think =
{
self.nextthink = time + fabs(self.speed);
if (self.state != STATE_ACTIVE)
return;
self.frame = self.frame + sign(self.speed);
if (self.spawnflags & MISC_MODEL_BACK_AND_FORTH && self.frame < self.first_frame) {
self.speed = -1 * self.speed;
self.frame += 2;
} else if (self.spawnflags & MISC_MODEL_BACK_AND_FORTH && self.frame > self.last_frame) {
self.speed = -1 * self.speed;
self.frame-=2;
}
else
self.frame = wrap(self.frame, self.first_frame, self.last_frame);
if (self.spawnflags & MISC_MODEL_ONLY_ONCE && self.frame == self.last_frame && self.last_frame != self.first_frame)
self.nextthink = -1;
if (self.spawnflags & MISC_MODEL_PLAY_COUNT && self.frame == self.last_frame && self.last_frame != self.first_frame)
{
if (!self.count)
objerror ("Error: set count to the number of animation cycles!");
self.cnt = self.cnt +1;
dprint (ftos(self.cnt));
dprint ("\n");
if (self.cnt != self.count)
return FALSE;
else
self.nextthink = -1;
}
};
void() misc_model =
{
if (!self.mdl || self.mdl == "") {
// NZP: Check for .model instead
if (!self.model || self.model == "")
objerror("Model not defined");
} else {
// Convert to .model instead of .mdl
self.model = self.mdl;
}
//
// Set default stats.
//
// Center offset.
if(!self.centeroffset)
self.centeroffset = '0 0 0';
// Custom Bounding Box.
if(!self.mdlsz)
self.mdlsz = '32 32 32';
// Generate Proper Bounding Box size.
vector vmin, vmax;
vmin_x = self.centeroffset_x - (self.mdlsz_x / 2);
vmin_y = self.centeroffset_y - (self.mdlsz_y / 2);
vmin_z = self.centeroffset_z - (self.mdlsz_z / 2);
vmax_x = self.centeroffset_x + (self.mdlsz_x / 2);
vmax_y = self.centeroffset_y + (self.mdlsz_y / 2);
vmax_z = self.centeroffset_z + (self.mdlsz_z / 2);
setsize (self, vmin, vmax);
// Set our model
precache_model(self.model);
setmodel(self, self.model);
// Model has collision box
if (self.spawnflags & MISC_MODEL_SOLID)
self.solid = SOLID_BBOX;
else
self.solid = SOLID_NOT;
// Model has gravity
if (self.spawnflags & MISC_MODEL_GRAVITY)
self.movetype = MOVETYPE_TOSS;
else
self.movetype = MOVETYPE_NONE;
// Model is fullbright
if (self.spawnflags & MISC_MODEL_FULLBRIGHT)
self.effects = self.effects | EF_FULLBRIGHT;
self.use = misc_model_use;
if (!self.frame)
self.frame = self.first_frame;
// Make static (not animate) if not given a frame range, and not affected by gravity
// also remains active if it has a targetname (so it can be killtargeted/toggled)
if (!self.last_frame && !(self.spawnflags & 1) && !(self.spawnflags & MISC_MODEL_SOLID) && !self.targetname)
makestatic(self);
// if it as a custom animation range
if (self.last_frame) {
// Default animation speed to 10 fps
if (!self.speed) {
self.speed = 0.1;
}
self.nextthink = time + self.speed;
self.think = misc_model_think;
}
// Start hidden
if (self.spawnflags & MISC_MODEL_STARTOFF)
self.state = STATE_ACTIVE;
else
self.state = STATE_INVISIBLE;
misc_model_use();
};
//
// place_model()
// Converts old place_model entities to use misc_model instead.
//
void() place_model =
{
// Grab an updated model path.
self.model = convert_old_asset_path(self.model);
// Convert the VEC_HULL bounds to match mdlsz.
self.mdlsz = '64 64 88';
// misc_model just uses frame plainly.
self.frame = self.sequence;
// Move fullbright spawnflag to the new param.
if (self.spawnflags & 1)
self.spawnflags = 64;
else
self.spawnflags = 0;
// Now just execute the misc_model spawn function.
misc_model();
};

View file

@ -0,0 +1,211 @@
/*
* math.qc
*
* Author: Joshua Skelton joshua.skelton@gmail.com
*
* A collection of helpful math functions.
*/
// Forward declarations
float(float value, float minValue, float maxValue) clamp;
float(float a, float b) mod;
float(float x) sign;
float(float value, float minValue, float maxValue) wrap;
/*
* clamp
*
* Limits the given value to the given range.
*
* value: A number
*
* minValue: The minimum value of the range
*
* maxValue: The maximum value of the range
*
* Returns: A number within the given range.
*/
float(float value, float minValue, float maxValue) clamp = {
if (value < minValue) {
return minValue;
}
else if (value > maxValue) {
return maxValue;
}
return value;
};
/*
* mod
*
* Returns the remainder after the division of a by n
*
* a: The dividend
*
* b: The divisor
*
* Returns: The remainder of a divided by n
*/
#ifndef PC
float(float a, float n) mod = {
return a - (n * floor(a / n));
};
#endif
/*
* sign
*
* Returns an indication of the sign of the given number.
*
* x: A number
*
* Returns: -1 if x < 0, 0 if x == 0, 1 if x > 0.
*/
float(float x) sign = {
if (x > 0) {
return 1;
}
else if (x < 0) {
return -1;
}
return 0;
};
/*
* wrap
*
* Limits the given value to the given range and will wrap the value to the
* the other end of the range if exceeded.
*
* value: A number
*
* minValue: The minimum value of the range
*
* maxValue: The maximum value of the range
*
* Returns: A number within the given range.
*/
float(float value, float minValue, float maxValue) wrap = {
local float range = maxValue - minValue;
return mod(value - minValue, range + 1) + minValue;
};
float(float a, float b, float mix) lerp =
{
if (mix <= 0) return a;
if (mix >= 1) return b;
return (b * mix + a * ( 1 - mix ) );
}
vector(vector a, vector b, float mix) lerpVector =
{
if (mix <= 0) return a;
if (mix >= 1) return b;
return (b * mix + a * ( 1 - mix ) );
}
// for a relaxing lerp: hermite lerp.
float(float a, float b, float mix) lerpHermite =
{
if (mix <= 0) return a;
if (mix >= 1) return b;
local float h01;
h01 = mix * mix;
h01 *= 3 - 2 * mix;
return (b * h01 + a * ( 1 - h01 ) );
}
vector(vector a, vector b, float mix) lerpVectorHermite =
{
if (mix <= 0) return a;
if (mix >= 1) return b;
local float h01;
h01 = mix * mix;
h01 *= 3 - 2 * mix;
return (b * h01 + a * ( 1 - h01 ) );
}
float(float anga, float angb) angledif =
{
float dif;
dif = fabs(anga - angb);
if (dif > 180)
dif = 360 - dif;
return dif;
}
float(vector ang, vector base_ang, vector offset) isInAngle = {
if (angledif(ang_x, base_ang_x) > offset_x || angledif(ang_y, base_ang_y) > offset_y)
return FALSE;
else
return TRUE;
};
// normalizes an angle vector to the 0/+359 range
vector(vector ang) normalizeAngles = {
ang_x = ang_x - floor(ang_x/360) * 360;
ang_y = ang_y - floor(ang_y/360) * 360;
ang_z = ang_z - floor(ang_z/360) * 360;
/*
while (ang_x > 360)
ang_x = ang_x - 360;
while (ang_x < 0)
ang_x = ang_x + 360;
while (ang_y > 360)
ang_y = ang_y - 360;
while (ang_y < 0)
ang_y = ang_y + 360;
while (ang_z > 360)
ang_z = ang_z - 360;
while (ang_z < 0)
ang_z = ang_z + 360;
*/
return ang;
};
// normalizes an angle vector to the -180/+179 range
vector(vector ang) normalizeAngles180 = {
ang_x = ((ang_x+180) - floor((ang_x+180)/360) * 360) - 180;
ang_y = ((ang_y+180) - floor((ang_y+180)/360) * 360) - 180;
ang_z = ((ang_z+180) - floor((ang_z+180)/360) * 360) - 180;
/*
while (ang_x > 180)
ang_x = ang_x - 360;
while (ang_x < -180)
ang_x = ang_x + 360;
while (ang_y > 180)
ang_y = ang_y - 360;
while (ang_y < -180)
ang_y = ang_y + 360;
while (ang_z > 180)
ang_z = ang_z - 360;
while (ang_z < -180)
ang_z = ang_z + 360;
*/
return ang;
};