]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/server/gamec/t_jumppads.c
replaced mauvebot and urrebot with havocbot (Urre didn't want me to keep
[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 .vector dest;
61
62 void() trigger_push_findtarget =
63 {
64         local entity e;
65         local float grav;
66         local float flighttime;
67         local float dist;
68         local vector org;
69
70         // first calculate a typical start point for the jump
71         org = (self.absmin + self.absmax) * 0.5;
72         org_z = self.absmax_z - PL_MIN_z;
73
74         if (self.target)
75         {
76                 // find the target
77                 self.enemy = find(world, targetname, self.target);
78                 if (!self.enemy)
79                 {
80                         objerror("trigger_push: target not found\n");
81                         remove(self);
82                         return;
83                 }
84
85                 // figure out how long it will take to hit the point considering gravity
86                 grav = cvar("sv_gravity");
87                 flighttime = sqrt((self.enemy.origin_z - org_z) / (0.5 * grav));
88                 if (!flighttime)
89                 {
90                         objerror("trigger_push: jump pad with bad destination\n");
91                         remove(self);
92                         return;
93                 }
94
95                 // how far in X and Y to move
96                 self.movedir = (self.enemy.origin - org);
97                 self.movedir_z = 0;
98                 dist = vlen(self.movedir);
99
100                 // finally calculate the velocity
101                 self.movedir = normalize(self.movedir) * (dist / flighttime);
102                 self.movedir_z = flighttime * grav;
103         }
104         else
105                 flighttime = 0;
106
107         // calculate the destination and spawn a teleporter waypoint
108         e = spawn();
109         setorigin(e, org);
110         setsize(e, PL_MIN, PL_MAX);
111         e.velocity = self.movedir;
112         tracetoss(e, e);
113         self.dest = trace_endpos;
114         remove(e);
115
116         waypoint_spawnforteleporter(self, self.dest, flighttime);
117 };
118
119 void() trigger_push =
120 {
121         if (self.angles != '0 0 0')
122                 SetMovedir ();
123
124         self.solid = SOLID_TRIGGER;
125         setmodel (self, self.model);
126         self.movetype = MOVETYPE_NONE;
127         self.modelindex = 0;
128         self.model = "";
129
130         self.touch = trigger_push_touch;
131
132         // normal push setup
133         if (!self.speed)
134                 self.speed = 1000;
135         self.movedir = self.movedir * self.speed * 10;
136
137         // this must be called to spawn the teleport waypoints for bots
138         self.think = trigger_push_findtarget;
139         self.nextthink = time + 0.2;
140 };
141
142 void() target_push = {};
143 void() info_notnull = {};
144 void() target_position = {};