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;
        }
Beispiel #2
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");
        }
Beispiel #3
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);
        }
        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;
        }
 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);
 }
 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);
 }
Beispiel #7
0
        private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            this.taskActionsGroupBox.Enabled = false;
            try
            {
                //fix for multiple load problem
                this.mod = new CMod();
                this.buildtree = new CBuildtree(this);
                this.mod.f = this;
                this.universalkeywordsList.Items.Clear();
                this.unitkeywords.Items.Clear();
                this.Units.Items.Clear();
                this.currentbuildqueue.Items.Clear();

                string text1 = "";
                this.openFileDialog.ShowDialog();
                if (System.IO.File.Exists(this.openFileDialog.FileName))
                {
                    String[] path = openFileDialog.FileName.Split('\\');
                    configfile1 = path[path.Length-1];//this.openFileDialog.FileName;
                    Stream stream1 = this.openFileDialog.OpenFile();
                    StreamReader reader1 = new StreamReader(stream1);
                    text1 = reader1.ReadToEnd();
                    reader1.Close();
                    TdfParser parser1 = new TdfParser(text1);
                    string[] textArray1 = this.openFileDialog.FileName.Split(new char[] { '\\' });
                    string text2 = "";
                    for (int num1 = 0; num1 < textArray1.Length; num1++)
                    {
                        if ((num1 + 1) >= textArray1.Length)
                        {
                            break;
                        }
                        text2 = text2 + textArray1[num1] + "/";
                    }

                    String s = parser1.RootSection.GetStringValue("foobar", @"ntai\modconfig");
                    if(s.Equals("foobar")){
                        MessageBox.Show("If you're trying to open a config inside the /AI/NTai/configs/ folder then your choosing the wrong file. Please select the file in the /AI/NTai/ folder", "Access exception.");
                        return;
                    }
                    if (this.buildtree.Load(text2 + parser1.RootSection.GetStringValue(@"ntai\modconfig")))
                    {
                        configfile2 = parser1.RootSection.GetStringValue(@"ntai\modconfig");
                        this.mod.LoadMod(text2 + parser1.RootSection.GetStringValue(@"ntai\learndata"));
                        configfile3 = parser1.RootSection.GetStringValue(@"ntai\learndata");
                        this.mod.modname = parser1.RootSection.GetStringValue(@"ntai\modname");
                        this.modlabel.Text = this.mod.modname + " is loaded";
                        ArrayList list1 = this.buildtree.keywords.GetUniversalKeywords();
                        foreach (string text3 in list1)
                        {
                            this.universalkeywordsList.Items.Add(text3);
                        }
                        ArrayList list2 = new ArrayList();
                        foreach (string text4 in this.mod.units)
                        {
                            list2.Add(text4 + " - " + this.mod.human_names[text4] + " " + this.mod.descriptions[text4]);
                        }
                        this.buildtree.keywords.AddCollection(this.mod.units, EWordType.e_unitname);
                        foreach (string text5 in list2)
                        {
                            this.unitkeywords.Items.Add(text5);
                            this.Units.Items.Add(text5);
                        }
                        this.currentbuildqueue.Items.Clear();
                        foreach (string text6 in this.buildtree.tasklists.Keys)
                        {
                            this.currentbuildqueue.Items.Add(text6);
                        }
                    }
                    else
                    {
                        this.modlabel.Text = this.mod.modname + " FAILED to load";
                    }
                }
            }
            catch (UnauthorizedAccessException)
            {
                MessageBox.Show("If you're trying to open a config inside the /AI/NTai/configs/ folder then your choosing the wrong file. Please select the file in the /AI/NTai/ folder", "Access exception.");
            }
        }
Beispiel #8
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);
        }
Beispiel #9
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();
        }
Beispiel #10
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;
        }
Beispiel #11
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);
     }
 }