예제 #1
0
        static void Main(string[] args)
        {
            var mapNumber = "01";

            // Use an absolute path to the planetside mod ready location
            var data = ZplReader.ReadZplFile($"D:\\Planetside (Mod ready)\\Planetside", mapNumber);
        }
예제 #2
0
        static void Main(string[] args)
        {
            System.Threading.Tasks.Parallel.ForEach(maps, map =>
            {
                var mapNumber = map.Number;
                var mapName   = map.Name;

                var zplData = map.IsCave ? ZplReader.ReadZplFile(_planetsideModReadyFolder, mapNumber) : new List <Zipline>();

                var json     = File.ReadAllText($"guids_{map.FilePrefix.ToLower()}{mapNumber}.json");
                var _objList = JsonConvert.DeserializeObject <List <PlanetSideObject> >(json);

                var _lastTurretGUID = 5000;             // This keeps track of the last used turret weapon guid, as they seem to be arbitrarily assigned at 5000+
                var _usedLockIds    = new List <int>(); // List of lock ids already used to ensure no lock is assigned to two doors
                var _usedDoorIds    = new List <int>(); // List of door ids already used to ensure no door is assigned two locks (e.g. Akkan CC has two locks on top of each other for one door)

                var file = File.Create($"{map.FilePrefix}{mapNumber}.scala");
                using (var writer = new StreamWriter(file))
                {
                    writer.WriteLine("package zonemaps");
                    writer.WriteLine("");
                    if (!string.IsNullOrWhiteSpace(map.MapScale))
                    {
                        writer.WriteLine("import net.psforever.objects.zones.MapScale");
                    }
                    writer.WriteLine("import net.psforever.objects.zones.ZoneMap");
                    writer.WriteLine("import net.psforever.objects.GlobalDefinitions._");
                    writer.WriteLine("import net.psforever.objects.LocalProjectile");
                    writer.WriteLine("import net.psforever.objects.ballistics.Projectile");
                    writer.WriteLine("import net.psforever.objects.serverobject.doors.Door");
                    writer.WriteLine("import net.psforever.objects.serverobject.generator.Generator");
                    writer.WriteLine("import net.psforever.objects.serverobject.implantmech.ImplantTerminalMech");
                    writer.WriteLine("import net.psforever.objects.serverobject.locks.IFFLock");
                    writer.WriteLine("import net.psforever.objects.serverobject.mblocker.Locker");
                    writer.WriteLine("import net.psforever.objects.serverobject.pad.VehicleSpawnPad");
                    writer.WriteLine("import net.psforever.objects.serverobject.painbox.Painbox");
                    writer.WriteLine("import net.psforever.objects.serverobject.structures.{Building, FoundationBuilder, StructureType, WarpGate}");
                    writer.WriteLine("import net.psforever.objects.serverobject.terminals.{CaptureTerminal, ProximityTerminal, Terminal}");
                    writer.WriteLine("import net.psforever.objects.serverobject.tube.SpawnTube");
                    writer.WriteLine("import net.psforever.objects.serverobject.resourcesilo.ResourceSilo");
                    writer.WriteLine("import net.psforever.objects.serverobject.turret.FacilityTurret");
                    writer.WriteLine("import net.psforever.types.Vector3");
                    writer.WriteLine("import net.psforever.objects.serverobject.zipline.ZipLinePath");
                    writer.WriteLine("");
                    writer.WriteLine($"object {map.FilePrefix}{mapNumber} {{ // {mapName}");
                    writer.WriteLine($"val ZoneMap = new ZoneMap(\"{map.FilePrefix.ToLower()}{mapNumber}\") {{");
                    if (!string.IsNullOrWhiteSpace(map.MapScale))
                    {
                        writer.WriteLine($"Scale = {map.MapScale}");
                    }
                    writer.WriteLine($"Checksum = {map.Checksum}L");

                    var processed = new List <PlanetSideObject>();
                    foreach (var obj in _objList.Where(x => x.Owner == null && !_blacklistedTypes.Contains(x.ObjectType)))
                    {
                        var children = _objList.Where(x => x.Owner == obj.Id).ToList();

                        var structureType = "Building";

                        // For some reason when spawning at a Redoubt building the client requests a spawn type of Tower, likely to allow the choice of spawning at both Redoubt and Module buildings
                        if (_towerTypes.Contains(obj.ObjectType.ToLower()) || obj.ObjectType.ToLower() == "redoubt")
                        {
                            structureType = "Tower";
                        }
                        if (_buildingTypes.Contains(obj.ObjectType.ToLower()))
                        {
                            structureType = "Facility";
                        }
                        if (_bunkerTypes.Contains(obj.ObjectType.ToLower()))
                        {
                            structureType = "Bunker";
                        }
                        //todo: Platform types

                        if (_towerTypes.Contains(obj.ObjectType.ToLower()) ||
                            _buildingTypes.Contains(obj.ObjectType.ToLower()) ||
                            _bunkerTypes.Contains(obj.ObjectType.ToLower()) ||
                            _warpGateTypes.Contains(obj.ObjectType.ToLower()) ||
                            _otherBuildingTypes.Contains(obj.ObjectType.ToLower()) ||
                            _cavernBuildingTypes.Contains(obj.ObjectType.ToLower())
                            )
                        {
                            writer.WriteLine("");
                            writer.WriteLine($"Building{obj.MapID}()");
                            writer.WriteLine($"def Building{obj.MapID}() : Unit = {{ // Name: {obj.ObjectName} Type: {obj.ObjectType} GUID: {obj.GUID}, MapID: {obj.MapID}");

                            if (_warpGateTypes.Contains(obj.ObjectType.ToLower()))
                            {
                                writer.WriteLine(obj.ObjectType.ToLower() == "hst"
                                    ? $"LocalBuilding(\"{obj.ObjectName}\", {obj.GUID}, {obj.MapID}, FoundationBuilder(WarpGate.Structure(Vector3({obj.AbsX}f, {obj.AbsY}f, {obj.AbsZ}f), hst)))"
                                    : $"LocalBuilding(\"{obj.ObjectName}\", {obj.GUID}, {obj.MapID}, FoundationBuilder(WarpGate.Structure(Vector3({obj.AbsX}f, {obj.AbsY}f, {obj.AbsZ}f))))");
                            }
                            else
                            {
                                writer.WriteLine($"LocalBuilding(\"{obj.ObjectName}\", {obj.GUID}, {obj.MapID}, FoundationBuilder(Building.Structure(StructureType.{structureType}, Vector3({obj.AbsX}f, {obj.AbsY}f, {obj.AbsZ}f), Vector3(0f, 0f, {obj.YawDegrees}f), {obj.ObjectType})))");
                            }

                            WriteCaptureConsole(_objList, children, writer);
                            WriteDoorsAndLocks(_objList, ref _usedDoorIds, ref _usedLockIds, children, writer);
                            WriteLockers(_objList, children, writer);
                            WriteTerminalsAndSpawnPads(_objList, children, obj, writer);
                            WriteResourceSilos(_objList, children, writer);
                            WriteSpawnTubes(_objList, children, obj, writer);
                            WriteProximityTerminals(_objList, children, writer);
                            WriteTurrets(_objList, ref _lastTurretGUID, children, writer);
                            WriteImplantTerminals(_objList, children, writer);
                            WritePainboxes(_objList, children, writer);
                            WriteGeneratorsAndTerminals(_objList, children, writer);
                            writer.WriteLine("}");

                            processed.Add(obj);
                        }
                    }

                    var zoneOwnedObjects = _objList.Where(x => x.Owner == null && !processed.Contains(x) && !_blacklistedTypes.Contains(x.ObjectType)).ToList();

                    if (zoneOwnedObjects.Count() > 0)
                    {
                        writer.WriteLine("");
                        writer.WriteLine("ZoneOwnedObjects()");
                        writer.WriteLine("def ZoneOwnedObjects() : Unit = {");
                        WriteCaptureConsole(_objList, zoneOwnedObjects, writer);
                        WriteDoorsAndLocks(_objList, ref _usedDoorIds, ref _usedLockIds, zoneOwnedObjects, writer);
                        WriteLockers(_objList, zoneOwnedObjects, writer);
                        WriteTerminalsAndSpawnPads(_objList, zoneOwnedObjects, null, writer);
                        WriteResourceSilos(_objList, zoneOwnedObjects, writer);
                        WriteSpawnTubes(_objList, zoneOwnedObjects, null, writer);
                        WriteProximityTerminals(_objList, zoneOwnedObjects, writer);
                        WriteTurrets(_objList, ref _lastTurretGUID, zoneOwnedObjects, writer);
                        WriteImplantTerminals(_objList, zoneOwnedObjects, writer);
                        WritePainboxes(_objList, zoneOwnedObjects, writer);
                        writer.WriteLine("}");
                    }

                    WriteLatticeLinks(map, writer);
                    if (zplData.Count != 0)
                    {
                        WriteZipLines(zplData, writer);
                    }

                    writer.WriteLine("}");
                    writer.WriteLine("}");
                    writer.Flush();
                }
            });

            Console.WriteLine("Done");
        }
예제 #3
0
        static void Main(string[] args)
        {
            var maps = new List <(string name, string mapNumber, bool isCave)> {
                ("Solsar", "01", false),
                ("Hossin", "02", false),
                ("Cyssor", "03", false),
                ("Ishundar", "04", false),
                ("Forseral", "05", false),
                ("Ceryshen", "06", false),
                ("Esamir", "07", false),
                ("Oshur Prime", "08", false),
                ("Searhus", "09", false),
                ("Amerish", "10", false),
                ("HOME1 (NEW CONGLOMORATE SANCTUARY)", "11", false),
                ("HOME2 (TERRAN REPUBLIC SANCTUARY)", "12", false),
                ("HOME3 (VANU SOVREIGNTY SANCTUARY)", "13", false),
                ("Nexus", "96", false),
                ("Desolation", "97", false),
                ("Ascension", "98", false),
                ("Extinction", "99", false),
                ("Supai", "01", true),
                ("Hunhau", "02", true),
                ("Adlivun", "03", true),
                ("Byblos", "04", true),
                ("Annwn", "05", true),
                ("Drugaskan", "06", true)
            };

            // Load all *.ubr files
            Parallel.ForEach(Directory.GetFiles(_planetsideModReadyFolder, "*.ubr", SearchOption.AllDirectories),
                             file => { _ubrData.TryAdd(file, UBRReader.GetUbrData(file)); });

            foreach (var map in maps)
            {
                var identifiableObjects = new List <PlanetSideObject>();

                var(mapName, mapNumber, isCave) = map;
                Console.WriteLine($"Processing map {mapNumber} - {mapName}");

                int id = 0;

                if (!isCave)
                {
                    // Read the contents_map mpo file, and the associated objects_map lst file
                    var mpoData = MPOReader.ReadMPOFile(_planetsideModReadyFolder, mapNumber);
                    foreach (var entry in mpoData)
                    {
                        ProcessObject(identifiableObjects, entry, ref id, mapId: mpoData.IndexOf(entry) + 1, isTopLevel: true);
                    }
                }

                // Read groundcover data
                var groundCoverData = LSTReader.ReadGroundCoverLST(_planetsideModReadyFolder, mapNumber, isCave);
                foreach (var line in groundCoverData)
                {
                    var mapObj = LstObjectToMapObject(line);
                    ProcessObject(
                        identifiableObjects,
                        mapObj,
                        ref id,
                        mapId: line.Id,
                        isTopLevel: !mapObj.HasBangPrefix
                        );
                }

                // Battle islands for some reason have an X/Y offset applied to all coordinates in game_objects.adb.lst. Thus, we need to account for that.
                //19318:add_property map99 mapOffsetX 1024.0
                //19319:add_property map99 mapOffsetY 1024.0
                if (new List <string>()
                {
                    "96", "97", "98", "99"
                }.Contains(mapNumber))
                {
                    for (int i = 0; i < identifiableObjects.Count(); i++)
                    {
                        identifiableObjects[i].AbsX += 1024;
                        identifiableObjects[i].AbsY += 1024;
                    }
                }

                // bfr_building doesn't actually have a GUID itself - the door does which is a sub-object in the ubr file.
                // Remove it from the list before assigning GUIDs
                identifiableObjects.RemoveAll(x => x.ObjectType == "bfr_building");

                // Assign GUIDs to loaded map objects
                GUIDAssigner.AssignGUIDs(identifiableObjects);

                // Sanity checking to make sure the amount of objects we've got matches a list of expected object counts
                SanityChecker.CheckObjectCounts(identifiableObjects, mapName, mapNumber);

                // Sanity checking that assigned GUIDs match expected GUID ranges
                SanityChecker.CheckGuidRanges(identifiableObjects, mapName, mapNumber);

                RemoveUnusedLluSockets(identifiableObjects, mapNumber);

                // Export to json file
                var json = JsonConvert.SerializeObject(identifiableObjects.OrderBy(x => x.GUID), Formatting.Indented);

                var filename = !isCave ? $"map{mapNumber}.json" : $"ugd{mapNumber}.json";
                File.WriteAllText(filename, json);

                if (isCave)
                {
                    // Read zipline data, reformat and export as json
                    var zplData = ZplReader.ReadZplFile(_planetsideModReadyFolder, mapNumber);

                    File.WriteAllText($"zpl_ugd{mapNumber}.json", JsonConvert.SerializeObject(zplData, Formatting.Indented));
                }
            }

            Console.WriteLine("Done");
            Console.ReadKey();
        }