mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-07 20:31:51 +09:00
more draft on Actor inventory (save <RefID/ItemID, amount>), successfully implemented 9-set hangul johab font, Hashtable -> HashMap
Former-commit-id: 4f51d33a166ca10ee49c471104ebe97aeee33fe7 Former-commit-id: 0066f44d522f3c9d96ad57b92d17a05dc920bffb
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -100,3 +100,12 @@
|
||||
|
||||
Scale ^ 3 ^ (3/4)
|
||||
= (ThisWgt / TargetWgt) ^ (3/4)
|
||||
|
||||
|
||||
== (De)serialisation ==
|
||||
|
||||
* Custom binary + GSON
|
||||
|
||||
* Custom binary: Game map
|
||||
|
||||
* GSON: Actors, game configurations
|
||||
Binary file not shown.
Binary file not shown.
|
Before Width: | Height: | Size: 1.7 KiB After Width: | Height: | Size: 19 KiB |
@@ -61,9 +61,9 @@ public class HSVUtil {
|
||||
}
|
||||
|
||||
return new Color(
|
||||
(int) ((R_prime + m) * 255)
|
||||
, (int) ((G_prime + m) * 255)
|
||||
, (int) ((B_prime + m) * 255)
|
||||
(R_prime + m)
|
||||
, (G_prime + m)
|
||||
, (B_prime + m)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -72,9 +72,9 @@ public class HSVUtil {
|
||||
}
|
||||
|
||||
public static HSV fromRGB(Color color) {
|
||||
float r = color.getRed() / 255f;
|
||||
float g = color.getGreen() / 255f;
|
||||
float b = color.getBlue() / 255f;
|
||||
float r = color.r;
|
||||
float g = color.g;
|
||||
float b = color.b;
|
||||
|
||||
float rgbMin = FastMath.min(r, g, b);
|
||||
float rgbMax = FastMath.max(r, g, b);
|
||||
|
||||
@@ -10,5 +10,9 @@ public interface Actor {
|
||||
|
||||
void update(GameContainer gc, int delta_t);
|
||||
|
||||
/**
|
||||
* Valid RefID is equal to or greater than 32768.
|
||||
* @return Reference ID. (32768-0x7FFF_FFFF_FFFF_FFFF)
|
||||
*/
|
||||
long getRefID();
|
||||
}
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
package com.Torvald.Terrarum.Actors;
|
||||
|
||||
import com.Torvald.Terrarum.GameItem.InventoryItem;
|
||||
import com.Torvald.Terrarum.GameItem.ItemCodex;
|
||||
import com.sun.istack.internal.Nullable;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 16-01-15.
|
||||
@@ -14,10 +18,13 @@ public class ActorInventory {
|
||||
@Nullable private int capacityByWeight;
|
||||
private int capacityMode;
|
||||
|
||||
private LinkedList<InventoryItem> pocket;
|
||||
/**
|
||||
* <ReferenceID, Amounts>
|
||||
*/
|
||||
private HashMap<Long, Integer> itemList;
|
||||
|
||||
public final int CAPACITY_MODE_COUNT = 1;
|
||||
public final int CAPACITY_MODE_WEIGHT = 2;
|
||||
public final transient int CAPACITY_MODE_COUNT = 1;
|
||||
public final transient int CAPACITY_MODE_WEIGHT = 2;
|
||||
|
||||
/**
|
||||
* Construct new inventory with specified capacity.
|
||||
@@ -53,26 +60,28 @@ public class ActorInventory {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get reference to the pocket
|
||||
* Get reference to the itemList
|
||||
* @return
|
||||
*/
|
||||
public LinkedList<InventoryItem> getPocket() {
|
||||
return pocket;
|
||||
public Map<Long, Integer> getItemList() {
|
||||
return itemList;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get clone of the pocket
|
||||
* Get clone of the itemList
|
||||
* @return
|
||||
*/
|
||||
public LinkedList<InventoryItem> getCopyOfPocket() {
|
||||
return (LinkedList<InventoryItem>) (pocket.clone());
|
||||
public Map getCopyOfItemList() {
|
||||
return (Map) (itemList.clone());
|
||||
}
|
||||
|
||||
public float getTotalWeight() {
|
||||
float weight = 0;
|
||||
|
||||
for (InventoryItem item : pocket) {
|
||||
weight += item.getWeight();
|
||||
for (Map.Entry<Long, Integer> item : itemList.entrySet()) {
|
||||
//weight += item.getWeight();
|
||||
weight += ItemCodex.getItem(item.getKey()).getWeight()
|
||||
* item.getValue();
|
||||
}
|
||||
|
||||
return weight;
|
||||
@@ -81,19 +90,24 @@ public class ActorInventory {
|
||||
public float getTotalCount() {
|
||||
int count = 0;
|
||||
|
||||
for (InventoryItem item : pocket) {
|
||||
count += 1;
|
||||
for (Map.Entry<Long, Integer> item : itemList.entrySet()) {
|
||||
//weight += item.getWeight();
|
||||
count += item.getValue();
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
public void appendToPocket(InventoryItem item) {
|
||||
pocket.add(item);
|
||||
long key = item.getItemID();
|
||||
if (itemList.containsKey(key))
|
||||
itemList.put(key, itemList.get(key) + 1);
|
||||
else
|
||||
itemList.put(key, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether the pocket contains too many items
|
||||
* Check whether the itemList contains too many items
|
||||
* @return
|
||||
*/
|
||||
public boolean isEncumbered() {
|
||||
|
||||
@@ -1,13 +1,10 @@
|
||||
package com.Torvald.Terrarum.Actors;
|
||||
|
||||
import com.Torvald.Terrarum.KVHashtable;
|
||||
|
||||
import java.util.Hashtable;
|
||||
import java.util.Set;
|
||||
import com.Torvald.Terrarum.KVHashMap;
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 16-01-03.
|
||||
*/
|
||||
public class ActorValue extends KVHashtable {
|
||||
public class ActorValue extends KVHashMap {
|
||||
|
||||
}
|
||||
|
||||
@@ -10,6 +10,8 @@ import com.jme3.math.FastMath;
|
||||
import org.newdawn.slick.GameContainer;
|
||||
import org.newdawn.slick.Graphics;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 16-01-13.
|
||||
*/
|
||||
@@ -19,8 +21,7 @@ public class ActorWithBody implements Actor, Visible, Glowing {
|
||||
|
||||
ActorInventory inventory;
|
||||
|
||||
private @NotNull
|
||||
float hitboxTranslateX; // relative to spritePosX
|
||||
private @NotNull float hitboxTranslateX; // relative to spritePosX
|
||||
private @NotNull float hitboxTranslateY; // relative to spritePosY
|
||||
private @NotNull int baseHitboxW;
|
||||
private @NotNull int baseHitboxH;
|
||||
@@ -34,13 +35,12 @@ public class ActorWithBody implements Actor, Visible, Glowing {
|
||||
* +3.0 is acceleration. You __accumulate__ acceleration to the velocity.
|
||||
*/
|
||||
private volatile @NotNull float veloX, veloY;
|
||||
private final float VELO_HARD_LIMIT = 10000;
|
||||
private final transient float VELO_HARD_LIMIT = 10000;
|
||||
|
||||
boolean grounded = false;
|
||||
|
||||
@Nullable
|
||||
SpriteAnimation sprite;
|
||||
@Nullable SpriteAnimation spriteGlow;
|
||||
@Nullable transient SpriteAnimation sprite;
|
||||
@Nullable transient SpriteAnimation spriteGlow;
|
||||
/** Default to 'false' */
|
||||
private boolean visible = false;
|
||||
/** Default to 'true' */
|
||||
@@ -60,15 +60,15 @@ public class ActorWithBody implements Actor, Visible, Glowing {
|
||||
/**
|
||||
* Physical properties
|
||||
*/
|
||||
@NonZero private volatile float scale = 1;
|
||||
@NonZero private volatile float mass = 2f;
|
||||
private final float MASS_LOWEST = 2f;
|
||||
@NonZero private volatile transient float scale = 1;
|
||||
@NonZero private volatile transient float mass = 2f;
|
||||
private final transient float MASS_LOWEST = 2f;
|
||||
/** Valid range: [0, 1] */
|
||||
private float elasticity = 0;
|
||||
private final float ELASTICITY_MAX = 0.993f;
|
||||
private final transient float ELASTICITY_MAX = 0.993f;
|
||||
@NoNegative private float density = 1000;
|
||||
|
||||
private static final int TSIZE = MapDrawer.TILE_SIZE;
|
||||
private static final transient int TSIZE = MapDrawer.TILE_SIZE;
|
||||
private static int AUTO_CLIMB_RATE = TSIZE / 8;
|
||||
|
||||
/**
|
||||
@@ -77,53 +77,53 @@ public class ActorWithBody implements Actor, Visible, Glowing {
|
||||
* s^2 = 1/FPS = 1/60 if FPS is targeted to 60
|
||||
* meter to pixel : 24/FPS
|
||||
*/
|
||||
private final float METER = 24f;
|
||||
private final transient float METER = 24f;
|
||||
/**
|
||||
* [m / s^2] * SI_TO_GAME_ACC -> [px / IFrame^2]
|
||||
*/
|
||||
private final float SI_TO_GAME_ACC = METER / FastMath.sqr(Terrarum.TARGET_FPS);
|
||||
private final transient float SI_TO_GAME_ACC = METER / FastMath.sqr(Terrarum.TARGET_FPS);
|
||||
/**
|
||||
* [m / s] * SI_TO_GAME_VEL -> [px / IFrame]
|
||||
*/
|
||||
private final float SI_TO_GAME_VEL = METER / Terrarum.TARGET_FPS;
|
||||
private final transient float SI_TO_GAME_VEL = METER / Terrarum.TARGET_FPS;
|
||||
|
||||
private float gravitation;
|
||||
private final float DRAG_COEFF = 1f;
|
||||
private final transient float DRAG_COEFF = 1f;
|
||||
|
||||
private final int CONTACT_AREA_TOP = 0;
|
||||
private final int CONTACT_AREA_RIGHT = 1;
|
||||
private final int CONTACT_AREA_BOTTOM = 2;
|
||||
private final int CONTACT_AREA_LEFT = 3;
|
||||
private final transient int CONTACT_AREA_TOP = 0;
|
||||
private final transient int CONTACT_AREA_RIGHT = 1;
|
||||
private final transient int CONTACT_AREA_BOTTOM = 2;
|
||||
private final transient int CONTACT_AREA_LEFT = 3;
|
||||
|
||||
private final int UD_COMPENSATOR_MAX = TSIZE;
|
||||
private final int LR_COMPENSATOR_MAX = TSIZE;
|
||||
private final int TILE_AUTOCLIMB_RATE = 4;
|
||||
private final transient int UD_COMPENSATOR_MAX = TSIZE;
|
||||
private final transient int LR_COMPENSATOR_MAX = TSIZE;
|
||||
private final transient int TILE_AUTOCLIMB_RATE = 4;
|
||||
|
||||
/**
|
||||
* A constant to make falling faster so that the game is more playable
|
||||
*/
|
||||
private final float G_MUL_PLAYABLE_CONST = 1.4142f;
|
||||
private final transient float G_MUL_PLAYABLE_CONST = 1.4142f;
|
||||
|
||||
long referenceID;
|
||||
|
||||
private final int EVENT_MOVE_TOP = 0;
|
||||
private final int EVENT_MOVE_RIGHT = 1;
|
||||
private final int EVENT_MOVE_BOTTOM = 2;
|
||||
private final int EVENT_MOVE_LEFT = 3;
|
||||
private final int EVENT_MOVE_NONE = -1;
|
||||
private final transient int EVENT_MOVE_TOP = 0;
|
||||
private final transient int EVENT_MOVE_RIGHT = 1;
|
||||
private final transient int EVENT_MOVE_BOTTOM = 2;
|
||||
private final transient int EVENT_MOVE_LEFT = 3;
|
||||
private final transient int EVENT_MOVE_NONE = -1;
|
||||
|
||||
int eventMoving = EVENT_MOVE_NONE; // cannot collide both X-axis and Y-axis, or else jump control breaks up.
|
||||
|
||||
/**
|
||||
* in milliseconds
|
||||
*/
|
||||
public final int INVINCIBILITY_TIME = 500;
|
||||
public final transient int INVINCIBILITY_TIME = 500;
|
||||
|
||||
/**
|
||||
* Will ignore fluid resistance if (submerged height / actor height) <= this var
|
||||
*/
|
||||
private final float FLUID_RESISTANCE_IGNORE_THRESHOLD_RATIO = 0.2f;
|
||||
private final float FLUID_RESISTANCE_APPLY_FULL_RATIO = 0.5f;
|
||||
private final transient float FLUID_RESISTANCE_IGNORE_THRESHOLD_RATIO = 0.2f;
|
||||
private final transient float FLUID_RESISTANCE_APPLY_FULL_RATIO = 0.5f;
|
||||
|
||||
private GameMap map;
|
||||
|
||||
@@ -958,6 +958,10 @@ public class ActorWithBody implements Actor, Visible, Glowing {
|
||||
this.noSubjectToFluidResistance = noSubjectToFluidResistance;
|
||||
}
|
||||
|
||||
public float getElasticity() {
|
||||
return elasticity;
|
||||
}
|
||||
|
||||
public void setElasticity(float elasticity) {
|
||||
if (elasticity < 0)
|
||||
throw new IllegalArgumentException("[ActorWithBody] " + elasticity + ": valid elasticity value is [0, 1].");
|
||||
|
||||
@@ -6,6 +6,7 @@ import com.Torvald.Terrarum.GameItem.InventoryItem;
|
||||
import com.Torvald.Terrarum.Terrarum;
|
||||
import org.newdawn.slick.GameContainer;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
|
||||
@@ -16,7 +17,7 @@ public class NPCIntelligentBase extends ActorWithBody implements AIControlled, P
|
||||
Factionable, Landholder {
|
||||
|
||||
private InventoryItem itemData; // keep it for extendibility, like Carriers in SC1
|
||||
private ActorAI ai;
|
||||
private transient ActorAI ai;
|
||||
private ActorInventory inventory;
|
||||
|
||||
private HashSet<Faction> factionSet = new HashSet<>();
|
||||
@@ -51,35 +52,35 @@ public class NPCIntelligentBase extends ActorWithBody implements AIControlled, P
|
||||
public void attachItemData() {
|
||||
itemData = new InventoryItem() {
|
||||
@Override
|
||||
public float getWeight() {
|
||||
return getMass();
|
||||
public long getItemID() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getWeight() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** Set no effect */
|
||||
@Override
|
||||
public void effectWhileInPocket(GameContainer gc, int delta_t) {
|
||||
|
||||
}
|
||||
|
||||
/** Set no effect */
|
||||
@Override
|
||||
public void effectWhenPickedUp(GameContainer gc, int delta_t) {
|
||||
|
||||
}
|
||||
|
||||
/** Set no effect */
|
||||
@Override
|
||||
public void primaryUse(GameContainer gc, int delta_t) {
|
||||
|
||||
}
|
||||
|
||||
/** Set no effect */
|
||||
@Override
|
||||
public void secondaryUse(GameContainer gc, int delta_t) {
|
||||
|
||||
}
|
||||
|
||||
/** Set no effect */
|
||||
@Override
|
||||
public void effectWhenThrownAway(GameContainer gc, int delta_t) {
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ import org.lwjgl.input.Controller;
|
||||
import org.lwjgl.input.Controllers;
|
||||
import org.newdawn.slick.*;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.HashSet;
|
||||
|
||||
/**
|
||||
@@ -24,13 +25,13 @@ public class Player extends ActorWithBody implements Controllable, Pocketed, Fac
|
||||
|
||||
int jumpCounter = 0;
|
||||
int walkPowerCounter = 0;
|
||||
private final int MAX_JUMP_LENGTH = 17; // use 17; in internal frames
|
||||
private final transient int MAX_JUMP_LENGTH = 17; // use 17; in internal frames
|
||||
/**
|
||||
* experimental value.
|
||||
*/
|
||||
// private final float JUMP_ACCELERATION_MOD = ???f / 10000f; //quadratic mode
|
||||
private final float JUMP_ACCELERATION_MOD = 170f / 10000f; //linear mode
|
||||
private final int WALK_FRAMES_TO_MAX_ACCEL = 6;
|
||||
// private final transient float JUMP_ACCELERATION_MOD = ???f / 10000f; //quadratic mode
|
||||
private final transient float JUMP_ACCELERATION_MOD = 170f / 10000f; //linear mode
|
||||
private final transient int WALK_FRAMES_TO_MAX_ACCEL = 6;
|
||||
|
||||
public float readonly_totalX = 0, readonly_totalY = 0;
|
||||
|
||||
@@ -38,29 +39,29 @@ public class Player extends ActorWithBody implements Controllable, Pocketed, Fac
|
||||
|
||||
@NotNull int walkHeading;
|
||||
|
||||
private final int LEFT = 1;
|
||||
private final int RIGHT = 2;
|
||||
private final transient int LEFT = 1;
|
||||
private final transient int RIGHT = 2;
|
||||
|
||||
private int prevHMoveKey = -1;
|
||||
private int prevVMoveKey = -1;
|
||||
private final int KEY_NULL = -1;
|
||||
private final transient int KEY_NULL = -1;
|
||||
private int prevHMoveKey = KEY_NULL;
|
||||
private int prevVMoveKey = KEY_NULL;
|
||||
|
||||
static final float ACCEL_MULT_IN_FLIGHT = 0.48f;
|
||||
static final float WALK_STOP_ACCEL = 0.32f;
|
||||
static final float WALK_ACCEL_BASE = 0.32f;
|
||||
static final transient float ACCEL_MULT_IN_FLIGHT = 0.48f;
|
||||
static final transient float WALK_STOP_ACCEL = 0.32f;
|
||||
static final transient float WALK_ACCEL_BASE = 0.32f;
|
||||
|
||||
private boolean noClip = false;
|
||||
|
||||
public static final long PLAYER_REF_ID = 0x51621D;
|
||||
|
||||
private final float AXIS_POSMAX = 1.0f;
|
||||
private final int GAMEPAD_JUMP = 5;
|
||||
private final transient float AXIS_POSMAX = 1.0f;
|
||||
private final transient int GAMEPAD_JUMP = 5;
|
||||
|
||||
private final int TSIZE = MapDrawer.TILE_SIZE;
|
||||
private final transient int TSIZE = MapDrawer.TILE_SIZE;
|
||||
|
||||
private HashSet<Faction> factionSet = new HashSet<>();
|
||||
|
||||
private final int BASE_DENSITY = 1020;
|
||||
private final transient int BASE_DENSITY = 1020;
|
||||
|
||||
|
||||
/**
|
||||
@@ -91,13 +92,13 @@ public class Player extends ActorWithBody implements Controllable, Pocketed, Fac
|
||||
|
||||
if (noClip) { super.setGrounded(true); }
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void updatePhysicalInfos() {
|
||||
super.setScale(actorValue.getAsFloat("scale"));
|
||||
super.setMass(actorValue.getAsFloat("basemass")
|
||||
* FastMath.pow(super.getScale(), 3));
|
||||
if (super.getElasticity() != 0) super.setElasticity(0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -2,17 +2,17 @@ package com.Torvald.Terrarum.ConsoleCommand;
|
||||
|
||||
import com.Torvald.Terrarum.Terrarum;
|
||||
|
||||
import java.util.Hashtable;
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 16-01-15.
|
||||
*/
|
||||
public class CommandDict {
|
||||
|
||||
protected static Hashtable<String, ConsoleCommand> dict;
|
||||
protected static HashMap<String, ConsoleCommand> dict;
|
||||
|
||||
public CommandDict() {
|
||||
dict = new Hashtable<>();
|
||||
dict = new HashMap<>();
|
||||
|
||||
dict.put("echo", new Echo());
|
||||
dict.put("setav", new SetAV());
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
package com.Torvald.Terrarum;
|
||||
|
||||
import java.util.Hashtable;
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 15-12-30.
|
||||
*/
|
||||
public class GameConfig extends KVHashtable{
|
||||
public class GameConfig extends KVHashMap {
|
||||
|
||||
}
|
||||
|
||||
@@ -7,6 +7,15 @@ import org.newdawn.slick.GameContainer;
|
||||
*/
|
||||
public interface InventoryItem {
|
||||
|
||||
/**
|
||||
* Get internal ID of an Item.
|
||||
* 0-4096: Tiles
|
||||
* 4097-32767: Various items
|
||||
* >=32768: Actor RefID
|
||||
* @return
|
||||
*/
|
||||
long getItemID();
|
||||
|
||||
/**
|
||||
* Weight of the item
|
||||
* @return
|
||||
|
||||
20
src/com/Torvald/Terrarum/GameItem/ItemCodex.java
Normal file
20
src/com/Torvald/Terrarum/GameItem/ItemCodex.java
Normal file
@@ -0,0 +1,20 @@
|
||||
package com.Torvald.Terrarum.GameItem;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 16-03-11.
|
||||
*/
|
||||
public class ItemCodex {
|
||||
|
||||
/**
|
||||
* <ItemID or RefID for Actor, TheItem>
|
||||
* Will return corresponding Actor if ID >= 32768
|
||||
*/
|
||||
private static HashMap<Long, InventoryItem> itemCodex;
|
||||
|
||||
public static InventoryItem getItem(long code) {
|
||||
return itemCodex.get(code);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -12,6 +12,7 @@ package com.Torvald.Terrarum.GameMap;
|
||||
import com.sun.istack.internal.NotNull;
|
||||
import org.newdawn.slick.SlickException;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Spliterator;
|
||||
@@ -32,9 +33,9 @@ public class GameMap {
|
||||
public int spawnX;
|
||||
public int spawnY;
|
||||
|
||||
public static final int WALL = 0;
|
||||
public static final int TERRAIN = 1;
|
||||
public static final int WIRE = 2;
|
||||
public static transient final int WALL = 0;
|
||||
public static transient final int TERRAIN = 1;
|
||||
public static transient final int WIRE = 2;
|
||||
|
||||
//public World physWorld = new World( new Vec2(0, -TerrarumMain.game.gravitationalAccel) );
|
||||
//physics
|
||||
@@ -42,7 +43,7 @@ public class GameMap {
|
||||
private char globalLight;
|
||||
private WorldTime worldTime;
|
||||
|
||||
public static final int TILES_SUPPORTED = MapLayer.RANGE * PairedMapLayer.RANGE;
|
||||
public static transient final int TILES_SUPPORTED = MapLayer.RANGE * PairedMapLayer.RANGE;
|
||||
|
||||
/**
|
||||
* @param width
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.Torvald.Terrarum.GameMap;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Iterator;
|
||||
import java.util.Spliterator;
|
||||
import java.util.function.Consumer;
|
||||
@@ -14,7 +15,7 @@ public class MapLayer implements Iterable<Byte> {
|
||||
public int width;
|
||||
public int height;
|
||||
|
||||
public static final int RANGE = 256;
|
||||
public static transient final int RANGE = 256;
|
||||
|
||||
public MapLayer(int width, int height) {
|
||||
this.width = width;
|
||||
|
||||
@@ -2,6 +2,8 @@ package com.Torvald.Terrarum.GameMap;
|
||||
|
||||
import com.Torvald.Point.Point2f;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
|
||||
public class MapPoint {
|
||||
private Point2f startPoint;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.Torvald.Terrarum.GameMap;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Iterator;
|
||||
import java.util.Spliterator;
|
||||
import java.util.function.Consumer;
|
||||
@@ -22,7 +23,7 @@ public class PairedMapLayer implements Iterable<Integer> {
|
||||
public int width;
|
||||
public int height;
|
||||
|
||||
public static final int RANGE = 16;
|
||||
public static transient final int RANGE = 16;
|
||||
|
||||
public PairedMapLayer(int width, int height) {
|
||||
this.width = width / 2;
|
||||
|
||||
@@ -1,25 +1,29 @@
|
||||
package com.Torvald.Terrarum.GameMap;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 16-01-24.
|
||||
*/
|
||||
public class WorldTime {
|
||||
|
||||
public int seconds = 0;
|
||||
public int minutes = 0;
|
||||
public int hours = 0;
|
||||
private int seconds = 0;
|
||||
private int minutes = 0;
|
||||
private int hours = 0;
|
||||
|
||||
public int daysCount = 0; //NOT a calendar day
|
||||
private int daysCount = 0; //NOT a calendar day
|
||||
|
||||
public int days = 1;
|
||||
public int months = 1;
|
||||
public int years = 1;
|
||||
private int days = 1;
|
||||
private int months = 1;
|
||||
private int years = 1;
|
||||
|
||||
public int weeks = 1;
|
||||
public int dayOfWeek = 0; //0: Mondag-The first day of weekday
|
||||
private int dayOfWeek = 0; //0: Mondag-The first day of weekday
|
||||
|
||||
public static final int DAY_LENGTH = 79200; //must be the multiple of 3600
|
||||
public int timeDelta = 1;
|
||||
public static transient final int DAY_LENGTH = 79200; //must be the multiple of 3600
|
||||
private int timeDelta = 1;
|
||||
|
||||
private static transient final int HOUR_SEC = 3600;
|
||||
private static transient final int MINUTE_SEC = 60;
|
||||
|
||||
public final String[] DAYNAMES = { //daynames are taken from Nynorsk (å -> o)
|
||||
"Mondag"
|
||||
@@ -52,22 +56,7 @@ public class WorldTime {
|
||||
//time
|
||||
seconds += timeDelta;
|
||||
|
||||
if (seconds >= 60){
|
||||
seconds = 0;
|
||||
minutes++;
|
||||
}
|
||||
|
||||
if (minutes >= 60){
|
||||
minutes = 0;
|
||||
hours++;
|
||||
}
|
||||
|
||||
if (hours >= DAY_LENGTH/3600){
|
||||
hours = 0;
|
||||
days++;
|
||||
daysCount++;
|
||||
dayOfWeek++;
|
||||
}
|
||||
kickVariables();
|
||||
|
||||
//calendar (the world calendar)
|
||||
if (dayOfWeek == 7){
|
||||
@@ -97,37 +86,31 @@ public class WorldTime {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* How much time has passed today, in seconds.
|
||||
* @return
|
||||
*/
|
||||
public int elapsedSeconds(){
|
||||
return (3600 * hours + 60 * minutes + seconds) % DAY_LENGTH;
|
||||
return (HOUR_SEC * hours + MINUTE_SEC * minutes + seconds) % DAY_LENGTH;
|
||||
}
|
||||
|
||||
/**
|
||||
* How much time has passed since the beginning, in seconds.
|
||||
* @return
|
||||
*/
|
||||
public long totalSeconds(){
|
||||
return (long)(DAY_LENGTH) * daysCount + 3600 * hours + 60 * minutes + seconds;
|
||||
return (long)(DAY_LENGTH) * daysCount + HOUR_SEC * hours + MINUTE_SEC * minutes + seconds;
|
||||
}
|
||||
|
||||
public boolean isLeapYear(){
|
||||
boolean ret = false;
|
||||
|
||||
if (years % 4 == 0){
|
||||
ret = true;
|
||||
|
||||
if (years % 100 == 0){
|
||||
ret = false;
|
||||
|
||||
if (years % 400 == 0){
|
||||
ret = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
return ((years % 4 == 0) && (years % 100 != 0)) || (years % 400 == 0);
|
||||
}
|
||||
|
||||
public void setTime(int t){
|
||||
days += t / DAY_LENGTH;
|
||||
hours = t / 3600;
|
||||
minutes = (t - 3600 * hours) / 60;
|
||||
seconds = t - minutes * 60;
|
||||
hours = t / HOUR_SEC;
|
||||
minutes = (t - HOUR_SEC * hours) / MINUTE_SEC;
|
||||
seconds = t - minutes * MINUTE_SEC;
|
||||
}
|
||||
|
||||
public void addTime(int t){
|
||||
@@ -141,4 +124,23 @@ public class WorldTime {
|
||||
public String getDayName(){
|
||||
return DAYNAMES[dayOfWeek];
|
||||
}
|
||||
|
||||
private void kickVariables() {
|
||||
if (seconds >= 60){
|
||||
seconds = 0;
|
||||
minutes++;
|
||||
}
|
||||
|
||||
if (minutes >= 60){
|
||||
minutes = 0;
|
||||
hours++;
|
||||
}
|
||||
|
||||
if (hours >= DAY_LENGTH/3600){
|
||||
hours = 0;
|
||||
days++;
|
||||
daysCount++;
|
||||
dayOfWeek++;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,17 +1,18 @@
|
||||
package com.Torvald.Terrarum;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 15-12-30.
|
||||
*/
|
||||
public class KVHashtable {
|
||||
public class KVHashMap {
|
||||
|
||||
private Hashtable<String, Object> hashtable;
|
||||
private HashMap<String, Object> hashMap;
|
||||
|
||||
public KVHashtable() {
|
||||
hashtable = new Hashtable<>();
|
||||
public KVHashMap() {
|
||||
hashMap = new HashMap<>();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -23,7 +24,7 @@ public class KVHashtable {
|
||||
* @param value
|
||||
*/
|
||||
public void set(String key, Object value){
|
||||
hashtable.put(key.toLowerCase(), value);
|
||||
hashMap.put(key.toLowerCase(), value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -33,7 +34,7 @@ public class KVHashtable {
|
||||
* @return Object value
|
||||
*/
|
||||
public Object get(String key){
|
||||
return hashtable.get(key.toLowerCase());
|
||||
return hashMap.get(key.toLowerCase());
|
||||
}
|
||||
|
||||
public int getAsInt(String key) {
|
||||
@@ -55,11 +56,11 @@ public class KVHashtable {
|
||||
}
|
||||
|
||||
public boolean hasKey(String key) {
|
||||
return hashtable.containsKey(key);
|
||||
return hashMap.containsKey(key);
|
||||
}
|
||||
|
||||
public Set getKeySet() {
|
||||
return hashtable.keySet();
|
||||
return hashMap.keySet();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -100,3 +100,12 @@
|
||||
|
||||
Scale ^ 3 ^ (3/4)
|
||||
= (ThisWgt / TargetWgt) ^ (3/4)
|
||||
|
||||
|
||||
== (De)serialisation ==
|
||||
|
||||
* Custom binary + GSON
|
||||
|
||||
* Custom binary: Game map
|
||||
|
||||
* GSON: Actors, game configurations
|
||||
Reference in New Issue
Block a user