diff --git a/src/net/torvald/terrarum/console/GetTime.kt b/src/net/torvald/terrarum/console/GetTime.kt index db82be081..7e6eb3dcf 100644 --- a/src/net/torvald/terrarum/console/GetTime.kt +++ b/src/net/torvald/terrarum/console/GetTime.kt @@ -9,10 +9,7 @@ class GetTime : ConsoleCommand { override fun execute(args: Array) { val echo = Echo() val worldTime = Terrarum.ingame.world.time - echo.execute("Year ${worldTime.years}, Month ${worldTime.months}, " + - "Day ${worldTime.days} (${worldTime.getDayNameShort()}), " + - "${worldTime.getFormattedTime()}" - ) + echo.execute(worldTime.getFormattedTime()) } override fun printUsage() { diff --git a/src/net/torvald/terrarum/gameactors/ActorWithBody.kt b/src/net/torvald/terrarum/gameactors/ActorWithBody.kt index 2054ba128..fa167c994 100644 --- a/src/net/torvald/terrarum/gameactors/ActorWithBody.kt +++ b/src/net/torvald/terrarum/gameactors/ActorWithBody.kt @@ -130,8 +130,8 @@ open class ActorWithBody : Actor(), Visible { */ - var grounded = false - override var flagDespawn = false + @Volatile var grounded = false + override @Volatile var flagDespawn = false /** Default to 'false' */ var isVisible = false /** Default to 'true' */ @@ -146,7 +146,7 @@ open class ActorWithBody : Actor(), Visible { * think of a grass cutting on the Zelda games. It would also make a great puzzle to solve. * --minjaesong) */ - var isChronostasis = false + @Volatile var isChronostasis = false /** * Constants @@ -213,8 +213,8 @@ open class ActorWithBody : Actor(), Visible { @Transient private var assertPrinted = false // to use with Controller (incl. player) - internal var walledLeft = false - internal var walledRight = false + internal @Volatile var walledLeft = false + internal @Volatile var walledRight = false /** * true: This actor had just made collision diff --git a/src/net/torvald/terrarum/gameactors/HistoricalFigure.kt b/src/net/torvald/terrarum/gameactors/HistoricalFigure.kt new file mode 100644 index 000000000..877f5f33e --- /dev/null +++ b/src/net/torvald/terrarum/gameactors/HistoricalFigure.kt @@ -0,0 +1,49 @@ +package net.torvald.terrarum.gameactors + +import net.torvald.terrarum.gameworld.WorldTime + +/** + * An actor (NPC) which has life and death, + * though death might not exist if it has achieved immortality :) + * + * Created by minjaesong on 16-10-10. + */ +open class HistoricalFigure(born: GameDate, dead: GameDate? = null) : ActorWithBody() { + + init { + this.actorValue["_bornyear"] = born.year + this.actorValue["_borndays"] = born.yearlyDay + + if (dead != null) { + this.actorValue["_deadyear"] = dead.year + this.actorValue["_deaddays"] = dead.yearlyDay + } + } + +} + +data class GameDate(val year: Int, val yearlyDay: Int) { + operator fun plus(other: GameDate): GameDate { + var newyd = this.yearlyDay + other.yearlyDay + var newy = this.year + other.year + + if (newyd > WorldTime.YEAR_DAYS) { + newyd -= WorldTime.YEAR_DAYS + newy += 1 + } + + return GameDate(newy, newyd) + } + + operator fun minus(other: GameDate): GameDate { + var newyd = this.yearlyDay - other.yearlyDay + var newy = this.year - other.year + + if (newyd < 0) { + newyd += WorldTime.YEAR_DAYS + newy -= 1 + } + + return GameDate(newy, newyd) + } +} \ No newline at end of file diff --git a/src/net/torvald/terrarum/gameactors/NPCIntelligentBase.kt b/src/net/torvald/terrarum/gameactors/NPCIntelligentBase.kt index 629f12edc..5c5ed8195 100644 --- a/src/net/torvald/terrarum/gameactors/NPCIntelligentBase.kt +++ b/src/net/torvald/terrarum/gameactors/NPCIntelligentBase.kt @@ -10,7 +10,7 @@ import java.util.* /** * Created by minjaesong on 16-03-14. */ -open class NPCIntelligentBase : ActorWithBody() +open class NPCIntelligentBase(born: GameDate) : HistoricalFigure(born) , AIControlled, Pocketed, CanBeAnItem, Factionable, LandHolder { override var actorAI: ActorAI = object : ActorAI { diff --git a/src/net/torvald/terrarum/gameactors/PBCynthia.kt b/src/net/torvald/terrarum/gameactors/PBCynthia.kt index 0f03e1317..56bc1b5c9 100644 --- a/src/net/torvald/terrarum/gameactors/PBCynthia.kt +++ b/src/net/torvald/terrarum/gameactors/PBCynthia.kt @@ -9,7 +9,7 @@ import net.torvald.terrarum.mapdrawer.MapDrawer object PBCynthia { fun create(): Player { - val p: Player = Player() + val p: Player = Player(GameDate(100, 143)) // random value thrown CreatureRawInjector.inject(p.actorValue, "CreatureHuman.json") p.actorValue[AVKey.__PLAYER_QUICKBARSEL] = 0 diff --git a/src/net/torvald/terrarum/gameactors/PBSigrid.kt b/src/net/torvald/terrarum/gameactors/PBSigrid.kt index e2f1201d9..0bb5ae414 100644 --- a/src/net/torvald/terrarum/gameactors/PBSigrid.kt +++ b/src/net/torvald/terrarum/gameactors/PBSigrid.kt @@ -16,7 +16,7 @@ import java.io.IOException object PBSigrid { fun create(): Player { - val p = Player() + val p = Player(GameDate(-2147483648, 0)) // XD p.sprite = SpriteAnimation() p.sprite!!.setDimension(28, 51) diff --git a/src/net/torvald/terrarum/gameactors/Player.kt b/src/net/torvald/terrarum/gameactors/Player.kt index f465091fa..79c323274 100644 --- a/src/net/torvald/terrarum/gameactors/Player.kt +++ b/src/net/torvald/terrarum/gameactors/Player.kt @@ -19,7 +19,7 @@ import java.util.* * Created by minjaesong on 16-03-14. */ -class Player : ActorWithBody(), Controllable, Pocketed, Factionable, Luminous, LandHolder { +class Player(born: GameDate) : HistoricalFigure(born), Controllable, Pocketed, Factionable, Luminous, LandHolder { /** * empirical value. diff --git a/src/net/torvald/terrarum/gameworld/MapLayer.kt b/src/net/torvald/terrarum/gameworld/MapLayer.kt index a00d5f496..87d83c1d2 100644 --- a/src/net/torvald/terrarum/gameworld/MapLayer.kt +++ b/src/net/torvald/terrarum/gameworld/MapLayer.kt @@ -3,9 +3,9 @@ package net.torvald.terrarum.gameworld /** * Created by minjaesong on 16-01-17. */ -class MapLayer(var width: Int, var height: Int) : Iterable { +class MapLayer(val width: Int, val height: Int) : Iterable { - internal var data: Array + internal @Volatile var data: Array // in parallel programming: do not trust your register; always read freshly from RAM! init { data = Array(height) { ByteArray(width) } diff --git a/src/net/torvald/terrarum/gameworld/PairedMapLayer.kt b/src/net/torvald/terrarum/gameworld/PairedMapLayer.kt index 91790b998..19d10d5d6 100644 --- a/src/net/torvald/terrarum/gameworld/PairedMapLayer.kt +++ b/src/net/torvald/terrarum/gameworld/PairedMapLayer.kt @@ -7,7 +7,7 @@ import java.util.function.Consumer /** * Created by minjaesong on 16-02-15. */ -class PairedMapLayer(width: Int, var height: Int) : Iterable { +class PairedMapLayer(width: Int, val height: Int) : Iterable { /** * 0b_xxxx_yyyy, x for lower index, y for higher index @@ -17,9 +17,9 @@ class PairedMapLayer(width: Int, var height: Int) : Iterable { * 0110 1101 is interpreted as * 6 for tile 0, 13 for tile 1. */ - internal var dataPair: Array + internal @Volatile var dataPair: Array - var width: Int = 0 + val width: Int init { this.width = width / 2 diff --git a/src/net/torvald/terrarum/gameworld/WorldTime.kt b/src/net/torvald/terrarum/gameworld/WorldTime.kt index 5ee501345..efa2391dd 100644 --- a/src/net/torvald/terrarum/gameworld/WorldTime.kt +++ b/src/net/torvald/terrarum/gameworld/WorldTime.kt @@ -56,6 +56,8 @@ class WorldTime { val HOUR_MIN: Int = 60 val GAME_MIN_TO_REAL_SEC: Float = 60f + val YEAR_DAYS: Int = 365 + fun parseTime(s: String): Int = if (s.length >= 4) { s.toLowerCase().substringBefore('h').toInt() * WorldTime.HOUR_SEC + @@ -103,9 +105,6 @@ class WorldTime { val elapsedSeconds: Int get() = (HOUR_SEC * hours + MINUTE_SEC * minutes + seconds) % DAY_LENGTH - val isLeapYear: Boolean - get() = years % 4 == 0 && years % 100 != 0 || years % 400 == 0 - /** Sets time of this day. */ fun setTime(t: Int) { days += t / DAY_LENGTH @@ -148,11 +147,11 @@ class WorldTime { if (dayOfWeek == 7) { dayOfWeek = 0 } - if ((months == 12 || months == 7 && isLeapYear) && days == 31) { + if (months == 12 && days == 31) { dayOfWeek = 7 } - if ((months == 12 || months == 7 && isLeapYear) && days == 32) { + if (months == 12 && days == 32) { days = 1 months = 1 years++ @@ -173,7 +172,14 @@ class WorldTime { } } - fun getFormattedTime() = "${String.format("%02d", hours)}h${String.format("%02d", minutes)}" + /** Format: "%A %d %B %Y %X" */ + fun getFormattedTime() = "${getDayNameFull()} " + + "$days " + + "${getMonthNameFull()} " + + "$years " + + "${String.format("%02d", hours)}:" + + "${String.format("%02d", minutes)}:" + + "${String.format("%02d", seconds)}" fun getDayNameFull() = DAY_NAMES[dayOfWeek] fun getDayNameShort() = DAY_NAMES_SHORT[dayOfWeek] diff --git a/src/net/torvald/terrarum/virtualcomputer/assets/lua/BOOT.lua b/src/net/torvald/terrarum/virtualcomputer/assets/lua/BOOT.lua index eaf6ceda0..324282f18 100644 --- a/src/net/torvald/terrarum/virtualcomputer/assets/lua/BOOT.lua +++ b/src/net/torvald/terrarum/virtualcomputer/assets/lua/BOOT.lua @@ -455,7 +455,7 @@ do end ::brk:: end - return s + return s end local function push_onecapture(ms, i, s, e) diff --git a/src/org/dyn4j/geometry/Vector2.kt b/src/org/dyn4j/geometry/Vector2.kt index 114a4b664..3a5890718 100644 --- a/src/org/dyn4j/geometry/Vector2.kt +++ b/src/org/dyn4j/geometry/Vector2.kt @@ -66,10 +66,10 @@ import org.dyn4j.Epsilon class Vector2 { /** The magnitude of the x component of this [Vector2] */ - var x: Double = 0.0 + @Volatile var x: Double = 0.0 /** The magnitude of the y component of this [Vector2] */ - var y: Double = 0.0 + @Volatile var y: Double = 0.0 /** Default constructor. */ constructor() {