Git Repos / fte_dogmode / qc / base_func.qc
Last update to this file was on 2024-03-24 at 02:40.
Show base_func.qc
//==============================================================================
// base_func.qc -- func base class
//==============================================================================
//======================================================================
// Constants
//======================================================================
const float FUNC_STATE_TOP = 0; // button, door, elevator states
const float FUNC_STATE_BOTTOM = 1;
const float FUNC_STATE_UP = 2;
const float FUNC_STATE_DOWN = 3;
//======================================================================
// fields
//======================================================================
.float lip; //
.void() think1; // called by calcmove_done
.vector finaldest, finalangle;
//======================================================================
// forward declarations
//======================================================================
void() sub_calcmove_done_think;
void(entity e, vector tdest, float tspeed, void() newthink) sub_calcmove;
void() sub_calcanglemovecontroller_done;
void(entity e, vector destangle, float tspeed, void() func, entity c)
sub_calcanglemovecontroller;
void(entity e) base_func_init;
strip void() base_func;
//------------------------------------------------------------------------------
//----------------------------------------------------------------------
// class base_func: base_mapentity
// {
//==============================================================
// Subs
//==============================================================
//--------------------------------------------------------------
void() sub_calcmove_done_think =
{
setorigin (self, self.finaldest);
self.velocity = '0 0 0';
self.nextthink = -1;
if (self.think1)
self.think1 ();
};
//--------------------------------------------------------------
// SUB_CalcMove
//--------------------------------------------------------------
void(entity e, vector tdest, float tspeed, void() newthink)
sub_calcmove =
{
local vector vdestdelta;
local float len, traveltime, localtime;
if (!tspeed)
objerror ("sub_calcmove: No speed is defined!");
if (e.movetype == MOVETYPE_PUSH)
localtime = self.ltime;
else
localtime = time;
e.think1 = newthink;
e.finaldest = tdest;
e.think = sub_calcmove_done_think;
if (tdest == self.origin)
{
e.velocity = '0 0 0';
e.nextthink = localtime + 0.1;
return;
}
// set destdelta to the vector needed to move
vdestdelta = tdest - self.origin;
// calculate length of vector
len = vlen (vdestdelta);
// divide by speed to get time to reach tdest
traveltime = len / tspeed;
if (traveltime < 0.1)
{
e.velocity = '0 0 0';
e.nextthink = localtime + 0.1;
return;
}
// set nextthink to trigger a think when d is reached
e.nextthink = localtime + traveltime;
// scale the destdelta vector by the time spent traveling
// to get velocity
// qcc won't take vec/float
e.velocity = vdestdelta * (1 / traveltime);
};
//--------------------------------------------------------------
// SUB_CalcAngleMoveDoneController
// After rotating, set angle to exact final angle
//--------------------------------------------------------------
void() sub_calcanglemovecontroller_done =
{
self.owner.angles = self.finalangle;
self.owner.avelocity = '0 0 0';
self.nextthink = -1;
if (self.think1)
sub_runvoidas (self.owner, self.think1);
};
//--------------------------------------------------------------
// SUB_CalcAngleMoveController -- Same as SUB_CalcAngleMove, but
// using a separate controller entity to not lose track of current
// think functions.
//--------------------------------------------------------------
void(entity e, vector destangle, float tspeed, void() func,
entity c) sub_calcanglemovecontroller =
{
local vector destdelta;
local float len, traveltime;
if (!tspeed)
objerror("sub_calcanglemove: No speed is defined!\n");
// set destdelta to the vector needed to move
destdelta = normalize_angles180 (destangle - e.angles);
/*
dprint3 ("destangle: ", vtos(destangle), "\n");
dprint3 ("self.angles: ", vtos(self.angles), "\n");
dprint3 ("destdelta: ", vtos(destdelta), "\n");
*/
// calculate length of vector
len = vlen (destdelta);
// divide by speed to get time to reach dest
traveltime = len / tspeed;
// set nextthink to trigger a think when dest is reached
c.nextthink = time + traveltime;
// scale the destdelta vector by the time spent traveling to
// get velocity
e.avelocity = destdelta * (1 / traveltime);
// Makes sure controller.owner points to self so it can be
// referenced later in the think function
c.owner = e;
c.think1 = func;
c.finalangle = destangle;
c.think = sub_calcanglemovecontroller_done;
};
//==============================================================
// Constructor & Spawn Functions
//==============================================================
//--------------------------------------------------------------
void(entity e) base_func_init =
{
base_mapentity_init (e);
e.classgroup |= CG_FUNC;
};
//--------------------------------------------------------------
strip void() base_func =
{
base_func_init (self);
};
// };
Return to the top of this page or return to the overview of this repo.
Log base_func.qc
Date | Commit Message | Author | + | - |
---|---|---|---|---|
2024-03-24 | 2nd pass refactor, rework QC class structure | cev | +107 | -70 |
2024-02-18 | Client/player, projectiles, entrypoints refactor | cev | +7 | |
2024-01-31 | Class based monster refactor & start projectiles | cev | +10 | -6 |
2024-01-09 | Continue OO / Class-based refactor | cev | +133 |
Return to the top of this page or return to the overview of this repo.