public static void CargoTruckAIArriveAtTargetForRealGasStationPost(ushort vehicleID, ref Vehicle vehicleData)
        {
            BuildingManager instance = Singleton <BuildingManager> .instance;

            if (vehicleData.m_targetBuilding != 0)
            {
                Building buildingData = instance.m_buildings.m_buffer[vehicleData.m_targetBuilding];
                if (!(buildingData.Info.m_buildingAI is OutsideConnectionAI))
                {
                    if (GasStationAI.IsGasBuilding(vehicleData.m_targetBuilding) == true)
                    {
                        switch ((TransferManager.TransferReason)vehicleData.m_transferType)
                        {
                        case TransferManager.TransferReason.Petrol:

                            vehicleData.m_transferSize = 0;
                            if (MainDataStore.petrolBuffer[vehicleData.m_targetBuilding] <= 57000)
                            {
                                MainDataStore.petrolBuffer[vehicleData.m_targetBuilding] += 8000;
                            }
                            if (Loader.isRealCityRunning)
                            {
                                float productionValue = 8000 * GetResourcePrice((TransferManager.TransferReason)vehicleData.m_transferType);
                                Singleton <EconomyManager> .instance.FetchResource(EconomyManager.Resource.ResourcePrice, (int)productionValue, ItemClass.Service.PlayerIndustry, ItemClass.SubService.PlayerIndustryOil, ItemClass.Level.Level1);
                            }
                            break;

                        default:
                            DebugLog.LogToFileOnly("Error: Find a import trade m_transferType = " + vehicleData.m_transferType.ToString()); break;
                        }
                    }
                }
            }
        }
 public static void Postfix(ushort buildingID, ref Building buildingData, ref Building.Frame frameData)
 {
     if (GasStationAI.IsGasBuilding(buildingID))
     {
         if (buildingData.m_flags.IsFlagSet(Building.Flags.Completed))
         {
             GasStationAI.ProcessGasBuildingIncoming(buildingID, ref buildingData);
         }
     }
 }
예제 #3
0
 public static void PlayerBuildingAISimulationStepPostFix(ushort buildingID, ref Building buildingData, ref Building.Frame frameData)
 {
     MainDataStore.finalVehicleForFuelCount[buildingID] = MainDataStore.tempVehicleForFuelCount[buildingID];
     MainDataStore.tempVehicleForFuelCount[buildingID]  = 0;
     if (GasStationAI.IsGasBuilding(buildingID))
     {
         if (buildingData.m_flags.IsFlagSet(Building.Flags.Completed))
         {
             GasStationAI.ProcessGasBuildingIncoming(buildingID, ref buildingData);
         }
     }
 }
        public override void Update()
        {
            var Building = WorldInfoPanel.GetCurrentInstanceID().Building;

            if (WorldInfoPanel.GetCurrentInstanceID() != InstanceID.Empty)
            {
                BuildingID = WorldInfoPanel.GetCurrentInstanceID();
            }

            if (GasStationAI.IsGasBuilding(Building, true) && Loader.isGuiRunning)
            {
                relativePosition = new Vector3(playerBuildingInfo.size.x - width - 90, playerBuildingInfo.size.y - height);
                base.Show();
            }

            base.Update();
        }
        public static void StartTransfer(TransferManager.TransferReason material, TransferManager.TransferOffer offerOut, TransferManager.TransferOffer offerIn, int delta)
        {
            bool active  = offerIn.Active;
            bool active2 = offerOut.Active;

            if (active && offerIn.Vehicle != 0)
            {
                DebugLog.LogToFileOnly("Error: active && offerIn.Vehicle");
            }
            else if (active2 && offerOut.Vehicle != 0)
            {
                Array16 <Vehicle> vehicles2 = Singleton <VehicleManager> .instance.m_vehicles;
                ushort            vehicle2  = offerOut.Vehicle;
                VehicleInfo       info2     = vehicles2.m_buffer[(int)vehicle2].Info;
                offerIn.Amount = delta;
                if (GasStationAI.IsGasBuilding(offerIn.Building))
                {
                    Array16 <Building> buildings = Singleton <BuildingManager> .instance.m_buildings;
                    ushort             building  = offerIn.Building;
                    BuildingInfo       info3     = buildings.m_buffer[(int)building].Info;
                    StartGasTransfer(vehicle2, ref vehicles2.m_buffer[(int)vehicle2], material, offerIn);
                }
                else
                {
                    DebugLog.LogToFileOnly("Error: active2 && offerOut.Vehicle");
                }
            }
            else if (active && offerIn.Citizen != 0u)
            {
                DebugLog.LogToFileOnly("Error: active && offerIn.Citizen");
            }
            else if (active2 && offerOut.Citizen != 0u)
            {
                DebugLog.LogToFileOnly("Error: active2 && offerOut.Citizen");
            }
            else if (active2 && offerOut.Building != 0)
            {
                DebugLog.LogToFileOnly("Error: active2 && offerOut.Building");
            }
            else if (active && offerIn.Building != 0)
            {
                DebugLog.LogToFileOnly("Error: active && offerIn.Building");
            }
        }
        public static ushort FindToll(Vector3 pos, float maxDistance)
        {
            int             num      = Mathf.Max((int)((pos.x - maxDistance) / 64f + 135f), 0);
            int             num2     = Mathf.Max((int)((pos.z - maxDistance) / 64f + 135f), 0);
            int             num3     = Mathf.Min((int)((pos.x + maxDistance) / 64f + 135f), 269);
            int             num4     = Mathf.Min((int)((pos.z + maxDistance) / 64f + 135f), 269);
            ushort          result   = 0;
            BuildingManager building = Singleton <BuildingManager> .instance;
            float           num5     = maxDistance * maxDistance;

            for (int i = num2; i <= num4; i++)
            {
                for (int j = num; j <= num3; j++)
                {
                    ushort num6 = building.m_buildingGrid[i * 270 + j];
                    int    num7 = 0;
                    while (num6 != 0)
                    {
                        BuildingInfo info = building.m_buildings.m_buffer[(int)num6].Info;
                        if (GasStationAI.IsGasBuilding((ushort)num6))
                        {
                            if (!building.m_buildings.m_buffer[(int)num6].m_flags.IsFlagSet(Building.Flags.Deleted))
                            {
                                float num8 = Vector3.SqrMagnitude(pos - building.m_buildings.m_buffer[(int)num6].m_position);
                                if (num8 < num5)
                                {
                                    result = num6;
                                    num5   = num8;
                                    break;
                                }
                            }
                        }
                        num6 = building.m_buildings.m_buffer[(int)num6].m_nextGridBuilding;
                        if (++num7 >= 49152)
                        {
                            CODebugBase <LogChannel> .Error(LogChannel.Core, "Invalid list detected!\n" + Environment.StackTrace);

                            break;
                        }
                    }
                }
            }
            return(result);
        }
        private void RefreshDisplayData()
        {
            uint currentFrameIndex = Singleton <SimulationManager> .instance.m_currentFrameIndex;
            uint num2 = currentFrameIndex & 255u;

            if (PlayerBuildingUI.refeshOnce || (MainDataStore.lastBuilding != WorldInfoPanel.GetCurrentInstanceID().Building))
            {
                if (base.isVisible)
                {
                    MainDataStore.lastBuilding = WorldInfoPanel.GetCurrentInstanceID().Building;
                    Building buildingData = Singleton <BuildingManager> .instance.m_buildings.m_buffer[MainDataStore.lastBuilding];

                    if (GasStationAI.IsGasBuilding(MainDataStore.lastBuilding) == true)
                    {
                        this.Petrol.text = string.Format(Localization.Get("PETROL_STORED") + " [{0}]", MainDataStore.petrolBuffer[MainDataStore.lastBuilding]);
                        this.inComingVehicleCount.text = string.Format(Localization.Get("INCOMING_VEHICLE_COUNT") + " [{0}]", MainDataStore.finalVehicleForFuelCount[MainDataStore.lastBuilding]);
                        both.isVisible  = true;
                        heavy.isVisible = true;
                        small.isVisible = true;
                        both.isChecked  = (MainDataStore.resourceCategory[MainDataStore.lastBuilding] == 0) ? true : false;
                        heavy.isChecked = (MainDataStore.resourceCategory[MainDataStore.lastBuilding] == 1) ? true : false;
                        small.isChecked = (MainDataStore.resourceCategory[MainDataStore.lastBuilding] == 2) ? true : false;
                        both.text       = Localization.Get("ACCEPT_ALL_VEHICLE");
                        heavy.text      = Localization.Get("ACCEPT_HEAVY_VEHICLE");
                        small.text      = Localization.Get("ACCEPT_SMALL_VEHICLE");
                    }
                    else
                    {
                        this.Petrol.text = "";
                        this.inComingVehicleCount.text = "";
                        both.isVisible  = false;
                        heavy.isVisible = false;
                        small.isVisible = false;
                        Hide();
                    }
                    PlayerBuildingUI.refeshOnce = false;
                }
                else
                {
                    this.Hide();
                }
            }
        }
예제 #8
0
        private void RefreshDisplayData()
        {
            if (refeshOnce || (MainDataStore.lastBuildingID != WorldInfoPanel.GetCurrentInstanceID().Building))
            {
                if (base.isVisible)
                {
                    MainDataStore.lastBuildingID = WorldInfoPanel.GetCurrentInstanceID().Building;

                    if (GasStationAI.IsGasBuilding(MainDataStore.lastBuildingID, true) == true)
                    {
                        this.Petrol.text = string.Format(Localization.Get("PETROL_STORED") + " [{0}]", MainDataStore.petrolBuffer[MainDataStore.lastBuildingID]);
                        this.inComingVehicleCount.text = string.Format(Localization.Get("INCOMING_VEHICLE_COUNT") + " [{0}]", MainDataStore.finalVehicleForFuelCount[MainDataStore.lastBuildingID]);
                    }
                    else
                    {
                        this.Petrol.text = "";
                        this.inComingVehicleCount.text = "";
                    }

                    if (buildingType.text != Localization.Get("BUILDING_TYPE"))
                    {
                        buildingTypeDD.items = new string[] { Localization.Get("NORMAL_BUILDING"), Localization.Get("ACCEPT_ALL_VEHICLE"), Localization.Get("ACCEPT_HEAVY_VEHICLE"), Localization.Get("ACCEPT_SMALL_VEHICLE") }
                    }
                    ;
                    if (buildingTypeDD.selectedIndex != MainDataStore.resourceCategory[MainDataStore.lastBuildingID])
                    {
                        buildingTypeDD.selectedIndex = MainDataStore.resourceCategory[MainDataStore.lastBuildingID];
                    }
                    buildingType.text = Localization.Get("BUILDING_TYPE");
                    refeshOnce        = false;
                }
                else
                {
                    this.Hide();
                }
            }
        }
    }
        public static void VehicleStatus(int i, ref Vehicle vehicle, bool canCargoForFuel, bool canCarForFuel)
        {
            if (i < Singleton <VehicleManager> .instance.m_vehicles.m_size)
            {
                uint currentFrameIndex = Singleton <SimulationManager> .instance.m_currentFrameIndex;
                int  num4 = (int)(currentFrameIndex & 255u);
                if (((num4 >> 4) & 15u) == (i & 15u))
                {
                    if (!vehicle.m_flags.IsFlagSet(Vehicle.Flags.Arriving) && (vehicle.m_cargoParent == 0) && vehicle.m_flags.IsFlagSet(Vehicle.Flags.Spawned) && !vehicle.m_flags.IsFlagSet(Vehicle.Flags.GoingBack) && !vehicle.m_flags.IsFlagSet(Vehicle.Flags.Parking))
                    {
                        if (vehicle.Info.m_vehicleAI is CargoTruckAI && (vehicle.m_targetBuilding != 0))
                        {
                            if (!MainDataStore.alreadyAskForFuel[i])
                            {
                                if (GasStationAI.IsGasBuilding(vehicle.m_targetBuilding))
                                {
                                    MainDataStore.alreadyAskForFuel[i] = true;
                                }
                                else
                                {
                                    if (vehicle.m_flags.IsFlagSet(Vehicle.Flags.DummyTraffic) && canCargoForFuel)
                                    {
                                        RealGasStationThreading.RefreshDummyCargoFuel();
                                        if (RealGasStationThreading.dummyCargoNeedFuel)
                                        {
                                            TransferManager.TransferOffer offer = default(TransferManager.TransferOffer);
                                            offer.Priority = (i & 7);
                                            offer.Vehicle  = (ushort)i;
                                            offer.Position = vehicle.GetLastFramePosition();
                                            offer.Amount   = 1;
                                            offer.Active   = true;
                                            Singleton <TransferManager> .instance.AddOutgoingOffer((TransferManager.TransferReason) 127, offer);

                                            MainDataStore.alreadyAskForFuel[i] = true;
                                        }
                                        else
                                        {
                                            RealGasStationThreading.dummyCargoCount++;
                                        }
                                    }
                                    else
                                    {
                                        RealGasStationThreading.RefreshCargoFuel();
                                        if (RealGasStationThreading.cargoNeedFuel)
                                        {
                                            TransferManager.TransferOffer offer = default(TransferManager.TransferOffer);
                                            offer.Priority = (i & 7);
                                            offer.Vehicle  = (ushort)i;
                                            offer.Position = vehicle.GetLastFramePosition();
                                            offer.Amount   = 1;
                                            offer.Active   = true;
                                            Singleton <TransferManager> .instance.AddOutgoingOffer((TransferManager.TransferReason) 127, offer);

                                            MainDataStore.alreadyAskForFuel[i] = true;
                                        }
                                        else
                                        {
                                            RealGasStationThreading.cargoCount++;
                                        }
                                    }
                                }
                            }
                        }
                        else if (vehicle.Info.m_vehicleAI is PassengerCarAI && vehicle.Info.m_class.m_subService == ItemClass.SubService.ResidentialLow)
                        {
                            if (!MainDataStore.alreadyAskForFuel[i])
                            {
                                if (GasStationAI.IsGasBuilding(vehicle.m_targetBuilding))
                                {
                                    MainDataStore.alreadyAskForFuel[i] = true;
                                }
                                else
                                {
                                    ushort citizen = GetDriverInstance((ushort)i, ref vehicle);
                                    if (Singleton <CitizenManager> .instance.m_citizens.m_buffer[Singleton <CitizenManager> .instance.m_instances.m_buffer[citizen].m_citizen].m_flags.IsFlagSet(Citizen.Flags.DummyTraffic) && canCarForFuel)
                                    {
                                        RealGasStationThreading.RefreshDummyCarFuel();
                                        if (RealGasStationThreading.dummyCarNeedFuel)
                                        {
                                            TransferManager.TransferOffer offer = default(TransferManager.TransferOffer);
                                            offer.Priority = (i & 7);
                                            offer.Vehicle  = (ushort)i;
                                            offer.Position = vehicle.GetLastFramePosition();
                                            offer.Amount   = 1;
                                            offer.Active   = true;
                                            Singleton <TransferManager> .instance.AddOutgoingOffer((TransferManager.TransferReason) 126, offer);

                                            MainDataStore.alreadyAskForFuel[i] = true;
                                        }
                                        else
                                        {
                                            RealGasStationThreading.dummyCarCount++;
                                        }
                                    }
                                    else
                                    {
                                        RealGasStationThreading.RefreshCarFuel();
                                        if (RealGasStationThreading.carNeedFuel)
                                        {
                                            TransferManager.TransferOffer offer = default(TransferManager.TransferOffer);
                                            offer.Priority = (i & 7);
                                            offer.Vehicle  = (ushort)i;
                                            offer.Position = vehicle.GetLastFramePosition();
                                            offer.Amount   = 1;
                                            offer.Active   = true;
                                            Singleton <TransferManager> .instance.AddOutgoingOffer((TransferManager.TransferReason) 126, offer);

                                            MainDataStore.alreadyAskForFuel[i] = true;
                                        }
                                        else
                                        {
                                            RealGasStationThreading.carCount++;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                DebugLog.LogToFileOnly("Error: invalid vehicleID = " + i.ToString());
            }
        }
        public static void VehicleStatus(int i, ref Vehicle vehicle)
        {
            if (i < Singleton <VehicleManager> .instance.m_vehicles.m_size)
            {
                uint currentFrameIndex = Singleton <SimulationManager> .instance.m_currentFrameIndex;
                int  num4 = (int)(currentFrameIndex & 4095u);
                if (((num4 >> 8) & 255u) == (i & 255u))
                {
                    GetForFuelCount((ushort)i, ref vehicle);
                    VehicleManager instance = Singleton <VehicleManager> .instance;
                    if (!vehicle.m_flags.IsFlagSet(Vehicle.Flags.Arriving) && (vehicle.m_cargoParent == 0) && vehicle.m_flags.IsFlagSet(Vehicle.Flags.Spawned) && !vehicle.m_flags.IsFlagSet(Vehicle.Flags.GoingBack) && !vehicle.m_flags.IsFlagSet(Vehicle.Flags.Parking))
                    {
                        if (vehicle.Info.m_vehicleAI is CargoTruckAI && (vehicle.m_targetBuilding != 0))
                        {
                            if (!MainDataStore.alreadyAskForFuel[i])
                            {
                                if (GasStationAI.IsGasBuilding(vehicle.m_targetBuilding))
                                {
                                    MainDataStore.alreadyAskForFuel[i] = true;
                                }
                                else
                                {
                                    System.Random rand = new System.Random();
                                    if (vehicle.m_flags.IsFlagSet(Vehicle.Flags.DummyTraffic))
                                    {
                                        if (rand.Next(62) < 2)
                                        {
                                            TransferManager.TransferOffer offer = default(TransferManager.TransferOffer);
                                            offer.Priority = rand.Next(8);
                                            offer.Vehicle  = (ushort)i;
                                            offer.Position = vehicle.GetLastFramePosition();
                                            offer.Amount   = 1;
                                            offer.Active   = true;
                                            Singleton <TransferManager> .instance.AddOutgoingOffer((TransferManager.TransferReason) 113, offer);

                                            MainDataStore.alreadyAskForFuel[i] = true;
                                        }
                                    }
                                    else
                                    {
                                        if (rand.Next(93) < 2)
                                        {
                                            TransferManager.TransferOffer offer = default(TransferManager.TransferOffer);
                                            offer.Priority = rand.Next(8);
                                            offer.Vehicle  = (ushort)i;
                                            offer.Position = vehicle.GetLastFramePosition();
                                            offer.Amount   = 1;
                                            offer.Active   = true;
                                            Singleton <TransferManager> .instance.AddOutgoingOffer((TransferManager.TransferReason) 113, offer);

                                            MainDataStore.alreadyAskForFuel[i] = true;
                                        }
                                    }
                                }
                            }
                        }
                        else if (vehicle.Info.m_vehicleAI is PassengerCarAI && vehicle.Info.m_class.m_subService == ItemClass.SubService.ResidentialLow)
                        {
                            if (!MainDataStore.alreadyAskForFuel[i])
                            {
                                if (GasStationAI.IsGasBuilding(vehicle.m_targetBuilding))
                                {
                                    MainDataStore.alreadyAskForFuel[i] = true;
                                }
                                else
                                {
                                    System.Random rand    = new System.Random();
                                    ushort        citizen = GetDriverInstance((ushort)i, ref vehicle);
                                    if (Singleton <CitizenManager> .instance.m_citizens.m_buffer[Singleton <CitizenManager> .instance.m_instances.m_buffer[citizen].m_citizen].m_flags.IsFlagSet(Citizen.Flags.DummyTraffic))
                                    {
                                        if (rand.Next(62) < 2)
                                        {
                                            TransferManager.TransferOffer offer = default(TransferManager.TransferOffer);
                                            offer.Priority = rand.Next(8);
                                            offer.Vehicle  = (ushort)i;
                                            offer.Position = vehicle.GetLastFramePosition();
                                            offer.Amount   = 1;
                                            offer.Active   = true;
                                            Singleton <TransferManager> .instance.AddOutgoingOffer((TransferManager.TransferReason) 112, offer);

                                            MainDataStore.alreadyAskForFuel[i] = true;
                                        }
                                    }
                                    else
                                    {
                                        if (rand.Next(93) < 2)
                                        {
                                            TransferManager.TransferOffer offer = default(TransferManager.TransferOffer);
                                            offer.Priority = rand.Next(8);
                                            offer.Vehicle  = (ushort)i;
                                            offer.Position = vehicle.GetLastFramePosition();
                                            offer.Amount   = 1;
                                            offer.Active   = true;
                                            Singleton <TransferManager> .instance.AddOutgoingOffer((TransferManager.TransferReason) 112, offer);

                                            MainDataStore.alreadyAskForFuel[i] = true;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                DebugLog.LogToFileOnly("Error: invalid vehicleID = " + i.ToString());
            }
        }