/// <summary> /// New monsters move in from the edge of the map. /// </summary> /// <param name="hex"></param> public void ResolveOutsideSingleHexMigration(HexData hex) { // only for edge chances int numEdges = _worldMap.NumberOutsideEdges(hex); if (numEdges <= 0) { return; } // "5% chance per edge" int chance = numEdges * 5; int roll = _dice.Roll(1, 100); if (roll > chance) { return; } // Are they invaders, or settlers? var invaders = new Civilization(); invaders.InitializeAsRandomCiv(hex.Tier); // Depends on where they land: int subHexLoc = _dice.Roll(1, HexData.SUB_HEXES); var results = ResolveInvasionConflicts(hex, invaders, subHexLoc); if (results is null) { // no battle. settle in unclaimed land. var lair = new Lair(); lair.InitializeAsSettlerLair(invaders, subHexLoc, hex); lair.Treasure = 1; hex.LairList.Add(lair); return; } if ( (results.AttackerState == Battle.CombatantState.COMBATANT_STATE_ELIMINATED) || (results.AttackerState == Battle.CombatantState.COMBATANT_STATE_ROUTED) ) { // invaders have been dealt with. return; } // else the invaders win, and have been moved into their new lair. }
private void _doMigration(Lair lair, HexData hex) { if (lair.IsRuins()) { return; } string record = "The " + lair.HomeCiv.GetPluralName() + " are migrating to a new home."; lair.HomeCiv.History.addRecord(record); HexData targetHex; do { int migrationDirection = _dice.Roll(1, 6); var neighborLocation = hex.FindNeighborByIndex(migrationDirection); targetHex = _worldMap.GetHexByCoordinates(neighborLocation); } while (targetHex is null); int subHexIndex = _dice.Roll(1, HexData.SUB_HEXES); var existingLair = targetHex.GetLairAtLocation(subHexIndex); if (existingLair is null) { // Free real estate! var newLair = new Lair(); newLair.InitializeAsSettlerLair(lair.HomeCiv, subHexIndex, targetHex); targetHex.LairList.Add(newLair); lair.ForceAbandon(); // move the treasure newLair.Treasure = lair.Treasure; lair.Treasure = 0; return; } // Going to have to fight for the space. var battle = new Battle(_worldMap); battle.ResolveBattle(hex, targetHex, lair, existingLair); }