new actor type "HistoricalFigure" that has date of birth and death

Former-commit-id: ec7ca90f29e0c56b3553e87b5a95fd023d9c55e1
Former-commit-id: 685958754f78542843913731880eb73f90e8e4c9
This commit is contained in:
Song Minjae
2016-10-10 18:25:29 +09:00
parent b0736aa722
commit c1d72c29af
12 changed files with 79 additions and 27 deletions

View File

@@ -9,10 +9,7 @@ class GetTime : ConsoleCommand {
override fun execute(args: Array<String>) {
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() {

View File

@@ -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

View 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)
}
}

View File

@@ -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 {

View File

@@ -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

View File

@@ -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)

View File

@@ -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.

View File

@@ -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<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 {
data = Array(height) { ByteArray(width) }

View File

@@ -7,7 +7,7 @@ import java.util.function.Consumer
/**
* 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
@@ -17,9 +17,9 @@ class PairedMapLayer(width: Int, var height: Int) : Iterable<Byte> {
* 0110 1101 is interpreted as
* 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 {
this.width = width / 2

View File

@@ -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]

View File

@@ -455,7 +455,7 @@ do
end
::brk::
end
return s
return s
end
local function push_onecapture(ms, i, s, e)

View File

@@ -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() {