Exemple #1
0
        /// <summary>
        /// Gets a random <see cref="GridCell"/> object in the current map.
        /// </summary>
        /// <returns>a random grid cell</returns>
        public GridCell FindRandomCell()
        {
            int x = RandomNumber.UpTo(Size.Width - 1);
            int y = RandomNumber.UpTo(Size.Height - 1);

            return(this.gridCells[x, y]);
        }
        /// <summary>
        /// Gets a <see cref="VillageGoody"/> from the factory.
        /// </summary>
        /// <returns></returns>
        public static VillageGoody GetGoody(Village village, Unit explorer)
        {
            if (village == null)
            {
                throw new ArgumentNullException("village");
            }
            if (explorer == null)
            {
                throw new ArgumentNullException("explorer");
            }

            int          r     = RandomNumber.UpTo(7);
            VillageGoody goody = new EmptyGoody(village.TribeName);

            switch (r)
            {
            case 0:
                goody = new EmptyGoody(village.TribeName);
                break;

            case 1:
                goody = new GoldGoody(village.TribeName, GetGoldAmount());
                break;

            case 2:
                goody = new UnitGoody(village.TribeName, GetUnit(explorer));
                break;

            case 3:
                goody = new SettlerGoody(village.TribeName, GetSettler(explorer));
                break;

            case 4:
                goody = new TechnologyGoody(village.TribeName, GetTechnology(explorer.ParentCountry));
                break;

            case 5:
                goody = new BarbarianGoody(village.TribeName, GetBarbarian(explorer));
                break;

            case 6:
                goody = new CityGoody(village.TribeName, GetCity(village, explorer));
                break;

            case 7:
                goody = new MapGoody(village.TribeName);
                break;
            }

            return(goody);
        }
        /// <summary>
        /// Attempts to steal a random technolgy from the foreign country.
        /// </summary>
        /// <returns></returns>
        public EspionageResult StealTechnology()
        {
            if (!this.hasEmbassy)
            {
                throw new InvalidOperationException(ServerResources.EmbassyRequired);
            }
            if (!this.hasSpy)
            {
                throw new InvalidOperationException(ServerResources.SpyRequired);
            }
            if (this.foreignCountry.Government.Fallback)
            {
                return(EspionageResult.ImmuneToEspionage);
            }
            NamedObjectCollection <Technology> candidateTechs = new NamedObjectCollection <Technology>();
            Technology stolenTech;
            int        randIdx = RandomNumber.UpTo(75);

            if (randIdx >= 75)
            {
                //failure.
                bool spyCaught;
                //50 percent chance of spy being caught
                randIdx   = RandomNumber.UpTo(50);
                spyCaught = (randIdx >= 50);
                if (spyCaught)
                {
                    this.hasSpy = false;
                    this.foreignCountry.CaptureSpy(this, EspionageAction.StealTechnology, false, null);
                    return(EspionageResult.SpyCaught);
                }
                else
                {
                    return(EspionageResult.Failure);
                }
            }

            foreach (Technology foreignTech in this.foreignCountry.AcquiredTechnologies)
            {
                if (!this.parentCountry.AcquiredTechnologies.Contains(foreignTech))
                {
                    candidateTechs.Add(foreignTech);
                }
            }
            randIdx    = RandomNumber.UpTo(candidateTechs.Count - 1);
            stolenTech = candidateTechs[randIdx];
            this.parentCountry.AcquiredTechnologies.Add(stolenTech);
            return(EspionageResult.Success);
        }
Exemple #4
0
        //Returns a Resource reference for the given cell.  Chances are,
        //this will be null.
        private Resource FindResourceForCell(GridCell cell)
        {
            int      randResult = RandomNumber.UpTo(10);
            Resource resouce    = null;

            if (randResult == 5)    //10% chance of this happening.
            {
                List <Resource> possibleResources = FindPossibleResourcesForTerrain(cell.Terrain);

                if (possibleResources.Count > 0)
                {
                    int index = RandomNumber.Between(0, possibleResources.Count - 1);
                    resouce = possibleResources[index];
                }
            }
            return(resouce);
        }
Exemple #5
0
        /// <summary>
        ///	Gets a random land-based cell on the map.
        /// </summary>
        /// <returns></returns>
        public GridCell FindRandomDryCell()
        {
            int idx = RandomNumber.UpTo(this.dryCells.Count - 1);

            return(this.dryCells[idx]);
        }