public void Add(Settler settler)
 {
     settler.Setup();
     Settlers.Add(settler);
     if (!Families.Contains(settler.Family))
     {
         Families.Add(settler.Family);
     }
 }
 public void Add(Family family)
 {
     Families.Add(family);
     foreach (var member in family.Members)
     {
         member.Setup();
         Settlers.Add(member);
     }
 }
Beispiel #3
0
        public void GenerateSettlers()
        {
            for (var i = 0; i < 9; i++)
            {
                Settlers.Add(new Settler("settler" + i));
            }

            var families = new[] { new Family("Family0"), new Family("Family1"), new Family("Family2") };
            var family   = 0;

            foreach (var settler in Settlers)
            {
                families[family].Add(settler);
                family = (family + 1) % 3;
            }
        }
Beispiel #4
0
        private void CreateCity()
        {
            if (_unit != null && !(_unit is Settlers))
            {
                Error("SETTLERS");
                EndTask();
                return;
            }

            Settlers settlers = (_unit as Settlers);

            if (settlers != null)
            {
                _player = settlers.Player;
                _x      = settlers.X;
                _y      = settlers.Y;
            }

            if (Map[_x, _y].IsOcean)
            {
                EndTask();
                return;
            }

            if (Map[_x, _y].City != null)
            {
                // There is already a city here
                if (_unit is Settlers)
                {
                    if (Map[_x, _y].City.Size >= 10)
                    {
                        // City is 10 or larger, can not join city
                        Error("ADDCITY");
                        EndTask();
                        return;
                    }
                    Map[_x, _y].City.Size++;
                    Game.DisbandUnit(_unit);
                }
                EndTask();
                return;
            }

            CreateCity(_player, _x, _y);
        }
Beispiel #5
0
        internal static void CityProduction(City city)
        {
            if (city == null || city.Size == 0 || city.Tile == null)
            {
                return;
            }

            Player      player     = Game.GetPlayer(city.Owner);
            IProduction production = null;

            // Create 2 defensive units per city
            if (player.HasAdvance <LaborUnion>())
            {
                if (city.Tile.Units.Count(x => x is MechInf) < 2)
                {
                    production = new MechInf();
                }
            }
            else if (player.HasAdvance <Conscription>())
            {
                if (city.Tile.Units.Count(x => x is Riflemen) < 2)
                {
                    production = new Riflemen();
                }
            }
            else if (player.HasAdvance <Gunpowder>())
            {
                if (city.Tile.Units.Count(x => x is Musketeers) < 2)
                {
                    production = new Musketeers();
                }
            }
            else if (player.HasAdvance <BronzeWorking>())
            {
                if (city.Tile.Units.Count(x => x is Phalanx) < 2)
                {
                    production = new Phalanx();
                }
            }
            else
            {
                if (city.Tile.Units.Count(x => x is Militia) < 2)
                {
                    production = new Militia();
                }
            }

            // Create city improvements
            if (production == null)
            {
                if (!city.HasBuilding <Barracks>())
                {
                    production = new Barracks();
                }
                else if (player.HasAdvance <Pottery>() && !city.HasBuilding <Granary>())
                {
                    production = new Granary();
                }
                else if (player.HasAdvance <CeremonialBurial>() && !city.HasBuilding <Temple>())
                {
                    production = new Temple();
                }
                else if (player.HasAdvance <Masonry>() && !city.HasBuilding <CityWalls>())
                {
                    production = new CityWalls();
                }
            }

            // Create Settlers
            if (production == null)
            {
                if (city.Size > 3 && !city.Units.Any(x => x is Settlers) && player.Cities.Length < 10)
                {
                    production = new Settlers();
                }
            }

            // Create some other unit
            if (production == null)
            {
                if (city.Units.Length < 4)
                {
                    if (player.Government is Republic || player.Government is Democratic)
                    {
                        if (player.HasAdvance <Writing>())
                        {
                            production = new Diplomat();
                        }
                    }
                    else
                    {
                        if (player.HasAdvance <Automobile>())
                        {
                            production = new Armor();
                        }
                        else if (player.HasAdvance <Metallurgy>())
                        {
                            production = new Cannon();
                        }
                        else if (player.HasAdvance <Chivalry>())
                        {
                            production = new Knights();
                        }
                        else if (player.HasAdvance <TheWheel>())
                        {
                            production = new Chariot();
                        }
                        else if (player.HasAdvance <HorsebackRiding>())
                        {
                            production = new Cavalry();
                        }
                        else if (player.HasAdvance <IronWorking>())
                        {
                            production = new Legion();
                        }
                    }
                }
                else
                {
                    if (player.HasAdvance <Trade>())
                    {
                        production = new Caravan();
                    }
                }
            }

            // Set random production
            if (production == null)
            {
                IProduction[] items = city.AvailableProduction.ToArray();
                production = items[Common.Random.Next(items.Length)];
            }

            city.SetProduction(production);
        }
Beispiel #6
0
        private static IUnit CreateUnit(UnitType type, int x, int y)
        {
            IUnit unit;

            switch (type)
            {
            case UnitType.Settlers: unit = new Settlers(); break;

            case UnitType.Militia: unit = new Militia(); break;

            case UnitType.Phalanx: unit = new Phalanx(); break;

            case UnitType.Legion: unit = new Legion(); break;

            case UnitType.Musketeers: unit = new Musketeers(); break;

            case UnitType.Riflemen: unit = new Riflemen(); break;

            case UnitType.Cavalry: unit = new Cavalry(); break;

            case UnitType.Knights: unit = new Knights(); break;

            case UnitType.Catapult: unit = new Catapult(); break;

            case UnitType.Cannon: unit = new Cannon(); break;

            case UnitType.Chariot: unit = new Chariot(); break;

            case UnitType.Armor: unit = new Armor(); break;

            case UnitType.MechInf: unit = new MechInf(); break;

            case UnitType.Artillery: unit = new Artillery(); break;

            case UnitType.Fighter: unit = new Fighter(); break;

            case UnitType.Bomber: unit = new Bomber(); break;

            case UnitType.Trireme: unit = new Trireme(); break;

            case UnitType.Sail: unit = new Sail(); break;

            case UnitType.Frigate: unit = new Frigate(); break;

            case UnitType.Ironclad: unit = new Ironclad(); break;

            case UnitType.Cruiser: unit = new Cruiser(); break;

            case UnitType.Battleship: unit = new Battleship(); break;

            case UnitType.Submarine: unit = new Submarine(); break;

            case UnitType.Carrier: unit = new Carrier(); break;

            case UnitType.Transport: unit = new Transport(); break;

            case UnitType.Nuclear: unit = new Nuclear(); break;

            case UnitType.Diplomat: unit = new Diplomat(); break;

            case UnitType.Caravan: unit = new Caravan(); break;

            default: return(null);
            }
            unit.X         = x;
            unit.Y         = y;
            unit.MovesLeft = unit.Move;
            return(unit);
        }