mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-12 03:24:06 +09:00
new actor type "HistoricalFigure" that has date of birth and death
Former-commit-id: ec7ca90f29e0c56b3553e87b5a95fd023d9c55e1 Former-commit-id: 685958754f78542843913731880eb73f90e8e4c9
This commit is contained in:
@@ -9,10 +9,7 @@ class GetTime : ConsoleCommand {
|
|||||||
override fun execute(args: Array<String>) {
|
override fun execute(args: Array<String>) {
|
||||||
val echo = Echo()
|
val echo = Echo()
|
||||||
val worldTime = Terrarum.ingame.world.time
|
val worldTime = Terrarum.ingame.world.time
|
||||||
echo.execute("Year ${worldTime.years}, Month ${worldTime.months}, " +
|
echo.execute(worldTime.getFormattedTime())
|
||||||
"Day ${worldTime.days} (${worldTime.getDayNameShort()}), " +
|
|
||||||
"${worldTime.getFormattedTime()}"
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun printUsage() {
|
override fun printUsage() {
|
||||||
|
|||||||
@@ -130,8 +130,8 @@ open class ActorWithBody : Actor(), Visible {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
var grounded = false
|
@Volatile var grounded = false
|
||||||
override var flagDespawn = false
|
override @Volatile var flagDespawn = false
|
||||||
/** Default to 'false' */
|
/** Default to 'false' */
|
||||||
var isVisible = false
|
var isVisible = false
|
||||||
/** Default to 'true' */
|
/** 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.
|
* think of a grass cutting on the Zelda games. It would also make a great puzzle to solve.
|
||||||
* --minjaesong)
|
* --minjaesong)
|
||||||
*/
|
*/
|
||||||
var isChronostasis = false
|
@Volatile var isChronostasis = false
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constants
|
* Constants
|
||||||
@@ -213,8 +213,8 @@ open class ActorWithBody : Actor(), Visible {
|
|||||||
@Transient private var assertPrinted = false
|
@Transient private var assertPrinted = false
|
||||||
|
|
||||||
// to use with Controller (incl. player)
|
// to use with Controller (incl. player)
|
||||||
internal var walledLeft = false
|
internal @Volatile var walledLeft = false
|
||||||
internal var walledRight = false
|
internal @Volatile var walledRight = false
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* true: This actor had just made collision
|
* true: This actor had just made collision
|
||||||
|
|||||||
49
src/net/torvald/terrarum/gameactors/HistoricalFigure.kt
Normal file
49
src/net/torvald/terrarum/gameactors/HistoricalFigure.kt
Normal file
@@ -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)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -10,7 +10,7 @@ import java.util.*
|
|||||||
/**
|
/**
|
||||||
* Created by minjaesong on 16-03-14.
|
* Created by minjaesong on 16-03-14.
|
||||||
*/
|
*/
|
||||||
open class NPCIntelligentBase : ActorWithBody()
|
open class NPCIntelligentBase(born: GameDate) : HistoricalFigure(born)
|
||||||
, AIControlled, Pocketed, CanBeAnItem, Factionable, LandHolder {
|
, AIControlled, Pocketed, CanBeAnItem, Factionable, LandHolder {
|
||||||
|
|
||||||
override var actorAI: ActorAI = object : ActorAI {
|
override var actorAI: ActorAI = object : ActorAI {
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import net.torvald.terrarum.mapdrawer.MapDrawer
|
|||||||
object PBCynthia {
|
object PBCynthia {
|
||||||
|
|
||||||
fun create(): Player {
|
fun create(): Player {
|
||||||
val p: Player = Player()
|
val p: Player = Player(GameDate(100, 143)) // random value thrown
|
||||||
CreatureRawInjector.inject(p.actorValue, "CreatureHuman.json")
|
CreatureRawInjector.inject(p.actorValue, "CreatureHuman.json")
|
||||||
|
|
||||||
p.actorValue[AVKey.__PLAYER_QUICKBARSEL] = 0
|
p.actorValue[AVKey.__PLAYER_QUICKBARSEL] = 0
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ import java.io.IOException
|
|||||||
object PBSigrid {
|
object PBSigrid {
|
||||||
|
|
||||||
fun create(): Player {
|
fun create(): Player {
|
||||||
val p = Player()
|
val p = Player(GameDate(-2147483648, 0)) // XD
|
||||||
|
|
||||||
p.sprite = SpriteAnimation()
|
p.sprite = SpriteAnimation()
|
||||||
p.sprite!!.setDimension(28, 51)
|
p.sprite!!.setDimension(28, 51)
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ import java.util.*
|
|||||||
* Created by minjaesong on 16-03-14.
|
* 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.
|
* empirical value.
|
||||||
|
|||||||
@@ -3,9 +3,9 @@ package net.torvald.terrarum.gameworld
|
|||||||
/**
|
/**
|
||||||
* Created by minjaesong on 16-01-17.
|
* Created by minjaesong on 16-01-17.
|
||||||
*/
|
*/
|
||||||
class MapLayer(var width: Int, var height: Int) : Iterable<Byte> {
|
class MapLayer(val width: Int, val height: Int) : Iterable<Byte> {
|
||||||
|
|
||||||
internal var data: Array<ByteArray>
|
internal @Volatile var data: Array<ByteArray> // in parallel programming: do not trust your register; always read freshly from RAM!
|
||||||
|
|
||||||
init {
|
init {
|
||||||
data = Array(height) { ByteArray(width) }
|
data = Array(height) { ByteArray(width) }
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import java.util.function.Consumer
|
|||||||
/**
|
/**
|
||||||
* Created by minjaesong on 16-02-15.
|
* Created by minjaesong on 16-02-15.
|
||||||
*/
|
*/
|
||||||
class PairedMapLayer(width: Int, var height: Int) : Iterable<Byte> {
|
class PairedMapLayer(width: Int, val height: Int) : Iterable<Byte> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 0b_xxxx_yyyy, x for lower index, y for higher index
|
* 0b_xxxx_yyyy, x for lower index, y for higher index
|
||||||
@@ -17,9 +17,9 @@ class PairedMapLayer(width: Int, var height: Int) : Iterable<Byte> {
|
|||||||
* 0110 1101 is interpreted as
|
* 0110 1101 is interpreted as
|
||||||
* 6 for tile 0, 13 for tile 1.
|
* 6 for tile 0, 13 for tile 1.
|
||||||
*/
|
*/
|
||||||
internal var dataPair: Array<ByteArray>
|
internal @Volatile var dataPair: Array<ByteArray>
|
||||||
|
|
||||||
var width: Int = 0
|
val width: Int
|
||||||
|
|
||||||
init {
|
init {
|
||||||
this.width = width / 2
|
this.width = width / 2
|
||||||
|
|||||||
@@ -56,6 +56,8 @@ class WorldTime {
|
|||||||
val HOUR_MIN: Int = 60
|
val HOUR_MIN: Int = 60
|
||||||
val GAME_MIN_TO_REAL_SEC: Float = 60f
|
val GAME_MIN_TO_REAL_SEC: Float = 60f
|
||||||
|
|
||||||
|
val YEAR_DAYS: Int = 365
|
||||||
|
|
||||||
fun parseTime(s: String): Int =
|
fun parseTime(s: String): Int =
|
||||||
if (s.length >= 4) {
|
if (s.length >= 4) {
|
||||||
s.toLowerCase().substringBefore('h').toInt() * WorldTime.HOUR_SEC +
|
s.toLowerCase().substringBefore('h').toInt() * WorldTime.HOUR_SEC +
|
||||||
@@ -103,9 +105,6 @@ class WorldTime {
|
|||||||
val elapsedSeconds: Int
|
val elapsedSeconds: Int
|
||||||
get() = (HOUR_SEC * hours + MINUTE_SEC * minutes + seconds) % DAY_LENGTH
|
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. */
|
/** Sets time of this day. */
|
||||||
fun setTime(t: Int) {
|
fun setTime(t: Int) {
|
||||||
days += t / DAY_LENGTH
|
days += t / DAY_LENGTH
|
||||||
@@ -148,11 +147,11 @@ class WorldTime {
|
|||||||
if (dayOfWeek == 7) {
|
if (dayOfWeek == 7) {
|
||||||
dayOfWeek = 0
|
dayOfWeek = 0
|
||||||
}
|
}
|
||||||
if ((months == 12 || months == 7 && isLeapYear) && days == 31) {
|
if (months == 12 && days == 31) {
|
||||||
dayOfWeek = 7
|
dayOfWeek = 7
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((months == 12 || months == 7 && isLeapYear) && days == 32) {
|
if (months == 12 && days == 32) {
|
||||||
days = 1
|
days = 1
|
||||||
months = 1
|
months = 1
|
||||||
years++
|
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 getDayNameFull() = DAY_NAMES[dayOfWeek]
|
||||||
fun getDayNameShort() = DAY_NAMES_SHORT[dayOfWeek]
|
fun getDayNameShort() = DAY_NAMES_SHORT[dayOfWeek]
|
||||||
|
|||||||
@@ -455,7 +455,7 @@ do
|
|||||||
end
|
end
|
||||||
::brk::
|
::brk::
|
||||||
end
|
end
|
||||||
return s
|
return s
|
||||||
end
|
end
|
||||||
|
|
||||||
local function push_onecapture(ms, i, s, e)
|
local function push_onecapture(ms, i, s, e)
|
||||||
|
|||||||
@@ -66,10 +66,10 @@ import org.dyn4j.Epsilon
|
|||||||
class Vector2 {
|
class Vector2 {
|
||||||
|
|
||||||
/** The magnitude of the x component of this [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] */
|
/** The magnitude of the y component of this [Vector2] */
|
||||||
var y: Double = 0.0
|
@Volatile var y: Double = 0.0
|
||||||
|
|
||||||
/** Default constructor. */
|
/** Default constructor. */
|
||||||
constructor() {
|
constructor() {
|
||||||
|
|||||||
Reference in New Issue
Block a user