]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/server/gamec/t_jumppads.c
removing this makefile also
[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         {
27                 local float i;
28                 local float found;
29                 sound (other, CHAN_ITEM, "misc/jumppad.ogg", 1, ATTN_NORM);
30                 found = FALSE;
31                 for(i = 0; i < other.jumppadcount && i < NUM_JUMPPADSUSED; ++i)
32                         if(other.(jumppadsused[i]) == self)
33                                 found = TRUE;
34                 if(!found)
35                 {
36                         other.(jumppadsused[math_mod(other.jumppadcount, NUM_JUMPPADSUSED)]) = self;
37                         other.jumppadcount = other.jumppadcount + 1;
38                 }
39         }
40
41         // figure out how long it will take to hit the point considering gravity
42         grav = cvar("sv_gravity");
43         flighttime = sqrt((self.enemy.origin_z - org_z) / (0.5 * grav));
44         if (!flighttime)
45                 return;
46
47         // how far in X and Y to move
48         self.movedir = (self.enemy.origin - org);
49         self.movedir_z = 0;
50         dist = vlen(self.movedir);
51
52         // finally calculate the velocity
53         self.movedir = normalize(self.movedir) * (dist / flighttime);
54         self.movedir_z = flighttime * grav;
55
56         other.flags = other.flags - (other.flags & FL_ONGROUND);
57         // reset tracking of oldvelocity for impact damage (sudden velocity changes)
58         other.oldvelocity = other.velocity = self.movedir;
59         // reset tracking of who pushed you into a hazard (for kill credit)
60         other.pushltime = 0;
61
62         if (other.classname == "missile")
63                 other.angles = vectoangles (other.velocity);
64
65         if (self.spawnflags & PUSH_ONCE)
66         {
67                 self.touch = SUB_Null;
68                 self.think = SUB_Remove;
69                 self.nextthink = time;
70         }
71 };
72
73 .vector dest;
74
75 void() trigger_push_findtarget =
76 {
77         local entity e;
78         local float grav;
79         local float flighttime;
80         local float dist;
81         local vector org;
82
83         // first calculate a typical start point for the jump
84         org = (self.absmin + self.absmax) * 0.5;
85         org_z = self.absmax_z - PL_MIN_z;
86
87         if (self.target)
88         {
89                 // find the target
90                 self.enemy = find(world, targetname, self.target);
91                 if (!self.enemy)
92                 {
93                         objerror("trigger_push: target not found\n");
94                         remove(self);
95                         return;
96                 }
97
98                 // figure out how long it will take to hit the point considering gravity
99                 grav = cvar("sv_gravity");
100                 flighttime = sqrt((self.enemy.origin_z - org_z) / (0.5 * grav));
101                 if (!flighttime)
102                 {
103                         objerror("trigger_push: jump pad with bad destination\n");
104                         remove(self);
105                         return;
106                 }
107
108                 // how far in X and Y to move
109                 self.movedir = (self.enemy.origin - org);
110                 self.movedir_z = 0;
111                 dist = vlen(self.movedir);
112
113                 // finally calculate the velocity
114                 self.movedir = normalize(self.movedir) * (dist / flighttime);
115                 self.movedir_z = flighttime * grav;
116         }
117         else
118                 flighttime = 0;
119
120         // calculate the destination and spawn a teleporter waypoint
121         e = spawn();
122         setorigin(e, org);
123         setsize(e, PL_MIN, PL_MAX);
124         e.velocity = self.movedir;
125         tracetoss(e, e);
126         self.dest = trace_endpos;
127         remove(e);
128
129         waypoint_spawnforteleporter(self, self.dest, flighttime);
130 };
131
132 void() trigger_push =
133 {
134         if (self.angles != '0 0 0')
135                 SetMovedir ();
136
137         self.solid = SOLID_TRIGGER;
138         setmodel (self, self.model);
139         self.movetype = MOVETYPE_NONE;
140         self.modelindex = 0;
141         self.model = "";
142
143         self.touch = trigger_push_touch;
144
145         // normal push setup
146         if (!self.speed)
147                 self.speed = 1000;
148         self.movedir = self.movedir * self.speed * 10;
149
150         // this must be called to spawn the teleport waypoints for bots
151         self.think = trigger_push_findtarget;
152         self.nextthink = time + 0.2;
153 };
154
155 void() target_push = {};
156 void() info_notnull = {};
157 void() target_position = {};