Beispiel #1
0
    public void OnMouseOver()
    {
        if (GameState.instance.CurrentState != GameState.State.BuildCities)
            return;

        if (textObj == null) {
            textObj = GameObject.Find ("CityPopupText");
            if(textObj != null) {
                if (textMesh == null) {
                    textMesh = textObj.GetComponent<TextMesh> ();
                }
            }
        }

        if (textMesh == null) {
            return;
        }

        textObj.SetActive (true);

        int effectiveCost = StepCost (GameState.instance.gameStep) + effectiveTravelCost;

        if ((effectiveTravelCost == -1) || (StepCost (GameState.instance.gameStep) == -1)) {
            effectiveCost = -1;
        }
        if (effectiveCost == -1) {
            textObj.transform.position = transform.position + new Vector3(0.3f,0.2f,0);
            textMesh.text = gameObject.name + "\nCost: NA" ;//+ "(" + StepCost (GameState.instance.gameStep) + "," + effectiveTravelCost + ")";
        }
        else {
            textObj.transform.position = transform.position + new Vector3(0.3f, 0.2f,0);
            textMesh.text = gameObject.name + "\nCost: " + effectiveCost;// + "(" + StepCost (GameState.instance.gameStep) + "," + effectiveTravelCost + ")";

        }
        if (Input.GetMouseButtonDown (0)) {

            //current player buys city
        //			if(!isTentative) {
                Player p = GameState.instance.CurrentPlayer();
                if(effectiveCost == -1) {
                    print (gameObject.name + " is not available to purchase");
                } else if(p.cash >= effectiveCost) {
                    GameObject obj = (GameObject)Instantiate(
                        GameState.instance.powerPlantObject,
                        transform.position,
                        Quaternion.AngleAxis(Random.Range(0.0f,360.0f),Vector3.up));
                    obj.transform.position += objectOffsets[owners.Count];
                    obj.GetComponent<Renderer>().material.color = p.color;
                    obj.SetActive(true);

                    Player.CityPurchase purchase = new Player.CityPurchase();
                    purchase.purchaseCost = effectiveCost;
                    purchase.city = this;
                    purchase.isTentative = true;
                    purchase.obj = obj;

                    owners.Add(p);
                    p.cityPurchases.Add(purchase);
                    p.cities.Add(this);
                    p.cash -= effectiveCost;
                    print (p.gameObject.name + " bought " + gameObject.name + " for " + effectiveCost);

                    GameState.instance.RecomputeTravelCosts();
                } else {
                    print (p.gameObject.name + " does not have enough cash");
                }
        //			}
        }
    }
Beispiel #2
0
    public void OnMouseOver()
    {
        if (GameState.instance.CurrentState != GameState.State.BuildCities)
            return;

        if (textObj == null) {
            textObj = GameObject.Find ("CityPopupText");
            if(textObj != null) {
                if (textMesh == null) {
                    textMesh = textObj.GetComponent<TextMesh> ();
                }
            }
        }

        if (textMesh == null) {
            return;
        }

        textObj.SetActive (true);

        int effectiveCost = StepCost (GameState.instance.gameStep) + effectiveTravelCost;

        if ((effectiveTravelCost == -1) || (StepCost (GameState.instance.gameStep) == -1)) {
            effectiveCost = -1;
        }
        if (effectiveCost == -1) {
            textObj.transform.position = transform.position + new Vector3(0.3f,0.2f,0);
            textMesh.text = gameObject.name + "\nCost: NA" ;//+ "(" + StepCost (GameState.instance.gameStep) + "," + effectiveTravelCost + ")";
        }
        else {
            textObj.transform.position = transform.position + new Vector3(0.3f, 0.2f,0);
            textMesh.text = gameObject.name + "\nCost: " + effectiveCost;// + "(" + StepCost (GameState.instance.gameStep) + "," + effectiveTravelCost + ")";

        }
        if (Input.GetMouseButtonDown (0)) {

            //current player buys city
        //			if(!isTentative) {
                Player p = GameState.instance.CurrentPlayer();
                if(effectiveCost == -1) {
                    print (gameObject.name + " is not available to purchase");
                } else if(p.cash >= effectiveCost) {
                    GameObject obj = (GameObject)Instantiate(
                        GameState.instance.powerPlantObject,
                        transform.position,
                        Quaternion.AngleAxis(Random.Range(0.0f,360.0f),Vector3.up));
                    obj.transform.position += objectOffsets[owners.Count];
                    obj.GetComponent<Renderer>().material.color = p.color;
                    obj.SetActive(true);

                    Player.CityPurchase purchase = new Player.CityPurchase();
                    purchase.purchaseCost = effectiveCost;
                    purchase.city = this;
                    purchase.isTentative = true;
                    purchase.obj = obj;

                    owners.Add(p);
                    p.cityPurchases.Add(purchase);
                    p.cities.Add(this);
                    p.cash -= effectiveCost;
                    print (p.gameObject.name + " bought " + gameObject.name + " for " + effectiveCost);

                    GameState.instance.RecomputeTravelCosts();
                } else {
                    print (p.gameObject.name + " does not have enough cash");
                }
        //			}
        }
    }