Skip to content

Commit

Permalink
Kotlin entities: target_chrosslevel trigger/target
Browse files Browse the repository at this point in the history
  • Loading branch information
demoth committed Dec 11, 2022
1 parent 52760e5 commit 84dd900
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 74 deletions.
22 changes: 2 additions & 20 deletions game/src/main/java/jake2/game/GameSpawn.java
Original file line number Diff line number Diff line change
Expand Up @@ -357,26 +357,8 @@ private static void addSpawnAdapter(String id, EntThinkAdapter adapter) {
spawns.put("target_splash", TargetEntitiesKt::targetSplash);
spawns.put("target_spawner", TargetEntitiesKt::targetSpawner);
spawns.put("target_blaster", TargetEntitiesKt::targetBlaster);
addSpawnAdapter("target_crosslevel_trigger", new EntThinkAdapter() {
public String getID() {
return "SP_target_crosslevel_trigger";
}

public boolean think(SubgameEntity ent, GameExportsImpl gameExports) {
GameTarget.SP_target_crosslevel_trigger(ent);
return true;
}
});
addSpawnAdapter("target_crosslevel_target", new EntThinkAdapter() {
public String getID() {
return "SP_target_crosslevel_target";
}

public boolean think(SubgameEntity ent, GameExportsImpl gameExports) {
GameTarget.SP_target_crosslevel_target(ent, gameExports);
return true;
}
});
spawns.put("target_crosslevel_trigger", TargetEntitiesKt::targetCrosslevelTrigger);
spawns.put("target_crosslevel_target", TargetEntitiesKt::targetCrosslevelTarget);
addSpawnAdapter("target_laser", new EntThinkAdapter() {
public String getID() {
return "SP_target_laser";
Expand Down
52 changes: 0 additions & 52 deletions game/src/main/java/jake2/game/GameTarget.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,6 @@

class GameTarget {


static void SP_target_crosslevel_trigger(SubgameEntity self) {
self.svflags = Defines.SVF_NOCLIENT;
self.use = trigger_crosslevel_trigger_use;
}

static void SP_target_crosslevel_target(SubgameEntity self, GameExportsImpl gameExports) {
if (0 == self.delay)
self.delay = 1;
self.svflags = Defines.SVF_NOCLIENT;

self.think.action = target_crosslevel_target_think;
self.think.nextTime = gameExports.level.time + self.delay;
}

private static void target_laser_on(SubgameEntity self, GameExportsImpl gameExports) {
if (null == self.activator)
self.activator = self;
Expand All @@ -70,43 +55,6 @@ static void SP_target_laser(SubgameEntity self, GameExportsImpl gameExports) {
self.think.nextTime = gameExports.level.time + 1;
}

/**
* QUAKED target_crosslevel_trigger (.5 .5 .5) (-8 -8 -8) (8 8 8) trigger1
* trigger2 trigger3 trigger4 trigger5 trigger6 trigger7 trigger8 Once this
* trigger is touched/used, any trigger_crosslevel_target with the same
* trigger number is automatically used when a level is started within the
* same unit. It is OK to check multiple triggers. Message, delay, target,
* and killtarget also work.
*/
private static EntUseAdapter trigger_crosslevel_trigger_use = new EntUseAdapter() {
public String getID() { return "trigger_crosslevel_trigger_use"; }
public void use(SubgameEntity self, SubgameEntity other, SubgameEntity activator, GameExportsImpl gameExports) {
gameExports.game.serverflags |= self.spawnflags;
gameExports.freeEntity(self);
}
};

/**
* QUAKED target_crosslevel_target (.5 .5 .5) (-8 -8 -8) (8 8 8) trigger1
* trigger2 trigger3 trigger4 trigger5 trigger6 trigger7 trigger8 Triggered
* by a trigger_crosslevel elsewhere within a unit. If multiple triggers are
* checked, all must be true. Delay, target and killtarget also work.
*
* "delay" delay before using targets if the trigger has been activated
* (default 1)
*/
private static EntThinkAdapter target_crosslevel_target_think = new EntThinkAdapter() {
public String getID() { return "target_crosslevel_target_think"; }
public boolean think(SubgameEntity self, GameExportsImpl gameExports) {
if (self.spawnflags == (gameExports.game.serverflags
& Defines.SFL_CROSS_TRIGGER_MASK & self.spawnflags)) {
GameUtil.G_UseTargets(self, self, gameExports);
gameExports.freeEntity(self);
}
return true;
}
};

/**
* QUAKED target_laser (0 .5 .8) (-8 -8 -8) (8 8 8) START_ON RED GREEN BLUE
* YELLOW ORANGE FAT When triggered, fires a laser. You can either set a
Expand Down
52 changes: 50 additions & 2 deletions game/src/main/kotlin/jake2/game/targetEntities.kt
Original file line number Diff line number Diff line change
Expand Up @@ -567,8 +567,56 @@ private val targetChangelevelUse = registerUse("use_target_changelevel") { self,
}

// 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()
if (self.map.indexOf('*') > -1)
game.game.serverflags = game.game.serverflags and Defines.SFL_CROSS_TRIGGER_MASK.inv()

PlayerHud.BeginIntermission(self, game)
}

/**
* QUAKED target_crosslevel_trigger (.5 .5 .5) (-8 -8 -8) (8 8 8) trigger1
* trigger2 trigger3 trigger4 trigger5 trigger6 trigger7 trigger8
*
* Set's it's spawnflag to the serverflags register.
*
* Once this trigger is touched/used, any trigger_crosslevel_target with the same
* trigger number is automatically used when a level is started within the same unit.
* It is OK to check multiple triggers.
* Message, delay, target, and killtarget also work.
*/
fun targetCrosslevelTrigger(self: SubgameEntity, game: GameExportsImpl) {
self.svflags = Defines.SVF_NOCLIENT
self.use = targetCrosslevelTriggerUse
}

private val targetCrosslevelTriggerUse = registerUse("trigger_crosslevel_trigger_use") { self, _, _, game ->
game.game.serverflags = game.game.serverflags or self.spawnflags
game.freeEntity(self)
}

/**
* QUAKED target_crosslevel_target (.5 .5 .5) (-8 -8 -8) (8 8 8) trigger1
* trigger2 trigger3 trigger4 trigger5 trigger6 trigger7 trigger8
*
* Triggered by a trigger_crosslevel elsewhere within a unit.
* If multiple triggers are checked, all must be true.
* Delay, target and killtarget also work.
*
* "delay" delay before using targets if the trigger has been activated
* (default 1)
*/
fun targetCrosslevelTarget(self: SubgameEntity, game: GameExportsImpl) {
if (self.delay == 0f)
self.delay = 1f
self.svflags = Defines.SVF_NOCLIENT
self.think.action = targetCrosslevelTargetThink
self.think.nextTime = game.level.time + self.delay
}

private val targetCrosslevelTargetThink = registerThink("target_crosslevel_target_think") { self, game ->
if (self.spawnflags == Defines.SFL_CROSS_TRIGGER_MASK and game.game.serverflags and self.spawnflags) {
GameUtil.G_UseTargets(self, self, game)
game.freeEntity(self)
}
true
}

0 comments on commit 84dd900

Please sign in to comment.