Skip to content

Commit e07a91e

Browse files
committed
ImportCiv3: import starting units for scenarios
This improves the start of the mesoamerica scenario, which doesn't specify starting units the way the other scenarios do.
1 parent e48e29a commit e07a91e

File tree

1 file changed

+35
-14
lines changed

1 file changed

+35
-14
lines changed

C7Engine/C7GameData/ImportCiv3.cs

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -542,9 +542,23 @@ private void ImportSavUnits() {
542542
}
543543

544544
private void ImportBicUnits() {
545-
// TODO: This doesn't account for default starting units.
546545
BiqData theBiq = biq.Unit is null ? defaultBiq : biq;
547546

547+
var createUnitAtLocation = (SavePlayer player, int unitType, string experienceLevel, int hitPoints, int x, int y) => {
548+
PRTO prototype = theBiq.Prto[unitType];
549+
SaveUnit saveUnit = new SaveUnit{
550+
id = ids.CreateID(prototype.Name),
551+
owner = player.id,
552+
prototype = prototype.Name,
553+
currentLocation = new TileLocation(x, y),
554+
previousLocation = new TileLocation(x, y),
555+
experience = experienceLevel,
556+
hitPointsRemaining = hitPoints, // TODO: include bonus hitpoints from unit type
557+
movePointsRemaining = (float)prototype.Movement,
558+
};
559+
return saveUnit;
560+
};
561+
548562
foreach (UNIT unit in theBiq.Unit) {
549563
if (unit.Owner >= save.Players.Count) {
550564
continue;
@@ -553,20 +567,27 @@ private void ImportBicUnits() {
553567
// The owner index is into the list of civs, and we have a 1:1
554568
// mapping of players and civs.
555569
SavePlayer player = save.Players[unit.Owner];
556-
557-
PRTO prototype = theBiq.Prto[unit.UnitType];
558570
ExperienceLevel experience = save.ExperienceLevels[unit.ExperienceLevel];
559-
SaveUnit saveUnit = new SaveUnit{
560-
id = ids.CreateID(prototype.Name),
561-
owner = player.id,
562-
prototype = prototype.Name,
563-
currentLocation = new TileLocation(unit.X, unit.Y),
564-
previousLocation = new TileLocation(unit.X, unit.Y),
565-
experience = experience.key,
566-
hitPointsRemaining = experience.baseHitPoints, // TODO: include bonus hitpoints from unit type
567-
movePointsRemaining = (float)prototype.Movement,
568-
};
569-
save.Units.Add(saveUnit);
571+
save.Units.Add(createUnitAtLocation(player, unit.UnitType, experience.key, experience.baseHitPoints, unit.X, unit.Y));
572+
}
573+
574+
RULE rule = theBiq.Rule[0];
575+
foreach (SLOC starting_location in theBiq.Sloc) {
576+
// Skip barbarians
577+
if (starting_location.OwnerType <= 1) {
578+
continue;
579+
}
580+
581+
// The owner index is into the list of civs, and we have a 1:1
582+
// mapping of players and civs.
583+
SavePlayer player = save.Players[starting_location.Owner];
584+
int baseHitPoints = 3;
585+
if (rule.StartUnitType1 >= 0) {
586+
save.Units.Add(createUnitAtLocation(player, rule.StartUnitType1, "Regular", baseHitPoints, starting_location.X, starting_location.Y));
587+
}
588+
if (rule.StartUnitType2 >= 0) {
589+
save.Units.Add(createUnitAtLocation(player, rule.StartUnitType2, "Regular", baseHitPoints, starting_location.X, starting_location.Y));
590+
}
570591
}
571592
}
572593

0 commit comments

Comments
 (0)