Esempio n. 1
0
        void buttonpressed(object o, EventArgs args)
        {
            Button thisbutton = o as Button;

            Highlight(thisbutton);
            foreach (Button button in buttons)
            {
                Unhighlight(button);
            }

            string unitname = thisbutton.Name;

            LogFile.GetInstance().WriteLine(o.ToString() + " " + unitname + " pressed");

            if (!UnitCache.GetInstance().UnitsByName.ContainsKey(unitname))
            {
                Unit unit = new S3oLoader().LoadS3o("objects3d" + "/" + unitname + ".s3o");
                UnitCache.GetInstance().UnitsByName.Add(unitname, unit);
            }
            (BrushEffectController.GetInstance().brusheffects[typeof(AddFeature)] as AddFeature)
            .currentfeature = UnitCache.GetInstance().UnitsByName[unitname];
        }
Esempio n. 2
0
        public void LoadFeatures(string featurelistfilename, string featuredatafilename)
        {
            LogFile.GetInstance().WriteLine("LoadFeatures()");
            TdfParser tdfparser = TdfParser.FromFile(featurelistfilename);
            Terrain   terrain   = Terrain.GetInstance();

            terrain.FeatureMap = new Unit[terrain.MapWidth, terrain.MapHeight];
            Dictionary <int, string> featurenamebynumber = new Dictionary <int, string>();
            int numfeaturetypes = tdfparser.RootSection.GetIntValue("map/featuretypes/numtypes");

            LogFile.GetInstance().WriteLine("Num types: " + numfeaturetypes);
            for (int i = 0; i < numfeaturetypes; i++)
            {
                string featurename = tdfparser.RootSection.GetStringValue("map/featuretypes/type" + i);
                if (!File.Exists(Path.Combine("objects3d", featurename + ".s3o")))
                {
                    MainUI.GetInstance().uiwindow.WarningMessage("Warning: objects3d/" + featurename + ".s3o not found");
                }
                else
                {
                    LogFile.GetInstance().WriteLine("Feature type " + i + " " + featurename.ToLower());
                    featurenamebynumber.Add(i, featurename.ToLower());
                }
            }

            List <Sm3Feature> features = new List <Sm3Feature>();

            // from FeaturePlacer Form1.cs by Jelmer Cnossen
            FileStream fs = new FileStream(featuredatafilename, FileMode.Open);

            if (fs != null)
            {
                BinaryReader br = new BinaryReader(fs);
                if (br.ReadByte() != 0)
                {
                    MainUI.GetInstance().uiwindow.WarningMessage("The featuredata you are trying to load was saved using a different version.");
                    return;
                }

                int numFeatures = br.ReadInt32();
                features.Clear();
                for (int a = 0; a < numFeatures; a++)
                {
                    Sm3Feature f = new Sm3Feature();
                    features.Add(f);
                    f.type     = br.ReadInt32();
                    f.x        = br.ReadSingle();
                    f.y        = br.ReadSingle();
                    f.z        = br.ReadSingle();
                    f.rotation = br.ReadSingle();
                }
            }

            foreach (Sm3Feature sm3feature in features)
            {
                if (featurenamebynumber.ContainsKey(sm3feature.type))
                {
                    string featurename = featurenamebynumber[sm3feature.type].ToLower();
                    if (!UnitCache.GetInstance().UnitsByName.ContainsKey(featurename))
                    {
                        LogFile.GetInstance().WriteLine("Loading unit " + Path.Combine("objects3d", featurename + ".s3o") + " ... ");
                        Unit unit = new S3oLoader().LoadS3o(Path.Combine("objects3d", featurename + ".s3o"));
                        UnitCache.GetInstance().UnitsByName.Add(featurename, unit);
                    }
                    LogFile.GetInstance().WriteLine("Adding " + featurename + " at " + (int)(sm3feature.x / Terrain.SquareSize) + " " + (int)(sm3feature.y / Terrain.SquareSize));
                    terrain.FeatureMap[(int)(sm3feature.x / Terrain.SquareSize), (int)(sm3feature.y / Terrain.SquareSize)] = UnitCache.GetInstance().UnitsByName[featurename];
                }
            }

            terrain.OnTerrainModified();
        }