]> icculus.org git repositories - divverent/nexuiz.git/blob - qcsrc/jumppads.qc
info_notnull and target_position fix?
[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         // where the center is
14         //org = (self.absmin + self.absmax) * 0.5;
15         org = other.origin;
16
17         // figure out how long it will take to hit the point considering gravity
18         grav = cvar("sv_gravity");
19         flighttime = sqrt((self.enemy.origin_z - org_z) / (0.5 * grav));
20         //if (!flighttime)
21         //{
22         //      remove(self);
23         //      return;
24         //}
25
26         // how far in X and Y to move
27         self.movedir = (self.enemy.origin - org);
28         self.movedir_z = 0;
29         dist = vlen(self.movedir);
30
31         // finally calculate the velocity
32         self.movedir = normalize(self.movedir) * (dist / flighttime);
33         self.movedir_z = flighttime * grav;
34
35         other.velocity = self.movedir;
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 /*QUAKED trigger_push (.5 .5 .5) ? PUSH_ONCE SILENT
54 Improved version of normal trigger_push.
55
56 Pushes anything that touches it,
57 or acts as a jump pad, hitting "target"
58 at the apogee (peak) of the jump.
59
60 Target should be an info_notnull.
61
62 Flags:
63 "PUSH_ONCE" - removes itself after push
64 "SILENT" - no 'windtunnel' noise
65 Keys:
66 "target" - acts as jump pad, hits this entity
67 */
68
69 void() SetMovedir =
70 {
71         if (self.angles == '0 -1 0')
72                 self.movedir = '0 0 1';
73         else if (self.angles == '0 -2 0')
74                 self.movedir = '0 0 -1';
75         else
76         {
77                 makevectors (self.angles);
78                 self.movedir = v_forward;
79         }
80         
81         self.angles = '0 0 0';
82 };
83
84 void() trigger_push =
85 {
86         if (self.angles != '0 0 0')
87                 SetMovedir ();
88
89         self.solid = SOLID_TRIGGER;
90         setmodel (self, self.model);
91         self.movetype = MOVETYPE_NONE;
92         self.modelindex = 0;
93         self.model = "";
94
95         // normal push setup
96         if (!self.speed)
97                 self.speed = 1000;
98         self.movedir = self.movedir * self.speed * 10;
99
100         self.touch = trigger_push_touch;
101
102         // check if this is a jump pad
103         if (self.target)
104         {
105                 self.think = trigger_push_findtarget;
106                 self.nextthink = time + 0.2;
107         }
108 };
109
110
111 void() target_push =
112 {
113         trigger_push();
114 };
115
116 void() info_notnull = {};
117 void() info_targetposition = {};