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