From adfc5c3ce9826d07b426f3ead392dd9a64971db2 Mon Sep 17 00:00:00 2001 From: Tom Date: Sun, 5 Jan 2025 13:32:50 -0600 Subject: [PATCH] ImportCiv3.cs: Add support for loading cities in scenarios 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. --- C7GameData/ImportCiv3.cs | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/C7GameData/ImportCiv3.cs b/C7GameData/ImportCiv3.cs index 1d82e43a..d35c0920 100644 --- a/C7GameData/ImportCiv3.cs +++ b/C7GameData/ImportCiv3.cs @@ -12,8 +12,7 @@ namespace C7GameData { - public class Civ3ExtraInfo - { + public class Civ3ExtraInfo { public int BaseTerrainFileID; public int BaseTerrainImageID; } @@ -164,6 +163,7 @@ private SaveGame importBiq(string biqPath, string defaultBiqPath) { ImportSharedBiqData(); ImportBicLeaders(); ImportBicUnits(); + ImportBicCities(); Dictionary resourcesByIndex = ImportCiv3Resources(); SetMapDimensions(biq, save); @@ -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, @@ -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) {