From: Mario Date: Sat, 30 May 2020 11:40:42 +0000 (+1000) Subject: Implement support for target_teleporter to be used as a teleporter directly when... X-Git-Tag: xonotic-v0.8.5~994 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=1385f34729eca0b6b732033b5c12b6b30409a861;p=xonotic%2Fxonotic-data.pk3dir.git Implement support for target_teleporter to be used as a teleporter directly when activated, solves #1921 --- diff --git a/qcsrc/common/mapobjects/trigger/teleport.qc b/qcsrc/common/mapobjects/trigger/teleport.qc index 825dd01dd..ae82a82c1 100644 --- a/qcsrc/common/mapobjects/trigger/teleport.qc +++ b/qcsrc/common/mapobjects/trigger/teleport.qc @@ -88,7 +88,8 @@ void target_teleport_use(entity this, entity actor, entity trigger) this.target = s; } - SUB_UseTargets(e, player, player); + if(e != this) // only activate the target teleporter if target is different + SUB_UseTargets(e, player, player); } #endif @@ -127,7 +128,7 @@ spawnfunc(trigger_teleport) // this must be called to spawn the teleport waypoints for bots InitializeEntity(this, teleport_findtarget, INITPRIO_FINDTARGET); - if (this.target == "") + if (!this.target || this.target == "") { objerror (this, "Teleporter with no target"); return; @@ -136,23 +137,54 @@ spawnfunc(trigger_teleport) IL_PUSH(g_teleporters, this); } -spawnfunc(target_teleporter) +void target_teleporter_checktarget(entity this) { - if(this.target == "") + // target_teleporter is used in many strange ways + // we must attempt to figure out which way it is being used for in this instance + + if(!this.target || this.target == "") { - // actually a destination! - spawnfunc_info_teleport_destination(this); - return; + // this target_teleporter has no target + // so it must be either a destination for a teleporter or a teleporter itself + bool is_teleporter_target = false; + // NOTE: target2, target3, target4 unsupported, this may not be necessary as DeFrag maps have no such targets + FOREACH_ENTITY_STRING(target, this.targetname, + { + if(it.classname == "trigger_teleport" || it.classname == "target_teleporter") + { + is_teleporter_target = true; + break; // no need to keep looping once a valid target is found + } + }); + + if(is_teleporter_target) + { + // there were teleporters found targeting this, so it must be a destination! + spawnfunc_info_teleport_destination(this); + return; + } + + // set this entity up to be a teleporter, since it can be activated as one + this.enemy = this; + this.mangle = this.angles; + this.angles = '0 0 0'; } - this.active = ACTIVE_ACTIVE; + // seeing as this entity isn't targeted by a teleporter, it must be a teleporter itself + this.active = ACTIVE_ACTIVE; this.use = target_teleport_use; - if(this.noise != "") + if(this.noise && this.noise != "") FOREACH_WORD(this.noise, true, precache_sound(it)); - InitializeEntity(this, teleport_findtarget, INITPRIO_FINDTARGET); + 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 + teleport_findtarget(this); +} + +spawnfunc(target_teleporter) +{ + InitializeEntity(this, target_teleporter_checktarget, INITPRIO_FINDTARGET); } #elif defined(CSQC) NET_HANDLE(ENT_CLIENT_TRIGGER_TELEPORT, bool isnew)