]> git.xonotic.org Git - voretournament/voretournament.git/blob - data/qcsrc/server/t_teleporters.qc
Lastly, show portraits when they need to be shown, and sent the right player. Current...
[voretournament/voretournament.git] / data / qcsrc / server / t_teleporters.qc
1 void trigger_teleport_use()\r
2 {\r
3         if(teams_matter)\r
4                 self.team = activator.team;\r
5 }\r
6 \r
7 #define TDEATHLOOP(o) \\r
8         entity head; \\r
9         vector deathmin; \\r
10         vector deathmax; \\r
11         float deathradius; \\r
12         deathmin = (o) + player.mins; \\r
13         deathmax = (o) + player.maxs; \\r
14         if(telefragmin != telefragmax) \\r
15         { \\r
16                 if(deathmin_x > telefragmin_x) deathmin_x = telefragmin_x; \\r
17                 if(deathmin_y > telefragmin_y) deathmin_y = telefragmin_y; \\r
18                 if(deathmin_z > telefragmin_z) deathmin_z = telefragmin_z; \\r
19                 if(deathmax_x < telefragmax_x) deathmax_x = telefragmax_x; \\r
20                 if(deathmax_y < telefragmax_y) deathmax_y = telefragmax_y; \\r
21                 if(deathmax_z < telefragmax_z) deathmax_z = telefragmax_z; \\r
22         } \\r
23         deathradius = max(vlen(deathmin), vlen(deathmax)); \\r
24         for(head = findradius(o, deathradius); head; head = head.chain) \\r
25                 if(head != player) \\r
26                         if(head.takedamage) \\r
27                                 if(boxesoverlap(deathmin, deathmax, head.absmin, head.absmax))\r
28 \r
29 float check_tdeath(entity player, vector org, vector telefragmin, vector telefragmax)\r
30 {\r
31         TDEATHLOOP(org)\r
32         {\r
33                 if ((player.classname == "player") && (player.health >= 1))\r
34                 {\r
35                         if(head.classname == "player")\r
36                                 if(head.health >= 1)\r
37                                         return 1;\r
38                 }\r
39         }\r
40         return 0;\r
41 }\r
42 float tdeath_hit;\r
43 void tdeath(entity player, entity teleporter, entity telefragger, vector telefragmin, vector telefragmax)\r
44 {\r
45         tdeath_hit += 0; // dummy for compiler warning\r
46         TDEATHLOOP(player.origin)\r
47         {\r
48                 if ((player.classname == "player") && (player.health >= 1))\r
49                 {\r
50                         if(head.classname == "player")\r
51                                 if(head.health >= 1)\r
52                                         ++tdeath_hit;\r
53                         Damage (head, teleporter, telefragger, 10000, DEATH_TELEFRAG, head.origin, '0 0 0');\r
54                 }\r
55                 else if (telefragger.health < 1) // corpses gib\r
56                         Damage (head, teleporter, telefragger, 10000, DEATH_TELEFRAG, head.origin, '0 0 0');\r
57                 else // dead bodies and monsters gib themselves instead of telefragging\r
58                         Damage (telefragger, teleporter, telefragger, 10000, DEATH_TELEFRAG, telefragger.origin, '0 0 0');\r
59         }\r
60 }\r
61 \r
62 void spawn_tdeath(vector v0, entity e, vector v)\r
63 {\r
64         tdeath(e, e, e, '0 0 0', '0 0 0');\r
65 }\r
66 \r
67 .entity pusher;\r
68 #define TELEPORT_FLAG_SOUND 1\r
69 #define TELEPORT_FLAG_PARTICLES 2\r
70 #define TELEPORT_FLAG_TDEATH 4\r
71 \r
72 #define TELEPORT_FLAGS_WARPZONE   0\r
73 #define TELEPORT_FLAGS_PORTAL     (TELEPORT_FLAG_SOUND | TELEPORT_FLAG_PARTICLES)\r
74 #define TELEPORT_FLAGS_TELEPORTER (TELEPORT_FLAG_SOUND | TELEPORT_FLAG_PARTICLES | TELEPORT_FLAG_TDEATH)\r
75 void TeleportPlayer(entity teleporter, entity player, vector to, vector to_angles, vector to_velocity, vector telefragmin, vector telefragmax, float tflags)\r
76 {\r
77         entity oldself;\r
78         entity telefragger;\r
79         vector from;\r
80 \r
81         if(teleporter.owner)\r
82                 telefragger = teleporter.owner;\r
83         else\r
84                 telefragger = player;\r
85 \r
86         makevectors (to_angles);\r
87 \r
88         if(self.pushltime < time) // only show one teleport effect per teleporter per 0.2 seconds, for better fps\r
89         {\r
90                 if(tflags & TELEPORT_FLAG_SOUND)\r
91                         sound (player, CHAN_TRIGGER, "misc/teleport.wav", VOL_BASE, ATTN_NORM);\r
92                 if(tflags & TELEPORT_FLAG_PARTICLES)\r
93                 {\r
94                         pointparticles(particleeffectnum("teleport"), player.origin, '0 0 0', 1);\r
95                         pointparticles(particleeffectnum("teleport"), to + v_forward * 32, '0 0 0', 1);\r
96                 }\r
97                 self.pushltime = time + 0.2;\r
98         }\r
99 \r
100         // Relocate the player\r
101         // assuming to allows PL_MIN to PL_MAX box and some more\r
102         from = player.origin;\r
103         setorigin (player, to);\r
104         player.oldorigin = to; // don't undo the teleport by unsticking\r
105         player.angles = to_angles;\r
106         player.fixangle = TRUE;\r
107         player.velocity = to_velocity;\r
108         BITXOR_ASSIGN(player.effects, EF_TELEPORT_BIT);\r
109 \r
110         UpdateCSQCProjectileAfterTeleport(player);\r
111 \r
112         if(player.classname == "player")\r
113         {\r
114                 if(tflags & TELEPORT_FLAG_TDEATH)\r
115                         if(player.takedamage && player.deadflag == DEAD_NO && !g_race && !g_cts && cvar("g_telefrags"))\r
116                                 tdeath(player, teleporter, telefragger, telefragmin, telefragmax);\r
117 \r
118                 // player no longer is on ground\r
119                 player.flags &~= FL_ONGROUND;\r
120 \r
121                 // reset tracking of oldvelocity for impact damage (sudden velocity changes)\r
122                 player.oldvelocity = player.velocity;\r
123 \r
124                 // reset tracking of who pushed you into a hazard (for kill credit)\r
125                 if(teleporter.owner)\r
126                 {\r
127                         player.pusher = teleporter.owner;\r
128                         player.pushltime = time + cvar("g_maxpushtime");\r
129                 }\r
130                 else\r
131                 {\r
132                         player.pushltime = 0;\r
133                 }\r
134 \r
135                 player.lastteleporttime = time;\r
136 \r
137                 // stop player name display\r
138                 {\r
139                         oldself = self;\r
140                         self = player;\r
141                         ClearSelectedPlayer();\r
142                         self = oldself;\r
143                 }\r
144         }\r
145 }\r
146 \r
147 void Teleport_Touch (void)\r
148 {\r
149         entity oldself, e;\r
150         vector o;\r
151         float p;\r
152 \r
153         if (other.health < 1)\r
154                 return;\r
155         if not(other.flags & FL_CLIENT) // FIXME: Make missiles firable through the teleport too\r
156                 return;\r
157 \r
158         if(self.team)\r
159                 if((self.spawnflags & 4 == 0) == (self.team != other.team))\r
160                         return;\r
161 \r
162         EXACTTRIGGER_TOUCH;\r
163 \r
164         makevectors(self.enemy.mangle);\r
165 \r
166         if(other.classname == "player")\r
167                 RemoveGrabber(other);\r
168         \r
169         if(self.enemy)\r
170         {\r
171                 e = self.enemy;\r
172         }\r
173         else\r
174         {\r
175                 RandomSelection_Init();\r
176                 for(e = world; (e = find(e, targetname, self.target)); )\r
177                 {\r
178                         p = 1;\r
179                         if(cvar("g_telefrags_avoid"))\r
180                         {\r
181                                 o = e.origin + '0 0 1' * (1 - other.mins_z - 24);\r
182                                 if(check_tdeath(other, o, '0 0 0', '0 0 0'))\r
183                                         p = 0;\r
184                         }\r
185                         if(e.cnt)\r
186                                 RandomSelection_Add(e, 0, string_null, e.cnt, p);\r
187                         else\r
188                                 RandomSelection_Add(e, 0, string_null, 1, p);\r
189                 }\r
190                 e = RandomSelection_chosen_ent;\r
191         }\r
192 \r
193         if(!e)\r
194         {\r
195                 sprint(other, "Teleport destination vanished. Sorry... please complain to the mapper.\n");\r
196         }\r
197 \r
198         if(e.speed)\r
199                 if(vlen(other.velocity) > e.speed)\r
200                         other.velocity = normalize(other.velocity) * max(0, e.speed);\r
201         if(cvar("g_teleport_maxspeed"))\r
202                 if(vlen(other.velocity) > cvar("g_teleport_maxspeed"))\r
203                         other.velocity = normalize(other.velocity) * max(0, cvar("g_teleport_maxspeed"));\r
204 \r
205         o = e.origin + '0 0 1' * (1 - other.mins_z - 24);\r
206         TeleportPlayer(self, other, o, e.mangle, v_forward * vlen(other.velocity), '0 0 0', '0 0 0', TELEPORT_FLAGS_TELEPORTER);\r
207 \r
208         if(e.target)\r
209         {\r
210                 oldself = self;\r
211                 activator = other;\r
212                 self = e;\r
213                 SUB_UseTargets();\r
214                 self = oldself;\r
215         }\r
216 }\r
217 \r
218 void spawnfunc_info_teleport_destination (void)\r
219 {\r
220         self.classname = "info_teleport_destination";\r
221 \r
222         self.mangle = self.angles;\r
223         self.angles = '0 0 0';\r
224 \r
225         //setorigin (self, self.origin + '0 0 27');     // To fix a mappers' habit as old as Quake\r
226         setorigin (self, self.origin);\r
227 \r
228         IFTARGETED\r
229         {\r
230         }\r
231         else\r
232                 objerror ("^3Teleport destination without a targetname");\r
233 }\r
234 \r
235 void spawnfunc_misc_teleporter_dest (void)\r
236 {\r
237         spawnfunc_info_teleport_destination();\r
238 }\r
239 \r
240 void spawnfunc_target_teleporter (void)\r
241 {\r
242         spawnfunc_info_teleport_destination();\r
243 }\r
244 \r
245 void teleport_findtarget (void)\r
246 {\r
247         entity e;\r
248         float n;\r
249 \r
250         RandomSelection_Init();\r
251         n = 0;\r
252         for(e = world; (e = find(e, targetname, self.target)); )\r
253         {\r
254                 ++n;\r
255                 if(e.movetype == MOVETYPE_NONE)\r
256                         RandomSelection_Add(e, 0, string_null, 1, 1);\r
257                 if(e.classname != "info_teleport_destination")\r
258                         print("^3MAPPER ERROR: teleporter does target an invalid teleport destination entity. Angles will not work.\n");\r
259         }\r
260         if(RandomSelection_chosen_ent)\r
261                 waypoint_spawnforteleporter(self, RandomSelection_chosen_ent.origin, 0);\r
262 \r
263         if(n == 0)\r
264         {\r
265                 // no dest!\r
266                 objerror ("Teleporter with nonexistant target");\r
267                 return;\r
268         }\r
269         else if(n == 1)\r
270         {\r
271                 // exactly one dest - bots love that\r
272                 self.enemy = find(e, targetname, self.target);\r
273                 self.dest = self.enemy.origin;\r
274         }\r
275         else\r
276         {\r
277                 // have to use random selection every single time\r
278                 self.enemy = world;\r
279         }\r
280 \r
281         // now enable touch\r
282         self.touch = Teleport_Touch;\r
283 }\r
284 \r
285 void spawnfunc_trigger_teleport (void)\r
286 {\r
287         self.angles = '0 0 0';\r
288 \r
289         EXACTTRIGGER_INIT;\r
290 \r
291         self.use = trigger_teleport_use;\r
292 \r
293         // this must be called to spawn the teleport waypoints for bots\r
294         InitializeEntity(self, teleport_findtarget, INITPRIO_FINDTARGET);\r
295 \r
296         if (!self.target)\r
297         {\r
298                 objerror ("Teleporter with no target");\r
299                 return;\r
300         }\r
301 }\r
302 \r
303 void WarpZone_PostTeleportPlayer_Callback(entity pl)\r
304 {\r
305         UpdateCSQCProjectileAfterTeleport(pl);\r
306         if(pl.classname == "player")\r
307         {\r
308                 // reset tracking of oldvelocity for impact damage (sudden velocity changes)\r
309                 pl.oldvelocity = pl.velocity;\r
310                 // reset teleport time tracking too (or multijump can cause insane speeds)\r
311                 pl.lastteleporttime = time;\r
312         }\r
313 }\r