diff --git a/game/src/main/java/jake2/game/GameSpawn.java b/game/src/main/java/jake2/game/GameSpawn.java index 1fbab6c0..e1f358db 100644 --- a/game/src/main/java/jake2/game/GameSpawn.java +++ b/game/src/main/java/jake2/game/GameSpawn.java @@ -351,16 +351,7 @@ private static void addSpawnAdapter(String id, EntThinkAdapter adapter) { spawns.put("target_temp_entity", TargetEntitiesKt::targetTempEntity); spawns.put("target_speaker", TargetEntitiesKt::targetSpeaker); spawns.put("target_explosion", TargetEntitiesKt::targetExplosion); - addSpawnAdapter("target_changelevel", new EntThinkAdapter() { - public String getID() { - return "SP_target_changelevel"; - } - - public boolean think(SubgameEntity ent, GameExportsImpl gameExports) { - GameTarget.SP_target_changelevel(ent, gameExports); - return true; - } - }); + spawns.put("target_changelevel", TargetEntitiesKt::targetChangelevel); spawns.put("target_secret", TargetEntitiesKt::targetSecret); spawns.put("target_goal", TargetEntitiesKt::targetGoal); spawns.put("target_splash", TargetEntitiesKt::targetSplash); diff --git a/game/src/main/java/jake2/game/GameTarget.java b/game/src/main/java/jake2/game/GameTarget.java index d0ee77df..172a84dc 100644 --- a/game/src/main/java/jake2/game/GameTarget.java +++ b/game/src/main/java/jake2/game/GameTarget.java @@ -36,23 +36,6 @@ class GameTarget { - static void SP_target_changelevel(SubgameEntity ent, GameExportsImpl gameExports) { - if (ent.map == null) { - gameExports.gameImports.dprintf("target_changelevel with no map at " - + Lib.vtos(ent.s.origin) + "\n"); - gameExports.freeEntity(ent); - return; - } - - // ugly hack because *SOMEBODY* screwed up their map - if ((Lib.Q_stricmp(gameExports.level.mapname, "fact1") == 0) - && (Lib.Q_stricmp(ent.map, "fact3") == 0)) - ent.map = "fact3$secret1"; - - ent.use = use_target_changelevel; - ent.svflags = Defines.SVF_NOCLIENT; - } - static void SP_target_crosslevel_trigger(SubgameEntity self) { self.svflags = Defines.SVF_NOCLIENT; self.use = trigger_crosslevel_trigger_use; @@ -87,50 +70,6 @@ static void SP_target_laser(SubgameEntity self, GameExportsImpl gameExports) { self.think.nextTime = gameExports.level.time + 1; } - /** - * QUAKED target_changelevel (1 0 0) (-8 -8 -8) (8 8 8) Changes level to - * "map" when fired - */ - private static EntUseAdapter use_target_changelevel = new EntUseAdapter() { - public String getID() { return "use_target_changelevel"; } - public void use(SubgameEntity self, SubgameEntity other, SubgameEntity activator, GameExportsImpl gameExports) { - if (gameExports.level.intermissiontime != 0) - return; // already activated - - if (0 == gameExports.gameCvars.deathmatch.value && 0 == gameExports.gameCvars.coop.value) { - if (gameExports.g_edicts[1].health <= 0) - return; - } - - // if noexit, do a ton of damage to other - if (gameExports.gameCvars.deathmatch.value != 0 - && 0 == ((int) gameExports.gameCvars.dmflags.value & Defines.DF_ALLOW_EXIT) - && other != gameExports.g_edicts[0] /* world */ - ) { - GameCombat.T_Damage(other, self, self, Globals.vec3_origin, - other.s.origin, Globals.vec3_origin, - 10 * other.max_health, 1000, 0, GameDefines.MOD_EXIT, gameExports); - return; - } - - // if multiplayer, let everyone know who hit the exit - if (gameExports.gameCvars.deathmatch.value != 0) { - if (activator != null) { - gclient_t activatorClient = activator.getClient(); - if (activatorClient != null) gameExports.gameImports.bprintf(Defines.PRINT_HIGH, - activatorClient.pers.netname - + " exited the level.\n"); - } - } - - // if going to a new unit, clear cross triggers - if (self.map.indexOf('*') > -1) - gameExports.game.serverflags &= ~(Defines.SFL_CROSS_TRIGGER_MASK); - - PlayerHud.BeginIntermission(self, gameExports); - } - }; - /** * QUAKED target_crosslevel_trigger (.5 .5 .5) (-8 -8 -8) (8 8 8) trigger1 * trigger2 trigger3 trigger4 trigger5 trigger6 trigger7 trigger8 Once this diff --git a/game/src/main/kotlin/jake2/game/targetEntities.kt b/game/src/main/kotlin/jake2/game/targetEntities.kt index 60385b69..aa07c575 100644 --- a/game/src/main/kotlin/jake2/game/targetEntities.kt +++ b/game/src/main/kotlin/jake2/game/targetEntities.kt @@ -3,6 +3,7 @@ package jake2.game import jake2.game.adapters.SuperAdapter.Companion.registerThink import jake2.game.adapters.SuperAdapter.Companion.registerUse import jake2.qcommon.Defines +import jake2.qcommon.Globals import jake2.qcommon.network.MulticastTypes import jake2.qcommon.network.messages.server.PointTEMessage import jake2.qcommon.network.messages.server.SplashTEMessage @@ -514,3 +515,60 @@ private val targetStringUse = registerUse("target_string_use") { self, _, _, _ - } } + +/** + * QUAKED target_changelevel (1 0 0) (-8 -8 -8) (8 8 8) + * + * Changes level to "map" when fired + */ +fun targetChangelevel(self: SubgameEntity, game: GameExportsImpl) { + if (self.map == null) { + game.gameImports.dprintf("target_changelevel with no map at " + Lib.vtos(self.s.origin) + "\n") + game.freeEntity(self) + return + } + + // ugly hack because *SOMEBODY* screwed up their map + if(self.map == "fact3" && game.level.mapname == "fact1") + self.map = "fact3\$secret1" + + self.use = targetChangelevelUse + self.svflags = Defines.SVF_NOCLIENT +} + +private val targetChangelevelUse = registerUse("use_target_changelevel") { self, other, activator, game -> + if (game.level.intermissiontime != 0f) + return@registerUse // already activated + + + if (game.gameCvars.deathmatch.value == 0f && game.gameCvars.coop.value == 0f) { + if (game.g_edicts[1].health <= 0) + return@registerUse + } + + // if noexit, do a ton of damage to other + if (game.gameCvars.deathmatch.value != 0f + && game.gameCvars.dmflags.value.toInt() and Defines.DF_ALLOW_EXIT == 0 && other !== game.g_edicts[0] /* world */) { + GameCombat.T_Damage( + other, self, self, Globals.vec3_origin, + other!!.s.origin, Globals.vec3_origin, + 10 * other.max_health, 1000, 0, GameDefines.MOD_EXIT, game + ) + return@registerUse + } + + // if multiplayer, let everyone know who hit the exit + if (game.gameCvars.deathmatch.value != 0f) { + if (activator != null) { + val activatorClient = activator.client + if (activatorClient != null) + game.gameImports.bprintf(Defines.PRINT_HIGH, "${activatorClient.pers.netname} exited the level.\n") + } + } + + // if going to a new unit, clear cross triggers + if (self.map.indexOf('*') > -1) game.game.serverflags = + game.game.serverflags and Defines.SFL_CROSS_TRIGGER_MASK.inv() + + PlayerHud.BeginIntermission(self, game) +}