Skip to content

Commit 7b76c83

Browse files
committed
20x prod, 10x production
1 parent 5ae242b commit 7b76c83

9 files changed

Lines changed: 73 additions & 6 deletions

File tree

Open Empires/Assets/Scripts/Buildings/BuildingConstructionSystem.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class BuildingConstructionSystem
1414
private static readonly Fixed32 TurnRate = Fixed32.FromFloat(0.3f);
1515
private static readonly Fixed32 FacingThreshold = Fixed32.FromFloat(0.9f); // cos(~26 deg)
1616

17-
public List<int> Tick(UnitRegistry unitRegistry, BuildingRegistry buildingRegistry, MapData mapData, int currentTick, Fixed32 tickDuration, out List<(int unitId, int buildingId)> idledVillagers, out List<int> startedBuildingIds)
17+
public List<int> Tick(UnitRegistry unitRegistry, BuildingRegistry buildingRegistry, MapData mapData, int currentTick, Fixed32 tickDuration, out List<(int unitId, int buildingId)> idledVillagers, out List<int> startedBuildingIds, bool constructionCheatActive = false)
1818
{
1919
completedList.Clear();
2020
startedList.Clear();
@@ -134,7 +134,8 @@ public List<int> Tick(UnitRegistry unitRegistry, BuildingRegistry buildingRegist
134134
}
135135

136136
// In range and facing — do construction work
137-
building.ConstructionTicksRemaining--;
137+
building.ConstructionTicksRemaining -= constructionCheatActive ? 10 : 1;
138+
if (building.ConstructionTicksRemaining < 0) building.ConstructionTicksRemaining = 0;
138139
int ticksElapsed = building.ConstructionTicksTotal - building.ConstructionTicksRemaining;
139140
int targetHealth = (int)((long)building.MaxHealth * ticksElapsed / building.ConstructionTicksTotal);
140141
int prevTarget = (int)((long)building.MaxHealth * (ticksElapsed - 1) / building.ConstructionTicksTotal);

Open Empires/Assets/Scripts/Buildings/BuildingTrainingSystem.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public List<TrainingCompletion> Tick(BuildingRegistry registry, SimulationConfig
2727
if (building.IsDestroyed || !building.IsTraining)
2828
continue;
2929

30-
building.TrainingTicksRemaining -= productionCheatActive ? 10 : 1;
30+
building.TrainingTicksRemaining -= productionCheatActive ? 20 : 1;
3131
if (building.TrainingTicksRemaining <= 0)
3232
{
3333
int pending = 0;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
namespace OpenEmpires
2+
{
3+
public struct CheatConstructionCommand : ICommand
4+
{
5+
public CommandType Type => CommandType.CheatConstruction;
6+
public int PlayerId { get; set; }
7+
8+
public CheatConstructionCommand(int playerId)
9+
{
10+
PlayerId = playerId;
11+
}
12+
}
13+
}

Open Empires/Assets/Scripts/Commands/CheatConstructionCommand.cs.meta

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Open Empires/Assets/Scripts/Commands/ICommand.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public enum CommandType
2424
CheatResource,
2525
CheatProduction,
2626
CheatVision,
27+
CheatConstruction,
2728
DeleteUnits,
2829
DeleteBuilding,
2930
Surrender,

Open Empires/Assets/Scripts/Core/GameBootstrapper.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,10 @@ private void SetCommandPlayerId(ref ICommand cmd, int playerId)
402402
cheatProd.PlayerId = playerId;
403403
cmd = cheatProd;
404404
break;
405+
case CheatConstructionCommand cheatConstruct:
406+
cheatConstruct.PlayerId = playerId;
407+
cmd = cheatConstruct;
408+
break;
405409
case CheatVisionCommand cheatVis:
406410
cheatVis.PlayerId = playerId;
407411
cmd = cheatVis;

Open Empires/Assets/Scripts/Core/GameSimulation.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,7 @@ public string GetSystemHashDetail()
275275
}
276276

277277
public bool ProductionCheatActive { get; private set; }
278+
public bool ConstructionCheatActive { get; private set; }
278279

279280
public int CurrentTick => currentTick;
280281
public SimulationConfig Config => config;
@@ -455,6 +456,7 @@ public uint ComputeStateChecksum()
455456

456457
// Hash cheat state
457458
hash = hash * 31 + (ProductionCheatActive ? 1u : 0u);
459+
hash = hash * 31 + (ConstructionCheatActive ? 1u : 0u);
458460

459461
// Hash meteor state
460462
for (int i = 0; i < pendingMeteors.Count; i++)
@@ -804,7 +806,7 @@ private void RunSystems()
804806
if (hashSystems) lastSystemHashes[7] = ComputeQuickHash(); // after gathering
805807

806808
// Construction system
807-
var completedBuildingIds = constructionSystem.Tick(UnitRegistry, BuildingRegistry, MapData, currentTick, cachedTickDuration, out var idledVillagers, out var startedBuildingIds);
809+
var completedBuildingIds = constructionSystem.Tick(UnitRegistry, BuildingRegistry, MapData, currentTick, cachedTickDuration, out var idledVillagers, out var startedBuildingIds, ConstructionCheatActive);
808810

809811
// When construction first starts on a template, mark tiles non-walkable and eject units
810812
for (int i = 0; i < startedBuildingIds.Count; i++)
@@ -1456,6 +1458,9 @@ private void ProcessCommand(ICommand command)
14561458
case CheatProductionCommand cheatProd:
14571459
ProcessCheatProductionCommand(cheatProd);
14581460
break;
1461+
case CheatConstructionCommand cheatConstruct:
1462+
ProcessCheatConstructionCommand(cheatConstruct);
1463+
break;
14591464
case CheatVisionCommand cheatVis:
14601465
ProcessCheatVisionCommand(cheatVis);
14611466
break;
@@ -2540,6 +2545,11 @@ private void ProcessCheatProductionCommand(CheatProductionCommand cmd)
25402545
ProductionCheatActive = !ProductionCheatActive;
25412546
}
25422547

2548+
private void ProcessCheatConstructionCommand(CheatConstructionCommand cmd)
2549+
{
2550+
ConstructionCheatActive = !ConstructionCheatActive;
2551+
}
2552+
25432553
private void ProcessCheatVisionCommand(CheatVisionCommand cmd)
25442554
{
25452555
bool current = FogOfWar.HasVisionCheat(cmd.PlayerId);

Open Empires/Assets/Scripts/Network/CommandSerializer.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ public static (string commandType, string payload) ToJson(ICommand command)
111111
break;
112112
case CheatResourceCommand:
113113
case CheatProductionCommand:
114+
case CheatConstructionCommand:
114115
case CheatVisionCommand:
115116
payload = "{}";
116117
break;
@@ -151,6 +152,7 @@ public static ICommand FromJson(string commandType, string payload, int playerId
151152
"DeleteBuilding" => ParseDeleteBuildingCommand(payload, playerId),
152153
"CheatResource" => new CheatResourceCommand { PlayerId = playerId },
153154
"CheatProduction" => new CheatProductionCommand { PlayerId = playerId },
155+
"CheatConstruction" => new CheatConstructionCommand { PlayerId = playerId },
154156
"CheatVision" => new CheatVisionCommand { PlayerId = playerId },
155157
"Surrender" => ParseSurrenderCommand(payload, playerId),
156158
"SlaughterSheep" => ParseSlaughterSheepCommand(payload, playerId),
@@ -1151,6 +1153,7 @@ public static byte[] Serialize(List<ICommand> commands, int tick)
11511153
break;
11521154
case CheatResourceCommand:
11531155
case CheatProductionCommand:
1156+
case CheatConstructionCommand:
11541157
case CheatVisionCommand:
11551158
break;
11561159
}
@@ -1323,6 +1326,9 @@ public static (int tick, List<ICommand> commands) Deserialize(byte[] data)
13231326
case CommandType.CheatProduction:
13241327
commands.Add(new CheatProductionCommand { PlayerId = playerId });
13251328
break;
1329+
case CommandType.CheatConstruction:
1330+
commands.Add(new CheatConstructionCommand { PlayerId = playerId });
1331+
break;
13261332
case CommandType.CheatVision:
13271333
commands.Add(new CheatVisionCommand { PlayerId = playerId });
13281334
break;

Open Empires/Assets/Scripts/UI/SettingsMenuUI.cs

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ private void Update()
6767
if (productionCheatLabel == null) return;
6868
var sim = GameBootstrapper.Instance?.Simulation;
6969
bool active = sim != null && sim.ProductionCheatActive;
70-
productionCheatLabel.text = active ? "Prod 10x: ON" : "Prod 10x: OFF";
70+
productionCheatLabel.text = active ? "Prod 20x: ON" : "Prod 20x: OFF";
7171

7272
if (visionCheatLabel != null && sim != null)
7373
{
@@ -1025,10 +1025,40 @@ private void BuildMainSettingsContent(GameObject panelGO, float contentX, float
10251025
revealToggle.SetIsOnWithoutNotify(FogOfWarRenderer.RevealUnexplored);
10261026
revealToggle.onValueChanged.AddListener(value => FogOfWarRenderer.RevealUnexplored = value);
10271027

1028+
// 20x Production toggle — enqueues CheatProductionCommand which flips ProductionCheatActive
1029+
y -= 40f;
1030+
MakeLabel(panelGO.transform, "20x Production", rowX, y, fowLabelW, 24f, 16, FontStyles.Normal, TextAlignmentOptions.Left);
1031+
var prod10xToggle = CreateToggle(panelGO.transform, rowX + fowLabelW + 5f, y, 24f);
1032+
var simForProd = GameBootstrapper.Instance?.Simulation;
1033+
prod10xToggle.SetIsOnWithoutNotify(simForProd != null && simForProd.ProductionCheatActive);
1034+
prod10xToggle.onValueChanged.AddListener(value =>
1035+
{
1036+
var sim = GameBootstrapper.Instance?.Simulation;
1037+
if (sim == null) return;
1038+
if (sim.ProductionCheatActive == value) return;
1039+
int pid = FindFirstObjectByType<UnitSelectionManager>()?.LocalPlayerId ?? 0;
1040+
sim.CommandBuffer.EnqueueCommand(new CheatProductionCommand(pid));
1041+
});
1042+
1043+
// 10x Construction toggle — enqueues CheatConstructionCommand which flips ConstructionCheatActive
1044+
y -= 40f;
1045+
MakeLabel(panelGO.transform, "10x Construction", rowX, y, fowLabelW, 24f, 16, FontStyles.Normal, TextAlignmentOptions.Left);
1046+
var construct10xToggle = CreateToggle(panelGO.transform, rowX + fowLabelW + 5f, y, 24f);
1047+
var simForConstruct = GameBootstrapper.Instance?.Simulation;
1048+
construct10xToggle.SetIsOnWithoutNotify(simForConstruct != null && simForConstruct.ConstructionCheatActive);
1049+
construct10xToggle.onValueChanged.AddListener(value =>
1050+
{
1051+
var sim = GameBootstrapper.Instance?.Simulation;
1052+
if (sim == null) return;
1053+
if (sim.ConstructionCheatActive == value) return;
1054+
int pid = FindFirstObjectByType<UnitSelectionManager>()?.LocalPlayerId ?? 0;
1055+
sim.CommandBuffer.EnqueueCommand(new CheatConstructionCommand(pid));
1056+
});
1057+
10281058
// Cheat buttons
10291059
y -= 50f;
10301060

1031-
var resourcesBtnGO = CreateButtonWithLabel(panelGO.transform, "Resources", 0f, y, 160f, 36f, out _);
1061+
var resourcesBtnGO = CreateButtonWithLabel(panelGO.transform, "Resource Cheat", 0f, y, 160f, 36f, out _);
10321062
var resourcesRT = resourcesBtnGO.GetComponent<RectTransform>();
10331063
resourcesRT.pivot = new Vector2(0.5f, 0.5f);
10341064
resourcesRT.anchoredPosition = new Vector2(contentX - 90f, y);

0 commit comments

Comments
 (0)