]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/mapobjects/trigger/teleport.qc
825dd01ddeea559ac5f52d8cbd944904f0a0f0f0
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / mapobjects / trigger / teleport.qc
1 #include "teleport.qh"
2 REGISTER_NET_LINKED(ENT_CLIENT_TRIGGER_TELEPORT)
3
4 #ifdef SVQC
5 void trigger_teleport_use(entity this, entity actor, entity trigger)
6 {
7         if(teamplay)
8                 this.team = actor.team;
9 #ifdef SVQC
10         this.SendFlags |= SF_TRIGGER_UPDATE;
11 #endif
12 }
13 #endif
14
15 bool Teleport_Active(entity this, entity player)
16 {
17         if (this.active != ACTIVE_ACTIVE)
18                 return false;
19
20 #ifdef SVQC
21         if (!player.teleportable)
22                 return false;
23
24         if(player.vehicle)
25         if(!player.vehicle.teleportable)
26                 return false;
27
28         if(IS_TURRET(player))
29                 return false;
30 #elif defined(CSQC)
31         if(!IS_PLAYER(player))
32                 return false;
33 #endif
34
35         if(IS_DEAD(player))
36                 return false;
37
38         if(this.team)
39                 if(((this.spawnflags & INVERT_TEAMS) == 0) == (DIFF_TEAM(this, player)))
40                         return false;
41
42         return true;
43 }
44
45 void Teleport_Touch(entity this, entity toucher)
46 {
47         entity player = toucher;
48
49         if(!Teleport_Active(this, player))
50                 return;
51
52         EXACTTRIGGER_TOUCH(this, player);
53
54 #ifdef SVQC
55         if(IS_PLAYER(player))
56                 RemoveGrapplingHooks(player);
57 #endif
58
59         entity e;
60         e = Simple_TeleportPlayer(this, player);
61
62 #ifdef SVQC
63         string s = this.target; this.target = string_null;
64         SUB_UseTargets(this, player, player); // TODO: should we be using toucher for trigger too?
65         if (!this.target) this.target = s;
66
67         SUB_UseTargets(e, player, player);
68 #endif
69 }
70
71 #ifdef SVQC
72 void target_teleport_use(entity this, entity actor, entity trigger)
73 {
74         entity player = actor;
75
76         if(!Teleport_Active(this, player))
77                 return;
78
79         if(IS_PLAYER(player))
80                 RemoveGrapplingHooks(player);
81
82         entity e = Simple_TeleportPlayer(this, player);
83
84         string s = this.target; this.target = string_null;
85         SUB_UseTargets(this, player, player); // TODO: should we be using toucher for trigger too?
86         if (!this.target)
87         {
88                 this.target = s;
89         }
90
91         SUB_UseTargets(e, player, player);
92 }
93 #endif
94
95 #ifdef SVQC
96 float trigger_teleport_send(entity this, entity to, float sf)
97 {
98         WriteHeader(MSG_ENTITY, ENT_CLIENT_TRIGGER_TELEPORT);
99
100         WriteByte(MSG_ENTITY, this.team);
101         WriteInt24_t(MSG_ENTITY, this.spawnflags);
102         WriteByte(MSG_ENTITY, this.active);
103         WriteCoord(MSG_ENTITY, this.speed);
104
105         trigger_common_write(this, true);
106
107         return true;
108 }
109
110 void trigger_teleport_link(entity this)
111 {
112         //trigger_link(this, trigger_teleport_send);
113 }
114
115 spawnfunc(trigger_teleport)
116 {
117         this.angles = '0 0 0';
118
119         this.active = ACTIVE_ACTIVE;
120         //trigger_init(this); // only for predicted triggers?
121         EXACTTRIGGER_INIT;
122         this.use = trigger_teleport_use;
123
124         if(this.noise != "")
125                 FOREACH_WORD(this.noise, true, precache_sound(it));
126
127         // this must be called to spawn the teleport waypoints for bots
128         InitializeEntity(this, teleport_findtarget, INITPRIO_FINDTARGET);
129
130         if (this.target == "")
131         {
132                 objerror (this, "Teleporter with no target");
133                 return;
134         }
135
136         IL_PUSH(g_teleporters, this);
137 }
138
139 spawnfunc(target_teleporter)
140 {
141         if(this.target == "")
142         {
143                 // actually a destination!
144                 spawnfunc_info_teleport_destination(this);
145                 return;
146         }
147
148         this.active = ACTIVE_ACTIVE;
149
150         this.use = target_teleport_use;
151
152         if(this.noise != "")
153                 FOREACH_WORD(this.noise, true, precache_sound(it));
154
155         InitializeEntity(this, teleport_findtarget, INITPRIO_FINDTARGET);
156 }
157 #elif defined(CSQC)
158 NET_HANDLE(ENT_CLIENT_TRIGGER_TELEPORT, bool isnew)
159 {
160         this.classname = "trigger_teleport";
161         if(isnew)
162                 IL_PUSH(g_teleporters, this);
163         int mytm = ReadByte();
164         if(mytm)
165         {
166                 this.team = mytm - 1;
167         }
168         this.spawnflags = ReadInt24_t();
169         this.active = ReadByte();
170         this.speed = ReadCoord();
171
172         trigger_common_read(this, true);
173
174         this.entremove = trigger_remove_generic;
175         this.solid = SOLID_TRIGGER;
176         //settouch(this, trigger_push_touch);
177         this.move_time = time;
178         defer(this, 0.25, teleport_findtarget);
179
180         return true;
181 }
182
183 #endif