]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/triggers/trigger/teleport.qc
Use exact trigger hack on teleporters
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / triggers / trigger / teleport.qc
1 REGISTER_NET_LINKED(ENT_CLIENT_TRIGGER_TELEPORT)
2
3 #ifdef SVQC
4 void trigger_teleport_use()
5 {SELFPARAM();
6         if(teamplay)
7                 self.team = activator.team;
8 #ifdef SVQC
9         self.SendFlags |= SF_TRIGGER_UPDATE;
10 #endif
11 }
12 #endif
13
14 void Teleport_Touch ()
15 {SELFPARAM();
16         if (self.active != ACTIVE_ACTIVE)
17                 return;
18
19 #ifdef SVQC
20         if (!other.teleportable)
21                 return;
22
23         if(other.vehicle)
24         if(!other.vehicle.teleportable)
25                 return;
26
27         if(IS_TURRET(other))
28                 return;
29 #endif
30
31         if(PHYS_DEAD(other))
32                 return;
33
34         if(self.team)
35                 if(((self.spawnflags & 4) == 0) == (DIFF_TEAM(this, other)))
36                         return;
37
38         EXACTTRIGGER_TOUCH;
39
40 #ifdef SVQC
41         if(IS_PLAYER(other))
42                 RemoveGrapplingHook(other);
43 #endif
44
45         entity e;
46         e = Simple_TeleportPlayer(self, other);
47
48 #ifdef SVQC
49         activator = other;
50         string s = self.target; self.target = string_null;
51         SUB_UseTargets();
52         if (!self.target) self.target = s;
53
54         WITH(entity, self, e, SUB_UseTargets());
55 #endif
56 }
57
58 #ifdef SVQC
59 float trigger_teleport_send(entity to, float sf)
60 {SELFPARAM();
61         WriteHeader(MSG_ENTITY, ENT_CLIENT_TRIGGER_TELEPORT);
62
63         int f = 0;
64         if(self.warpzone_isboxy)
65                 BITSET_ASSIGN(f, 1);
66         if(self.origin != '0 0 0')
67                 BITSET_ASSIGN(f, 4);
68         WriteByte(MSG_ENTITY, f);
69
70         if(f & 4)
71         {
72                 WriteCoord(MSG_ENTITY, self.origin.x);
73                 WriteCoord(MSG_ENTITY, self.origin.y);
74                 WriteCoord(MSG_ENTITY, self.origin.z);
75         }
76
77         WriteShort(MSG_ENTITY, self.modelindex);
78         WriteCoord(MSG_ENTITY, self.mins.x);
79         WriteCoord(MSG_ENTITY, self.mins.y);
80         WriteCoord(MSG_ENTITY, self.mins.z);
81         WriteCoord(MSG_ENTITY, self.maxs.x);
82         WriteCoord(MSG_ENTITY, self.maxs.y);
83         WriteCoord(MSG_ENTITY, self.maxs.z);
84         WriteByte(MSG_ENTITY, bound(1, self.scale * 16, 255));
85         WriteByte(MSG_ENTITY, self.team);
86         WriteInt24_t(MSG_ENTITY, self.spawnflags);
87         WriteByte(MSG_ENTITY, self.active);
88         WriteCoord(MSG_ENTITY, self.speed);
89
90         trigger_common_write(true);
91
92         return true;
93 }
94
95 void trigger_teleport_link(entity this)
96 {
97         this.SendEntity = trigger_teleport_send;
98         this.SendFlags = 0xFFFFFF;
99 }
100
101 spawnfunc(trigger_teleport)
102 {
103         self.angles = '0 0 0';
104
105         string m = self.model;
106         WarpZoneLib_ExactTrigger_Init();
107         if(m != "")
108         {
109                 precache_model(m);
110                 _setmodel(self, m); // no precision needed
111         }
112         setorigin(self, self.origin);
113         if(self.scale)
114                 setsize(self, self.mins * self.scale, self.maxs * self.scale);
115         else
116                 setsize(self, self.mins, self.maxs);
117
118         self.active = ACTIVE_ACTIVE;
119         BITSET_ASSIGN(self.effects, EF_NODEPTHTEST);
120         self.use = trigger_teleport_use;
121
122         // this must be called to spawn the teleport waypoints for bots
123         InitializeEntity(self, teleport_findtarget, INITPRIO_FINDTARGET);
124
125         if (self.target == "")
126         {
127                 objerror ("Teleporter with no target");
128                 return;
129         }
130
131         self.teleport_next = teleport_first;
132         teleport_first = self;
133 }
134 #elif defined(CSQC)
135 NET_HANDLE(ENT_CLIENT_TRIGGER_TELEPORT, bool isnew)
136 {
137         int f = ReadByte();
138         self.warpzone_isboxy = (f & 1);
139         if(f & 4)
140         {
141                 self.origin_x = ReadCoord();
142                 self.origin_y = ReadCoord();
143                 self.origin_z = ReadCoord();
144         }
145         else
146                 self.origin = '0 0 0';
147
148         self.modelindex = ReadShort();
149         self.mins_x = ReadCoord();
150         self.mins_y = ReadCoord();
151         self.mins_z = ReadCoord();
152         self.maxs_x = ReadCoord();
153         self.maxs_y = ReadCoord();
154         self.maxs_z = ReadCoord();
155         self.scale = ReadByte() / 16;
156         self.classname = "trigger_teleport";
157         int mytm = ReadByte(); if(mytm) { self.team = mytm - 1; }
158         self.spawnflags = ReadInt24_t();
159         self.active = ReadByte();
160         self.speed = ReadCoord();
161
162         trigger_common_read(true);
163
164         self.entremove = trigger_remove_generic;
165         self.solid = SOLID_TRIGGER;
166         //self.draw = trigger_draw_generic;
167         //self.move_touch = trigger_push_touch;
168         self.drawmask = MASK_NORMAL;
169         self.move_time = time;
170         defer(self, 0.25, teleport_findtarget);
171
172         self.teleport_next = teleport_first;
173         teleport_first = self;
174
175         return true;
176 }
177
178 #endif