Skip to content

Commit

Permalink
ImportCiv3.cs: Add support for loading cities in scenarios
Browse files Browse the repository at this point in the history
This still has some limitations, in that it will only work if there is a
"Worker" unit. The `producible` field really should be loading from the
list of unit prototyes, but that can be done later.
  • Loading branch information
TomWerner committed Jan 5, 2025
1 parent b3821b1 commit adfc5c3
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions C7GameData/ImportCiv3.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@

namespace C7GameData {

public class Civ3ExtraInfo
{
public class Civ3ExtraInfo {
public int BaseTerrainFileID;
public int BaseTerrainImageID;
}
Expand Down Expand Up @@ -164,6 +163,7 @@ private SaveGame importBiq(string biqPath, string defaultBiqPath) {
ImportSharedBiqData();
ImportBicLeaders();
ImportBicUnits();
ImportBicCities();

Dictionary<int, Resource> resourcesByIndex = ImportCiv3Resources();
SetMapDimensions(biq, save);
Expand All @@ -173,7 +173,7 @@ private SaveGame importBiq(string biqPath, string defaultBiqPath) {
int i = 0;
foreach (QueryCiv3.Biq.TILE civ3Tile in biq.Tile) {
(int x, int y) = GetMapCoordinates(i, biq.Wmap[0].Width);
Civ3ExtraInfo extra = new Civ3ExtraInfo
Civ3ExtraInfo extra = new Civ3ExtraInfo
{
BaseTerrainFileID = civ3Tile.TextureFile,
BaseTerrainImageID = civ3Tile.TextureLocation,
Expand Down Expand Up @@ -434,6 +434,31 @@ private void ImportSavCities() {
}
}

private void ImportBicCities() {
BiqData theBiq = biq.Unit is null ? defaultBiq : biq;

foreach (CITY city in theBiq.City) {
if (city.Owner < 0 || city.Owner >= save.Players.Count) {
continue;
}
SavePlayer player = save.Players[city.Owner];
SaveCity saveCity = new SaveCity{
id = ids.CreateID("city"),
owner = player.id,
location = new TileLocation(city.X, city.Y),
// TODO: try and get this from the unit prototype
producible = "Worker",
name = city.Name,
size = city.Size,
shieldsStored = 0,
foodStored = 0,
foodNeededToGrow = 20, // HACK: don't know where to find this
// residents = city.Ppod // TODO: load tiles worked from PPOD
};
save.Cities.Add(saveCity);
}
}

private void ImportUnitPrototypes() {
PRTO[] Prto = biq.Prto ?? defaultBiq.Prto;
foreach (PRTO prto in Prto) {
Expand Down

0 comments on commit adfc5c3

Please sign in to comment.