]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/triggers/trigger/teleport.qc
Use a temporary hack to fix teleporters and jumppads not finding their targets
[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 this, entity to, float sf)
60 {
61         WriteHeader(MSG_ENTITY, ENT_CLIENT_TRIGGER_TELEPORT);
62         WriteByte(MSG_ENTITY, sf);
63
64         if(sf & 1)
65         {
66                 WriteByte(MSG_ENTITY, this.team);
67                 WriteInt24_t(MSG_ENTITY, this.spawnflags);
68                 WriteByte(MSG_ENTITY, this.active);
69                 WriteCoord(MSG_ENTITY, this.speed);
70
71                 trigger_common_write(true);
72         }
73
74         if(sf & 2)
75         {
76                 WriteByte(MSG_ENTITY, this.team);
77                 WriteByte(MSG_ENTITY, this.active);
78         }
79
80         return true;
81 }
82
83 void trigger_teleport_link(entity this)
84 {
85         Net_LinkEntity(this, false, 0, trigger_teleport_send);
86 }
87
88 spawnfunc(trigger_teleport)
89 {
90         self.angles = '0 0 0';
91
92         EXACTTRIGGER_INIT;
93
94         self.active = ACTIVE_ACTIVE;
95
96         self.use = trigger_teleport_use;
97
98         // this must be called to spawn the teleport waypoints for bots
99         InitializeEntity(self, teleport_findtarget, INITPRIO_FINDTARGET);
100
101         if (self.target == "")
102         {
103                 objerror ("Teleporter with no target");
104                 return;
105         }
106
107         self.teleport_next = teleport_first;
108         teleport_first = self;
109 }
110 #elif defined(CSQC)
111 NET_HANDLE(ENT_CLIENT_TRIGGER_TELEPORT, bool isnew)
112 {
113         int sf = ReadByte();
114
115         if(sf & 1)
116         {
117                 self.classname = "trigger_teleport";
118                 int mytm = ReadByte(); if(mytm) { self.team = mytm - 1; }
119                 self.spawnflags = ReadInt24_t();
120                 self.active = ReadByte();
121                 self.speed = ReadCoord();
122
123                 trigger_common_read(true);
124
125                 self.entremove = trigger_remove_generic;
126                 self.solid = SOLID_TRIGGER;
127                 //self.draw = trigger_draw_generic;
128                 //self.move_touch = trigger_push_touch;
129                 self.drawmask = MASK_NORMAL;
130                 self.move_time = time;
131                 defer(self, 0.25, teleport_findtarget);
132
133                 self.teleport_next = teleport_first;
134                 teleport_first = self;
135         }
136
137         if(sf & 2)
138         {
139                 self.team = ReadByte();
140                 self.active = ReadByte();
141         }
142         return true;
143 }
144
145 #endif