]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/server/t_teleporters.qc
make teleport sound as broken as before again :P
[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         sound (other, CHAN_TRIGGER, "misc/teleport.wav", VOL_BASE, ATTN_NORM);
66         pointparticles(particleeffectnum("teleport"), other.origin, '0 0 0', 1);
67
68         /*
69         // Make teleport effect where the player left
70         sound (self, CHAN_TRIGGER, "misc/teleport.wav", VOL_BASE, ATTN_NORM);
71         pointparticles(particleeffectnum("teleport"), other.origin, '0 0 0', 1);
72
73         // Make teleport effect where the player arrived
74         sound (self.enemy, CHAN_TRIGGER, "misc/teleport.wav", VOL_BASE, ATTN_NORM);
75         */
76
77         makevectors (self.enemy.mangle);
78         pointparticles(particleeffectnum("teleport"), self.enemy.origin + v_forward * 32, '0 0 0', 1);
79
80         // Relocate the player
81         setorigin (other, self.enemy.origin + '0 0 1' * (1 - other.mins_z - 24));
82         other.angles = self.enemy.mangle;
83         other.fixangle = TRUE;
84         other.velocity = v_forward * vlen(other.velocity);
85
86         // Kill anyone else in the teleporter box (NO MORE TDEATH)
87         if(other.takedamage)
88         {
89                 vector deathmin;
90                 vector deathmax;
91                 float deathradius;
92                 deathmin = other.absmin;
93                 deathmax = other.absmax;
94                 deathradius = max(vlen(deathmin), vlen(deathmax));
95                 for(head = findradius(other.origin, deathradius); head; head = head.chain)
96                         if(head != other)
97                                 if(head.takedamage)
98                                         if(boxesoverlap(deathmin, deathmax, head.absmin, head.absmax))
99                                         {
100                                                 if ((other.classname == "player") && (other.health >= 1))
101                                                         Damage (head, self, other, 10000, DEATH_TELEFRAG, head.origin, '0 0 0');
102                                                 else if (other.health < 1) // corpses gib
103                                                         Damage (head, self, other, 10000, DEATH_TELEFRAG, head.origin, '0 0 0');
104                                                 else // dead bodies and monsters gib themselves instead of telefragging
105                                                         Damage (other, self, other, 10000, DEATH_TELEFRAG, other.origin, '0 0 0');
106                                         }
107         }
108
109         // hide myself a tic
110         other.effects = other.effects | EF_NODRAW;
111         if (other.weaponentity) // misuse FL_FLY to avoid EF_NODRAW on viewmodel
112                 other.weaponentity.flags = other.weaponentity.flags | FL_FLY;
113         other.teleport_time = time + cvar("sys_ticrate");
114
115         other.flags = other.flags - (other.flags & FL_ONGROUND);
116         // reset tracking of oldvelocity for impact damage (sudden velocity changes)
117         other.oldvelocity = other.velocity;
118         // reset tracking of who pushed you into a hazard (for kill credit)
119         other.pushltime = 0;
120
121         // stop player name display
122         {
123                 entity oldself;
124                 oldself = self;
125                 self = other;
126                 ClearSelectedPlayer();
127                 self = oldself;
128         }
129 }
130
131 void spawnfunc_info_teleport_destination (void)
132 {
133         self.mangle = self.angles;
134         self.angles = '0 0 0';
135
136         //setorigin (self, self.origin + '0 0 27');     // To fix a mappers' habit as old as Quake
137         setorigin (self, self.origin);
138
139         if (!self.targetname)
140                 objerror ("Teleport destination without a targetname");
141 }
142
143 void spawnfunc_misc_teleporter_dest (void)
144 {
145         spawnfunc_info_teleport_destination();
146 }
147
148 void spawnfunc_target_teleporter (void)
149 {
150         spawnfunc_info_teleport_destination();
151 }
152
153 void teleport_findtarget (void)
154 {
155         // now enable touch
156         self.touch = Teleport_Touch;
157
158         self.enemy = find (world, targetname, self.target);
159         if (!self.enemy)
160         {
161                 objerror ("Teleporter with nonexistant target");
162                 remove(self);
163                 return;
164         }
165
166         self.dest = self.enemy.origin;
167         waypoint_spawnforteleporter(self, self.dest, 0);
168 }
169
170 void spawnfunc_trigger_teleport (void)
171 {
172         self.angles = '0 0 0';
173
174         self.solid = SOLID_TRIGGER;
175         self.movetype = MOVETYPE_NONE;
176
177         setmodel (self, self.model); // no precision needed
178
179         self.model = "";
180         self.modelindex = 0;
181
182         self.think = teleport_findtarget;
183         self.nextthink = time + 0.2;
184
185         if (!self.target)
186                 objerror ("Teleporter with no target");
187 }