summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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));