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