Ejemplo n.º 1
0
    private void UpdatePowerGenerationAndConsumption()
    {
        // Calculate the actual generation for this frame
        float combinedGeneration = m_ShipCurentGenerationRate * Time.deltaTime;

        // Calculate the combined consumption of all facilities
        float combinedConsumption = m_ShipCurrentConsumptionRate * Time.deltaTime;

        // If the current charge + combined generation of the ship is less than this frames consumption, there is insufficient power
        if (combinedConsumption > (m_ShipCurrentCharge + combinedGeneration))
        {
            // Deactivate power to all facilities onboard the ship
            foreach (GameObject facility in gameObject.GetComponent <CShipFacilities>().Facilities)
            {
                CFacilityPower fp = facility.GetComponent <CFacilityPower>();

                if (fp.IsPowerActive)
                {
                    fp.InsufficienttPower();
                }
            }
        }

        // Select the available storage units
        var availableStorageUnits =
            from psm in m_PowerStorages
            where psm.GetComponent <CPowerStorageBehaviour>().IsBatteryChargeAvailable
            select psm.GetComponent <CPowerStorageBehaviour>();

        // Distribute the charge and consumption to the storage units
        DistributeChargeAndConsumption(combinedGeneration, combinedConsumption, availableStorageUnits.ToList());
    }
Ejemplo n.º 2
0
    private void UpdateConsumptionVariables()
    {
        // Calculate the combined consumption of all facilities
        m_ShipCurrentConsumptionRate = 0.0f;
        foreach (GameObject facility in gameObject.GetComponent <CShipFacilities>().Facilities)
        {
            CFacilityPower fp = facility.GetComponent <CFacilityPower>();

            if (fp.IsPowerActive)
            {
                m_ShipCurrentConsumptionRate += fp.PowerConsumption;
            }
        }
    }
Ejemplo n.º 3
0
    /////////////////////////////////////////////////////////////////////////////////////////
    /////////////////////////////////////////////////////////////////////////////////////////

    //float fModulePowerConsumption;

    //[AServerOnly]
    //void UpdateModulePowerConsumption()
    //{
    //    fModulePowerConsumption = (float)CModuleInterface.GetAllModules().Sum((m) =>
    //    {
    //        CModulePower mp = m.GetComponent<CModulePower>();
    //        return (mp.IsPowerActive ? mp.PowerConsumption * Time.deltaTime : 0.0);
    //    });

    //    float TOTAL = combinedConsumption + fModulePowerConsumption;

    //    Debug.Log("TOTAL: " + TOTAL.ToString());
    //}

    /////////////////////////////////////////////////////////////////////////////////////////
    /////////////////////////////////////////////////////////////////////////////////////////

    public void OnGUI()
    {
        return;

        string shipPowerOutput = "ShipPowerInfo\n";

        shipPowerOutput += string.Format("\tBatteryChargePool: [{0}]\n",
                                         Math.Round(m_ShipCurrentCharge, 2));



        string generatorOutput = "GeneratorInfo\n";

        foreach (GameObject generator in m_PowerGenerators)
        {
            CFacilityInterface        fi  = CUtility.FindInParents <CFacilityInterface>(generator);
            CPowerGenerationBehaviour pgb = generator.GetComponent <CPowerGenerationBehaviour>();

            generatorOutput += string.Format("\t[{0}] Within Facility [{1}] Type [{2}] \n\t\tIsGenerationActive: [{3}] GenRate: [{4}]\n",
                                             generator.name,
                                             fi.FacilityId,
                                             fi.FacilityType,
                                             pgb.IsPowerGenerationActive,
                                             Math.Round(pgb.PowerGenerationRate, 2));
        }

        string storageOutput = "StorageInfo\n";

        foreach (GameObject storage in m_PowerStorages)
        {
            CFacilityInterface     fi  = CUtility.FindInParents <CFacilityInterface>(storage);
            CPowerStorageBehaviour psb = storage.GetComponent <CPowerStorageBehaviour>();

            storageOutput += string.Format("\t[{0}] Within Facility [{1}] Type [{2}] \n\t\tIsChargeAvailable: [{3}] Capacity: [{4}] Charge: [{5}]\n",
                                           storage.name,
                                           fi.FacilityId,
                                           fi.FacilityType,
                                           psb.IsBatteryChargeAvailable,
                                           Math.Round(psb.BatteryCapacity, 2),
                                           Math.Round(psb.BatteryCharge, 2));
        }

        string facilitiesOutput = "FacilityPowerInfo\n";

        foreach (GameObject facility in gameObject.GetComponent <CShipFacilities>().Facilities)
        {
            CFacilityInterface fi = facility.GetComponent <CFacilityInterface>();
            CFacilityPower     fp = facility.GetComponent <CFacilityPower>();

            facilitiesOutput += string.Format("\tFacility [{0}] Type [{1}] \n\t\tIsActive: [{2}] ConsRate: [{3}]\n",
                                              fi.FacilityId,
                                              fi.FacilityType,
                                              fp.IsPowerActive,
                                              Math.Round(fp.PowerConsumption, 2));
        }

        float boxWidth  = 500;
        float boxHeight = 600;

        GUI.Label(new Rect(Screen.width / 2 - boxWidth, 0.0f, boxWidth, boxHeight),
                  "Power Status'\n" + shipPowerOutput + generatorOutput + storageOutput + facilitiesOutput);
    }