more AI, divided ACCELBUFF and ACCELMULT_MOVEMENT

Former-commit-id: f3b4c390c363612dcc58c3d50cb7a47ba7452567
Former-commit-id: 95f71db97104cf55af7aba8e0289eb89efc078a4
This commit is contained in:
Song Minjae
2016-12-29 21:10:42 +09:00
parent 63bc018550
commit f7365ea47b
14 changed files with 72 additions and 39 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -2,6 +2,7 @@ package net.torvald.terrarum
import com.google.gson.JsonPrimitive import com.google.gson.JsonPrimitive
import java.util.* import java.util.*
import java.util.function.Consumer
/** /**
* Created by minjaesong on 15-12-30. * Created by minjaesong on 15-12-30.
@@ -102,4 +103,8 @@ open class KVHashMap {
val keySet: Set<Any> val keySet: Set<Any>
get() = hashMap.keys get() = hashMap.keys
fun remove(key: String) {
hashMap.remove(key, hashMap[key])
}
} }

View File

@@ -4,11 +4,9 @@ import net.torvald.imagefont.GameFontBase
import net.torvald.random.HQRNG import net.torvald.random.HQRNG
import net.torvald.terrarum.audio.AudioResourceLibrary import net.torvald.terrarum.audio.AudioResourceLibrary
import net.torvald.terrarum.concurrent.ThreadPool import net.torvald.terrarum.concurrent.ThreadPool
import net.torvald.terrarum.console.*
import net.torvald.terrarum.gameactors.ActorHumanoid import net.torvald.terrarum.gameactors.ActorHumanoid
import net.torvald.terrarum.gameactors.* import net.torvald.terrarum.gameactors.*
import net.torvald.terrarum.console.Authenticator
import net.torvald.terrarum.console.CommandDict
import net.torvald.terrarum.console.SetGlobalLightOverride
import net.torvald.terrarum.gameactors.physicssolver.CollisionSolver import net.torvald.terrarum.gameactors.physicssolver.CollisionSolver
import net.torvald.terrarum.gamecontroller.GameController import net.torvald.terrarum.gamecontroller.GameController
import net.torvald.terrarum.gamecontroller.Key import net.torvald.terrarum.gamecontroller.Key
@@ -227,6 +225,12 @@ constructor() : BasicGameState() {
debugWindow.update(gc, delta) debugWindow.update(gc, delta)
notifier.update(gc, delta) notifier.update(gc, delta)
// update debuggers using javax.swing //
if (Authenticator.b()) {
AVTracker.update()
ActorsList.update()
}
///////////////////////// /////////////////////////
// app-related updates // // app-related updates //

View File

@@ -224,7 +224,6 @@ constructor(gamename: String) : StateBasedGame(gamename) {
val STATE_ID_TOOL_NOISEGEN = 0x200 val STATE_ID_TOOL_NOISEGEN = 0x200
//var hasController = false
var controller: org.lwjgl.input.Controller? = null var controller: org.lwjgl.input.Controller? = null
private set private set
val CONTROLLER_DEADZONE = 0.1f val CONTROLLER_DEADZONE = 0.1f

View File

@@ -16,7 +16,6 @@ internal object SetAV : ConsoleCommand {
val ccM = GameFontBase.colToCode["m"] val ccM = GameFontBase.colToCode["m"]
override fun printUsage() { override fun printUsage() {
Echo("${ccW}Set actor value of specific target to desired value.") Echo("${ccW}Set actor value of specific target to desired value.")
Echo("${ccW}Usage: ${ccY}setav ${ccG}(id) <av> <val>") Echo("${ccW}Usage: ${ccY}setav ${ccG}(id) <av> <val>")
Echo("${ccW}blank ID for player. Data type will be inferred automatically.") Echo("${ccW}blank ID for player. Data type will be inferred automatically.")

View File

@@ -18,6 +18,8 @@ object AVKey {
*/ */
const val ACCEL = "accel" const val ACCEL = "accel"
const val ACCELBUFF = "$ACCEL$BUFF" const val ACCELBUFF = "$ACCEL$BUFF"
/** internal value used by ActorHumanoid to implement friction in walkfunction */
const val ACCELMULT_MOVEMENT = "__accelmultmvmt"
const val SCALE = "scale" const val SCALE = "scale"
const val SCALEBUFF = "$SCALE$BUFF" // aka PHYSIQUE const val SCALEBUFF = "$SCALE$BUFF" // aka PHYSIQUE
/** pixels */ /** pixels */

View File

@@ -220,14 +220,14 @@ open class ActorHumanoid(birth: GameDate, death: GameDate? = null)
private fun updateMovementControl() { private fun updateMovementControl() {
if (!noClip) { if (!noClip) {
if (grounded) { if (grounded) {
actorValue[AVKey.ACCELBUFF] = 1.0 actorValue[AVKey.ACCELMULT_MOVEMENT] = 1.0
} }
else { else {
actorValue[AVKey.ACCELBUFF] = ACCEL_MULT_IN_FLIGHT actorValue[AVKey.ACCELMULT_MOVEMENT] = ACCEL_MULT_IN_FLIGHT
} }
} }
else { else {
actorValue[AVKey.ACCELBUFF] = 1.0 actorValue[AVKey.ACCELMULT_MOVEMENT] = 1.0
} }
} }

View File

@@ -1165,6 +1165,7 @@ open class ActorWithBody : Actor() {
val avAcceleration: Double val avAcceleration: Double
get() = actorValue.getAsDouble(AVKey.ACCEL)!! * get() = actorValue.getAsDouble(AVKey.ACCEL)!! *
actorValue.getAsDouble(AVKey.ACCELBUFF)!! * actorValue.getAsDouble(AVKey.ACCELBUFF)!! *
(actorValue.getAsDouble(AVKey.ACCELMULT_MOVEMENT) ?: 1.0) *
scale.sqrt() scale.sqrt()
val avSpeedCap: Double val avSpeedCap: Double
get() = actorValue.getAsDouble(AVKey.SPEED)!! * get() = actorValue.getAsDouble(AVKey.SPEED)!! *

View File

@@ -27,14 +27,18 @@ open class HumanoidNPC(luaScript: EncapsulatedString, born: GameDate) : ActorHum
/** /**
* Initialised in init block. * Initialised in init block.
* Use function "function update(delta)" to step the AI. * Use lua function "update(delta)" to step the AI.
*/ */
protected val luaInstance: LuaValue protected val luaInstance: LuaValue
private val aiLuaAPI: AILuaAPI private val aiLuaAPI: AILuaAPI
init { init {
luag["io"] = LuaValue.NIL
luag["os"] = LuaValue.NIL
luag["luajava"] = LuaValue.NIL
aiLuaAPI = AILuaAPI(luag, this) aiLuaAPI = AILuaAPI(luag, this)
// load the script and execute it (initialises target script)
luaInstance = luag.load(luaScript.getString(), luaScript.javaClass.simpleName) luaInstance = luag.load(luaScript.getString(), luaScript.javaClass.simpleName)
luaInstance.call() luaInstance.call()
} }
@@ -77,8 +81,8 @@ open class HumanoidNPC(luaScript: EncapsulatedString, born: GameDate) : ActorHum
override fun update(gc: GameContainer, delta: Int) { override fun update(gc: GameContainer, delta: Int) {
super.update(gc, delta) super.update(gc, delta)
aiLuaAPI.update(delta)
// run "update()" function in the script
luag.get("update").call(delta.toLuaValue()) luag.get("update").call(delta.toLuaValue())
} }

View File

@@ -14,7 +14,7 @@ import org.luaj.vm2.lib.ZeroArgFunction
/** /**
* Created by minjaesong on 16-10-24. * Created by minjaesong on 16-10-24.
*/ */
internal class AILuaAPI(val g: Globals, actor: ActorWithBody) { internal class AILuaAPI(g: Globals, actor: ActorWithBody) {
init { init {
if (actor !is AIControlled) if (actor !is AIControlled)
@@ -36,10 +36,11 @@ internal class AILuaAPI(val g: Globals, actor: ActorWithBody) {
g["ai"]["moveRight"] = MoveRight(actor) g["ai"]["moveRight"] = MoveRight(actor)
g["ai"]["moveTo"] = MoveTo(actor) g["ai"]["moveTo"] = MoveTo(actor)
g["ai"]["jump"] = Jump(actor) g["ai"]["jump"] = Jump(actor)
}
fun update(delta: Int) {
// set up variables g["game"] = LuaValue.tableOf()
g["game"]["version"] = GameVersion()
g["game"]["versionRaw"] = GameVersionRaw()
} }
companion object { companion object {
@@ -47,35 +48,43 @@ internal class AILuaAPI(val g: Globals, actor: ActorWithBody) {
* Reads arbitrary ActorWithBody and returns its information as Lua table * Reads arbitrary ActorWithBody and returns its information as Lua table
*/ */
fun composeActorObject(actor: ActorWithBody): LuaTable { fun composeActorObject(actor: ActorWithBody): LuaTable {
val t = LuaValue.tableOf() val t: LuaTable = LuaValue.tableOf()
t["name"] = actor.actorValue.getAsString(AVKey.NAME) t["name"] = actor.actorValue.getAsString(AVKey.NAME).toLua()
t["posX"] = actor.hitbox.centeredX t["posX"] = actor.hitbox.centeredX.toLua()
t["posY"] = actor.hitbox.centeredY t["posY"] = actor.hitbox.centeredY.toLua()
t["veloX"] = actor.veloX t["veloX"] = actor.veloX.toLua()
t["veloY"] = actor.veloY t["veloY"] = actor.veloY.toLua()
t["width"] = actor.hitbox.width t["width"] = actor.hitbox.width.toLua()
t["height"] = actor.hitbox.height t["height"] = actor.hitbox.height.toLua()
t["mass"] = actor.mass t["mass"] = actor.mass.toLua()
t["collisionType"] = actor.collisionType t["collisionType"] = actor.collisionType.toLua()
t["strength"] = actor.avStrength t["strength"] = actor.avStrength.toLua()
val lumrgb: Int = actor.actorValue.getAsInt(AVKey.LUMINOSITY) ?: 0 val lumrgb: Int = actor.actorValue.getAsInt(AVKey.LUMINOSITY) ?: 0
val MUL_2 = LightmapRenderer.MUL_2 val MUL_2 = LightmapRenderer.MUL_2
val MUL = LightmapRenderer.MUL val MUL = LightmapRenderer.MUL
val CHMAX = LightmapRenderer.CHANNEL_MAX val CHMAX = LightmapRenderer.CHANNEL_MAX
t["luminosityRGB"] = lumrgb t["luminosityRGB"] = lumrgb.toLua()
t["luminosity"] = (lumrgb.div(MUL_2).and(CHMAX).times(3) + t["luminosity"] = (lumrgb.div(MUL_2).and(CHMAX).times(3) +
lumrgb.div(MUL).and(CHMAX).times(4) + lumrgb.div(MUL).and(CHMAX).times(4) +
lumrgb.and(1023)) / 8 // quick luminosity calculation lumrgb.and(1023)).div(8.0).toLua() // quick luminosity calculation
return t return t
} }
fun Double.toLua() = LuaValue.valueOf(this)
fun Int.toLua() = LuaValue.valueOf(this)
fun String.toLua() = LuaValue.valueOf(this)
fun Double?.toLua() = if (this == null) LuaValue.NIL else this.toLua()
fun Int?.toLua() = if (this == null) LuaValue.NIL else this.toLua()
fun String?.toLua() = if (this == null) LuaValue.NIL else this.toLua()
} }
class GetSelfActorInfo(val actor: ActorWithBody) : ZeroArgFunction() { class GetSelfActorInfo(val actor: ActorWithBody) : ZeroArgFunction() {
@@ -203,4 +212,18 @@ internal class AILuaAPI(val g: Globals, actor: ActorWithBody) {
} }
} }
class GameVersion() : ZeroArgFunction() {
override fun call(): LuaValue {
return Terrarum.VERSION_STRING.toLua()
}
}
class GameVersionRaw() : ZeroArgFunction() {
override fun call(): LuaValue {
return Terrarum.VERSION_RAW.toLua()
}
}
} }

View File

@@ -1,6 +1,8 @@
package net.torvald.terrarum.gameactors.ai.scripts package net.torvald.terrarum.gameactors.ai.scripts
/** /**
* Encapsulated text file
*
* Created by SKYHi14 on 2016-12-28. * Created by SKYHi14 on 2016-12-28.
*/ */
abstract class EncapsulatedString { abstract class EncapsulatedString {

View File

@@ -3,19 +3,16 @@ package net.torvald.terrarum.ui
import com.jme3.math.FastMath import com.jme3.math.FastMath
import net.torvald.imagefont.GameFontBase import net.torvald.imagefont.GameFontBase
import net.torvald.terrarum.gameworld.PairedMapLayer import net.torvald.terrarum.gameworld.PairedMapLayer
import net.torvald.terrarum.langpack.Lang
import net.torvald.terrarum.mapdrawer.LightmapRenderer import net.torvald.terrarum.mapdrawer.LightmapRenderer
import net.torvald.terrarum.mapdrawer.MapCamera import net.torvald.terrarum.mapdrawer.MapCamera
import net.torvald.terrarum.mapdrawer.MapDrawer import net.torvald.terrarum.mapdrawer.MapDrawer
import net.torvald.terrarum.Terrarum import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.blendNormal import net.torvald.terrarum.blendNormal
import net.torvald.terrarum.blendScreen import net.torvald.terrarum.blendScreen
import net.torvald.terrarum.gameactors.ActorHumanoid
import org.newdawn.slick.Color import org.newdawn.slick.Color
import org.newdawn.slick.GameContainer import org.newdawn.slick.GameContainer
import org.newdawn.slick.Graphics import org.newdawn.slick.Graphics
import org.newdawn.slick.Input import org.newdawn.slick.Input
import java.util.*
/** /**
* Created by minjaesong on 16-03-14. * Created by minjaesong on 16-03-14.
@@ -63,9 +60,6 @@ class BasicDebugInfoWindow : UICanvas {
val player = Terrarum.ingame.player val player = Terrarum.ingame.player
val sb = StringBuilder()
val formatter = Formatter(sb)
val mouseTileX = ((MapCamera.cameraX + gc.input.mouseX / Terrarum.ingame.screenZoom) / MapDrawer.TILE_SIZE).toInt() val mouseTileX = ((MapCamera.cameraX + gc.input.mouseX / Terrarum.ingame.screenZoom) / MapDrawer.TILE_SIZE).toInt()
val mouseTileY = ((MapCamera.cameraY + gc.input.mouseY / Terrarum.ingame.screenZoom) / MapDrawer.TILE_SIZE).toInt() val mouseTileY = ((MapCamera.cameraY + gc.input.mouseY / Terrarum.ingame.screenZoom) / MapDrawer.TILE_SIZE).toInt()
@@ -112,7 +106,7 @@ class BasicDebugInfoWindow : UICanvas {
val rawB = valRaw.rawB() val rawB = valRaw.rawB()
lightVal = if (valRaw == -1) "" lightVal = if (valRaw == -1) ""
else valRaw.toInt().toString() + " (" + else valRaw.toString() + " (" +
rawR.toString() + " " + rawR.toString() + " " +
rawG.toString() + " " + rawG.toString() + " " +
rawB.toString() + ")" rawB.toString() + ")"
@@ -182,11 +176,11 @@ class BasicDebugInfoWindow : UICanvas {
} }
private fun printLine(g: Graphics, l: Int, s: String) { private fun printLine(g: Graphics, l: Int, s: String) {
g.drawString(s, 10f, line(l).toFloat()) g.drawString(s, 10f, line(l))
} }
private fun printLineColumn(g: Graphics, col: Int, row: Int, s: String) { private fun printLineColumn(g: Graphics, col: Int, row: Int, s: String) {
g.drawString(s, (10 + column(col)).toFloat(), line(row).toFloat()) g.drawString(s, (10 + column(col)), line(row))
} }
val histogramW = 256 val histogramW = 256
@@ -194,9 +188,9 @@ class BasicDebugInfoWindow : UICanvas {
private fun drawHistogram(g: Graphics, histogram: LightmapRenderer.Histogram, x: Int, y: Int) { private fun drawHistogram(g: Graphics, histogram: LightmapRenderer.Histogram, x: Int, y: Int) {
val uiColour = Color(0xAA000000.toInt()) val uiColour = Color(0xAA000000.toInt())
val barR = Color(0xDD0000.toInt()) val barR = Color(0xDD0000)
val barG = Color(0x00DD00.toInt()) val barG = Color(0x00DD00)
val barB = Color(0x0000DD.toInt()) val barB = Color(0x0000DD)
val barColour = arrayOf(barR, barG, barB) val barColour = arrayOf(barR, barG, barB)
val w = histogramW.toFloat() val w = histogramW.toFloat()
val h = histogramH.toFloat() val h = histogramH.toFloat()