コード例 #1
0
        // Methods
        /// <summary>
        /// Initializes MainUnitFile with the given file name.
        /// </summary>
        /// <param name="fName">The name of the file</param>
        public void InitUnitFile(string filePath)
        {
            /// We're wrapping most of this method in a try-catch block to catch file exceptions.
            /// This will allow the app to quickly recover from incorrect file selections
            try
            {
                // First things first, initialize MainUnitFile
                MainUnitFile = new UnitFile(filePath);
                MainUnitFile.init();

                // Now that we've initialized the file, pull out the names for each unit
                UnitName tempUName;
                foreach (UnitFileNode node in MainUnitFile.UnitDir.TheUnits)
                {
                    tempUName = new UnitName(node.TheUnit, node.Index);
                    // Toss it on the NameList..
                    UnitEditor.NameList.Add(tempUName);

                    // ...and on the Armies
                    Armies.AddUnit(tempUName);
                }

                // Finally, set UnitEditor to the first unit in the list
                UnitEditor.changeSelection(UnitEditor.NameList[0]);
            }
            catch (SUE_InvalidFileException ivfe)
            {
                // Send message to user, redo file open.
                throw ivfe;
            }
        }
コード例 #2
0
        private static void Main(string[] args)
        {
            DateTime startTime = DateTime.Now;

            Console.Title = "ANTD";
            Console.WriteLine(ConsoleTime.GetTime(DateTime.Now) + "loading application...");

            SystemConfig.FirstLaunchDefaults();
            Console.WriteLine(ConsoleTime.GetTime(DateTime.Now) + "setting core system configuration...");

            Cfg.FirstLaunchDefaults();
            Console.WriteLine(ConsoleTime.GetTime(DateTime.Now) + "setting core cfg configuration...");

            var stop = new ManualResetEvent(false);

            Console.CancelKeyPress +=
                (sender, e) => {
                Console.WriteLine("^C");
                Database.ShutDown();
                stop.Set();
                e.Cancel = true;
            };
            string uri = SelfConfig.GetAntdUri();

            Console.WriteLine(ConsoleTime.GetTime(DateTime.Now) + "initializing antd");
            using (WebApp.Start <Startup>(uri)) {
                Console.WriteLine(ConsoleTime.GetTime(DateTime.Now) + "loading service");
                Console.WriteLine(ConsoleTime.GetTime(DateTime.Now) + "    service type -> server");
                Console.WriteLine(ConsoleTime.GetTime(DateTime.Now) + "                 -> server url -> {0}", uri);
                Console.WriteLine(ConsoleTime.GetTime(DateTime.Now) + "service is now running");
                var elapsed = DateTime.Now - startTime;
                Console.WriteLine(ConsoleTime.GetTime(DateTime.Now) + "loaded in: " + elapsed);

                Console.WriteLine("");
                ServiceUnitInfo.SetDefaultUnitInfo();
                Console.WriteLine(ConsoleTime.GetTime(DateTime.Now) + "misc -> default unit info saved to database");

                UnitFile.WriteForSelf();
                Console.WriteLine(ConsoleTime.GetTime(DateTime.Now) + "self -> unit file created");

                Systemctl.Enable("antd.service");
                Console.WriteLine(ConsoleTime.GetTime(DateTime.Now) + "self -> unit file enabled");

                //Console.WriteLine("");
                //string[] watchThese = new string[] {
                //    "/cfg",
                //    "/proc/sys",
                //    "/sys/class/net"
                //};
                //foreach (string folder in watchThese) {
                //    new DirectoryWatcher(folder).Watch();
                //    Console.WriteLine(ConsoleTime.GetTime(DateTime.Now) + "watcher enabled for {0}", folder);
                //}

                stop.WaitOne();
            }
        }
コード例 #3
0
    private static UnitClass[] GetHeroClasses(UnitClass source, string spritename)
    {
        UnitClass cls1  = new UnitClass(source);
        UnitFile  file1 = new UnitFile();

        file1.FileName = "graphics/units/heroes/" + spritename + "/sprites";
        cls1.File      = file1;

        UnitClass cls2  = new UnitClass(source);
        UnitFile  file2 = new UnitFile();

        file2.FileName = "graphics/units/heroes_l/" + spritename + "/sprites";
        cls2.File      = file2;

        return(new UnitClass[] { cls2, cls1 });
    }
コード例 #4
0
        public ViewLotEditor(DatabaseIndex index, Dictionary <uint, Property> properties)
        {
            UnitFileEntry = new UnitFile();
            UnitFileEntry.Load(properties);

            InitializeComponent();

            OriginalIndex = index;

            ContainerGrid.DataContext = UnitFileEntry;

            LoadUnitModel();
            viewPort.Children.Add(manipulator);

            viewPort.CameraMode            = CameraMode.Inspect;
            viewPort.ZoomExtentsWhenLoaded = true;
        }
コード例 #5
0
        static int Main(string[] args)
        {
            UnitFile theFile;
            string   fName = "UnitTypes.dat";
            Unit     curUnit;

            // Try building it with the file name provided
            theFile = new UnitFile(fName);

            // Try initializing it
            try
            {
                theFile.init();
                Console.Out.WriteLine("The file was read and has {0} units", theFile.UnitCount);

                List <UnitFactionNode> theFacts = theFile.UnitDir.GetStartingUnits();
                Console.Out.WriteLine("______________________________ NEA\tCon\tGPF\tRoT\tCal\tPac\tEU\tRUS");
                foreach (UnitFactionNode fact in theFacts)
                {
                    Console.Out.WriteLine("{0,-30} {1,5} {2,5} {3,5} {4,5} {4,5} {5,5} {6,5} {7,5} {8,5}",
                                          fact.Name.Value,
                                          fact.FactionCounts[(int)UnitFaction.NEA].Value,
                                          fact.FactionCounts[(int)UnitFaction.Con].Value,
                                          fact.FactionCounts[(int)UnitFaction.GPF].Value,
                                          fact.FactionCounts[(int)UnitFaction.RoT].Value,
                                          fact.FactionCounts[(int)UnitFaction.Cal].Value,
                                          fact.FactionCounts[(int)UnitFaction.Pac].Value,
                                          fact.FactionCounts[(int)UnitFaction.EU].Value,
                                          fact.FactionCounts[(int)UnitFaction.Rus].Value);
                }
            }
            catch (SUE_InvalidFileException sueIFE)
            {
                Console.Out.WriteLine(sueIFE.Message);
            }

            return(0);
        }
コード例 #6
0
 protected override Texture2D GetDeathPalette(UnitFile cls)
 {
     return(GetPalette());
 }
コード例 #7
0
 protected virtual Texture2D GetDeathPalette(UnitFile f)
 {
     return(f.UpdatePalette(LogicUnit.Face));
 }
コード例 #8
0
    public static int[] HeroMaterials = new int[16]; // 0 = heroes_l, 1 = heroes

    public static void InitClasses()
    {
        if (ClassesLoaded)
        {
            return;
        }
        ClassesLoaded = true;
        Registry reg       = new Registry("graphics/units/units.reg");
        int      UnitCount = reg.GetInt("Global", "UnitCount", 0);
        int      FileCount = reg.GetInt("Global", "FileCount", 0);

        for (int i = 0; i < FileCount; i++)
        {
            string   filename = reg.GetString("Files", string.Format("File{0}", i), "");
            UnitFile file     = new UnitFile();
            file.FileName = "graphics/units/" + filename.Replace('\\', '/');
            Files.Add(file);
        }

        for (int i = 0; i < UnitCount; i++)
        {
            string    on  = string.Format("Unit{0}", i);
            UnitClass cls = new UnitClass();

            cls.DescText = reg.GetString(on, "DescText", cls.DescText);
            cls.ID       = reg.GetInt(on, "ID", cls.ID);
            int clsFile = reg.GetInt(on, "File", -1);
            if (clsFile >= 0 && clsFile < Files.Count)
            {
                cls.File = Files[clsFile];
            }
            cls.ParentID        = reg.GetInt(on, "Parent", cls.ParentID);
            cls.Index           = reg.GetInt(on, "Index", cls.Index);
            cls.IdlePhases      = reg.GetInt(on, "IdlePhases", cls.IdlePhases);
            cls.MovePhases      = reg.GetInt(on, "MovePhases", cls.MovePhases);
            cls.MoveBeginPhases = reg.GetInt(on, "MoveBeginPhases", cls.MoveBeginPhases);
            cls.AttackPhases    = reg.GetInt(on, "AttackPhases", cls.AttackPhases);
            cls.DyingPhases     = reg.GetInt(on, "DyingPhases", cls.DyingPhases);
            cls.BonePhases      = reg.GetInt(on, "BonePhases", cls.BonePhases);
            cls.Width           = reg.GetInt(on, "Width", cls.Width);
            cls.Height          = reg.GetInt(on, "Height", cls.Height);
            if (cls.Width != UnitClass.MagicIntNull && cls.Height != UnitClass.MagicIntNull)
            {
                int w  = cls.Width;
                int h  = cls.Height;
                int cx = reg.GetInt(on, "CenterX", UnitClass.MagicIntNull);
                int cy = reg.GetInt(on, "CenterY", UnitClass.MagicIntNull);
                if (cx != UnitClass.MagicIntNull && cy != UnitClass.MagicIntNull)
                {
                    cls.CenterX = (float)cx / w;
                    cls.CenterY = (float)cy / h;
                }

                int s1x = reg.GetInt(on, "SelectionX1", UnitClass.MagicIntNull);
                int s1y = reg.GetInt(on, "SelectionY1", UnitClass.MagicIntNull);
                int s2x = reg.GetInt(on, "SelectionX2", UnitClass.MagicIntNull);
                int s2y = reg.GetInt(on, "SelectionY2", UnitClass.MagicIntNull);
                if (s1x != UnitClass.MagicIntNull && s1y != UnitClass.MagicIntNull &&
                    s2x != UnitClass.MagicIntNull && s2y != UnitClass.MagicIntNull)
                {
                    cls.SelectionX1 = s1x - w / 2;
                    cls.SelectionX2 = s2x - w / 2;
                    cls.SelectionY1 = s1y - h / 2;
                    cls.SelectionY2 = s2y - h / 2;
                }
            }

            int[] attackAnimFrame = reg.GetArray(on, "AttackAnimFrame", null);
            int[] attackAnimTime  = reg.GetArray(on, "AttackAnimTime", null);
            if (attackAnimFrame != null && attackAnimTime != null &&
                attackAnimFrame.Length == attackAnimTime.Length)
            {
                cls.AttackFrames = new UnitClass.AnimationFrame[attackAnimFrame.Length];
                for (int j = 0; j < cls.AttackFrames.Length; j++)
                {
                    UnitClass.AnimationFrame af;
                    af.Frame            = attackAnimFrame[j];
                    af.Time             = attackAnimTime[j];
                    cls.AttackFrames[j] = af;
                }
            }

            int[] moveAnimFrame = reg.GetArray(on, "MoveAnimFrame", null);
            int[] moveAnimTime  = reg.GetArray(on, "MoveAnimTime", null);
            if (moveAnimFrame != null && moveAnimTime != null &&
                moveAnimFrame.Length == moveAnimTime.Length)
            {
                cls.MoveFrames = new UnitClass.AnimationFrame[moveAnimFrame.Length];
                for (int j = 0; j < cls.MoveFrames.Length; j++)
                {
                    UnitClass.AnimationFrame af;
                    af.Frame          = moveAnimFrame[j];
                    af.Time           = moveAnimTime[j];
                    cls.MoveFrames[j] = af;
                }
            }

            int[] idleAnimFrame = reg.GetArray(on, "IdleAnimFrame", null);
            int[] idleAnimTime  = reg.GetArray(on, "IdleAnimTime", null);
            if (idleAnimFrame != null && idleAnimTime != null &&
                idleAnimFrame.Length == idleAnimTime.Length)
            {
                cls.IdleFrames = new UnitClass.AnimationFrame[idleAnimFrame.Length];
                for (int j = 0; j < cls.IdleFrames.Length; j++)
                {
                    UnitClass.AnimationFrame af;
                    af.Frame          = idleAnimFrame[j];
                    af.Time           = idleAnimTime[j];
                    cls.IdleFrames[j] = af;
                }
            }

            cls.DyingID     = reg.GetInt(on, "Dying", cls.DyingID);
            cls.Palette     = reg.GetInt(on, "Palette", cls.Palette);
            cls.AttackDelay = reg.GetInt(on, "AttackDelay", cls.AttackDelay);
            cls.InfoPicture = reg.GetString(on, "InfoPicture", cls.InfoPicture);
            cls.InMapEditor = reg.GetInt(on, "InMapEditor", 0) != 0;
            cls.Flip        = reg.GetInt(on, "Flip", 0) != 0;
            cls.Projectile  = reg.GetInt(on, "Projectile", cls.Projectile);
            int[] shootOffset = reg.GetArray(on, "ShootOffset", null);
            if (shootOffset != null && shootOffset.Length == 16)
            {
                cls.ShootOffset = new Vector2[8];
                for (int j = 0; j < 8; j++)
                {
                    int   ix = shootOffset[j * 2];
                    int   iy = shootOffset[j * 2 + 1];
                    float fx = ix;
                    float fy = iy;
                    cls.ShootOffset[j] = new Vector2(fx, fy);
                }
            }

            Classes.Add(cls);
        }

        foreach (UnitClass cls in Classes)
        {
            int id = cls.ParentID;
            while (id != -1)
            {
                UnitClass clsp = null;
                foreach (UnitClass clsp_ in Classes)
                {
                    if (clsp_.ID == id)
                    {
                        clsp = clsp_;
                        break;
                    }
                }

                if (clsp == null)
                {
                    break;
                }

                if (cls.Parent == null)
                {
                    cls.Parent = clsp;
                }

                if (cls.DescText == null)
                {
                    cls.DescText = clsp.DescText;
                }
                if (cls.File == null)
                {
                    cls.File = clsp.File;
                }
                if (cls.Index == UnitClass.MagicIntNull)
                {
                    cls.Index = clsp.Index;
                }
                if (cls.IdlePhases == UnitClass.MagicIntNull)
                {
                    cls.IdlePhases = clsp.IdlePhases;
                }
                if (cls.MovePhases == UnitClass.MagicIntNull)
                {
                    cls.MovePhases = clsp.MovePhases;
                }
                if (cls.MoveBeginPhases == UnitClass.MagicIntNull)
                {
                    cls.MoveBeginPhases = clsp.MoveBeginPhases;
                }
                if (cls.AttackPhases == UnitClass.MagicIntNull)
                {
                    cls.AttackPhases = clsp.AttackPhases;
                }
                if (cls.DyingPhases == UnitClass.MagicIntNull)
                {
                    cls.DyingPhases = clsp.DyingPhases;
                }
                if (cls.BonePhases == UnitClass.MagicIntNull)
                {
                    cls.BonePhases = clsp.BonePhases;
                }
                if (cls.Width == UnitClass.MagicIntNull)
                {
                    cls.Width = clsp.Width;
                }
                if (cls.Height == UnitClass.MagicIntNull)
                {
                    cls.Height = clsp.Height;
                }
                if (cls.CenterX == -2)
                {
                    cls.CenterX = clsp.CenterX;
                }
                if (cls.CenterY == -2)
                {
                    cls.CenterY = clsp.CenterY;
                }
                if (cls.SelectionX1 == UnitClass.MagicIntNull)
                {
                    cls.SelectionX1 = clsp.SelectionX1;
                }
                if (cls.SelectionY1 == UnitClass.MagicIntNull)
                {
                    cls.SelectionY1 = clsp.SelectionY1;
                }
                if (cls.SelectionX2 == UnitClass.MagicIntNull)
                {
                    cls.SelectionX2 = clsp.SelectionX2;
                }
                if (cls.SelectionY2 == UnitClass.MagicIntNull)
                {
                    cls.SelectionY2 = clsp.SelectionY2;
                }
                if (cls.AttackFrames == null)
                {
                    cls.AttackFrames = clsp.AttackFrames;
                }
                if (cls.MoveFrames == null)
                {
                    cls.MoveFrames = clsp.MoveFrames;
                }
                if (cls.DyingID == UnitClass.MagicIntNull)
                {
                    cls.DyingID = clsp.DyingID;
                }
                if (cls.Palette == UnitClass.MagicIntNull)
                {
                    cls.Palette = clsp.Palette;
                }
                if (cls.AttackDelay == UnitClass.MagicIntNull)
                {
                    cls.AttackDelay = clsp.AttackDelay;
                }
                if (cls.InfoPicture == null)
                {
                    cls.InfoPicture = clsp.InfoPicture;
                }
                if (cls.InMapEditor == false)
                {
                    cls.InMapEditor = clsp.InMapEditor;
                }
                if (cls.Flip == false)
                {
                    cls.Flip = clsp.Flip;
                }
                if (cls.Projectile == UnitClass.MagicIntNull)
                {
                    cls.Projectile = clsp.Projectile;
                }
                if (cls.ShootOffset == null)
                {
                    cls.ShootOffset = clsp.ShootOffset;
                }

                id = clsp.ParentID;
            }
        }

        foreach (UnitClass cls in Classes)
        {
            if (cls.DescText == null)
            {
                cls.DescText = "<INVALID>";
            }
            if (cls.Index == UnitClass.MagicIntNull)
            {
                cls.Index = 0;
            }
            if (cls.IdlePhases == UnitClass.MagicIntNull)
            {
                cls.IdlePhases = 1;
            }
            if (cls.MovePhases == UnitClass.MagicIntNull)
            {
                cls.MovePhases = 0;
            }
            if (cls.MoveBeginPhases == UnitClass.MagicIntNull)
            {
                cls.MoveBeginPhases = 0;
            }
            if (cls.AttackPhases == UnitClass.MagicIntNull)
            {
                cls.AttackPhases = 0;
            }
            if (cls.DyingPhases == UnitClass.MagicIntNull)
            {
                cls.DyingPhases = 0;
            }
            if (cls.BonePhases == UnitClass.MagicIntNull)
            {
                cls.BonePhases = 0;
            }
            if (cls.Width == UnitClass.MagicIntNull)
            {
                cls.Width = 0;
            }
            if (cls.Height == UnitClass.MagicIntNull)
            {
                cls.Height = 0;
            }
            if (cls.CenterX == -2)
            {
                cls.CenterX = 0;
            }
            if (cls.CenterY == -2)
            {
                cls.CenterY = 0;
            }
            if (cls.SelectionX1 == UnitClass.MagicIntNull)
            {
                cls.SelectionX1 = 0;
            }
            if (cls.SelectionY1 == UnitClass.MagicIntNull)
            {
                cls.SelectionY1 = 0;
            }
            if (cls.SelectionX2 == UnitClass.MagicIntNull)
            {
                cls.SelectionX2 = 0;
            }
            if (cls.SelectionY2 == UnitClass.MagicIntNull)
            {
                cls.SelectionY2 = 0;
            }
            if (cls.AttackFrames == null)
            {
                cls.AttackFrames = null;
            }
            if (cls.MoveFrames == null)
            {
                cls.MoveFrames = null;
            }
            if (cls.DyingID == UnitClass.MagicIntNull)
            {
                cls.DyingID = cls.ID;
            }
            if (cls.Palette == UnitClass.MagicIntNull)
            {
                cls.Palette = -1;
            }
            if (cls.AttackDelay == UnitClass.MagicIntNull)
            {
                cls.AttackDelay = 0;
            }
            if (cls.InfoPicture == null)
            {
                cls.InfoPicture = "beeh";
            }
            if (cls.Projectile == UnitClass.MagicIntNull)
            {
                cls.Projectile = 0;
            }
            if (cls.ShootOffset == null)
            {
                cls.ShootOffset = new Vector2[8];
                for (int i = 0; i < 8; i++)
                {
                    cls.ShootOffset[i] = new Vector2(0.0f, 0.0f);
                }
            }
            else
            {
                for (int i = 0; i < 8; i++)
                {
                    cls.ShootOffset[i].x = cls.ShootOffset[i].x / cls.Width - cls.CenterX;
                    cls.ShootOffset[i].y = cls.ShootOffset[i].y / cls.Height - cls.CenterY;
                }
            }
            cls.Dying       = GetUnitClassById(cls.DyingID);
            cls.InfoPicture = "graphics/infowindow/" + cls.InfoPicture;
        }

        // init human hero classes
        HeroUnarmed     = GetHeroClasses(GetUnitClassById(1), "unarmed");
        HeroUnarmed_    = GetHeroClasses(GetUnitClassById(2), "unarmed_");
        HeroSwordsman   = GetHeroClasses(GetUnitClassById(3), "swordsman");
        HeroSwordsman_  = GetHeroClasses(GetUnitClassById(4), "swordsman_");
        HeroSwordsman2h = GetHeroClasses(GetUnitClassById(5), "swordsman2h");
        HeroAxeman      = GetHeroClasses(GetUnitClassById(7), "axeman");
        HeroAxeman_     = GetHeroClasses(GetUnitClassById(8), "axeman_");
        HeroAxeman2h    = GetHeroClasses(GetUnitClassById(9), "axeman2h");
        HeroClubman     = GetHeroClasses(GetUnitClassById(10), "clubman");
        HeroClubman_    = GetHeroClasses(GetUnitClassById(11), "clubman_");
        HeroPikeman     = GetHeroClasses(GetUnitClassById(12), "pikeman");
        HeroPikeman_    = GetHeroClasses(GetUnitClassById(13), "pikeman_");
        HeroArcher      = GetHeroClasses(GetUnitClassById(14), "archer");
        HeroCrossbowman = GetHeroClasses(GetUnitClassById(15), "xbowman");
        HeroMage        = GetHeroClasses(GetUnitClassById(23), "mage");
        HeroMageSt      = GetHeroClasses(GetUnitClassById(24), "mage_st");

        Registry materialReg = new Registry("graphics/units/material.reg");

        for (int i = 0; i < 16; i++)
        {
            string matRaw = materialReg.GetString(string.Format("Material{0}", i), "Path", "heroes_l").ToLower();
            if (matRaw == "heroes")
            {
                HeroMaterials[i] = 1;
            }
            else
            {
                HeroMaterials[i] = 0;
            }
        }
    }
コード例 #9
0
        public ActionResult Create(FileModel fileModel)
        {
            if (ModelState.IsValid && fileModel.UploadFile != null)
            {
                var fileId = Guid.NewGuid();
                var aws = new FileHandle();
                var result = aws.NewFile("pedagogyworld", fileId.ToString("N"), fileModel.UploadFile.InputStream, fileModel.UploadFile.ContentType);
                if (result)
                {
                    var file = new File
                        {
                            Id = fileId,
                            ContentType = fileModel.UploadFile.ContentType,
                            ContentLength = fileModel.UploadFile.ContentLength,
                            FileName = fileModel.UploadFile.FileName,
                            StoragePath = fileId.ToString("N"),
                            UserProfile_Id = (int) Membership.GetUser().ProviderUserKey
                        };
                    db.Files.Add(file);

                    foreach (var t in fileModel.FileIds)
                    {
                        var type = new FileFileType
                        {
                            File_Id = fileId,
                            FileType_Id = t
                        };
                        db.FileFileTypes.Add(type);
                    }

                    var unit = new UnitFile
                    {
                        File_Id = fileId,
                        Unit_Id = fileModel.Id
                    };

                    db.UnitFiles.Add(unit);
                    db.SaveChanges();
                }
                return RedirectToAction("Details", "Unit", new { fileModel.Id });
            }
            var typeList = new List<SelectListItem>();
            foreach (var t in db.FileTypes)
            {
                typeList.Add(new SelectListItem
                {
                    Text = t.FileTypeName,
                    Value = t.Id.ToString()
                });
            }
            fileModel.FileTypes = typeList.ToList();
            return View(fileModel);
        }