]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/server/t_teleporters.qc
refactor common setmodel calls for moving brushes and triggers; ALWAYS support .mins...
[divverent/nexuiz.git] / data / qcsrc / server / t_teleporters.qc
1 void Teleport_Touch (void)
2 {
3         entity head;
4         entity oldself;
5
6         if (other.health < 1)
7                 return;
8         if (!other.flags & FL_CLIENT)   // FIXME: Make missiles firable through the teleport too
9                 return;
10
11         sound (other, CHAN_TRIGGER, "misc/teleport.wav", VOL_BASE, ATTN_NORM);
12         pointparticles(particleeffectnum("teleport"), other.origin, '0 0 0', 1);
13
14         /*
15         // Make teleport effect where the player left
16         sound (self, CHAN_TRIGGER, "misc/teleport.wav", VOL_BASE, ATTN_NORM);
17         pointparticles(particleeffectnum("teleport"), other.origin, '0 0 0', 1);
18
19         // Make teleport effect where the player arrived
20         sound (self.enemy, CHAN_TRIGGER, "misc/teleport.wav", VOL_BASE, ATTN_NORM);
21         */
22
23         makevectors (self.enemy.mangle);
24         pointparticles(particleeffectnum("teleport"), self.enemy.origin + v_forward * 32, '0 0 0', 1);
25
26         // Relocate the player
27         setorigin (other, self.enemy.origin + '0 0 1' * (1 - other.mins_z - 24));
28         other.angles = self.enemy.mangle;
29         other.fixangle = TRUE;
30         other.velocity = v_forward * vlen(other.velocity);
31
32         // Kill anyone else in the teleporter box (NO MORE TDEATH)
33         if(other.takedamage && !g_race)
34         {
35                 vector deathmin;
36                 vector deathmax;
37                 float deathradius;
38                 deathmin = other.absmin;
39                 deathmax = other.absmax;
40                 deathradius = max(vlen(deathmin), vlen(deathmax));
41                 for(head = findradius(other.origin, deathradius); head; head = head.chain)
42                         if(head != other)
43                                 if(head.takedamage)
44                                         if(boxesoverlap(deathmin, deathmax, head.absmin, head.absmax))
45                                         {
46                                                 if ((other.classname == "player") && (other.health >= 1))
47                                                         Damage (head, self, other, 10000, DEATH_TELEFRAG, head.origin, '0 0 0');
48                                                 else if (other.health < 1) // corpses gib
49                                                         Damage (head, self, other, 10000, DEATH_TELEFRAG, head.origin, '0 0 0');
50                                                 else // dead bodies and monsters gib themselves instead of telefragging
51                                                         Damage (other, self, other, 10000, DEATH_TELEFRAG, other.origin, '0 0 0');
52                                         }
53         }
54
55         // hide myself a tic
56         other.effects = other.effects | EF_NODRAW;
57         if (other.weaponentity) // misuse FL_FLY to avoid EF_NODRAW on viewmodel
58                 other.weaponentity.flags = other.weaponentity.flags | FL_FLY;
59         other.teleport_time = time + cvar("sys_ticrate");
60
61         other.flags = other.flags - (other.flags & FL_ONGROUND);
62         // reset tracking of oldvelocity for impact damage (sudden velocity changes)
63         other.oldvelocity = other.velocity;
64         // reset tracking of who pushed you into a hazard (for kill credit)
65         other.pushltime = 0;
66
67         // stop player name display
68         {
69                 oldself = self;
70                 self = other;
71                 ClearSelectedPlayer();
72                 self = oldself;
73         }
74
75         if(self.enemy.target)
76         {
77                 oldself = self;
78                 activator = other;
79                 self = self.enemy;
80                 SUB_UseTargets();
81                 self = oldself;
82         }
83 }
84
85 void spawnfunc_info_teleport_destination (void)
86 {
87         self.mangle = self.angles;
88         self.angles = '0 0 0';
89
90         //setorigin (self, self.origin + '0 0 27');     // To fix a mappers' habit as old as Quake
91         setorigin (self, self.origin);
92
93         if (!self.targetname)
94                 objerror ("Teleport destination without a targetname");
95 }
96
97 void spawnfunc_misc_teleporter_dest (void)
98 {
99         spawnfunc_info_teleport_destination();
100 }
101
102 void spawnfunc_target_teleporter (void)
103 {
104         spawnfunc_info_teleport_destination();
105 }
106
107 void teleport_findtarget (void)
108 {
109         // now enable touch
110         self.touch = Teleport_Touch;
111
112         self.enemy = find (world, targetname, self.target);
113         if (!self.enemy)
114         {
115                 objerror ("Teleporter with nonexistant target");
116                 remove(self);
117                 return;
118         }
119
120         self.dest = self.enemy.origin;
121         waypoint_spawnforteleporter(self, self.dest, 0);
122 }
123
124 void spawnfunc_trigger_teleport (void)
125 {
126         self.angles = '0 0 0';
127
128         InitTrigger();
129
130         self.think = teleport_findtarget;
131         self.nextthink = time + 0.2;
132
133         if (!self.target)
134                 objerror ("Teleporter with no target");
135 }