"mult" renamed to "buff" to prevent confusion with pre-calculated "mult" (character variants)

Former-commit-id: 104d0a57bc67491427d823c2f91688c85e8841c5
Former-commit-id: 5a835c7a759006df25d8783f4f97b568a1517104
This commit is contained in:
Song Minjae
2016-12-27 21:56:03 +09:00
parent bb63816201
commit c77a89d0db
5 changed files with 72 additions and 60 deletions

View File

@@ -6,38 +6,39 @@ package net.torvald.terrarum.gameactors
* Created by minjaesong on 16-04-02. * Created by minjaesong on 16-04-02.
*/ */
object AVKey { object AVKey {
const val MULT = "mult" const val BUFF = "buff"
/** pixels per frame /** pixels per frame
* walking/running speed * walking/running speed
*/ */
const val SPEED = "speed" const val SPEED = "speed"
const val SPEEDMULT = "$SPEED$MULT" const val SPEEDBUFF = "$SPEED$BUFF"
/** pixels per frame squared /** pixels per frame squared
* acceleration of the movement (e.g. running, flying, driving, etc.) * acceleration of the movement (e.g. running, flying, driving, etc.)
*/ */
const val ACCEL = "accel" const val ACCEL = "accel"
const val ACCELMULT = "$ACCEL$MULT" const val ACCELBUFF = "$ACCEL$BUFF"
const val SCALE = "scale" const val SCALE = "scale"
const val SCALEBUFF = "$SCALE$BUFF" // aka PHYSIQUE
/** pixels */ /** pixels */
const val BASEHEIGHT = "baseheight" const val BASEHEIGHT = "baseheight"
/** kilogrammes */ /** kilogrammes */
const val BASEMASS = "basemass" const val BASEMASS = "basemass"
/** pixels per frame */ /** pixels per frame */
const val JUMPPOWER = "jumppower" const val JUMPPOWER = "jumppower"
const val JUMPPOWERMULT = "$JUMPPOWER$MULT" const val JUMPPOWERBUFF = "$JUMPPOWER$BUFF"
/** Int /** Int
* "Default" value of 1 000 * "Default" value of 1 000
*/ */
const val STRENGTH = "strength" const val STRENGTH = "strength"
const val STRENGTHBUFF = "$STRENGTH$BUFF"
const val ENCUMBRANCE = "encumbrance" const val ENCUMBRANCE = "encumbrance"
/** 30-bit RGB (Int) /** 30-bit RGB (Int)
* 0000 0010000000 0010000000 0010000000 * 0000 0010000000 0010000000 0010000000
* ^ Red ^ Green ^ Blue * ^ Red ^ Green ^ Blue
*/ */
const val LUMINOSITY = "luminosity" const val LUMINOSITY = "luminosity"
const val PHYSIQUEMULT = "physique$MULT"
const val DRAGCOEFF = "dragcoeff" const val DRAGCOEFF = "dragcoeff"
/** String /** String
@@ -46,7 +47,7 @@ object AVKey {
const val NAME = "name" const val NAME = "name"
/** String /** String
* e.g. Duudson * e.g. Duudsoni
*/ */
const val RACENAME = "racename" const val RACENAME = "racename"
/** String /** String
@@ -72,10 +73,10 @@ object AVKey {
* current defence point of worn armour(s) * current defence point of worn armour(s)
*/ */
const val ARMOURDEFENCE = "armourdefence" const val ARMOURDEFENCE = "armourdefence"
const val ARMOURDEFENCEMULT = "$ARMOURDEFENCE$MULT" const val ARMOURDEFENCEBUFF = "$ARMOURDEFENCE$BUFF"
const val MAGICREGENRATE = "magicregenrate" const val MAGICREGENRATE = "magicregenrate"
const val MAGICREGENRATEMULT = "$MAGICREGENRATE$MULT" const val MAGICREGENRATEBUFF = "$MAGICREGENRATE$BUFF"
/** String /** String

View File

@@ -219,14 +219,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.ACCELMULT] = 1.0 actorValue[AVKey.ACCELBUFF] = 1.0
} }
else { else {
actorValue[AVKey.ACCELMULT] = ACCEL_MULT_IN_FLIGHT actorValue[AVKey.ACCELBUFF] = ACCEL_MULT_IN_FLIGHT
} }
} }
else { else {
actorValue[AVKey.ACCELMULT] = 1.0 actorValue[AVKey.ACCELBUFF] = 1.0
} }
} }
@@ -382,23 +382,15 @@ open class ActorHumanoid(birth: GameDate, death: GameDate? = null)
private fun walkHorizontal(left: Boolean, absAxisVal: Float) { private fun walkHorizontal(left: Boolean, absAxisVal: Float) {
if ((!walledLeft && left) || (!walledRight && !left)) { if ((!walledLeft && left) || (!walledRight && !left)) {
readonly_totalX = readonly_totalX =
absMax(// keyboard absMax( // keyboard
actorValue.getAsDouble(AVKey.ACCEL)!! * avAcceleration * applyVelo(walkCounterX) * (if (left) -1f else 1f),
actorValue.getAsDouble(AVKey.ACCELMULT)!! * // gamepad
Math.sqrt(scale) * avAcceleration * (if (left) -1f else 1f) * absAxisVal
applyVelo(walkCounterX) *
(if (left) -1f else 1f)
, // gamepad
actorValue.getAsDouble(AVKey.ACCEL)!! *
actorValue.getAsDouble(AVKey.ACCELMULT)!! *
Math.sqrt(scale) *
(if (left) -1f else 1f) * absAxisVal
// do not add applyVelo(walkCounterY) here, as it prevents player from moving with gamepad
) )
//applyForce(Vector2(readonly_totalX, 0.0)) //applyForce(Vector2(readonly_totalX, 0.0))
walkX += readonly_totalX walkX += readonly_totalX
walkX = absClamp(walkX, actorValue.getAsDouble(AVKey.SPEED)!! * actorValue.getAsDouble(AVKey.SPEEDMULT)!!) walkX = walkX.bipolarClamp(avSpeedCap)
walkCounterX += 1 walkCounterX += 1
@@ -420,21 +412,14 @@ open class ActorHumanoid(birth: GameDate, death: GameDate? = null)
*/ */
private fun walkVertical(up: Boolean, absAxisVal: Float) { private fun walkVertical(up: Boolean, absAxisVal: Float) {
readonly_totalY = readonly_totalY =
absMax(// keyboard absMax( // keyboard
actorValue.getAsDouble(AVKey.ACCEL)!! * avAcceleration * applyVelo(walkCounterY) * (if (up) -1f else 1f),
actorValue.getAsDouble(AVKey.ACCELMULT)!! * // gamepad
Math.sqrt(scale) * avAcceleration * (if (up) -1f else 1f) * absAxisVal
applyVelo(walkCounterY) *
(if (up) -1f else 1f)
, // gamepad
actorValue.getAsDouble(AVKey.ACCEL)!! *
actorValue.getAsDouble(AVKey.ACCELMULT)!! *
Math.sqrt(scale) *
(if (up) -1f else 1f) * absAxisVal
) )
walkY += readonly_totalY walkY += readonly_totalY
walkY = absClamp(walkY, actorValue.getAsDouble(AVKey.SPEED)!! * actorValue.getAsDouble(AVKey.SPEEDMULT)!!) walkY = walkY.bipolarClamp(avSpeedCap)
walkCounterY += 1 walkCounterY += 1
@@ -472,7 +457,7 @@ open class ActorHumanoid(birth: GameDate, death: GameDate? = null)
*/ */
private fun jump() { private fun jump() {
val len = MAX_JUMP_LENGTH.toFloat() val len = MAX_JUMP_LENGTH.toFloat()
val pwr = actorValue.getAsDouble(AVKey.JUMPPOWER)!! * (actorValue.getAsDouble(AVKey.JUMPPOWERMULT) ?: 1.0) val pwr = actorValue.getAsDouble(AVKey.JUMPPOWER)!! * (actorValue.getAsDouble(AVKey.JUMPPOWERBUFF) ?: 1.0)
val jumpLinearThre = 0.08 val jumpLinearThre = 0.08
fun jumpFunc(x: Int): Double { fun jumpFunc(x: Int): Double {
@@ -511,15 +496,6 @@ open class ActorHumanoid(birth: GameDate, death: GameDate? = null)
return input.isKeyDown(KeyMap.getKeyCode(fn)) return input.isKeyDown(KeyMap.getKeyCode(fn))
} }
private fun absClamp(i: Double, ceil: Double): Double {
if (i > 0)
return if (i > ceil) ceil else i
else if (i < 0)
return if (-i > ceil) -ceil else i
else
return 0.0
}
fun isNoClip(): Boolean { fun isNoClip(): Boolean {
return noClip return noClip
} }

View File

@@ -23,6 +23,10 @@ import java.util.*
*/ */
open class ActorWithBody : Actor() { open class ActorWithBody : Actor() {
/** !! ActorValue macros are on the very bottom of the source !! **/
override var actorValue: ActorValue = ActorValue() override var actorValue: ActorValue = ActorValue()
@Transient internal var sprite: SpriteAnimation? = null @Transient internal var sprite: SpriteAnimation? = null
@@ -93,10 +97,13 @@ open class ActorWithBody : Actor() {
/** /**
* Physical properties. * Physical properties.
*/ */
/** Apparent scale. Use "avBaseScale" for base scale */
var scale: Double var scale: Double
get() = actorValue.getAsDouble(AVKey.SCALE) ?: 1.0 get() = (actorValue.getAsDouble(AVKey.SCALE) ?: 1.0) *
set(value) = actorValue.set(AVKey.SCALE, value) (actorValue.getAsDouble(AVKey.SCALEBUFF) ?: 1.0)
set(value) = actorValue.set(AVKey.SCALE, value / (actorValue.getAsDouble(AVKey.SCALEBUFF) ?: 1.0))
@Transient val MASS_LOWEST = 0.1 // Kilograms @Transient val MASS_LOWEST = 0.1 // Kilograms
/** Apparent mass. Use "avBaseMass" for base mass */
var mass: Double var mass: Double
get() = actorValue.getAsDouble(AVKey.BASEMASS) ?: MASS_DEFAULT * Math.pow(scale, 3.0) get() = actorValue.getAsDouble(AVKey.BASEMASS) ?: MASS_DEFAULT * Math.pow(scale, 3.0)
set(value) { set(value) {
@@ -107,7 +114,7 @@ open class ActorWithBody : Actor() {
actorValue[AVKey.BASEMASS] = MASS_LOWEST actorValue[AVKey.BASEMASS] = MASS_LOWEST
} }
actorValue[AVKey.BASEMASS] = value actorValue[AVKey.BASEMASS] = value / Math.pow(scale, 3.0)
} }
@Transient private val MASS_DEFAULT: Double = 60.0 @Transient private val MASS_DEFAULT: Double = 60.0
/** Valid range: [0, 1] */ /** Valid range: [0, 1] */
@@ -1134,16 +1141,45 @@ open class ActorWithBody : Actor() {
return if (Math.abs(x) > ceil) ceil else x return if (Math.abs(x) > ceil) ceil else x
} }
} }
// gameplay-related actorvalue macros
var avBaseScale: Double // use canonical "scale" for apparent scale (base * buff)
get() = actorValue.getAsDouble(AVKey.SCALE) ?: 1.0
set(value) { actorValue[AVKey.SCALE] = value }
/** Apparent strength */
var avStrength: Double
get() = (actorValue.getAsDouble(AVKey.STRENGTH) ?: 0.0) *
(actorValue.getAsDouble(AVKey.STRENGTHBUFF) ?: 0.0) * scale
set(value) {
actorValue[AVKey.STRENGTH] =
value /
((actorValue.getAsDouble(AVKey.STRENGTHBUFF) ?: 1.0) * (avBaseStrength ?: 1.0))
}
var avBaseStrength: Double?
get() = actorValue.getAsDouble(AVKey.STRENGTH)
set(value) { actorValue[AVKey.STRENGTH] = value!! }
var avBaseMass: Double
get() = actorValue.getAsDouble(AVKey.BASEMASS) ?: MASS_DEFAULT
set(value) { actorValue[AVKey.BASEMASS] = value }
val avAcceleration: Double
get() = actorValue.getAsDouble(AVKey.ACCEL)!! *
actorValue.getAsDouble(AVKey.ACCELBUFF)!! *
scale.sqrt()
val avSpeedCap: Double
get() = actorValue.getAsDouble(AVKey.SPEED)!! *
actorValue.getAsDouble(AVKey.SPEEDBUFF)!! *
scale.sqrt()
} }
fun Double.floorInt() = Math.floor(this).toInt() fun Double.floorInt() = Math.floor(this).toInt()
fun Float.floorInt() = FastMath.floor(this).toInt() fun Float.floorInt() = FastMath.floor(this)
fun Float.ceilInt() = FastMath.ceil(this).toInt() fun Float.ceilInt() = FastMath.ceil(this)
fun Double.round() = Math.round(this).toDouble() fun Double.round() = Math.round(this).toDouble()
fun Double.floor() = Math.floor(this) fun Double.floor() = Math.floor(this)
fun Double.ceil() = this.floor() + 1.0 fun Double.ceil() = this.floor() + 1.0
fun Double.roundInt(): Int = Math.round(this).toInt() fun Double.roundInt(): Int = Math.round(this).toInt()
fun Float.roundInt(): Int = Math.round(this).toInt() fun Float.roundInt(): Int = Math.round(this)
fun Double.abs() = Math.abs(this) fun Double.abs() = Math.abs(this)
fun Double.sqr() = this * this fun Double.sqr() = this * this
fun Double.sqrt() = Math.sqrt(this) fun Double.sqrt() = Math.sqrt(this)

View File

@@ -17,7 +17,7 @@ object InjectCreatureRaw {
// FIXME strength not injected properly? // FIXME strength not injected properly?
const val JSONPATH = "./assets/raw/creatures/" const val JSONPATH = "./assets/raw/creatures/"
private const val MULTIPLIER_RAW_ELEM_SUFFIX = AVKey.MULT private const val JSONMULT = "mult" // one appears in JSON files
/** /**
* 'Injects' creature raw ActorValue to the ActorValue reference provided. * 'Injects' creature raw ActorValue to the ActorValue reference provided.
@@ -43,7 +43,7 @@ object InjectCreatureRaw {
setAVBooleans(actorValueRef, elementsBoolean, jsonObj) setAVBooleans(actorValueRef, elementsBoolean, jsonObj)
actorValueRef[AVKey.ACCEL] = ActorHumanoid.WALK_ACCEL_BASE actorValueRef[AVKey.ACCEL] = ActorHumanoid.WALK_ACCEL_BASE
actorValueRef[AVKey.ACCELMULT] = 1.0 actorValueRef[AVKey.ACCELBUFF] = 1.0
} }
/** /**
@@ -60,11 +60,11 @@ object InjectCreatureRaw {
// roll fudge dice and get value [-3, 3] as [0, 6] // roll fudge dice and get value [-3, 3] as [0, 6]
val varSelected = Fudge3(SecureRandom()).rollForArray() val varSelected = Fudge3(SecureRandom()).rollForArray()
// get multiplier from json. Assuming percentile // get multiplier from json. Assuming percentile
val multiplier = jsonObject.get(s + MULTIPLIER_RAW_ELEM_SUFFIX).asJsonArray.get(varSelected).asInt val multiplier = jsonObject.get(s + JSONMULT).asJsonArray.get(varSelected).asInt
val realValue = baseValue * multiplier / 100.0 val realValue = baseValue * multiplier / 100.0
avRef[s] = realValue avRef[s] = realValue
avRef[s + MULTIPLIER_RAW_ELEM_SUFFIX] = 1.0 // use multiplied value as 'base' for all sort of things avRef[s + "buff"] = 1.0 // buffed value: use multiplied value as 'base' for all sort of things
} }
} }
@@ -113,7 +113,6 @@ object InjectCreatureRaw {
/** /**
* Fetch and set actor values that should multiplier be applied to the base value of 1. * Fetch and set actor values that should multiplier be applied to the base value of 1.
* E.g. physiquemult
* @param avRef * @param avRef
* * * *
* @param elemSet * @param elemSet

View File

@@ -39,13 +39,13 @@ object PlayerBuilderSigrid {
p.actorValue = ActorValue() p.actorValue = ActorValue()
p.actorValue[AVKey.SCALE] = 1.0 p.actorValue[AVKey.SCALE] = 1.0
p.actorValue[AVKey.SPEED] = 4.0 p.actorValue[AVKey.SPEED] = 4.0
p.actorValue[AVKey.SPEEDMULT] = 1.0 p.actorValue[AVKey.SPEEDBUFF] = 1.0
p.actorValue[AVKey.ACCEL] = ActorHumanoid.WALK_ACCEL_BASE p.actorValue[AVKey.ACCEL] = ActorHumanoid.WALK_ACCEL_BASE
p.actorValue[AVKey.ACCELMULT] = 1.0 p.actorValue[AVKey.ACCELBUFF] = 1.0
p.actorValue[AVKey.JUMPPOWER] = 5.0 p.actorValue[AVKey.JUMPPOWER] = 5.0
p.actorValue[AVKey.BASEMASS] = 80.0 p.actorValue[AVKey.BASEMASS] = 80.0
p.actorValue[AVKey.PHYSIQUEMULT] = 1 // Constant 1.0 for player, meant to be used by random mobs p.actorValue[AVKey.SCALEBUFF] = 1.0 // Constant 1.0 for player, meant to be used by random mobs
/** /**
* fixed value, or 'base value', from creature strength of Dwarf Fortress. * fixed value, or 'base value', from creature strength of Dwarf Fortress.
* Human race uses 1000. (see CreatureHuman.json) * Human race uses 1000. (see CreatureHuman.json)