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