Example #1
0
        /// <summary>
        /// 初始化城市
        /// </summary>
        private void LoadCities()
        {
            List <City> cityList = new List <City>(MaxCities);

            FileLocation      fl     = FileSystem.Instance.Locate("cities.xml", GameFileLocs.Config);
            GameConfiguration resCon = new GameConfiguration(fl);

            GameConfiguration.ValueCollection resVals      = resCon.Values;
            Dictionary <string, City>         resolveTable = new Dictionary <string, City>(MaxCities);

            foreach (GameConfigurationSection sect in resVals)
            {
                City   city;
                string typestr = sect.GetString("Type", string.Empty).ToLowerInvariant();

                CityType type = City.ParseType(typestr);

                switch (type)
                {
                case CityType.Neutral:
                    city = new City(this, null, type);
                    break;

                case CityType.Oil:
                case CityType.Green:
                    city = new GatherCity(this, null, type);
                    break;

                case CityType.Disease:
                case CityType.Education:
                case CityType.Health:
                case CityType.Volience:
                    city = new ProductionCity(this, null, type);
                    break;

                default:
                    city = new City(this, null, type);
                    break;
                }

                city.Parse(sect);

                resolveTable.Add(sect.Name, city);
                cityList.Add(city);
            }

            for (int i = 0; i < cityList.Count; i++)
            {
                cityList[i].ResolveCities(resolveTable);
            }

            cities = cityList.ToArray();
        }
Example #2
0
        public Game(Code2015 game, GameCreationParameters gcp)
        {
            this.game       = game;
            this.renderSys  = game.RenderSystem;
            this.parameters = gcp;
            this.soundWorld = new SoundObjectWorld();

            gameState = new GameState(GetLocalPlayers(gcp));

            BattleField field = gameState.Field;

            // 初始化场景
            this.scene = new GameScene(renderSys);



            field.ResourceBallChanged += Field_ResourceBallChanged;

            for (int i = 0; i < field.CityCount; i++)
            {
                City city = field.Cities[i];

                city.InitalizeGraphics(renderSys);
                city.CityVisible += scene.City_Visible;

                GatherCity gaCity = city as GatherCity;
                if (gaCity != null)
                {
                    gaCity.Harvester.InitializeGraphics(renderSys);
                    scene.Scene.AddObjectToScene(gaCity.Harvester);
                }
                scene.Scene.AddObjectToScene(city);
            }

            field.Fog.InitailizeGraphics(renderSys);

            AddResources(field);
            AddScenery(field);

            gameState.InitialStandards();
            {
                HumanPlayer = gameState.LocalHumanPlayer;
                City hstart = HumanPlayer.Area.RootCity;
                this.scene.Camera.Longitude = MathEx.Degree2Radian(hstart.Longitude);
                this.scene.Camera.Latitude  = MathEx.Degree2Radian(hstart.Latitude);
            }
            this.ingameUI = new InGameUI(game, this, scene, gameState);
        }
Example #3
0
        public AIDecisionHelper(BattleField world)
        {
            cityDataTable = new Dictionary <City, CityData>(world.CityCount);

            for (int i = 0; i < world.CityCount; i++)
            {
                City    cc    = world.Cities[i];
                Vector2 myPos = new Vector2(cc.Latitude, cc.Longitude);

                CityData data = new CityData();
                data.city = cc;


                GatherCity gc = cc as GatherCity;

                if (gc != null)
                {
                    data.ResourceCount = gc.GetNearResourceCount();
                }


                //data.NearbyCity = new FastList<City>();
                //for (int j = 0; j < world.CityCount; j++)
                //{
                //    City cc2 = world.GetCity(j);
                //    if (cc != cc2)
                //    {
                //        Vector2 pos = new Vector2(cc2.Latitude, cc2.Longitude);
                //        float dist = Vector2.Distance(pos, myPos);

                //        if (dist < PlayerArea.CaptureDistanceThreshold)
                //        {
                //            data.NearbyCity.Add(cc2);
                //        }
                //    }
                //}
                cityDataTable.Add(cc, data);
            }
        }