Пример #1
0
        private static void LoadSystem(Section sec)
        {
            var sysNick = sec.GetFirstOf("nickname")[0].ToLowerInvariant();
            _log.NewMessage(LogType.Garbage, "Universe: Parsing system {0}", sysNick);

            var stIDSName = GetIDSParm(sec.GetAnySetting("strid_name")[0]);

            var stIDSInfo1 = "";
            if (sec.ContainsAnyOf("ids_info1","ids_short_name"))
                stIDSInfo1 = GetIDSParm(sec.GetAnySetting("ids_info")[0]);

            Gis.Systems.AddSystemsRow(sysNick, stIDSName,stIDSInfo1);

            //string file = Directory.GetParent(ini.filePath).FullName + "\\" + section.GetSetting("file").Str(0);
            //TODO: Warning, hardcoded system path! :S
            var sysFile = new DataFile(_flDataPath + @"\Universe\" + sec.GetFirstOf("file")[0]);

            foreach (var obj in sysFile.GetSections("Object"))
            {
                Setting curset;
                //string pos;
                var idsInfo = "";
                var idsInfo1 = "";

                //TODO: do we need pos?
                //if (obj.TryGetFirstOf("pos", out curset))
                //    pos = string.Join(", ", curset);

                //get infocard for the object
                if (obj.TryGetFirstOf("ids_info", out curset))
                {
                    uint id;
                    if (!uint.TryParse(curset[0], out id))
                    {
                        _log.NewMessage(LogType.Warning, "Can't find ID for object: {0}", curset[0]);
                    }

                    idsInfo = GetIDString(id);
                    if (InfocardMap.ContainsKey(id))
                        idsInfo1 = GetIDString(InfocardMap[id]);
                }

                //add the icard to the base if object is base
                if (obj.TryGetFirstOf("base", out curset))
                    //TODO: really join the stuff, infos are in XML format.
                    Gis.Bases.FindByNickname(curset[0]).Infocard = idsInfo + idsInfo1;

            }

            //TODO: zones needed?
        }
Пример #2
0
        static void _bgw_DoWork(object sender, DoWorkEventArgs e)
        {
            var flIni = (DataFile)((object[]) e.Argument)[0];
            var flPath = (string)((object[])e.Argument)[1];
            // Load the string dlls.
            LoadLibrary(flPath + @"\EXE\" + @"resources.dll");

            foreach (var flResName in flIni.GetSettings("Resources", "DLL"))
                LoadLibrary(flPath + @"\EXE\" + flResName[0]);

            //Scan INIs and bases
            //TODO there's only one universe entry, so do we need foreach universe?
            foreach (var entry in flIni.GetSettings("Data", "universe"))
            {
                //TODO: halt backgroundworker if needed

                var universeIni = new DataFile(_flDataPath + @"\" + entry[0]);

                //Load bases
                foreach (var baseSection in universeIni.GetSections("Base"))
                {

                    LoadBase(baseSection);
                }

                //Load systems
                foreach (var sysSection in universeIni.GetSections("system"))
                {
                    LoadSystem(sysSection);
                }
            }

            foreach (var entry in flIni.GetSettings("Data", "equipment"))
            {
                var equipFile = new DataFile(_flDataPath + @"\" + entry[0]);

                foreach (var eqSection in equipFile.Sections)
                {
                    LoadEquipSection(eqSection);
                }
            }

            foreach (var entry in flIni.GetSettings("Data", "groups"))
            {
                var facFile = new DataFile(_flDataPath + @"\" + entry[0]);

                foreach (var faSection in facFile.GetSections("Group"))
                {
                    LoadFaction(faSection);
                }
            }

            foreach (var entry in flIni.GetSettings("Data", "ships"))
            {
                var shFile = new DataFile(_flDataPath + @"\" + entry[0]);

                foreach (var shSection in shFile.GetSections("Ship"))
                {
                    LoadShip(shSection);
                }
            }

            _log.NewMessage(LogType.Debug, "Universe: Parsing loadouts...");
            var loFile = new DataFile(_flDataPath + @"\equipment\goods.ini");

            foreach (var loSection in loFile.GetSections("Good").Where(w => w.GetFirstOf("category")[0] == "ship"))
            {
                LoadLoadout(loSection, loFile);
            }

            if (!Properties.Settings.Default.FLDataUseCache) return;

            _log.NewMessage(LogType.Info, "Universe: Saving game cache...");
            Gis.WriteXml(flPath + @"/FLSAM_Data.xml");
            _log.NewMessage(LogType.Info, "Universe: Game cache saved.");
        }
Пример #3
0
        private static void LoadLoadout(Section sec, DataFile file)
        {
            //if (sec.GetFirstOf("category")[0] != "ship") return;
            //done in LINQ
            var hullNickName = sec.GetFirstOf("hull")[0];

            //TODO: foreach or FirstOrDefault?
            var shSection = file.GetSections("Good").FirstOrDefault(w =>
                (w.GetFirstOf("category")[0] == "shiphull") &
                (w.GetFirstOf("nickname")[0] == hullNickName)
                );

            if (shSection == null)
            {
                _log.NewMessage(LogType.Warning, "Can't find package for shiphull {0}!", hullNickName);
                return;
            }

                var shipNickname = shSection.GetFirstOf("ship")[0];
                var shiphash = CreateID(shipNickname);

                uint defaultSound = 0;
                uint defaultPowerPlant = 0;
                uint defaultEngine = 0;

                foreach (var set in sec.GetSettings("addon"))
                {
                    if (set.Count != 3)
                    {
                        _log.NewMessage(LogType.Warning,
                            "Package for ship {0}: addon {1} has wrong arg count", shipNickname, set[0]);
                        continue;
                    }

                    var equipNick = set[0];
                    var item = Gis.Equipment.FindByHash(CreateID(equipNick));
                    if (item == null)
                    {
                        _log.NewMessage(LogType.Warning, @"Can't find {0} in DB: from loadout {1} \ {2}", equipNick,
                            hullNickName, shipNickname);
                        continue;
                    }

                    EquipTypes eqType;
                    Enum.TryParse(item.Type, out eqType);

                    switch (eqType)
                    {
                        case EquipTypes.Engine:
                            defaultEngine = item.Hash;
                            break;
                        case EquipTypes.Powerplant:
                            defaultPowerPlant = item.Hash;
                            break;
                        case EquipTypes.InternalFX:
                            defaultSound = item.Hash;
                            break;
                            case EquipTypes.Light:
                            if (set[1] == "internal")
                                _log.NewMessage(LogType.Warning, "Invalid hardpoint for light {0} (internal): {1}", equipNick, hullNickName);
                            break;
                        case EquipTypes.AttachedFX:
                             if (set[1] == "internal")
                                 _log.NewMessage(LogType.Warning, "Invalid hardpoint for attachedFX {0} (internal): {1}", equipNick, hullNickName);
                            break;
                    }

                }
                Gis.ShipDefaultInternals.AddShipDefaultInternalsRow(Gis.Ships.FindByHash(shiphash), defaultEngine,
                    defaultSound, defaultPowerPlant);
        }