]> icculus.org git repositories - divverent/nexuiz.git/blob - qcsrc/jumppads.qc
Fixed two minor bugs.
[divverent/nexuiz.git] / qcsrc / jumppads.qc
1 float PUSH_ONCE                 = 1;
2 float PUSH_SILENT               = 2;
3
4 // TODO: add sounds
5 void() trigger_push_touch =
6 {
7         local float flighttime, dist, grav;
8         local vector org;
9
10         if (!other.health)
11                 return;
12
13         org = other.origin;
14
15         // figure out how long it will take to hit the point considering gravity
16         grav = cvar("sv_gravity");
17         flighttime = sqrt((self.enemy.origin_z - org_z) / (0.5 * grav));
18         if (!flighttime)
19                 return;
20
21         // how far in X and Y to move
22         self.movedir = (self.enemy.origin - org);
23         self.movedir_z = 0;
24         dist = vlen(self.movedir);
25
26         // finally calculate the velocity
27         self.movedir = normalize(self.movedir) * (dist / flighttime);
28         self.movedir_z = flighttime * grav;
29
30         other.velocity = self.movedir;
31         other.flags = other.flags - (other.flags & FL_ONGROUND);
32
33         if (self.spawnflags & PUSH_ONCE)
34         {
35                 self.touch = SUB_Null;
36                 self.think = SUB_Remove;
37                 self.nextthink = time;
38         }
39 };
40
41 void() trigger_push_findtarget =
42 {
43         // find the target
44         self.enemy = find(world, targetname, self.target);
45         if (!self.enemy)
46                 objerror("trigger_push: target not found\n");
47 };
48
49 void() trigger_push =
50 {
51         if (self.angles != '0 0 0')
52                 SetMovedir ();
53
54         self.solid = SOLID_TRIGGER;
55         setmodel (self, self.model);
56         self.movetype = MOVETYPE_NONE;
57         self.modelindex = 0;
58         self.model = "";
59
60         self.touch = trigger_push_touch;
61
62         // check if this is a jump pad
63         if (self.target)
64         {
65                 self.think = trigger_push_findtarget;
66                 self.nextthink = time + 0.2;
67         }
68         else
69         {
70                 // normal push setup
71                 if (!self.speed)
72                         self.speed = 1000;
73                 self.movedir = self.movedir * self.speed * 10;
74         }
75 };
76
77 void() target_push = { trigger_push(); };
78 void() info_notnull = {};
79 void() target_position = {};