Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        /// <summary>
        /// Determines the number of edges of the hex that fall outside the
        /// existing map.
        /// </summary>
        /// <param name="hex"></param>
        /// <returns></returns>
        public int NumberOutsideEdges(HexData hex)
        {
            int numOuterEdges = 0;

            for (int i = 0; i < 6; ++i)
            {
                int index          = i + 1;
                var neighborCoords = hex.FindNeighborByIndex(index);
                var neighbor       = GetHexByCoordinates(neighborCoords.Item1,
                                                         neighborCoords.Item2);
                if (neighbor == null)
                {
                    ++numOuterEdges;
                }
            }
            return(numOuterEdges);
        }
Esempio n. 3
0
        /// <summary>
        /// Losers of a battle will try to search their home hex for a like
        /// race to join, or and adjacent hex if that fails.
        /// If that fails, they are eliminated.
        /// </summary>
        /// <param name="losers"></param>
        /// <param name="loserHome"></param>
        /// <param name="baseName">The name of the home base that the refugees
        /// just left. They can't go back here.</param>
        void MoveLosers(Civilization losers, HexData loserHome,
                        string baseName)
        {
            bool isFoundHex = RefugeesSearchHex(losers, loserHome, baseName);

            if (isFoundHex)
            {
                return;
            }
            int  nextIndex = _dice.Roll(1, 6);
            bool isFound   = false;

            for (int i = 0; i < 6; ++i)
            {
                ++nextIndex;
                if (nextIndex > 6)
                {
                    nextIndex = 1;
                }
                var nextCoords = loserHome.FindNeighborByIndex(nextIndex);
                var nextHex    = _worldMap.GetHexByCoordinates(nextCoords.Item1,
                                                               nextCoords.Item2);
                if (nextHex is null)
                {
                    continue;
                }
                isFound = RefugeesSearchHex(losers, nextHex, baseName);
                if (isFound)
                {
                    break;
                }
            }
            if (isFound)
            {
                return;
            }

            // no available place to go!
            string report = "The " + losers.GetPluralName()
                            + " could not find refuge.";

            losers.History.addRecord(report);

            losers.DissolvePopulation();
        }