Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix: increasing castle defender count #137

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions Freeserf.Core/Building.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand All @@ -1967,7 +1969,7 @@ void UpdateCastle()
player.IncreaseCastleKnights();
}
}
else
else if (player.CastleKnights > player.CastleKnightsWanted)
{
player.DecreaseCastleKnights();

Expand Down
15 changes: 15 additions & 0 deletions Freeserf.Core/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()
{
Expand Down Expand Up @@ -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 };
Expand Down Expand Up @@ -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
}
}

/// <summary>
Expand Down Expand Up @@ -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);
}
}
}
2 changes: 2 additions & 0 deletions Freeserf.Core/PlayerState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,8 @@ public dword MilitaryMaxGold
}
}
}
[Data]
public byte CastleKnightsRequested { get; set; }

public bool HasCastle
{
Expand Down