Exemple #1
0
    public void SetGenerator(Generator newGenerator)
    {
        //If we have an existing generator, give back the power to that one.
        //This should not happen often, but just in case we do not want someone to duplicate or lose power.
        if (generator != null)
        {
            generator.availablePower += requiredPower;
            generator.connected.Remove(this);
            generator.CheckPower();
        }

        //Remove power from the new generator
        generator = newGenerator;

        generator.availablePower -= requiredPower;
        generator.connected.Add(this);
        //Check with the breaker first if we have one to prevent a blackout
        if (breaker != null)
        {
            breaker.CheckPower();
        }
        generator.CheckPower();

        if (generator.on)
        {
            hasPower = true;
        }

        if (tooltip != null)
        {
            tooltip.SetProperty("Has Power", hasPower.ToString());
        }
    }
Exemple #2
0
    public void SetBreaker(Breaker newBreaker)
    {
        //If we have an existing breaker, give back the power to that one.
        //This should not happen often, but just in case we do not want someone to duplicate or lose power.
        if (breaker != null)
        {
            breaker.takenPower -= requiredPower;
            breaker.connected.Remove(this);
            breaker.CheckPower();
        }

        breaker = newBreaker;

        //Remove power from the new breaker
        //Make the breaker check if it will blackout the generator
        breaker.takenPower += requiredPower;
        breaker.connected.Add(this);
        breaker.CheckPower();

        if (breaker.hasPower)
        {
            hasPower = true;
        }

        if (tooltip != null)
        {
            tooltip.SetProperty("Has Power", hasPower.ToString());
        }
    }