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