+#include "subs.qh"
void SUB_NullThink(entity this) { }
void SUB_CalcMoveDone(entity this);
.float friction;
void SUB_Friction (entity this)
{
- this.SUB_NEXTTHINK = time;
+ this.nextthink = time;
if(IS_ONGROUND(this))
- this.SUB_VELOCITY = this.SUB_VELOCITY * (1 - frametime * this.friction);
+ this.velocity = this.velocity * (1 - frametime * this.friction);
}
/*
else
{
// remove
- remove (ent);
+ delete(ent);
}
}
{
if(this.alpha == 0)
this.alpha = 1;
- SUB_THINK(this, SUB_SetFade_Think);
- this.SUB_NEXTTHINK = time;
+ setthink(this, SUB_SetFade_Think);
+ this.nextthink = time;
this.alpha -= frametime * this.fade_rate;
if (this.alpha < 0.01)
SUB_VanishOrRemove(this);
else
- this.SUB_NEXTTHINK = time;
+ this.nextthink = time;
}
/*
void SUB_SetFade (entity ent, float when, float fading_time)
{
ent.fade_rate = 1/fading_time;
- SUB_THINK(ent, SUB_SetFade_Think);
- ent.SUB_NEXTTHINK = when;
+ setthink(ent, SUB_SetFade_Think);
+ ent.nextthink = when;
}
/*
=============
SUB_CalcMove
-calculate this.SUB_VELOCITY and this.SUB_NEXTTHINK to reach dest from
-this.SUB_ORIGIN traveling at speed
+calculate this.velocity and this.nextthink to reach dest from
+this.origin traveling at speed
===============
*/
void SUB_CalcMoveDone(entity this)
{
// After moving, set origin to exact final destination
- SUB_SETORIGIN (this, this.finaldest);
- this.SUB_VELOCITY = '0 0 0';
- this.SUB_NEXTTHINK = -1;
- if (this.think1)
+ setorigin (this, this.finaldest);
+ this.velocity = '0 0 0';
+ this.nextthink = -1;
+ if (this.think1 && this.think1 != SUB_CalcMoveDone)
this.think1 (this);
}
destangle_x = -destangle_x; // flip up / down orientation
// take the shortest distance for the angles
- vector v = SUB_ANGLES(this.owner);
+ vector v = this.owner.angles;
v.x -= 360 * floor((v.x - destangle_x) / 360 + 0.5);
v.y -= 360 * floor((v.y - destangle_y) / 360 + 0.5);
v.z -= 360 * floor((v.z - destangle_z) / 360 + 0.5);
- SUB_ANGLES(this.owner) = v;
- angloc = destangle - SUB_ANGLES(this.owner);
+ this.owner.angles = v;
+ angloc = destangle - this.owner.angles;
angloc = angloc * (1 / PHYS_INPUT_FRAMETIME); // so it arrives for the next frame
- this.owner.SUB_AVELOCITY = angloc;
+ this.owner.avelocity = angloc;
}
if(nexttick < this.animstate_endtime)
- veloc = nextpos - this.owner.SUB_ORIGIN;
+ veloc = nextpos - this.owner.origin;
else
- veloc = this.finaldest - this.owner.SUB_ORIGIN;
+ veloc = this.finaldest - this.owner.origin;
veloc = veloc * (1 / PHYS_INPUT_FRAMETIME); // so it arrives for the next frame
- this.owner.SUB_VELOCITY = veloc;
+ this.owner.velocity = veloc;
this.nextthink = nexttick;
}
else
{
// derivative: delta + 2 * delta2 (e.g. for angle positioning)
entity own = this.owner;
- SUB_THINK(own, this.think1);
- remove(this);
- SUB_THUNK(own)(own);
+ setthink(own, this.think1);
+ // set the owner's reference to this entity to NULL
+ own.move_controller = NULL;
+ delete(this);
+ getthink(own)(own);
}
}
this.think1 = func;
this.finaldest = tdest;
- SUB_THINK(this, SUB_CalcMoveDone);
+ setthink(this, SUB_CalcMoveDone);
switch(tspeedtype)
{
default:
case TSPEED_START:
- traveltime = 2 * vlen(tcontrol - this.SUB_ORIGIN) / tspeed;
+ traveltime = 2 * vlen(tcontrol - this.origin) / tspeed;
break;
case TSPEED_END:
traveltime = 2 * vlen(tcontrol - tdest) / tspeed;
break;
case TSPEED_LINEAR:
- traveltime = vlen(tdest - this.SUB_ORIGIN) / tspeed;
+ traveltime = vlen(tdest - this.origin) / tspeed;
break;
case TSPEED_TIME:
traveltime = tspeed;
if (traveltime < 0.1) // useless anim
{
- this.SUB_VELOCITY = '0 0 0';
- this.SUB_NEXTTHINK = this.SUB_LTIME + 0.1;
+ this.velocity = '0 0 0';
+ this.nextthink = this.ltime + 0.1;
return;
}
+ // delete the previous controller, otherwise changing movement midway is glitchy
+ if (this.move_controller != NULL)
+ {
+ delete(this.move_controller);
+ }
controller = new(SUB_CalcMove_controller);
controller.owner = this;
+ this.move_controller = controller;
controller.platmovetype = this.platmovetype;
controller.platmovetype_start = this.platmovetype_start;
controller.platmovetype_end = this.platmovetype_end;
- SUB_CalcMove_controller_setbezier(controller, this.SUB_ORIGIN, tcontrol, tdest);
+ SUB_CalcMove_controller_setbezier(controller, this.origin, tcontrol, tdest);
controller.finaldest = (tdest + '0 0 0.125'); // where do we want to end? Offset to overshoot a bit.
controller.animstate_starttime = time;
controller.animstate_endtime = time + traveltime;
setthink(controller, SUB_CalcMove_controller_think);
- controller.think1 = SUB_THUNK(this);
+ controller.think1 = getthink(this);
// the thinking is now done by the controller
- SUB_THINK(this, SUB_NullThink); // for PushMove
- this.SUB_NEXTTHINK = this.SUB_LTIME + traveltime;
+ setthink(this, SUB_NullThink); // for PushMove
+ this.nextthink = this.ltime + traveltime;
// invoke controller
getthink(controller)(controller);
this.think1 = func;
this.finaldest = tdest;
- SUB_THINK(this, SUB_CalcMoveDone);
+ setthink(this, SUB_CalcMoveDone);
- if (tdest == this.SUB_ORIGIN)
+ if (tdest == this.origin)
{
- this.SUB_VELOCITY = '0 0 0';
- this.SUB_NEXTTHINK = this.SUB_LTIME + 0.1;
+ this.velocity = '0 0 0';
+ this.nextthink = this.ltime + 0.1;
return;
}
- delta = tdest - this.SUB_ORIGIN;
+ delta = tdest - this.origin;
switch(tspeedtype)
{
// The only currently implemented alternative movement is linear (value 1)
if (traveltime < 0.15 || (this.platmovetype_start == 1 && this.platmovetype_end == 1)) // is this correct?
{
- this.SUB_VELOCITY = delta * (1/traveltime); // QuakeC doesn't allow vector/float division
- this.SUB_NEXTTHINK = this.SUB_LTIME + traveltime;
+ this.velocity = delta * (1/traveltime); // QuakeC doesn't allow vector/float division
+ this.nextthink = this.ltime + traveltime;
return;
}
// now just run like a bezier curve...
- SUB_CalcMove_Bezier(this, (this.SUB_ORIGIN + tdest) * 0.5, tdest, tspeedtype, tspeed, func);
+ SUB_CalcMove_Bezier(this, (this.origin + tdest) * 0.5, tdest, tspeedtype, tspeed, func);
}
void SUB_CalcMoveEnt (entity ent, vector tdest, float tspeedtype, float tspeed, void(entity this) func)
=============
SUB_CalcAngleMove
-calculate this.SUB_AVELOCITY and this.SUB_NEXTTHINK to reach destangle from
+calculate this.avelocity and this.nextthink to reach destangle from
this.angles rotating
-The calling function should make sure this.SUB_THINK is valid
+The calling function should make sure this.setthink is valid
===============
*/
void SUB_CalcAngleMoveDone(entity this)
{
// After rotating, set angle to exact final angle
this.angles = this.finalangle;
- this.SUB_AVELOCITY = '0 0 0';
- this.SUB_NEXTTHINK = -1;
- if (this.think1)
+ this.avelocity = '0 0 0';
+ this.nextthink = -1;
+ if (this.think1 && this.think1 != SUB_CalcAngleMoveDone) // avoid endless loops
this.think1 (this);
}
// FIXME: I fixed this function only for rotation around the main axes
void SUB_CalcAngleMove (entity this, vector destangle, float tspeedtype, float tspeed, void(entity this) func)
{
- vector delta;
- float traveltime;
-
if (!tspeed)
objerror (this, "No speed is defined!");
this.angles_x -= 360 * floor((this.angles_x - destangle_x) / 360 + 0.5);
this.angles_y -= 360 * floor((this.angles_y - destangle_y) / 360 + 0.5);
this.angles_z -= 360 * floor((this.angles_z - destangle_z) / 360 + 0.5);
- delta = destangle - this.angles;
+ vector delta = destangle - this.angles;
+ float traveltime;
switch(tspeedtype)
{
this.think1 = func;
this.finalangle = destangle;
- SUB_THINK(this, SUB_CalcAngleMoveDone);
+ setthink(this, SUB_CalcAngleMoveDone);
if (traveltime < 0.1)
{
- this.SUB_AVELOCITY = '0 0 0';
- this.SUB_NEXTTHINK = this.SUB_LTIME + 0.1;
+ this.avelocity = '0 0 0';
+ this.nextthink = this.ltime + 0.1;
return;
}
- this.SUB_AVELOCITY = delta * (1 / traveltime);
- this.SUB_NEXTTHINK = this.SUB_LTIME + traveltime;
+ this.avelocity = delta * (1 / traveltime);
+ this.nextthink = this.ltime + traveltime;
}
void SUB_CalcAngleMoveEnt (entity ent, vector destangle, float tspeedtype, float tspeed, void(entity this) func)