WorldPower

This page uses GameObject from Unity. The glossary says what each one is.

WorldPower tells your mod about blackouts and generators, and lets you control how the player wakes up after a blackout.

WorldPower blackouts, generators and wake-ups

Use ScheduleWakeUp to choose how the player wakes after a blackout, and WakeUp to wake them now.

public static class WorldPower
{
    public static event Action BlackoutStarted;
    public static event Action<bool> GeneratorToggled;

    public static bool IsAvailable { get; }

    public static bool IsBlackoutRunning { get; }
    public static bool AnyGeneratorRunning { get; }

    public static bool ScheduleWakeUp(float fadeOutSpeed, float wakeUpDelay, WakeUpAnimation wakeUpAnimation, bool autoWakeUp);
    public static bool WakeUp();
}
Property Type What it means
IsAvailable bool false when a blackout or generator event could not be set up.
IsBlackoutRunning bool true while a blackout sequence is playing.
AnyGeneratorRunning bool true while any generator is running with power.
Method Returns What it does
ScheduleWakeUp(fadeOutSpeed, wakeUpDelay, wakeUpAnimation, autoWakeUp) bool Sets how the player wakes after the next level load.
WakeUp() bool Wakes the player now.
Event Gives you When it fires
BlackoutStarted Nothing A blackout has just started.
GeneratorToggled bool A generator was switched. The value is the new On state.

WakeUpAnimation how the player wakes up

ScheduleWakeUp takes one of these to pick how the player wakes up.

public enum WakeUpAnimation
{
    None,
    OnGround,
    OnGround2
}
Value Meaning
None No wake-up animation.
OnGround The player wakes up on the ground.
OnGround2 The player wakes up on the ground, with the game’s second ground animation.

Things to know

  • The game has no single power cut for the whole world. Power belongs to each device. IsBlackoutRunning is only about the scripted blackout: the fade to black, the theft and the teleport. (Power is per device (PowerSource). IsBlackoutRunning is true while any BlackoutTrigger sequence is in progress.)
  • BlackoutStarted fires when a new blackout sequence starts. Calls made while one is already running do not fire it again. (It fires when a BlackoutTrigger.StartBlackout call starts a new sequence.)
  • GeneratorToggled fires when a generator is really switched on or off. The value is the new On state. It does not fire when a generator runs out of fuel, because the game turns that off another way. (It fires when the generator’s On switch changes through CraftingBase.Toggle.)
  • ScheduleWakeUp only stores the wake-up for later. The wake-up happens on the next level load, which is when the player wakes. ScheduleWakeUp does not change the level, so your code must change it, the way the game’s blackout does just before the level change. (It calls BlackoutController.SetScheduleWakeUp. The wake-up takes effect in BlackoutController.OnLoadingGame. BlackoutTrigger changes the level with SaveController.ChangeLevel.)
  • WakeUp wakes the player now, using the settings the game stored at the last blackout. It does not use the ones from ScheduleWakeUp. A blackout with autoWakeUp set to false stores them. With none stored, it runs with the animation None and no delay, and it turns the controls back on. (It calls the game’s BlackoutController.TriggerWakeUp, which uses the manual values from SetPendingFinish.)
  • IsAvailable tells you whether the two events work. It is false when the blackout change or the generator change is missing or turned off. A missing change stops only its own event, and the other event keeps firing while IsAvailable is false. Reads are not affected.
  • The light culling system is not a power state. It only hides far-away lights to save work, so it is not here. (It is LightsController.)

Limits

  • Both calls return false in some cases: during a save or a load, and when the game’s blackout controller is missing. WakeUp also returns false when the black screen is missing, because the game needs it to finish the wake-up. (BlackoutController.instance is null, or BlackCanvas.instance is null. FinishWakeUp reads BlackCanvas.instance.gameObject.)