]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/triggers/trigger/teleport.qc
Merge branch 'master' into Lyberta/StandaloneOverkillWeapons
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / triggers / 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 & 4) == 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) this.target = s;
87
88         SUB_UseTargets(e, player, player);
89 }
90 #endif
91
92 #ifdef SVQC
93 float trigger_teleport_send(entity this, entity to, float sf)
94 {
95         WriteHeader(MSG_ENTITY, ENT_CLIENT_TRIGGER_TELEPORT);
96
97         WriteByte(MSG_ENTITY, this.team);
98         WriteInt24_t(MSG_ENTITY, this.spawnflags);
99         WriteByte(MSG_ENTITY, this.active);
100         WriteCoord(MSG_ENTITY, this.speed);
101
102         trigger_common_write(this, true);
103
104         return true;
105 }
106
107 void trigger_teleport_link(entity this)
108 {
109         //trigger_link(this, trigger_teleport_send);
110 }
111
112 spawnfunc(trigger_teleport)
113 {
114         this.angles = '0 0 0';
115
116         this.active = ACTIVE_ACTIVE;
117         //trigger_init(this); // only for predicted triggers?
118         EXACTTRIGGER_INIT;
119         this.use = trigger_teleport_use;
120
121         if(this.noise != "")
122                 FOREACH_WORD(this.noise, true, precache_sound(it));
123
124         // this must be called to spawn the teleport waypoints for bots
125         InitializeEntity(this, teleport_findtarget, INITPRIO_FINDTARGET);
126
127         if (this.target == "")
128         {
129                 objerror (this, "Teleporter with no target");
130                 return;
131         }
132
133         IL_PUSH(g_teleporters, this);
134 }
135
136 spawnfunc(target_teleporter)
137 {
138         if(this.target == "")
139         {
140                 // actually a destination!
141                 spawnfunc_info_teleport_destination(this);
142                 return;
143         }
144
145         this.active = ACTIVE_ACTIVE;
146
147         this.use = target_teleport_use;
148
149         if(this.noise != "")
150                 FOREACH_WORD(this.noise, true, precache_sound(it));
151
152         InitializeEntity(this, teleport_findtarget, INITPRIO_FINDTARGET);
153 }
154 #elif defined(CSQC)
155 NET_HANDLE(ENT_CLIENT_TRIGGER_TELEPORT, bool isnew)
156 {
157         this.classname = "trigger_teleport";
158         if(isnew)
159                 IL_PUSH(g_teleporters, this);
160         int mytm = ReadByte(); if(mytm) { this.team = mytm - 1; }
161         this.spawnflags = ReadInt24_t();
162         this.active = ReadByte();
163         this.speed = ReadCoord();
164
165         trigger_common_read(this, true);
166
167         this.entremove = trigger_remove_generic;
168         this.solid = SOLID_TRIGGER;
169         //settouch(this, trigger_push_touch);
170         this.move_time = time;
171         defer(this, 0.25, teleport_findtarget);
172
173         return true;
174 }
175
176 #endif