Skip to content

Commit

Permalink
Rework monster decision code #109: PoC introduce Behavior tree
Browse files Browse the repository at this point in the history
wip melee attack + hit event
  • Loading branch information
demoth committed Jan 16, 2024
1 parent 8950b50 commit 2b80649
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
7 changes: 3 additions & 4 deletions game/src/main/java/jake2/game/GameWeapon.java
Original file line number Diff line number Diff line change
Expand Up @@ -521,10 +521,9 @@ public static boolean fire_hit(SubgameEntity self, float[] aim, int damage,
SubgameEntity target = (SubgameEntity) tr.ent;
if (0 == target.takedamage)
return false;
// if it will hit any client/monster then hit the one we wanted to
// hit
if ((tr.ent.svflags & Defines.SVF_MONSTER) != 0
|| (tr.ent.getClient() != null))
// fixme WTF???
// if it will hit any client/monster then hit the one we wanted to hit
if ((tr.ent.svflags & Defines.SVF_MONSTER) != 0 || tr.ent.getClient() != null)
tr.ent = self.enemy;
}

Expand Down
9 changes: 8 additions & 1 deletion game/src/main/kotlin/jake2/game/character/GameCharacter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package jake2.game.character
import jake2.game.*
import jake2.game.adapters.SuperAdapter.Companion.registerThink
import jake2.game.components.ThinkComponent
import jake2.game.monsters.M_Infantry
import jake2.qcommon.Defines
import jake2.qcommon.util.Lib
import jake2.qcommon.util.Math3D
import kotlin.random.Random

Expand Down Expand Up @@ -103,6 +105,7 @@ class GameCharacter(
private val soundPain: Int = game.gameImports.soundindex("infantry/infpain1.wav")
private val soundDead: Int = game.gameImports.soundindex("infantry/infdeth1.wav")
private val soundSwing = game.gameImports.soundindex("infantry/infatck2.wav")
private val soundHit = game.gameImports.soundindex("infantry/melee2.wav")

var health = 100f
val currentFrame: Int
Expand All @@ -127,7 +130,11 @@ class GameCharacter(
}
}
"attack-melee-event" -> {
game.gameImports.dprintf("Hit!")
val aim = floatArrayOf(GameDefines.MELEE_DISTANCE.toFloat(), 0f, 0f)
if (GameWeapon.fire_hit(self, aim, 5 + Lib.rand() % 5, 50, game)) { // fixme: assumes self.enemy is set
game.gameImports.sound(self, Defines.CHAN_WEAPON, soundHit, 1f, Defines.ATTN_NORM.toFloat(), 0f)
}

}
"sound-fidget-event" -> sound(soundFidget)
"sound-pain-event" -> sound(soundPain)
Expand Down

0 comments on commit 2b80649

Please sign in to comment.