Example #1
0
        List <MapTextureStageModel> LoadTextureStages(string sm3directory, TdfParser.Section terrainsection)
        {
            int numstages = terrainsection.GetIntValue("numtexturestages");
            List <MapTextureStageModel> stages = new List <MapTextureStageModel>();
            TerrainModel terrainmodel          = MetaverseClient.GetInstance().worldstorage.terrainmodel;

            for (int i = 0; i < numstages; i++)
            {
                TdfParser.Section texstagesection    = terrainsection.SubSection("texstage" + i);
                string            texturename        = texstagesection.GetStringValue("source");
                string            blendertexturename = texstagesection.GetStringValue("blender");
                string            operation          = texstagesection.GetStringValue("operation").ToLower();

                int          tilesize;
                ImageWrapper splattexture = LoadSplatTexture(sm3directory, terrainsection, texturename, out tilesize);
                if (operation == "blend")
                {
                    ImageWrapper blendtexture = LoadBlendTexture(sm3directory, terrainsection, blendertexturename);
                    stages.Add(new MapTextureStageModel(MapTextureStageModel.OperationType.Blend, tilesize, splattexture, blendtexture));
                }
                else // todo: add other operations
                {
                    stages.Add(new MapTextureStageModel(MapTextureStageModel.OperationType.Replace, tilesize, splattexture));
                }
            }
            terrainmodel.texturestages = stages;
            return(stages);
        }
Example #2
0
        void LoadHeightMap(string sm3directory, TdfParser.Section terrainsection)
        {
            string filename     = Path.Combine(sm3directory, terrainsection.GetStringValue("heightmap"));
            double heightoffset = terrainsection.GetDoubleValue("heightoffset");
            double heightscale  = terrainsection.GetDoubleValue("heightscale");

            LogFile.GetInstance().WriteLine("heightoffset: " + heightoffset + " heightscale " + heightscale);
            Terrain.GetInstance().MinHeight = heightoffset;
            Terrain.GetInstance().MaxHeight = heightoffset + heightscale; // I guess???

            Image image = new Image(filename);
            //Bitmap bitmap = DevIL.DevIL.LoadBitmap(filename);
            int width  = image.Width;
            int height = image.Height;

            Terrain.GetInstance().HeightMapWidth  = width;
            Terrain.GetInstance().HeightMapHeight = height;
            Terrain.GetInstance().Map             = new double[width, height];
            LogFile.GetInstance().WriteLine("loaded bitmap " + width + " x " + height);
            double minheight        = Terrain.GetInstance().MinHeight;
            double maxheight        = Terrain.GetInstance().MaxHeight;
            double heightmultiplier = (maxheight - minheight) / 255;

            LogFile.GetInstance().WriteLine("heightmultiplier: " + heightmultiplier + " minheight: " + minheight);
            for (int i = 0; i < width; i++)
            {
                for (int j = 0; j < height; j++)
                {
                    Terrain.GetInstance().Map[i, j] =
                        (float)(minheight + heightmultiplier *
                                image.GetBlue(i, j));
                }
            }
            terrain.HeightmapFilename = filename;
        }
Example #3
0
        List <MapTextureStage> LoadTextureStages(string sm3directory, TdfParser.Section terrainsection)
        {
            int numstages = terrainsection.GetIntValue("numtexturestages");
            List <MapTextureStage> stages = new List <MapTextureStage>();

            for (int i = 0; i < numstages; i++)
            {
                TdfParser.Section texstagesection    = terrainsection.SubSection("texstage" + i);
                string            texturename        = texstagesection.GetStringValue("source");
                string            blendertexturename = texstagesection.GetStringValue("blender");
                string            operation          = texstagesection.GetStringValue("operation").ToLower();

                int      tilesize;
                ITexture texture = LoadTexture(sm3directory, terrainsection, texturename, out tilesize);
                if (operation == "blend")
                {
                    ITexture blendtexture = LoadTextureAsAlpha(sm3directory, terrainsection, blendertexturename);
                    stages.Add(new MapTextureStage(MapTextureStage.OperationType.Blend, tilesize, texture, blendtexture));
                }
                else // todo: add other operations
                {
                    stages.Add(new MapTextureStage(MapTextureStage.OperationType.Replace, tilesize, texture));
                }
            }
            Terrain.GetInstance().texturestages = stages;
            return(stages);
        }
Example #4
0
 public void Dump(TdfParser.Section section)
 {
     this.f.debugsave.Text = this.f.debugsave.Text + section.Name + "\n";
     foreach (TdfParser.Section section1 in section.SubSections.Values)
     {
         this.Dump(section1);
     }
 }
Example #5
0
        ITexture LoadTextureAsAlpha(string sm3directory, TdfParser.Section terrainsection, string texturesectionname)
        {
            TdfParser.Section texturesection = terrainsection.SubSection(texturesectionname);
            string            texturename    = Path.Combine(sm3directory, texturesection.GetStringValue("file"));

            LogFile.GetInstance().WriteLine(texturename);
            return(GlTexture.FromAlphamapFile(texturename));
        }
Example #6
0
        ITexture LoadTexture(string sm3directory, TdfParser.Section terrainsection, string texturesectionname, out int tilesize)
        {
            TdfParser.Section texturesection = terrainsection.SubSection(texturesectionname);
            string            texturename    = Path.Combine(sm3directory, texturesection.GetStringValue("file"));

            LogFile.GetInstance().WriteLine(texturename);
            tilesize = texturesection.GetIntValue("tilesize");
            return(GlTexture.FromFile(texturename));
        }
Example #7
0
        ImageWrapper LoadBlendTexture(string sm3directory, TdfParser.Section terrainsection, string texturesectionname)
        {
            TdfParser.Section texturesection = terrainsection.SubSection(texturesectionname);
            string            texturename    = Path.Combine(sm3directory, texturesection.GetStringValue("file"));

            LogFile.WriteLine(texturename);
            return(new ImageWrapper(texturename));
            //return GlTexture.FromAlphamapFile(texturename);
        }
Example #8
0
        public void LoadSm3(string filename)
        {
            terrain.tdfparser = TdfParser.FromFile(filename);
            TdfParser.Section terrainsection = terrain.tdfparser.RootSection.SubSection("map/terrain");
            string            tdfdirectory   = Path.GetDirectoryName(Path.GetDirectoryName(filename));

            LoadTextureStages(tdfdirectory, terrainsection);
            LoadHeightMap(tdfdirectory, terrainsection);
            terrain.OnTerrainModified();
            MainUI.GetInstance().uiwindow.InfoMessage("SM3 load completed");
        }
Example #9
0
        private string GetValueByPath(string path)
        {
            List <string> list1 = this.GetPathParts(path);

            TdfParser.Section section1 = this;
            for (int num1 = 0; num1 < (list1.Count - 1); num1++)
            {
                section1 = section1.SubSections[list1[num1]];
            }
            return(section1.Values[list1[list1.Count - 1]]);
        }
Example #10
0
        private TdfParser.Section GetSectionByPath(string path)
        {
            List <string> list1 = this.GetPathParts(path);

            TdfParser.Section section1 = this;
            for (int num1 = 0; num1 < list1.Count; num1++)
            {
                section1 = section1.SubSections[list1[num1]];
            }
            return(section1);
        }
Example #11
0
        ImageWrapper LoadSplatTexture(string sm3directory, TdfParser.Section terrainsection, string texturesectionname, out int tilesize)
        {
            TdfParser.Section texturesection = terrainsection.SubSection(texturesectionname);
            string            texturename    = Path.Combine(sm3directory, texturesection.GetStringValue("file"));

            LogFile.WriteLine(texturename);
            tilesize = texturesection.GetIntValue("tilesize");
            ImageWrapper splattexture = new ImageWrapper(texturename);

            return(splattexture);
            //return GlTexture.FromFile(texturename);
        }
Example #12
0
        public bool LoadMod(string modfile)
        {
            this.modfilename = modfile;
            TdfParser parser1 = TdfParser.FromFile(modfile);

            if (parser1 != null)
            {
                TdfParser.Section section1 = parser1.RootSection.SubSection(@"AI\VALUES");
                if (section1 != null)
                {
                    foreach (string text1 in section1.Values.Keys)
                    {
                        string text2 = text1;
                        text2 = text2.ToLower();
                        text2 = text2.Trim();
                        this.units.Add(text2);
                        this.values[text2] = section1.GetDoubleValue(text1);
                    }
                }
                section1 = parser1.RootSection.SubSection(@"AI\NAMES");
                if (section1 != null)
                {
                    foreach (string text3 in section1.Values.Keys)
                    {
                        string text4 = text3;
                        text4 = text4.ToLower();
                        text4 = text4.Trim();
                        this.human_names[text4] = section1.GetStringValue(text3);
                    }
                }
                section1 = parser1.RootSection.SubSection(@"AI\DESCRIPTIONS");
                if (section1 != null)
                {
                    foreach (string text5 in section1.Values.Keys)
                    {
                        string text6 = text5;
                        text6 = text6.ToLower();
                        text6 = text6.Trim();
                        this.descriptions[text6] = section1.GetStringValue(text5);
                    }
                }
                this.units.Sort();
            }
            return(false);
        }
Example #13
0
        public bool Load(string TDFfile)
        {
            this.buildtreefilename = TDFfile;
            Stream       stream1 = File.OpenRead(TDFfile);
            StreamReader reader1 = new StreamReader(stream1);
            string       text1   = reader1.ReadToEnd();

            reader1.Close();
            TdfParser parser1 = new TdfParser(text1);

            this.author           = parser1.RootSection.GetStringValue("", @"AI\author");
            this.f.debugsave.Text = this.f.debugsave.Text + this.author + "\n";
            this.version          = parser1.RootSection.GetStringValue("0.1", @"AI\version");
            this.message          = parser1.RootSection.GetStringValue("", @"AI\message");

            this.use_mod_default           = parser1.RootSection.GetIntValue(0, @"AI\use_mod_default");
            this.use_mod_default_if_absent = parser1.RootSection.GetIntValue(1, @"AI\use_mod_default_if_absent");
            this.defence_spacing           = (decimal)parser1.RootSection.GetIntValue(7, @"AI\defence_spacing");
            this.power_spacing             = (decimal)parser1.RootSection.GetIntValue(6, @"AI\power_spacing");
            this.factory_spacing           = (decimal)parser1.RootSection.GetIntValue(4, @"AI\factory_spacing");
            this.default_spacing           = (decimal)parser1.RootSection.GetIntValue(5, @"AI\default_spacing");
            this.spacemod              = this.inttobool(parser1.RootSection.GetIntValue(0, @"AI\spacemod"));
            this.Antistall             = this.inttobool(parser1.RootSection.GetIntValue(1, @"AI\antistall"));
            this.StallTimeImMobile     = (decimal)parser1.RootSection.GetIntValue(0, @"AI\MaxStallTimeImmobile");
            this.StallTimeMobile       = (decimal)parser1.RootSection.GetIntValue(0, @"AI\MaxStallTimeMobile");
            this.powerRule             = Convert.ToDecimal(parser1.RootSection.GetDoubleValue(0.7, @"ECONOMY\RULES\power"));
            this.mexRule               = Convert.ToDecimal(parser1.RootSection.GetDoubleValue(0.7, @"ECONOMY\RULES\mex"));
            this.powerRuleEx           = Convert.ToDecimal(parser1.RootSection.GetDoubleValue(0.7, @"ECONOMY\RULES\EXTREME\power"));
            this.mexRuleEx             = Convert.ToDecimal(parser1.RootSection.GetDoubleValue(0.7, @"ECONOMY\RULES\EXTREME\mex"));
            this.factorymetalRule      = Convert.ToDecimal(parser1.RootSection.GetDoubleValue(0.7, @"ECONOMY\RULES\factorymetal"));
            this.factorymetalRuleEx    = Convert.ToDecimal(parser1.RootSection.GetDoubleValue(0.7, @"ECONOMY\RULES\EXTREME\factorymetal"));
            this.factoryenergyRule     = Convert.ToDecimal(parser1.RootSection.GetDoubleValue(0.7, @"ECONOMY\RULES\factoryenergy"));
            this.factoryenergyRuleEx   = Convert.ToDecimal(parser1.RootSection.GetDoubleValue(0.7, @"ECONOMY\RULES\EXTREME\factoryenergy"));
            this.factorymetalgapRule   = Convert.ToDecimal(parser1.RootSection.GetDoubleValue(0.7, @"ECONOMY\RULES\factorymetalgap"));
            this.factorymetalgapRuleEx = Convert.ToDecimal(parser1.RootSection.GetDoubleValue(0.7, @"ECONOMY\RULES\EXTREME\factorymetalgap"));
            this.energystorageRule     = Convert.ToDecimal(parser1.RootSection.GetDoubleValue(0.7, @"ECONOMY\RULES\energystorage"));
            this.energystorageRuleEx   = Convert.ToDecimal(parser1.RootSection.GetDoubleValue(0.7, @"ECONOMY\RULES\EXTREME\energystorage"));
            this.metalstorageRule      = Convert.ToDecimal(parser1.RootSection.GetDoubleValue(0.7, @"ECONOMY\RULES\metalstorage"));
            this.metalstorageRuleEx    = Convert.ToDecimal(parser1.RootSection.GetDoubleValue(0.7, @"ECONOMY\RULES\EXTREME\metalstorage"));
            this.makermetalRule        = Convert.ToDecimal(parser1.RootSection.GetDoubleValue(0.7, @"ECONOMY\RULES\makermetal"));
            this.makermetalRuleEx      = Convert.ToDecimal(parser1.RootSection.GetDoubleValue(0.7, @"ECONOMY\RULES\EXTREME\makermetal"));
            this.makerenergyRule       = Convert.ToDecimal(parser1.RootSection.GetDoubleValue(0.7, @"ECONOMY\RULES\makerenergy"));
            this.makerenergyRuleEx     = Convert.ToDecimal(parser1.RootSection.GetDoubleValue(0.7, @"ECONOMY\RULES\EXTREME\makerenergy"));
            this.normal_handicap       = Convert.ToDecimal(parser1.RootSection.GetDoubleValue(0, @"AI\normal_handicap"));
            this.antistallwindow       = Convert.ToDecimal(parser1.RootSection.GetDoubleValue(43, @"AI\antistallwindow"));

            this.initialAttackSize = Convert.ToDecimal(parser1.RootSection.GetDoubleValue(5, @"AI\initial_threat_value"));
            this.interpolate       = parser1.RootSection.GetStringValue(@"AI\interpolate_tag").Equals("b_rule_extreme_nofact");

            this.AttackIncrementValue      = Convert.ToDecimal(parser1.RootSection.GetDoubleValue(1, @"AI\increase_threshold_value"));
            this.maxAttackSize             = Convert.ToDecimal(parser1.RootSection.GetDoubleValue(1, @"AI\maximum_attack_group_size"));
            this.AttackIncrementPercentage = Convert.ToDecimal(parser1.RootSection.GetDoubleValue(1, @"AI\increase_threshold_percentage"));

            this.mexnoweaponradius = Convert.ToDecimal(parser1.RootSection.GetDoubleValue(900, @"AI\mexnoweaponradius"));

            this.GeoSearchRadius = Convert.ToDecimal(parser1.RootSection.GetDoubleValue(3000, @"AI\geotherm\searchdistance"));
            this.NoEnemyGeo      = Convert.ToDecimal(parser1.RootSection.GetDoubleValue(600, @"AI\geotherm\noenemiesdistance"));

            string[] textArray1 = parser1.RootSection.GetStringValue(" ", @"AI\hold_pos").Split(new char[] { ',' });
            foreach (string text3 in textArray1)
            {
                string text4 = text3;
                text4.Trim();
                text4 = text4.ToLower();
                this.movement[text4] = 0;
            }
            textArray1 = parser1.RootSection.GetStringValue(" ", @"AI\maneouvre").Split(new char[] { ',' });
            foreach (string text5 in textArray1)
            {
                string text6 = text5;
                text6.Trim();
                text6 = text6.ToLower();
                this.movement[text6] = 1;
            }
            textArray1 = parser1.RootSection.GetStringValue(" ", @"AI\roam").Split(new char[] { ',' });
            foreach (string text7 in textArray1)
            {
                string text8 = text7;
                text8.Trim();
                text8 = text8.ToLower();
                this.movement[text8] = 2;
            }
            textArray1 = parser1.RootSection.GetStringValue(" ", @"AI\hold_fire").Split(new char[] { ',' });
            foreach (string text9 in textArray1)
            {
                string text10 = text9;
                text10 = text10.Trim();
                text10 = text10.ToLower();
                this.firingstate[text10] = 0;
            }
            textArray1 = parser1.RootSection.GetStringValue(" ", @"AI\return_fire").Split(new char[] { ',' });
            foreach (string text11 in textArray1)
            {
                string text12 = text11;
                text12.Trim();
                text12 = text12.ToLower();
                this.firingstate[text12] = 1;
            }
            textArray1 = parser1.RootSection.GetStringValue(" ", @"AI\fire_at_will").Split(new char[] { ',' });
            foreach (string text13 in textArray1)
            {
                string text14 = text13;
                text14.Trim();
                text14 = text14.ToLower();
                this.firingstate[text14] = 2;
            }
            foreach (string text15 in parser1.RootSection.GetStringValue(" ", @"AI\attackers").Split(new char[] { ',' }))
            {
                string text16 = text15;
                text16 = text16.Trim();
                text16 = text16.ToLower();
                this.attackers.Add(text16);
            }
            foreach (string text17 in parser1.RootSection.GetStringValue(" ", @"AI\scouters").Split(new char[] { ',' }))
            {
                string text18 = text17;
                text18 = text18.Trim();
                text18 = text18.ToLower();
                this.scouters.Add(text18);
            }
            foreach (string text19 in parser1.RootSection.GetStringValue(" ", @"AI\kamikaze").Split(new char[] { ',' }))
            {
                string text20 = text19;
                text20 = text20.Trim();
                text20 = text20.ToLower();
                this.kamikaze.Add(text20);
            }
            foreach (string text21 in parser1.RootSection.GetStringValue(" ", @"AI\solobuild").Split(new char[] { ',' }))
            {
                string text22 = text21;
                text22 = text22.Trim();
                text22 = text22.ToLower();
                this.solobuild.Add(text22);
            }
            foreach (string text23 in parser1.RootSection.GetStringValue(" ", @"AI\singlebuild").Split(new char[] { ',' }))
            {
                string text24 = text23;
                text24 = text24.Trim();
                text24 = text24.ToLower();
                this.singlebuild.Add(text24);
            }
            foreach (string text25 in parser1.RootSection.GetStringValue(" ", @"AI\alwaysantistall").Split(new char[] { ',' }))
            {
                string text26 = text25;
                text26 = text26.Trim();
                text26 = text26.ToLower();
                this.alwaysantistall.Add(text26);
            }
            foreach (string text27 in parser1.RootSection.GetStringValue(" ", @"AI\neverantistall").Split(new char[] { ',' }))
            {
                string text28 = text27;
                text28 = text28.Trim();
                text28 = text28.ToLower();
                this.neverantistall.Add(text28);
            }
            TdfParser.Section section1 = parser1.RootSection.SubSection(@"Resource\ConstructionRepairRanges");
            if (section1 != null)
            {
                foreach (string text29 in section1.Values.Keys)
                {
                    this.ConstructionRepairRanges[text29] = decimal.Parse(section1.Values[text29]);
                }
            }
            section1 = parser1.RootSection.SubSection(@"Resource\ConstructionExclusionRange");
            if (section1 != null)
            {
                foreach (string text30 in section1.Values.Keys)
                {
                    this.ConstructionExclusionRange[text30] = decimal.Parse(section1.Values[text30]);
                }
            }
            section1 = parser1.RootSection.SubSection(@"Resource\MaxEnergy");
            if (section1 != null)
            {
                foreach (string text31 in section1.Values.Keys)
                {
                    this.MaxEnergy[text31] = decimal.Parse(section1.Values[text31]);
                }
            }
            section1 = parser1.RootSection.SubSection(@"Resource\MinEnergy");
            if (section1 != null)
            {
                foreach (string text32 in section1.Values.Keys)
                {
                    this.MinEnergy[text32] = decimal.Parse(section1.Values[text32]);
                }
            }
            section1 = parser1.RootSection.SubSection(@"TASKLISTS\NORMAL");
            if (section1 != null)
            {
                foreach (string text33 in section1.Values.Keys)
                {
                    ArrayList list1 = new ArrayList();
                    foreach (string text34 in section1.Values[text33].Split(new char[] { ',' }))
                    {
                        string text35 = text34;
                        text35 = text35.Trim();
                        text35 = text35.ToLower();
                        list1.Add(text35);
                    }
                    this.unittasklists[text33] = list1;
                }
            }
            section1 = parser1.RootSection.SubSection(@"TASKLISTS\CHEAT");
            if (section1 != null)
            {
                foreach (string text36 in section1.Values.Keys)
                {
                    ArrayList list2 = new ArrayList();
                    foreach (string text37 in section1.Values[text36].Split(new char[] { ',' }))
                    {
                        string text38 = text37;
                        text38 = text38.Trim();
                        text38 = text38.ToLower();
                        list2.Add(text38);
                    }
                    this.unitcheattasklists[text36] = list2;
                }
            }
            section1 = parser1.RootSection.SubSection(@"TASKLISTS\LISTS");
            if (section1 != null)
            {
                foreach (string text39 in section1.Values.Keys)
                {
                    ArrayList list3 = new ArrayList();
                    foreach (string text40 in section1.Values[text39].Split(new char[] { ',' }))
                    {
                        string text41 = text40;
                        text41 = text41.Trim();
                        text41 = text41.ToLower();
                        list3.Add(text41);
                    }
                    this.tasklists[text39] = list3;
                }
            }
            return(true);
        }