summaryrefslogtreecommitdiffstats
path: root/core/src/ch
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2016-04-12 21:18:10 +0200
committerJérémy Zurcher <jeremy@asynk.ch>2016-04-12 21:18:10 +0200
commit165cc4ebe9ec2fbcc8726461522a6dc06219a803 (patch)
tree5d3755d9d26ef07a59936901a05539915423bf70 /core/src/ch
parentcfda2d8f300c672b4d73ad79df3f20888965815d (diff)
downloadRustAndDust-165cc4ebe9ec2fbcc8726461522a6dc06219a803.zip
RustAndDust-165cc4ebe9ec2fbcc8726461522a6dc06219a803.tar.gz
Unit: id is private
Diffstat (limited to 'core/src/ch')
-rw-r--r--core/src/ch/asynk/rustanddust/game/Unit.java11
-rw-r--r--core/src/ch/asynk/rustanddust/game/map/Map5Marshal.java20
2 files changed, 17 insertions, 14 deletions
diff --git a/core/src/ch/asynk/rustanddust/game/Unit.java b/core/src/ch/asynk/rustanddust/game/Unit.java
index 7894f81..1efb607 100644
--- a/core/src/ch/asynk/rustanddust/game/Unit.java
+++ b/core/src/ch/asynk/rustanddust/game/Unit.java
@@ -23,7 +23,7 @@ public class Unit extends HeadedPawn
public static final int FLANK_ATTACK_BONUS = 1;
- public static int unit_id = 1;
+ public static int unitId = 1;
public enum UnitType implements Pawn.PawnType
{
@@ -54,12 +54,12 @@ public class Unit extends HeadedPawn
public String toString() { return s; }
}
+ private int id;
public int rng;
public int def;
public int cdef;
public int mp;
public int mpLeft;
- public int id;
public UnitCode code;
public UnitType type;
public boolean hq;
@@ -74,8 +74,8 @@ public class Unit extends HeadedPawn
super(army, chit, body, turret, overlays);
hq = false;
ace = false;
- this.id = unit_id;
- unit_id += 1;
+ this.id = unitId;
+ unitId += 1;
this.entryZone = null;
this.exitZone = null;
}
@@ -114,6 +114,9 @@ public class Unit extends HeadedPawn
commonSetup();
}
+ public int id() { return id; }
+ public void id(int i) { id = i; updateDescr(); }
+
public Army getArmy()
{
return (Army) getFaction();
diff --git a/core/src/ch/asynk/rustanddust/game/map/Map5Marshal.java b/core/src/ch/asynk/rustanddust/game/map/Map5Marshal.java
index f13951d..9b51790 100644
--- a/core/src/ch/asynk/rustanddust/game/map/Map5Marshal.java
+++ b/core/src/ch/asynk/rustanddust/game/map/Map5Marshal.java
@@ -82,7 +82,7 @@ public abstract class Map5Marshal extends Map4Orders implements Marshal
private void unloadUnit(Json json, Unit unit, boolean pos)
{
json.writeObjectStart();
- json.writeValue("id", unit.id);
+ json.writeValue("id", unit.id());
json.writeValue("code", unit.code);
json.writeArrayStart("v");
json.writeValue(unit.hq);
@@ -174,7 +174,7 @@ public abstract class Map5Marshal extends Map4Orders implements Marshal
if (o.activable.size() > 0) {
json.writeArrayStart("a");
for(Unit u : o.activable)
- json.writeValue(u.id);
+ json.writeValue(u.id());
json.writeArrayEnd();
}
json.writeObjectEnd();
@@ -185,7 +185,7 @@ public abstract class Map5Marshal extends Map4Orders implements Marshal
private void unloadMoveOrder(Json json, Move m)
{
json.writeValue("mType", m.type);
- json.writeValue("id", ((Unit) m.pawn).id);
+ json.writeValue("id", ((Unit) m.pawn).id());
if (m.from != null) {
json.writeArrayStart("from");
json.writeValue(m.from.getCol());
@@ -214,12 +214,12 @@ public abstract class Map5Marshal extends Map4Orders implements Marshal
private void unloadEngageOrder(Json json, Engagement e)
{
json.writeArrayStart("u");
- json.writeValue(e.attacker.id);
- json.writeValue(e.defender.id);
+ json.writeValue(e.attacker.id());
+ json.writeValue(e.defender.id());
json.writeArrayEnd();
json.writeArrayStart("us");
for (Unit u : e.assists)
- json.writeValue(u.id);
+ json.writeValue(u.id());
json.writeArrayEnd();
json.writeArrayStart("d");
json.writeValue(e.d1);
@@ -241,7 +241,7 @@ public abstract class Map5Marshal extends Map4Orders implements Marshal
private void unloadPromoteOrder(Json json, Unit u)
{
- json.writeValue("id", u.id);
+ json.writeValue("id", u.id());
}
private void unloadUnit(Json json, String key, Unit u)
@@ -253,7 +253,7 @@ public abstract class Map5Marshal extends Map4Orders implements Marshal
{
if (key != null) json.writeObjectStart(key);
else json.writeObjectStart();
- json.writeValue("id", u.id);
+ json.writeValue("id", u.id());
Hex h = u.getHex();
if (pos && (h != null)) {
json.writeArrayStart("p");
@@ -319,7 +319,7 @@ public abstract class Map5Marshal extends Map4Orders implements Marshal
if (i != -1) u.entryZone = entryZones.get(i);
i = a.getInt(5);
if (i != -1) u.exitZone = exitZones.get(i);
- u.id = unitId;
+ u.id(unitId);
if (pos) {
a = v.get("p");
Hex h = getHex(a.getInt(0), a.getInt(1));
@@ -478,7 +478,7 @@ public abstract class Map5Marshal extends Map4Orders implements Marshal
private static Unit findById(int id)
{
for (Unit u : units) {
- if (u.id == id)
+ if (u.id() == id)
return u;
}
RustAndDust.error(String.format("loadPromoteOrder: unable to find unit %d", id));