diff --git a/out/production/Terrarum_renewed/com/Torvald/ColourUtil/HSVUtil.class b/out/production/Terrarum_renewed/com/Torvald/ColourUtil/HSVUtil.class index b43ccff97..5010a249d 100644 Binary files a/out/production/Terrarum_renewed/com/Torvald/ColourUtil/HSVUtil.class and b/out/production/Terrarum_renewed/com/Torvald/ColourUtil/HSVUtil.class differ diff --git a/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/ActorInventory.class b/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/ActorInventory.class index d173b1c06..e9118fca3 100644 Binary files a/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/ActorInventory.class and b/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/ActorInventory.class differ diff --git a/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/ActorValue.class b/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/ActorValue.class index 348d193f4..fc6d024cb 100644 Binary files a/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/ActorValue.class and b/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/ActorValue.class differ diff --git a/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/ActorWithBody.class b/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/ActorWithBody.class index d24eaab99..adb1057e0 100644 Binary files a/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/ActorWithBody.class and b/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/ActorWithBody.class differ diff --git a/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/NPCIntelligentBase$1.class b/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/NPCIntelligentBase$1.class index 4a3c50cf9..5b43492b9 100644 Binary files a/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/NPCIntelligentBase$1.class and b/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/NPCIntelligentBase$1.class differ diff --git a/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/NPCIntelligentBase.class b/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/NPCIntelligentBase.class index e8be17dee..f4e1e88b6 100644 Binary files a/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/NPCIntelligentBase.class and b/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/NPCIntelligentBase.class differ diff --git a/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/PBFSigrid.class b/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/PBFSigrid.class index 9c496f9e1..dd6a3d1df 100644 Binary files a/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/PBFSigrid.class and b/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/PBFSigrid.class differ diff --git a/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/Player.class b/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/Player.class index ee24d1984..e31cdfd63 100644 Binary files a/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/Player.class and b/out/production/Terrarum_renewed/com/Torvald/Terrarum/Actors/Player.class differ diff --git a/out/production/Terrarum_renewed/com/Torvald/Terrarum/ConsoleCommand/CodexEdictis.class b/out/production/Terrarum_renewed/com/Torvald/Terrarum/ConsoleCommand/CodexEdictis.class index 33b5ac130..f8cbcefe0 100644 Binary files a/out/production/Terrarum_renewed/com/Torvald/Terrarum/ConsoleCommand/CodexEdictis.class and b/out/production/Terrarum_renewed/com/Torvald/Terrarum/ConsoleCommand/CodexEdictis.class differ diff --git a/out/production/Terrarum_renewed/com/Torvald/Terrarum/ConsoleCommand/CommandDict.class b/out/production/Terrarum_renewed/com/Torvald/Terrarum/ConsoleCommand/CommandDict.class index 2263a9795..c02ba3e5a 100644 Binary files a/out/production/Terrarum_renewed/com/Torvald/Terrarum/ConsoleCommand/CommandDict.class and b/out/production/Terrarum_renewed/com/Torvald/Terrarum/ConsoleCommand/CommandDict.class differ diff --git a/out/production/Terrarum_renewed/com/Torvald/Terrarum/ConsoleCommand/GetAV.class b/out/production/Terrarum_renewed/com/Torvald/Terrarum/ConsoleCommand/GetAV.class index 692e95445..c27084b51 100644 Binary files a/out/production/Terrarum_renewed/com/Torvald/Terrarum/ConsoleCommand/GetAV.class and b/out/production/Terrarum_renewed/com/Torvald/Terrarum/ConsoleCommand/GetAV.class differ diff --git a/out/production/Terrarum_renewed/com/Torvald/Terrarum/ConsoleCommand/GetFactioning.class b/out/production/Terrarum_renewed/com/Torvald/Terrarum/ConsoleCommand/GetFactioning.class index 549c1548f..8030070ae 100644 Binary files a/out/production/Terrarum_renewed/com/Torvald/Terrarum/ConsoleCommand/GetFactioning.class and b/out/production/Terrarum_renewed/com/Torvald/Terrarum/ConsoleCommand/GetFactioning.class differ diff --git a/out/production/Terrarum_renewed/com/Torvald/Terrarum/Game.class b/out/production/Terrarum_renewed/com/Torvald/Terrarum/Game.class index 4cc538e7e..8739c8a87 100644 Binary files a/out/production/Terrarum_renewed/com/Torvald/Terrarum/Game.class and b/out/production/Terrarum_renewed/com/Torvald/Terrarum/Game.class differ diff --git a/out/production/Terrarum_renewed/com/Torvald/Terrarum/GameConfig.class b/out/production/Terrarum_renewed/com/Torvald/Terrarum/GameConfig.class index 2d92adb8f..3ead73d33 100644 Binary files a/out/production/Terrarum_renewed/com/Torvald/Terrarum/GameConfig.class and b/out/production/Terrarum_renewed/com/Torvald/Terrarum/GameConfig.class differ diff --git a/out/production/Terrarum_renewed/com/Torvald/Terrarum/GameItem/InventoryItem.class b/out/production/Terrarum_renewed/com/Torvald/Terrarum/GameItem/InventoryItem.class index c120d386d..1d9123e5b 100644 Binary files a/out/production/Terrarum_renewed/com/Torvald/Terrarum/GameItem/InventoryItem.class and b/out/production/Terrarum_renewed/com/Torvald/Terrarum/GameItem/InventoryItem.class differ diff --git a/out/production/Terrarum_renewed/com/Torvald/Terrarum/GameItem/ItemCodex.class b/out/production/Terrarum_renewed/com/Torvald/Terrarum/GameItem/ItemCodex.class new file mode 100644 index 000000000..f741d7d72 Binary files /dev/null and b/out/production/Terrarum_renewed/com/Torvald/Terrarum/GameItem/ItemCodex.class differ diff --git a/out/production/Terrarum_renewed/com/Torvald/Terrarum/GameMap/GameMap.class b/out/production/Terrarum_renewed/com/Torvald/Terrarum/GameMap/GameMap.class index dd675bac6..313157133 100644 Binary files a/out/production/Terrarum_renewed/com/Torvald/Terrarum/GameMap/GameMap.class and b/out/production/Terrarum_renewed/com/Torvald/Terrarum/GameMap/GameMap.class differ diff --git a/out/production/Terrarum_renewed/com/Torvald/Terrarum/GameMap/MapLayer$1.class b/out/production/Terrarum_renewed/com/Torvald/Terrarum/GameMap/MapLayer$1.class index 0a91bfa1d..d71e19445 100644 Binary files a/out/production/Terrarum_renewed/com/Torvald/Terrarum/GameMap/MapLayer$1.class and b/out/production/Terrarum_renewed/com/Torvald/Terrarum/GameMap/MapLayer$1.class differ diff --git a/out/production/Terrarum_renewed/com/Torvald/Terrarum/GameMap/MapLayer.class b/out/production/Terrarum_renewed/com/Torvald/Terrarum/GameMap/MapLayer.class index 61b4276a1..03158fb50 100644 Binary files a/out/production/Terrarum_renewed/com/Torvald/Terrarum/GameMap/MapLayer.class and b/out/production/Terrarum_renewed/com/Torvald/Terrarum/GameMap/MapLayer.class differ diff --git a/out/production/Terrarum_renewed/com/Torvald/Terrarum/GameMap/MapPoint.class b/out/production/Terrarum_renewed/com/Torvald/Terrarum/GameMap/MapPoint.class index bc1dc4194..64982fd41 100644 Binary files a/out/production/Terrarum_renewed/com/Torvald/Terrarum/GameMap/MapPoint.class and b/out/production/Terrarum_renewed/com/Torvald/Terrarum/GameMap/MapPoint.class differ diff --git a/out/production/Terrarum_renewed/com/Torvald/Terrarum/GameMap/PairedMapLayer$1.class b/out/production/Terrarum_renewed/com/Torvald/Terrarum/GameMap/PairedMapLayer$1.class index 8ef476810..26d57bf82 100644 Binary files a/out/production/Terrarum_renewed/com/Torvald/Terrarum/GameMap/PairedMapLayer$1.class and b/out/production/Terrarum_renewed/com/Torvald/Terrarum/GameMap/PairedMapLayer$1.class differ diff --git a/out/production/Terrarum_renewed/com/Torvald/Terrarum/GameMap/PairedMapLayer.class b/out/production/Terrarum_renewed/com/Torvald/Terrarum/GameMap/PairedMapLayer.class index c323bd3f8..58345670b 100644 Binary files a/out/production/Terrarum_renewed/com/Torvald/Terrarum/GameMap/PairedMapLayer.class and b/out/production/Terrarum_renewed/com/Torvald/Terrarum/GameMap/PairedMapLayer.class differ diff --git a/out/production/Terrarum_renewed/com/Torvald/Terrarum/GameMap/WorldTime.class b/out/production/Terrarum_renewed/com/Torvald/Terrarum/GameMap/WorldTime.class index d6e0e95b2..e3045e91c 100644 Binary files a/out/production/Terrarum_renewed/com/Torvald/Terrarum/GameMap/WorldTime.class and b/out/production/Terrarum_renewed/com/Torvald/Terrarum/GameMap/WorldTime.class differ diff --git a/out/production/Terrarum_renewed/com/Torvald/Terrarum/KVHashMap.class b/out/production/Terrarum_renewed/com/Torvald/Terrarum/KVHashMap.class new file mode 100644 index 000000000..2812a4842 Binary files /dev/null and b/out/production/Terrarum_renewed/com/Torvald/Terrarum/KVHashMap.class differ diff --git a/out/production/Terrarum_renewed/com/Torvald/Terrarum/KVHashtable.class b/out/production/Terrarum_renewed/com/Torvald/Terrarum/KVHashtable.class deleted file mode 100644 index 8754597b3..000000000 Binary files a/out/production/Terrarum_renewed/com/Torvald/Terrarum/KVHashtable.class and /dev/null differ diff --git a/out/production/Terrarum_renewed/com/Torvald/Terrarum/MECHNANICS b/out/production/Terrarum_renewed/com/Torvald/Terrarum/MECHNANICS index 87969412c..f895ceb58 100644 --- a/out/production/Terrarum_renewed/com/Torvald/Terrarum/MECHNANICS +++ b/out/production/Terrarum_renewed/com/Torvald/Terrarum/MECHNANICS @@ -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 \ No newline at end of file diff --git a/out/production/Terrarum_renewed/com/Torvald/Terrarum/MapGenerator/MapGenerator.class b/out/production/Terrarum_renewed/com/Torvald/Terrarum/MapGenerator/MapGenerator.class index 59eb50be6..fff906ed6 100644 Binary files a/out/production/Terrarum_renewed/com/Torvald/Terrarum/MapGenerator/MapGenerator.class and b/out/production/Terrarum_renewed/com/Torvald/Terrarum/MapGenerator/MapGenerator.class differ diff --git a/res/graphics/fonts/han_johab.png b/res/graphics/fonts/han_johab.png index 11bc3ca03..9d1cff0f3 100644 Binary files a/res/graphics/fonts/han_johab.png and b/res/graphics/fonts/han_johab.png differ diff --git a/src/com/Torvald/ColourUtil/HSVUtil.java b/src/com/Torvald/ColourUtil/HSVUtil.java index 14fcb2a87..9a79a1108 100644 --- a/src/com/Torvald/ColourUtil/HSVUtil.java +++ b/src/com/Torvald/ColourUtil/HSVUtil.java @@ -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); diff --git a/src/com/Torvald/Terrarum/Actors/Actor.java b/src/com/Torvald/Terrarum/Actors/Actor.java index ad40e3602..54a60be02 100644 --- a/src/com/Torvald/Terrarum/Actors/Actor.java +++ b/src/com/Torvald/Terrarum/Actors/Actor.java @@ -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(); } diff --git a/src/com/Torvald/Terrarum/Actors/ActorInventory.java b/src/com/Torvald/Terrarum/Actors/ActorInventory.java index 63ecd2e70..c7d0ad062 100644 --- a/src/com/Torvald/Terrarum/Actors/ActorInventory.java +++ b/src/com/Torvald/Terrarum/Actors/ActorInventory.java @@ -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 pocket; + /** + * <ReferenceID, Amounts> + */ + private HashMap 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 getPocket() { - return pocket; + public Map getItemList() { + return itemList; } /** - * Get clone of the pocket + * Get clone of the itemList * @return */ - public LinkedList getCopyOfPocket() { - return (LinkedList) (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 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 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() { diff --git a/src/com/Torvald/Terrarum/Actors/ActorValue.java b/src/com/Torvald/Terrarum/Actors/ActorValue.java index 45a5ba5f3..9b8640b24 100644 --- a/src/com/Torvald/Terrarum/Actors/ActorValue.java +++ b/src/com/Torvald/Terrarum/Actors/ActorValue.java @@ -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 { } diff --git a/src/com/Torvald/Terrarum/Actors/ActorWithBody.java b/src/com/Torvald/Terrarum/Actors/ActorWithBody.java index 36259a6db..8b9b11402 100644 --- a/src/com/Torvald/Terrarum/Actors/ActorWithBody.java +++ b/src/com/Torvald/Terrarum/Actors/ActorWithBody.java @@ -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]."); diff --git a/src/com/Torvald/Terrarum/Actors/NPCIntelligentBase.java b/src/com/Torvald/Terrarum/Actors/NPCIntelligentBase.java index 9d597c374..eae22f103 100644 --- a/src/com/Torvald/Terrarum/Actors/NPCIntelligentBase.java +++ b/src/com/Torvald/Terrarum/Actors/NPCIntelligentBase.java @@ -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 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) { diff --git a/src/com/Torvald/Terrarum/Actors/Player.java b/src/com/Torvald/Terrarum/Actors/Player.java index 5a1ad88b1..a3105a511 100644 --- a/src/com/Torvald/Terrarum/Actors/Player.java +++ b/src/com/Torvald/Terrarum/Actors/Player.java @@ -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 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); } /** diff --git a/src/com/Torvald/Terrarum/ConsoleCommand/CommandDict.java b/src/com/Torvald/Terrarum/ConsoleCommand/CommandDict.java index ab937301a..4041c2781 100644 --- a/src/com/Torvald/Terrarum/ConsoleCommand/CommandDict.java +++ b/src/com/Torvald/Terrarum/ConsoleCommand/CommandDict.java @@ -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 dict; + protected static HashMap dict; public CommandDict() { - dict = new Hashtable<>(); + dict = new HashMap<>(); dict.put("echo", new Echo()); dict.put("setav", new SetAV()); diff --git a/src/com/Torvald/Terrarum/GameConfig.java b/src/com/Torvald/Terrarum/GameConfig.java index d6cdf9d14..94572d996 100644 --- a/src/com/Torvald/Terrarum/GameConfig.java +++ b/src/com/Torvald/Terrarum/GameConfig.java @@ -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 { } diff --git a/src/com/Torvald/Terrarum/GameItem/InventoryItem.java b/src/com/Torvald/Terrarum/GameItem/InventoryItem.java index 2ce8e2a1e..bc3707c40 100644 --- a/src/com/Torvald/Terrarum/GameItem/InventoryItem.java +++ b/src/com/Torvald/Terrarum/GameItem/InventoryItem.java @@ -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 diff --git a/src/com/Torvald/Terrarum/GameItem/ItemCodex.java b/src/com/Torvald/Terrarum/GameItem/ItemCodex.java new file mode 100644 index 000000000..88c6b312d --- /dev/null +++ b/src/com/Torvald/Terrarum/GameItem/ItemCodex.java @@ -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 itemCodex; + + public static InventoryItem getItem(long code) { + return itemCodex.get(code); + } + +} diff --git a/src/com/Torvald/Terrarum/GameMap/GameMap.java b/src/com/Torvald/Terrarum/GameMap/GameMap.java index df40988b5..877df4432 100644 --- a/src/com/Torvald/Terrarum/GameMap/GameMap.java +++ b/src/com/Torvald/Terrarum/GameMap/GameMap.java @@ -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 diff --git a/src/com/Torvald/Terrarum/GameMap/MapLayer.java b/src/com/Torvald/Terrarum/GameMap/MapLayer.java index 039c0e297..203abc6ac 100644 --- a/src/com/Torvald/Terrarum/GameMap/MapLayer.java +++ b/src/com/Torvald/Terrarum/GameMap/MapLayer.java @@ -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 { 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; diff --git a/src/com/Torvald/Terrarum/GameMap/MapPoint.java b/src/com/Torvald/Terrarum/GameMap/MapPoint.java index ec79e51a2..8b1a134dd 100644 --- a/src/com/Torvald/Terrarum/GameMap/MapPoint.java +++ b/src/com/Torvald/Terrarum/GameMap/MapPoint.java @@ -2,6 +2,8 @@ package com.Torvald.Terrarum.GameMap; import com.Torvald.Point.Point2f; +import java.io.Serializable; + public class MapPoint { private Point2f startPoint; diff --git a/src/com/Torvald/Terrarum/GameMap/PairedMapLayer.java b/src/com/Torvald/Terrarum/GameMap/PairedMapLayer.java index 68e0ba00c..107942ca8 100644 --- a/src/com/Torvald/Terrarum/GameMap/PairedMapLayer.java +++ b/src/com/Torvald/Terrarum/GameMap/PairedMapLayer.java @@ -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 { 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; diff --git a/src/com/Torvald/Terrarum/GameMap/WorldTime.java b/src/com/Torvald/Terrarum/GameMap/WorldTime.java index 2e1c4da69..0962fd507 100644 --- a/src/com/Torvald/Terrarum/GameMap/WorldTime.java +++ b/src/com/Torvald/Terrarum/GameMap/WorldTime.java @@ -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++; + } + } } \ No newline at end of file diff --git a/src/com/Torvald/Terrarum/KVHashtable.java b/src/com/Torvald/Terrarum/KVHashMap.java similarity index 78% rename from src/com/Torvald/Terrarum/KVHashtable.java rename to src/com/Torvald/Terrarum/KVHashMap.java index 5f1cb2204..32490546a 100644 --- a/src/com/Torvald/Terrarum/KVHashtable.java +++ b/src/com/Torvald/Terrarum/KVHashMap.java @@ -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 hashtable; + private HashMap 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(); } } \ No newline at end of file diff --git a/src/com/Torvald/Terrarum/MECHNANICS b/src/com/Torvald/Terrarum/MECHNANICS index 87969412c..f895ceb58 100644 --- a/src/com/Torvald/Terrarum/MECHNANICS +++ b/src/com/Torvald/Terrarum/MECHNANICS @@ -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 \ No newline at end of file