public void TryPlant(bool allow_plant_from_storage = false)
    {
        timeUntilSelfPlant = Util.RandomVariance(2400f, 600f);
        if (!allow_plant_from_storage && base.gameObject.HasTag(GameTags.Stored))
        {
            return;
        }
        int cell = Grid.PosToCell(base.gameObject);

        if (!TestSuitableGround(cell))
        {
            return;
        }
        Vector3    position   = Grid.CellToPosCBC(cell, Grid.SceneLayer.BuildingFront);
        GameObject gameObject = GameUtil.KInstantiate(Assets.GetPrefab(PlantID), position, Grid.SceneLayer.BuildingFront, null, 0);

        gameObject.SetActive(true);
        Pickupable component  = GetComponent <Pickupable>();
        Pickupable pickupable = component.Take(1f);

        if (!((Object)pickupable != (Object)null))
        {
            KCrashReporter.Assert(false, "Seed has fractional total amount < 1f");
            return;
        }
        Crop component2 = gameObject.GetComponent <Crop>();

        if (!((Object)component2 != (Object)null))
        {
            goto IL_00a5;
        }
        goto IL_00a5;
IL_00a5:
        Util.KDestroyGameObject(pickupable.gameObject);
    }
Example #2
0
 private unsafe void OnSimRegistered(int handle)
 {
     if ((UnityEngine.Object) this != (UnityEngine.Object)null && simHandle == -2)
     {
         simHandle = handle;
         int   handleIndex = Sim.GetHandleIndex(handle);
         float temperature = Game.Instance.simData.elementChunks[handleIndex].temperature;
         if (temperature <= 0f)
         {
             KCrashReporter.Assert(false, "Bad temperature");
         }
         handleInstanceMap[simHandle] = this;
         if (pendingEnergyModifications > 0f)
         {
             ModifyEnergy(pendingEnergyModifications);
             pendingEnergyModifications = 0f;
         }
         if (onSimRegistered != null)
         {
             onSimRegistered(this);
         }
     }
     else
     {
         SimMessages.RemoveElementChunk(handle, -1);
     }
 }
Example #3
0
    public void OnLand(object data)
    {
        SpaceDestination spacecraftDestination = SpacecraftManager.instance.GetSpacecraftDestination(SpacecraftManager.instance.GetSpacecraftID(GetComponent <RocketModule>().conditionManager.GetComponent <LaunchableRocket>()));

        SpaceDestination.ResearchOpportunity researchOpportunity = spacecraftDestination.TryCompleteResearchOpportunity();
        if (researchOpportunity != null)
        {
            GameObject gameObject = GameUtil.KInstantiate(Assets.GetPrefab("ResearchDatabank"), base.gameObject.transform.GetPosition(), Grid.SceneLayer.Ore, null, 0);
            gameObject.SetActive(true);
            gameObject.GetComponent <PrimaryElement>().Mass = (float)researchOpportunity.dataValue;
            if (!string.IsNullOrEmpty(researchOpportunity.discoveredRareItem))
            {
                GameObject prefab = Assets.GetPrefab(researchOpportunity.discoveredRareItem);
                if ((Object)prefab == (Object)null)
                {
                    KCrashReporter.Assert(false, "Missing prefab: " + researchOpportunity.discoveredRareItem);
                }
                else
                {
                    GameObject gameObject2 = GameUtil.KInstantiate(prefab, base.gameObject.transform.GetPosition(), Grid.SceneLayer.Ore, null, 0);
                    gameObject2.SetActive(true);
                }
            }
        }
        GameObject gameObject3 = GameUtil.KInstantiate(Assets.GetPrefab("ResearchDatabank"), base.gameObject.transform.GetPosition(), Grid.SceneLayer.Ore, null, 0);

        gameObject3.SetActive(true);
        gameObject3.GetComponent <PrimaryElement>().Mass = (float)ROCKETRY.DESTINATION_RESEARCH.EVERGREEN;
    }
Example #4
0
    public void SpawnResources(object data)
    {
        SpaceDestination spacecraftDestination = SpacecraftManager.instance.GetSpacecraftDestination(SpacecraftManager.instance.GetSpacecraftID(GetComponent <RocketModule>().conditionManager.GetComponent <LaunchableRocket>()));
        int rootCell = Grid.PosToCell(base.gameObject);

        foreach (KeyValuePair <SimHashes, float> item in spacecraftDestination.GetMissionResourceResult(storage.RemainingCapacity(), storageType == CargoType.solids, storageType == CargoType.liquids, storageType == CargoType.gasses))
        {
            Element element = ElementLoader.FindElementByHash(item.Key);
            if (storageType == CargoType.solids && element.IsSolid)
            {
                GameObject gameObject = Scenario.SpawnPrefab(rootCell, 0, 0, element.tag.Name, Grid.SceneLayer.Ore);
                gameObject.GetComponent <PrimaryElement>().Mass        = item.Value;
                gameObject.GetComponent <PrimaryElement>().Temperature = ElementLoader.FindElementByHash(item.Key).defaultValues.temperature;
                gameObject.SetActive(true);
                storage.Store(gameObject, false, false, true, false);
            }
            else if (storageType == CargoType.liquids && element.IsLiquid)
            {
                storage.AddLiquid(item.Key, item.Value, ElementLoader.FindElementByHash(item.Key).defaultValues.temperature, byte.MaxValue, 0, false, true);
            }
            else if (storageType == CargoType.gasses && element.IsGas)
            {
                storage.AddGasChunk(item.Key, item.Value, ElementLoader.FindElementByHash(item.Key).defaultValues.temperature, byte.MaxValue, 0, false, true);
            }
        }
        if (storageType == CargoType.entities)
        {
            foreach (KeyValuePair <Tag, int> item2 in spacecraftDestination.GetMissionEntityResult())
            {
                GameObject prefab = Assets.GetPrefab(item2.Key);
                if ((UnityEngine.Object)prefab == (UnityEngine.Object)null)
                {
                    KCrashReporter.Assert(false, "Missing prefab: " + item2.Key.Name);
                }
                else
                {
                    for (int i = 0; i < item2.Value; i++)
                    {
                        GameObject gameObject2 = Util.KInstantiate(prefab, base.transform.position);
                        gameObject2.SetActive(true);
                        storage.Store(gameObject2, false, false, true, false);
                        Baggable component = gameObject2.GetComponent <Baggable>();
                        if ((UnityEngine.Object)component != (UnityEngine.Object)null)
                        {
                            component.SetWrangled();
                        }
                    }
                }
            }
        }
    }
Example #5
0
 private void SetTemperature(float temperature)
 {
     if (float.IsNaN(temperature) || float.IsInfinity(temperature))
     {
         DebugUtil.LogErrorArgs(base.gameObject, "Invalid temperature [" + temperature + "]");
     }
     else
     {
         if (temperature <= 0f)
         {
             KCrashReporter.Assert(false, "Tried to set PrimaryElement.Temperature to a value <= 0");
         }
         setTemperatureCallback(this, temperature);
     }
 }
Example #6
0
 private Action <InfoDialogScreen> OpenCodex(string key)
 {
     return(delegate(InfoDialogScreen dialog)
     {
         dialog.Deactivate();
         string entryForLock = CodexCache.GetEntryForLock(key);
         if (entryForLock == null)
         {
             KCrashReporter.Assert(false, "Missing codex entry: " + key);
         }
         else
         {
             ManagementMenu.Instance.OpenCodexToEntry(entryForLock);
         }
     });
 }
 public override void Begin(Precondition.Context context)
 {
     if ((UnityEngine.Object)context.consumerState.consumer == (UnityEngine.Object)null)
     {
         Debug.LogError("EATCHORE null context.consumer");
     }
     else
     {
         RationMonitor.Instance sMI = context.consumerState.consumer.GetSMI <RationMonitor.Instance>();
         if (sMI == null)
         {
             Debug.LogError("EATCHORE null RationMonitor.Instance");
         }
         else
         {
             Edible edible = sMI.GetEdible();
             if ((UnityEngine.Object)edible.gameObject == (UnityEngine.Object)null)
             {
                 Debug.LogError("EATCHORE null edible.gameObject");
             }
             else if (base.smi == null)
             {
                 Debug.LogError("EATCHORE null smi");
             }
             else if (base.smi.sm == null)
             {
                 Debug.LogError("EATCHORE null smi.sm");
             }
             else if (base.smi.sm.ediblesource == null)
             {
                 Debug.LogError("EATCHORE null smi.sm.ediblesource");
             }
             else
             {
                 base.smi.sm.ediblesource.Set(edible.gameObject, base.smi);
                 KCrashReporter.Assert(edible.FoodInfo.CaloriesPerUnit > 0f, edible.GetProperName() + " has invalid calories per unit. Will result in NaNs");
                 AmountInstance amountInstance = Db.Get().Amounts.Calories.Lookup(gameObject);
                 float          num            = (amountInstance.GetMax() - amountInstance.value) / edible.FoodInfo.CaloriesPerUnit;
                 KCrashReporter.Assert(num > 0f, "EatChore is requesting an invalid amount of food");
                 base.smi.sm.requestedfoodunits.Set(num, base.smi);
                 base.smi.sm.eater.Set(context.consumerState.gameObject, base.smi);
                 base.Begin(context);
             }
         }
     }
 }
Example #8
0
 private void StopConsuming(Worker worker)
 {
     DebugUtil.DevAssert(isBeingConsumed, "StopConsuming() called without StartConsuming()");
     isBeingConsumed = false;
     if (float.IsNaN(consumptionTime))
     {
         DebugUtil.DevAssert(false, "consumptionTime NaN in StopConsuming()");
     }
     else
     {
         PrimaryElement component = base.gameObject.GetComponent <PrimaryElement>();
         if ((Object)component != (Object)null && component.DiseaseCount > 0)
         {
             new EmoteChore(worker.GetComponent <ChoreProvider>(), Db.Get().ChoreTypes.EmoteHighPriority, "anim_react_contaminated_food_kanim", new HashedString[1]
             {
                 "react"
             }, null);
         }
         float num = Mathf.Clamp01(consumptionTime / GetFeedingTime(worker));
         unitsConsumed = Units * num;
         if (float.IsNaN(unitsConsumed))
         {
             KCrashReporter.Assert(false, "Why is unitsConsumed NaN?");
             unitsConsumed = Units;
         }
         caloriesConsumed = unitsConsumed * foodInfo.CaloriesPerUnit;
         Units           -= unitsConsumed;
         for (int i = 0; i < foodInfo.Effects.Count; i++)
         {
             worker.GetComponent <Effects>().Add(foodInfo.Effects[i], true);
         }
         ReportManager.Instance.ReportValue(ReportManager.ReportType.CaloriesCreated, 0f - caloriesConsumed, StringFormatter.Replace(UI.ENDOFDAYREPORT.NOTES.EATEN, "{0}", this.GetProperName()), worker.GetProperName());
         AddQualityEffects(worker);
         worker.Trigger(1121894420, this);
         Trigger(-10536414, worker.gameObject);
         unitsConsumed    = float.NaN;
         caloriesConsumed = float.NaN;
         consumptionTime  = float.NaN;
         if (Units <= 0f)
         {
             base.gameObject.DeleteObject();
         }
     }
 }
    public float Open()
    {
        if (openCount == 0 && DisplacesGas(doorType))
        {
            StructureTemperatureComponents structureTemperatures = GameComps.StructureTemperatures;
            HandleVector <int> .Handle     handle = structureTemperatures.GetHandle(base.gameObject);
            if (handle.IsValid() && structureTemperatures.IsBypassed(handle))
            {
                int[] placementCells = building.PlacementCells;
                float num            = 0f;
                int   num2           = 0;
                foreach (int i2 in placementCells)
                {
                    if (Grid.Mass[i2] > 0f)
                    {
                        num2++;
                        num += Grid.Temperature[i2];
                    }
                }
                if (num2 > 0)
                {
                    num /= (float)placementCells.Length;
                    PrimaryElement component = GetComponent <PrimaryElement>();
                    KCrashReporter.Assert(num > 0f, "Door has calculated an invalid temperature");
                    component.Temperature = num;
                }
            }
        }
        openCount++;
        float result = 1f;

        if ((Object)consumer != (Object)null)
        {
            result = ((!consumer.IsPowered) ? 0.5f : 1f);
        }
        switch (controlState)
        {
        case ControlState.Auto:
        case ControlState.Opened:
            controller.sm.isOpen.Set(true, controller);
            break;
        }
        return(result);
    }
Example #10
0
    private unsafe static void OnSetTemperature(PrimaryElement primary_element, float temperature)
    {
        if (temperature <= 0f)
        {
            KCrashReporter.Assert(false, "STT.OnSetTemperature - Tried to set <= 0 degree temperature");
            temperature = 293f;
        }
        SimTemperatureTransfer component = primary_element.GetComponent <SimTemperatureTransfer>();

        if (Sim.IsValidHandle(component.simHandle))
        {
            float mass          = primary_element.Mass;
            float heat_capacity = (!(mass >= 0.01f)) ? 0f : (mass * primary_element.Element.specificHeatCapacity);
            SimMessages.SetElementChunkData(component.simHandle, temperature, heat_capacity);
            int handleIndex = Sim.GetHandleIndex(component.simHandle);
            Game.Instance.simData.elementChunks[handleIndex].temperature = temperature;
        }
        else
        {
            primary_element.InternalTemperature = temperature;
        }
    }
Example #11
0
    public void AddParticle(Vector2 root_pos, byte elementIdx, float base_mass, float temperature, byte disease_idx, int base_disease_count, bool skip_sound = false, bool skip_decor = false, bool debug_track = false, bool disable_randomness = false)
    {
        int num = Grid.PosToCell(root_pos);

        if (!Grid.IsValidCell(num))
        {
            KCrashReporter.Assert(false, "Trying to add falling water outside of the scene");
        }
        else
        {
            if (temperature <= 0f || base_mass <= 0f)
            {
                Debug.LogError($"Unexpected water mass/temperature values added to the falling water manager T({temperature}) M({base_mass})");
            }
            float time = GetTime();
            if (!skip_sound)
            {
                if (!topSounds.TryGetValue(num, out SoundInfo value))
                {
                    value        = default(SoundInfo);
                    value.handle = LoopingSoundManager.StartSound(liquid_top_loop, root_pos, true, true);
                }
                value.startTime = time;
                LoopingSoundManager.Get().UpdateSecondParameter(value.handle, HASH_LIQUIDVOLUME, SoundUtil.GetLiquidVolume(base_mass));
                topSounds[num] = value;
            }
            while (base_mass > 0f)
            {
                float num2 = UnityEngine.Random.value * 2f * particleMassVariation - particleMassVariation;
                float num3 = Mathf.Max(0f, Mathf.Min(base_mass, particleMassToSplit + num2));
                float num4 = num3 / base_mass;
                base_mass -= num3;
                int     disease_count = (int)(num4 * (float)base_disease_count);
                int     frame         = UnityEngine.Random.Range(0, numFrames);
                Vector2 b             = (!disable_randomness) ? new Vector2(jitterStep * Mathf.Sin(offset), jitterStep * Mathf.Sin(offset + 17f)) : Vector2.zero;
                Vector2 b2            = (!disable_randomness) ? new Vector2(UnityEngine.Random.Range(0f - multipleOffsetRange.x, multipleOffsetRange.x), UnityEngine.Random.Range(0f - multipleOffsetRange.y, multipleOffsetRange.y)) : Vector2.zero;
                Element element       = ElementLoader.elements[elementIdx];
                Vector2 vector        = root_pos;
                bool    flag          = !skip_decor && SpawnLiquidTopDecor(time, Grid.CellLeft(num), false, element);
                bool    flag2         = !skip_decor && SpawnLiquidTopDecor(time, Grid.CellRight(num), true, element);
                Vector2 b3            = Vector2.ClampMagnitude(initialOffset + b + b2, 1f);
                if (flag || flag2)
                {
                    if (flag && flag2)
                    {
                        vector   += b3;
                        vector.x += 0.5f;
                    }
                    else if (flag)
                    {
                        vector += b3;
                    }
                    else
                    {
                        vector.x += 1f - b3.x;
                        vector.y += b3.y;
                    }
                }
                else
                {
                    vector   += b3;
                    vector.x += 0.5f;
                }
                int           num5     = Grid.PosToCell(vector);
                Element       element2 = Grid.Element[num5];
                Element.State state    = element2.state & Element.State.Solid;
                if (state == Element.State.Solid || (Grid.Properties[num5] & 2) != 0)
                {
                    vector.y = Mathf.Floor(vector.y + 1f);
                }
                physics.Add(new ParticlePhysics(vector, Vector2.zero, frame, elementIdx));
                particleProperties.Add(new ParticleProperties(elementIdx, num3, temperature, disease_idx, disease_count, debug_track));
            }
        }
    }