pickaxe working as intended

This commit is contained in:
Song Minjae
2017-04-18 01:14:25 +09:00
parent cec266d396
commit 56d78d50ca
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"
"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"
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
import net.torvald.terrarum.ModMgr
import org.apache.commons.csv.CSVFormat
import org.apache.commons.csv.CSVParser
import org.apache.commons.csv.CSVRecord
@@ -16,8 +17,7 @@ object CSVFetcher {
private var csvString: StringBuffer? = null
@Throws(IOException::class)
operator fun invoke(csvFilePath: String): List<CSVRecord> {
fun readFromFile(csvFilePath: String): List<CSVRecord> {
csvString = StringBuffer() // reset buffer every time it called
readCSVasString(csvFilePath)
@@ -40,6 +40,8 @@ object CSVFetcher {
return csvRecordList
}
fun readFromModule(module: String, path: String) = readFromFile(ModMgr.getPath(module, path))
fun readFromString(csv: String): List<CSVRecord> {
val csvParser = CSVParser.parse(
csv,

View File

@@ -5,14 +5,14 @@ import net.torvald.terrarum.weather.toColor
import org.newdawn.slick.Color
import org.newdawn.slick.Image
import net.torvald.colourutil.CIEXYZUtil.toColor
import net.torvald.terrarum.ModuleManager
import net.torvald.terrarum.ModMgr
/**
* RGB-modeled CCT calculator
* Created by minjaesong on 16-07-26.
*/
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 {
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.itemproperties.ItemCodex
import net.torvald.terrarum.itemproperties.MaterialCodex
import net.torvald.terrarum.tileproperties.TilePropCSV
import net.torvald.terrarum.tileproperties.TileCodex
import org.apache.commons.codec.digest.DigestUtils
import java.io.FileInputStream
@@ -36,7 +35,7 @@ object WriteMeta {
* @param savegameName -- Nullable. If the value is not specified, saveDirectoryName will be used instead.
*/
fun write(saveDirectoryName: String, savegameName: String?): Boolean {
val hashArray: ArrayList<ByteArray> = ArrayList()
/*val hashArray: ArrayList<ByteArray> = ArrayList()
val savenameAsByteArray: ByteArray =
(savegameName ?: saveDirectoryName).toByteArray(Charsets.UTF_8)
@@ -75,20 +74,7 @@ object WriteMeta {
}
catch (e: IOException) {
e.printStackTrace()
}
}*/
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,61 +51,48 @@ class KVHashMap {
fun getAsInt(key: String): Int? {
val value = get(key)
if (value == null) return null
if (value is JsonPrimitive)
return value.asInt
try {
return value as Int
}
catch (e: ClassCastException) {
return null
}
}
fun getAsDouble(key: String): Double? {
val value = get(key)
if (value == null) return null
if (value is Int)
return value.toDouble()
else if (value is JsonPrimitive)
return value.asDouble
try {
return value as Double
}
catch (e: ClassCastException) {
return null
}
}
fun getAsString(key: String): String? {
val value = get(key)
if (value == null) return null
if (value is JsonPrimitive)
return value.asString
try {
return value as String
}
catch (e: ClassCastException) {
return null
}
}
fun getAsBoolean(key: String): Boolean? {
val value = get(key)
if (value == null) return null
if (value is JsonPrimitive)
return value.asBoolean
try {
return value as Boolean
}
catch (e: ClassCastException) {
return null
}
}
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.
*/
object ModuleManager {
object ModMgr {
data class ModuleMetadata(val order: Int, val isDir: Boolean, val desc: String, val libraries: Array<String>) {
override fun toString() =
@@ -35,7 +35,7 @@ object ModuleManager {
loadOrder.forEachIndexed { index, it ->
val moduleName = it[0]
println("[ModuleManager] Loading module $moduleName")
println("[ModMgr] Loading module $moduleName")
val description = it[1]
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.Key
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.WorldSimulator
import net.torvald.terrarum.gameworld.WorldTime

View File

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

View File

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

View File

@@ -1,7 +1,7 @@
package net.torvald.terrarum
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.UIInventory
import net.torvald.terrarum.ui.UIItem

View File

@@ -79,6 +79,11 @@ object AVKey {
const val MAGICREGENRATE = "magicregenrate"
const val MAGICREGENRATEBUFF = "$MAGICREGENRATE$BUFF"
/** Double
*
*/
const val ACTION_INTERVAL = "actioninterval"
/** String
* UUID for certain fixtures
@@ -91,4 +96,9 @@ object AVKey {
/** SYNOPSIS: __qsitem1 .. __qsitem10
* contains tem ID; they are supposed to be unique. Indices must be ONE-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
import com.jme3.math.FastMath
import net.torvald.terrarum.Millisec
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.gameactors.faction.Faction
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 org.newdawn.slick.GameContainer
import org.newdawn.slick.Input
@@ -22,6 +23,7 @@ open class ActorHumanoid(birth: GameDate, death: GameDate? = null)
var vehicleRiding: Controllable? = null // usually player only
/** Must be set by PlayerFactory */
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 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_WALK = 1

View File

@@ -1,7 +1,7 @@
package net.torvald.terrarum.gameactors
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.ui.UIInventory
import java.util.*

View File

@@ -1329,6 +1329,7 @@ fun Float.roundInt(): Int = Math.round(this)
fun Double.abs() = Math.abs(this)
fun Double.sqr() = this * this
fun Double.sqrt() = Math.sqrt(this)
fun Float.sqrt() = FastMath.sqrt(this)
fun Int.abs() = if (this < 0) -this else this
fun Double.bipolarClamp(limit: Double) =
if (this > 0 && this > limit) limit

View File

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

View File

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

View File

@@ -1,6 +1,6 @@
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.tileproperties.TileCodex
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.gamecontroller.mouseX
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.compiler.LuaC
import org.luaj.vm2.lib.*

View File

@@ -5,7 +5,7 @@ import net.torvald.random.Fudge3
import net.torvald.terrarum.langpack.Lang
import com.google.gson.JsonObject
import net.torvald.terrarum.ActorValue
import net.torvald.terrarum.ModuleManager
import net.torvald.terrarum.ModMgr
import net.torvald.terrarum.gameactors.ActorHumanoid
import org.newdawn.slick.SlickException
import java.io.IOException
@@ -25,7 +25,7 @@ object InjectCreatureRaw {
* @param jsonFileName with extension
*/
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 elementsString = arrayOf(AVKey.RACENAME, AVKey.RACENAMEPLURAL)

View File

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

View File

@@ -1,7 +1,7 @@
package net.torvald.terrarum.gameactors
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.ai.LuaAIWrapper
import net.torvald.terrarum.mapdrawer.FeaturesDrawer
@@ -20,10 +20,12 @@ object PlayerBuilderCynthia {
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.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!!.setRowsAndFrames(1, 1)

View File

@@ -5,7 +5,7 @@ import net.torvald.terrarum.gameactors.faction.Faction
import net.torvald.spriteanimation.SpriteAnimation
import com.google.gson.JsonObject
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.faction.FactionFactory
import net.torvald.terrarum.itemproperties.ItemCodex
@@ -28,11 +28,11 @@ object PlayerBuilderSigrid {
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!!.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!!.setRowsAndFrames(1, 1)
@@ -64,7 +64,8 @@ object PlayerBuilderSigrid {
p.actorValue[AVKey.BASEDEFENCE] = 141
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.setHitboxDimension(15, p.actorValue.getAsInt(AVKey.BASEHEIGHT)!!, 11, 0)

View File

@@ -1,6 +1,6 @@
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.mapdrawer.FeaturesDrawer
@@ -14,10 +14,12 @@ object PlayerBuilderTestSubject1 {
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.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!!.setRowsAndFrames(2, 4)

View File

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

View File

@@ -2,7 +2,7 @@ package net.torvald.terrarum.gameactors.faction
import net.torvald.JsonFetcher
import com.google.gson.JsonObject
import net.torvald.terrarum.ModuleManager
import net.torvald.terrarum.ModMgr
import java.io.IOException
@@ -16,7 +16,7 @@ object FactionFactory {
*/
@Throws(IOException::class)
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)
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.Terrarum
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.tileproperties.Tile
import net.torvald.terrarum.tileproperties.TileCodex
@@ -78,7 +78,7 @@ object GameController {
if (input.isMouseButtonDown(Terrarum.getConfigInt("mouseprimary"))) {
ingame.player!!.consumePrimary(itemOnGrip)
}
else if (input.isMouseButtonDown(Terrarum.getConfigInt("mousesecondary"))) {
if (input.isMouseButtonDown(Terrarum.getConfigInt("mousesecondary"))) {
ingame.player!!.consumeSecondary(itemOnGrip)
}
}
@@ -113,7 +113,21 @@ object GameController {
}
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) {

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
import net.torvald.terrarum.realestate.RealEstateUtility
import net.torvald.terrarum.tileproperties.TileCodex
import org.dyn4j.geometry.Vector2
import org.newdawn.slick.SlickException
typealias TileAddress = Long
typealias TileDamage = Int
typealias TileDamage = Float
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)
if (terrainDamages[addr] == null) {
if (terrainDamages[addr] == null) { // add new
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
}
}
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)
if (wallDamages[addr] == null) {
if (wallDamages[addr] == null) { // add new
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
}
// remove tile from the world
if (wallDamages[addr]!! >= TileCodex[getTileFromWall(x, y)].strength) {
setTileWall(x, y, 0)
return true
}
fun getWallDamage(x: Int, y: Int) =
wallDamages[RealEstateUtility.getAbsoluteTileNumber(x, y)] ?: 0
return false
}
fun getWallDamage(x: Int, y: Int): Float =
wallDamages[RealEstateUtility.getAbsoluteTileNumber(x, y)] ?: 0f
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.

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.gameactors.Pocketed
@@ -96,6 +96,8 @@ abstract class InventoryItem : Comparable<InventoryItem>, Cloneable {
*/
open var durability: Float = 0f
var using = false
/**
* 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 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
*/

View File

@@ -3,12 +3,13 @@ package net.torvald.terrarum.itemproperties
import net.torvald.point.Point2d
import net.torvald.terrarum.KVHashMap
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.gameactors.AVKey
import net.torvald.terrarum.gameactors.ActorWithSprite
import net.torvald.terrarum.gamecontroller.mouseTileX
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.mapdrawer.TilesDrawer
import net.torvald.terrarum.mapdrawer.TilesDrawer.wallOverlayColour
@@ -108,17 +109,27 @@ object ItemCodex {
override var baseMass = 10.0
override var baseToolSize: Double? = 10.0
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 equipPosition = EquipPosition.HAND_GRIP
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 {
itemProperties[IVKey.ITEMTYPE] = IVKey.ItemType.PICK
name = "Steel pickaxe"
}
override fun primaryUse(gc: GameContainer, delta: Int): Boolean {
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)
Terrarum.ingame!!.actorContainer.forEach {
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))
return false
// 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.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
}
}

View File

@@ -47,13 +47,13 @@ class ItemEffectsLuaAPI(g: Globals) {
class StrikeEarth : ThreeArgFunction() {
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
}
}
class StrikeWall : ThreeArgFunction() {
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
}
}

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
// must be a item properties
var weapSharpnessMod: Double, // multiplier
var forceMod: Int, // arbitrary unit. See Pickaxe_Power.xlsx
var armourMod: Double // multiplier
)

View File

@@ -7,12 +7,14 @@ import net.torvald.terrarum.tileproperties.TileCodex
import com.jme3.math.FastMath
import net.torvald.terrarum.*
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.LightmapRenderer.normaliseToColour
import net.torvald.terrarum.mapdrawer.MapCamera.x
import net.torvald.terrarum.mapdrawer.MapCamera.y
import net.torvald.terrarum.mapdrawer.MapCamera.height
import net.torvald.terrarum.mapdrawer.MapCamera.width
import net.torvald.terrarum.realestate.RealEstateUtility
import org.lwjgl.opengl.GL11
import org.newdawn.slick.*
import java.util.*
@@ -25,10 +27,11 @@ object TilesDrawer {
private val TILE_SIZE = FeaturesDrawer.TILE_SIZE
private val TILE_SIZEF = FeaturesDrawer.TILE_SIZE.toFloat()
var tilesTerrain: SpriteSheet = SpriteSheet(ModuleManager.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.
var tilesWire: SpriteSheet = SpriteSheet(ModuleManager.getPath("basegame", "tiles/wire.tga"), TILE_SIZE, TILE_SIZE)
private set
val tilesTerrain = SpriteSheet(ModMgr.getPath("basegame", "tiles/terrain.tga"), TILE_SIZE, TILE_SIZE)
// Slick has some weird quirks with PNG's transparency. I'm using 32-bit targa here.
val tilesWire = SpriteSheet(ModMgr.getPath("basegame", "tiles/wire.tga"), TILE_SIZE, TILE_SIZE)
val breakAnimSteps = 10
val WALL = GameWorld.WALL
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.
* 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.GLASS_CRUDE,
Tile.GLASS_CLEAN,
@@ -98,7 +101,7 @@ object TilesDrawer {
* Connectivity group 02 : natural tiles
* 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_QUARRIED,
Tile.STONE_TILE_WHITE,
@@ -163,7 +166,7 @@ object TilesDrawer {
/**
* Torches, levers, switches, ...
*/
var TILES_WALL_STICKER = arrayOf(
val TILES_WALL_STICKER = arrayListOf(
Tile.TORCH,
Tile.TORCH_FROST,
Tile.TORCH_OFF,
@@ -173,7 +176,7 @@ object TilesDrawer {
/**
* platforms, ...
*/
var TILES_WALL_STICKER_CONNECT_SELF = arrayOf(
val TILES_WALL_STICKER_CONNECT_SELF = arrayListOf(
Tile.PLATFORM_BIRCH,
Tile.PLATFORM_BLOODROSE,
Tile.PLATFORM_EBONY,
@@ -186,7 +189,7 @@ object TilesDrawer {
* will blend colour using colour multiplication
* 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_1,
Tile.WATER_2,
@@ -304,7 +307,7 @@ object TilesDrawer {
val noDamageLayer = mode % 3 == WIRE
// draw
// draw a tile, but only when illuminated
try {
if ((mode == WALL || mode == TERRAIN) && // not an air tile
(thisTile ?: 0) != Tile.AIR) {
@@ -344,14 +347,15 @@ object TilesDrawer {
}
val thisTileX: Int
if (!noDamageLayer)
thisTileX = PairedMapLayer.RANGE * ((thisTile ?: 0) % PairedMapLayer.RANGE) + nearbyTilesInfo
val thisTileX = if (!noDamageLayer)
PairedMapLayer.RANGE * ((thisTile ?: 0) % PairedMapLayer.RANGE) + nearbyTilesInfo
else
thisTileX = nearbyTilesInfo
nearbyTilesInfo
val thisTileY = (thisTile ?: 0) / PairedMapLayer.RANGE
// draw a tile
if (drawModeTilesBlendMul) {
if (TilesDrawer.isBlendMul(thisTile)) {
drawTile(mode, x, y, thisTileX, thisTileY)
@@ -362,10 +366,25 @@ object TilesDrawer {
// 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)
// draw black patch
else {
zeroTileCounter++
//drawTile(mode, x, y, 1, 0) // black patch
zeroTileCounter++ // unused for now
GL11.glColor4f(0f, 0f, 0f, 1f)
GL11.glTexCoord2f(0f, 0f)

View File

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

View File

@@ -1,6 +1,7 @@
package net.torvald.terrarum.tileproperties
import net.torvald.CSVFetcher
import net.torvald.terrarum.ModMgr
import net.torvald.terrarum.gameworld.MapLayer
import net.torvald.terrarum.gameworld.PairedMapLayer
import org.apache.commons.csv.CSVRecord
@@ -14,14 +15,12 @@ object TileCodex {
private var tileProps: Array<TileProp>
val CSV_PATH = "/net/torvald/terrarum/tileproperties/tileprop.csv"
const val TILE_UNIQUE_MAX = MapLayer.RANGE * PairedMapLayer.RANGE
private val nullProp = TileProp()
init {
tileProps = Array<TileProp>(TILE_UNIQUE_MAX * 2, { i -> TileProp() })
tileProps = Array<TileProp>(TILE_UNIQUE_MAX * 2, { TileProp() })
for (i in tileProps.indices) {
tileProps[i] = TileProp()
@@ -29,7 +28,7 @@ object TileCodex {
try {
// 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")
@@ -50,15 +49,15 @@ object TileCodex {
}
fun get(index: Int, damage: Int): TileProp {
fun get(index: Int, subID: Int): TileProp {
try {
tileProps[idDamageToIndex(index, damage)].id
tileProps[idDamageToIndex(index, subID)].id
}
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 {

View File

@@ -3,7 +3,7 @@ package net.torvald.terrarum.tileproperties
/**
* Created by minjaesong on 16-09-11.
*/
object TilePropCSV {
object TilePropCSVFUfufufufufufffnufuuufufu {
operator fun invoke() = """
"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"

View File

@@ -6,7 +6,7 @@ import net.torvald.terrarum.Terrarum.joypadLabelNinA
import net.torvald.terrarum.Terrarum.joypadLabelNinY
import net.torvald.terrarum.gameactors.*
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.langpack.Lang
import org.newdawn.slick.*

View File

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

Binary file not shown.