Beispiel #1
0
    public bool PlaceBuilding(int x, int y, BuildingTypes type, bool free = false)
    {
        if (!map.CellAtPositionIsType(x, y, CellType.Empty) || (!free && Money - 2000 < 0))
        {
            return(false);
        }

        CityThing t = new CityThing();

        t.cell  = map.CellAtPosition(x, y);
        t.type  = CellType.Building;
        t.Size  = (int)type;
        t.Name  = "A building (" + type.ToString() + ")";
        t.state = ThingState.Normal;

        t.cell.thing = t;

        totalBuildings++;

        if (!free)
        {
            Money -= 2000;
        }

        return(true);
    }
Beispiel #2
0
    public bool PlaceDefense(int x, int y, bool free = false)
    {
        if (!map.CellAtPositionIsType(x, y, CellType.Empty) || (!free && Money - 50000 < 0))
        {
            return(false);
        }

        CityThing t = new CityThing();

        t.cell  = map.CellAtPosition(x, y);
        t.type  = CellType.Defense;
        t.Size  = 0;
        t.Name  = "A rocket launcher";
        t.state = ThingState.Normal;

        t.cell.thing = t;

        totalBuildings++;

        if (!free)
        {
            Money -= 50000;
        }

        return(true);
    }
Beispiel #3
0
    public void OnBomb(Vector3 pos, float damage)
    {
        Vector3    worldPos = (pos + (Vector3.one * (MeshSize / 2))) / MeshSize;
        Vector2Int twoPos   = new Vector2Int(Mathf.FloorToInt(worldPos.x * MapSize), Mathf.FloorToInt(worldPos.z * MapSize));

        if (twoPos.x < 0 || twoPos.x > MapSize || twoPos.y < 0 || twoPos.y > MapSize)
        {
            return;
        }

        CityThing t = null;

        if (city.map.CellAtPosition(twoPos.x, twoPos.y) != null)
        {
            t = city.map.CellAtPosition(twoPos.x, twoPos.y).thing;
        }

        if (t == null || t.type == CellType.Empty)
        {
            return;
        }

        t.Damage            += damage;
        city.damageReceived += damage;

        Vector2 gridPos  = Vector2.zero;
        float   cellSize = MeshSize / MapSize;

        gridPos.x = (((float)twoPos.x / MapSize) * MeshSize) - (MeshSize / 2) + (cellSize / 2);
        gridPos.y = (((float)twoPos.y / MapSize) * MeshSize) - (MeshSize / 2) + (cellSize / 2);

        if (t.type == CellType.Building && t.state != ThingState.Damaged)
        {
            Destroy(t.view.gameObject);

            GameObject bPrefab = Resources.Load <GameObject>(Random.Range(0f, 1f) > 0.5f ? "Prefabs/Bombed-1" : "Prefabs/Bombed-2");
            GameObject v       = Instantiate(bPrefab, new Vector3(gridPos.x, 0, gridPos.y), Quaternion.identity, transform);
            v.transform.rotation = Quaternion.Euler(0, rotations[Random.Range(0, 4)], 0);
            v.GetComponent <CityThingView>().thing = t;
            t.view  = v.GetComponent <CityThingView>();
            t.state = ThingState.Damaged;
            t.Name  = "A damaged building";
        }
        else if (t.view != null)
        {
            //Destroy(t.view);
            //t.view.gameObject.SetActive(false);

            t.state = ThingState.Damaged;
        }
    }
Beispiel #4
0
    public bool PlaceRoad(int x, int y)
    {
        if (!map.CellAtPositionIsType(x, y, CellType.Empty) || Money - 800 < 0)
        {
            return(false);
        }

        CityThing t = new CityThing();

        t.cell  = map.CellAtPosition(x, y);
        t.type  = CellType.Building;
        t.Size  = 1;
        t.Name  = "A road";
        t.state = ThingState.Normal;

        t.cell.thing = t;

        Money -= 800;

        return(true);
    }
Beispiel #5
0
    public bool PlaceTree(int x, int y, bool free = false)
    {
        if (!map.CellAtPositionIsType(x, y, CellType.Empty) || (!free && Money - 400 < 0))
        {
            return(false);
        }

        CityThing t = new CityThing();

        t.cell  = map.CellAtPosition(x, y);
        t.type  = CellType.Park;
        t.Size  = 1;
        t.Name  = "A tree";
        t.state = ThingState.Normal;

        t.cell.thing = t;

        if (!free)
        {
            Money -= 400;
        }

        return(true);
    }