示例#1
0
        private GlobalStructureList ReadGlobalStructurList()
        {
            var gsl = new GlobalStructureList()
            {
                globalStructures = new Dictionary <string, List <GlobalStructureInfo> >()
            };

            var globalStructuresList = new Dictionary <int, GlobalStructureInfo>();
            var dockedToList         = new Dictionary <int, List <int> >();

            using (var DbConnection = new SQLiteConnection($"Data Source='{GlobalDbPath}'"))
            {
                DbConnection.Open();

                Dictionary <int, string> playfields = ReadPlayfields(DbConnection);

                using (var cmd = new SQLiteCommand(DbConnection))
                {
                    cmd.CommandText =
                        @"
SELECT * FROM Structures 
LEFT JOIN Entities ON Structures.entityid = Entities.entityid
ORDER BY pfid
";

                    List <GlobalStructureInfo> currentPlayfieldStructures = null;
                    int currentPlayfieldId = 0;

                    bool initCols            = true;
                    int  pfIdCol             = 0;
                    int  entityIdCol         = 0;
                    int  classNrCol          = 0;
                    int  cntLightsCol        = 0;
                    int  cntTrianglesCol     = 0;
                    int  cntBlocksCol        = 0;
                    int  cntDevicesCol       = 0;
                    int  fuelCol             = 0;
                    int  ispoweredCol        = 0;
                    int  pilotidCol          = 0;
                    int  rotXCol             = 0;
                    int  rotYCol             = 0;
                    int  rotZCol             = 0;
                    int  posXCol             = 0;
                    int  posYCol             = 0;
                    int  posZCol             = 0;
                    int  nameCol             = 0;
                    int  facIdCol            = 0;
                    int  lastvisitedticksCol = 0;
                    int  facgroupCol         = 0;
                    int  etypeCol            = 0;
                    int  coretypeCol         = 0;
                    int  dockedToCol         = 0;

                    var reader = cmd.ExecuteReader();
                    while (reader.Read())
                    {
                        if (initCols)
                        {
                            initCols = false;

                            pfIdCol = reader.GetOrdinal("pfid");

                            entityIdCol         = reader.GetOrdinal("entityid");
                            classNrCol          = reader.GetOrdinal("classNr");
                            cntLightsCol        = reader.GetOrdinal("cntLights");
                            cntTrianglesCol     = reader.GetOrdinal("cntTriangles");
                            cntBlocksCol        = reader.GetOrdinal("cntBlocks");
                            cntDevicesCol       = reader.GetOrdinal("cntDevices");
                            fuelCol             = reader.GetOrdinal("fuel");
                            ispoweredCol        = reader.GetOrdinal("ispowered");
                            pilotidCol          = reader.GetOrdinal("pilotid");
                            rotXCol             = reader.GetOrdinal("rotX");
                            rotYCol             = reader.GetOrdinal("rotY");
                            rotZCol             = reader.GetOrdinal("rotZ");
                            posXCol             = reader.GetOrdinal("posX");
                            posYCol             = reader.GetOrdinal("posY");
                            posZCol             = reader.GetOrdinal("posZ");
                            nameCol             = reader.GetOrdinal("name");
                            facIdCol            = reader.GetOrdinal("facid");
                            lastvisitedticksCol = reader.GetOrdinal("lastvisitedticks");
                            facgroupCol         = reader.GetOrdinal("facgroup");
                            etypeCol            = reader.GetOrdinal("etype");
                            coretypeCol         = reader.GetOrdinal("coretype");
                            dockedToCol         = reader.GetOrdinal("dockedTo");
                        }

                        int pfid = reader.GetInt32(pfIdCol);

                        if (pfid != currentPlayfieldId)
                        {
                            currentPlayfieldId = pfid;
                            gsl.globalStructures.Add(playfields[pfid], currentPlayfieldStructures = new List <GlobalStructureInfo>());
                        }

                        var gsi = new GlobalStructureInfo()
                        {
                            id             = reader.GetInt32(entityIdCol),
                            dockedShips    = new List <int>(),
                            classNr        = reader.GetInt32(classNrCol),
                            cntLights      = reader.GetInt32(cntLightsCol),
                            cntTriangles   = reader.GetInt32(cntTrianglesCol),
                            cntBlocks      = reader.GetInt32(cntBlocksCol),
                            cntDevices     = reader.GetInt32(cntDevicesCol),
                            fuel           = (int)reader.GetFloat(fuelCol),
                            powered        = reader.GetBoolean(ispoweredCol),
                            rot            = new PVector3(reader.GetFloat(rotXCol), reader.GetFloat(rotYCol), reader.GetFloat(rotZCol)),
                            pos            = new PVector3(reader.GetFloat(posXCol), reader.GetFloat(posYCol), reader.GetFloat(posZCol)),
                            lastVisitedUTC = reader.GetInt64(lastvisitedticksCol),
                            name           = reader.GetString(nameCol),
                            factionId      = reader.GetInt32(facIdCol),
                            factionGroup   = reader.GetByte(facgroupCol),
                            type           = reader.GetByte(etypeCol),
                            coreType       = (sbyte)reader.GetByte(coretypeCol),
                            pilotId        = reader[pilotidCol] is DBNull ? 0 : reader.GetInt32(pilotidCol),
                        };

                        if (!(reader[dockedToCol] is DBNull))
                        {
                            var dockedTo = reader.GetInt32(dockedToCol);
                            if (dockedToList.TryGetValue(dockedTo, out var dockedShips))
                            {
                                dockedShips.Add(gsi.id);
                            }
                            else
                            {
                                dockedToList.Add(dockedTo, new List <int> {
                                    gsi.id
                                });
                            }
                        }

                        globalStructuresList.Add(gsi.id, gsi);
                        currentPlayfieldStructures.Add(gsi);
                    }
                }
            }

            foreach (var item in dockedToList)
            {
                globalStructuresList[item.Key].dockedShips.AddRange(item.Value);
            }

            return(gsl);
        }
示例#2
0
        /// <summary>
        /// Read building sheet.
        /// </summary>
        public static Dictionary <map_id, GlobalStructureInfo> ReadBuildingSheet()
        {
            string[][] buildingSheet = ReadSheet("building.txt");
            if (buildingSheet == null)
            {
                return(null);
            }

            Dictionary <map_id, GlobalStructureInfo> infoRecords = new Dictionary <map_id, GlobalStructureInfo>(buildingSheet.GetLength(0));

            // Read rows
            for (int i = 0; i < buildingSheet.GetLength(0); ++i)
            {
                string[] row = buildingSheet[i];

                // Skip rows that don't contain enough data (probably empty line)
                if (row.Length < 32)
                {
                    continue;
                }

                string     codeName           = row[0];                                 // Code_Name
                string     produceName        = row[1];                                 // Produce List Name
                string     buildingName       = row[2];                                 // Building Name
                int        sizeX              = ReadInt(row[3]);                        // X-size
                int        sizeY              = ReadInt(row[4]);                        // y-size
                ColonyType owner              = ReadOwner(row[5]);                      // Owner [P/E/B]
                int        hitPoints          = ReadInt(row[6]);                        // Hit Points
                int        armorClass         = ReadInt(row[7]);                        // Armor Class
                bool       border             = ReadBool(row[8]);                       // Border [Y/N]
                int        commonOreCost      = ReadInt(row[9]);                        // Common Ore Cost
                int        rareOreCost        = ReadInt(row[10]);                       // Rare Ore Cost
                bool       structureKit       = ReadBool(row[11]);                      // Structure Kit [Y/N]
                int        buildingPoints     = ReadInt(row[12]);                       // Building Points
                int        commonRubble       = ReadInt(row[13]);                       // Normal Rubble (tile count)
                int        rareRubble         = ReadInt(row[14]);                       // Rare Rubble (tile count)
                int        powerRequired      = ReadInt(row[15]);                       // Power Required
                int        workersRequired    = ReadInt(row[16]);                       // Workers Required
                int        scientistsRequired = ReadInt(row[17]);                       // Scientists Required
                int        sightRange         = ReadInt(row[18]);                       // Sight Range
                bool       dockingAll         = ReadBool(row[19]);                      // Docking All [Y/N]
                bool       dockingTruck       = ReadBool(row[20]);                      // Docking Truck [Y/N]
                bool       dockingConvec      = ReadBool(row[21]);                      // Docking Convec [Y/N]
                bool       dockingEvac        = ReadBool(row[22]);                      // Docking Evac [Y/N]
                int        dockingLocationE   = ReadInt(row[23]);                       // Docking Loc E
                int        dockingLocationP   = ReadInt(row[24]);                       // Docking Loc P
                int        storageCapacity    = ReadInt(row[25]);                       // Storage Capacity
                int        productionCapacity = ReadInt(row[26]);                       // Production Capacity
                int        storageBays        = ReadInt(row[27]);                       // Storage bays
                bool       autoTargeted       = ReadBool(row[28]);                      // Can be autotargeted [Y/N]
                int        explosionSize      = ReadInt(row[29]);                       // Explosion size
                int        resourcePriority   = ReadInt(row[30]);                       // Resource priority
                int        researchTopic      = ReadInt(row[31]);                       // Research topic (leading zero, tech ID)

                map_id unitTypeId = GetMapIdFromCodeName(codeName);

                BuildingFlags buildingFlags = 0;

                if (structureKit)
                {
                    buildingFlags |= BuildingFlags.StructureKit;
                }
                if (dockingAll)
                {
                    buildingFlags |= BuildingFlags.DockingAll;
                }
                if (dockingTruck)
                {
                    buildingFlags |= BuildingFlags.DockingTruck;
                }
                if (dockingConvec)
                {
                    buildingFlags |= BuildingFlags.DockingConvec;
                }
                if (dockingEvac)
                {
                    buildingFlags |= BuildingFlags.DockingEvac;
                }
                if (autoTargeted)
                {
                    buildingFlags |= BuildingFlags.CanBeAutoTargeted;
                }

                infoRecords[unitTypeId] = new GlobalStructureInfo(unitTypeId, researchTopic, buildingName, codeName,
                                                                  hitPoints, armorClass, commonOreCost, rareOreCost, buildingPoints, sightRange,
                                                                  produceName, sizeX, sizeY, buildingFlags, resourcePriority, rareRubble, commonRubble, dockingLocationE, dockingLocationP,
                                                                  powerRequired, workersRequired, scientistsRequired, storageCapacity, productionCapacity, storageBays, explosionSize);
            }

            return(infoRecords);
        }
        private string GetStructureChanges(GlobalStructureInfo?aLastData, GlobalStructureInfo aStructureInfo, Action <dynamic> aAddInfo)
        {
            dynamic Changes = new ExpandoObject();

            if (aLastData?.dockedShips?.Count != aStructureInfo.dockedShips?.Count)
            {
                Changes.DockedShips = aStructureInfo.dockedShips;     Changes.DockedShipsOld = aLastData?.dockedShips;
            }
            if (aLastData?.classNr != aStructureInfo.classNr)
            {
                Changes.ClassNr = aStructureInfo.classNr;         Changes.ClassNrOld = aLastData?.classNr;
            }
            if (aLastData?.cntLights != aStructureInfo.cntLights)
            {
                Changes.CntLights = aStructureInfo.cntLights;       Changes.CntLightsOld = aLastData?.cntLights;
            }
            if (aLastData?.cntTriangles != aStructureInfo.cntTriangles)
            {
                Changes.CntTriangles = aStructureInfo.cntTriangles;    Changes.CntTrianglesOld = aLastData?.cntTriangles;
            }
            if (aLastData?.cntBlocks != aStructureInfo.cntBlocks)
            {
                Changes.CntBlocks = aStructureInfo.cntBlocks;       Changes.CntBlocksOld = aLastData?.cntBlocks;
            }
            if (aLastData?.cntDevices != aStructureInfo.cntDevices)
            {
                Changes.CntDevices = aStructureInfo.cntDevices;      Changes.CntDevicesOld = aLastData?.cntDevices;
            }
            if (aLastData?.powered != aStructureInfo.powered)
            {
                Changes.Powered = aStructureInfo.powered;         Changes.PoweredOld = aLastData?.powered;
            }
            if (aLastData?.name != aStructureInfo.name)
            {
                Changes.Name = aStructureInfo.name;            Changes.NameOld = aLastData?.name;
            }
            if (aLastData?.factionId != aStructureInfo.factionId)
            {
                Changes.FactionId = aStructureInfo.factionId;       Changes.FactionIdOld = aLastData?.factionId;
            }
            if (aLastData?.factionGroup != aStructureInfo.factionGroup)
            {
                Changes.FactionGroup = aStructureInfo.factionGroup;    Changes.FactionGroupOld = aLastData?.factionGroup;
            }
            if (aLastData?.coreType != aStructureInfo.coreType)
            {
                Changes.CoreType = aStructureInfo.coreType;        Changes.CoreTypeOld = aLastData?.coreType;
            }
            if (aLastData?.pilotId != aStructureInfo.pilotId)
            {
                Changes.PilotId = aStructureInfo.pilotId;         Changes.PilotIdOld = aLastData?.pilotId;
            }
            if (aLastData?.type != aStructureInfo.type)
            {
                Changes.Type = aStructureInfo.type;            Changes.TypeOld = aLastData?.type;
            }
            if (aLastData?.lastVisitedUTC != aStructureInfo.lastVisitedUTC)
            {
                Changes.LastVisitedUTC = DateTime.FromBinary(aStructureInfo.lastVisitedUTC);
            }
            aAddInfo?.Invoke(Changes);
            return(JsonConvert.SerializeObject(Changes, ExpandoObjectConverter));
        }