Example #1
0
    //ADD CONDITIONS TO MAKE BIGGER
    public void CheckBiggerSize()
    {
        //if no bigger house to evolve to, don't continue
        if (string.IsNullOrEmpty(biggerHouse))
        {
            return;
        }

        //make containers for adjacent houses
        World map = world.Map;
        House h1  = null;
        House h2  = null;
        House h3  = null;

        //check X+1, Y for small house
        //if there is no house or the house there is too big, don't evolve it
        if (map.IsBuildingAt(X + 1, Y))
        {
            House h = map.GetBuildingAt(X + 1, Y).GetComponent <House>();
            if (h == null)
            {
                return;
            }
            if (h.HouseSize != 1)
            {
                return;
            }
            h1 = h;
        }

        //check X, Y+1 for small house
        if (map.IsBuildingAt(X, Y + 1))
        {
            House h = map.GetBuildingAt(X, Y + 1).GetComponent <House>();
            if (h == null)
            {
                return;
            }
            if (h.HouseSize != 1)
            {
                return;
            }
            h2 = h;
        }

        //check X+1, Y+1 for small house
        if (map.IsBuildingAt(X + 1, Y + 1))
        {
            House h = map.GetBuildingAt(X + 1, Y + 1).GetComponent <House>();
            if (h == null)
            {
                return;
            }
            if (h.HouseSize != 1)
            {
                return;
            }
            h3 = h;
        }

        //only proceed if all houses are same level
        if (h1 == null || h2 == null || h3 == null)
        {
            return;
        }

        if (h1.Level != Level || h2.Level != Level || h3.Level != Level)
        {
            return;
        }

        //combine arrays
        Water = ArrayFunctions.CombineArrays(Water, h1.Water, h2.Water, h3.Water);
        Food  = ArrayFunctions.CombineArrays(Food, h1.Food, h2.Food, h3.Food);

        //combine stats
        Residents += h1.Residents + h2.Residents + h3.Residents;
        Health    += h1.Health + h2.Health + h3.Health;

        world.Demolish(h1.X, h1.Y);
        world.Demolish(h2.X, h2.Y);
        world.Demolish(h3.X, h3.Y);
        labor.AddPopulation(h1.Residents + h2.Residents + h3.Residents);
        ChangeHouse(biggerHouse);
    }