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)))
45 void Teleport_Touch(entity this, entity toucher)
47 entity player = toucher;
49 if(!Teleport_Active(this, player))
52 EXACTTRIGGER_TOUCH(this, player);
56 RemoveGrapplingHooks(player);
60 e = Simple_TeleportPlayer(this, player);
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;
67 SUB_UseTargets(e, player, player);
72 void target_teleport_use(entity this, entity actor, entity trigger)
74 entity player = actor;
76 if(!Teleport_Active(this, player))
80 RemoveGrapplingHooks(player);
82 entity e = Simple_TeleportPlayer(this, player);
84 string s = this.target; this.target = string_null;
85 SUB_UseTargets(this, player, player); // TODO: should we be using toucher for trigger too?
91 if(e != this) // only activate the target teleporter if target is different
92 SUB_UseTargets(e, player, player);
97 float trigger_teleport_send(entity this, entity to, float sf)
99 WriteHeader(MSG_ENTITY, ENT_CLIENT_TRIGGER_TELEPORT);
101 WriteByte(MSG_ENTITY, this.team);
102 WriteInt24_t(MSG_ENTITY, this.spawnflags);
103 WriteByte(MSG_ENTITY, this.active);
104 WriteCoord(MSG_ENTITY, this.speed);
106 trigger_common_write(this, true);
111 void trigger_teleport_link(entity this)
113 //trigger_link(this, trigger_teleport_send);
116 spawnfunc(trigger_teleport)
118 this.angles = '0 0 0';
120 this.active = ACTIVE_ACTIVE;
121 //trigger_init(this); // only for predicted triggers?
123 this.use = trigger_teleport_use;
126 FOREACH_WORD(this.noise, true, precache_sound(it));
128 // this must be called to spawn the teleport waypoints for bots
129 InitializeEntity(this, teleport_findtarget, INITPRIO_FINDTARGET);
131 if (!this.target || this.target == "")
133 objerror (this, "Teleporter with no target");
137 IL_PUSH(g_teleporters, this);
140 void target_teleporter_checktarget(entity this)
142 // target_teleporter is used in many strange ways
143 // we must attempt to figure out which way it is being used for in this instance
145 if(!this.target || this.target == "")
147 // this target_teleporter has no target
148 // so it must be either a destination for a teleporter or a teleporter itself
149 bool is_teleporter_target = false;
150 // NOTE: target2, target3, target4 unsupported, this may not be necessary as DeFrag maps have no such targets
151 FOREACH_ENTITY_STRING(target, this.targetname,
153 if(it.classname == "trigger_teleport" || it.classname == "target_teleporter")
155 is_teleporter_target = true;
156 break; // no need to keep looping once a valid target is found
160 if(is_teleporter_target)
162 // there were teleporters found targeting this, so it must be a destination!
163 spawnfunc_info_teleport_destination(this);
167 // set this entity up to be a teleporter, since it can be activated as one
169 this.mangle = this.angles;
170 this.angles = '0 0 0';
173 // seeing as this entity isn't targeted by a teleporter, it must be a teleporter itself
175 this.active = ACTIVE_ACTIVE;
176 this.use = target_teleport_use;
178 if(this.noise && this.noise != "")
179 FOREACH_WORD(this.noise, true, precache_sound(it));
181 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
182 teleport_findtarget(this);
185 spawnfunc(target_teleporter)
187 InitializeEntity(this, target_teleporter_checktarget, INITPRIO_FINDTARGET);
190 NET_HANDLE(ENT_CLIENT_TRIGGER_TELEPORT, bool isnew)
192 this.classname = "trigger_teleport";
194 IL_PUSH(g_teleporters, this);
195 int mytm = ReadByte();
198 this.team = mytm - 1;
200 this.spawnflags = ReadInt24_t();
201 this.active = ReadByte();
202 this.speed = ReadCoord();
204 trigger_common_read(this, true);
206 this.entremove = trigger_remove_generic;
207 this.solid = SOLID_TRIGGER;
208 //settouch(this, trigger_push_touch);
209 this.move_time = time;
210 defer(this, 0.25, teleport_findtarget);