hook: always enter the pulling state right
[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         RemoveGrapplingHook(other);
34
35         // Kill anyone else in the teleporter box (NO MORE TDEATH)
36         if(other.takedamage && !g_race)
37         {
38                 vector deathmin;
39                 vector deathmax;
40                 float deathradius;
41                 deathmin = other.absmin;
42                 deathmax = other.absmax;
43                 deathradius = max(vlen(deathmin), vlen(deathmax));
44                 for(head = findradius(other.origin, deathradius); head; head = head.chain)
45                         if(head != other)
46                                 if(head.takedamage)
47                                         if(boxesoverlap(deathmin, deathmax, head.absmin, head.absmax))
48                                         {
49                                                 if ((other.classname == "player") && (other.health >= 1))
50                                                         Damage (head, self, other, 10000, DEATH_TELEFRAG, head.origin, '0 0 0');
51                                                 else if (other.health < 1) // corpses gib
52                                                         Damage (head, self, other, 10000, DEATH_TELEFRAG, head.origin, '0 0 0');
53                                                 else // dead bodies and monsters gib themselves instead of telefragging
54                                                         Damage (other, self, other, 10000, DEATH_TELEFRAG, other.origin, '0 0 0');
55                                         }
56         }
57
58         // hide myself a tic
59         other.effects = other.effects | EF_NODRAW;
60         if (other.weaponentity) // misuse FL_FLY to avoid EF_NODRAW on viewmodel
61                 other.weaponentity.flags = other.weaponentity.flags | FL_FLY;
62         other.teleport_time = time + cvar("sys_ticrate");
63
64         other.flags = other.flags - (other.flags & FL_ONGROUND);
65         // reset tracking of oldvelocity for impact damage (sudden velocity changes)
66         other.oldvelocity = other.velocity;
67         // reset tracking of who pushed you into a hazard (for kill credit)
68         other.pushltime = 0;
69
70         // stop player name display
71         {
72                 oldself = self;
73                 self = other;
74                 ClearSelectedPlayer();
75                 self = oldself;
76         }
77
78         if(self.enemy.target)
79         {
80                 oldself = self;
81                 activator = other;
82                 self = self.enemy;
83                 SUB_UseTargets();
84                 self = oldself;
85         }
86 }
87
88 void spawnfunc_info_teleport_destination (void)
89 {
90         self.mangle = self.angles;
91         self.angles = '0 0 0';
92
93         //setorigin (self, self.origin + '0 0 27');     // To fix a mappers' habit as old as Quake
94         setorigin (self, self.origin);
95
96         IFTARGETED
97         {
98         }
99         else
100                 objerror ("Teleport destination without a targetname");
101 }
102
103 void spawnfunc_misc_teleporter_dest (void)
104 {
105         spawnfunc_info_teleport_destination();
106 }
107
108 void spawnfunc_target_teleporter (void)
109 {
110         spawnfunc_info_teleport_destination();
111 }
112
113 void teleport_findtarget (void)
114 {
115         // now enable touch
116         self.touch = Teleport_Touch;
117
118         self.enemy = find (world, targetname, self.target);
119         if (!self.enemy)
120         {
121                 objerror ("Teleporter with nonexistant target");
122                 remove(self);
123                 return;
124         }
125
126         self.dest = self.enemy.origin;
127         waypoint_spawnforteleporter(self, self.dest, 0);
128 }
129
130 void spawnfunc_trigger_teleport (void)
131 {
132         self.angles = '0 0 0';
133
134         EXACTTRIGGER_INIT;
135
136         // this must be called to spawn the teleport waypoints for bots
137         InitializeEntity(self, teleport_findtarget, INITPRIO_FINDTARGET);
138
139         if (!self.target)
140                 objerror ("Teleporter with no target");
141 }