]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/server/t_teleporters.qc
reassign the sound channels in a more meaningful way (allows a global channel mixer...
[divverent/nexuiz.git] / data / qcsrc / server / t_teleporters.qc
1 void tdeath_touch()
2 {
3         if (other == self.owner)
4                 return;
5         // so teleporting shots etc can't telefrag
6         if (!self.owner.takedamage)
7                 return;
8         if (!other.takedamage)
9                 return;
10
11         if ((self.owner.classname == "player") && (self.owner.health >= 1))
12                 Damage (other, self, self.owner, 10000, DEATH_TELEFRAG, other.origin, '0 0 0');
13         else if (other.health < 1) // corpses gib
14                 Damage (other, self, self.owner, 10000, DEATH_TELEFRAG, other.origin, '0 0 0');
15         else // dead bodies and monsters gib themselves instead of telefragging
16                 Damage (self.owner, self, self.owner, 10000, DEATH_TELEFRAG, self.owner.origin, '0 0 0');
17 };
18
19 void tdeath_remove()
20 {
21         if (self.owner)
22         {
23                 self.owner.effects = self.owner.effects - (self.owner.effects & EF_NODRAW);
24                 if (self.owner.weaponentity)
25                         self.owner.weaponentity.flags = self.owner.weaponentity.flags - (self.owner.weaponentity.flags & FL_FLY);
26         }
27         remove(self);
28 }
29
30 // org2 is where they will return to if the teleport fails
31 void spawn_tdeath(vector org, entity death_owner, vector org2)
32 {
33         local entity death;
34
35         death = spawn();
36 //      death.classname = "teledeath";
37         death.movetype = MOVETYPE_NONE;
38         death.solid = SOLID_TRIGGER;
39         death.angles = '0 0 0';
40         death.dest2 = org2;
41         setsize (death, death_owner.mins - '1 1 1', death_owner.maxs + '1 1 1');
42         setorigin (death, org);
43         death.touch = tdeath_touch;
44         death.nextthink = time + 0.2;
45         death.think = tdeath_remove;
46         death.owner = death_owner;
47
48         // hide entity to avoid "ghosts" between teleporter and destination caused by clientside interpolation
49         death.owner.effects = death.owner.effects | EF_NODRAW;
50         if (death.owner.weaponentity) // misuse FL_FLY to avoid EF_NODRAW on viewmodel
51                 death.owner.weaponentity.flags = death.owner.weaponentity.flags | FL_FLY;
52
53         force_retouch = 2;              // make sure even still objects get hit
54 };
55
56 void Teleport_Touch (void)
57 {
58         entity head;
59
60         if (other.health < 1)
61                 return;
62         if (!other.flags & FL_CLIENT)   // FIXME: Make missiles firable through the teleport too
63                 return;
64
65         // Make teleport effect where the player left
66         sound (other, CHAN_ITEM, "misc/teleport.wav", VOL_BASE, ATTN_NORM);
67         pointparticles(particleeffectnum("teleport"), other.origin, '0 0 0', 1);
68
69         // Make teleport effect where the player arrived
70         sound (self.enemy, CHAN_ITEM, "misc/teleport.wav", VOL_BASE, ATTN_NORM);
71         makevectors (self.enemy.mangle);
72         pointparticles(particleeffectnum("teleport"), self.enemy.origin + v_forward * 32, '0 0 0', 1);
73
74         // Relocate the player
75         setorigin (other, self.enemy.origin + '0 0 1' * (1 - other.mins_z - 24));
76         other.angles = self.enemy.mangle;
77         other.fixangle = TRUE;
78         other.velocity = v_forward * vlen(other.velocity);
79
80         // Kill anyone else in the teleporter box (NO MORE TDEATH)
81         if(other.takedamage)
82         {
83                 vector deathmin;
84                 vector deathmax;
85                 float deathradius;
86                 deathmin = other.absmin;
87                 deathmax = other.absmax;
88                 deathradius = max(vlen(deathmin), vlen(deathmax));
89                 for(head = findradius(other.origin, deathradius); head; head = head.chain)
90                         if(head != other)
91                                 if(head.takedamage)
92                                         if(boxesoverlap(deathmin, deathmax, head.absmin, head.absmax))
93                                         {
94                                                 if ((other.classname == "player") && (other.health >= 1))
95                                                         Damage (head, self, other, 10000, DEATH_TELEFRAG, head.origin, '0 0 0');
96                                                 else if (other.health < 1) // corpses gib
97                                                         Damage (head, self, other, 10000, DEATH_TELEFRAG, head.origin, '0 0 0');
98                                                 else // dead bodies and monsters gib themselves instead of telefragging
99                                                         Damage (other, self, other, 10000, DEATH_TELEFRAG, other.origin, '0 0 0');
100                                         }
101         }
102
103         // hide myself a tic
104         other.effects = other.effects | EF_NODRAW;
105         if (other.weaponentity) // misuse FL_FLY to avoid EF_NODRAW on viewmodel
106                 other.weaponentity.flags = other.weaponentity.flags | FL_FLY;
107         other.teleport_time = time + cvar("sys_ticrate");
108
109         other.flags = other.flags - (other.flags & FL_ONGROUND);
110         // reset tracking of oldvelocity for impact damage (sudden velocity changes)
111         other.oldvelocity = other.velocity;
112         // reset tracking of who pushed you into a hazard (for kill credit)
113         other.pushltime = 0;
114
115         // stop player name display
116         {
117                 entity oldself;
118                 oldself = self;
119                 self = other;
120                 ClearSelectedPlayer();
121                 self = oldself;
122         }
123 }
124
125 void spawnfunc_info_teleport_destination (void)
126 {
127         self.mangle = self.angles;
128         self.angles = '0 0 0';
129
130         //setorigin (self, self.origin + '0 0 27');     // To fix a mappers' habit as old as Quake
131         setorigin (self, self.origin);
132
133         if (!self.targetname)
134                 objerror ("Teleport destination without a targetname");
135 }
136
137 void spawnfunc_misc_teleporter_dest (void)
138 {
139         spawnfunc_info_teleport_destination();
140 }
141
142 void spawnfunc_target_teleporter (void)
143 {
144         spawnfunc_info_teleport_destination();
145 }
146
147 void teleport_findtarget (void)
148 {
149         // now enable touch
150         self.touch = Teleport_Touch;
151
152         self.enemy = find (world, targetname, self.target);
153         if (!self.enemy)
154         {
155                 objerror ("Teleporter with nonexistant target");
156                 remove(self);
157                 return;
158         }
159
160         self.dest = self.enemy.origin;
161         waypoint_spawnforteleporter(self, self.dest, 0);
162 }
163
164 void spawnfunc_trigger_teleport (void)
165 {
166         self.angles = '0 0 0';
167
168         self.solid = SOLID_TRIGGER;
169         self.movetype = MOVETYPE_NONE;
170
171         setmodel (self, self.model); // no precision needed
172
173         self.model = "";
174         self.modelindex = 0;
175
176         self.think = teleport_findtarget;
177         self.nextthink = time + 0.2;
178
179         if (!self.target)
180                 objerror ("Teleporter with no target");
181 }