Skip to content

Commit

Permalink
Properly import known technologies when loading saves/scenarios
Browse files Browse the repository at this point in the history
  • Loading branch information
TomWerner committed Jan 29, 2025
1 parent 8dcd00f commit 6e890f6
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
2 changes: 1 addition & 1 deletion C7GameData/Civilization.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ public Civilization(string name) {
public List<string> cityNames = new List<string>();

// The IDs of all the techs that this civ starts with.
public List<ID> startingTechs = new();
public HashSet<ID> startingTechs = new();
}
}
29 changes: 28 additions & 1 deletion C7GameData/ImportCiv3.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using QueryCiv3;
using QueryCiv3.Biq;
using C7GameData.Save;
using System.IO;

/*
This will read a Civ3 sav into C7 native format for immediate use or saving to native JSON save
Expand Down Expand Up @@ -370,6 +369,13 @@ private void ImportBicLeaders() {
// Put the player in the correct starting era.
player.eraCivilopediaName = theBiq.Eras[lead.InitialEra].CivilopediaEntry;

// Add the starting techs for scenarios.
if (theBiq.LeadTech != null) {
for (int j = 0; j < theBiq.LeadTech[leadIndex].Length; ++j) {
player.knownTechs.Add(save.Techs[theBiq.LeadTech[leadIndex][j]].id);
}
}

// Mark the first human playable civ as the human player.
if (lead.HumanPlayer == 1 && !foundHuman) {
player.human = true;
Expand All @@ -394,9 +400,17 @@ private void ImportSavLeaders() {
/*cityNameIndex=*/leader.FoundedCities,
/*era=*/theBiq.Eras[leader.Era].CivilopediaEntry);


// TODO: store non-negative values of leader.Researching,
// which indexes into save.Techs.

// Record any techs that this player knows.
for (int k = 0; k < savData.KnownTechFlags.Length; ++k) {
if (savData.KnownTechFlags[k][i]) {
player.knownTechs.Add(save.Techs[k].id);
}
}

save.Players.Add(player);
i++;
}
Expand Down Expand Up @@ -706,6 +720,19 @@ private void ImportTechs() {
if (race.FreeTech4 > -1) {
sc.startingTechs.Add(save.Techs[race.FreeTech4].id);
}

// Remove any invalid starting techs. Some scenarios like
// Fall of Rome give starting techs without giving all of the
// prereqs, so they should be ignored.
sc.startingTechs.RemoveWhere(t => {
SaveTech st = save.Techs.Find(x => x.id == t);
foreach (ID prereqId in st.Prerequisites) {
if (!sc.startingTechs.Contains(prereqId)) {
return true;
}
}
return false;
});
}
}

Expand Down
1 change: 1 addition & 0 deletions QueryCiv3/Sav.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public unsafe class SavData {
public CLNY[] Clny;

public int[] CitiesPerContinent;
// Bit k of element i means that civ k knows tech i.
public IntBitmap[] KnownTechFlags;
public int[] GreatWonderCityIDs;
public bool[] GreatWondersBuilt;
Expand Down

0 comments on commit 6e890f6

Please sign in to comment.