mirror of
https://github.com/nzp-team/quakec.git
synced 2024-11-28 23:02:51 +00:00
Added "misc_model" to Map Entities
This commit is contained in:
parent
60d5c8f184
commit
a17d24062b
5 changed files with 400 additions and 0 deletions
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -744,3 +744,189 @@ void() func_ending =
|
|||
|
||||
self.touch = touch_ending;
|
||||
};
|
||||
|
||||
/*
|
||||
askasdklasdjalskdjaklsdjaklsdjaklsjdklasjdklasjdklasjdklasjdklasjdklasjdklasjdklasjdklasjdklasjdlaks
|
||||
klsdjflsdjflskdjfslkdfjskldfjsdklfjskldfjskldjfklsdjfklsdjfklsdjfklsdjfklsdjfklsdjfklsdjfklsdjfklsfj
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
----------------------------------------MISC_MODEL--------------------------------------------------
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
klsjakljsdklasjdklasjdaklsdjaklsdjaklsdjaklsdjaklsdjaklsjdaskljaskljdaklsjdlaskjdklasjklasjdklasjdkl
|
||||
aklsjdklasjdklasjdaklsjdklasjdaklsjdklasjdaskldjlaskdjaklsdjaskldjaskldjaskldjaskldjaklsdjaklsdjalsd
|
||||
*/
|
||||
|
||||
/*QUAKED misc_model (0 0.5 0.8) (-8 -8 -8) (8 8 8) X X X X X X X X NOT_ON_EASY NOT_ON_NORMAL NOT_ON_HARD_OR_NIGHTMARE NOT_IN_DEATHMATCH NOT_IN_COOP NOT_IN_SINGLEPLAYER X NOT_ON_HARD_ONLY NOT_ON_NIGHTMARE_ONLY
|
||||
{
|
||||
model ({"path" : mdl, "skin" : skin, "frame": frame});
|
||||
}
|
||||
An entity for displaying models. A frame range can be given to animate the
|
||||
model.
|
||||
|
||||
mdl: The model to display. Can be of type mdl, bsp, or spr.
|
||||
|
||||
frame: The frame to display. Can be used to offset the animation.
|
||||
|
||||
first_frame: The starting frame of the animation.
|
||||
|
||||
last_frame: The last frame of the animation.
|
||||
*/
|
||||
|
||||
// The starting frame of the animation
|
||||
.float first_frame;
|
||||
|
||||
// The ending frame of the animation
|
||||
.float last_frame;
|
||||
|
||||
// Forward declarations
|
||||
void() misc_model_think;
|
||||
|
||||
float MISC_MODEL_GRAVITY = 1;
|
||||
float MISC_MODEL_SOLID = 2;
|
||||
float MISC_MODEL_BACK_AND_FORTH = 4;
|
||||
float MISC_MODEL_ONLY_ONCE = 8;
|
||||
float MISC_MODEL_PLAY_COUNT = 16;
|
||||
float MISC_MODEL_STARTOFF = 32;
|
||||
|
||||
//misc_model decs
|
||||
.string mdl;
|
||||
.vector mdlsz;
|
||||
.vector centeroffset;
|
||||
.float count; // for counting triggers
|
||||
.float cnt; // misc flag
|
||||
float STATE_ACTIVE = 0;
|
||||
float STATE_INACTIVE = 1;
|
||||
float STATE_INVISIBLE = 8;
|
||||
|
||||
|
||||
void() misc_model_use =
|
||||
{
|
||||
if (self.state == STATE_ACTIVE) {
|
||||
if (self.spawnflags & MISC_MODEL_SOLID) self.solid = SOLID_NOT;
|
||||
self.model = "";
|
||||
|
||||
self.state = STATE_INVISIBLE;
|
||||
setorigin(self, self.origin);
|
||||
}
|
||||
else {
|
||||
if (self.spawnflags & MISC_MODEL_SOLID) self.solid = SOLID_BBOX;
|
||||
self.model = self.mdl;
|
||||
|
||||
self.state = STATE_ACTIVE;
|
||||
setorigin(self, self.origin);
|
||||
}
|
||||
};
|
||||
|
||||
void() misc_model =
|
||||
{
|
||||
if (!self.mdl || self.mdl == "")
|
||||
{
|
||||
objerror("Model not defined");
|
||||
}
|
||||
|
||||
if(!self.centeroffset) self.centeroffset = '0 0 0';
|
||||
if(!self.mdlsz) self.mdlsz = '32 32 32';
|
||||
|
||||
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);
|
||||
|
||||
precache_model(self.mdl);
|
||||
setmodel(self, self.mdl);
|
||||
|
||||
setsize (self, vmin, vmax);
|
||||
|
||||
if(self.spawnflags & MISC_MODEL_SOLID) self.solid = SOLID_BBOX;
|
||||
else self.solid = SOLID_NOT;
|
||||
|
||||
if(self.spawnflags & 1) self.movetype = MOVETYPE_TOSS;
|
||||
else self.movetype = MOVETYPE_NONE;
|
||||
|
||||
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);
|
||||
}
|
||||
// Make static (not animate) if not given a frame range, and not affected by gravity
|
||||
//changed by bmFbr
|
||||
// if (!self.last_frame && !(self.spawnflags & MISC_MODEL_GRAVITY)) {
|
||||
// makestatic(self);
|
||||
// return;
|
||||
// }
|
||||
|
||||
if (self.last_frame) { // if it as a custom animation range
|
||||
// Default animation speed to 10 fps
|
||||
if (!self.speed) {
|
||||
self.speed = 0.1;
|
||||
}
|
||||
self.nextthink = time + self.speed;
|
||||
self.think = misc_model_think;
|
||||
}
|
||||
|
||||
if (self.spawnflags & 32)
|
||||
self.state = STATE_ACTIVE;
|
||||
else
|
||||
self.state = STATE_INVISIBLE;
|
||||
|
||||
misc_model_use();
|
||||
|
||||
};
|
||||
|
||||
/*
|
||||
* misc_model_think
|
||||
*
|
||||
* Handles animation for misc_model entity.
|
||||
*/
|
||||
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;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
|
211
source/server/utilities/math.qc
Normal file
211
source/server/utilities/math.qc
Normal 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;
|
||||
};
|
Loading…
Reference in a new issue