diff --git a/src/main/java/com/bernard/greposimu/controller/SchedulerController.java b/src/main/java/com/bernard/greposimu/controller/SchedulerController.java index 233239f..b568a4c 100644 --- a/src/main/java/com/bernard/greposimu/controller/SchedulerController.java +++ b/src/main/java/com/bernard/greposimu/controller/SchedulerController.java @@ -8,19 +8,18 @@ import java.util.stream.Collectors; import org.springframework.http.MediaType; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; -import org.springframework.util.MultiValueMap; import org.springframework.web.bind.annotation.CrossOrigin; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; import com.bernard.greposimu.GrepoSimuApplication; import com.bernard.greposimu.model.game.GameConfig; import com.bernard.greposimu.model.simulator.Ville; import com.bernard.greposimu.model.simulator.command.Command; +import com.bernard.greposimu.model.simulator.command.TownCommand; import com.bernard.greposimu.model.simulator.SimulatorData; import com.bernard.greposimu.model.simulator.objective.TownObjective; import com.bernard.greposimu.source.JSONSourcer; @@ -57,10 +56,20 @@ public class SchedulerController { StringBuilder out = new StringBuilder(); for(Ville v : sd.getVilles().values()) { out.append("

==== Ville "+v.getNom()+" ====

\n"); + out.append(""); } - - model.addAttribute("content",out.toString()); + model.addAttribute("raw",out.toString()); return "debug"; } diff --git a/src/main/java/com/bernard/greposimu/controller/SimulatorController.java b/src/main/java/com/bernard/greposimu/controller/SimulatorController.java index c4a627d..158f6b9 100644 --- a/src/main/java/com/bernard/greposimu/controller/SimulatorController.java +++ b/src/main/java/com/bernard/greposimu/controller/SimulatorController.java @@ -11,7 +11,6 @@ import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.ModelAttribute; -import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestParam; import com.bernard.greposimu.GrepoSimuApplication; diff --git a/src/main/java/com/bernard/greposimu/engine/game/Fight.java b/src/main/java/com/bernard/greposimu/engine/game/Fight.java index 770d8bc..51ffc4d 100644 --- a/src/main/java/com/bernard/greposimu/engine/game/Fight.java +++ b/src/main/java/com/bernard/greposimu/engine/game/Fight.java @@ -7,7 +7,6 @@ import com.bernard.greposimu.model.DefContext; import com.bernard.greposimu.model.FightStats; import com.bernard.greposimu.model.OffContext; import com.bernard.greposimu.model.game.GameConfig; -import com.bernard.greposimu.model.game.researches.Research; import com.bernard.greposimu.model.game.units.FightType; import com.bernard.greposimu.model.game.units.NavalUnit; import com.bernard.greposimu.model.game.units.TerrestrialUnit; diff --git a/src/main/java/com/bernard/greposimu/model/game/Resources.java b/src/main/java/com/bernard/greposimu/model/game/Resources.java index fdf278b..31751f0 100644 --- a/src/main/java/com/bernard/greposimu/model/game/Resources.java +++ b/src/main/java/com/bernard/greposimu/model/game/Resources.java @@ -23,5 +23,14 @@ public class Resources { public int getIron() { return iron; } + + public Resources prod(double p){ + return new Resources((int)p*wood, (int)p*stone, (int)p*iron); + } + + @Override + public String toString() { + return "["+this.wood+";"+this.stone+";"+this.iron+"]"; + } } diff --git a/src/main/java/com/bernard/greposimu/model/game/researches/Research.java b/src/main/java/com/bernard/greposimu/model/game/researches/Research.java index d4d9f22..2c0ef93 100644 --- a/src/main/java/com/bernard/greposimu/model/game/researches/Research.java +++ b/src/main/java/com/bernard/greposimu/model/game/researches/Research.java @@ -62,5 +62,4 @@ public class Research implements Identified{ return researchPoints; } - } diff --git a/src/main/java/com/bernard/greposimu/model/simulator/SimulatorData.java b/src/main/java/com/bernard/greposimu/model/simulator/SimulatorData.java index a274148..4a670bf 100644 --- a/src/main/java/com/bernard/greposimu/model/simulator/SimulatorData.java +++ b/src/main/java/com/bernard/greposimu/model/simulator/SimulatorData.java @@ -4,19 +4,22 @@ import java.util.Map; public class SimulatorData { - Map villes; + Map villes; Joueureuse joueureuse; - public SimulatorData(Map villes, Joueureuse joueureuse) { - super(); + public SimulatorData(Map villes, Joueureuse joueureuse) { this.villes = villes; this.joueureuse = joueureuse; } - public Map getVilles() { + public Map getVilles() { return villes; } + + public Ville getVille(int id) { + return villes.get(id); + } public Joueureuse getJoueureuse() { return joueureuse; 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 670cb8e..d53af37 100644 --- a/src/main/java/com/bernard/greposimu/model/simulator/Ville.java +++ b/src/main/java/com/bernard/greposimu/model/simulator/Ville.java @@ -176,6 +176,10 @@ public class Ville { return researches; } + public boolean hasResearch(Research r) { + return researches.contains(r); + } + public List getResearchQueue() { return researchQueue; } 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 index d4f0cca..c09caac 100644 --- a/src/main/java/com/bernard/greposimu/model/simulator/command/BuildCommand.java +++ b/src/main/java/com/bernard/greposimu/model/simulator/command/BuildCommand.java @@ -1,7 +1,9 @@ package com.bernard.greposimu.model.simulator.command; import com.bernard.greposimu.model.game.Building; +import com.bernard.greposimu.model.game.GameConfig; import com.bernard.greposimu.model.game.Resources; +import com.bernard.greposimu.model.simulator.SimulatorData; public class BuildCommand extends TownCommand { @@ -12,9 +14,8 @@ public class BuildCommand extends TownCommand { boolean tearingDown; - public BuildCommand(int town, Resources need, Building building, int level, boolean tearingDown) { - this.town = town; - this.need = need; + public BuildCommand(GameConfig gc, int town, Building building, int level, boolean tearingDown) { + super(gc,town); this.building = building; this.level = level; this.tearingDown = tearingDown; @@ -27,5 +28,17 @@ public class BuildCommand extends TownCommand { else return "[%d] Build %s from %d -> %d".formatted(this.town,this.building.name(),this.level-1,this.level); } + + @Override + public Resources neededResources(SimulatorData sd) { + // TODO Auto-generated method stub + return new Resources(1000, 1000, 1000); + } + + @Override + public int timeNeeded(SimulatorData sd) { + // TODO Auto-generated method stub + return 3600; + } } 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 index 12446ac..0184feb 100644 --- a/src/main/java/com/bernard/greposimu/model/simulator/command/Command.java +++ b/src/main/java/com/bernard/greposimu/model/simulator/command/Command.java @@ -1,5 +1,16 @@ package com.bernard.greposimu.model.simulator.command; +import com.bernard.greposimu.model.game.GameConfig; +import com.bernard.greposimu.model.simulator.SimulatorData; + public abstract class Command { + GameConfig gc; + + public Command(GameConfig gc) { + this.gc = gc; + } + + public abstract int timeNeeded(SimulatorData sd); + } 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 index d3e6c6d..029af32 100644 --- a/src/main/java/com/bernard/greposimu/model/simulator/command/HideStoreCommand.java +++ b/src/main/java/com/bernard/greposimu/model/simulator/command/HideStoreCommand.java @@ -1,11 +1,15 @@ package com.bernard.greposimu.model.simulator.command; +import com.bernard.greposimu.model.game.GameConfig; +import com.bernard.greposimu.model.game.Resources; +import com.bernard.greposimu.model.simulator.SimulatorData; + public class HideStoreCommand extends TownCommand { int amount; - public HideStoreCommand(int town, int amount) { - this.town = town; + public HideStoreCommand(GameConfig gc, int town, int amount) { + super(gc,town); this.amount = amount; } @@ -13,5 +17,15 @@ public class HideStoreCommand extends TownCommand { public String toString() { return "[%d] Store %d iron in the hide".formatted(this.town,this.amount); } - + + @Override + public Resources neededResources(SimulatorData sd) { + return new Resources(0, 0, this.amount); + } + + @Override + public int timeNeeded(SimulatorData sd) { + return 0; + } + } 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 index bcefecc..c5d0a73 100644 --- a/src/main/java/com/bernard/greposimu/model/simulator/command/RecruitCommand.java +++ b/src/main/java/com/bernard/greposimu/model/simulator/command/RecruitCommand.java @@ -1,16 +1,19 @@ package com.bernard.greposimu.model.simulator.command; +import com.bernard.greposimu.model.game.Building; +import com.bernard.greposimu.model.game.GameConfig; import com.bernard.greposimu.model.game.Resources; import com.bernard.greposimu.model.game.units.Unit; +import com.bernard.greposimu.model.simulator.SimulatorData; +import com.bernard.greposimu.model.simulator.Ville; 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; + public RecruitCommand(GameConfig gc,int town, Unit unit, int count) { + super(gc,town); this.unit = unit; this.count = count; } @@ -19,5 +22,30 @@ public class RecruitCommand extends TownCommand{ public String toString() { return "[%d] Recruit %d %s".formatted(this.town,this.count, this.unit.getName()); } + + @Override + public Resources neededResources(SimulatorData sd) { + Resources base = this.unit.getBuildCost(); + Ville v = sd.getVille(town); + double percentage = 1.0; + //TODO take heroes into account, generalize resarches + if(v.hasResearch(gc.getResearch("conscription"))) + percentage -= .1; + return base.prod(percentage*count); + } + + @Override + public int timeNeeded(SimulatorData sd) { + int base = this.unit.getBuildTime(); + Ville v = sd.getVille(town); + double percentage = 1.0; + //TODO take heroes into account, generalize resarches + if(v.hasResearch(gc.getResearch("instructor"))) + percentage -= .1; + //TODO move this code in gameconfig + //TODO use the real application computation (helpers/general_modifications.js:221) + percentage -= Math.pow(v.getBatiments().get(Building.BARRACKS) - 1, 1.1) / 100; + return (int) (base * percentage * count); + } } 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 index 39fbb3b..8e0f15d 100644 --- a/src/main/java/com/bernard/greposimu/model/simulator/command/ResearchCommand.java +++ b/src/main/java/com/bernard/greposimu/model/simulator/command/ResearchCommand.java @@ -1,15 +1,16 @@ package com.bernard.greposimu.model.simulator.command; +import com.bernard.greposimu.model.game.GameConfig; import com.bernard.greposimu.model.game.Resources; import com.bernard.greposimu.model.game.researches.Research; +import com.bernard.greposimu.model.simulator.SimulatorData; 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; + public ResearchCommand(GameConfig gc, int town, Resources need, Research research, boolean forget) { + super(gc,town); this.research = research; this.forget = forget; } @@ -21,5 +22,19 @@ public class ResearchCommand extends TownCommand { else return "[%d] Research %s".formatted(this.town,this.research.getName()); } + + @Override + public Resources neededResources(SimulatorData sd) { + //TODO take into account other modifiers (heroes zB) + //TODO take forgetting into account + return research.getResources(); + } + + @Override + public int timeNeeded(SimulatorData sd) { + //TODO take into account other modifiers (heroes zB) + //TODO take forgetting into account + return research.getRequiredTime(); + } } 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 index c483dba..9b27d1f 100644 --- a/src/main/java/com/bernard/greposimu/model/simulator/command/TownCommand.java +++ b/src/main/java/com/bernard/greposimu/model/simulator/command/TownCommand.java @@ -1,11 +1,17 @@ package com.bernard.greposimu.model.simulator.command; +import com.bernard.greposimu.model.game.GameConfig; import com.bernard.greposimu.model.game.Resources; +import com.bernard.greposimu.model.simulator.SimulatorData; public abstract class TownCommand extends Command { int town; + + public TownCommand(GameConfig gc, int town) { + super(gc); + this.town = town; + } - Resources need; - + public abstract Resources neededResources(SimulatorData sd); } 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 index ceab138..4fb8692 100644 --- a/src/main/java/com/bernard/greposimu/model/simulator/objective/TownObjective.java +++ b/src/main/java/com/bernard/greposimu/model/simulator/objective/TownObjective.java @@ -72,10 +72,10 @@ public class TownObjective { if(cur != obj) { if(obj>cur) for(int i=cur+1;i<=obj;i++) - commands.add(new BuildCommand(v.getId(), null, b, i, false)); + commands.add(new BuildCommand(gc,v.getId(), b, i, false)); else for(int i=cur-1;i>=obj;i--) - commands.add(new BuildCommand(v.getId(), null, b, i, true)); + commands.add(new BuildCommand(gc,v.getId(), b, i, true)); } //TODO check queue } @@ -84,9 +84,9 @@ public class TownObjective { boolean cur = v.getResearches().contains(r); boolean obj = this.researches.contains(r); if(cur && !obj) - commands.add(new ResearchCommand(v.getId(),null,r,true)); + commands.add(new ResearchCommand(gc,v.getId(),null,r,true)); else if (!cur && obj) - commands.add(new ResearchCommand(v.getId(),null,r,false)); + commands.add(new ResearchCommand(gc,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()))); @@ -94,12 +94,12 @@ public class TownObjective { 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)); + commands.add(new RecruitCommand(gc,v.getId(), u, diff)); //TODO manage unit removal planned } if(v.getPiecesStoquees() < hide) - commands.add(new HideStoreCommand(v.getId(), hide - v.getPiecesStoquees())); + commands.add(new HideStoreCommand(gc,v.getId(), hide - v.getPiecesStoquees())); return commands; } diff --git a/src/main/java/com/bernard/greposimu/source/JSONSourcer.java b/src/main/java/com/bernard/greposimu/source/JSONSourcer.java index f135e0a..436eca1 100644 --- a/src/main/java/com/bernard/greposimu/source/JSONSourcer.java +++ b/src/main/java/com/bernard/greposimu/source/JSONSourcer.java @@ -10,7 +10,6 @@ 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; @@ -66,7 +65,7 @@ public class JSONSourcer { try { SourcedData sd = om.readValue(json, SourcedData.class); - Map villes = new HashMap(); + Map villes = new HashMap<>(); for(String idS : sd.towns.keySet()) { Integer id = Integer.parseInt(idS); SourcedTown st = sd.getTowns().get(idS); @@ -139,7 +138,7 @@ public class JSONSourcer { } Set townCele = sd.celebrations.stream().filter(c -> c.getTown() == id).collect(Collectors.toSet()); - villes.put(st.name, new Ville( + villes.put(id, new Ville( id, st.name, buildings, diff --git a/src/main/resources/templates/debug.html b/src/main/resources/templates/debug.html index 726bdca..3288618 100644 --- a/src/main/resources/templates/debug.html +++ b/src/main/resources/templates/debug.html @@ -16,6 +16,7 @@ body {

+