float SUB_True() { return 1; }
float SUB_False() { return 0; }
-void(vector destangle, float tspeed, void() func) SUB_CalcAngleMove;
void() SUB_CalcMoveDone;
void() SUB_CalcAngleMoveDone;
//void() SUB_UseTargets;
controller.destvec2 = '0 0 0';
}
-void SUB_CalcMove_Bezier (vector tcontrol, vector tdest, float tspeed, void() func)
+float TSPEED_TIME = -1;
+float TSPEED_LINEAR = 0;
+float TSPEED_START = 1;
+float TSPEED_END = 2;
+// TODO average too?
+
+void SUB_CalcMove_Bezier (vector tcontrol, vector tdest, float tspeedtype, float tspeed, void() func)
{
float traveltime;
entity controller;
self.finaldest = tdest;
self.think = SUB_CalcMoveDone;
- if(tspeed > 0) // positive: start speed
- traveltime = 2 * vlen(tcontrol - self.origin) / tspeed;
- else // negative: end speed
- traveltime = 2 * vlen(tcontrol - tdest) / -tspeed;
+ switch(tspeedtype)
+ {
+ default:
+ case TSPEED_START:
+ traveltime = 2 * vlen(tcontrol - self.origin) / tspeed;
+ break;
+ case TSPEED_END:
+ traveltime = 2 * vlen(tcontrol - tdest) / tspeed;
+ break;
+ case TSPEED_LINEAR:
+ traveltime = vlen(tdest - self.origin) / tspeed;
+ break;
+ case TSPEED_TIME:
+ traveltime = tspeed;
+ break;
+ }
if (traveltime < 0.1) // useless anim
{
self = self.owner;
}
-void SUB_CalcMove (vector tdest, float tspeed, void() func)
+void SUB_CalcMove (vector tdest, float tspeedtype, float tspeed, void() func)
{
vector delta;
float traveltime;
}
delta = tdest - self.origin;
- traveltime = vlen (delta) / tspeed;
+
+ switch(tspeedtype)
+ {
+ default:
+ case TSPEED_START:
+ case TSPEED_END:
+ case TSPEED_LINEAR:
+ traveltime = vlen (delta) / tspeed;
+ break;
+ case TSPEED_TIME:
+ traveltime = tspeed;
+ break;
+ }
// Very short animations don't really show off the effect
// of controlled animation, so let's just use linear movement.
}
// now just run like a bezier curve...
- SUB_CalcMove_Bezier((self.origin + tdest) * 0.5, tdest, tspeed, func);
+ SUB_CalcMove_Bezier((self.origin + tdest) * 0.5, tdest, tspeedtype, tspeed, func);
}
-void SUB_CalcMoveEnt (entity ent, vector tdest, float tspeed, void() func)
+void SUB_CalcMoveEnt (entity ent, vector tdest, float tspeedtype, float tspeed, void() func)
{
entity oldself;
oldself = self;
self = ent;
- SUB_CalcMove (tdest, tspeed, func);
+ SUB_CalcMove (tdest, tspeedtype, tspeed, func);
self = oldself;
}
}
// FIXME: I fixed this function only for rotation around the main axes
-void SUB_CalcAngleMove (vector destangle, float tspeed, void() func)
+void SUB_CalcAngleMove (vector destangle, float tspeedtype, float tspeed, void() func)
{
vector delta;
float traveltime;
self.angles_y -= 360 * floor((self.angles_y - destangle_y) / 360 + 0.5);
self.angles_z -= 360 * floor((self.angles_z - destangle_z) / 360 + 0.5);
delta = destangle - self.angles;
- traveltime = vlen (delta) / tspeed;
+
+ switch(tspeedtype)
+ {
+ default:
+ case TSPEED_START:
+ case TSPEED_END:
+ case TSPEED_LINEAR:
+ traveltime = vlen (delta) / tspeed;
+ break;
+ case TSPEED_TIME:
+ traveltime = tspeed;
+ break;
+ }
self.think1 = func;
self.finalangle = destangle;
self.nextthink = self.ltime + traveltime;
}
-void SUB_CalcAngleMoveEnt (entity ent, vector destangle, float tspeed, void() func)
+void SUB_CalcAngleMoveEnt (entity ent, vector destangle, float tspeedtype, float tspeed, void() func)
{
entity oldself;
oldself = self;
self = ent;
- SUB_CalcAngleMove (destangle, tspeed, func);
+ SUB_CalcAngleMove (destangle, tspeedtype, tspeed, func);
self = oldself;
}
{
sound (self, CH_TRIGGER_SINGLE, self.noise, VOL_BASE, ATTN_NORM);
self.state = 3;
- SUB_CalcMove (self.pos2, self.speed, plat_hit_bottom);
+ SUB_CalcMove (self.pos2, TSPEED_LINEAR, self.speed, plat_hit_bottom);
}
void plat_go_up()
{
sound (self, CH_TRIGGER_SINGLE, self.noise, VOL_BASE, ATTN_NORM);
self.state = 4;
- SUB_CalcMove (self.pos1, self.speed, plat_hit_top);
+ SUB_CalcMove (self.pos1, TSPEED_LINEAR, self.speed, plat_hit_top);
}
void plat_center_touch()
{
entity targ;
targ = find(world, targetname, self.target);
- SUB_CalcAngleMove(targ.origin, self.ltime + self.wait, train_wait);
+ SUB_CalcAngleMove(targ.origin, TSPEED_TIME, self.ltime + self.wait, train_wait);
self.train_wait_turning = TRUE;
return;
}
if (targ.speed)
{
if (self.spawnflags & 1)
- SUB_CalcMove_Bezier(cp_org, targ.origin - self.mins, targ.speed, train_wait);
+ SUB_CalcMove_Bezier(cp_org, targ.origin - self.mins, TSPEED_LINEAR, targ.speed, train_wait);
else
- SUB_CalcMove(targ.origin - self.mins, targ.speed, train_wait);
+ SUB_CalcMove(targ.origin - self.mins, TSPEED_LINEAR, targ.speed, train_wait);
}
else
{
if (self.spawnflags & 1)
- SUB_CalcMove_Bezier(cp_org, targ.origin - self.mins, self.speed, train_wait);
+ SUB_CalcMove_Bezier(cp_org, targ.origin - self.mins, TSPEED_LINEAR, self.speed, train_wait);
else
- SUB_CalcMove(targ.origin - self.mins, self.speed, train_wait);
+ SUB_CalcMove(targ.origin - self.mins, TSPEED_LINEAR, self.speed, train_wait);
}
if(self.noise != "")
void button_return()
{
self.state = STATE_DOWN;
- SUB_CalcMove (self.pos1, self.speed, button_done);
+ SUB_CalcMove (self.pos1, TSPEED_LINEAR, self.speed, button_done);
self.frame = 0; // use normal textures
if (self.health)
self.takedamage = DAMAGE_YES; // can be shot again
sound (self, CH_TRIGGER, self.noise, VOL_BASE, ATTN_NORM);
self.state = STATE_UP;
- SUB_CalcMove (self.pos2, self.speed, button_wait);
+ SUB_CalcMove (self.pos2, TSPEED_LINEAR, self.speed, button_wait);
}
void button_reset()
}
self.state = STATE_DOWN;
- SUB_CalcMove (self.pos1, self.speed, door_hit_bottom);
+ SUB_CalcMove (self.pos1, TSPEED_LINEAR, self.speed, door_hit_bottom);
}
void door_go_up()
if (self.noise2 != "")
sound (self, CH_TRIGGER_SINGLE, self.noise2, VOL_BASE, ATTN_NORM);
self.state = STATE_UP;
- SUB_CalcMove (self.pos2, self.speed, door_hit_top);
+ SUB_CalcMove (self.pos2, TSPEED_LINEAR, self.speed, door_hit_top);
string oldmessage;
oldmessage = self.message;
}
self.state = STATE_DOWN;
- SUB_CalcAngleMove (self.pos1, self.speed, door_rotating_hit_bottom);
+ SUB_CalcAngleMove (self.pos1, TSPEED_LINEAR, self.speed, door_rotating_hit_bottom);
}
void door_rotating_go_up()
if (self.noise2 != "")
sound (self, CH_TRIGGER_SINGLE, self.noise2, VOL_BASE, ATTN_NORM);
self.state = STATE_UP;
- SUB_CalcAngleMove (self.pos2, self.speed, door_rotating_hit_top);
+ SUB_CalcAngleMove (self.pos2, TSPEED_LINEAR, self.speed, door_rotating_hit_top);
string oldmessage;
oldmessage = self.message;
self.dest1 = self.origin + v_right * (self.t_width * temp);
self.dest2 = self.dest1 + v_forward * self.t_length;
- SUB_CalcMove(self.dest1, self.speed, fd_secret_move1);
+ SUB_CalcMove(self.dest1, TSPEED_LINEAR, self.speed, fd_secret_move1);
if (self.noise2 != "")
sound(self, CH_TRIGGER_SINGLE, self.noise2, VOL_BASE, ATTN_NORM);
}
{
if (self.noise2 != "")
sound(self, CH_TRIGGER_SINGLE, self.noise2, VOL_BASE, ATTN_NORM);
- SUB_CalcMove(self.dest2, self.speed, fd_secret_move3);
+ SUB_CalcMove(self.dest2, TSPEED_LINEAR, self.speed, fd_secret_move3);
}
// Wait here until time to go back...
{
if (self.noise2 != "")
sound(self, CH_TRIGGER_SINGLE, self.noise2, VOL_BASE, ATTN_NORM);
- SUB_CalcMove(self.dest1, self.speed, fd_secret_move5);
+ SUB_CalcMove(self.dest1, TSPEED_LINEAR, self.speed, fd_secret_move5);
}
// Wait 1 second...
{
if (self.noise2 != "")
sound(self, CH_TRIGGER_SINGLE, self.noise2, VOL_BASE, ATTN_NORM);
- SUB_CalcMove(self.oldorigin, self.speed, fd_secret_done);
+ SUB_CalcMove(self.oldorigin, TSPEED_LINEAR, self.speed, fd_secret_done);
}
void fd_secret_done()