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