pickaxe working as intended

This commit is contained in:
Song Minjae
2017-04-18 01:14:25 +09:00
parent f840dbe7de
commit 5fe604cf45
41 changed files with 271 additions and 231 deletions

View File

@@ -1,4 +1,4 @@
"id";"dmg";"name" ; "opacity";"strength";"dsty";"mate";"fluid";"solid";"wall"; "lumcolor";"drop";"ddmg";"fall";"dlfn";"vscs";"fv";"friction" "id";"sid";"name" ; "opacity";"strength";"dsty";"mate";"fluid";"solid";"wall"; "lumcolor";"drop";"ddmg";"fall";"dlfn";"vscs";"fv";"friction"
"0"; "0";"TILE_AIR" ; "8396808"; "1"; "1";"null"; "0"; "0"; "0"; "0"; "0"; "0"; "0"; "0"; "N/A"; "0";"4" "0"; "0";"TILE_AIR" ; "8396808"; "1"; "1";"null"; "0"; "0"; "0"; "0"; "0"; "0"; "0"; "0"; "N/A"; "0";"4"
"1"; "0";"TILE_STONE" ; "33587232"; "48";"2400";"rock"; "0"; "1"; "1"; "0"; "1"; "0"; "0"; "0"; "N/A"; "0";"16" "1"; "0";"TILE_STONE" ; "33587232"; "48";"2400";"rock"; "0"; "1"; "1"; "0"; "1"; "0"; "0"; "0"; "N/A"; "0";"16"
"1"; "1";"TILE_STONE_QUARRIED" ; "33587232"; "48";"2400";"rock"; "0"; "1"; "1"; "0"; "1"; "1"; "0"; "0"; "N/A"; "0";"16" "1"; "1";"TILE_STONE_QUARRIED" ; "33587232"; "48";"2400";"rock"; "0"; "1"; "1"; "0"; "1"; "1"; "0"; "0"; "N/A"; "0";"16"
Can't render this file because it contains an unexpected character in line 1 and column 18.

View File

@@ -1,5 +1,6 @@
package net.torvald package net.torvald
import net.torvald.terrarum.ModMgr
import org.apache.commons.csv.CSVFormat import org.apache.commons.csv.CSVFormat
import org.apache.commons.csv.CSVParser import org.apache.commons.csv.CSVParser
import org.apache.commons.csv.CSVRecord import org.apache.commons.csv.CSVRecord
@@ -16,8 +17,7 @@ object CSVFetcher {
private var csvString: StringBuffer? = null private var csvString: StringBuffer? = null
@Throws(IOException::class) fun readFromFile(csvFilePath: String): List<CSVRecord> {
operator fun invoke(csvFilePath: String): List<CSVRecord> {
csvString = StringBuffer() // reset buffer every time it called csvString = StringBuffer() // reset buffer every time it called
readCSVasString(csvFilePath) readCSVasString(csvFilePath)
@@ -40,6 +40,8 @@ object CSVFetcher {
return csvRecordList return csvRecordList
} }
fun readFromModule(module: String, path: String) = readFromFile(ModMgr.getPath(module, path))
fun readFromString(csv: String): List<CSVRecord> { fun readFromString(csv: String): List<CSVRecord> {
val csvParser = CSVParser.parse( val csvParser = CSVParser.parse(
csv, csv,

View File

@@ -5,14 +5,14 @@ import net.torvald.terrarum.weather.toColor
import org.newdawn.slick.Color import org.newdawn.slick.Color
import org.newdawn.slick.Image import org.newdawn.slick.Image
import net.torvald.colourutil.CIEXYZUtil.toColor import net.torvald.colourutil.CIEXYZUtil.toColor
import net.torvald.terrarum.ModuleManager import net.torvald.terrarum.ModMgr
/** /**
* RGB-modeled CCT calculator * RGB-modeled CCT calculator
* Created by minjaesong on 16-07-26. * Created by minjaesong on 16-07-26.
*/ */
object ColourTemp { object ColourTemp {
private var envOverlayColourmap = Image(ModuleManager.getPath("basegame", "colourmap/black_body_col_1000_40000_K.tga")) private var envOverlayColourmap = Image(ModMgr.getPath("basegame", "colourmap/black_body_col_1000_40000_K.tga"))
private fun colTempToImagePos(K: Int): Int { private fun colTempToImagePos(K: Int): Int {
if (K < 1000 || K >= 40000) throw IllegalArgumentException("K: out of range. ($K)") if (K < 1000 || K >= 40000) throw IllegalArgumentException("K: out of range. ($K)")

View File

@@ -5,7 +5,6 @@ import net.torvald.terrarum.mapgenerator.RoguelikeRandomiser
import net.torvald.terrarum.Terrarum import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.itemproperties.ItemCodex import net.torvald.terrarum.itemproperties.ItemCodex
import net.torvald.terrarum.itemproperties.MaterialCodex import net.torvald.terrarum.itemproperties.MaterialCodex
import net.torvald.terrarum.tileproperties.TilePropCSV
import net.torvald.terrarum.tileproperties.TileCodex import net.torvald.terrarum.tileproperties.TileCodex
import org.apache.commons.codec.digest.DigestUtils import org.apache.commons.codec.digest.DigestUtils
import java.io.FileInputStream import java.io.FileInputStream
@@ -36,7 +35,7 @@ object WriteMeta {
* @param savegameName -- Nullable. If the value is not specified, saveDirectoryName will be used instead. * @param savegameName -- Nullable. If the value is not specified, saveDirectoryName will be used instead.
*/ */
fun write(saveDirectoryName: String, savegameName: String?): Boolean { fun write(saveDirectoryName: String, savegameName: String?): Boolean {
val hashArray: ArrayList<ByteArray> = ArrayList() /*val hashArray: ArrayList<ByteArray> = ArrayList()
val savenameAsByteArray: ByteArray = val savenameAsByteArray: ByteArray =
(savegameName ?: saveDirectoryName).toByteArray(Charsets.UTF_8) (savegameName ?: saveDirectoryName).toByteArray(Charsets.UTF_8)
@@ -75,20 +74,7 @@ object WriteMeta {
} }
catch (e: IOException) { catch (e: IOException) {
e.printStackTrace() e.printStackTrace()
} }*/
return false return false
} }
fun toByteArray(long: Long): ByteArray {
return byteArrayOf(
(long.ushr(0x38) and 0xFF).toByte(),
(long.ushr(0x30) and 0xFF).toByte(),
(long.ushr(0x28) and 0xFF).toByte(),
(long.ushr(0x20) and 0xFF).toByte(),
(long.ushr(0x18) and 0xFF).toByte(),
(long.ushr(0x10) and 0xFF).toByte(),
(long.ushr(0x08) and 0xFF).toByte(),
(long and 0xFF).toByte()
)
}
} }

View File

@@ -51,60 +51,47 @@ class KVHashMap {
fun getAsInt(key: String): Int? { fun getAsInt(key: String): Int? {
val value = get(key) val value = get(key)
if (value == null) return null
if (value is JsonPrimitive) if (value is JsonPrimitive)
return value.asInt return value.asInt
try { return value as Int
return value as Int
}
catch (e: ClassCastException) {
return null
}
} }
fun getAsDouble(key: String): Double? { fun getAsDouble(key: String): Double? {
val value = get(key) val value = get(key)
if (value == null) return null
if (value is Int) if (value is Int)
return value.toDouble() return value.toDouble()
else if (value is JsonPrimitive) else if (value is JsonPrimitive)
return value.asDouble return value.asDouble
try { return value as Double
return value as Double
}
catch (e: ClassCastException) {
return null
}
} }
fun getAsString(key: String): String? { fun getAsString(key: String): String? {
val value = get(key) val value = get(key)
if (value == null) return null
if (value is JsonPrimitive) if (value is JsonPrimitive)
return value.asString return value.asString
try { return value as String
return value as String
}
catch (e: ClassCastException) {
return null
}
} }
fun getAsBoolean(key: String): Boolean? { fun getAsBoolean(key: String): Boolean? {
val value = get(key) val value = get(key)
if (value == null) return null
if (value is JsonPrimitive) if (value is JsonPrimitive)
return value.asBoolean return value.asBoolean
try { return value as Boolean
return value as Boolean
}
catch (e: ClassCastException) {
return null
}
} }
fun hasKey(key: String) = hashMap.containsKey(key) fun hasKey(key: String) = hashMap.containsKey(key)

View File

@@ -11,7 +11,7 @@ import java.nio.file.FileSystems
* *
* Created by SKYHi14 on 2017-04-17. * Created by SKYHi14 on 2017-04-17.
*/ */
object ModuleManager { object ModMgr {
data class ModuleMetadata(val order: Int, val isDir: Boolean, val desc: String, val libraries: Array<String>) { data class ModuleMetadata(val order: Int, val isDir: Boolean, val desc: String, val libraries: Array<String>) {
override fun toString() = override fun toString() =
@@ -35,7 +35,7 @@ object ModuleManager {
loadOrder.forEachIndexed { index, it -> loadOrder.forEachIndexed { index, it ->
val moduleName = it[0] val moduleName = it[0]
println("[ModuleManager] Loading module $moduleName") println("[ModMgr] Loading module $moduleName")
val description = it[1] val description = it[1]
val libs = it[2].split(';').toTypedArray() val libs = it[2].split(';').toTypedArray()

View File

@@ -12,7 +12,7 @@ import net.torvald.terrarum.gameactors.physicssolver.CollisionSolver
import net.torvald.terrarum.gamecontroller.GameController import net.torvald.terrarum.gamecontroller.GameController
import net.torvald.terrarum.gamecontroller.Key import net.torvald.terrarum.gamecontroller.Key
import net.torvald.terrarum.gamecontroller.KeyToggler import net.torvald.terrarum.gamecontroller.KeyToggler
import net.torvald.terrarum.gameitem.InventoryItem import net.torvald.terrarum.itemproperties.InventoryItem
import net.torvald.terrarum.gameworld.GameWorld import net.torvald.terrarum.gameworld.GameWorld
import net.torvald.terrarum.gameworld.WorldSimulator import net.torvald.terrarum.gameworld.WorldSimulator
import net.torvald.terrarum.gameworld.WorldTime import net.torvald.terrarum.gameworld.WorldTime

View File

@@ -1,8 +1,8 @@
package net.torvald.terrarum package net.torvald.terrarum
import net.torvald.terrarum.gameactors.* import net.torvald.terrarum.gameactors.*
import net.torvald.terrarum.gameitem.IVKey import net.torvald.terrarum.itemproperties.IVKey
import net.torvald.terrarum.gameitem.InventoryItem import net.torvald.terrarum.itemproperties.InventoryItem
import net.torvald.terrarum.itemproperties.ItemCodex import net.torvald.terrarum.itemproperties.ItemCodex
import net.torvald.terrarum.tileproperties.Tile import net.torvald.terrarum.tileproperties.Tile
import net.torvald.terrarum.ui.* import net.torvald.terrarum.ui.*

View File

@@ -313,7 +313,7 @@ object Terrarum : StateBasedGame(GAME_NAME) {
// load modules // load modules
ModuleManager ModMgr
gc.graphics.clear() // clean up any 'dust' in the buffer gc.graphics.clear() // clean up any 'dust' in the buffer

View File

@@ -1,7 +1,7 @@
package net.torvald.terrarum package net.torvald.terrarum
import net.torvald.colourutil.CIELabUtil.darkerLab import net.torvald.colourutil.CIELabUtil.darkerLab
import net.torvald.terrarum.gameitem.InventoryItem import net.torvald.terrarum.itemproperties.InventoryItem
import net.torvald.terrarum.ui.UICanvas import net.torvald.terrarum.ui.UICanvas
import net.torvald.terrarum.ui.UIInventory import net.torvald.terrarum.ui.UIInventory
import net.torvald.terrarum.ui.UIItem import net.torvald.terrarum.ui.UIItem

View File

@@ -79,6 +79,11 @@ object AVKey {
const val MAGICREGENRATE = "magicregenrate" const val MAGICREGENRATE = "magicregenrate"
const val MAGICREGENRATEBUFF = "$MAGICREGENRATE$BUFF" const val MAGICREGENRATEBUFF = "$MAGICREGENRATE$BUFF"
/** Double
*
*/
const val ACTION_INTERVAL = "actioninterval"
/** String /** String
* UUID for certain fixtures * UUID for certain fixtures
@@ -91,4 +96,9 @@ object AVKey {
/** SYNOPSIS: __qsitem1 .. __qsitem10 /** SYNOPSIS: __qsitem1 .. __qsitem10
* contains tem ID; they are supposed to be unique. Indices must be ONE-BASED! */ * contains tem ID; they are supposed to be unique. Indices must be ONE-BASED! */
const val __PLAYER_QSPREFIX = "__qsitem" // __qsitem1 .. __qsitem10 (NOT ZERO BASED!) const val __PLAYER_QSPREFIX = "__qsitem" // __qsitem1 .. __qsitem10 (NOT ZERO BASED!)
/** 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"
} }

View File

@@ -1,10 +1,11 @@
package net.torvald.terrarum.gameactors package net.torvald.terrarum.gameactors
import com.jme3.math.FastMath import com.jme3.math.FastMath
import net.torvald.terrarum.Millisec
import net.torvald.terrarum.Terrarum import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.gameactors.faction.Faction import net.torvald.terrarum.gameactors.faction.Faction
import net.torvald.terrarum.gamecontroller.EnumKeyFunc import net.torvald.terrarum.gamecontroller.EnumKeyFunc
import net.torvald.terrarum.gameitem.InventoryItem import net.torvald.terrarum.itemproperties.InventoryItem
import net.torvald.terrarum.realestate.RealEstateUtility import net.torvald.terrarum.realestate.RealEstateUtility
import org.newdawn.slick.GameContainer import org.newdawn.slick.GameContainer
import org.newdawn.slick.Input import org.newdawn.slick.Input
@@ -22,6 +23,7 @@ open class ActorHumanoid(birth: GameDate, death: GameDate? = null)
var vehicleRiding: Controllable? = null // usually player only var vehicleRiding: Controllable? = null // usually player only
/** Must be set by PlayerFactory */ /** Must be set by PlayerFactory */
override var inventory: ActorInventory = ActorInventory(this, 2000, ActorInventory.CAPACITY_MODE_WEIGHT) // default constructor override var inventory: ActorInventory = ActorInventory(this, 2000, ActorInventory.CAPACITY_MODE_WEIGHT) // default constructor
@@ -77,6 +79,8 @@ open class ActorHumanoid(birth: GameDate, death: GameDate? = null)
@Transient internal const val WALK_ACCEL_BASE: Double = 0.67 @Transient internal const val WALK_ACCEL_BASE: Double = 0.67
@Transient const val BASE_HEIGHT = 40 @Transient const val BASE_HEIGHT = 40
// 333.33 miliseconds
@Transient const val BASE_ACTION_INTERVAL = 1000.0 / 3.0
@Transient const val SPRITE_ROW_IDLE = 0 @Transient const val SPRITE_ROW_IDLE = 0
@Transient const val SPRITE_ROW_WALK = 1 @Transient const val SPRITE_ROW_WALK = 1

View File

@@ -1,7 +1,7 @@
package net.torvald.terrarum.gameactors package net.torvald.terrarum.gameactors
import net.torvald.terrarum.Terrarum import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.gameitem.InventoryItem import net.torvald.terrarum.itemproperties.InventoryItem
import net.torvald.terrarum.itemproperties.ItemCodex import net.torvald.terrarum.itemproperties.ItemCodex
import net.torvald.terrarum.ui.UIInventory import net.torvald.terrarum.ui.UIInventory
import java.util.* import java.util.*

View File

@@ -1329,6 +1329,7 @@ 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)
fun Float.sqrt() = FastMath.sqrt(this)
fun Int.abs() = if (this < 0) -this else this fun Int.abs() = if (this < 0) -this else this
fun Double.bipolarClamp(limit: Double) = fun Double.bipolarClamp(limit: Double) =
if (this > 0 && this > limit) limit if (this > 0 && this > limit) limit

View File

@@ -1,6 +1,6 @@
package net.torvald.terrarum.gameactors package net.torvald.terrarum.gameactors
import net.torvald.terrarum.gameitem.InventoryItem import net.torvald.terrarum.itemproperties.InventoryItem
/** /**
* Created by minjaesong on 16-01-31. * Created by minjaesong on 16-01-31.

View File

@@ -22,6 +22,9 @@ object CreatureBuilder {
val actor = ActorWithSprite(Actor.RenderOrder.MIDDLE) val actor = ActorWithSprite(Actor.RenderOrder.MIDDLE)
InjectCreatureRaw(actor.actorValue, module, jsonFileName) InjectCreatureRaw(actor.actorValue, module, jsonFileName)
actor.actorValue[AVKey.__ACTION_TIMER] = 0.0
return actor return actor
} }
} }

View File

@@ -1,6 +1,6 @@
package net.torvald.terrarum.gameactors package net.torvald.terrarum.gameactors
import net.torvald.terrarum.gameitem.InventoryItem import net.torvald.terrarum.itemproperties.InventoryItem
import net.torvald.terrarum.itemproperties.ItemCodex import net.torvald.terrarum.itemproperties.ItemCodex
import net.torvald.terrarum.tileproperties.TileCodex import net.torvald.terrarum.tileproperties.TileCodex
import org.newdawn.slick.GameContainer import org.newdawn.slick.GameContainer

View File

@@ -7,7 +7,7 @@ import net.torvald.terrarum.gameactors.ai.ActorAI
import net.torvald.terrarum.gameactors.ai.LuaAIWrapper import net.torvald.terrarum.gameactors.ai.LuaAIWrapper
import net.torvald.terrarum.gamecontroller.mouseX import net.torvald.terrarum.gamecontroller.mouseX
import net.torvald.terrarum.gamecontroller.mouseY import net.torvald.terrarum.gamecontroller.mouseY
import net.torvald.terrarum.gameitem.InventoryItem import net.torvald.terrarum.itemproperties.InventoryItem
import org.luaj.vm2.* import org.luaj.vm2.*
import org.luaj.vm2.compiler.LuaC import org.luaj.vm2.compiler.LuaC
import org.luaj.vm2.lib.* import org.luaj.vm2.lib.*

View File

@@ -5,7 +5,7 @@ import net.torvald.random.Fudge3
import net.torvald.terrarum.langpack.Lang import net.torvald.terrarum.langpack.Lang
import com.google.gson.JsonObject import com.google.gson.JsonObject
import net.torvald.terrarum.ActorValue import net.torvald.terrarum.ActorValue
import net.torvald.terrarum.ModuleManager import net.torvald.terrarum.ModMgr
import net.torvald.terrarum.gameactors.ActorHumanoid import net.torvald.terrarum.gameactors.ActorHumanoid
import org.newdawn.slick.SlickException import org.newdawn.slick.SlickException
import java.io.IOException import java.io.IOException
@@ -25,7 +25,7 @@ object InjectCreatureRaw {
* @param jsonFileName with extension * @param jsonFileName with extension
*/ */
operator fun invoke(actorValueRef: ActorValue, module: String, jsonFileName: String) { operator fun invoke(actorValueRef: ActorValue, module: String, jsonFileName: String) {
val jsonObj = JsonFetcher(ModuleManager.getPath(module, "creatures/$jsonFileName")) val jsonObj = JsonFetcher(ModMgr.getPath(module, "creatures/$jsonFileName"))
val elementsInt = arrayOf(AVKey.BASEHEIGHT, AVKey.TOOLSIZE, AVKey.ENCUMBRANCE) val elementsInt = arrayOf(AVKey.BASEHEIGHT, AVKey.TOOLSIZE, AVKey.ENCUMBRANCE)
val elementsString = arrayOf(AVKey.RACENAME, AVKey.RACENAMEPLURAL) val elementsString = arrayOf(AVKey.RACENAME, AVKey.RACENAMEPLURAL)

View File

@@ -19,6 +19,8 @@ object PlayerBuilder {
// do etc. // do etc.
p.actorValue[AVKey.__PLAYER_QUICKSLOTSEL] = 0 p.actorValue[AVKey.__PLAYER_QUICKSLOTSEL] = 0
p.actorValue[AVKey.__ACTION_TIMER] = 0.0
p.actorValue[AVKey.ACTION_INTERVAL] = ActorHumanoid.BASE_ACTION_INTERVAL
return p return p
} }

View File

@@ -1,7 +1,7 @@
package net.torvald.terrarum.gameactors package net.torvald.terrarum.gameactors
import net.torvald.spriteanimation.SpriteAnimation import net.torvald.spriteanimation.SpriteAnimation
import net.torvald.terrarum.ModuleManager import net.torvald.terrarum.ModMgr
import net.torvald.terrarum.gameactors.ActorHumanoid import net.torvald.terrarum.gameactors.ActorHumanoid
import net.torvald.terrarum.gameactors.ai.LuaAIWrapper import net.torvald.terrarum.gameactors.ai.LuaAIWrapper
import net.torvald.terrarum.mapdrawer.FeaturesDrawer import net.torvald.terrarum.mapdrawer.FeaturesDrawer
@@ -20,10 +20,12 @@ object PlayerBuilderCynthia {
p.actorValue[AVKey.__PLAYER_QUICKSLOTSEL] = 0 p.actorValue[AVKey.__PLAYER_QUICKSLOTSEL] = 0
p.actorValue[AVKey.__ACTION_TIMER] = 0.0
p.actorValue[AVKey.ACTION_INTERVAL] = ActorHumanoid.BASE_ACTION_INTERVAL
p.actorValue[AVKey.NAME] = "Cynthia" p.actorValue[AVKey.NAME] = "Cynthia"
p.makeNewSprite(26, 42, ModuleManager.getPath("basegame", "sprites/test_player_2.tga")) p.makeNewSprite(26, 42, ModMgr.getPath("basegame", "sprites/test_player_2.tga"))
p.sprite!!.delay = 200 p.sprite!!.delay = 200
p.sprite!!.setRowsAndFrames(1, 1) p.sprite!!.setRowsAndFrames(1, 1)

View File

@@ -5,7 +5,7 @@ import net.torvald.terrarum.gameactors.faction.Faction
import net.torvald.spriteanimation.SpriteAnimation import net.torvald.spriteanimation.SpriteAnimation
import com.google.gson.JsonObject import com.google.gson.JsonObject
import net.torvald.terrarum.ActorValue import net.torvald.terrarum.ActorValue
import net.torvald.terrarum.ModuleManager import net.torvald.terrarum.ModMgr
import net.torvald.terrarum.gameactors.ActorHumanoid import net.torvald.terrarum.gameactors.ActorHumanoid
import net.torvald.terrarum.gameactors.faction.FactionFactory import net.torvald.terrarum.gameactors.faction.FactionFactory
import net.torvald.terrarum.itemproperties.ItemCodex import net.torvald.terrarum.itemproperties.ItemCodex
@@ -28,11 +28,11 @@ object PlayerBuilderSigrid {
p.referenceID = 0x51621D // the only constant of this procedural universe p.referenceID = 0x51621D // the only constant of this procedural universe
p.makeNewSprite(28, 51, ModuleManager.getPath("basegame", "sprites/test_player.tga")) p.makeNewSprite(28, 51, ModMgr.getPath("basegame", "sprites/test_player.tga"))
p.sprite!!.delay = 200 p.sprite!!.delay = 200
p.sprite!!.setRowsAndFrames(1, 1) p.sprite!!.setRowsAndFrames(1, 1)
p.makeNewSpriteGlow(28, 51, ModuleManager.getPath("basegame", "sprites/test_player_glow.tga")) p.makeNewSpriteGlow(28, 51, ModMgr.getPath("basegame", "sprites/test_player_glow.tga"))
p.spriteGlow!!.delay = 200 p.spriteGlow!!.delay = 200
p.spriteGlow!!.setRowsAndFrames(1, 1) p.spriteGlow!!.setRowsAndFrames(1, 1)
@@ -64,7 +64,8 @@ object PlayerBuilderSigrid {
p.actorValue[AVKey.BASEDEFENCE] = 141 p.actorValue[AVKey.BASEDEFENCE] = 141
p.actorValue[AVKey.__PLAYER_QUICKSLOTSEL] = 0 p.actorValue[AVKey.__PLAYER_QUICKSLOTSEL] = 0
//p.actorValue["__selectedtile"] = 147 // test code; replace with <tile_item>.primaryUse(gc, delta) p.actorValue[AVKey.__ACTION_TIMER] = 0.0
p.actorValue[AVKey.ACTION_INTERVAL] = ActorHumanoid.BASE_ACTION_INTERVAL
p.actorValue["__aimhelper"] = true // TODO when you'll gonna implement it? p.actorValue["__aimhelper"] = true // TODO when you'll gonna implement it?
p.setHitboxDimension(15, p.actorValue.getAsInt(AVKey.BASEHEIGHT)!!, 11, 0) p.setHitboxDimension(15, p.actorValue.getAsInt(AVKey.BASEHEIGHT)!!, 11, 0)

View File

@@ -1,6 +1,6 @@
package net.torvald.terrarum.gameactors package net.torvald.terrarum.gameactors
import net.torvald.terrarum.ModuleManager import net.torvald.terrarum.ModMgr
import net.torvald.terrarum.gameactors.ai.LuaAIWrapper import net.torvald.terrarum.gameactors.ai.LuaAIWrapper
import net.torvald.terrarum.mapdrawer.FeaturesDrawer import net.torvald.terrarum.mapdrawer.FeaturesDrawer
@@ -14,10 +14,12 @@ object PlayerBuilderTestSubject1 {
p.actorValue[AVKey.__PLAYER_QUICKSLOTSEL] = 0 p.actorValue[AVKey.__PLAYER_QUICKSLOTSEL] = 0
p.actorValue[AVKey.__ACTION_TIMER] = 0.0
p.actorValue[AVKey.ACTION_INTERVAL] = ActorHumanoid.BASE_ACTION_INTERVAL
p.actorValue[AVKey.NAME] = "Test Subject 1" p.actorValue[AVKey.NAME] = "Test Subject 1"
p.makeNewSprite(48, 52, ModuleManager.getPath("basegame", "sprites/npc_template_anim_prototype.tga")) p.makeNewSprite(48, 52, ModMgr.getPath("basegame", "sprites/npc_template_anim_prototype.tga"))
p.sprite!!.delay = 200 p.sprite!!.delay = 200
p.sprite!!.setRowsAndFrames(2, 4) p.sprite!!.setRowsAndFrames(2, 4)

View File

@@ -1,7 +1,7 @@
package net.torvald.terrarum.gameactors package net.torvald.terrarum.gameactors
import net.torvald.terrarum.Terrarum import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.gameitem.InventoryItem import net.torvald.terrarum.itemproperties.InventoryItem
import net.torvald.terrarum.itemproperties.ItemCodex import net.torvald.terrarum.itemproperties.ItemCodex
/** /**

View File

@@ -2,7 +2,7 @@ package net.torvald.terrarum.gameactors.faction
import net.torvald.JsonFetcher import net.torvald.JsonFetcher
import com.google.gson.JsonObject import com.google.gson.JsonObject
import net.torvald.terrarum.ModuleManager import net.torvald.terrarum.ModMgr
import java.io.IOException import java.io.IOException
@@ -16,7 +16,7 @@ object FactionFactory {
*/ */
@Throws(IOException::class) @Throws(IOException::class)
fun create(module: String, path: String): Faction { fun create(module: String, path: String): Faction {
val jsonObj = JsonFetcher(ModuleManager.getPath(module, path)) val jsonObj = JsonFetcher(ModMgr.getPath(module, path))
val factionObj = Faction(jsonObj.get("factionname").asString) val factionObj = Faction(jsonObj.get("factionname").asString)
jsonObj.get("factionamicable").asJsonArray.forEach { factionObj.addFactionAmicable(it.asString) } jsonObj.get("factionamicable").asJsonArray.forEach { factionObj.addFactionAmicable(it.asString) }

View File

@@ -4,7 +4,7 @@ import net.torvald.terrarum.mapdrawer.TilesDrawer
import net.torvald.terrarum.mapdrawer.FeaturesDrawer import net.torvald.terrarum.mapdrawer.FeaturesDrawer
import net.torvald.terrarum.Terrarum import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.gameactors.* import net.torvald.terrarum.gameactors.*
import net.torvald.terrarum.gameitem.InventoryItem import net.torvald.terrarum.itemproperties.InventoryItem
import net.torvald.terrarum.mapdrawer.MapCamera import net.torvald.terrarum.mapdrawer.MapCamera
import net.torvald.terrarum.tileproperties.Tile import net.torvald.terrarum.tileproperties.Tile
import net.torvald.terrarum.tileproperties.TileCodex import net.torvald.terrarum.tileproperties.TileCodex
@@ -78,7 +78,7 @@ object GameController {
if (input.isMouseButtonDown(Terrarum.getConfigInt("mouseprimary"))) { if (input.isMouseButtonDown(Terrarum.getConfigInt("mouseprimary"))) {
ingame.player!!.consumePrimary(itemOnGrip) ingame.player!!.consumePrimary(itemOnGrip)
} }
else if (input.isMouseButtonDown(Terrarum.getConfigInt("mousesecondary"))) { if (input.isMouseButtonDown(Terrarum.getConfigInt("mousesecondary"))) {
ingame.player!!.consumeSecondary(itemOnGrip) ingame.player!!.consumeSecondary(itemOnGrip)
} }
} }
@@ -113,7 +113,21 @@ object GameController {
} }
fun mouseReleased(button: Int, x: Int, y: Int) { fun mouseReleased(button: Int, x: Int, y: Int) {
if (Terrarum.ingame != null) {
val ingame = Terrarum.ingame!!
if (ingame.player != null && ingame.canPlayerControl) {
val itemOnGrip = ingame.player!!.inventory.itemEquipped[InventoryItem.EquipPosition.HAND_GRIP]
if (itemOnGrip != null) {
if (button == Terrarum.getConfigInt("mousePrimary")) {
itemOnGrip.endPrimaryUse(Terrarum.appgc, Terrarum.UPDATE_DELTA)
}
if (button == Terrarum.getConfigInt("mouseSecondary")) {
itemOnGrip.endSecondaryUse(Terrarum.appgc, Terrarum.UPDATE_DELTA)
}
}
}
}
} }
fun mouseWheelMoved(change: Int) { fun mouseWheelMoved(change: Int) {

View File

@@ -1,67 +0,0 @@
package net.torvald.terrarum.gameitem
import net.torvald.random.HQRNG
import net.torvald.terrarum.KVHashMap
import net.torvald.terrarum.itemproperties.ItemCodex
import org.newdawn.slick.GameContainer
/**
* Items that has some more information (like floppy disk that contains UUID)
*
* @param baseItemID ID of the item that this item is based on
*
* Created by minjaesong on 16-09-08.
*/
@Deprecated("Use InventoryItem's ItemProp")
open abstract class DynamicItem(val baseItemID: Int?, newMass: Double? = null, newScale: Double? = null)
: InventoryItem() {
/*
override val id: Int = generateUniqueDynamicItemID()
private fun generateUniqueDynamicItemID(): Int {
var ret: Int
do {
ret = HQRNG().nextInt().and(0x7FFFFFFF) // set new ID
} while (ItemCodex.contains(ret) || ret < ItemCodex.ITEM_DYNAMIC_MIN || ret > ItemCodex.ITEM_DYNAMIC_MAX) // check for collision
return ret
}
/**
* Weight of the item
*/
override var mass: Double
get() = itemInfo.getAsDouble(ItemInfoKey.MASS)!!
set(value) {
itemInfo[ItemInfoKey.MASS] = value
}
/**
* Scale of the item. Real mass: mass * (scale^3)
*
* For static item, it must be 1.0. If you tinkered the item to be bigger,
* it must be re-assigned as Dynamic Item
*/
override var scale: Double
get() = itemInfo.getAsDouble(ItemInfoKey.SCALE) ?: 1.0
set(value) {
itemInfo[ItemInfoKey.SCALE] = value
}
val itemInfo = KVHashMap()
init {
// set mass to the value from item codex using baseItemID
if (baseItemID == null) {
mass = newMass!!
}
else {
mass = newMass ?: ItemCodex[baseItemID].mass
}
if (baseItemID == null) {
scale = newScale!!
}
else {
scale = newScale ?: ItemCodex[baseItemID].scale
}
}*/
}

View File

@@ -2,11 +2,12 @@
package net.torvald.terrarum.gameworld package net.torvald.terrarum.gameworld
import net.torvald.terrarum.realestate.RealEstateUtility import net.torvald.terrarum.realestate.RealEstateUtility
import net.torvald.terrarum.tileproperties.TileCodex
import org.dyn4j.geometry.Vector2 import org.dyn4j.geometry.Vector2
import org.newdawn.slick.SlickException import org.newdawn.slick.SlickException
typealias TileAddress = Long typealias TileAddress = Long
typealias TileDamage = Int typealias TileDamage = Float
class GameWorld(val width: Int, val height: Int) { class GameWorld(val width: Int, val height: Int) {
@@ -211,31 +212,61 @@ class GameWorld(val width: Int, val height: Int) {
} }
} }
fun inflctTerrainDamage(x: Int, y: Int, damage: Int) { /**
* @return true if block is broken
*/
fun inflctTerrainDamage(x: Int, y: Int, damage: Float): Boolean {
val addr = RealEstateUtility.getAbsoluteTileNumber(x, y) val addr = RealEstateUtility.getAbsoluteTileNumber(x, y)
if (terrainDamages[addr] == null) { if (terrainDamages[addr] == null) { // add new
terrainDamages[addr] = damage terrainDamages[addr] = damage
} }
else { else if (terrainDamages[addr]!! + damage <= 0) { // tile is (somehow) fully healed
terrainDamages.remove(addr)
}
else { // normal situation
terrainDamages[addr] = terrainDamages[addr]!! + damage terrainDamages[addr] = terrainDamages[addr]!! + damage
} }
}
fun getTerrainDamage(x: Int, y: Int) =
terrainDamages[RealEstateUtility.getAbsoluteTileNumber(x, y)] ?: 0
fun inflctWallDamage(x: Int, y: Int, damage: Int) { //println("[GameWorld] accumulated damage: ${terrainDamages[addr]}")
// remove tile from the world
if (terrainDamages[addr]!! >= TileCodex[getTileFromTerrain(x, y)].strength) {
setTileTerrain(x, y, 0)
return true
}
return false
}
fun getTerrainDamage(x: Int, y: Int): Float =
terrainDamages[RealEstateUtility.getAbsoluteTileNumber(x, y)] ?: 0f
/**
* @return true if block is broken
*/
fun inflctWallDamage(x: Int, y: Int, damage: Float): Boolean {
val addr = RealEstateUtility.getAbsoluteTileNumber(x, y) val addr = RealEstateUtility.getAbsoluteTileNumber(x, y)
if (wallDamages[addr] == null) { if (wallDamages[addr] == null) { // add new
wallDamages[addr] = damage wallDamages[addr] = damage
} }
else { else if (wallDamages[addr]!! + damage <= 0) { // tile is (somehow) fully healed
wallDamages.remove(addr)
}
else { // normal situation
wallDamages[addr] = wallDamages[addr]!! + damage wallDamages[addr] = wallDamages[addr]!! + damage
} }
// remove tile from the world
if (wallDamages[addr]!! >= TileCodex[getTileFromWall(x, y)].strength) {
setTileWall(x, y, 0)
return true
}
return false
} }
fun getWallDamage(x: Int, y: Int) = fun getWallDamage(x: Int, y: Int): Float =
wallDamages[RealEstateUtility.getAbsoluteTileNumber(x, y)] ?: 0 wallDamages[RealEstateUtility.getAbsoluteTileNumber(x, y)] ?: 0f
companion object { companion object {

View File

@@ -0,0 +1,26 @@
package net.torvald.terrarum.itemproperties
import net.torvald.terrarum.gameactors.roundInt
import net.torvald.terrarum.gameactors.sqrt
/**
* Created by SKYHi14 on 2017-04-17.
*/
object Calculate {
/**
* Pickaxe power per action (swing)
*
* @return arbrtrary unit
*
* See: work_files/Pickaxe Power.xlsx
*
* TODO Newtons as unit?
*/
fun pickaxePower(material: Material): Float {
return 4f * material.forceMod.toFloat().sqrt()
}
fun armorwhatever() { TODO() }
fun yogafire() { TODO() }
}

View File

@@ -1,4 +1,4 @@
package net.torvald.terrarum.gameitem package net.torvald.terrarum.itemproperties
/** /**
* Created by minjaesong on 16-09-09. * Created by minjaesong on 16-09-09.

View File

@@ -1,4 +1,4 @@
package net.torvald.terrarum.gameitem package net.torvald.terrarum.itemproperties
import net.torvald.terrarum.ItemValue import net.torvald.terrarum.ItemValue
import net.torvald.terrarum.gameactors.Pocketed import net.torvald.terrarum.gameactors.Pocketed
@@ -96,6 +96,8 @@ abstract class InventoryItem : Comparable<InventoryItem>, Cloneable {
*/ */
open var durability: Float = 0f open var durability: Float = 0f
var using = false
/** /**
* Effects applied continuously while in pocket * Effects applied continuously while in pocket
*/ */
@@ -129,6 +131,9 @@ abstract class InventoryItem : Comparable<InventoryItem>, Cloneable {
*/ */
open fun secondaryUse(gc: GameContainer, delta: Int): Boolean = false open fun secondaryUse(gc: GameContainer, delta: Int): Boolean = false
open fun endPrimaryUse(gc: GameContainer, delta: Int): Boolean = false
open fun endSecondaryUse(gc: GameContainer, delta: Int): Boolean = false
/** /**
* Effects applied immediately only once if thrown from pocket * Effects applied immediately only once if thrown from pocket
*/ */

View File

@@ -3,12 +3,13 @@ package net.torvald.terrarum.itemproperties
import net.torvald.point.Point2d import net.torvald.point.Point2d
import net.torvald.terrarum.KVHashMap import net.torvald.terrarum.KVHashMap
import net.torvald.terrarum.gameactors.CanBeAnItem import net.torvald.terrarum.gameactors.CanBeAnItem
import net.torvald.terrarum.gameitem.InventoryItem import net.torvald.terrarum.itemproperties.InventoryItem
import net.torvald.terrarum.Terrarum import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.gameactors.AVKey
import net.torvald.terrarum.gameactors.ActorWithSprite import net.torvald.terrarum.gameactors.ActorWithSprite
import net.torvald.terrarum.gamecontroller.mouseTileX import net.torvald.terrarum.gamecontroller.mouseTileX
import net.torvald.terrarum.gamecontroller.mouseTileY import net.torvald.terrarum.gamecontroller.mouseTileY
import net.torvald.terrarum.gameitem.IVKey import net.torvald.terrarum.itemproperties.IVKey
import net.torvald.terrarum.gameworld.GameWorld import net.torvald.terrarum.gameworld.GameWorld
import net.torvald.terrarum.mapdrawer.TilesDrawer import net.torvald.terrarum.mapdrawer.TilesDrawer
import net.torvald.terrarum.mapdrawer.TilesDrawer.wallOverlayColour import net.torvald.terrarum.mapdrawer.TilesDrawer.wallOverlayColour
@@ -108,17 +109,27 @@ object ItemCodex {
override var baseMass = 10.0 override var baseMass = 10.0
override var baseToolSize: Double? = 10.0 override var baseToolSize: Double? = 10.0
override var consumable = false override var consumable = false
override var maxDurability = 200 // this much tiles before breaking override var maxDurability = 606 // this much tiles before breaking
override var durability = maxDurability.toFloat() override var durability = maxDurability.toFloat()
override var equipPosition = EquipPosition.HAND_GRIP override var equipPosition = EquipPosition.HAND_GRIP
override var inventoryCategory = Category.TOOL override var inventoryCategory = Category.TOOL
private val testmaterial = Material(
0,0,0,0,0,0,0,0,14,0.0 // quick test material Steel
)
init { init {
itemProperties[IVKey.ITEMTYPE] = IVKey.ItemType.PICK itemProperties[IVKey.ITEMTYPE] = IVKey.ItemType.PICK
name = "Steel pickaxe"
} }
override fun primaryUse(gc: GameContainer, delta: Int): Boolean { override fun primaryUse(gc: GameContainer, delta: Int): Boolean {
val mousePoint = Point2d(gc.mouseTileX.toDouble(), gc.mouseTileY.toDouble()) val mousePoint = Point2d(gc.mouseTileX.toDouble(), gc.mouseTileY.toDouble())
val actorvalue = Terrarum.ingame!!.player!!.actorValue
using = true
// linear search filter (check for intersection with tilewise mouse point and tilewise hitbox) // linear search filter (check for intersection with tilewise mouse point and tilewise hitbox)
Terrarum.ingame!!.actorContainer.forEach { Terrarum.ingame!!.actorContainer.forEach {
if (it is ActorWithSprite && it.tilewiseHitbox.intersects(mousePoint)) if (it is ActorWithSprite && it.tilewiseHitbox.intersects(mousePoint))
@@ -129,19 +140,21 @@ object ItemCodex {
if (Tile.AIR == Terrarum.ingame!!.world.getTileFromTerrain(gc.mouseTileX, gc.mouseTileY)) if (Tile.AIR == Terrarum.ingame!!.world.getTileFromTerrain(gc.mouseTileX, gc.mouseTileY))
return false return false
// filter passed, do the job // filter passed, do the job
Terrarum.ingame!!.world.setTileTerrain( val swingDmgToFrameDmg = delta.toDouble() / actorvalue.getAsDouble(AVKey.ACTION_INTERVAL)!!
return Terrarum.ingame!!.world.inflctTerrainDamage(
gc.mouseTileX, gc.mouseTileX,
gc.mouseTileY, gc.mouseTileY,
Tile.AIR Calculate.pickaxePower(testmaterial) * swingDmgToFrameDmg.toFloat()
) )
/*Terrarum.ingame!!.world.inflctTerrainDamage( }
gc.mouseTileX,
gc.mouseTileY,
<power calculation using ForceMod (ref. Pickaxe Power.xlsx) and other shits>
)*/
override fun endPrimaryUse(gc: GameContainer, delta: Int): Boolean {
using = false
// reset action timer to zero
Terrarum.ingame!!.player!!.actorValue[AVKey.__ACTION_TIMER] = 0.0
return true return true
} }
} }

View File

@@ -47,13 +47,13 @@ class ItemEffectsLuaAPI(g: Globals) {
class StrikeEarth : ThreeArgFunction() { class StrikeEarth : ThreeArgFunction() {
override fun call(x: LuaValue, y: LuaValue, power: LuaValue): LuaValue { override fun call(x: LuaValue, y: LuaValue, power: LuaValue): LuaValue {
Terrarum.ingame!!.world.inflctTerrainDamage(x.checkint(), y.checkint(), power.checkint()) Terrarum.ingame!!.world.inflctTerrainDamage(x.checkint(), y.checkint(), power.checkdouble().toFloat())
return LuaValue.NONE return LuaValue.NONE
} }
} }
class StrikeWall : ThreeArgFunction() { class StrikeWall : ThreeArgFunction() {
override fun call(x: LuaValue, y: LuaValue, power: LuaValue): LuaValue { override fun call(x: LuaValue, y: LuaValue, power: LuaValue): LuaValue {
Terrarum.ingame!!.world.inflctWallDamage(x.checkint(), y.checkint(), power.checkint()) Terrarum.ingame!!.world.inflctWallDamage(x.checkint(), y.checkint(), power.checkdouble().toFloat())
return LuaValue.NONE return LuaValue.NONE
} }
} }

View File

@@ -30,7 +30,7 @@ data class Material (
var thermalConductivity: Int, // pascal (N/m^2); if the item (e.g. sword) receives a force that exceeds this value, the item will be destroyed var thermalConductivity: Int, // pascal (N/m^2); if the item (e.g. sword) receives a force that exceeds this value, the item will be destroyed
// must be a item properties
var weapSharpnessMod: Double, // multiplier var forceMod: Int, // arbitrary unit. See Pickaxe_Power.xlsx
var armourMod: Double // multiplier var armourMod: Double // multiplier
) )

View File

@@ -7,12 +7,14 @@ import net.torvald.terrarum.tileproperties.TileCodex
import com.jme3.math.FastMath import com.jme3.math.FastMath
import net.torvald.terrarum.* import net.torvald.terrarum.*
import net.torvald.terrarum.concurrent.ThreadParallel import net.torvald.terrarum.concurrent.ThreadParallel
import net.torvald.terrarum.gameactors.roundInt
import net.torvald.terrarum.mapdrawer.FeaturesDrawer.TILE_SIZE import net.torvald.terrarum.mapdrawer.FeaturesDrawer.TILE_SIZE
import net.torvald.terrarum.mapdrawer.LightmapRenderer.normaliseToColour import net.torvald.terrarum.mapdrawer.LightmapRenderer.normaliseToColour
import net.torvald.terrarum.mapdrawer.MapCamera.x import net.torvald.terrarum.mapdrawer.MapCamera.x
import net.torvald.terrarum.mapdrawer.MapCamera.y import net.torvald.terrarum.mapdrawer.MapCamera.y
import net.torvald.terrarum.mapdrawer.MapCamera.height import net.torvald.terrarum.mapdrawer.MapCamera.height
import net.torvald.terrarum.mapdrawer.MapCamera.width import net.torvald.terrarum.mapdrawer.MapCamera.width
import net.torvald.terrarum.realestate.RealEstateUtility
import org.lwjgl.opengl.GL11 import org.lwjgl.opengl.GL11
import org.newdawn.slick.* import org.newdawn.slick.*
import java.util.* import java.util.*
@@ -25,10 +27,11 @@ object TilesDrawer {
private val TILE_SIZE = FeaturesDrawer.TILE_SIZE private val TILE_SIZE = FeaturesDrawer.TILE_SIZE
private val TILE_SIZEF = FeaturesDrawer.TILE_SIZE.toFloat() private val TILE_SIZEF = FeaturesDrawer.TILE_SIZE.toFloat()
var tilesTerrain: SpriteSheet = SpriteSheet(ModuleManager.getPath("basegame", "tiles/terrain.tga"), TILE_SIZE, TILE_SIZE) val tilesTerrain = SpriteSheet(ModMgr.getPath("basegame", "tiles/terrain.tga"), TILE_SIZE, TILE_SIZE)
private set // Slick has some weird quirks with PNG's transparency. I'm using 32-bit targa here. // Slick has some weird quirks with PNG's transparency. I'm using 32-bit targa here.
var tilesWire: SpriteSheet = SpriteSheet(ModuleManager.getPath("basegame", "tiles/wire.tga"), TILE_SIZE, TILE_SIZE) val tilesWire = SpriteSheet(ModMgr.getPath("basegame", "tiles/wire.tga"), TILE_SIZE, TILE_SIZE)
private set
val breakAnimSteps = 10
val WALL = GameWorld.WALL val WALL = GameWorld.WALL
val TERRAIN = GameWorld.TERRAIN val TERRAIN = GameWorld.TERRAIN
@@ -49,7 +52,7 @@ object TilesDrawer {
* It holds different shading rule to discriminate with group 02, index 0 is single tile. * It holds different shading rule to discriminate with group 02, index 0 is single tile.
* These are the tiles that only connects to itself, will not connect to colour variants * These are the tiles that only connects to itself, will not connect to colour variants
*/ */
var TILES_CONNECT_SELF = arrayOf( val TILES_CONNECT_SELF = arrayListOf(
Tile.ICE_MAGICAL, Tile.ICE_MAGICAL,
Tile.GLASS_CRUDE, Tile.GLASS_CRUDE,
Tile.GLASS_CLEAN, Tile.GLASS_CLEAN,
@@ -98,7 +101,7 @@ object TilesDrawer {
* Connectivity group 02 : natural tiles * Connectivity group 02 : natural tiles
* It holds different shading rule to discriminate with group 01, index 0 is middle tile. * It holds different shading rule to discriminate with group 01, index 0 is middle tile.
*/ */
var TILES_CONNECT_MUTUAL = arrayOf( val TILES_CONNECT_MUTUAL = arrayListOf(
Tile.STONE, Tile.STONE,
Tile.STONE_QUARRIED, Tile.STONE_QUARRIED,
Tile.STONE_TILE_WHITE, Tile.STONE_TILE_WHITE,
@@ -163,7 +166,7 @@ object TilesDrawer {
/** /**
* Torches, levers, switches, ... * Torches, levers, switches, ...
*/ */
var TILES_WALL_STICKER = arrayOf( val TILES_WALL_STICKER = arrayListOf(
Tile.TORCH, Tile.TORCH,
Tile.TORCH_FROST, Tile.TORCH_FROST,
Tile.TORCH_OFF, Tile.TORCH_OFF,
@@ -173,7 +176,7 @@ object TilesDrawer {
/** /**
* platforms, ... * platforms, ...
*/ */
var TILES_WALL_STICKER_CONNECT_SELF = arrayOf( val TILES_WALL_STICKER_CONNECT_SELF = arrayListOf(
Tile.PLATFORM_BIRCH, Tile.PLATFORM_BIRCH,
Tile.PLATFORM_BLOODROSE, Tile.PLATFORM_BLOODROSE,
Tile.PLATFORM_EBONY, Tile.PLATFORM_EBONY,
@@ -186,7 +189,7 @@ object TilesDrawer {
* will blend colour using colour multiplication * will blend colour using colour multiplication
* i.e. red hues get lost if you dive into the water * i.e. red hues get lost if you dive into the water
*/ */
var TILES_BLEND_MUL = arrayOf( val TILES_BLEND_MUL = arrayListOf(
Tile.WATER, Tile.WATER,
Tile.WATER_1, Tile.WATER_1,
Tile.WATER_2, Tile.WATER_2,
@@ -304,7 +307,7 @@ object TilesDrawer {
val noDamageLayer = mode % 3 == WIRE val noDamageLayer = mode % 3 == WIRE
// draw // draw a tile, but only when illuminated
try { try {
if ((mode == WALL || mode == TERRAIN) && // not an air tile if ((mode == WALL || mode == TERRAIN) && // not an air tile
(thisTile ?: 0) != Tile.AIR) { (thisTile ?: 0) != Tile.AIR) {
@@ -318,54 +321,70 @@ object TilesDrawer {
LightmapRenderer.getHighestRGB(x + 1, y + 1) ?: 0 >= tileDrawLightThreshold || LightmapRenderer.getHighestRGB(x + 1, y + 1) ?: 0 >= tileDrawLightThreshold ||
LightmapRenderer.getHighestRGB(x + 1, y - 1) ?: 0 >= tileDrawLightThreshold || LightmapRenderer.getHighestRGB(x + 1, y - 1) ?: 0 >= tileDrawLightThreshold ||
LightmapRenderer.getHighestRGB(x - 1, y + 1) ?: 0 >= tileDrawLightThreshold) { LightmapRenderer.getHighestRGB(x - 1, y + 1) ?: 0 >= tileDrawLightThreshold) {
// blackness // blackness
if (zeroTileCounter > 0) { if (zeroTileCounter > 0) {
/* unable to do anything */ /* unable to do anything */
zeroTileCounter = 0 zeroTileCounter = 0
} }
val nearbyTilesInfo: Int val nearbyTilesInfo: Int
if (isPlatform(thisTile)) { if (isPlatform(thisTile)) {
nearbyTilesInfo = getNearbyTilesInfoPlatform(x, y) nearbyTilesInfo = getNearbyTilesInfoPlatform(x, y)
} }
else if (isWallSticker(thisTile)) { else if (isWallSticker(thisTile)) {
nearbyTilesInfo = getNearbyTilesInfoWallSticker(x, y) nearbyTilesInfo = getNearbyTilesInfoWallSticker(x, y)
} }
else if (isConnectMutual(thisTile)) { else if (isConnectMutual(thisTile)) {
nearbyTilesInfo = getNearbyTilesInfoNonSolid(x, y, mode) nearbyTilesInfo = getNearbyTilesInfoNonSolid(x, y, mode)
} }
else if (isConnectSelf(thisTile)) { else if (isConnectSelf(thisTile)) {
nearbyTilesInfo = getNearbyTilesInfo(x, y, mode, thisTile) nearbyTilesInfo = getNearbyTilesInfo(x, y, mode, thisTile)
} }
else { else {
nearbyTilesInfo = 0 nearbyTilesInfo = 0
} }
val thisTileX: Int val thisTileX = if (!noDamageLayer)
if (!noDamageLayer) PairedMapLayer.RANGE * ((thisTile ?: 0) % PairedMapLayer.RANGE) + nearbyTilesInfo
thisTileX = PairedMapLayer.RANGE * ((thisTile ?: 0) % PairedMapLayer.RANGE) + nearbyTilesInfo else
else nearbyTilesInfo
thisTileX = nearbyTilesInfo
val thisTileY = (thisTile ?: 0) / PairedMapLayer.RANGE val thisTileY = (thisTile ?: 0) / PairedMapLayer.RANGE
if (drawModeTilesBlendMul) {
if (TilesDrawer.isBlendMul(thisTile)) { // draw a tile
drawTile(mode, x, y, thisTileX, thisTileY) if (drawModeTilesBlendMul) {
} if (TilesDrawer.isBlendMul(thisTile)) {
}
else {
// do NOT add "if (!isBlendMul(thisTile))"!
// or else they will not look like they should be when backed with wall
drawTile(mode, x, y, thisTileX, thisTileY) drawTile(mode, x, y, thisTileX, thisTileY)
} }
}
else {
// do NOT add "if (!isBlendMul(thisTile))"!
// or else they will not look like they should be when backed with wall
drawTile(mode, x, y, thisTileX, thisTileY)
}
// draw a breakage
if (mode == TERRAIN || mode == WALL) {
val breakage = if (mode == TERRAIN) world.getTerrainDamage(x, y) else world.getWallDamage(x, y)
val maxHealth = TileCodex[world.getTileFromTerrain(x, y)].strength
val stage = (breakage / maxHealth).times(breakAnimSteps).roundInt()
// actual drawing
if (stage > 0) {
// alpha blending works, but no GL blend func...
drawTile(mode, x, y, 5 + stage, 0)
}
}
} // end if (is illuminated) } // end if (is illuminated)
// draw black patch
else { else {
zeroTileCounter++ zeroTileCounter++ // unused for now
//drawTile(mode, x, y, 1, 0) // black patch
GL11.glColor4f(0f, 0f, 0f, 1f) GL11.glColor4f(0f, 0f, 0f, 1f)
GL11.glTexCoord2f(0f, 0f) GL11.glTexCoord2f(0f, 0f)

View File

@@ -7,7 +7,7 @@ import net.torvald.terrarum.Terrarum
*/ */
object Tile { object Tile {
val AIR = 0 val AIR = 0 // hard coded; this is the standard
val STONE = TileCodex.idDamageToIndex(1, 0) val STONE = TileCodex.idDamageToIndex(1, 0)
val STONE_QUARRIED = TileCodex.idDamageToIndex(1, 1) val STONE_QUARRIED = TileCodex.idDamageToIndex(1, 1)

View File

@@ -1,6 +1,7 @@
package net.torvald.terrarum.tileproperties package net.torvald.terrarum.tileproperties
import net.torvald.CSVFetcher import net.torvald.CSVFetcher
import net.torvald.terrarum.ModMgr
import net.torvald.terrarum.gameworld.MapLayer import net.torvald.terrarum.gameworld.MapLayer
import net.torvald.terrarum.gameworld.PairedMapLayer import net.torvald.terrarum.gameworld.PairedMapLayer
import org.apache.commons.csv.CSVRecord import org.apache.commons.csv.CSVRecord
@@ -14,14 +15,12 @@ object TileCodex {
private var tileProps: Array<TileProp> private var tileProps: Array<TileProp>
val CSV_PATH = "/net/torvald/terrarum/tileproperties/tileprop.csv"
const val TILE_UNIQUE_MAX = MapLayer.RANGE * PairedMapLayer.RANGE const val TILE_UNIQUE_MAX = MapLayer.RANGE * PairedMapLayer.RANGE
private val nullProp = TileProp() private val nullProp = TileProp()
init { init {
tileProps = Array<TileProp>(TILE_UNIQUE_MAX * 2, { i -> TileProp() }) tileProps = Array<TileProp>(TILE_UNIQUE_MAX * 2, { TileProp() })
for (i in tileProps.indices) { for (i in tileProps.indices) {
tileProps[i] = TileProp() tileProps[i] = TileProp()
@@ -29,7 +28,7 @@ object TileCodex {
try { try {
// todo verify CSV using pre-calculated SHA256 hash // todo verify CSV using pre-calculated SHA256 hash
val records = CSVFetcher.readFromString(TilePropCSV()) val records = CSVFetcher.readFromModule("basegame", "tiles/tileprop.csv")
println("[TileCodex] Building tile properties table") println("[TileCodex] Building tile properties table")
@@ -50,15 +49,15 @@ object TileCodex {
} }
fun get(index: Int, damage: Int): TileProp { fun get(index: Int, subID: Int): TileProp {
try { try {
tileProps[idDamageToIndex(index, damage)].id tileProps[idDamageToIndex(index, subID)].id
} }
catch (e: NullPointerException) { catch (e: NullPointerException) {
throw NullPointerException("Tile prop with id $index and damage $damage does not exist.") throw NullPointerException("Tile prop with id $index and subID $subID does not exist.")
} }
return tileProps[idDamageToIndex(index, damage)] return tileProps[idDamageToIndex(index, subID)]
} }
operator fun get(rawIndex: Int?): TileProp { operator fun get(rawIndex: Int?): TileProp {

View File

@@ -3,7 +3,7 @@ package net.torvald.terrarum.tileproperties
/** /**
* Created by minjaesong on 16-09-11. * Created by minjaesong on 16-09-11.
*/ */
object TilePropCSV { object TilePropCSVFUfufufufufufffnufuuufufu {
operator fun invoke() = """ operator fun invoke() = """
"id";"sid";"name" ; "opacity";"strength";"dsty";"mate";"fluid";"solid";"wall"; "lumcolor";"drop";"ddmg";"fall";"dlfn";"vscs";"fv";"friction" "id";"sid";"name" ; "opacity";"strength";"dsty";"mate";"fluid";"solid";"wall"; "lumcolor";"drop";"ddmg";"fall";"dlfn";"vscs";"fv";"friction"
"0"; "0";"TILE_AIR" ; "8396808"; "1"; "1";"null"; "0"; "0"; "0"; "0"; "0"; "0"; "0"; "0"; "N/A"; "0";"4" "0"; "0";"TILE_AIR" ; "8396808"; "1"; "1";"null"; "0"; "0"; "0"; "0"; "0"; "0"; "0"; "0"; "N/A"; "0";"4"

View File

@@ -6,7 +6,7 @@ import net.torvald.terrarum.Terrarum.joypadLabelNinA
import net.torvald.terrarum.Terrarum.joypadLabelNinY import net.torvald.terrarum.Terrarum.joypadLabelNinY
import net.torvald.terrarum.gameactors.* import net.torvald.terrarum.gameactors.*
import net.torvald.terrarum.gameactors.ActorInventory.Companion.CAPACITY_MODE_NO_ENCUMBER import net.torvald.terrarum.gameactors.ActorInventory.Companion.CAPACITY_MODE_NO_ENCUMBER
import net.torvald.terrarum.gameitem.InventoryItem import net.torvald.terrarum.itemproperties.InventoryItem
import net.torvald.terrarum.itemproperties.ItemCodex import net.torvald.terrarum.itemproperties.ItemCodex
import net.torvald.terrarum.langpack.Lang import net.torvald.terrarum.langpack.Lang
import org.newdawn.slick.* import org.newdawn.slick.*

View File

@@ -49,7 +49,7 @@ object WeatherMixer {
// read weather descriptions from assets/weather (modular weather) // read weather descriptions from assets/weather (modular weather)
val weatherRawValidList = ArrayList<File>() val weatherRawValidList = ArrayList<File>()
val weatherRaws = ModuleManager.getFiles("basegame", "weathers") val weatherRaws = ModMgr.getFiles("basegame", "weathers")
weatherRaws.forEach { weatherRaws.forEach {
if (!it.isDirectory && it.name.endsWith(".json")) if (!it.isDirectory && it.name.endsWith(".json"))
weatherRawValidList.add(it) weatherRawValidList.add(it)
@@ -207,7 +207,7 @@ object WeatherMixer {
// parse globalLight // parse globalLight
if (globalLightInJson.isString) if (globalLightInJson.isString)
globalLight = Image(ModuleManager.getPath("basegame", "$pathToImage/${globalLightInJson.asString}")) globalLight = Image(ModMgr.getPath("basegame", "$pathToImage/${globalLightInJson.asString}"))
else if (globalLightInJson.isNumber) { else if (globalLightInJson.isNumber) {
// make 1x1 image with specified colour // make 1x1 image with specified colour
globalLight = Image(1, 1) globalLight = Image(1, 1)
@@ -219,7 +219,7 @@ object WeatherMixer {
// parse skyboxGradColourMap // parse skyboxGradColourMap
if (skyboxInJson.isString) if (skyboxInJson.isString)
skybox = Image(ModuleManager.getPath("basegame", "$pathToImage/${skyboxInJson.asString}")) skybox = Image(ModMgr.getPath("basegame", "$pathToImage/${skyboxInJson.asString}"))
else if (globalLightInJson.isNumber) { else if (globalLightInJson.isNumber) {
// make 1x2 image with specified colour // make 1x2 image with specified colour
skybox = Image(1, 2) skybox = Image(1, 2)
@@ -231,7 +231,7 @@ object WeatherMixer {
// get extra images // get extra images
for (i in extraImagesPath) for (i in extraImagesPath)
extraImages.add(Image(ModuleManager.getPath("basegame", "$pathToImage/${i.asString}"))) extraImages.add(Image(ModMgr.getPath("basegame", "$pathToImage/${i.asString}")))
// get mix from // get mix from

Binary file not shown.