Exemplo n.º 1
0
        public void Add(ScriptCommand scriptScope)
        {
            if (!AllowDuplicates && ChildrenMap.ContainsKey(scriptScope.Name))
            {
                return;
            }

            Children.Add(scriptScope);
            ChildrenMap[scriptScope.Name] = scriptScope;
            scriptScope.Parent            = this;
        }
Exemplo n.º 2
0
 public void SetValue(String name, object value)
 {
     if (!scope.ChildrenMap.ContainsKey(name))
     {
         var c = new ScriptCommand(name, value, scope);
         scope.Add(c);
     }
     else
     {
         (scope.ChildrenMap[name] as ScriptCommand).Value = value;
     }
 }
Exemplo n.º 3
0
        public void AddDated(int date, ScriptCommand command)
        {
            ScriptScope dates = null;

            if (Date.ContainsKey(date))
            {
                dates = Date[date];
            }
            else
            {
                dates      = new ScriptScope(date.ToString());
                Date[date] = dates;
                Scope.Add(dates);
            }

            dates.Add(command);
        }
Exemplo n.º 4
0
        private void RemoveAllReligionTests(ScriptScope node)
        {
            for (int index = 0; index < node.Children.Count; index++)
            {
                var child = node.Children[index];

                if (child is ScriptScope)
                {
                    RemoveAllReligionTests(child as ScriptScope);
                }
                if (child is ScriptCommand)
                {
                    ScriptCommand c = (ScriptCommand)child;
                    if (c.Name == "religion" || c.Name == "religion_group")
                    {
                        if (c.Value.ToString().ToUpper() == "FROM" || c.Value.ToString().ToUpper() == "ROOT" || c.Value.ToString().ToUpper().Contains("PREV"))
                        {
                        }
                        else
                        {
                            node.Remove(child);
                            index--;
                        }
                        continue;
                    }
                    if (c.Name == "culture" || c.Name == "culture_group")
                    {
                        if (c.Value.ToString().ToUpper() == "FROM" || c.Value.ToString().ToUpper() == "ROOT" || c.Value.ToString().ToUpper().Contains("PREV"))
                        {
                        }
                        else
                        {
                            node.Remove(child);
                            index--;
                        }
                        continue;
                    }
                }
            }
        }
Exemplo n.º 5
0
        public void RegisterProperty(int line, string property, object child)
        {
            ScriptCommand command = child as ScriptCommand;

            foreach (var propertyInfo in this.GetType().GetProperties())
            {
                if (propertyInfo.Name == command.Name)
                {
                    if (command.Value.GetType() == propertyInfo.PropertyType)
                    {
                        propertyInfo.SetValue(this, command.Value);
                    }
                    else
                    {
                        if (command.Value is ScriptReference)
                        {
                            var scriptReference = command.Value as ScriptReference;
                            if (propertyInfo.PropertyType == typeof(int))
                            {
                                propertyInfo.SetValue(this, Convert.ToInt32(scriptReference.Referenced));
                            }
                            else if (propertyInfo.PropertyType == typeof(float))
                            {
                                propertyInfo.SetValue(this, Convert.ToSingle(scriptReference.Referenced));
                            }
                            else if (propertyInfo.PropertyType == typeof(Color))
                            {
                                int r = 0;
                                int g = 0;
                                int b = 0;

                                String[] str = scriptReference.Referenced.Split(' ');
                                int[]    rgb = new int[3];
                                int      c   = 0;

                                foreach (var s in str)
                                {
                                    if (s.Trim().Length > 0)
                                    {
                                        rgb[c] = Convert.ToInt32(s.Trim());
                                        c++;
                                        if (c >= 3)
                                        {
                                            break;
                                        }
                                    }
                                }

                                if (c == 0)
                                {
                                    propertyInfo.SetValue(this, Color.Black);
                                }
                                else if (c < 3)
                                {
                                    for (int n = c; n < 3; n++)
                                    {
                                        rgb[n] = rgb[n - 1];
                                    }
                                }

                                for (int n = 0; n < 3; n++)
                                {
                                    if (rgb[n] > 255)
                                    {
                                        rgb[n] = 255;
                                    }
                                    if (rgb[n] < 0)
                                    {
                                        rgb[n] = 0;
                                    }
                                }
                                propertyInfo.SetValue(this, Color.FromArgb(255, rgb[0], rgb[1], rgb[2]));
                            }
                            else
                            {
                                propertyInfo.SetValue(this, scriptReference.Referenced);
                            }
                        }
                    }
                }
            }

            PropertyMap[property] = line;
        }
Exemplo n.º 6
0
        private void ConvertReligionTests(ScriptScope node)
        {
            for (int index = 0; index < node.Children.Count; index++)
            {
                var child = node.Children[index];
                if (child is ScriptScope)
                {
                    ConvertReligionTests(child as ScriptScope);
                }
                if (child is ScriptCommand)
                {
                    ScriptCommand c = (ScriptCommand)child;
                    if (c.Name == "religion" || c.Name == "secret_religion")
                    {
                        if (c.Value.ToString().ToUpper() == "FROM" || c.Value.ToString().ToUpper() == "ROOT" || c.Value.ToString().ToUpper().Contains("PREV"))
                        {
                        }
                        else
                        {
                            if (c.Value.ToString() == "catholic")
                            {
                                c.Value = ReligionManager.instance.CatholicSub.Name;
                            }
                            else if (c.Value.ToString() == "orthodox")
                            {
                                c.Value = ReligionManager.instance.OrthodoxSub.Name;
                            }
                            else if (c.Value.ToString() == "sunni")
                            {
                                c.Value = ReligionManager.instance.SunniEquiv.Name;
                            }
                            else if (c.Value.ToString() == "shiite")
                            {
                                c.Value = ReligionManager.instance.ShiiteEquiv.Name;
                            }
                            else if (c.Value.ToString() == "norse_pagan")
                            {
                                c.Value = ReligionManager.instance.NorseSub.Name;
                            }
                            else if (c.Value.ToString() == "norse_pagan_reformed")
                            {
                                c.Value = ReligionManager.instance.NorseReformSub.Name;
                            }
                        }
                        continue;
                    }

                    if (c.Name == "religion_group")
                    {
                        if (c.Value.ToString().ToUpper() == "FROM" || c.Value.ToString().ToUpper() == "ROOT" || c.Value.ToString().ToUpper().Contains("PREV"))
                        {
                        }
                        else
                        {
                            if (c.Value.ToString() == "christian")
                            {
                                c.Value = ReligionManager.instance.ChristianGroupSub.Name;
                            }
                            else if (c.Value.ToString() == "muslim")
                            {
                                c.Value = ReligionManager.instance.MuslimGroupSub.Name;
                            }
                            else if (c.Value.ToString() == "indian_group")
                            {
                                c.Value = ReligionManager.instance.IndianGroupSub.Name;
                            }
                            else if (c.Value.ToString() == "zoroastrian_group")
                            {
                                c.Value = ReligionManager.instance.ZoroGroupSub.Name;
                            }
                            else if (c.Value.ToString() == "jewish_group")
                            {
                                c.Value = ReligionManager.instance.JewGroupSub.Name;
                            }
                            else if (c.Value.ToString() == "pagan_group")
                            {
                                c.Value = ReligionManager.instance.PaganGroupSub.Name;
                            }
                        }
                        continue;
                    }
                }
            }
        }
Exemplo n.º 7
0
        public void Load()
        {
            String provincesDir = Globals.GameDir + "history\\provinces\\";

            foreach (var file in Directory.GetFiles(provincesDir))
            {
                String name = file.Substring(file.LastIndexOf('\\') + 1);
                int    id   = Convert.ToInt32(name.Split('-')[0].Trim());
            }
            TitleManager.instance.Load();

            //    foreach (var provinceParser in Provinces)
            {
                //        provinceParser.DoTitleOwnership();
            }

            for (int n = 0; n < 2000; n++)
            {
                ProvinceParser parser = new ProvinceParser(new ScriptScope());
                parser.Name = "c_unnamed" + n;
                parser.id   = n + 1;
                ProvinceIDMap[parser.id] = parser;
                //     TitleManager.instance.CreateDukeScriptScope();
                Provinces.Add(parser);
            }
            provincesDir = Globals.GameDir + "history\\provinces\\";
            foreach (var file in Directory.GetFiles(provincesDir))
            {
                String name = file.Substring(file.LastIndexOf('\\') + 1);
                int    id   = Convert.ToInt32(name.Split('-')[0].Trim());

                {
                    Script s = ScriptLoader.instance.Load(file);

                    ScriptCommand terrain = (ScriptCommand)s.Root.Find("terrain");

                    if (terrain != null)
                    {
                        var ter = terrain.Value.ToString();
                        LoadedTerrain[id] = ter;
                    }
                    else
                    {
                    }
                }
                ProvinceIDMap[id].land = true;
            }
            //s
            ProvinceBitmap       = new Bitmap(Globals.MapDir + "map\\provinces.bmp");
            ProvinceBitmap       = ResizeBitmap(ProvinceBitmap, (int)(ProvinceBitmap.Width * SizeMod), (int)(ProvinceBitmap.Height * SizeMod));
            ProvinceRenderBitmap = new Bitmap(ProvinceBitmap.Width, ProvinceBitmap.Height);
            LoadDefinitions();

            ProvincePixelMap = new ProvinceParser[ProvinceBitmap.Width, ProvinceBitmap.Height];

            CreateLandscape();

            LockBitmap lockBitmap = new LockBitmap(ProvinceBitmap);

            lockBitmap.LockBits();
            for (int x = 0; x < lockBitmap.Width; x++)
            {
                for (int y = 0; y < lockBitmap.Height; y++)
                {
                    Color col = lockBitmap.GetPixel(x, y);
                    // col2 = Color.FromArgb(255, col.R, col.G, col.B);
                    if (ProvinceColorMap.ContainsKey(col))
                    {
                        ProvincePixelMap[x, y] = ProvinceColorMap[col];
                        ProvinceColorMap[col].Points.Add(new Point(x, y));
                    }

                    int minX = x - 1;
                    int minY = y - 1;
                    if (minX < 0)
                    {
                        minX = 0;
                    }
                    if (minY < 0)
                    {
                        minY = 0;
                    }

                    for (int xx = minX; xx <= x; xx++)
                    {
                        for (int yy = minY; yy <= y; yy++)
                        {
                            if (xx == x && yy == y)
                            {
                                continue;
                            }

                            Color col2 = lockBitmap.GetPixel(xx, yy);
                            if (col2 != col && ProvinceColorMap.ContainsKey(col2) && ProvinceColorMap.ContainsKey(col))
                            {
                                ProvinceColorMap[col].AddAdjacent(ProvinceColorMap[col2]);
                            }
                        }
                    }
                }
            }

            for (int y = lockBitmap.Height - 1; y >= 0; y--)
            {
                for (int x = lockBitmap.Width - 1; x >= 0; x--)
                {
                    Color col = lockBitmap.GetPixel(x, y);
                    // col2 = Color.FromArgb(255, col.R, col.G, col.B);

                    int maxX = x + 1;
                    int maxY = y + 1;

                    maxX = Math.Min(lockBitmap.Width - 1, maxX);
                    maxY = Math.Min(lockBitmap.Height - 1, maxY);

                    for (int xx = x; xx <= maxX; xx++)
                    {
                        for (int yy = y; yy <= maxY; yy++)
                        {
                            if (xx == x && yy == y)
                            {
                                continue;
                            }

                            Color col2 = lockBitmap.GetPixel(xx, yy);
                            if (col2 != col && ProvinceColorMap.ContainsKey(col2) && ProvinceColorMap.ContainsKey(col))
                            {
                                ProvinceColorMap[col].AddAdjacent(ProvinceColorMap[col2]);
                            }
                        }
                    }
                }
            }
            lockBitmap.UnlockBits();

            foreach (var provinceParser in Provinces)
            {
                int maxX = -1000000;
                int maxY = -1000000;
                int minX = 1000000;
                int minY = 1000000;
                if (provinceParser.Points.Count == 0)
                {
                    continue;
                }

                foreach (var point in provinceParser.Points)
                {
                    if (point.X > maxX)
                    {
                        maxX = point.X;
                    }
                    if (point.Y > maxY)
                    {
                        maxY = point.Y;
                    }
                    if (point.X < minX)
                    {
                        minX = point.X;
                    }
                    if (point.Y < minY)
                    {
                        minY = point.Y;
                    }
                }

                Bitmap            bmp = new Bitmap(maxX - minX + 1, maxY - minY + 1);
                ProvinceMapBitmap b   = new ProvinceMapBitmap()
                {
                    Bitmap = bmp, MapPoint = new Point(minX, minY)
                };
                LockBitmap lb = new LockBitmap(b.Bitmap);

                lb.LockBits();
                for (int x = 0; x < lb.Width; x++)
                {
                    for (int y = 0; y < lb.Height; y++)
                    {
                        lb.SetPixel(x, y, Color.Transparent);
                    }
                }
                foreach (var point in provinceParser.Points)
                {
                    lb.SetPixel(point.X - minX, point.Y - minY, Color.White);
                }
                lb.UnlockBits();

                ProvinceBitmaps[provinceParser.id] = b;
            }

            LoadAdjacencies();

            Simulation.SimulationManager.instance.Init();
        }
Exemplo n.º 8
0
 public ScriptCommand Copy()
 {
     var s = new ScriptCommand(Name, Value, null);
     s.AlwaysQuote = AlwaysQuote;
     return s;
 }
Exemplo n.º 9
0
 public void Add(ScriptCommand scriptScope)
 {
     if (!AllowDuplicates && ChildrenMap.ContainsKey(scriptScope.Name))
         return;
     
     Children.Add(scriptScope);
     ChildrenMap[scriptScope.Name] = scriptScope;
     scriptScope.Parent = this;
 }
Exemplo n.º 10
0
        public void Save(StreamWriter file, int depth)
        {
            if (Name == "d_rajput_band")
            {
                int gfdgf = 0;
            }
            String tab = "";

            for (int n = 1; n < depth; n++)
            {
                tab += "\t";
            }
            string ret = "\n";

            if (depth > 0)
            {
                file.Write(tab + Name + " = {" + ret);
            }

            string rett = "\t";

            tab = "";
            for (int n = 1; n < depth; n++)
            {
                tab += rett;
            }
            foreach (var child in Children)
            {
                if (child is ScriptCommand)
                {
                    ScriptCommand c = child as ScriptCommand;
                    if (c.AlwaysQuote)
                    {
                        String str = GetExportStringFromObject(c.Value);
                        if (!str.Trim().StartsWith("\""))
                        {
                            str = '"'.ToString() + str + '"'.ToString();
                        }
                        file.Write(tab + rett + c.Name + " = " + str + ret);
                    }
                    else
                    {
                        file.Write(tab + rett + c.Name + " = " + GetExportStringFromObject(c.Value) + ret);
                    }
                }
                if (child is ScriptScope)
                {
                    (child as ScriptScope).Save(file, depth + 1);
                }
            }
            if (Data.Trim().Length > 0)
            {
                file.Write(Data);
            }
            if (depth > 0)
            {
                if (depth == 1)
                {
                    file.Write(tab + "}\n\n");
                }
                else
                {
                    file.Write(tab + "}\n");
                }
            }
        }
Exemplo n.º 11
0
        private ScriptScope ConvertReligionTests(ScriptScope node, List <object> toDelete)
        {
            for (int index = 0; index < node.Children.Count; index++)
            {
                var child = node.Children[index];
                if (child is ScriptScope)
                {
                    var sc = child as ScriptScope;

                    if (sc.Name == "narrative_event")
                    {
                        //     node.Children.Remove(sc);
                        //    continue;
                    }
                }
                if (child is ScriptScope)
                {
                    var sc = child as ScriptScope;
                    if (sc.Name == "distance")
                    {
                        foreach (var o in sc.Children)
                        {
                            if (o is ScriptCommand && ((ScriptCommand)o).Name.Trim() == "where")
                            {
                                try
                                {
                                    if (((ScriptCommand)o).Value is ScriptReference)
                                    {
                                        int prov = Convert.ToInt32(((ScriptReference)((ScriptCommand)o).Value).Referenced);
                                        toDelete.Add((ScriptCommand)o);
                                        return(null);
                                    }

                                    int prov2 = Convert.ToInt32((((ScriptCommand)o).Value));
                                    toDelete.Add(Convert.ToInt32(((ScriptCommand)o)));
                                    return(null);
                                }
                                catch (Exception ex)
                                {
                                }
                            }
                        }
                    }

                    if (sc.Name == "regional_percentage")
                    {
                        node.Remove(child);
                        index--;
                        continue;
                    }
                    ConvertReligionTests(child as ScriptScope, toDelete);
                    if ((child as ScriptScope).Children.Count == 0)
                    {
                        node.Remove(child);
                        index--;
                    }
                    if ((child as ScriptScope).Children.Count == 1 && (child as ScriptScope).Name == "modifier")
                    {
                        node.Remove(child);
                        index--;
                    }
                }
                if (child is ScriptCommand)
                {
                    ScriptCommand c = (ScriptCommand)child;

                    if (c.Name == "completely_controls")
                    {
                        toDelete.Add(c);
                        return(null);
                    }

                    if (c.Name == "culture_group" || c.Name == "culture")
                    {
                        if (c.Value.ToString().ToUpper() == "THIS" || c.Value.ToString().ToUpper() == "FROM" || c.Value.ToString().ToUpper() == "ROOT" || c.Value.ToString().ToUpper().Contains("PREV"))
                        {
                        }
                        else
                        {
                            toDelete.Add(c);
                            return(null);
                        }
                    }
                    if (c.Name == "religion" || c.Name == "secret_religion")
                    {
                        if (c.Value.ToString().ToUpper() == "FROM" || c.Value.ToString().ToUpper() == "ROOT" || c.Value.ToString().ToUpper().Contains("PREV"))
                        {
                        }
                        if (c.Value.ToString().ToUpper() == "THIS")
                        {
                        }
                        else
                        {
                            if (c.Value.ToString() == "hindu")
                            {
                                c.Value = ReligionManager.instance.HinduEquiv.Name;
                            }
                            else if (c.Value.ToString() == "buddhist")
                            {
                                c.Value = ReligionManager.instance.BuddhistEquiv.Name;
                            }
                            else if (c.Value.ToString() == "jain")
                            {
                                c.Value = ReligionManager.instance.JainEquiv.Name;
                            }
                            else if (c.Value.ToString() == "catholic")
                            {
                                c.Value = ReligionManager.instance.CatholicSub.Name;
                            }
                            else if (c.Value.ToString() == "orthodox")
                            {
                                c.Value = ReligionManager.instance.OrthodoxSub.Name;
                            }
                            else if (c.Value.ToString() == "sunni")
                            {
                                c.Value = ReligionManager.instance.SunniEquiv.Name;
                            }
                            else if (c.Value.ToString() == "shiite")
                            {
                                c.Value = ReligionManager.instance.ShiiteEquiv.Name;
                            }
                            else if (c.Value.ToString() == "norse_pagan")
                            {
                                c.Value = ReligionManager.instance.NorseSub.Name;
                            }
                            else if (c.Value.ToString() == "norse_pagan_reformed")
                            {
                                c.Value = ReligionManager.instance.NorseReformSub.Name;
                            }
                        }

                        continue;
                    }
                    if (c.Name == "religion_group")
                    {
                        if (c.Value.ToString().ToUpper() == "FROM" || c.Value.ToString().ToUpper() == "ROOT" || c.Value.ToString().ToUpper().Contains("PREV"))
                        {
                        }
                        else
                        {
                            if (c.Value.ToString() == "christian")
                            {
                                c.Value = ReligionManager.instance.ChristianGroupSub.Name;
                            }
                            else if (c.Value.ToString() == "muslim")
                            {
                                c.Value = ReligionManager.instance.MuslimGroupSub.Name;
                            }
                            else if (c.Value.ToString() == "indian_group")
                            {
                                c.Value = ReligionManager.instance.IndianGroupSub.Name;
                            }
                            else if (c.Value.ToString() == "zoroastrian_group")
                            {
                                c.Value = ReligionManager.instance.ZoroGroupSub.Name;
                            }
                            else if (c.Value.ToString() == "jewish_group")
                            {
                                c.Value = ReligionManager.instance.JewGroupSub.Name;
                            }
                            else if (c.Value.ToString() == "pagan_group")
                            {
                                c.Value = ReligionManager.instance.PaganGroupSub.Name;
                            }
                        }
                        continue;
                    }
                }
            }
            return(null);
        }