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