Ejemplo n.º 1
0
        public static List <ushort> getAllBuildingsFromCity(ServiceSystemDefinition ssd)
        {
            List <ushort>     saida = new List <ushort>();
            var               bm    = Singleton <BuildingManager> .instance;
            FastList <ushort> buildings;

            if (ssd.outsideConnection)
            {
                buildings = bm.GetOutsideConnections();
            }
            else
            {
                buildings = bm.GetServiceBuildings(ssd.service);
            }

            SVMUtils.doLog("getAllBuildingsFromCity ({0}) buildings = {1} (s={2})", ssd, buildings.ToArray(), buildings.m_size);

            foreach (ushort i in buildings)
            {
                if (ssd.isFromSystem(bm.m_buildings.m_buffer[i].Info))
                {
                    saida.Add(i);
                }
            }
            SVMUtils.doLog("getAllBuildingsFromCity ({0}) buildings = {1} (s={2}); saida.sz = {3}", ssd, buildings.ToArray(), buildings.m_size, saida.Count);
            return(saida);
        }
Ejemplo n.º 2
0
        public static int GetMaxVehiclesBuilding(ushort buildingID, VehicleInfo.VehicleType type)
        {
            Building b        = Singleton <BuildingManager> .instance.m_buildings.m_buffer[buildingID];
            var      ext      = SVMBuildingAIOverrideUtils.getBuildingOverrideExtension(b.Info);
            var      maxField = ext.GetVehicleMaxCountField(type);

            if (maxField == null)
            {
                return(0xFFFFFF);
            }
            return(SVMUtils.GetPrivateField <int>(b.Info.GetAI(), maxField) * SVMBuildingUtils.GetProductionRate(ref b) / 100);
        }
Ejemplo n.º 3
0
        public static List <ushort> getAllBuildingsFromCity(ServiceSystemDefinition ssd, int?districtId = null, bool strict = false, bool mustAllowSpawn = false)
        {
            List <ushort>     saida = new List <ushort>();
            var               bm    = Singleton <BuildingManager> .instance;
            FastList <ushort> buildings;
            var               ext = ssd.GetTransportExtension();

            if (ssd.outsideConnection)
            {
                buildings = bm.GetOutsideConnections();
            }
            else
            {
                buildings = bm.GetServiceBuildings(ssd.service);
            }

            SVMUtils.doLog("getAllBuildingsFromCity ({0}) buildings = {1} (s={2})", ssd, buildings.ToArray(), buildings.m_size);

            foreach (ushort i in buildings)
            {
                if (ssd.isFromSystem(bm.m_buildings.m_buffer[i].Info))
                {
                    if (districtId != null && ext.GetAllowDistrictServiceRestrictions())
                    {
                        var buildingDistrict = DistrictManager.instance.GetDistrict(bm.m_buildings.m_buffer[i].m_position);
                        if (districtId != buildingDistrict && (strict || !ext.GetAllowGoOutsideEffective(buildingDistrict)))
                        {
                            continue;
                        }
                    }
                    if (mustAllowSpawn)
                    {
                        int max      = GetMaxVehiclesBuilding(i, ssd.vehicleType, ssd.level);
                        int count    = 0;
                        int cargo    = 0;
                        int capacity = 0;
                        int inbound  = 0;
                        int outbound = 0;
                        SVMBuildingUtils.CalculateOwnVehicles(i, ref bm.m_buildings.m_buffer[i], SVMBuildingAIOverrideUtils.getBuildingOverrideExtensionStrict(bm.m_buildings.m_buffer[i].Info).GetManagedReasons(bm.m_buildings.m_buffer[i].Info).Where(x => x.Value.vehicleLevel == null).Select(x => x.Key), ref count, ref cargo, ref capacity, ref inbound, ref outbound);
                        if (count >= max)
                        {
                            continue;
                        }
                    }
                    saida.Add(i);
                }
            }
            SVMUtils.doLog("getAllBuildingsFromCity ({0}) buildings = {1} (s={2}); saida.sz = {3}", ssd, buildings.ToArray(), buildings.m_size, saida.Count);
            return(saida);
        }
Ejemplo n.º 4
0
        public static Texture2D loadTexture(int x, int y, string filename)
        {
            try
            {
                Texture2D texture = new Texture2D(x, y);
                texture.LoadImage(loadResourceData(filename));
                return(texture);
            }
            catch (Exception e)
            {
                SVMUtils.doErrorLog("The file could not be read:" + e.Message);
            }

            return(null);
        }
Ejemplo n.º 5
0
        public static string loadResourceString(string name, string prefix = "Klyte.ServiceVehiclesManager.")
        {
            name = prefix + name;

            UnmanagedMemoryStream stream = (UnmanagedMemoryStream)ResourceAssembly.GetManifestResourceStream(name);

            if (stream == null)
            {
                SVMUtils.doErrorLog("Could not find resource: " + name);
                return(null);
            }

            StreamReader read = new StreamReader(stream);

            return(read.ReadToEnd());
        }
Ejemplo n.º 6
0
        public static byte[] loadResourceData(string name, string prefix = "Klyte.ServiceVehiclesManager.")
        {
            name = prefix + name;

            UnmanagedMemoryStream stream = (UnmanagedMemoryStream)ResourceAssembly.GetManifestResourceStream(name);

            if (stream == null)
            {
                SVMUtils.doErrorLog("Could not find resource: " + name);
                return(null);
            }

            BinaryReader read = new BinaryReader(stream);

            return(read.ReadBytes((int)stream.Length));
        }