From 3b3e3a3b512d124ad4e806eb0198aee559cbc3cd Mon Sep 17 00:00:00 2001 From: Mikael Gustavsson Date: Tue, 15 Feb 2022 21:14:42 +0100 Subject: [PATCH] Bugfix: when increasing castle defender count and knights need to come from warehouses, all soldiers from all warehouses would come --- Freeserf.Core/Building.cs | 8 +++++--- Freeserf.Core/Player.cs | 15 +++++++++++++++ Freeserf.Core/PlayerState.cs | 2 ++ 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/Freeserf.Core/Building.cs b/Freeserf.Core/Building.cs index a8e2d50..1caa9aa 100644 --- a/Freeserf.Core/Building.cs +++ b/Freeserf.Core/Building.cs @@ -1923,7 +1923,7 @@ void UpdateCastle() lastKnight.SerfType = bestKnightType; } } - else if (player.CastleKnights < player.CastleKnightsWanted) + else if (player.CastleKnights + player.CastleKnightsRequested < player.CastleKnightsWanted) { var knightType = Serf.Type.None; @@ -1954,8 +1954,10 @@ void UpdateCastle() else { // if we don't have a knight, send one - if (player.TickSendKnightDelay()) + if (player.TickSendKnightDelay()) { + player.IncreaseCastleKnightsRequested(); SendKnightToBuilding(); + } } } else @@ -1967,7 +1969,7 @@ void UpdateCastle() player.IncreaseCastleKnights(); } } - else + else if (player.CastleKnights > player.CastleKnightsWanted) { player.DecreaseCastleKnights(); diff --git a/Freeserf.Core/Player.cs b/Freeserf.Core/Player.cs index 8a79acc..f96248c 100644 --- a/Freeserf.Core/Player.cs +++ b/Freeserf.Core/Player.cs @@ -514,9 +514,15 @@ public void SetKnightOccupation(byte[] values) settings.KnightOccupation[0] = values[i]; } + public void IncreaseCastleKnightsRequested() + { + ++state.CastleKnightsRequested; + } + public void IncreaseCastleKnights() { ++state.CastleKnights; + if ( CastleKnightsRequested > 0 ) --state.CastleKnightsRequested; } public void DecreaseCastleKnights() @@ -1289,6 +1295,8 @@ public byte GetInventoryPriority(Resource.Type type) public uint TotalMilitaryScore => state.TotalMilitaryScore; + public byte CastleKnightsRequested => state.CastleKnightsRequested; + // Update player game state as part of the game progression. public void Update() { @@ -1764,6 +1772,7 @@ public uint WheatMill get => settings.WheatMill; set => settings.WheatMill = (word)value; } + public uint GetWheatMill() { return WheatMill; } static readonly int[] minLevelHut = new int[] { 1, 1, 2, 2, 3 }; @@ -2040,6 +2049,11 @@ public void ReadFrom(SaveReaderText reader) state.CastleScore = (sbyte)reader.Value("castle_score").ReadInt(); state.CastleKnights = (byte)reader.Value("castle_knights").ReadUInt(); settings.CastleKnightsWanted = (byte)reader.Value("castle_knights_wanted").ReadUInt(); + try { + state.CastleKnightsRequested = (byte)reader.Value("castle_knights_requested").ReadUInt(); + } catch { + state.CastleKnightsRequested = 0; //dont break old save games, assume 0 + } } /// @@ -2146,6 +2160,7 @@ public void WriteTo(SaveWriterText writer) writer.Value("castle_knights").Write(state.CastleKnights); writer.Value("castle_knights_wanted").Write(settings.CastleKnightsWanted); + writer.Value("castle_knights_requested").Write(state.CastleKnightsRequested); } } } diff --git a/Freeserf.Core/PlayerState.cs b/Freeserf.Core/PlayerState.cs index 1f89d06..b7ef6e7 100644 --- a/Freeserf.Core/PlayerState.cs +++ b/Freeserf.Core/PlayerState.cs @@ -431,6 +431,8 @@ public dword MilitaryMaxGold } } } + [Data] + public byte CastleKnightsRequested { get; set; } public bool HasCastle {