dump (another useless message)

This commit is contained in:
minjaesong
2018-08-05 21:57:18 +09:00
parent 24b2e2a2af
commit eee8a18875
130 changed files with 1350 additions and 563 deletions

View File

@@ -0,0 +1,201 @@
package net.torvald.terrarum.modulebasegame
import com.badlogic.gdx.Gdx
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.Texture
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import com.badlogic.gdx.graphics.g2d.TextureRegion
import net.torvald.terrarum.AppLoader
import net.torvald.terrarum.IngameInstance
import net.torvald.terrarum.ModMgr
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.blockproperties.Block
import net.torvald.terrarum.gameactors.*
import net.torvald.terrarum.gameworld.GameWorld
import net.torvald.terrarum.modulebasegame.gameactors.ActorHumanoid
import net.torvald.terrarum.modulebasegame.gameworld.GameWorldExtension
import net.torvald.terrarum.modulebasegame.ui.Notification
import net.torvald.terrarum.modulebasegame.ui.UIBuildingMakerToolbox
import net.torvald.terrarum.ui.UICanvas
import net.torvald.terrarum.worlddrawer.LightmapRenderer
import net.torvald.terrarum.worlddrawer.WorldCamera
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
import kotlin.system.measureNanoTime
/**
* Created by minjaesong on 2018-07-06.
*/
class BuildingMaker(batch: SpriteBatch) : IngameInstance(batch) {
val gameWorld = GameWorldExtension(1024, 256)
init {
// ghetto world for building
println("[BuildingMaker] Generating builder world...")
for (y in 150 until gameWorld.height) {
for (x in 0 until gameWorld.width) {
// wall layer
gameWorld.setTileWall(x, y, Block.DIRT)
// terrain layer
gameWorld.setTileTerrain(x, y, if (y == 150) Block.GRASS else Block.DIRT)
}
}
world = gameWorld
}
override var playableActor: ActorHumanoid = MovableWorldCamera(world)
val uiToolbox = UIBuildingMakerToolbox()
val notifier = Notification()
val uiContainer = ArrayList<UICanvas>()
val blockPointingCursor = object : ActorWithBody(Actor.RenderOrder.FRONT) {
override var referenceID: ActorID? = Terrarum.generateUniqueReferenceID(renderOrder)
val body = TextureRegionPack(Gdx.files.internal("assets/graphics/blocks/block_markings_common.tga"), 16, 16)
override val hitbox = Hitbox(0.0, 0.0, 16.0, 16.0)
override fun drawBody(batch: SpriteBatch) {
batch.color = Color.YELLOW
batch.draw(body.get(0, 0), hitbox.startX.toFloat(), hitbox.startY.toFloat())
}
override fun drawGlow(batch: SpriteBatch) { }
override fun dispose() {
body.dispose()
}
override fun update(delta: Float) {
hitbox.setPosition(
Terrarum.mouseTileX * 16.0,
Terrarum.mouseTileY * 16.0
)
}
override fun onActorValueChange(key: String, value: Any?) { }
override fun run() {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
}
protected var updateDeltaCounter = 0.0
protected val updateRate = 1.0 / Terrarum.TARGET_INTERNAL_FPS
private val actorsRenderTop = ArrayList<ActorWithBody>()
init {
actorsRenderTop.add(blockPointingCursor)
uiContainer.add(uiToolbox)
uiContainer.add(notifier)
uiToolbox.setPosition(Terrarum.WIDTH - 20, 4)
notifier.setPosition(
(Terrarum.WIDTH - notifier.width) / 2, Terrarum.HEIGHT - notifier.height)
playableActor.setPosition(512 * 16.0, 149 * 16.0)
LightmapRenderer.fireRecalculateEvent()
}
override fun render(delta: Float) {
Gdx.graphics.setTitle("${AppLoader.GAME_NAME} Building Maker" +
" — F: ${Gdx.graphics.framesPerSecond} (${Terrarum.TARGET_INTERNAL_FPS})" +
" — M: ${Terrarum.memInUse}M / ${Terrarum.memTotal}M / ${Terrarum.memXmx}M"
)
// ASYNCHRONOUS UPDATE AND RENDER //
/** UPDATE CODE GOES HERE */
updateDeltaCounter += delta
if (false && Terrarum.getConfigBoolean("multithread")) { // NO MULTITHREADING: camera don't like concurrent modification (jittery actor movements)
// else, NOP;
}
else {
var updateTries = 0
while (updateDeltaCounter >= updateRate) {
//updateGame(delta)
Terrarum.debugTimers["Ingame.update"] = measureNanoTime { updateGame(delta) }
updateDeltaCounter -= updateRate
updateTries++
if (updateTries >= Terrarum.UPDATE_CATCHUP_MAX_TRIES) {
break
}
}
}
/** RENDER CODE GOES HERE */
//renderGame(batch)
Terrarum.debugTimers["Ingame.render"] = measureNanoTime { renderGame() }
}
private fun updateGame(delta: Float) {
blockPointingCursor.update(delta)
playableActor.update(delta)
uiContainer.forEach { it.update(delta) }
WorldCamera.update(world, playableActor)
}
private fun renderGame() {
IngameRenderer(world as GameWorldExtension, actorsRenderFront = actorsRenderTop, uisToDraw = uiContainer)
}
override fun resize(width: Int, height: Int) {
IngameRenderer.resize(Terrarum.WIDTH, Terrarum.HEIGHT)
uiToolbox.setPosition(Terrarum.WIDTH - 20, 4)
notifier.setPosition(
(Terrarum.WIDTH - notifier.width) / 2, Terrarum.HEIGHT - notifier.height)
println("[BuildingMaker] Resize event")
}
}
class MovableWorldCamera(world: GameWorld) : ActorHumanoid(world, 0, usePhysics = false) {
init {
referenceID = Terrarum.PLAYER_REF_ID
isNoClip = true
setHitboxDimension(1, 1, 0, 0)
actorValue[AVKey.SPEED] = 8.0
actorValue[AVKey.SPEEDBUFF] = 1.0
actorValue[AVKey.ACCEL] = ActorHumanoid.WALK_ACCEL_BASE
actorValue[AVKey.ACCELBUFF] = 1.0
actorValue[AVKey.JUMPPOWER] = 0.0
}
override fun drawBody(batch: SpriteBatch) {
}
override fun drawGlow(batch: SpriteBatch) {
}
override fun onActorValueChange(key: String, value: Any?) {
}
}

View File

@@ -1,6 +1,6 @@
package net.torvald.terrarum.modulebasegame
import net.torvald.point.Point2d
import net.torvald.terrarum.Point2d
import net.torvald.terrarum.ModMgr
import net.torvald.terrarum.ModuleEntryPoint
import net.torvald.terrarum.Terrarum
@@ -8,7 +8,7 @@ import net.torvald.terrarum.blockproperties.BlockCodex
import net.torvald.terrarum.itemproperties.GameItem
import net.torvald.terrarum.itemproperties.ItemCodex
import net.torvald.terrarum.itemproperties.Material
import net.torvald.terrarum.modulebasegame.gameactors.ActorWithPhysics
import net.torvald.terrarum.gameactors.ActorWBMovable
/**
* Created by minjaesong on 2018-06-21.
@@ -61,7 +61,7 @@ class EntryPoint : ModuleEntryPoint() {
// check for collision with actors (BLOCK only)
if (this.inventoryCategory == Category.BLOCK) {
ingame.actorContainer.forEach {
if (it is ActorWithPhysics && it.hIntTilewiseHitbox.intersects(mousePoint))
if (it is ActorWBMovable && it.hIntTilewiseHitbox.intersects(mousePoint))
return false
}
}

View File

@@ -1,11 +1,8 @@
package net.torvald.terrarum.modulebasegame
import com.badlogic.gdx.Gdx
import com.badlogic.gdx.Input
import com.badlogic.gdx.Screen
import com.badlogic.gdx.graphics.*
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import com.badlogic.gdx.graphics.glutils.FrameBuffer
import net.torvald.dataclass.CircularArray
import net.torvald.terrarum.blockproperties.BlockPropUtil
@@ -18,28 +15,24 @@ import net.torvald.terrarum.gamecontroller.IngameController
import net.torvald.terrarum.gamecontroller.KeyToggler
import net.torvald.terrarum.gameworld.GameWorld
import net.torvald.terrarum.modulebasegame.gameworld.WorldSimulator
import net.torvald.terrarum.weather.WeatherMixer
import net.torvald.terrarum.modulebasegame.weather.WeatherMixer
import net.torvald.terrarum.worlddrawer.BlocksDrawer
import net.torvald.terrarum.worlddrawer.FeaturesDrawer
import net.torvald.terrarum.worlddrawer.LightmapRenderer
import net.torvald.terrarum.worlddrawer.WorldCamera
import java.util.ArrayList
import java.util.concurrent.locks.Lock
import java.util.concurrent.locks.ReentrantLock
import javax.swing.JOptionPane
import com.badlogic.gdx.graphics.OrthographicCamera
import net.torvald.random.HQRNG
import net.torvald.terrarum.*
import net.torvald.terrarum.gameworld.fmod
import net.torvald.terrarum.modulebasegame.console.AVTracker
import net.torvald.terrarum.modulebasegame.console.ActorsList
import net.torvald.terrarum.console.Authenticator
import net.torvald.terrarum.console.SetGlobalLightOverride
import net.torvald.terrarum.itemproperties.ItemCodex
import net.torvald.terrarum.modulebasegame.gameactors.*
import net.torvald.terrarum.modulebasegame.gameworld.GameWorldExtension
import net.torvald.terrarum.modulebasegame.imagefont.Watch7SegMain
import net.torvald.terrarum.modulebasegame.imagefont.WatchDotAlph
import net.torvald.terrarum.modulebasegame.ui.*
@@ -53,14 +46,16 @@ import kotlin.system.measureNanoTime
* Created by minjaesong on 2017-06-16.
*/
class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
open class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
private val ACTOR_UPDATE_RANGE = 4096
lateinit var world: GameWorld
lateinit var historicalFigureIDBucket: ArrayList<Int>
lateinit var gameworld: GameWorldExtension
lateinit var theRealGamer: IngamePlayer
/**
* list of Actors that is sorted by Actors' referenceID
*/
@@ -76,55 +71,18 @@ class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
private val actorsRenderMidTop = ArrayList<ActorWithBody>(ACTORCONTAINER_INITIAL_SIZE)
private val actorsRenderFront = ArrayList<ActorWithBody>(ACTORCONTAINER_INITIAL_SIZE)
lateinit var playableActorDelegate: PlayableActorDelegate // player must exist; use dummy player if there is none (required for camera)
private set
inline val player: ActorHumanoid // currently POSSESSED actor :)
get() = playableActorDelegate.actor
//var screenZoom = 1.0f // definition moved to IngameInstance
//val ZOOM_MAXIMUM = 4.0f // definition moved to IngameInstance
//val ZOOM_MINIMUM = 0.5f // definition moved to IngameInstance
companion object {
//val lightmapDownsample = 4f //2f: still has choppy look when the camera moves but unnoticeable when blurred
/** Sets camera position so that (0,0) would be top-left of the screen, (width, height) be bottom-right. */
fun setCameraPosition(batch: SpriteBatch, camera: Camera, newX: Float, newY: Float) {
camera.position.set((-newX + Terrarum.HALFW).round(), (-newY + Terrarum.HALFH).round(), 0f)
camera.update()
batch.projectionMatrix = camera.combined
}
/**
* Usage:
*
* override var referenceID: Int = generateUniqueReferenceID()
*/
fun generateUniqueReferenceID(renderOrder: Actor.RenderOrder): ActorID {
fun hasCollision(value: ActorID) =
try {
Terrarum.ingame!!.theGameHasActor(value) ||
value < ItemCodex.ACTORID_MIN ||
value !in when (renderOrder) {
Actor.RenderOrder.BEHIND -> Actor.RANGE_BEHIND
Actor.RenderOrder.MIDDLE -> Actor.RANGE_MIDDLE
Actor.RenderOrder.MIDTOP -> Actor.RANGE_MIDTOP
Actor.RenderOrder.FRONT -> Actor.RANGE_FRONT
}
}
catch (gameNotInitialisedException: KotlinNullPointerException) {
false
}
var ret: Int
do {
ret = HQRNG().nextInt().and(0x7FFFFFFF) // set new ID
} while (hasCollision(ret)) // check for collision
return ret
}
}
@@ -134,13 +92,6 @@ class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
private val useShader: Boolean = false
private val shaderProgram = 0
val KEY_LIGHTMAP_RENDER = Input.Keys.F7
lateinit var debugWindow: UICanvas
lateinit var notifier: UICanvas
@@ -213,7 +164,7 @@ class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
GameLoadMode.LOAD_FROM -> enter(gameLoadInfoPayload as GameSaveData)
}
LightmapRenderer.world = this.world
//LightmapRenderer.world = this.world
//BlocksDrawer.world = this.world
FeaturesDrawer.world = this.world
@@ -221,9 +172,9 @@ class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
}
data class GameSaveData(
val world: GameWorld,
val world: GameWorldExtension,
val historicalFigureIDBucket: ArrayList<Int>,
val realGamePlayer: ActorHumanoid
val realGamePlayer: IngamePlayer
)
data class NewWorldParameters(
@@ -244,10 +195,12 @@ class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
LoadScreen.addMessage("Loading world from save")
world = gameSaveData.world
gameworld = gameSaveData.world
world = gameworld
historicalFigureIDBucket = gameSaveData.historicalFigureIDBucket
playableActorDelegate = PlayableActorDelegate(gameSaveData.realGamePlayer)
addNewActor(player)
theRealGamer = gameSaveData.realGamePlayer
playableActor = gameSaveData.realGamePlayer
addNewActor(playableActor)
@@ -268,7 +221,8 @@ class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
// init map as chosen size
world = GameWorld(worldParams.width, worldParams.height)
gameworld = GameWorldExtension(worldParams.width, worldParams.height)
world = gameworld as GameWorld
// generate terrain for the map
WorldGenerator.attachMap(world)
@@ -301,7 +255,7 @@ class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
/** Load rest of the game with GL context */
fun postInit() {
//LightmapRenderer.world = this.world
BlocksDrawer.world = this.world
//BlocksDrawer.world = this.world
//FeaturesDrawer.world = this.world
@@ -342,7 +296,7 @@ class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
-uiInventoryPlayer.width,
70
)*/
uiInventoryPlayer = UIInventoryFull(player,
uiInventoryPlayer = UIInventoryFull(playableActor,
toggleKeyLiteral = Terrarum.getConfigInt("keyinventory")
)
uiInventoryPlayer.setPosition(0, 0)
@@ -368,11 +322,11 @@ class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
//uiVitalItem.setAsAlwaysVisible()
// basic watch-style notification bar (temperature, new mail)
uiWatchBasic = UIBasicNotifier(player)
uiWatchBasic = UIBasicNotifier(playableActor)
uiWatchBasic.setAsAlwaysVisible()
uiWatchBasic.setPosition(Terrarum.WIDTH - uiWatchBasic.width, 0)
uiWatchTierOne = UITierOneWatch(player)
uiWatchTierOne = UITierOneWatch(playableActor)
uiWatchTierOne.setAsAlwaysVisible()
uiWatchTierOne.setPosition(Terrarum.WIDTH - uiWatchTierOne.width, uiWatchBasic.height - 2)
@@ -460,15 +414,15 @@ class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
if (!gameFullyLoaded) {
if (gameLoadMode == GameLoadMode.CREATE_NEW) {
playableActorDelegate = PlayableActorDelegate(PlayerBuilderSigrid())
playableActor = PlayerBuilderSigrid()
// go to spawn position
player.setPosition(
playableActor.setPosition(
world.spawnX * FeaturesDrawer.TILE_SIZE.toDouble(),
world.spawnY * FeaturesDrawer.TILE_SIZE.toDouble()
)
addNewActor(player)
addNewActor(playableActor)
}
postInit()
@@ -527,6 +481,8 @@ class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
}
protected fun updateGame(delta: Float) {
val world = this.world as GameWorldExtension
particlesActive = 0
@@ -542,17 +498,17 @@ class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
BlockPropUtil.dynamicLumFuncTickClock()
world.updateWorldTime(delta)
//WorldSimulator(player, delta)
WeatherMixer.update(delta, player)
WeatherMixer.update(delta, playableActor)
BlockStats.update()
if (!(CommandDict["setgl"] as SetGlobalLightOverride).lightOverride)
world.globalLight = WeatherMixer.globalLightNow
gameworld.globalLight = WeatherMixer.globalLightNow
////////////////////////////
// camera-related updates //
////////////////////////////
FeaturesDrawer.update(delta)
WorldCamera.update(world, player)
WorldCamera.update(gameworld, playableActor)
@@ -589,13 +545,13 @@ class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
private fun renderGame() {
IngameRenderer.invoke(
world,
world as GameWorldExtension,
actorsRenderBehind,
actorsRenderMiddle,
actorsRenderMidTop,
actorsRenderFront,
particlesContainer,
player,
playableActor,
uiContainer
)
}
@@ -603,39 +559,32 @@ class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
private fun repossessActor() {
// check if currently pocessed actor is removed from game
if (!theGameHasActor(player)) {
if (!theGameHasActor(playableActor)) {
// re-possess canonical player
if (theGameHasActor(Player.PLAYER_REF_ID))
changePossession(Player.PLAYER_REF_ID)
if (theGameHasActor(Terrarum.PLAYER_REF_ID))
changePossession(Terrarum.PLAYER_REF_ID)
else
changePossession(0x51621D) // FIXME fallback debug mode (FIXME is there for a reminder visible in ya IDE)
}
}
private fun changePossession(newActor: PlayableActorDelegate) {
if (!theGameHasActor(player)) {
private fun changePossession(newActor: ActorHumanoid) {
if (!theGameHasActor(playableActor)) {
throw IllegalArgumentException("No such actor in the game: $newActor")
}
playableActorDelegate = newActor
WorldSimulator(player, Terrarum.deltaTime)
playableActor = newActor
WorldSimulator(playableActor, Terrarum.deltaTime)
}
private fun changePossession(refid: Int) {
// TODO prevent possessing other player on multiplayer
val actorToChange = getActorByID(refid)
if (!theGameHasActor(refid)) {
throw IllegalArgumentException(
"No such actor in the game: $refid (elemsActive: ${actorContainer.size}, " +
"elemsInactive: ${actorContainerInactive.size})")
if (actorToChange !is ActorHumanoid) {
throw Error("Unpossessable actor $refid: type expected ActorHumanoid, got ${actorToChange.javaClass.canonicalName}")
}
// take care of old delegate
playableActorDelegate!!.actor.collisionType = HumanoidNPC.DEFAULT_COLLISION_TYPE
// accept new delegate
playableActorDelegate = PlayableActorDelegate(getActorByID(refid) as ActorHumanoid)
playableActorDelegate!!.actor.collisionType = ActorWithPhysics.COLLISION_KINEMATIC
WorldSimulator(player, Terrarum.deltaTime)
changePossession(getActorByID(refid) as ActorHumanoid)
}
/** Send message to notifier UI and toggle the UI as opened. */
@@ -709,11 +658,11 @@ class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
ThreadParallel.startAll()
playableActorDelegate?.update(delta)
playableActor.update(delta)
}
else {
actorContainer.forEach {
if (it != playableActorDelegate?.actor) {
if (it != playableActor) {
it.update(delta)
if (it is Pocketed) {
@@ -726,7 +675,7 @@ class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
}
}
}
playableActorDelegate?.update(delta)
playableActor.update(delta)
//AmmoMeterProxy(player, uiVitalItem.UI as UIVitalMetre)
}
}
@@ -779,7 +728,7 @@ class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
* This is how remove function of [java.util.ArrayList] is defined.
*/
override fun removeActor(actor: Actor) {
if (actor.referenceID == player.referenceID || actor.referenceID == 0x51621D) // do not delete this magic
if (actor.referenceID == theRealGamer.referenceID || actor.referenceID == 0x51621D) // do not delete this magic
throw RuntimeException("Attempted to remove player.")
val indexToDelete = actorContainer.binarySearch(actor.referenceID!!)
if (indexToDelete >= 0) {
@@ -929,8 +878,6 @@ class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
*/
override fun resize(width: Int, height: Int) {
BlocksDrawer.resize(Terrarum.WIDTH, Terrarum.HEIGHT)
LightmapRenderer.resize(Terrarum.WIDTH, Terrarum.HEIGHT)
MegaRainGovernor.resize()

View File

@@ -13,8 +13,9 @@ import net.torvald.terrarum.gameworld.GameWorld
import net.torvald.terrarum.gameworld.fmod
import net.torvald.terrarum.modulebasegame.gameactors.ActorHumanoid
import net.torvald.terrarum.modulebasegame.gameactors.ParticleBase
import net.torvald.terrarum.modulebasegame.gameworld.GameWorldExtension
import net.torvald.terrarum.ui.UICanvas
import net.torvald.terrarum.weather.WeatherMixer
import net.torvald.terrarum.modulebasegame.weather.WeatherMixer
import net.torvald.terrarum.worlddrawer.BlocksDrawer
import net.torvald.terrarum.worlddrawer.FeaturesDrawer
import net.torvald.terrarum.worlddrawer.LightmapRenderer
@@ -50,7 +51,7 @@ object IngameRenderer {
private var initDone = false
private var player: ActorHumanoid? = null
private var player: ActorWithBody? = null
var uiListToDraw = ArrayList<UICanvas>()
@@ -59,13 +60,13 @@ object IngameRenderer {
private var debugMode = 0
operator fun invoke(
world: GameWorld,
world: GameWorldExtension,
actorsRenderBehind: List<ActorWithBody>? = null,
actorsRenderMiddle: List<ActorWithBody>? = null,
actorsRenderMidTop: List<ActorWithBody>? = null,
actorsRenderFront : List<ActorWithBody>? = null,
particlesContainer: CircularArray<ParticleBase>? = null,
player: ActorHumanoid? = null,
player: ActorWithBody? = null,
uisToDraw: ArrayList<UICanvas>? = null
) {
@@ -77,8 +78,6 @@ object IngameRenderer {
this.player = player
LightmapRenderer.fireRecalculateEvent()
prepLightmapRGBA()
@@ -141,7 +140,7 @@ object IngameRenderer {
batch.fillRect(0f, 0f, 6f, 10f)
batch.color = Color.LIME
batch.fillRect(6f, 0f, 6f, 10f)
batch.color = Color.BLUE
batch.color = Color.ROYAL
batch.fillRect(12f, 0f, 6f, 10f)
batch.color = Color.WHITE
}
@@ -390,7 +389,7 @@ object IngameRenderer {
}
private fun init(world: GameWorld) {
private fun init(world: GameWorldExtension) {
if (!initDone) {
batch = SpriteBatch()
camera = OrthographicCamera(widthf, heightf)
@@ -401,13 +400,13 @@ object IngameRenderer {
resize(width, height)
LightmapRenderer.world = world
initDone = true
}
BlocksDrawer.world = world
LightmapRenderer.setWorld(world)
FeaturesDrawer.world = world
}
private fun clearBuffer() {
@@ -513,6 +512,9 @@ object IngameRenderer {
BlocksDrawer.resize(width, height)
LightmapRenderer.resize(width, height)
//LightmapRenderer.fireRecalculateEvent()
}
private val TILE_SIZEF = FeaturesDrawer.TILE_SIZE.toFloat()

View File

@@ -16,7 +16,7 @@ internal object AVTracker : ConsoleCommand {
override fun execute(args: Array<String>) {
if (args.size < 2) {
jPanelInstances.add(ActorValueTracker((Terrarum.ingame!! as Ingame).player))
jPanelInstances.add(ActorValueTracker((Terrarum.ingame!! as Ingame).playableActor))
}
else {
try {

View File

@@ -16,7 +16,7 @@ internal object ExportAV : ConsoleCommand {
if (args.size == 2) {
try {
JsonWriter.writeToFile(
(Terrarum.ingame!! as Ingame).player.actorValue,
(Terrarum.ingame!! as Ingame).playableActor.actorValue,
Terrarum.defaultDir + "/Exports/" + args[1] + ".json")
Echo("ExportAV: exported to " + args[1] + ".json")

View File

@@ -62,7 +62,7 @@ internal object ExportMap : ConsoleCommand {
}
override fun execute(args: Array<String>) {
val world = (Terrarum.ingame!! as Ingame).world
val world = (Terrarum.ingame!!.world)
if (args.size == 2) {

View File

@@ -17,9 +17,9 @@ internal object GetAV : ConsoleCommand {
val ingame = Terrarum.ingame!! as Ingame
if (args.size == 1 && ingame.player != null) {
if (args.size == 1 && ingame.playableActor != null) {
// print all actorvalue of player
val av = ingame.player.actorValue
val av = ingame.playableActor.actorValue
val keyset = av.keySet
Echo("$ccW== ActorValue list for ${ccY}player $ccW==")
@@ -37,14 +37,14 @@ internal object GetAV : ConsoleCommand {
if (!args[1].isNum()) { // args[1] is ActorValue name
Echo("${ccW}player.$ccM${args[1]} $ccW= " +
ccG +
ingame.player.actorValue[args[1]] +
ingame.playableActor.actorValue[args[1]] +
" $ccO" +
ingame.player.actorValue[args[1]]!!.javaClass.simpleName
ingame.playableActor.actorValue[args[1]]!!.javaClass.simpleName
)
println("[GetAV] player.${args[1]} = " +
ingame.player.actorValue[args[1]] +
ingame.playableActor.actorValue[args[1]] +
" " +
ingame.player.actorValue[args[1]]!!.javaClass.simpleName
ingame.playableActor.actorValue[args[1]]!!.javaClass.simpleName
)
}
else {

View File

@@ -6,8 +6,7 @@ import net.torvald.terrarum.console.ConsoleCommand
import net.torvald.terrarum.console.Echo
import net.torvald.terrarum.console.EchoError
import net.torvald.terrarum.gameactors.Factionable
import net.torvald.terrarum.modulebasegame.Ingame
import net.torvald.terrarum.modulebasegame.gameactors.Player
import net.torvald.terrarum.modulebasegame.gameactors.IngamePlayer
import net.torvald.terrarumsansbitmap.gdx.GameFontBase
/**
@@ -29,8 +28,8 @@ internal object GetFactioning : ConsoleCommand {
fun printOutFactioning(id: Int) {
val a = Terrarum.ingame!!.getActorByID(id)
if (a is Factionable) {
Echo("$ccW== Faction assignment for $ccY${if (id == Player.PLAYER_REF_ID) "player" else id.toString()} $ccW==")
println("[GetFactioning] == Faction assignment for '${if (id == Player.PLAYER_REF_ID) "player" else id.toString()}' ==")
Echo("$ccW== Faction assignment for $ccY${if (id == Terrarum.PLAYER_REF_ID) "player" else id.toString()} $ccW==")
println("[GetFactioning] == Faction assignment for '${if (id == Terrarum.PLAYER_REF_ID) "player" else id.toString()}' ==")
// get all factioning data of player
val factionSet = a.faction
@@ -84,7 +83,7 @@ internal object GetFactioning : ConsoleCommand {
}
if (args.size == 1) {
printOutFactioning(Player.PLAYER_REF_ID)
printOutFactioning(Terrarum.PLAYER_REF_ID)
}
else {
if (!args[1].isNum()) {

View File

@@ -3,7 +3,7 @@ package net.torvald.terrarum.modulebasegame.console
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.console.ConsoleCommand
import net.torvald.terrarum.console.Echo
import net.torvald.terrarum.modulebasegame.Ingame
import net.torvald.terrarum.modulebasegame.gameworld.GameWorldExtension
/**
* Created by minjaesong on 2016-03-20.
@@ -11,7 +11,7 @@ import net.torvald.terrarum.modulebasegame.Ingame
internal object GetTime : ConsoleCommand {
override fun execute(args: Array<String>) {
val worldTime = (Terrarum.ingame!! as Ingame).world.time
val worldTime = (Terrarum.ingame!!.world as GameWorldExtension).time
Echo(worldTime.getFormattedTime())
}

View File

@@ -16,7 +16,7 @@ import java.io.IOException
internal object GsonTest : ConsoleCommand {
override fun execute(args: Array<String>) {
if (args.size == 2) {
val avelem = Gson().toJsonTree((Terrarum.ingame!! as Ingame).player)
val avelem = Gson().toJsonTree((Terrarum.ingame!! as Ingame).playableActor)
val jsonString = avelem.toString()

View File

@@ -20,10 +20,10 @@ object ImportLayerData : ConsoleCommand {
//val fis = GZIPInputStream(FileInputStream(args[1])) // this gzip is kaput
val fis = FileInputStream(args[1])
(Terrarum.ingame!! as Ingame).world = ReadLayerData(fis)
(Terrarum.ingame!! as Ingame).player.setPosition(
(Terrarum.ingame!! as Ingame).world.spawnY * FeaturesDrawer.TILE_SIZE.toDouble(),
(Terrarum.ingame!! as Ingame).world.spawnX * FeaturesDrawer.TILE_SIZE.toDouble()
(Terrarum.ingame!!.world) = ReadLayerData(fis)
(Terrarum.ingame!! as Ingame).playableActor.setPosition(
(Terrarum.ingame!!.world).spawnY * FeaturesDrawer.TILE_SIZE.toDouble(),
(Terrarum.ingame!!.world).spawnX * FeaturesDrawer.TILE_SIZE.toDouble()
)
fis.close()
Echo("Successfully loaded ${args[1]}")

View File

@@ -4,7 +4,7 @@ import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.console.ConsoleCommand
import net.torvald.terrarum.console.Echo
import net.torvald.terrarum.console.EchoError
import net.torvald.terrarum.modulebasegame.gameactors.Player
import net.torvald.terrarum.modulebasegame.gameactors.IngamePlayer
import net.torvald.terrarum.modulebasegame.gameactors.Pocketed
import net.torvald.terrarum.itemproperties.ItemCodex
import net.torvald.terrarum.modulebasegame.Ingame
@@ -14,7 +14,7 @@ import net.torvald.terrarum.modulebasegame.Ingame
*/
internal object Inventory : ConsoleCommand {
private var target: Pocketed? = (Terrarum.ingame!! as Ingame).player
private var target: Pocketed? = (Terrarum.ingame!! as Ingame).playableActor
override fun execute(args: Array<String>) {
if (args.size == 1) {
@@ -48,7 +48,7 @@ internal object Inventory : ConsoleCommand {
}
}
private fun setTarget(actorRefId: Int = Player.PLAYER_REF_ID) {
private fun setTarget(actorRefId: Int = Terrarum.PLAYER_REF_ID) {
val actor = Terrarum.ingame!!.getActorByID(actorRefId)
if (actor !is Pocketed) {
EchoError("Cannot edit inventory of incompatible actor: $actor")

View File

@@ -12,8 +12,8 @@ import net.torvald.terrarum.modulebasegame.Ingame
internal object Seed : ConsoleCommand {
override fun execute(args: Array<String>) {
Echo("Map$ccW: $ccG${(Terrarum.ingame!! as Ingame).world.generatorSeed}")
println("[seed] Map$ccW: $ccG${(Terrarum.ingame!! as Ingame).world.generatorSeed}")
Echo("Map$ccW: $ccG${(Terrarum.ingame!!.world).generatorSeed}")
println("[seed] Map$ccW: $ccG${(Terrarum.ingame!!.world).generatorSeed}")
// TODO display randomiser seed
}

View File

@@ -63,7 +63,7 @@ internal object SetAV : ConsoleCommand {
return
}
(Terrarum.ingame!! as Ingame).player.actorValue[args[1]] = newValue
(Terrarum.ingame!! as Ingame).playableActor.actorValue[args[1]] = newValue
Echo("${ccW}Set $ccM${args[1]} ${ccW}for ${ccY}player ${ccW}to $ccG$newValue")
println("[SetAV] set ActorValue '${args[1]}' for player to '$newValue'.")
}

View File

@@ -5,7 +5,7 @@ import net.torvald.terrarum.console.ConsoleCommand
import net.torvald.terrarum.console.Echo
import net.torvald.terrarum.console.EchoError
import net.torvald.terrarum.modulebasegame.Ingame
import net.torvald.terrarum.modulebasegame.gameactors.ActorWithPhysics
import net.torvald.terrarum.gameactors.ActorWBMovable
/**
* Created by minjaesong on 2017-01-20.
@@ -14,13 +14,13 @@ internal object SetScale : ConsoleCommand {
override fun execute(args: Array<String>) {
if (args.size == 2 || args.size == 3) {
try {
val targetID = if (args.size == 3) args[1].toInt() else (Terrarum.ingame!! as Ingame).player.referenceID
val targetID = if (args.size == 3) args[1].toInt() else (Terrarum.ingame!! as Ingame).playableActor.referenceID
val scale = args[if (args.size == 3) 2 else 1].toDouble()
val target = Terrarum.ingame!!.getActorByID(targetID!!)
if (target !is ActorWithPhysics) {
EchoError("Target is not ActorWithPhysics")
if (target !is ActorWBMovable) {
EchoError("Target is not ActorWBMovable")
}
else {
target.scale = scale

View File

@@ -11,7 +11,7 @@ import net.torvald.terrarum.modulebasegame.Ingame
*/
internal object SetTime : ConsoleCommand {
override fun execute(args: Array<String>) {
val world = (Terrarum.ingame!! as Ingame).world
val world = (Terrarum.ingame!! as Ingame).gameworld
if (args.size == 2) {

View File

@@ -13,7 +13,7 @@ internal object SetTimeDelta : ConsoleCommand {
val HARD_LIMIT = 60
override fun execute(args: Array<String>) {
val world = (Terrarum.ingame!! as Ingame).world
val world = (Terrarum.ingame!! as Ingame).gameworld
if (args.size == 2) {

View File

@@ -13,7 +13,7 @@ import org.dyn4j.geometry.Vector2
internal object SpawnPhysTestBall : ConsoleCommand {
@Throws(Exception::class)
override fun execute(args: Array<String>) {
val world = (Terrarum.ingame!! as Ingame).world
val world = (Terrarum.ingame!!.world)
val mouseX = Terrarum.mouseX

View File

@@ -13,7 +13,7 @@ internal object SpawnPhysTestLunarLander : ConsoleCommand {
override fun execute(args: Array<String>) {
val mouseX = Terrarum.mouseX
val mouseY = Terrarum.mouseY
val lander = PhysTestLuarLander((Terrarum.ingame!! as Ingame).world)
val lander = PhysTestLuarLander((Terrarum.ingame!!.world))
lander.setPosition(mouseX, mouseY)

View File

@@ -11,7 +11,7 @@ import net.torvald.terrarum.modulebasegame.gameactors.FixtureTikiTorch
*/
internal object SpawnTikiTorch : ConsoleCommand {
override fun execute(args: Array<String>) {
val torch = FixtureTikiTorch((Terrarum.ingame!! as Ingame).world)
val torch = FixtureTikiTorch((Terrarum.ingame!!.world))
torch.setPosition(Terrarum.mouseX, Terrarum.mouseY)
Terrarum.ingame!!.addNewActor(torch)

View File

@@ -6,7 +6,7 @@ import net.torvald.terrarum.console.ConsoleCommand
import net.torvald.terrarum.console.Echo
import net.torvald.terrarum.console.EchoError
import net.torvald.terrarum.modulebasegame.Ingame
import net.torvald.terrarum.modulebasegame.gameactors.ActorWithPhysics
import net.torvald.terrarum.gameactors.ActorWBMovable
/**
* Created by minjaesong on 2016-01-24.
@@ -27,32 +27,32 @@ internal object Teleport : ConsoleCommand {
return
}
(Terrarum.ingame!! as Ingame).player.setPosition(x.toDouble(), y.toDouble())
(Terrarum.ingame!! as Ingame).playableActor.setPosition(x.toDouble(), y.toDouble())
}
else if (args.size == 4) {
if (args[2].toLowerCase() != "to") {
EchoError("missing 'to' on teleport command")
return
}
val fromActor: ActorWithPhysics
val targetActor: ActorWithPhysics
val fromActor: ActorWBMovable
val targetActor: ActorWBMovable
try {
val fromActorID = args[1].toInt()
val targetActorID = if (args[3].toLowerCase() == "player")
(Terrarum.ingame!! as Ingame).player.referenceID!!
(Terrarum.ingame!! as Ingame).playableActor.referenceID!!
else
args[3].toInt()
// if from == target, ignore the action
if (fromActorID == targetActorID) return
if (Terrarum.ingame!!.getActorByID(fromActorID) !is ActorWithPhysics ||
Terrarum.ingame!!.getActorByID(targetActorID) !is ActorWithPhysics) {
if (Terrarum.ingame!!.getActorByID(fromActorID) !is ActorWBMovable ||
Terrarum.ingame!!.getActorByID(targetActorID) !is ActorWBMovable) {
throw IllegalArgumentException()
}
else {
fromActor = Terrarum.ingame!!.getActorByID(fromActorID) as ActorWithPhysics
targetActor = Terrarum.ingame!!.getActorByID(targetActorID) as ActorWithPhysics
fromActor = Terrarum.ingame!!.getActorByID(fromActorID) as ActorWBMovable
targetActor = Terrarum.ingame!!.getActorByID(targetActorID) as ActorWBMovable
}
}
catch (e: NumberFormatException) {
@@ -75,7 +75,7 @@ internal object Teleport : ConsoleCommand {
return
}
val actor: ActorWithPhysics
val actor: ActorWBMovable
val x: Int
val y: Int
try {
@@ -83,11 +83,11 @@ internal object Teleport : ConsoleCommand {
y = args[4].toInt() * FeaturesDrawer.TILE_SIZE + FeaturesDrawer.TILE_SIZE / 2
val actorID = args[1].toInt()
if (Terrarum.ingame!!.getActorByID(actorID) !is ActorWithPhysics) {
if (Terrarum.ingame!!.getActorByID(actorID) !is ActorWBMovable) {
throw IllegalArgumentException()
}
else {
actor = Terrarum.ingame!!.getActorByID(actorID) as ActorWithPhysics
actor = Terrarum.ingame!!.getActorByID(actorID) as ActorWBMovable
}
}
catch (e: NumberFormatException) {

View File

@@ -10,9 +10,9 @@ import net.torvald.terrarum.modulebasegame.Ingame
*/
internal object ToggleNoClip : ConsoleCommand {
override fun execute(args: Array<String>) {
val status = (Terrarum.ingame!! as Ingame).player.isNoClip()
val status = (Terrarum.ingame!! as Ingame).playableActor.isNoClip
(Terrarum.ingame!! as Ingame).player.setNoClip(!status)
(Terrarum.ingame!! as Ingame).playableActor.isNoClip = !status
Echo("Set no-clip status to " + (!status).toString())
}

View File

@@ -7,7 +7,7 @@ import net.torvald.terrarum.console.Echo
import net.torvald.terrarum.modulebasegame.console.SetAV
import net.torvald.terrarum.gameactors.Actor
import net.torvald.terrarum.modulebasegame.Ingame
import net.torvald.terrarum.modulebasegame.gameactors.ActorWithPhysics
import net.torvald.terrarum.gameactors.ActorWBMovable
import net.torvald.terrarum.worlddrawer.FeaturesDrawer
import java.awt.BorderLayout
import java.awt.GridLayout
@@ -29,7 +29,7 @@ class ActorValueTracker constructor() : JFrame() {
private val avPosArea = JTextArea()
private val avPosScroller = JScrollPane(avPosArea)
private var actor: ActorWithPhysics? = null
private var actor: ActorWBMovable? = null
private var actorValue: ActorValue? = null
private val modavInputKey = JTextField()
@@ -84,11 +84,11 @@ class ActorValueTracker constructor() : JFrame() {
buttonChangeActor.addMouseListener(object : MouseAdapter() {
override fun mousePressed(e: MouseEvent?) {
if (actorIDField.text.toLowerCase() == "player") {
actor = (Terrarum.ingame!! as Ingame).player
actor = (Terrarum.ingame!! as Ingame).playableActor
actorValue = actor!!.actorValue
}
else if (actorIDField.text.isNotBlank()) {
actor = Terrarum.ingame!!.getActorByID(actorIDField.text.toInt()) as ActorWithPhysics
actor = Terrarum.ingame!!.getActorByID(actorIDField.text.toInt()) as ActorWBMovable
actorValue = actor!!.actorValue
}
}
@@ -152,7 +152,7 @@ class ActorValueTracker constructor() : JFrame() {
this.title = "AVTracker — $actor"
if (actor is ActorWithPhysics) {
if (actor is ActorWBMovable) {
this.actor = actor
}

View File

@@ -1,115 +0,0 @@
package net.torvald.terrarum.modulebasegame.gameactors
/**
* See [res/raw/Creature_raw_doc.md] for information about raw.
*
* Created by minjaesong on 2016-04-02.
*/
object AVKey {
const val BUFF = "buff"
/** pixels per frame
* walking/running speed
*/
const val SPEED = "speed"
const val SPEEDBUFF = "$SPEED$BUFF"
/** pixels per frame squared
* acceleration of the movement (e.g. running, flying, driving, etc.)
*/
const val ACCEL = "accel"
const val ACCELBUFF = "$ACCEL$BUFF"
/** internal value used by ActorHumanoid to implement friction in walkfunction */
const val SCALE = "scale"
const val SCALEBUFF = "$SCALE$BUFF" // aka PHYSIQUE
/** pixels */
const val BASEHEIGHT = "baseheight"
/** kilogrammes */
const val BASEMASS = "basemass"
/** pixels per frame */
const val JUMPPOWER = "jumppower"
const val JUMPPOWERBUFF = "$JUMPPOWER$BUFF"
/** Int
* "Default" value of 1 000
*/
const val STRENGTH = "strength"
const val STRENGTHBUFF = "$STRENGTH$BUFF"
const val ENCUMBRANCE = "encumbrance"
/** 30-bit RGB (Int)
* 0000 0010000000 0010000000 0010000000
* ^ Red ^ Green ^ Blue
*/
const val LUMR = "luminosityred"
const val LUMG = "luminositygreen"
const val LUMB = "luminosityblue"
const val LUMA = "luminosityuv"
const val DRAGCOEFF = "dragcoeff"
const val FALLDAMPENMULT = "falldampenmult"
/** String
* e.g. Jarppi
*/
const val NAME = "name"
/** String
* e.g. Duudsoni
*/
const val RACENAME = "racename"
/** String
* e.g. Duudsonit
*/
const val RACENAMEPLURAL = "racenameplural"
/** killogrammes
* will affect attack strength, speed and inventory label
* (see "Attack momentum calculator.numbers")
* e.g. Hatchet (tiny)
*/
const val TOOLSIZE = "toolsize"
/** Boolean
* whether the player can talk with it
*/
const val INTELLIGENT = "intelligent"
/** (unit TBA)
* base defence point of the species
*/
const val BASEDEFENCE = "basedefence"
/** (unit TBA)
* current defence point of worn armour(s)
*/
const val ARMOURDEFENCE = "armourdefence"
const val ARMOURDEFENCEBUFF = "$ARMOURDEFENCE$BUFF"
const val MAGICREGENRATE = "magicregenrate"
const val MAGICREGENRATEBUFF = "$MAGICREGENRATE$BUFF"
/** Double
*
*/
const val ACTION_INTERVAL = "actioninterval"
/** String
* UUID for certain fixtures
*/
const val UUID = "uuid"
const val __PLAYER_QUICKSLOTSEL = "__quickslotselection"
/** Double
* When using tool/arm/etc. how long action button is held, in milliseconds (Int)
* Or for NPCs, how long it has been waiting for next move
*/
const val __ACTION_TIMER = "__actiontimer"
const val HEALTH = "health"
const val MAGIC = "magic"
const val __HISTORICAL_BORNTIME = "__borntime" // time_t
const val __HISTORICAL_DEADTIME = "__deadtime" // time_t
}

View File

@@ -5,10 +5,7 @@ import com.badlogic.gdx.graphics.Color
import com.jme3.math.FastMath
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.bipolarClamp
import net.torvald.terrarum.gameactors.Controllable
import net.torvald.terrarum.gameactors.Factionable
import net.torvald.terrarum.gameactors.Hitbox
import net.torvald.terrarum.gameactors.Luminous
import net.torvald.terrarum.gameactors.*
import net.torvald.terrarum.gameactors.faction.Faction
import net.torvald.terrarum.gameworld.GameWorld
import net.torvald.terrarum.itemproperties.GameItem
@@ -32,7 +29,7 @@ open class ActorHumanoid(
birth: time_t,
death: time_t? = null,
usePhysics: Boolean = true
) : ActorWithPhysics(world, RenderOrder.MIDDLE, usePhysics = usePhysics), Controllable, Pocketed, Factionable, Luminous, LandHolder, HistoricalFigure {
) : ActorWBMovable(world, RenderOrder.MIDDLE, usePhysics = usePhysics), Controllable, Pocketed, Factionable, Luminous, LandHolder, HistoricalFigure {
@@ -139,8 +136,6 @@ open class ActorHumanoid(
@Transient private var prevHMoveKey = KEY_NULL
@Transient private var prevVMoveKey = KEY_NULL
internal var noClip = false
@Transient private val AXIS_KEYBOARD = -13372f // leetz
@Transient private val GAMEPAD_JUMP = 7
@@ -150,7 +145,7 @@ open class ActorHumanoid(
protected var isRightDown = false
protected var isJumpDown = false
protected inline val isGamer: Boolean
get() = if (Terrarum.ingame == null) false else this == (Terrarum.ingame!! as Ingame).player
get() = if (Terrarum.ingame == null) false else this == Terrarum.ingame!!.playableActor
private val nullItem = object : GameItem() {
@@ -174,7 +169,7 @@ open class ActorHumanoid(
override fun update(delta: Float) {
super.update(delta)
if (vehicleRiding is Player)
if (vehicleRiding is IngamePlayer)
throw Error("Attempted to 'ride' player object. ($vehicleRiding)")
if (vehicleRiding != null && vehicleRiding == this)
throw Error("Attempted to 'ride' itself. ($vehicleRiding)")
@@ -188,7 +183,7 @@ open class ActorHumanoid(
updateSprite(delta)
if (noClip) {
if (isNoClip) {
//grounded = true
}
@@ -277,7 +272,7 @@ open class ActorHumanoid(
}
// ↑E
// ↑D
if (isNoClip() && !isUpDown && !isDownDown) {
if (isNoClip && !isUpDown && !isDownDown) {
walkVStop()
prevVMoveKey = KEY_NULL
}
@@ -313,7 +308,7 @@ open class ActorHumanoid(
/**
* Up/Down movement
*/
if (noClip || COLLISION_TEST_MODE) {
if (isNoClip || COLLISION_TEST_MODE) {
if (hasController) {
if (axisY != 0f) {
walkVertical(axisY < 0, axisY.abs())
@@ -343,7 +338,7 @@ open class ActorHumanoid(
* Jump control
*/
if (isJumpDown) {
if (!noClip) {
if (!isNoClip) {
if (airJumpingAllowed ||
(!airJumpingAllowed && walledBottom)) {
jumping = true
@@ -385,7 +380,7 @@ open class ActorHumanoid(
* this code base, ACCELERATION must be changed (in other words, we must deal with JERK) accordingly
* to the FRICTION.
*
* So I'm adding walkX/Y and getting the ActorWithPhysics.setNewNextHitbox to use the velocity value of
* So I'm adding walkX/Y and getting the ActorWBMovable.setNewNextHitbox to use the velocity value of
* walkX/Y + velocity, which is stored in variable moveDelta.
*
* Be warned.
@@ -608,18 +603,6 @@ open class ActorHumanoid(
}
}
fun isNoClip(): Boolean {
return noClip
}
fun setNoClip(b: Boolean) {
noClip = b
if (b) {
externalForce.zero()
controllerMoveDelta?.zero()
}
}
fun Float.abs() = FastMath.abs(this)

View File

@@ -2,6 +2,7 @@ package net.torvald.terrarum.modulebasegame.gameactors
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.blockproperties.BlockCodex
import net.torvald.terrarum.gameactors.AVKey
import net.torvald.terrarum.gameactors.Actor
import net.torvald.terrarum.itemproperties.GameItem
import net.torvald.terrarum.itemproperties.ItemCodex
@@ -60,10 +61,10 @@ class ActorInventory(val actor: Pocketed, var maxCapacity: Int, var capacityMode
if (count < 0)
throw IllegalArgumentException("Item count is negative number. If you intended removing items, use remove()\n" +
"These commands are NOT INTERCHANGEABLE; they handle things differently according to the context.")
if (item.originalID == Player.PLAYER_REF_ID || item.originalID == 0x51621D) // do not delete this magic
if (item.originalID == Terrarum.PLAYER_REF_ID || item.originalID == 0x51621D) // do not delete this magic
throw IllegalArgumentException("Attempted to put human player into the inventory.")
if (((Terrarum.ingame as? Ingame)?.gameFullyLoaded ?: false) &&
(item.originalID == (Terrarum.ingame as? Ingame)?.player?.referenceID))
(item.originalID == (Terrarum.ingame as? Ingame)?.playableActor?.referenceID))
throw IllegalArgumentException("Attempted to put active player into the inventory.")
if ((!item.stackable || item.dynamicID in ITEM_DYNAMIC) && count > 1)
throw IllegalArgumentException("Attempting to adding stack of item but the item is not stackable; item: $item, count: $count")

View File

@@ -1,6 +1,8 @@
package net.torvald.terrarum.modulebasegame.gameactors
import net.torvald.terrarum.gameactors.AVKey
import net.torvald.terrarum.gameactors.Actor
import net.torvald.terrarum.gameactors.ActorWBMovable
import net.torvald.terrarum.gameworld.GameWorld
@@ -13,8 +15,8 @@ object CreatureBuilder {
/**
* @Param jsonFileName with extension
*/
operator fun invoke(world: GameWorld, module: String, jsonFileName: String): ActorWithPhysics {
val actor = ActorWithPhysics(world, Actor.RenderOrder.MIDDLE)
operator fun invoke(world: GameWorld, module: String, jsonFileName: String): ActorWBMovable {
val actor = ActorWBMovable(world, Actor.RenderOrder.MIDDLE)
InjectCreatureRaw(actor.actorValue, module, jsonFileName)

View File

@@ -173,6 +173,6 @@ object DecodeTapestry {
readCounter++
}
return TapestryObject((Terrarum.ingame!! as Ingame).world, outImageData, artName, authorName)
return TapestryObject((Terrarum.ingame!!.world), outImageData, artName, authorName)
}
}

View File

@@ -4,12 +4,13 @@ import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.terrarum.itemproperties.GameItem
import net.torvald.terrarum.itemproperties.ItemCodex
import net.torvald.terrarum.blockproperties.BlockCodex
import net.torvald.terrarum.gameactors.ActorWBMovable
import net.torvald.terrarum.gameworld.GameWorld
/**
* Created by minjaesong on 2016-03-15.
*/
open class DroppedItem(world: GameWorld, private val item: GameItem) : ActorWithPhysics(world, RenderOrder.MIDTOP) {
open class DroppedItem(world: GameWorld, private val item: GameItem) : ActorWBMovable(world, RenderOrder.MIDTOP) {
init {
if (item.dynamicID >= ItemCodex.ACTORID_MIN)

View File

@@ -1,12 +1,13 @@
package net.torvald.terrarum.modulebasegame.gameactors
import net.torvald.terrarum.gameactors.ActorWBMovable
import net.torvald.terrarum.gameworld.GameWorld
/**
* Created by minjaesong on 2016-06-17.
*/
open class FixtureBase(world: GameWorld, physics: Boolean = true) :
ActorWithPhysics(world, RenderOrder.BEHIND, immobileBody = true, usePhysics = physics) {
ActorWBMovable(world, RenderOrder.BEHIND, immobileBody = true, usePhysics = physics) {
/**
* 0: Open
* 1: Blocked

View File

@@ -4,6 +4,7 @@ import com.badlogic.gdx.graphics.Color
import net.torvald.terrarum.ModMgr
import net.torvald.terrarum.blockproperties.Block
import net.torvald.terrarum.blockproperties.BlockCodex
import net.torvald.terrarum.gameactors.AVKey
import net.torvald.terrarum.gameactors.Hitbox
import net.torvald.terrarum.gameactors.Luminous
import net.torvald.terrarum.gameworld.GameWorld

View File

@@ -2,11 +2,11 @@ package net.torvald.terrarum.modulebasegame.gameactors
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.gameactors.AIControlled
import net.torvald.terrarum.gameactors.AVKey
import net.torvald.terrarum.gameactors.ai.ActorAI
import net.torvald.terrarum.gameworld.GameWorld
import net.torvald.terrarum.itemproperties.GameItem
import net.torvald.terrarum.itemproperties.Material
import net.torvald.terrarum.modulebasegame.gameactors.ActorWithPhysics.Companion.COLLISION_DYNAMIC
import net.torvald.terrarum.modulebasegame.gameworld.time_t
/**

View File

@@ -1,6 +1,7 @@
package net.torvald.terrarum.modulebasegame.gameactors
import net.torvald.terrarum.gameworld.GameWorld
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.modulebasegame.gameworld.GameWorldExtension
import net.torvald.terrarum.modulebasegame.gameworld.time_t
@@ -10,27 +11,17 @@ import net.torvald.terrarum.modulebasegame.gameworld.time_t
* Created by minjaesong on 2015-12-31.
*/
class Player(world: GameWorld, born: time_t) : ActorHumanoid(world, born) {
companion object {
@Transient const val PLAYER_REF_ID: Int = 0x91A7E2
}
class IngamePlayer(world: GameWorldExtension, born: time_t) : ActorHumanoid(world, born) {
/**
* Creates new Player instance with empty elements (sprites, actorvalue, etc.).
* **Use PlayerFactory to build player!**
* @throws SlickException
*/
init {
referenceID = PLAYER_REF_ID // forcibly set ID
referenceID = Terrarum.PLAYER_REF_ID // forcibly set ID
density = BASE_DENSITY
collisionType = COLLISION_KINEMATIC
}
override fun update(delta: Float) {
super.update(delta)
}
}

View File

@@ -5,6 +5,7 @@ import net.torvald.random.Fudge3
import net.torvald.terrarum.langpack.Lang
import com.google.gson.JsonObject
import net.torvald.terrarum.ModMgr
import net.torvald.terrarum.gameactors.AVKey
import net.torvald.terrarum.gameactors.ActorValue
import java.security.SecureRandom

View File

@@ -4,14 +4,13 @@ import com.badlogic.gdx.graphics.g2d.SpriteBatch
import com.badlogic.gdx.graphics.g2d.TextureRegion
import net.torvald.terrarum.Second
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.modulebasegame.gameactors.ActorWithPhysics.Companion.SI_TO_GAME_ACC
import net.torvald.terrarum.gameactors.ActorWBMovable.Companion.SI_TO_GAME_ACC
import net.torvald.terrarum.worlddrawer.FeaturesDrawer.TILE_SIZE
import net.torvald.terrarum.blockproperties.Block
import net.torvald.terrarum.blockproperties.BlockCodex
import net.torvald.terrarum.floorInt
import net.torvald.terrarum.gameactors.Actor
import net.torvald.terrarum.gameactors.Hitbox
import net.torvald.terrarum.modulebasegame.Ingame
import org.dyn4j.geometry.Vector2
/**
@@ -48,7 +47,7 @@ open class ParticleBase(renderOrder: Actor.RenderOrder, val despawnUponCollision
if (despawnUponCollision) {
if (velocity.isZero ||
// simple stuck check
BlockCodex[(Terrarum.ingame!! as Ingame).world.getTileFromTerrain(
BlockCodex[(Terrarum.ingame!!.world).getTileFromTerrain(
hitbox.canonicalX.div(TILE_SIZE).floorInt(),
hitbox.canonicalY.div(TILE_SIZE).floorInt()
) ?: Block.STONE].isSolid) {
@@ -62,7 +61,7 @@ open class ParticleBase(renderOrder: Actor.RenderOrder, val despawnUponCollision
// gravity, winds, etc. (external forces)
if (!isNoSubjectToGrav) {
velocity += (Terrarum.ingame!! as Ingame).world.gravitation / dragCoefficient * SI_TO_GAME_ACC
velocity += (Terrarum.ingame!!.world).gravitation / dragCoefficient * SI_TO_GAME_ACC
}

View File

@@ -7,6 +7,7 @@ import net.torvald.random.HQRNG
import net.torvald.terrarum.ModMgr
import net.torvald.terrarum.Second
import net.torvald.terrarum.gameactors.Actor
import net.torvald.terrarum.gameactors.ActorWBMovable
/**
* Created by minjaesong on 2017-12-18.
@@ -23,7 +24,7 @@ class ParticleMegaRain(posX: Double, posY: Double) : ParticleBase(Actor.RenderOr
w, h
)
velocity.y = 11.5 * ActorWithPhysics.SI_TO_GAME_VEL
velocity.y = 11.5 * ActorWBMovable.SI_TO_GAME_VEL
}
}

View File

@@ -3,14 +3,14 @@ package net.torvald.terrarum.modulebasegame.gameactors
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.gameactors.ActorWBMovable
import net.torvald.terrarum.gameworld.GameWorld
import net.torvald.terrarum.modulebasegame.Ingame
import net.torvald.terrarum.modulebasegame.worldgenerator.RoguelikeRandomiser
/**
* Created by minjaesong on 2016-03-05.
*/
class PhysTestBall(world: GameWorld) : ActorWithPhysics(world, RenderOrder.MIDDLE, immobileBody = true) {
class PhysTestBall(world: GameWorld) : ActorWBMovable(world, RenderOrder.MIDDLE, immobileBody = true) {
private var color = Color.GOLD
@@ -32,13 +32,13 @@ class PhysTestBall(world: GameWorld) : ActorWithPhysics(world, RenderOrder.MIDDL
)
it.circle(
hitbox.startX.toFloat() + (Terrarum.ingame!! as Ingame).world.width * TILE_SIZE - 1f,
hitbox.startX.toFloat() + (Terrarum.ingame!!.world).width * TILE_SIZE - 1f,
hitbox.startY.toFloat() - 1f,
hitbox.width.toFloat()
)
it.circle(
hitbox.startX.toFloat() - (Terrarum.ingame!! as Ingame).world.width * TILE_SIZE - 1f,
hitbox.startX.toFloat() - (Terrarum.ingame!!.world).width * TILE_SIZE - 1f,
hitbox.startY.toFloat() - 1f,
hitbox.width.toFloat()
)

View File

@@ -6,6 +6,8 @@ import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.Texture
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.terrarum.ModMgr
import net.torvald.terrarum.gameactors.AVKey
import net.torvald.terrarum.gameactors.ActorWBMovable
import net.torvald.terrarum.gameactors.Controllable
import net.torvald.terrarum.gameactors.Hitbox
import net.torvald.terrarum.gameworld.GameWorld
@@ -13,7 +15,7 @@ import net.torvald.terrarum.gameworld.GameWorld
/**
* Created by minjaesong on 2018-01-17.
*/
class PhysTestLuarLander(world: GameWorld) : ActorWithPhysics(world, RenderOrder.MIDTOP), Controllable {
class PhysTestLuarLander(world: GameWorld) : ActorWBMovable(world, RenderOrder.MIDTOP), Controllable {
private val texture = Texture(ModMgr.getGdxFile("basegame", "sprites/phystest_lunarlander.tga"))

View File

@@ -1,6 +1,7 @@
package net.torvald.terrarum.modulebasegame.gameactors
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.gameactors.AVKey
import net.torvald.terrarum.gameactors.Actor
import net.torvald.terrarum.modulebasegame.Ingame
@@ -10,7 +11,9 @@ import net.torvald.terrarum.modulebasegame.Ingame
object PlayerBuilder {
operator fun invoke(): Actor {
val p: Actor = Player((Terrarum.ingame!! as Ingame).world, (Terrarum.ingame!! as Ingame).world.time.TIME_T)
val world = (Terrarum.ingame!! as Ingame).gameworld
val p: Actor = IngamePlayer(world, world.time.TIME_T)
InjectCreatureRaw(p.actorValue, "basegame", "CreatureHuman.json")
// attach sprite

View File

@@ -2,8 +2,9 @@ package net.torvald.terrarum.modulebasegame.gameactors
import net.torvald.terrarum.ModMgr
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.gameactors.AVKey
import net.torvald.terrarum.gameactors.ActorWBMovable
import net.torvald.terrarum.gameactors.ai.NullAI
import net.torvald.terrarum.modulebasegame.Ingame
import net.torvald.terrarum.worlddrawer.FeaturesDrawer
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
@@ -12,10 +13,10 @@ import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
*/
object PlayerBuilderCynthia {
operator fun invoke(): ActorWithPhysics {
//val p: Player = Player(GameDate(100, 143)) // random value thrown
operator fun invoke(): ActorWBMovable {
//val p: IngamePlayer = IngamePlayer(GameDate(100, 143)) // random value thrown
val p: HumanoidNPC = HumanoidNPC(
(Terrarum.ingame!! as Ingame).world,
(Terrarum.ingame!!.world),
NullAI(),
-589141658L) // random value thrown
InjectCreatureRaw(p.actorValue, "basegame", "CreatureHuman.json")

View File

@@ -5,7 +5,9 @@ import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.gameactors.faction.FactionFactory
import net.torvald.terrarum.itemproperties.ItemCodex
import net.torvald.terrarum.blockproperties.Block
import net.torvald.terrarum.gameactors.AVKey
import net.torvald.terrarum.modulebasegame.Ingame
import net.torvald.terrarum.modulebasegame.gameworld.GameWorldExtension
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
/**
@@ -14,8 +16,8 @@ import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
object PlayerBuilderSigrid {
operator fun invoke(): Player {
val p = Player((Terrarum.ingame!! as Ingame).world, -9223372036854775807L) // XD
operator fun invoke(): IngamePlayer {
val p = IngamePlayer((Terrarum.ingame!! as Ingame).gameworld, -9223372036854775807L) // XD
p.referenceID = 0x51621D // the only constant of this procedural universe

View File

@@ -2,6 +2,7 @@ package net.torvald.terrarum.modulebasegame.gameactors
import net.torvald.terrarum.ModMgr
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.gameactors.AVKey
import net.torvald.terrarum.modulebasegame.Ingame
import net.torvald.terrarum.worlddrawer.FeaturesDrawer
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
@@ -10,8 +11,8 @@ import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
* Created by minjaesong on 2017-02-10.
*/
object PlayerBuilderTestSubject1 {
operator fun invoke(): Player {
val p: Player = Player((Terrarum.ingame!! as Ingame).world, -589141658L) // random value thrown
operator fun invoke(): IngamePlayer {
val p: IngamePlayer = IngamePlayer((Terrarum.ingame!! as Ingame).gameworld, -589141658L) // random value thrown
InjectCreatureRaw(p.actorValue, "basegame", "CreatureHuman.json")

View File

@@ -2,14 +2,14 @@ package net.torvald.terrarum.modulebasegame.gameactors
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.point.Point2d
import net.torvald.terrarum.Point2d
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.blockproperties.Block
import net.torvald.terrarum.blockproperties.BlockCodex
import net.torvald.terrarum.gameactors.ActorWBMovable
import net.torvald.terrarum.gameactors.Hitbox
import net.torvald.terrarum.gameactors.Luminous
import net.torvald.terrarum.gameworld.GameWorld
import net.torvald.terrarum.modulebasegame.Ingame
import org.dyn4j.geometry.Vector2
import java.util.*
@@ -25,7 +25,7 @@ open class ProjectileSimple(
private val type: Int,
fromPoint: Vector2, // projected coord
toPoint: Vector2 // arriving coord
) : ActorWithPhysics(world, RenderOrder.MIDTOP), Luminous, Projectile {
) : ActorWBMovable(world, RenderOrder.MIDTOP), Luminous, Projectile {
val damage: Int
val displayColour: Color
@@ -77,7 +77,7 @@ open class ProjectileSimple(
lifetimeCounter += delta
if (walledTop || walledBottom || walledRight || walledLeft || lifetimeCounter >= lifetimeMax ||
// stuck check
BlockCodex[(Terrarum.ingame!! as Ingame).world.getTileFromTerrain(feetPosTile[0], feetPosTile[1]) ?: Block.STONE].isSolid
BlockCodex[(Terrarum.ingame!!.world).getTileFromTerrain(feetPosTile[0], feetPosTile[1]) ?: Block.STONE].isSolid
) {
flagDespawn()
}

View File

@@ -1,6 +1,7 @@
package net.torvald.terrarum.modulebasegame.gameactors
import com.badlogic.gdx.graphics.Color
import net.torvald.terrarum.gameactors.ActorWBMovable
import net.torvald.terrarum.gameactors.Hitbox
import net.torvald.terrarum.gameactors.Luminous
import net.torvald.terrarum.gameworld.GameWorld
@@ -8,7 +9,7 @@ import net.torvald.terrarum.gameworld.GameWorld
/**
* Created by minjaesong on 2016-04-26.
*/
class WeaponSwung(world: GameWorld, val itemID: Int) : ActorWithPhysics(world, RenderOrder.MIDTOP), Luminous {
class WeaponSwung(world: GameWorld, val itemID: Int) : ActorWBMovable(world, RenderOrder.MIDTOP), Luminous {
// just let the solver use AABB; it's cheap but works just enough
/**

View File

@@ -35,7 +35,7 @@ class SmarterSlimes : ActorAI {
// TEST: just target player
val playerXPos = (Terrarum.ingame!! as Ingame).player.centrePosPoint.x
val playerXPos = (Terrarum.ingame!! as Ingame).playableActor.centrePosPoint.x
val thisXPos = actor.centrePosPoint.x
val xDiff = thisXPos - playerXPos

View File

@@ -2,7 +2,7 @@ package net.torvald.terrarum.modulebasegame.gameactors.physicssolver
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.modulebasegame.Ingame
import net.torvald.terrarum.modulebasegame.gameactors.ActorWithPhysics
import net.torvald.terrarum.gameactors.ActorWBMovable
import java.util.*
/**
@@ -20,9 +20,9 @@ object CollisionSolver {
private val collListX = ArrayList<CollisionMarkings>(COLL_LIST_SIZE)
private val collListY = ArrayList<CollisionMarkings>(COLL_LIST_SIZE)
private val collCandidateX = ArrayList<Pair<ActorWithPhysics, ActorWithPhysics>>(COLL_CANDIDATES_SIZE)
private val collCandidateY = ArrayList<Pair<ActorWithPhysics, ActorWithPhysics>>(COLL_CANDIDATES_SIZE)
private var collCandidates = ArrayList<Pair<ActorWithPhysics, ActorWithPhysics>>(COLL_FINAL_CANDIDATES_SIZE)
private val collCandidateX = ArrayList<Pair<ActorWBMovable, ActorWBMovable>>(COLL_CANDIDATES_SIZE)
private val collCandidateY = ArrayList<Pair<ActorWBMovable, ActorWBMovable>>(COLL_CANDIDATES_SIZE)
private var collCandidates = ArrayList<Pair<ActorWBMovable, ActorWBMovable>>(COLL_FINAL_CANDIDATES_SIZE)
private val collCandidateStack = Stack<CollisionMarkings>()
@@ -40,7 +40,7 @@ object CollisionSolver {
// mark list x
(Terrarum.ingame!! as Ingame).actorContainer.forEach { it ->
if (it is ActorWithPhysics) {
if (it is ActorWBMovable) {
collListX.add(CollisionMarkings(it.hitbox.hitboxStart.x, STARTPOINT, it))
collListX.add(CollisionMarkings(it.hitbox.hitboxEnd.x, ENDPOINT, it))
}
@@ -73,7 +73,7 @@ object CollisionSolver {
// mark list y
(Terrarum.ingame!! as Ingame).actorContainer.forEach { it ->
if (it is ActorWithPhysics) {
if (it is ActorWBMovable) {
collListY.add(CollisionMarkings(it.hitbox.hitboxStart.y, STARTPOINT, it))
collListY.add(CollisionMarkings(it.hitbox.hitboxEnd.y, ENDPOINT, it))
}
@@ -89,7 +89,7 @@ object CollisionSolver {
else if (it.kind == ENDPOINT) {
val mark_this = it
val mark_other = collCandidateStack.pop()
val collCandidate: Pair<ActorWithPhysics, ActorWithPhysics>
val collCandidate: Pair<ActorWBMovable, ActorWBMovable>
// make sure actor with lower ID comes first
if (mark_this.actor < mark_other.actor)
collCandidate = Pair(mark_this.actor, mark_other.actor)
@@ -137,7 +137,7 @@ object CollisionSolver {
return indexOfEqFn(this, other) >= 0
}
private fun solveCollision(a: ActorWithPhysics, b: ActorWithPhysics) {
private fun solveCollision(a: ActorWBMovable, b: ActorWBMovable) {
// some of the Pair(a, b) are either duplicates or erroneously reported.
// e.g. (A, B), (B, C) and then (A, C);
// in some situation (A, C) will not making any contact with each other
@@ -173,11 +173,11 @@ object CollisionSolver {
}
}
private infix fun ActorWithPhysics.makesCollisionWith(other: ActorWithPhysics) =
this.collisionType != ActorWithPhysics.COLLISION_NOCOLLIDE &&
other.collisionType != ActorWithPhysics.COLLISION_NOCOLLIDE
private infix fun ActorWBMovable.makesCollisionWith(other: ActorWBMovable) =
this.collisionType != ActorWBMovable.COLLISION_NOCOLLIDE &&
other.collisionType != ActorWBMovable.COLLISION_NOCOLLIDE
private infix fun ActorWithPhysics.isCollidingWith(other: ActorWithPhysics): Boolean {
private infix fun ActorWBMovable.isCollidingWith(other: ActorWBMovable): Boolean {
val ax = this.hitbox.centeredX
val ay = this.hitbox.centeredY
val bx = other.hitbox.centeredX
@@ -208,7 +208,7 @@ object CollisionSolver {
data class CollisionMarkings(
val pos: Double,
val kind: Int,
val actor: ActorWithPhysics
val actor: ActorWBMovable
)
/**

View File

@@ -1,6 +1,6 @@
package net.torvald.terrarum.modulebasegame.gameactors.physicssolver
import net.torvald.terrarum.modulebasegame.gameactors.ActorWithPhysics
import net.torvald.terrarum.gameactors.ActorWBMovable
/**
* Created by minjaesong on 2016-05-01.
@@ -11,7 +11,7 @@ object VelocitySolver {
}
private fun applyGravity(actor: ActorWithPhysics) {
private fun applyGravity(actor: ActorWBMovable) {
}

View File

@@ -0,0 +1,46 @@
package net.torvald.terrarum.modulebasegame.gameworld
import com.badlogic.gdx.graphics.Color
import net.torvald.terrarum.gameworld.*
import kotlin.properties.Delegates
/**
* Created by minjaesong on 2018-07-03.
*/
class GameWorldExtension(width: Int, height: Int): GameWorld(width, height) {
val time: WorldTime
val economy = GameEconomy()
// delegated properties //
/*val layerWall: MapLayer; get() = baseworld.layerWall
val layerTerrain: MapLayer; get() = baseworld.layerTerrain
val layerWire: MapLayer; get() = baseworld.layerWire
val layerWallLowBits: PairedMapLayer; get() = baseworld.layerWallLowBits
val layerTerrainLowBits: PairedMapLayer; get() = baseworld.layerTerrainLowBits
val layerHalfThermal: MapLayerHalfFloat; get() = baseworld.layerHalfThermal
var spawnX: Int; get() = baseworld.spawnX; set(v) { baseworld.spawnX = v }
var spawnY: Int; get() = baseworld.spawnY; set(v) { baseworld.spawnY = v }
val wallDamages: HashMap<BlockAddress, BlockDamage>; get() = baseworld.wallDamages
val terrainDamages: HashMap<BlockAddress, BlockDamage>; get() = baseworld.terrainDamages
var globalLight: Color; get() = baseworld.globalLight; set(v) { baseworld.globalLight = v }
var averageTemperature: Float; get() = baseworld.averageTemperature; set(v) { baseworld.averageTemperature = v }
var generatorSeed: Long; get() = baseworld.generatorSeed; set(v) { baseworld.generatorSeed = v }
val terrainArray: ByteArray; get() = baseworld.terrainArray
val wallArray: ByteArray; get() = baseworld.wallArray
val wireArray: ByteArray; get() = baseworld.wireArray
val damageDataArray: ByteArray; get() = baseworld.damageDataArray*/
init {
time = WorldTime(
71 * WorldTime.DAY_LENGTH +
7 * WorldTime.HOUR_SEC +
30L * WorldTime.MINUTE_SEC
)
}
fun updateWorldTime(delta: Float) {
time.update(delta)
}
}

View File

@@ -38,7 +38,7 @@ object WorldSimulator {
val colourNone = Color(0x808080FF.toInt())
val colourWater = Color(0x66BBFFFF.toInt())
private val world = (Terrarum.ingame!! as Ingame).world
private val world = (Terrarum.ingame!!.world)
operator fun invoke(p: ActorHumanoid?, delta: Float) {
if (p != null) {

View File

@@ -1,10 +1,10 @@
package net.torvald.terrarum.modulebasegame.items
import net.torvald.point.Point2d
import net.torvald.terrarum.Point2d
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.blockproperties.Block
import net.torvald.terrarum.modulebasegame.gameactors.AVKey
import net.torvald.terrarum.modulebasegame.gameactors.ActorWithPhysics
import net.torvald.terrarum.gameactors.AVKey
import net.torvald.terrarum.gameactors.ActorWBMovable
import net.torvald.terrarum.itemproperties.Calculate
import net.torvald.terrarum.itemproperties.GameItem
import net.torvald.terrarum.itemproperties.ItemID
@@ -38,27 +38,27 @@ class PickaxeGeneric(override val originalID: ItemID) : GameItem() {
val mouseTileY = Terrarum.mouseTileY
val mousePoint = Point2d(mouseTileX.toDouble(), mouseTileY.toDouble())
val actorvalue = (Terrarum.ingame!! as Ingame).player.actorValue
val actorvalue = (Terrarum.ingame!! as Ingame).playableActor.actorValue
using = true
// linear search filter (check for intersection with tilewise mouse point and tilewise hitbox)
// return false if hitting actors
Terrarum.ingame!!.actorContainer.forEach({
if (it is ActorWithPhysics && it.hIntTilewiseHitbox.intersects(mousePoint))
if (it is ActorWBMovable && it.hIntTilewiseHitbox.intersects(mousePoint))
return false
})
// return false if here's no tile
if (Block.AIR == (Terrarum.ingame!! as Ingame).world.getTileFromTerrain(mouseTileX, mouseTileY))
if (Block.AIR == (Terrarum.ingame!!.world).getTileFromTerrain(mouseTileX, mouseTileY))
return false
// filter passed, do the job
val swingDmgToFrameDmg = delta.toDouble() / actorvalue.getAsDouble(AVKey.ACTION_INTERVAL)!!
(Terrarum.ingame!! as Ingame).world.inflictTerrainDamage(
(Terrarum.ingame!!.world).inflictTerrainDamage(
mouseTileX, mouseTileY,
Calculate.pickaxePower((Terrarum.ingame!! as Ingame).player, material) * swingDmgToFrameDmg
Calculate.pickaxePower((Terrarum.ingame!! as Ingame).playableActor, material) * swingDmgToFrameDmg
)
return true
@@ -67,7 +67,7 @@ class PickaxeGeneric(override val originalID: ItemID) : GameItem() {
override fun endPrimaryUse(delta: Float): Boolean {
using = false
// reset action timer to zero
(Terrarum.ingame!! as Ingame).player.actorValue.set(AVKey.__ACTION_TIMER, 0.0)
(Terrarum.ingame!! as Ingame).playableActor.actorValue.set(AVKey.__ACTION_TIMER, 0.0)
return true
}
}

View File

@@ -1,6 +1,6 @@
package net.torvald.terrarum.modulebasegame.magiccontroller
import net.torvald.terrarum.modulebasegame.gameactors.AVKey
import net.torvald.terrarum.gameactors.AVKey
import net.torvald.terrarum.gameactors.Actor
/**

View File

@@ -115,11 +115,11 @@ class UIBasicNotifier(private val player: ActorHumanoid?) : UICanvas() {
if (player != null) {
val playerPos = player.hIntTilewiseHitbox
lightLevel = (LightmapRenderer.getLight(playerPos.centeredX.toInt(), playerPos.centeredY.toInt()) ?:
(Terrarum.ingame!! as Ingame).world.globalLight
(Terrarum.ingame!!.world).globalLight
)
}
else {
lightLevel = (Terrarum.ingame!! as Ingame).world.globalLight
lightLevel = (Terrarum.ingame!!.world).globalLight
}

View File

@@ -0,0 +1,92 @@
package net.torvald.terrarum.modulebasegame.ui
import com.badlogic.gdx.graphics.Camera
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.terrarum.ModMgr
import net.torvald.terrarum.Second
import net.torvald.terrarum.ui.UICanvas
import net.torvald.terrarum.ui.UIItemImageButton
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
class UIBuildingMakerToolbox : UICanvas() {
val toolsTexture = TextureRegionPack(ModMgr.getGdxFile("basegame", "gui/building_maker_toolbox.tga"), 16, 16)
val tools = Array(toolsTexture.verticalCount, { UIItemImageButton(
this, toolsTexture.get(0, it),
posX = 0,
posY = 20 * it,
highlightable = true
) })
override var width = 16
override var height = 20 * tools.size - 4
override var openCloseTime = 0f
var selectedTool = 0; private set
init {
setAsAlwaysVisible()
tools[selectedTool].highlighted = true
}
override fun updateUI(delta: Float) {
tools.forEachIndexed { counter, it ->
it.update(delta)
if (it.highlighted) selectedTool = counter
}
}
override fun renderUI(batch: SpriteBatch, camera: Camera) {
tools.forEach { it.render(batch, camera) }
}
override fun doOpening(delta: Float) { }
override fun doClosing(delta: Float) { }
override fun endOpening(delta: Float) { }
override fun endClosing(delta: Float) { }
override fun dispose() {
toolsTexture.dispose()
}
override fun mouseMoved(screenX: Int, screenY: Int): Boolean {
return super.mouseMoved(screenX, screenY)
}
override fun touchDragged(screenX: Int, screenY: Int, pointer: Int): Boolean {
return super.touchDragged(screenX, screenY, pointer)
}
override fun touchDown(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
return super.touchDown(screenX, screenY, pointer, button)
}
override fun touchUp(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
return super.touchUp(screenX, screenY, pointer, button)
}
override fun scrolled(amount: Int): Boolean {
return super.scrolled(amount)
}
override fun keyDown(keycode: Int): Boolean {
return super.keyDown(keycode)
}
override fun keyUp(keycode: Int): Boolean {
return super.keyUp(keycode)
}
override fun keyTyped(character: Char): Boolean {
return super.keyTyped(character)
}
override fun resize(width: Int, height: Int) {
super.resize(width, height)
}
}

View File

@@ -7,7 +7,7 @@ import com.badlogic.gdx.graphics.GL20
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import com.badlogic.gdx.graphics.glutils.ShapeRenderer
import net.torvald.terrarum.*
import net.torvald.terrarum.modulebasegame.gameactors.ActorWithPhysics
import net.torvald.terrarum.gameactors.ActorWBMovable
import net.torvald.terrarum.modulebasegame.gameactors.ActorInventory.Companion.CAPACITY_MODE_NO_ENCUMBER
import net.torvald.terrarum.modulebasegame.gameactors.Pocketed
import net.torvald.terrarum.Second
@@ -91,7 +91,7 @@ class UIInventoryFull(
UIItemInventoryEquippedView(
this,
actor!!.inventory,
actor as ActorWithPhysics,
actor as ActorWBMovable,
internalWidth - UIItemInventoryEquippedView.width + (Terrarum.WIDTH - internalWidth) / 2,
109 + (Terrarum.HEIGHT - internalHeight) / 2
)

View File

@@ -5,7 +5,7 @@ import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.terrarum.*
import net.torvald.terrarum.modulebasegame.gameactors.ActorInventory
import net.torvald.terrarum.modulebasegame.gameactors.ActorWithPhysics
import net.torvald.terrarum.gameactors.ActorWBMovable
import net.torvald.terrarum.itemproperties.GameItem
import net.torvald.terrarum.itemproperties.ItemCodex
import net.torvald.terrarum.ui.UIItem
@@ -16,7 +16,7 @@ import net.torvald.terrarum.ui.UIItem
class UIItemInventoryEquippedView(
parentUI: UIInventoryFull,
val inventory: ActorInventory,
val theActor: ActorWithPhysics,
val theActor: ActorWBMovable,
override var posX: Int,
override var posY: Int
) : UIItem(parentUI) {

View File

@@ -5,7 +5,7 @@ import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import com.jme3.math.FastMath
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.modulebasegame.gameactors.AVKey
import net.torvald.terrarum.gameactors.AVKey
import net.torvald.terrarum.Second
import net.torvald.terrarum.itemproperties.ItemCodex
import net.torvald.terrarum.modulebasegame.Ingame
@@ -39,7 +39,7 @@ class UIPieMenu : UICanvas() {
override fun updateUI(delta: Float) {
if (selection >= 0)
(Terrarum.ingame!! as Ingame).player.actorValue[AVKey.__PLAYER_QUICKSLOTSEL] =
(Terrarum.ingame!! as Ingame).playableActor.actorValue[AVKey.__PLAYER_QUICKSLOTSEL] =
selection % slotCount
@@ -83,7 +83,7 @@ class UIPieMenu : UICanvas() {
// draw item
val itemPair = (Terrarum.ingame!! as Ingame).player.inventory.getQuickBar(i)
val itemPair = (Terrarum.ingame!! as Ingame).playableActor.inventory.getQuickBar(i)
if (itemPair != null) {
val itemImage = ItemCodex.getItemImage(itemPair.item)

View File

@@ -5,7 +5,7 @@ import com.badlogic.gdx.graphics.Camera
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.modulebasegame.gameactors.AVKey
import net.torvald.terrarum.gameactors.AVKey
import net.torvald.terrarum.Second
import net.torvald.terrarum.gameworld.fmod
import net.torvald.terrarum.itemproperties.ItemCodex
@@ -28,8 +28,8 @@ class UIQuickBar : UICanvas() {
private val startPointY = ItemSlotImageBuilder.slotImage.tileH / 2
private var selection: Int
get() = (Terrarum.ingame!! as Ingame).player.actorValue.getAsInt(AVKey.__PLAYER_QUICKSLOTSEL) ?: 0
set(value) { (Terrarum.ingame!! as Ingame).player.actorValue.set(AVKey.__PLAYER_QUICKSLOTSEL, value.fmod(SLOT_COUNT)) }
get() = (Terrarum.ingame!! as Ingame).playableActor.actorValue.getAsInt(AVKey.__PLAYER_QUICKSLOTSEL) ?: 0
set(value) { (Terrarum.ingame!! as Ingame).playableActor.actorValue.set(AVKey.__PLAYER_QUICKSLOTSEL, value.fmod(SLOT_COUNT)) }
override fun updateUI(delta: Float) {
}
@@ -54,7 +54,7 @@ class UIQuickBar : UICanvas() {
)
// draw item
val itemPair = (Terrarum.ingame!! as Ingame).player.inventory.getQuickBar(i)
val itemPair = (Terrarum.ingame!! as Ingame).playableActor.inventory.getQuickBar(i)
if (itemPair != null) {
val itemImage = ItemCodex.getItemImage(itemPair.item)

View File

@@ -8,6 +8,7 @@ import net.torvald.terrarum.*
import net.torvald.terrarum.modulebasegame.gameactors.ActorHumanoid
import net.torvald.terrarum.Second
import net.torvald.terrarum.modulebasegame.Ingame
import net.torvald.terrarum.modulebasegame.gameworld.GameWorldExtension
import net.torvald.terrarum.roundInt
import net.torvald.terrarum.modulebasegame.gameworld.WorldTime
import net.torvald.terrarum.modulebasegame.imagefont.Watch7SegMain
@@ -40,7 +41,7 @@ class UITierOneWatch(private val player: ActorHumanoid?) : UICanvas() {
private val lcdLitCol = Color(0x141414_ff)
private val worldTime: WorldTime
get() = (Terrarum.ingame!! as Ingame).world.time
get() = (Terrarum.ingame!!.world as GameWorldExtension).time
override fun updateUI(delta: Float) {
@@ -70,11 +71,11 @@ class UITierOneWatch(private val player: ActorHumanoid?) : UICanvas() {
if (player != null) {
val playerPos = player.hIntTilewiseHitbox
lightLevel = (LightmapRenderer.getLight(playerPos.centeredX.toInt(), playerPos.centeredY.toInt()) ?:
(Terrarum.ingame!! as Ingame).world.globalLight
(Terrarum.ingame!!.world).globalLight
)
}
else {
lightLevel = (Terrarum.ingame!! as Ingame).world.globalLight
lightLevel = (Terrarum.ingame!!.world).globalLight
}
// backplate

View File

@@ -7,6 +7,7 @@ import net.torvald.random.HQRNG
import net.torvald.terrarum.modulebasegame.Ingame
import net.torvald.terrarum.LoadScreen
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.modulebasegame.BuildingMaker
import net.torvald.terrarum.ui.UICanvas
import net.torvald.terrarum.ui.UIItemTextButtonList
@@ -14,13 +15,14 @@ class UITitleRemoConRoot : UICanvas() {
companion object {
val remoConWidth = 240
fun getRemoConHeight(menu: ArrayList<String>) = 36 * menu.size.plus(1)
fun getRemoConHeight(menu: Array<String>) = 36 * menu.size.plus(1)
val menubarOffY: Int; get() = Terrarum.HEIGHT / 2 - (Terrarum.fontGame.lineHeight * 1.5).toInt()
}
/** Contains STRING_IDs */
val menuLabels = arrayOf(
val menuLabels = arrayListOf(
"MENU_MODE_SINGLEPLAYER",
"MENU_OPTIONS",
"MENU_MODULES",
@@ -29,6 +31,15 @@ class UITitleRemoConRoot : UICanvas() {
"MENU_LABEL_QUIT"
)
init {
if (Terrarum.getConfigBoolean("__debug")) {
menuLabels.addAll(arrayOf(
" Development Tools $",
"Building Maker"
))
}
}
override var width: Int = remoConWidth
override var height: Int = getRemoConHeight(menuLabels)
@@ -37,7 +48,7 @@ class UITitleRemoConRoot : UICanvas() {
private val menubar = UIItemTextButtonList(
this,
menuLabels,
menuLabels.toTypedArray(),
0, menubarOffY,
this.width, this.height,
textAreaWidth = this.width,
@@ -104,6 +115,19 @@ class UITitleRemoConRoot : UICanvas() {
remoConCredits.setAsOpen()
}
menubar.buttons[menuLabels.indexOf("MENU_LABEL_QUIT")].clickOnceListener = { _, _, _ -> Thread.sleep(50); System.exit(0) }
if (Terrarum.getConfigBoolean("__debug")) {
menubar.buttons[menuLabels.indexOf("Building Maker")].clickOnceListener = { _, _, _ ->
this.setAsClose()
Thread.sleep(50)
val maker = BuildingMaker(Terrarum.batch)
Terrarum.ingame = maker
Terrarum.setScreen(maker)
}
}
}
override fun updateUI(delta: Float) {

View File

@@ -0,0 +1,20 @@
package net.torvald.terrarum.modulebasegame.weather
import com.badlogic.gdx.graphics.Texture
import net.torvald.terrarum.GdxColorMap
import java.util.*
/**
* Note: Colour maps are likely to have sparse data points
* (i.e., they have 2 475 px in width and you'll need 79 200 data points for a day)
* so between two must be interpolated.
*
* Created by minjaesong on 2016-07-11.
*/
data class BaseModularWeather(
var skyboxGradColourMap: GdxColorMap, // row 0: skybox grad top, row 1: skybox grad bottom, row 2: sunlight (RGBA)
val classification: String,
var extraImages: ArrayList<Texture>,
val mixFrom: String? = null,
val mixPercentage: Double? = null
)

View File

@@ -0,0 +1,253 @@
package net.torvald.terrarum.modulebasegame.weather
import com.badlogic.gdx.Gdx
import com.badlogic.gdx.Input
import com.badlogic.gdx.graphics.*
import net.torvald.terrarum.utils.JsonFetcher
import net.torvald.colourutil.*
import net.torvald.random.HQRNG
import net.torvald.terrarum.*
import net.torvald.terrarum.gameactors.ActorWithBody
import net.torvald.terrarum.modulebasegame.gameactors.ParticleMegaRain
import net.torvald.terrarum.gamecontroller.KeyToggler
import net.torvald.terrarum.modulebasegame.Ingame
import net.torvald.terrarum.modulebasegame.gameworld.GameWorldExtension
import net.torvald.terrarum.modulebasegame.gameworld.WorldTime
import net.torvald.terrarum.worlddrawer.FeaturesDrawer
import net.torvald.terrarum.worlddrawer.WorldCamera
import net.torvald.terrarum.modulebasegame.worldgenerator.WorldGenerator
import java.io.File
import java.util.*
/**
*
*
* Current, next are there for cross-fading two weathers
*
*
* Building a CLUT:
* Brightest:Darkest must be "around" 10:1
* Is RGBA-formatted (32-bit)
*
* Created by minjaesong on 2016-07-11.
*/
internal object WeatherMixer {
var weatherList: HashMap<String, ArrayList<BaseModularWeather>>
var currentWeather: BaseModularWeather
var nextWeather: BaseModularWeather
lateinit var mixedWeather: BaseModularWeather
val globalLightNow = Color(0)
// Weather indices
const val WEATHER_GENERIC = "generic"
const val WEATHER_GENERIC_RAIN = "genericrain"
// TODO add weather classification indices manually
// TODO to save from GL overhead, store lightmap to array; use GdxColorMap
init {
weatherList = HashMap<String, ArrayList<BaseModularWeather>>()
// read weather descriptions from assets/weather (modular weather)
val weatherRawValidList = ArrayList<File>()
val weatherRaws = ModMgr.getFiles("basegame", "weathers")
weatherRaws.forEach {
if (!it.isDirectory && it.name.endsWith(".json"))
weatherRawValidList.add(it)
}
// --> read from directory and store file that looks like RAW
for (raw in weatherRawValidList) {
val weather = readFromJson(raw)
// if List for the classification does not exist, make one
if (!weatherList.containsKey(weather.classification))
weatherList.put(weather.classification, ArrayList())
weatherList[weather.classification]!!.add(weather)
}
// initialise
currentWeather = weatherList[WEATHER_GENERIC]!![0]
nextWeather = getRandomWeather(WEATHER_GENERIC)
}
/**
* Part of Ingame update
*/
fun update(delta: Float, player: ActorWithBody) {
currentWeather = weatherList[WEATHER_GENERIC]!![0]
// test rain toggled by F2
if (KeyToggler.isOn(Input.Keys.F2)) {
val playerPosX = player.hitbox.centeredX
val playerPosY = player.hitbox.centeredY
kotlin.repeat(7) {
val rainParticle = ParticleMegaRain(
playerPosX + HQRNG().nextInt(Terrarum.WIDTH) - Terrarum.HALFW,
playerPosY - Terrarum.HEIGHT
)
(Terrarum.ingame!! as Ingame).addParticle(rainParticle)
}
//globalLightNow.set(getGlobalLightOfTime((Terrarum.ingame!!.world).time.todaySeconds).mul(0.3f, 0.3f, 0.3f, 0.58f))
}
}
//private val parallaxZeroPos = WorldGenerator.TERRAIN_AVERAGE_HEIGHT * 0.75f // just an arb multiplier (266.66666 -> 200)
private val parallaxDomainSize = WorldGenerator.TERRAIN_UNDULATION / 2f
/**
* Sub-portion of IngameRenderer. You are not supposed to directly deal with this.
*/
internal fun render(camera: Camera, world: GameWorldExtension) {
val parallaxZeroPos = (world.height / 3) * 0.75f // just an arb multiplier (266.66666 -> 200)
// we will not care for nextSkybox for now
val timeNow = world.time.todaySeconds
val skyboxColourMap = currentWeather.skyboxGradColourMap
// calculate global light
val globalLight = getGradientColour(skyboxColourMap, 2, timeNow)
globalLightNow.set(globalLight)
/* (copied from the shader source)
UV mapping coord.y
-+ <- 1.0 =
D| = // parallax of +1
i| = =
s| = // parallax of 0
p| = =
.| = // parallax of -1
-+ <- 0.0 =
*/
val parallax: Float = (parallaxZeroPos - WorldCamera.gdxCamY.div(FeaturesDrawer.TILE_SIZE.toFloat())) / parallaxDomainSize
// draw skybox to provided graphics instance
val topCol = getGradientColour(skyboxColourMap, 0, timeNow)
val bottomCol = getGradientColour(skyboxColourMap, 1, timeNow)
//Terrarum.textureWhiteSquare.bind(0)
Terrarum.shaderSkyboxFill.begin()
Terrarum.shaderSkyboxFill.setUniformMatrix("u_projTrans", camera.combined)
Terrarum.shaderSkyboxFill.setUniformf("topColor", topCol.r, topCol.g, topCol.b)
Terrarum.shaderSkyboxFill.setUniformf("bottomColor", bottomCol.r, bottomCol.g, bottomCol.b)
Terrarum.shaderSkyboxFill.setUniformf("parallax", parallax)
Terrarum.shaderSkyboxFill.setUniformf("parallax_size", 1f/3f)
Terrarum.fullscreenQuad.render(Terrarum.shaderSkyboxFill, GL20.GL_TRIANGLES)
Terrarum.shaderSkyboxFill.end()
Gdx.gl.glActiveTexture(GL20.GL_TEXTURE0) // so that batch that comes next will bind any tex to it
}
fun Float.clampOne() = if (this > 1) 1f else this
private operator fun Color.times(other: Color) = Color(this.r * other.r, this.g * other.g, this.b * other.b, 1f)
/**
* Get a GL of specific time
*/
fun getGlobalLightOfTime(timeInSec: Int): Color =
getGradientColour(currentWeather.skyboxGradColourMap, 2, timeInSec)
fun getGradientColour(colorMap: GdxColorMap, row: Int, timeInSec: Int): Color {
val dataPointDistance = WorldTime.DAY_LENGTH / colorMap.width
val phaseThis: Int = timeInSec / dataPointDistance // x-coord in gradmap
val phaseNext: Int = (phaseThis + 1) % colorMap.width
val colourThis = colorMap.get(phaseThis, row)
val colourNext = colorMap.get(phaseNext, row)
// interpolate R, G, B and A
val scale = (timeInSec % dataPointDistance).toFloat() / dataPointDistance // [0.0, 1.0]
val newCol = CIELuvUtil.getGradient(scale, colourThis, colourNext)
/* // very nice monitor code
// 65 -> 66 | 300 | 19623 | RGB8(255, 0, 255) -[41%]-> RGB8(193, 97, 23) | * `230`40`160`
// ^ step |width| time | colour from scale colour to | output
if (dataPointDistance == 300)
println("$phaseThis -> $phaseNext | $dataPointDistance | $timeInSec" +
" | ${colourThis.toStringRGB()} -[${scale.times(100).toInt()}%]-> ${colourNext.toStringRGB()}" +
" | * `$r`$g`$b`")*/
return newCol
}
fun getWeatherList(classification: String) = weatherList[classification]!!
fun getRandomWeather(classification: String) =
getWeatherList(classification)[HQRNG().nextInt(getWeatherList(classification).size)]
fun readFromJson(file: File): BaseModularWeather = readFromJson(file.path)
fun readFromJson(path: String): BaseModularWeather {
/* JSON structure:
{
"skyboxGradColourMap": "colourmap/sky_colour.tga", // string (path to image) for dynamic. Image must be RGBA8888 or RGB888
"extraImages": [
// if any, it will be like:
sun01.tga,
clouds01.tga,
clouds02.tga,
auroraBlueViolet.tga
]
}
*/
val pathToImage = "weathers"
val JSON = JsonFetcher(path)
val skyboxInJson = JSON.get("skyboxGradColourMap").asJsonPrimitive
val extraImagesPath = JSON.getAsJsonArray("extraImages")
val skybox = if (skyboxInJson.isString)
GdxColorMap(ModMgr.getGdxFile("basegame", "$pathToImage/${skyboxInJson.asString}"))
else
throw IllegalStateException("In weather descriptor $path -- skyboxGradColourMap seems malformed.")
val extraImages = ArrayList<Texture>()
for (i in extraImagesPath)
extraImages.add(Texture(ModMgr.getGdxFile("basegame", "$pathToImage/${i.asString}")))
val classification = JSON.get("classification").asJsonPrimitive.asString
var mixFrom: String?
try { mixFrom = JSON.get("mixFrom").asJsonPrimitive.asString }
catch (e: IllegalStateException) { mixFrom = null }
var mixPercentage: Double?
try { mixPercentage = JSON.get("mixPercentage").asJsonPrimitive.asDouble }
catch (e: IllegalStateException) { mixPercentage = null }
return BaseModularWeather(
skyboxGradColourMap = skybox,
classification = classification,
extraImages = extraImages
)
}
}

View File

@@ -605,7 +605,7 @@ object WorldGenerator {
private fun fillMapByNoiseMap() {
println("[mapgenerator] Shaping world...")
LoadScreen.addMessage("Shaping world...")
LoadScreen.addMessage("Reticulating splines...") // RETICULATING SPLINES
// generate dirt-stone transition line
// use catmull spline
val dirtStoneLine = IntArray(WIDTH)