From fa7d0362c796b43e9706ac30f63fb4889990ce13 Mon Sep 17 00:00:00 2001 From: Samy Avrillon Date: Thu, 31 Oct 2024 16:23:49 +0100 Subject: [PATCH] Added Town Objectives --- build.gradle | 3 +- .../greposimu/model/game/Building.java | 96 ++++++--- .../greposimu/model/game/GameConfig.java | 37 ++++ .../greposimu/model/game/GrepoYaml.java | 78 +++++++ .../greposimu/model/game/UnitResources.java | 28 +++ .../model/game/queues/BuildingQueueItem.java | 55 +++++ .../model/game/queues/QueueItem.java | 5 + .../game/queues/RecruitmentQueueItem.java | 43 ++++ .../model/game/queues/ResearchQueueItem.java | 44 ++++ .../greposimu/model/game/units/Unit.java | 5 + .../greposimu/model/runtime/Timestamp.java | 5 + .../greposimu/model/runtime/Ville.java | 4 +- .../greposimu/model/simulator/Joueureuse.java | 70 +++++++ .../greposimu/model/simulator/Movements.java | 23 +++ .../model/simulator/SimulatorData.java | 25 +++ .../greposimu/model/simulator/Troupes.java | 33 ++- .../greposimu/model/simulator/Ville.java | 157 +++++++++++++- .../model/simulator/command/BuildCommand.java | 31 +++ .../model/simulator/command/Command.java | 5 + .../simulator/command/HideStoreCommand.java | 17 ++ .../simulator/command/RecruitCommand.java | 23 +++ .../simulator/command/ResearchCommand.java | 25 +++ .../model/simulator/command/TownCommand.java | 11 + .../simulator/objective/TownObjective.java | 132 ++++++++++++ .../bernard/greposimu/source/JSONSourcer.java | 183 +++++++++++++++++ .../source/SourcedBuildingOrder.java | 46 +++++ .../greposimu/source/SourcedCastedPower.java | 37 ++++ .../greposimu/source/SourcedCelebration.java | 18 ++ .../bernard/greposimu/source/SourcedData.java | 40 ++++ .../source/SourcedFavRessources.java | 31 +++ .../source/SourcedMilitaryOrders.java | 51 +++++ .../greposimu/source/SourcedMilitiaTimes.java | 13 ++ .../source/SourcedRecruitmentOrder.java | 49 +++++ .../source/SourcedResearchOrder.java | 31 +++ .../greposimu/source/SourcedRessources.java | 22 ++ .../bernard/greposimu/source/SourcedTown.java | 95 +++++++++ .../source/SourcedTownResources.java | 39 ++++ .../greposimu/source/SourcedTrades.java | 66 ++++++ .../greposimu/source/SourcedUnits.java | 23 +++ src/main/resources/greposource.js | 192 +++++++++++++++++- .../greposimu/GrepoSimuApplicationTests.java | 71 ++++++- src/test/resources/objectives.yml | 67 ++++++ 42 files changed, 1980 insertions(+), 49 deletions(-) create mode 100644 src/main/java/com/bernard/greposimu/model/game/GrepoYaml.java create mode 100644 src/main/java/com/bernard/greposimu/model/game/UnitResources.java create mode 100644 src/main/java/com/bernard/greposimu/model/game/queues/BuildingQueueItem.java create mode 100644 src/main/java/com/bernard/greposimu/model/game/queues/QueueItem.java create mode 100644 src/main/java/com/bernard/greposimu/model/game/queues/RecruitmentQueueItem.java create mode 100644 src/main/java/com/bernard/greposimu/model/game/queues/ResearchQueueItem.java create mode 100644 src/main/java/com/bernard/greposimu/model/simulator/Movements.java create mode 100644 src/main/java/com/bernard/greposimu/model/simulator/SimulatorData.java create mode 100644 src/main/java/com/bernard/greposimu/model/simulator/command/BuildCommand.java create mode 100644 src/main/java/com/bernard/greposimu/model/simulator/command/Command.java create mode 100644 src/main/java/com/bernard/greposimu/model/simulator/command/HideStoreCommand.java create mode 100644 src/main/java/com/bernard/greposimu/model/simulator/command/RecruitCommand.java create mode 100644 src/main/java/com/bernard/greposimu/model/simulator/command/ResearchCommand.java create mode 100644 src/main/java/com/bernard/greposimu/model/simulator/command/TownCommand.java create mode 100644 src/main/java/com/bernard/greposimu/model/simulator/objective/TownObjective.java create mode 100644 src/main/java/com/bernard/greposimu/source/JSONSourcer.java create mode 100644 src/main/java/com/bernard/greposimu/source/SourcedBuildingOrder.java create mode 100644 src/main/java/com/bernard/greposimu/source/SourcedCastedPower.java create mode 100644 src/main/java/com/bernard/greposimu/source/SourcedCelebration.java create mode 100644 src/main/java/com/bernard/greposimu/source/SourcedData.java create mode 100644 src/main/java/com/bernard/greposimu/source/SourcedFavRessources.java create mode 100644 src/main/java/com/bernard/greposimu/source/SourcedMilitaryOrders.java create mode 100644 src/main/java/com/bernard/greposimu/source/SourcedMilitiaTimes.java create mode 100644 src/main/java/com/bernard/greposimu/source/SourcedRecruitmentOrder.java create mode 100644 src/main/java/com/bernard/greposimu/source/SourcedResearchOrder.java create mode 100644 src/main/java/com/bernard/greposimu/source/SourcedRessources.java create mode 100644 src/main/java/com/bernard/greposimu/source/SourcedTown.java create mode 100644 src/main/java/com/bernard/greposimu/source/SourcedTownResources.java create mode 100644 src/main/java/com/bernard/greposimu/source/SourcedTrades.java create mode 100644 src/main/java/com/bernard/greposimu/source/SourcedUnits.java create mode 100644 src/test/resources/objectives.yml diff --git a/build.gradle b/build.gradle index fac5353..13f73f5 100644 --- a/build.gradle +++ b/build.gradle @@ -25,11 +25,10 @@ dependencies { developmentOnly 'org.springframework.boot:spring-boot-devtools' testImplementation 'org.springframework.boot:spring-boot-starter-test' - implementation 'org.yaml:snakeyaml:2.2' implementation 'org.ojalgo:ojalgo:54.0.0' implementation 'com.fasterxml.jackson.core:jackson-databind:2.17.1' + implementation 'com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.17.1' implementation 'org.json:json:20240303' - } tasks.named('test') { diff --git a/src/main/java/com/bernard/greposimu/model/game/Building.java b/src/main/java/com/bernard/greposimu/model/game/Building.java index 657d743..ca03f34 100644 --- a/src/main/java/com/bernard/greposimu/model/game/Building.java +++ b/src/main/java/com/bernard/greposimu/model/game/Building.java @@ -1,26 +1,76 @@ package com.bernard.greposimu.model.game; -public enum Building { - AGORA, - SENAT, - SCIERIE, - FERME, - CARRIERE, - ENTREPOT, - MINE, - CASERNE, - TEMPLE, - MARCHE, - PORT, - ACADEMIE, - REMPARTS, - GROTTE, - THEATRE, - THERMES, - BIBLIOTHEQUE, - PHARE, - TOUR, - STATUE, - ORACLE, - COMPTOIR; +import java.util.Map; + +public enum Building implements Identified{ + + /* + * var s = "" + for(var b in GameData.buildings){ + var bb = GameData.buildings[b]; + s += b.toUpperCase()+'("'+b+'",'+bb.resources.wood+","+bb.wood_factor+","+bb.resources.stone+","+bb.stone_factor+","+bb.resources.iron+","+bb.iron_factor+","+bb.pop+","+bb.pop_factor+","+bb.points+","+bb.points_factor+bb.build_time+","+bb.build_time_factor+","+bb.build_time_reduction+"),\n"; + } + */ + MAIN("main",6.0,2.15,2.0,2.53,2.0,2.3,1.0,1.5,100.0,1.1300,1.8,0.3,25), + HIDE("hide",200.0,1.3,400.0,1,700.0,0.9,3.0,0.5,50.0,1.2420,1.456,0,10), + PLACE("place",10.0,2,0.0,2,0.0,2,1.0,0,30.0,1.111,2.17,0,1), + LUMBER("lumber",2.6,1.9,2.0,2.1,1.49,2.1,1.0,1.25,20.0,1.1120,1.9,1,40), + STONER("stoner",1.3,2.1,2.6,1.9,2.4,2.1,1.0,1.25,20.0,1.1300,1.62,1,40), + IRONER("ironer",5.0,1.9,2.0,2,4.0,1.8,1.0,1.25,20.0,1.1600,1.41,0.5,40), + MARKET("market",50.0,1.48,20.0,1.62,5.0,1.98,2.0,1.1,100.0,1.08480,1.6,0.4,30), + DOCKS("docks",400.0,0.9,200.0,0.98,100.0,1.1,4.0,1,60.0,1.11500,1.1,0,30), + BARRACKS("barracks",70.0,1.22,20.0,1.67,40.0,1.54,1.0,1.3,30.0,1.115900,1.25,0.5,30), + WALL("wall",400.0,0,350.0,1,200.0,1.1,2.0,1.16,30.0,1.12900,1.3,0,25), + STORAGE("storage",35.0,1.52,55.0,1.52,15.0,1.66,0.0,1,13.0,1.141800,1.23,0.4,35), + FARM("farm",8.0,1.87,5.0,2.03,1.0,2.4,0.0,0,15.0,1.12300,1.7,1,45), + ACADEMY("academy",100.0,1.21,200.0,1.1,120.0,1.2,3.0,1,60.0,1.121200,1.25,0,36), + TEMPLE("temple",500.0,0.865,900.0,0.7,600.0,0.82,5.0,1,200.0,1.083600,1.145,0,30), + THEATER("theater",8000.0,2,8000.0,2,8000.0,2,60.0,1,500.0,164800,2.17,0,1), + THERMAL("thermal",9000.0,2,6000.0,2,9000.0,2,60.0,1,500.0,164800,2.17,0,1), + LIBRARY("library",9500.0,2,7500.0,2,7000.0,2,60.0,1,500.0,164800,2.17,0,1), + LIGHTHOUSE("lighthouse",6000.0,2,10000.0,2,8000.0,2,60.0,1,500.0,164800.0,2.17,0,1), + TOWER("tower",8000.0,2,10000.0,2,6000.0,2,60.0,1,500.0,164800.0,2.17,0,1), + STATUE("statue",6000.0,2,10500.0,2,7500.0,2,60.0,1,500.0,164800.0,2.17,0,1), + ORACLE("oracle",6500.0,2,7000.0,2,9500.0,2,60.0,1,500.0,164800.0,2.17,0,1), + TRADE_OFFICE("trade_office",10500.0,2,7000.0,2,6500.0,2,60.0,1,500.0,164800.0,1,0,1); + + String id; + + private double wood0,woodF,stone0,stoneF,iron0,ironF,pop0,popF,pts0,ptsF,build0,buildF,buildR; + int maxLevel; + + private Building(String id, double wood0, double woodF, double stone0, double stoneF, double iron0, double ironF, + double pop0, double popF, double pts0, double ptsF, double build0, double buildF, int maxLevel) { + this.id = id; + this.wood0 = wood0; + this.woodF = woodF; + this.stone0 = stone0; + this.stoneF = stoneF; + this.iron0 = iron0; + this.ironF = ironF; + this.pop0 = pop0; + this.popF = popF; + this.pts0 = pts0; + this.ptsF = ptsF; + this.build0 = build0; + this.buildF = buildF; + this.maxLevel = maxLevel; + } + + @Override + public String getId() { + return id; + } + + public static int getFarmPopulation(int farm) { + return (int) Math.floor(Math.pow(farm, 1.455)*14); + } + + public int getRequiredPop(int level) { + return (int) Math.floor(pop0*Math.pow(level, popF)); + } + + public int popInBuildings(Map buildings) { + return buildings.entrySet().stream().mapToInt(e -> e.getKey().getRequiredPop(e.getValue())).sum(); + } } diff --git a/src/main/java/com/bernard/greposimu/model/game/GameConfig.java b/src/main/java/com/bernard/greposimu/model/game/GameConfig.java index ddab664..44d43b9 100644 --- a/src/main/java/com/bernard/greposimu/model/game/GameConfig.java +++ b/src/main/java/com/bernard/greposimu/model/game/GameConfig.java @@ -1,5 +1,6 @@ package com.bernard.greposimu.model.game; +import java.util.Arrays; import java.util.Collections; import java.util.Set; @@ -57,5 +58,41 @@ public class GameConfig { public Research getResearch(String id) { return Utils.getIdentified(this.researches, id); } + + public Building getBuilding(String bid) { + return Arrays.stream(Building.values()).filter(b -> b.id.equals(bid)).findAny().orElse(null); + } + + public God getGod(String god) { + return Utils.getIdentified(this.gods, god); + } + + public Set getBuildings() { + return Set.of(Building.values()); + } + + @SuppressWarnings("unchecked") + public T getIdentified(Class clazz, String id) { + if(Unit.class.isAssignableFrom(clazz)) + return (T)this.getUnit(id); + if(Hero.class.isAssignableFrom(clazz)) + return (T)this.getHero(id); + if(Research.class.isAssignableFrom(clazz)) + return (T)this.getResearch(id); + if(God.class.isAssignableFrom(clazz)) + return (T)this.getGod(id); + if(Building.class.isAssignableFrom(clazz)) + return (T)this.getBuilding(id); + throw new UnsupportedOperationException("Cannot get identified object of class "+clazz.getName()); + } + + public static int getTotalPop(int farmLevel, boolean thermal, boolean charrue, boolean pygmallion, int bonus) { + int tot = Building.getFarmPopulation(farmLevel); + if(thermal)tot = (int)Math.floor(tot*1.1); + if(charrue)tot += 200; + if(pygmallion)tot += 5*farmLevel; + tot += bonus; + return tot; + } } diff --git a/src/main/java/com/bernard/greposimu/model/game/GrepoYaml.java b/src/main/java/com/bernard/greposimu/model/game/GrepoYaml.java new file mode 100644 index 0000000..a5715af --- /dev/null +++ b/src/main/java/com/bernard/greposimu/model/game/GrepoYaml.java @@ -0,0 +1,78 @@ +package com.bernard.greposimu.model.game; + +import java.io.IOException; + +import com.bernard.greposimu.model.game.researches.Research; +import com.bernard.greposimu.model.game.units.Hero; +import com.bernard.greposimu.model.game.units.Unit; +import com.fasterxml.jackson.core.JacksonException; +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.JsonDeserializer; +import com.fasterxml.jackson.databind.JsonSerializer; +import com.fasterxml.jackson.databind.KeyDeserializer; +import com.fasterxml.jackson.databind.SerializerProvider; +import com.fasterxml.jackson.databind.module.SimpleModule; + +public class GrepoYaml extends SimpleModule { + + GameConfig gc; + + public GrepoYaml(GameConfig gc) { + this.gc = gc; + registerId(Unit.class); + registerId(Research.class); + registerId(Building.class); + registerId(God.class); + registerId(Hero.class); + } + + private void registerId(Class clazz){ + this.addSerializer(clazz, new IdSerializer()); + this.addKeySerializer(clazz, new IdKeySerializer()); + this.addDeserializer(clazz, new IdDeserializer(clazz)); + this.addKeyDeserializer(clazz, new IdKeyDeserializer(clazz)); + } + + public class IdSerializer extends JsonSerializer{ + @Override + public void serialize(T value, JsonGenerator gen, SerializerProvider serializers) throws IOException { + gen.writeString(value.getId()); + } + } + public class IdKeySerializer extends JsonSerializer{ + @Override + public void serialize(T value, JsonGenerator gen, SerializerProvider serializers) throws IOException { + gen.writeFieldName(value.getId()); + } + } + + public class IdDeserializer extends JsonDeserializer { + + Class clazz; + + public IdDeserializer(Class clazz) { + this.clazz = clazz; + } + + @Override + public T deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JacksonException { + String id = p.getText(); + return gc.getIdentified(clazz, id); + } + } + public class IdKeyDeserializer extends KeyDeserializer { + + Class clazz; + + public IdKeyDeserializer(Class clazz) { + this.clazz = clazz; + } + + @Override + public Object deserializeKey(String key, DeserializationContext ctxt) throws IOException { + return gc.getIdentified(clazz, key); + } + } +} diff --git a/src/main/java/com/bernard/greposimu/model/game/UnitResources.java b/src/main/java/com/bernard/greposimu/model/game/UnitResources.java new file mode 100644 index 0000000..040ff8f --- /dev/null +++ b/src/main/java/com/bernard/greposimu/model/game/UnitResources.java @@ -0,0 +1,28 @@ +package com.bernard.greposimu.model.game; + +public class UnitResources extends Resources { + + God god; + int favor; + + public UnitResources(int wood, int stone, int iron) { + super(wood, stone, iron); + this.god = null; + this.favor = 0; + } + + public UnitResources(int wood, int stone, int iron, God god, int favor) { + super(wood, stone, iron); + this.god = god; + this.favor = favor; + } + + public God getGod() { + return god; + } + public int getFavor() { + return favor; + } + + +} diff --git a/src/main/java/com/bernard/greposimu/model/game/queues/BuildingQueueItem.java b/src/main/java/com/bernard/greposimu/model/game/queues/BuildingQueueItem.java new file mode 100644 index 0000000..ba530fe --- /dev/null +++ b/src/main/java/com/bernard/greposimu/model/game/queues/BuildingQueueItem.java @@ -0,0 +1,55 @@ +package com.bernard.greposimu.model.game.queues; + +import com.bernard.greposimu.model.game.Building; +import com.bernard.greposimu.model.game.Resources; +import com.bernard.greposimu.model.runtime.Timestamp; + +public class BuildingQueueItem extends QueueItem { + + public BuildingQueueItem(long buildingTime, Building building, boolean tearingDown, Timestamp beginTime, + Timestamp endTime, Resources refund, Resources cost) { + this.buildingTime = buildingTime; + this.building = building; + this.tearingDown = tearingDown; + this.beginTime = beginTime; + this.endTime = endTime; + this.refund = refund; + this.cost = cost; + } + long buildingTime; + + // the building being built + Building building; + boolean tearingDown; + + Timestamp beginTime; + Timestamp endTime; + + Resources refund; + Resources cost; + + public long getBuildingTime() { + return buildingTime; + } + public Building getBuilding() { + return building; + } + public boolean isTearingDown() { + return tearingDown; + } + public Timestamp getBeginTime() { + return beginTime; + } + public Timestamp getEndTime() { + return endTime; + } + public Resources getRefund() { + return refund; + } + public Resources getCost() { + return cost; + } + + + +} diff --git a/src/main/java/com/bernard/greposimu/model/game/queues/QueueItem.java b/src/main/java/com/bernard/greposimu/model/game/queues/QueueItem.java new file mode 100644 index 0000000..ced527a --- /dev/null +++ b/src/main/java/com/bernard/greposimu/model/game/queues/QueueItem.java @@ -0,0 +1,5 @@ +package com.bernard.greposimu.model.game.queues; + +public class QueueItem { + +} diff --git a/src/main/java/com/bernard/greposimu/model/game/queues/RecruitmentQueueItem.java b/src/main/java/com/bernard/greposimu/model/game/queues/RecruitmentQueueItem.java new file mode 100644 index 0000000..85080b1 --- /dev/null +++ b/src/main/java/com/bernard/greposimu/model/game/queues/RecruitmentQueueItem.java @@ -0,0 +1,43 @@ +package com.bernard.greposimu.model.game.queues; + +import com.bernard.greposimu.model.game.UnitResources; +import com.bernard.greposimu.model.game.units.Unit; +import com.bernard.greposimu.model.runtime.Timestamp; + +public class RecruitmentQueueItem extends QueueItem { + + RecruitmentKind kind; + Unit unit; + + // Number of units requested + int count; + // Number of units that have been done + int done; + + + Timestamp beginTime; + Timestamp endTime; + + UnitResources refund; + UnitResources cost; + + + + public RecruitmentQueueItem(RecruitmentKind kind, Unit unit, int count, int done, Timestamp beginTime, + Timestamp endTime, UnitResources refund, UnitResources cost) { + this.kind = kind; + this.unit = unit; + this.count = count; + this.done = done; + this.beginTime = beginTime; + this.endTime = endTime; + this.refund = refund; + this.cost = cost; + } + + + + public static enum RecruitmentKind { + GROUND,NAVAL; + } +} diff --git a/src/main/java/com/bernard/greposimu/model/game/queues/ResearchQueueItem.java b/src/main/java/com/bernard/greposimu/model/game/queues/ResearchQueueItem.java new file mode 100644 index 0000000..550ef93 --- /dev/null +++ b/src/main/java/com/bernard/greposimu/model/game/queues/ResearchQueueItem.java @@ -0,0 +1,44 @@ +package com.bernard.greposimu.model.game.queues; + +import com.bernard.greposimu.model.game.Resources; +import com.bernard.greposimu.model.game.researches.Research; +import com.bernard.greposimu.model.runtime.Timestamp; + +public class ResearchQueueItem extends QueueItem { + + // the building being built + Research research; + + Timestamp beginTime; + Timestamp endTime; + + Resources refund; + + public ResearchQueueItem(Research research, Timestamp beginTime, Timestamp endTime, Resources refund) { + this.research = research; + this.beginTime = beginTime; + this.endTime = endTime; + this.refund = refund; + } + + public Research getResearch() { + return research; + } + + public Timestamp getBeginTime() { + return beginTime; + } + + public Timestamp getEndTime() { + return endTime; + } + + public Resources getRefund() { + return refund; + } + + + + + +} diff --git a/src/main/java/com/bernard/greposimu/model/game/units/Unit.java b/src/main/java/com/bernard/greposimu/model/game/units/Unit.java index 50fd105..1c865fc 100644 --- a/src/main/java/com/bernard/greposimu/model/game/units/Unit.java +++ b/src/main/java/com/bernard/greposimu/model/game/units/Unit.java @@ -92,4 +92,9 @@ public abstract class Unit implements Identified{ return !this.isGround(); } + @Override + public String toString() { + return name; + } + } diff --git a/src/main/java/com/bernard/greposimu/model/runtime/Timestamp.java b/src/main/java/com/bernard/greposimu/model/runtime/Timestamp.java index e881cdc..db17abc 100644 --- a/src/main/java/com/bernard/greposimu/model/runtime/Timestamp.java +++ b/src/main/java/com/bernard/greposimu/model/runtime/Timestamp.java @@ -3,5 +3,10 @@ package com.bernard.greposimu.model.runtime; public class Timestamp { long timestamp; + + public Timestamp(long timestamp) { + this.timestamp = timestamp; + } + } diff --git a/src/main/java/com/bernard/greposimu/model/runtime/Ville.java b/src/main/java/com/bernard/greposimu/model/runtime/Ville.java index 9318b6f..221cc98 100644 --- a/src/main/java/com/bernard/greposimu/model/runtime/Ville.java +++ b/src/main/java/com/bernard/greposimu/model/runtime/Ville.java @@ -1,5 +1,7 @@ package com.bernard.greposimu.model.runtime; +import java.util.Map; + import com.bernard.greposimu.model.game.Resources; public class Ville { @@ -13,6 +15,6 @@ public class Ville { Resources resources; - Map batiments + Map batiments; } diff --git a/src/main/java/com/bernard/greposimu/model/simulator/Joueureuse.java b/src/main/java/com/bernard/greposimu/model/simulator/Joueureuse.java index 9d888f5..686303a 100644 --- a/src/main/java/com/bernard/greposimu/model/simulator/Joueureuse.java +++ b/src/main/java/com/bernard/greposimu/model/simulator/Joueureuse.java @@ -2,6 +2,7 @@ package com.bernard.greposimu.model.simulator; import java.util.List; import java.util.Map; +import java.util.Set; import com.bernard.greposimu.model.game.God; import com.bernard.greposimu.model.runtime.Timestamp; @@ -24,9 +25,78 @@ public class Joueureuse { List inventory; + // Remparts + Troupes slainAsOff,slainAsDef,lostAsOff,lostAsDef; + + Set movements; + + + + public Joueureuse(Map favor, int rage, int gold, Map heroes, + Map heroesArrival, Map heroesLevel, List inventory, + Troupes slainAsOff, Troupes slainAsDef, Troupes lostAsOff, Troupes lostAsDef, Set movements) { + this.favor = favor; + this.rage = rage; + this.gold = gold; + this.heroes = heroes; + this.heroesArrival = heroesArrival; + this.heroesLevel = heroesLevel; + this.inventory = inventory; + this.slainAsOff = slainAsOff; + this.slainAsDef = slainAsDef; + this.lostAsOff = lostAsOff; + this.lostAsDef = lostAsDef; + this.movements = movements; + } + + public Map getFavor() { + return favor; + } + + public int getRage() { + return rage; + } + + public int getGold() { + return gold; + } + + public Map getHeroes() { + return heroes; + } + + public Map getHeroesArrival() { + return heroesArrival; + } + + public Map getHeroesLevel() { + return heroesLevel; + } + + public List getInventory() { + return inventory; + } + + public Troupes getSlainAsDef() { + return slainAsDef; + } + public Troupes getSlainAsOff() { + return slainAsOff; + } + public Troupes getLostAsDef() { + return lostAsDef; + } + public Troupes getLostAsOff() { + return lostAsOff; + } + public Set getMovements() { + return movements; + } //TODO quêtes //TODO messages/rapports //TODO profile //TODO alliance + allianceMessages + + } diff --git a/src/main/java/com/bernard/greposimu/model/simulator/Movements.java b/src/main/java/com/bernard/greposimu/model/simulator/Movements.java new file mode 100644 index 0000000..715874f --- /dev/null +++ b/src/main/java/com/bernard/greposimu/model/simulator/Movements.java @@ -0,0 +1,23 @@ +package com.bernard.greposimu.model.simulator; + +import com.bernard.greposimu.model.runtime.Timestamp; + +public class Movements { + + Timestamp arrival; + Timestamp started; + + Timestamp cancelableUntil; + + Timestamp invisibleUntil; + + boolean destIsAttack; + boolean origIsAttack; + int home; + int player; + int target; + + String type; + + Troupes troupes; +} diff --git a/src/main/java/com/bernard/greposimu/model/simulator/SimulatorData.java b/src/main/java/com/bernard/greposimu/model/simulator/SimulatorData.java new file mode 100644 index 0000000..a274148 --- /dev/null +++ b/src/main/java/com/bernard/greposimu/model/simulator/SimulatorData.java @@ -0,0 +1,25 @@ +package com.bernard.greposimu.model.simulator; + +import java.util.Map; + +public class SimulatorData { + + Map villes; + + Joueureuse joueureuse; + + public SimulatorData(Map villes, Joueureuse joueureuse) { + super(); + this.villes = villes; + this.joueureuse = joueureuse; + } + + public Map getVilles() { + return villes; + } + + public Joueureuse getJoueureuse() { + return joueureuse; + } + +} diff --git a/src/main/java/com/bernard/greposimu/model/simulator/Troupes.java b/src/main/java/com/bernard/greposimu/model/simulator/Troupes.java index 6eed530..81c999c 100644 --- a/src/main/java/com/bernard/greposimu/model/simulator/Troupes.java +++ b/src/main/java/com/bernard/greposimu/model/simulator/Troupes.java @@ -1,9 +1,40 @@ package com.bernard.greposimu.model.simulator; import java.util.Map; +import java.util.function.Function; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import com.bernard.greposimu.model.game.units.Unit; public class Troupes { - Map unites; + Map unites; + + public Troupes(Map unites) { + this.unites = unites; + } + + public Map getUnites() { + return unites; + } + + public static final Troupes add(Troupes a, Troupes b) { + return new Troupes( + Stream.concat(a.unites.keySet().stream(), b.unites.keySet().stream()) + .distinct().collect(Collectors.toMap(Function.identity(), + u -> a.unites.getOrDefault(u, 0)+b.unites.getOrDefault(u, 0))) + ); + } + + public int pop() { + return unites.entrySet().stream().mapToInt(e -> e.getValue()*e.getKey().getPopulation()).sum(); + } + + @Override + public String toString() { + return "Troupes [unites=" + unites + "]"; + } + } diff --git a/src/main/java/com/bernard/greposimu/model/simulator/Ville.java b/src/main/java/com/bernard/greposimu/model/simulator/Ville.java index e748d7d..670cb8e 100644 --- a/src/main/java/com/bernard/greposimu/model/simulator/Ville.java +++ b/src/main/java/com/bernard/greposimu/model/simulator/Ville.java @@ -4,15 +4,22 @@ import java.util.List; import java.util.Map; import java.util.Set; +import com.bernard.greposimu.model.game.Building; import com.bernard.greposimu.model.game.God; import com.bernard.greposimu.model.game.Resources; +import com.bernard.greposimu.model.game.powers.Power; +import com.bernard.greposimu.model.game.queues.BuildingQueueItem; +import com.bernard.greposimu.model.game.queues.RecruitmentQueueItem; +import com.bernard.greposimu.model.game.queues.ResearchQueueItem; +import com.bernard.greposimu.model.game.researches.Research; import com.bernard.greposimu.model.runtime.Timestamp; public class Ville { + int id; String nom; - Map batiments; + Map batiments; Troupes troupes; @@ -23,35 +30,33 @@ public class Ville { Map soutenus; // sortilegeId -> effectEnd - Map sortileges; + Map sortileges; // Agora Timestamp festivalEnd,olympiquesEnd,marchEnd,theaterEnd; // Academie - Set researches; - List researchQueue; + Set researches; + List researchQueue; // Senat - List buildingQueue; + List buildingQueue; // Farm - Timestamp miliceAppel; + // End time of militia + Timestamp miliceUntil; // Entrepôt Resources storage; // Caserne - List terrestrialQueue; + List terrestrialQueue; // Temple God god; // Port - List navalQueue; - - // Remparts - Troupes slainAsOff,slainAsDef,lostAsOff,lostAsDef; + List navalQueue; // Grotte int piecesStoquees; @@ -61,9 +66,47 @@ public class Ville { Set incomingTrade; Set outgoingTrade; + + public Ville(int id, String nom, Map batiments, Troupes troupes, Map soutiens, + Map soutenus, Map sortileges, Timestamp festivalEnd, + Timestamp olympiquesEnd, Timestamp marchEnd, Timestamp theaterEnd, Set researches, + List researchQueue, List buildingQueue, Timestamp miliceUntil, + Resources storage, List terrestrialQueue, God god, + List navalQueue, int piecesStoquees, Set ordresMilitaires, Set incomingTrade, + Set outgoingTrade) { + super(); + this.id = id; + this.nom = nom; + this.batiments = batiments; + this.troupes = troupes; + this.soutiens = soutiens; + this.soutenus = soutenus; + this.sortileges = sortileges; + this.festivalEnd = festivalEnd; + this.olympiquesEnd = olympiquesEnd; + this.marchEnd = marchEnd; + this.theaterEnd = theaterEnd; + this.researches = researches; + this.researchQueue = researchQueue; + this.buildingQueue = buildingQueue; + this.miliceUntil = miliceUntil; + this.storage = storage; + this.terrestrialQueue = terrestrialQueue; + this.god = god; + this.navalQueue = navalQueue; + this.piecesStoquees = piecesStoquees; + this.ordresMilitaires = ordresMilitaires; + this.incomingTrade = incomingTrade; + this.outgoingTrade = outgoingTrade; + } + public static class TradeOrder { Resources resources; Integer other; + public TradeOrder(Resources resources, Integer other) { + this.resources = resources; + this.other = other; + } } public static class UnitOrder { Troupes attq; @@ -84,5 +127,97 @@ public class Ville { Timestamp endTime; long duration; } + + public int getId() { + return id; + } + + public String getNom() { + return nom; + } + + public Map getBatiments() { + return batiments; + } + + public Troupes getTroupes() { + return troupes; + } + + public Map getSoutiens() { + return soutiens; + } + + public Map getSoutenus() { + return soutenus; + } + + public Map getSortileges() { + return sortileges; + } + + public Timestamp getFestivalEnd() { + return festivalEnd; + } + + public Timestamp getOlympiquesEnd() { + return olympiquesEnd; + } + + public Timestamp getMarchEnd() { + return marchEnd; + } + + public Timestamp getTheaterEnd() { + return theaterEnd; + } + + public Set getResearches() { + return researches; + } + + public List getResearchQueue() { + return researchQueue; + } + + public List getBuildingQueue() { + return buildingQueue; + } + + public Timestamp getMiliceUntil() { + return miliceUntil; + } + + public Resources getStorage() { + return storage; + } + + public List getTerrestrialQueue() { + return terrestrialQueue; + } + + public God getGod() { + return god; + } + + public List getNavalQueue() { + return navalQueue; + } + + public int getPiecesStoquees() { + return piecesStoquees; + } + + public Set getOrdresMilitaires() { + return ordresMilitaires; + } + + public Set getIncomingTrade() { + return incomingTrade; + } + + public Set getOutgoingTrade() { + return outgoingTrade; + } } diff --git a/src/main/java/com/bernard/greposimu/model/simulator/command/BuildCommand.java b/src/main/java/com/bernard/greposimu/model/simulator/command/BuildCommand.java new file mode 100644 index 0000000..d4f0cca --- /dev/null +++ b/src/main/java/com/bernard/greposimu/model/simulator/command/BuildCommand.java @@ -0,0 +1,31 @@ +package com.bernard.greposimu.model.simulator.command; + +import com.bernard.greposimu.model.game.Building; +import com.bernard.greposimu.model.game.Resources; + +public class BuildCommand extends TownCommand { + + Building building; + + // Destination level of the build + int level; + + boolean tearingDown; + + public BuildCommand(int town, Resources need, Building building, int level, boolean tearingDown) { + this.town = town; + this.need = need; + this.building = building; + this.level = level; + this.tearingDown = tearingDown; + } + + @Override + public String toString() { + if(tearingDown) + return "[%d] Destroy %s from %d -> %d".formatted(this.town,this.building.name(),this.level+1,this.level); + else + return "[%d] Build %s from %d -> %d".formatted(this.town,this.building.name(),this.level-1,this.level); + } + +} diff --git a/src/main/java/com/bernard/greposimu/model/simulator/command/Command.java b/src/main/java/com/bernard/greposimu/model/simulator/command/Command.java new file mode 100644 index 0000000..12446ac --- /dev/null +++ b/src/main/java/com/bernard/greposimu/model/simulator/command/Command.java @@ -0,0 +1,5 @@ +package com.bernard.greposimu.model.simulator.command; + +public abstract class Command { + +} diff --git a/src/main/java/com/bernard/greposimu/model/simulator/command/HideStoreCommand.java b/src/main/java/com/bernard/greposimu/model/simulator/command/HideStoreCommand.java new file mode 100644 index 0000000..d3e6c6d --- /dev/null +++ b/src/main/java/com/bernard/greposimu/model/simulator/command/HideStoreCommand.java @@ -0,0 +1,17 @@ +package com.bernard.greposimu.model.simulator.command; + +public class HideStoreCommand extends TownCommand { + + int amount; + + public HideStoreCommand(int town, int amount) { + this.town = town; + this.amount = amount; + } + + @Override + public String toString() { + return "[%d] Store %d iron in the hide".formatted(this.town,this.amount); + } + +} diff --git a/src/main/java/com/bernard/greposimu/model/simulator/command/RecruitCommand.java b/src/main/java/com/bernard/greposimu/model/simulator/command/RecruitCommand.java new file mode 100644 index 0000000..bcefecc --- /dev/null +++ b/src/main/java/com/bernard/greposimu/model/simulator/command/RecruitCommand.java @@ -0,0 +1,23 @@ +package com.bernard.greposimu.model.simulator.command; + +import com.bernard.greposimu.model.game.Resources; +import com.bernard.greposimu.model.game.units.Unit; + +public class RecruitCommand extends TownCommand{ + + Unit unit; + int count; + + public RecruitCommand(int town, Resources need, Unit unit, int count) { + this.town = town; + this.need = need; + this.unit = unit; + this.count = count; + } + + @Override + public String toString() { + return "[%d] Recruit %d %s".formatted(this.town,this.count, this.unit.getName()); + } + +} diff --git a/src/main/java/com/bernard/greposimu/model/simulator/command/ResearchCommand.java b/src/main/java/com/bernard/greposimu/model/simulator/command/ResearchCommand.java new file mode 100644 index 0000000..39fbb3b --- /dev/null +++ b/src/main/java/com/bernard/greposimu/model/simulator/command/ResearchCommand.java @@ -0,0 +1,25 @@ +package com.bernard.greposimu.model.simulator.command; + +import com.bernard.greposimu.model.game.Resources; +import com.bernard.greposimu.model.game.researches.Research; + +public class ResearchCommand extends TownCommand { + + Research research; + boolean forget; + public ResearchCommand(int town, Resources need, Research research, boolean forget) { + this.town = town; + this.need = need; + this.research = research; + this.forget = forget; + } + + @Override + public String toString() { + if(forget) + return "[%d] Forget research %s".formatted(this.town,this.research.getName()); + else + return "[%d] Research %s".formatted(this.town,this.research.getName()); + } + +} diff --git a/src/main/java/com/bernard/greposimu/model/simulator/command/TownCommand.java b/src/main/java/com/bernard/greposimu/model/simulator/command/TownCommand.java new file mode 100644 index 0000000..c483dba --- /dev/null +++ b/src/main/java/com/bernard/greposimu/model/simulator/command/TownCommand.java @@ -0,0 +1,11 @@ +package com.bernard.greposimu.model.simulator.command; + +import com.bernard.greposimu.model.game.Resources; + +public abstract class TownCommand extends Command { + + int town; + + Resources need; + +} diff --git a/src/main/java/com/bernard/greposimu/model/simulator/objective/TownObjective.java b/src/main/java/com/bernard/greposimu/model/simulator/objective/TownObjective.java new file mode 100644 index 0000000..e2ed9cf --- /dev/null +++ b/src/main/java/com/bernard/greposimu/model/simulator/objective/TownObjective.java @@ -0,0 +1,132 @@ +package com.bernard.greposimu.model.simulator.objective; + +import java.util.HashSet; +import java.util.Map; +import java.util.Set; +import java.util.stream.Collectors; + +import com.bernard.greposimu.model.game.Building; +import com.bernard.greposimu.model.game.GameConfig; +import com.bernard.greposimu.model.game.God; +import com.bernard.greposimu.model.game.researches.Research; +import com.bernard.greposimu.model.game.units.Unit; +import com.bernard.greposimu.model.simulator.Troupes; +import com.bernard.greposimu.model.simulator.Ville; +import com.bernard.greposimu.model.simulator.command.BuildCommand; +import com.bernard.greposimu.model.simulator.command.Command; +import com.bernard.greposimu.model.simulator.command.HideStoreCommand; +import com.bernard.greposimu.model.simulator.command.RecruitCommand; +import com.bernard.greposimu.model.simulator.command.ResearchCommand; + +public class TownObjective { + GameConfig gc; + + Map buildings; + Map unitsProportions; + Set researches; + int hide; + God god; + + TownObjective() {} + + public TownObjective(GameConfig gc, Map buildings, Map unitsProportions, + Set researches, int hide, God god) { + this.gc = gc; + this.buildings = buildings; + this.unitsProportions = unitsProportions; + this.researches = researches; + this.hide = hide; + this.god = god; + } + + public static final int villeMaxPop(GameConfig gc, Ville v) { + return GameConfig.getTotalPop( + v.getBatiments().getOrDefault(Building.FARM,0), + v.getBatiments().getOrDefault(Building.THERMAL, 0)>=1, + v.getResearches().contains(gc.getResearch("plow")), + v.getGod().getId().equals("aphrodite"), + 0); //TODO take popultion_boost into account + } + public Troupes targetTroupes() { + int popRest = GameConfig.getTotalPop( + this.buildings.getOrDefault(Building.FARM,0), + this.buildings.getOrDefault(Building.THERMAL, 0)>=1, + this.researches.contains(gc.getResearch("plow")), + this.god.getId().equals("aphrodite"), + 0) //TODO take popultion_boost into account + - + this.buildings.entrySet().stream().mapToInt(e -> e.getKey().getRequiredPop(e.getValue())).sum(); + double totalProp = this.unitsProportions.values().stream().collect(Collectors.summarizingDouble(d -> d)).getSum(); + return new Troupes(this.unitsProportions.entrySet().stream().collect(Collectors.toMap( + e -> e.getKey(), + e -> (int)Math.floor(e.getValue()*popRest/totalProp/e.getKey().getPopulation())))); + } + + public Set getDifferences(Ville v) { + + Set commands = new HashSet<>(); + + for(Building b :gc.getBuildings()) { + int cur = v.getBatiments().getOrDefault(b, 0); + int obj = this.buildings.getOrDefault(b, 0); + if(cur != obj) { + if(obj>cur) + for(int i=cur+1;i<=obj;i++) + commands.add(new BuildCommand(v.getId(), null, b, i, false)); + else + for(int i=cur-1;i>=obj;i--) + commands.add(new BuildCommand(v.getId(), null, b, i, true)); + } + //TODO check queue + } + + for(Research r : gc.getResearches()) { + boolean cur = v.getResearches().contains(r); + boolean obj = this.researches.contains(r); + if(cur && !obj) + commands.add(new ResearchCommand(v.getId(),null,r,true)); + else if (!cur && obj) + commands.add(new ResearchCommand(v.getId(),null,r,false)); + //TODO check queue + } + Troupes tot = Troupes.add(v.getTroupes(),v.getSoutiens().values().stream().reduce(Troupes::add).orElse(new Troupes(Map.of()))); + Troupes target = this.targetTroupes(); + for(Unit u : gc.getUnits()) { + int diff = target.getUnites().getOrDefault(u,0) - tot.getUnites().getOrDefault(u,0); + if(diff > 0) + commands.add(new RecruitCommand(v.getId(), null, u, diff)); + //TODO manage unit removal planned + } + + if(v.getPiecesStoquees() < hide) + commands.add(new HideStoreCommand(v.getId(), hide - v.getPiecesStoquees())); + return commands; + } + + public Map getBuildings() { + return buildings; + } + + public Map getUnitsProportions() { + return unitsProportions; + } + + public Set getResearches() { + return researches; + } + + public int getHide() { + return hide; + } + + public God getGod() { + return god; + } + + @Override + public String toString() { + return "TownObjective [gc=" + gc + ", buildings=" + buildings + ", unitsProportions=" + unitsProportions + + ", researches=" + researches + ", hide=" + hide + ", god=" + god + "]"; + } + +} diff --git a/src/main/java/com/bernard/greposimu/source/JSONSourcer.java b/src/main/java/com/bernard/greposimu/source/JSONSourcer.java new file mode 100644 index 0000000..3efd350 --- /dev/null +++ b/src/main/java/com/bernard/greposimu/source/JSONSourcer.java @@ -0,0 +1,183 @@ +package com.bernard.greposimu.source; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.stream.Collectors; + +import com.bernard.greposimu.GrepoSimu; +import com.bernard.greposimu.model.game.Building; +import com.bernard.greposimu.model.game.GameConfig; +import com.bernard.greposimu.model.game.God; +import com.bernard.greposimu.model.game.Resources; +import com.bernard.greposimu.model.game.UnitResources; +import com.bernard.greposimu.model.game.powers.Power; +import com.bernard.greposimu.model.game.queues.BuildingQueueItem; +import com.bernard.greposimu.model.game.queues.RecruitmentQueueItem; +import com.bernard.greposimu.model.game.queues.RecruitmentQueueItem.RecruitmentKind; +import com.bernard.greposimu.model.game.queues.ResearchQueueItem; +import com.bernard.greposimu.model.game.researches.Research; +import com.bernard.greposimu.model.game.units.Unit; +import com.bernard.greposimu.model.runtime.Timestamp; +import com.bernard.greposimu.model.simulator.Joueureuse; +import com.bernard.greposimu.model.simulator.SimulatorData; +import com.bernard.greposimu.model.simulator.Troupes; +import com.bernard.greposimu.model.simulator.Ville; +import com.bernard.greposimu.model.simulator.Ville.TradeOrder; +import com.fasterxml.jackson.core.exc.StreamReadException; +import com.fasterxml.jackson.databind.DatabindException; +import com.fasterxml.jackson.databind.ObjectMapper; + +public class JSONSourcer { + + public static final void readSource(File file) { + ObjectMapper om = new ObjectMapper(); + try { + SourcedData sd = om.readValue(file, SourcedData.class); + System.out.println(sd); + } catch (StreamReadException e) { + e.printStackTrace(); + } catch (DatabindException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + public static final Troupes getTroupes(GameConfig gc, Map count) { + Map troup = new HashMap<>(); + for(String u : count.keySet())troup.put(gc.getUnit(u), count.get(u)); + return new Troupes(troup); + } + public static final Resources getResources(SourcedRessources res) { + return new Resources(res.wood, res.stone, res.iron); + } + public static final UnitResources getUnitResources(God god, SourcedFavRessources res) { + return new UnitResources(res.wood, res.stone, res.iron,god,res.favor); + } + + public static final SimulatorData makeSimulationData(File file, GameConfig gc) { + ObjectMapper om = new ObjectMapper(); + try { + SourcedData sd = om.readValue(file, SourcedData.class); + + Map villes = new HashMap(); + for(String idS : sd.towns.keySet()) { + Integer id = Integer.parseInt(idS); + SourcedTown st = sd.getTowns().get(idS); + + Map buildings = new HashMap<>(); + for(String bid : st.buildings.keySet())buildings.put(gc.getBuilding(bid), st.buildings.get(bid)); + Set researches = new HashSet<>(); + for(String rid : st.researches.keySet())if(st.researches.get(rid))researches.add(gc.getResearch(rid)); + Map soutiens = new HashMap(); + Map soutenus = new HashMap(); + for(SourcedUnits uts : sd.units) { + if(uts.orig == id && uts.curr != id) + soutiens.put(uts.curr, getTroupes(gc, uts.getUnits())); + if(uts.curr == id && uts.orig != id) + soutenus.put(uts.orig, getTroupes(gc, uts.getUnits())); + } + + List buildingQueue = new ArrayList<>(); + for(SourcedBuildingOrder sbo : st.buildingOrders) + buildingQueue.add(new BuildingQueueItem( + sbo.getBuildingTime(), + gc.getBuilding(sbo.building), + sbo.isTearingDown(), + new Timestamp(sbo.getBeginTime()), + new Timestamp(sbo.getEndTime()), + getResources(sbo.getRefund()), + getResources(sbo.getCost()) + )); + List terrestrialQueue = new ArrayList<>(); + List navalQueue = new ArrayList<>(); + for(SourcedRecruitmentOrder sro : st.recruitingOrders) { + Unit u = gc.getUnit(sro.unit); + RecruitmentQueueItem rqi = new RecruitmentQueueItem( + sro.getKind().equals("ground")?RecruitmentKind.GROUND:RecruitmentKind.NAVAL, + u, + sro.getCount(), + sro.getDone(), + new Timestamp(sro.getBeginTime()), + new Timestamp(sro.getEndTime()), + getUnitResources(u.isMythological()?u.getGod():null, sro.getRefund()), + getUnitResources(null, sro.getCost()) + ); + if(sro.kind.equals("ground")) + terrestrialQueue.add(rqi); + else if(sro.kind.equals("naval")) + navalQueue.add(rqi); + } + List researchQueue = new ArrayList<>(); + for(SourcedResearchOrder sro : st.researchOrders) + researchQueue.add(new ResearchQueueItem( + gc.getResearch(sro.getResearch()), + new Timestamp(sro.getBeginTime()), + new Timestamp(sro.getEndTime()), + getResources(sro.getRefund()) + )); + Map sortileges = new HashMap<>(); + for(SourcedCastedPower sp : st.castedPowers) { + //TODO + } + Set incomingTrade = new HashSet<>(); + Set outgoingTrade = new HashSet<>(); + for(SourcedTrades str : sd.trades) { + //TODO support farmtowns + if(str.destType.equals("town_trade") && str.origType.equals("town_trade")){ + if(Integer.parseInt(str.dest) == id) + incomingTrade.add(new TradeOrder(new Resources(str.getWood(), str.getStone(), str.getIron()), Integer.parseInt(str.orig))); + if(Integer.parseInt(str.orig) == id) + incomingTrade.add(new TradeOrder(new Resources(str.getWood(), str.getStone(), str.getIron()), Integer.parseInt(str.dest))); + } + } + + Set townCele = sd.celebrations.stream().filter(c -> c.getTown() == id).collect(Collectors.toSet()); + villes.put(st.name, new Ville( + id, + st.name, + buildings, + getTroupes(gc, st.getUnitsTotal()), + soutiens, + soutenus, + sortileges, + + townCele.stream().filter(c -> c.type.equals("party")).map(SourcedCelebration::getEnd).map(Timestamp::new).findAny().orElse(null), + townCele.stream().filter(c -> c.type.equals("games")).map(SourcedCelebration::getEnd).map(Timestamp::new).findAny().orElse(null), + townCele.stream().filter(c -> c.type.equals("triumph")).map(SourcedCelebration::getEnd).map(Timestamp::new).findAny().orElse(null), + townCele.stream().filter(c -> c.type.equals("theater")).map(SourcedCelebration::getEnd).map(Timestamp::new).findAny().orElse(null), + + researches, + researchQueue, + buildingQueue, + st.getMilitia()==null?null:new Timestamp(st.getMilitia().getEnd()), + new Resources(st.getResources().wood, st.getResources().stone, st.getResources().iron), + terrestrialQueue, + gc.getGod(st.god), + navalQueue, + st.espstorage, + null,//ordresMilitaires, + incomingTrade, + outgoingTrade)); + + } + Joueureuse joueureuse = new Joueureuse(null, 0, 0, null, null, null, null, null, null, null, null, null); + + return new SimulatorData(villes, joueureuse); + } catch (StreamReadException e) { + e.printStackTrace(); + } catch (DatabindException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + return null; + } + +} diff --git a/src/main/java/com/bernard/greposimu/source/SourcedBuildingOrder.java b/src/main/java/com/bernard/greposimu/source/SourcedBuildingOrder.java new file mode 100644 index 0000000..78ddbee --- /dev/null +++ b/src/main/java/com/bernard/greposimu/source/SourcedBuildingOrder.java @@ -0,0 +1,46 @@ +package com.bernard.greposimu.source; + +public class SourcedBuildingOrder { + + @Override + public String toString() { + return "SourcedBuildingOrder [buildingTime=" + buildingTime + ", building=" + building + ", beginTime=" + + beginTime + ", tearingDown=" + tearingDown + ", endTime=" + endTime + ", refund=" + refund + ", cost=" + + cost + "]"; + } + long buildingTime; + + // the id of the building being built + String building; + + long beginTime; + boolean tearingDown; + long endTime; + + SourcedRessources refund; + SourcedRessources cost; + + public long getBuildingTime() { + return buildingTime; + } + public String getBuilding() { + return building; + } + public long getBeginTime() { + return beginTime; + } + public boolean isTearingDown() { + return tearingDown; + } + public long getEndTime() { + return endTime; + } + public SourcedRessources getRefund() { + return refund; + } + public SourcedRessources getCost() { + return cost; + } + + +} diff --git a/src/main/java/com/bernard/greposimu/source/SourcedCastedPower.java b/src/main/java/com/bernard/greposimu/source/SourcedCastedPower.java new file mode 100644 index 0000000..322fe4d --- /dev/null +++ b/src/main/java/com/bernard/greposimu/source/SourcedCastedPower.java @@ -0,0 +1,37 @@ +package com.bernard.greposimu.source; + +public class SourcedCastedPower { + + Object configuration; + Long endTime; + int extended; + Integer level; + Long originPlayer; + String power; + + @Override + public String toString() { + return "SourcedCastedPower [configuration=" + configuration + ", endTime=" + endTime + ", extended=" + extended + + ", level=" + level + ", originPlayer=" + originPlayer + ", power=" + power + "]"; + } + public Object getConfiguration() { + return configuration; + } + public Long getEndTime() { + return endTime; + } + public int getExtended() { + return extended; + } + public Integer getLevel() { + return level; + } + public Long getOriginPlayer() { + return originPlayer; + } + public String getPower() { + return power; + } + + +} diff --git a/src/main/java/com/bernard/greposimu/source/SourcedCelebration.java b/src/main/java/com/bernard/greposimu/source/SourcedCelebration.java new file mode 100644 index 0000000..d577dbc --- /dev/null +++ b/src/main/java/com/bernard/greposimu/source/SourcedCelebration.java @@ -0,0 +1,18 @@ +package com.bernard.greposimu.source; + +public class SourcedCelebration { + + int town; + String type; + long end; + + public int getTown() { + return town; + } + public String getType() { + return type; + } + public long getEnd() { + return end; + } +} diff --git a/src/main/java/com/bernard/greposimu/source/SourcedData.java b/src/main/java/com/bernard/greposimu/source/SourcedData.java new file mode 100644 index 0000000..1285134 --- /dev/null +++ b/src/main/java/com/bernard/greposimu/source/SourcedData.java @@ -0,0 +1,40 @@ +package com.bernard.greposimu.source; + +import java.util.List; +import java.util.Map; + +public class SourcedData { + + Map towns; + List celebrations; + List movements; + List trades; + + Map favors; + List units; + + public Map getTowns() { + return towns; + } + public List getCelebrations() { + return celebrations; + } + public List getMovements() { + return movements; + } + public List getTrades() { + return trades; + } + public Map getFavors() { + return favors; + } + public List getUnits() { + return units; + } + @Override + public String toString() { + return "SourcedData [towns=" + towns + ", celebrations=" + celebrations + ", movements=" + movements + + ", trades=" + trades + ", favors=" + favors + "]"; + } + +} diff --git a/src/main/java/com/bernard/greposimu/source/SourcedFavRessources.java b/src/main/java/com/bernard/greposimu/source/SourcedFavRessources.java new file mode 100644 index 0000000..01cf968 --- /dev/null +++ b/src/main/java/com/bernard/greposimu/source/SourcedFavRessources.java @@ -0,0 +1,31 @@ +package com.bernard.greposimu.source; + +public class SourcedFavRessources { + int wood; + int iron; + int stone; + int favor; + int pop; + public int getWood() { + return wood; + } + public int getIron() { + return iron; + } + public int getStone() { + return stone; + } + public int getFavor() { + return favor; + } + public int getPop() { + return pop; + } + @Override + public String toString() { + return "SourcedFavRessources [wood=" + wood + ", iron=" + iron + ", stone=" + stone + ", favor=" + favor + + ", pop=" + pop + "]"; + } + + +} diff --git a/src/main/java/com/bernard/greposimu/source/SourcedMilitaryOrders.java b/src/main/java/com/bernard/greposimu/source/SourcedMilitaryOrders.java new file mode 100644 index 0000000..bc426ab --- /dev/null +++ b/src/main/java/com/bernard/greposimu/source/SourcedMilitaryOrders.java @@ -0,0 +1,51 @@ +package com.bernard.greposimu.source; + +public class SourcedMilitaryOrders { + + long start; + long arrival; + long cancelableUntil; + long invisibleUntil; + + boolean destIsAttackSpot; + boolean origIsAttackSpot; + + int player; + int homeId; + int targetId; + + String type; + + public long getArrival() { + return arrival; + } + public long getCancelableUntil() { + return cancelableUntil; + } + public long getInvisibleUntil() { + return invisibleUntil; + } + public boolean isDestIsAttackSpot() { + return destIsAttackSpot; + } + public boolean isOrigIsAttackSpot() { + return origIsAttackSpot; + } + public int getHomeId() { + return homeId; + } + public int getPlayer() { + return player; + } + public long getStart() { + return start; + } + public int getTargetId() { + return targetId; + } + public String getType() { + return type; + } + + +} diff --git a/src/main/java/com/bernard/greposimu/source/SourcedMilitiaTimes.java b/src/main/java/com/bernard/greposimu/source/SourcedMilitiaTimes.java new file mode 100644 index 0000000..a4509ff --- /dev/null +++ b/src/main/java/com/bernard/greposimu/source/SourcedMilitiaTimes.java @@ -0,0 +1,13 @@ +package com.bernard.greposimu.source; + +public class SourcedMilitiaTimes { + long start; + long end; + + public long getStart() { + return start; + } + public long getEnd() { + return end; + } +} diff --git a/src/main/java/com/bernard/greposimu/source/SourcedRecruitmentOrder.java b/src/main/java/com/bernard/greposimu/source/SourcedRecruitmentOrder.java new file mode 100644 index 0000000..edee375 --- /dev/null +++ b/src/main/java/com/bernard/greposimu/source/SourcedRecruitmentOrder.java @@ -0,0 +1,49 @@ +package com.bernard.greposimu.source; + +public class SourcedRecruitmentOrder { + + int count; + + int done; + + String kind; + // the id of the building being built + String unit; + + long beginTime; + long endTime; + + SourcedFavRessources refund; + SourcedFavRessources cost; + public int getCount() { + return count; + } + public int getDone() { + return done; + } + public String getKind() { + return kind; + } + public String getUnit() { + return unit; + } + public long getBeginTime() { + return beginTime; + } + public long getEndTime() { + return endTime; + } + public SourcedFavRessources getRefund() { + return refund; + } + public SourcedFavRessources getCost() { + return cost; + } + @Override + public String toString() { + return "SourcedRecruitmentOrder [count=" + count + ", done=" + done + ", kind=" + kind + ", unit=" + unit + + ", beginTime=" + beginTime + ", endTime=" + endTime + ", refund=" + refund + ", cost=" + cost + "]"; + } + + +} \ No newline at end of file diff --git a/src/main/java/com/bernard/greposimu/source/SourcedResearchOrder.java b/src/main/java/com/bernard/greposimu/source/SourcedResearchOrder.java new file mode 100644 index 0000000..a4961fe --- /dev/null +++ b/src/main/java/com/bernard/greposimu/source/SourcedResearchOrder.java @@ -0,0 +1,31 @@ +package com.bernard.greposimu.source; + +public class SourcedResearchOrder { + + // the id of the building being built + String research; + + long beginTime; + long endTime; + + SourcedRessources refund; + + public String getResearch() { + return research; + } + + public long getBeginTime() { + return beginTime; + } + + public long getEndTime() { + return endTime; + } + + public SourcedRessources getRefund() { + return refund; + } + + + +} diff --git a/src/main/java/com/bernard/greposimu/source/SourcedRessources.java b/src/main/java/com/bernard/greposimu/source/SourcedRessources.java new file mode 100644 index 0000000..b33f4c5 --- /dev/null +++ b/src/main/java/com/bernard/greposimu/source/SourcedRessources.java @@ -0,0 +1,22 @@ +package com.bernard.greposimu.source; + +public class SourcedRessources { + int wood; + int iron; + int stone; + @Override + public String toString() { + return "SourcedRessources [wood=" + wood + ", iron=" + iron + ", stone=" + stone + "]"; + } + public int getWood() { + return wood; + } + public int getIron() { + return iron; + } + public int getStone() { + return stone; + } + + +} diff --git a/src/main/java/com/bernard/greposimu/source/SourcedTown.java b/src/main/java/com/bernard/greposimu/source/SourcedTown.java new file mode 100644 index 0000000..56bd71c --- /dev/null +++ b/src/main/java/com/bernard/greposimu/source/SourcedTown.java @@ -0,0 +1,95 @@ +package com.bernard.greposimu.source; + +import java.util.List; +import java.util.Map; + +public class SourcedTown { + + String name; + int points; + + String god; + SourcedTownResources resources; + int espstorage; + + /* GLOBAL UNITS */ + // unit_id -> number of units + // TOTAL units defending this city + Map unitsTotal; + // TOTAL units from this city defending another city + Map outerTotal; + // TOTAL units from other cities defending this city + Map supportTotal; + + + // building_id -> level + Map buildings; + + // research_id -> hasBeenResearched + Map researches; + + List castedPowers; + + + List buildingOrders; + List recruitingOrders; + List researchOrders; + + SourcedMilitiaTimes militia; + + public String getName() { + return name; + } + public int getPoints() { + return points; + } + public Map getUnitsTotal() { + return unitsTotal; + } + public Map getOuterTotal() { + return outerTotal; + } + public Map getSupportTotal() { + return supportTotal; + } + public Map getBuildings() { + return buildings; + } + public Map getResearches() { + return researches; + } + public List getCastedPowers() { + return castedPowers; + } + public List getBuildingOrders() { + return buildingOrders; + } + public List getRecruitingOrders() { + return recruitingOrders; + } + public List getResearchOrders() { + return researchOrders; + } + public SourcedTownResources getResources() { + return resources; + } + public int getEspstorage() { + return espstorage; + } + public SourcedMilitiaTimes getMilitia() { + return militia; + } + public String getGod() { + return god; + } + @Override + public String toString() { + return "SourcedTown [name=" + name + ", points=" + points + ", god=" + god + ", resources=" + resources + + ", espstorage=" + espstorage + ", unitsTotal=" + unitsTotal + ", outerTotal=" + outerTotal + + ", supportTotal=" + supportTotal + ", buildings=" + buildings + ", researches=" + researches + + ", castedPowers=" + castedPowers + ", buildingOrders=" + buildingOrders + ", recruitingOrders=" + + recruitingOrders + ", researchOrders=" + researchOrders + ", militia=" + militia + "]"; + } + + +} diff --git a/src/main/java/com/bernard/greposimu/source/SourcedTownResources.java b/src/main/java/com/bernard/greposimu/source/SourcedTownResources.java new file mode 100644 index 0000000..d363e88 --- /dev/null +++ b/src/main/java/com/bernard/greposimu/source/SourcedTownResources.java @@ -0,0 +1,39 @@ +package com.bernard.greposimu.source; + +public class SourcedTownResources { + + int wood,stone,iron,storage,population,favor; + + public int getWood() { + return wood; + } + + public int getStone() { + return stone; + } + + public int getIron() { + return iron; + } + + public int getStorage() { + return storage; + } + + public int getPopulation() { + return population; + } + + @Override + public String toString() { + return "SourcedTownResources [wood=" + wood + ", stone=" + stone + ", iron=" + iron + ", storage=" + storage + + ", population=" + population + ", favor=" + favor + "]"; + } + + public int getFavor() { + return favor; + } + + + +} diff --git a/src/main/java/com/bernard/greposimu/source/SourcedTrades.java b/src/main/java/com/bernard/greposimu/source/SourcedTrades.java new file mode 100644 index 0000000..a6c2c2d --- /dev/null +++ b/src/main/java/com/bernard/greposimu/source/SourcedTrades.java @@ -0,0 +1,66 @@ +package com.bernard.greposimu.source; + +public class SourcedTrades { + + long start; + long arrival; + String dest; + String destType; + String orig; + String origType; + + int gold,stone,wood,iron; + + boolean exchange; + + public long getStart() { + return start; + } + + public long getArrival() { + return arrival; + } + + public String getDest() { + return dest; + } + + public String getDestType() { + return destType; + } + + public String getOrig() { + return orig; + } + + public String getOrigType() { + return origType; + } + + public int getGold() { + return gold; + } + + public int getStone() { + return stone; + } + + public int getWood() { + return wood; + } + + public int getIron() { + return iron; + } + + public boolean isExchange() { + return exchange; + } + + @Override + public String toString() { + return "SourcedTrades [start=" + start + ", arrival=" + arrival + ", dest=" + dest + ", destType=" + destType + + ", orig=" + orig + ", origType=" + origType + ", gold=" + gold + ", stone=" + stone + ", wood=" + wood + + ", iron=" + iron + ", exchange=" + exchange + "]"; + } +} diff --git a/src/main/java/com/bernard/greposimu/source/SourcedUnits.java b/src/main/java/com/bernard/greposimu/source/SourcedUnits.java new file mode 100644 index 0000000..abcdcdb --- /dev/null +++ b/src/main/java/com/bernard/greposimu/source/SourcedUnits.java @@ -0,0 +1,23 @@ +package com.bernard.greposimu.source; + +import java.util.Map; + +public class SourcedUnits { + int orig; + int curr; + Map units; + boolean sameIsland; + + public int getOrig() { + return orig; + } + public int getCurr() { + return curr; + } + public Map getUnits() { + return units; + } + public boolean isSameIsland() { + return sameIsland; + } +} diff --git a/src/main/resources/greposource.js b/src/main/resources/greposource.js index 7b07819..e88be46 100644 --- a/src/main/resources/greposource.js +++ b/src/main/resources/greposource.js @@ -1,11 +1,183 @@ -out = {} -for(var townid in ITowns.towns) { - out[townid] = {} - out[townid].units = ITowns.towns[townid].units() - out[townid].support = ITowns.towns[townid].unitsSupport() - out[townid].outer = ITowns.towns[townid].unitsOuter() - out[townid].resources = ITowns.towns[townid].resources() - out[townid].buildings = ITowns.towns[townid].buildings().getBuildings() - out[townid].researches = ITowns.towns[townid].researches().attributes +function downloadObjectAsJson(exportObj, exportName){ + var dataStr = "data:text/json;charset=utf-8," + encodeURIComponent(JSON.stringify(exportObj,null,2)); + var downloadAnchorNode = document.createElement('a'); + downloadAnchorNode.setAttribute("href", dataStr); + downloadAnchorNode.setAttribute("download", exportName + ".json"); + document.body.appendChild(downloadAnchorNode); // required for firefox + downloadAnchorNode.click(); + downloadAnchorNode.remove(); } -var json = JSON.stringify(out) \ No newline at end of file + +function getAllFragments() { + out = {} + for(var storename in ITowns){ + + if(typeof ITowns[storename] === 'object' && "fragments" in ITowns[storename]){ + out[storename] = {} + store = ITowns[storename].fragments + for(var townid in store) { + out[storename][townid] = [] + for(var i = 0; i < store[townid].models.length;i++){ + out[storename][townid].push(store[townid].models[i].attributes) + } + } + } + } + return out +} + +function makeObject() { + out = {} + for(var townid in ITowns.towns) { + out[townid] = {} + out[townid].name = ITowns.towns[townid].name + out[townid].points = ITowns.towns[townid].points + out[townid].god = ITowns.towns[townid].god() + out[townid].unitsTotal = ITowns.towns[townid].units() + out[townid].supportTotal = ITowns.towns[townid].unitsSupport() + out[townid].outerTotal = ITowns.towns[townid].unitsOuter() + out[townid].resources = ITowns.towns[townid].resources() + out[townid].buildings = ITowns.towns[townid].getBuildings().getBuildings() + out[townid].researches = ITowns.towns[townid].researches().attributes + out[townid].espstorage = ITowns.towns[townid].getEspionageStorage() + + orderz = ITowns.towns[townid].buildingOrders() + out[townid].buildingOrders = [] + for(var i = 0; i