2 REGISTER_NET_LINKED(ENT_CLIENT_TRIGGER_TELEPORT)
5 void trigger_teleport_use(entity this, entity actor, entity trigger)
8 this.team = actor.team;
10 this.SendFlags |= SF_TRIGGER_UPDATE;
15 bool Teleport_Active(entity this, entity player)
17 if (this.active != ACTIVE_ACTIVE)
21 if (!player.teleportable)
25 if(!player.vehicle.teleportable)
31 if(!IS_PLAYER(player))
39 if(((this.spawnflags & INVERT_TEAMS) == 0) == (DIFF_TEAM(this, player)))
42 // no need to call IS_OBSERVER(), observers never call use/touch functions which means this is never an observer
43 if(this.classname == "trigger_teleport" && this.spawnflags & TELEPORT_OBSERVERS_ONLY)
49 void Teleport_Touch(entity this, entity toucher)
51 entity player = toucher;
53 if(!Teleport_Active(this, player))
56 EXACTTRIGGER_TOUCH(this, player);
60 RemoveGrapplingHooks(player);
64 e = Simple_TeleportPlayer(this, player);
67 string s = this.target; this.target = string_null;
68 SUB_UseTargets(this, player, player); // TODO: should we be using toucher for trigger too?
69 if (!this.target) this.target = s;
71 SUB_UseTargets(e, player, player);
76 void target_teleport_use(entity this, entity actor, entity trigger)
78 entity player = actor;
80 if(!Teleport_Active(this, player))
84 RemoveGrapplingHooks(player);
86 entity e = Simple_TeleportPlayer(this, player);
88 string s = this.target; this.target = string_null;
89 SUB_UseTargets(this, player, player); // TODO: should we be using toucher for trigger too?
95 if(e != this) // only activate the target teleporter if target is different
96 SUB_UseTargets(e, player, player);
101 float trigger_teleport_send(entity this, entity to, float sf)
103 WriteHeader(MSG_ENTITY, ENT_CLIENT_TRIGGER_TELEPORT);
105 WriteByte(MSG_ENTITY, this.team);
106 WriteInt24_t(MSG_ENTITY, this.spawnflags);
107 WriteByte(MSG_ENTITY, this.active);
108 WriteCoord(MSG_ENTITY, this.speed);
110 trigger_common_write(this, true);
115 void trigger_teleport_link(entity this)
117 //trigger_link(this, trigger_teleport_send);
120 spawnfunc(trigger_teleport)
122 this.angles = '0 0 0';
124 this.active = ACTIVE_ACTIVE;
126 this.use = trigger_teleport_use;
129 FOREACH_WORD(this.noise, true, precache_sound(it));
131 // this must be called to spawn the teleport waypoints for bots
132 InitializeEntity(this, teleport_findtarget, INITPRIO_FINDTARGET);
134 if (!this.target || this.target == "")
136 objerror (this, "Teleporter with no target");
140 IL_PUSH(g_teleporters, this);
143 void target_teleporter_checktarget(entity this)
145 // target_teleporter is used in many strange ways
146 // we must attempt to figure out which way it is being used for in this instance
148 if(!this.target || this.target == "")
150 // this target_teleporter has no target
151 // so it must be either a destination for a teleporter or a teleporter itself
152 bool is_teleporter_target = false;
153 // NOTE: target2, target3, target4 unsupported, this may not be necessary as DeFrag maps have no such targets
154 FOREACH_ENTITY_STRING(target, this.targetname,
156 if(it.classname == "trigger_teleport" || it.classname == "target_teleporter")
158 is_teleporter_target = true;
159 break; // no need to keep looping once a valid target is found
163 if(is_teleporter_target)
165 // there were teleporters found targeting this, so it must be a destination!
166 spawnfunc_info_teleport_destination(this);
170 // set this entity up to be a teleporter, since it can be activated as one
172 this.mangle = this.angles;
173 this.angles = '0 0 0';
176 // seeing as this entity isn't targeted by a teleporter, it must be a teleporter itself
178 this.active = ACTIVE_ACTIVE;
179 this.use = target_teleport_use;
181 if(this.noise && this.noise != "")
182 FOREACH_WORD(this.noise, true, precache_sound(it));
184 if(this.target && this.target != "") // no need to find a target on this entity, as it does not have one and .enemy is already set as required
185 teleport_findtarget(this);
188 spawnfunc(target_teleporter)
190 InitializeEntity(this, target_teleporter_checktarget, INITPRIO_FINDTARGET);
193 NET_HANDLE(ENT_CLIENT_TRIGGER_TELEPORT, bool isnew)
195 this.classname = "trigger_teleport";
197 IL_PUSH(g_teleporters, this);
198 int mytm = ReadByte();
201 this.team = mytm - 1;
203 this.spawnflags = ReadInt24_t();
204 this.active = ReadByte();
205 this.speed = ReadCoord();
207 trigger_common_read(this, true);
209 this.entremove = trigger_remove_generic;
210 this.solid = SOLID_TRIGGER;
211 //settouch(this, trigger_push_touch);
212 this.move_time = time;
213 defer(this, 0.25, teleport_findtarget);