Example #1
0
    public void Demolish(IBuildableData demolishData)
    {
        BuildingResult result = BuildingResult.Init;

        if (moneyManager.CanSpend(demolishData.Price))
        {
            switch (demolishData.Buildable)
            {
            case Buildable.Station:
                DemolishStation(demolishData as StationData, out result);
                break;

            case Buildable.Track:
                DemolishTrack(demolishData as TrackData, out result);
                break;

            case Buildable.All:
                DemolishAll(demolishData, out result);
                break;

            default:
                throw new ArgumentOutOfRangeException();
                break;
            }
        }
        else
        {
            result = BuildingResult.InsufficientFunds;
        }

        switch (result)
        {
        case BuildingResult.Success:
            moneyManager.Spend(demolishData.Price);
            break;

        case BuildingResult.InsufficientFunds:
        case BuildingResult.SpaceBlocked:
        case BuildingResult.IllegalPlacement:
        case BuildingResult.NothingThere:
            Debug.LogWarning("Demolish Failed - " + demolishData.Buildable + " - " + result);
            break;

        default:
            throw new ArgumentOutOfRangeException();
            break;
        }
    }