Exemple #1
0
    public void SetTile(int x, int y, GameObject prefab)
    {
        int i = WorldGridIndex(x, y);

        if (tiles[i] != null)
        {
            BuildingPrice price = tiles[i].GetComponent <BuildingPrice>();
            if (price.hidesTerrain)
            {
                foreach (Renderer gfx in terrain[i].GetComponentsInChildren <Renderer>())
                {
                    gfx.enabled = true;
                }
            }
            Destroy(tiles[i]);
        }

        if (prefab != null)
        {
            GameObject ngo = Instantiate(prefab);
            foreach (SpecialStates states in ngo.GetComponentsInChildren <SpecialStates>())
            {
                if (states.hideInWorld)
                {
                    states.gameObject.SetActive(false);
                }
            }
            BuildingPrice price = ngo.GetComponent <BuildingPrice>();
            if (price != null && price.hidesTerrain)
            {
                foreach (Renderer gfx in terrain[i].GetComponentsInChildren <Renderer>())
                {
                    gfx.enabled = false;
                }
            }
            ngo.transform.parent        = transform;
            ngo.transform.localPosition = Vector3.right * x * tileSpacing + Vector3.back * y * tileSpacing + (HeightOffset(x, y) + (price != null ? price.heightOffset : 0)) * Vector3.up;
            ngo.transform.localRotation = Quaternion.Euler(0, 90 * Random.Range(0, 4), 0);
            foreach (Transform trans in ngo.GetComponentsInChildren <Transform>(true))
            {
                trans.gameObject.layer = 0;
            }

            GameTile tile = ngo.GetComponent <GameTile>();
            if (tile != null)
            {
                tile.enabled  = true;
                tile.x        = x;
                tile.y        = y;
                price.enabled = false;
                foreach (BuildingPrice menuItem in BuildMenu.instance.GetComponentsInChildren <BuildingPrice>(true))
                {
                    menuItem.BuildingComplete(price.type);
                }
                tiles[i] = ngo;
            }
        }
    }
Exemple #2
0
    public bool GetPassable(int x, int y)
    {
        GameObject tile = GetTile(x, y);

        if (tile != null)
        {
            BuildingPrice price = tile.GetComponent <BuildingPrice>();
            return(price.type == "pit" || price.type == "pit_full" || price.type == "construct" || price.type == "crop" || price.type == "baby_crop" || price.type == "baby_tree");
        }
        return(true);
    }
Exemple #3
0
    void Upkeep()
    {
        BuildingPrice price = GetComponent <BuildingPrice>();

        if (working || !ContainsPerson(price.workCosts))
        {
            foreach (SpecialStates child in GetComponentsInChildren <SpecialStates>(true))
            {
                if (child.activeOnWork)
                {
                    child.gameObject.SetActive(false);
                }
            }

            working = false;
            bool okay = true;
            for (int i = 0; i < price.workCosts.Length; ++i)
            {
                BuildingPrice.Cost cost = price.workCosts[i];
                if (cost.type == Resources.Type.TIME)
                {
                    okay = false;
                    --cost.amount;
                    price.workCosts[i] = cost;
                    // FIXME (hitch) this is a horrible hack to update time display, IRL lookup what field we are
                    // updating!
                    GetComponentInChildren <CostDisplay>(true).costs[0].text.text = cost.amount.ToString();
                    if (construction != null)
                    {
                        construction.transform.localPosition += construction.deltaPos;
                        construction.transform.localScale    += construction.deltaScale;
                    }
                }
                if (cost.amount <= 0)
                {
                    okay = true;
                }
            }
            if (okay)
            {
                foreach (BuildingPrice.Cost entry in workGain)
                {
                    ScoreTracker.instance.AddIncome(entry.type, entry.amount);
                }
                Resources.instance.AddResources(workGain);
                if (changeOnWork)
                {
                    TileGrid.instance.SetTile(x, y, workState);
                }
            }
        }
        isFirstTurn = false;
    }
 void OnMouseUpAsButton()
 {
     if (enabled && requirement == "" && !ScoreTracker.instance.isSummaryShowing)
     {
         if (selected != null)
         {
             HighlightEffect.RemoveHighlight(selected.gameObject);
         }
         HighlightEffect.AddHighlight(gameObject, selectionColor, true);
         selected             = this;
         BuildMenu.activeTool = this;
     }
 }
Exemple #5
0
    void OnEnable()
    {
        audio       = GetComponent <AudioSource>();
        isFirstTurn = true;
        if (firstTurnWork && TileGrid.instance.worldGenerated)
        {
            audio.PlayOneShot(workerPlaceSounds[Random.Range(0, workerPlaceSounds.Length)]);
            working = true;
            foreach (SpecialStates child in GetComponentsInChildren <SpecialStates>(true))
            {
                if (child.activeOnWork)
                {
                    child.gameObject.SetActive(true);
                }
            }
        }

        BuildingPrice price   = GetComponent <BuildingPrice>();
        CostDisplay   display = Instantiate(Resources.instance.workCostDisplay).GetComponent <CostDisplay>();

        display.transform.SetParent(transform);
        display.transform.localPosition = price.heightOffset * -Vector3.up;

        int q = 0;

        foreach (BuildingPrice.Cost cost in price.workCosts)
        {
            display.costs[q].sprite.gameObject.SetActive(true);
            display.costs[q].sprite.sprite = Resources.instance.GetIcon(cost.type);
            display.costs[q].text.text     = cost.amount.ToString();
            ++q;
        }

        if (!price.alwaysShowCost)
        {
            display.gameObject.SetActive(false);
        }

        foreach (BuildingPrice.Cost max in maxIncreses)
        {
            Resources.instance.SetValue(max.type, Resources.instance.GetValue(max.type, true) + max.amount, true);
        }
    }
Exemple #6
0
    private int AddToMenu(int i, MenuEntry go)
    {
        Transform menuItem = Instantiate(go.prefab).transform;

        menuItem.gameObject.GetComponent <BuildingPrice>().enabled = true;
        menuItem.parent        = transform;
        menuItem.localPosition = i * (1.57f + ((i % 2 == 1) ? 0.1f : 0)) * Vector3.down + ((i % 2 == 1) ? 1.5f : 0) * Vector3.right + go.yOffset * Vector3.up;
        menuItem.rotation      = itemRotation;
        menuItem.localScale    = Vector3.one;
        foreach (Transform trans in menuItem.gameObject.GetComponentsInChildren <Transform>(true))
        {
            trans.gameObject.layer = gameObject.layer;
        }
        foreach (SpecialStates states in menuItem.GetComponentsInChildren <SpecialStates>())
        {
            if (states.hideInMenu)
            {
                Destroy(states.gameObject);
            }
        }

        BuildingPrice price = menuItem.GetComponent <BuildingPrice>();

        if (price != null)
        {
            price.prefab = go.prefab;
            BuildingPrice.Cost[] costs    = price.buildCosts;
            Transform            costItem = null;
            if (costs.Length > 0)
            {
                costItem                  = Instantiate(costTip).transform;
                costItem.parent           = menuItem;
                costItem.localPosition    = Vector3.zero;
                costItem.localRotation    = Quaternion.identity;
                costItem.localScale       = Vector3.one;
                costItem.gameObject.layer = gameObject.layer;
                CostDisplay display = costItem.GetComponent <CostDisplay>();
                int         q       = 0;
                foreach (BuildingPrice.Cost cost in costs)
                {
                    display.costs[q].sprite.gameObject.SetActive(true);
                    display.costs[q].sprite.sprite = resourcePool.GetIcon(cost.type);
                    display.costs[q].text.text     = cost.amount.ToString();
                    ++q;
                }
            }
            if (price.requirement != "")
            {
                if (costItem != null)
                {
                    costItem.gameObject.SetActive(false);
                }
                foreach (Renderer render in menuItem.GetComponentsInChildren <Renderer>())
                {
                    render.enabled = false;
                }
                HighlightEffect.AddHighlight(menuItem.gameObject, new Color(1, 1, 1), true);
            }
        }

        return(i + 1);
    }
    void Update()
    {
        GameObject hovering = null;
        RaycastHit hit;
        bool       buildStage = (RoundManager.instance.stage == RoundManager.RoundStage.DAWN || RoundManager.instance.stage == RoundManager.RoundStage.DUSK);

        if (!ScoreTracker.instance.isSummaryShowing && buildStage && menuCamera.ScreenToWorldPoint(Input.mousePosition).x < menuLimiter.position.x && Physics.Raycast(camera.ScreenPointToRay(Input.mousePosition), out hit, Mathf.Infinity, terrainLayer))
        {
            hovering = hit.collider.gameObject;
        }

        if (currentHover != hovering)
        {
            // Remove old:
            if (currentHover != null)
            {
                if (currentTile != null)
                {
                    HighlightEffect.RemoveHighlight(currentTile);

                    BuildingPrice price   = currentTile.GetComponent <BuildingPrice>();
                    CostDisplay   display = currentTile.GetComponentInChildren <CostDisplay>(true);
                    if (price != null && display != null && !price.alwaysShowCost)
                    {
                        display.gameObject.SetActive(false);
                    }
                }
                else
                {
                    HighlightEffect.RemoveHighlight(currentHover);
                }
            }

            // Add new:
            currentPoint = null;
            currentHover = null;
            currentTile  = null;
            if (hovering != null)
            {
                currentPoint = world.GetTerrainPos(hovering);
                if (currentPoint != null)
                {
                    GameObject tile = world.GetTile(currentPoint.x, currentPoint.y);
                    if (tile != null)
                    {
                        HighlightEffect.AddHighlight(tile, blockHoverColor);
                        currentTile = tile;

                        BuildingPrice price   = currentTile.GetComponent <BuildingPrice>();
                        CostDisplay   display = currentTile.GetComponentInChildren <CostDisplay>(true);
                        if (price != null && display != null && !price.alwaysShowCost)
                        {
                            display.gameObject.SetActive(true);
                        }
                    }
                    else
                    {
                        HighlightEffect.AddHighlight(hovering, blockHoverColor);
                    }
                    currentHover = hovering;
                }
            }
        }

        if (!ScoreTracker.instance.isSummaryShowing && buildStage && Input.GetButtonDown("Click") && currentPoint != null)
        {
            if (currentTile == null)
            {
                if (BuildMenu.activeTool != null && BuildMenu.activeTool.isPlaceable && Resources.instance.TryBuy(BuildMenu.activeTool.buildCosts))
                {
                    if (BuildMenu.activeTool.construction != null)
                    {
                        world.SetTile(currentPoint.x, currentPoint.y, BuildMenu.activeTool.construction);
                    }
                    else
                    {
                        world.SetTile(currentPoint.x, currentPoint.y, BuildingPrice.selected.prefab);
                    }
                    HighlightEffect.RemoveHighlight(currentHover);
                    currentHover = null;
                    world.GetTile(currentPoint.x, currentPoint.y).GetComponent <GameTile>().audio.PlayOneShot(buildSound);
                    SoundEffects.PlaySound(buildSound);
                    foreach (BuildingPrice.Cost cost in BuildMenu.activeTool.buildCosts)
                    {
                        if (cost.type != Resources.Type.PERSON && cost.type != Resources.Type.TIME)
                        {
                            ScoreTracker.instance.AddExpenses(cost.type, cost.amount);
                        }
                    }
                }
            }
            else
            {
                currentTile.GetComponent <GameTile>().ClickTile(world, currentPoint.x, currentPoint.y);
            }
        }
    }
Exemple #8
0
 private void Start()
 {
     currentPrice = BuildingPrice.getPrice(typeObject);
     _SetPrice(currentPrice);
 }
Exemple #9
0
    private bool InteractWith(int x, int y, int pass)
    {
        GameObject go = TileGrid.instance.GetTile(x, y);

        if (go != null)
        {
            BuildingPrice price = go.GetComponent <BuildingPrice>();
            if (price.type == "pit" && pass == 0)
            {
                audio.PlayOneShot(fallSound, fall_volume);
                TimeOfDayPopper.overrideMaterial = GetComponentInChildren <MeshRenderer>().sharedMaterial;
                TileGrid.instance.SetTile(x, y, animalPit);
                return(true);
            }

            GameTile tile = go.GetComponent <GameTile>();
            if (moveType == MoveStyle.STALK)
            {
                if ((price.type == "baby_tree" || price.type == "baby_crop" || price.type == "crop") && !tile.working && pass == 1)
                {
                    audio.PlayOneShot(attackSound, attack_volume);
                    ScoreTracker.instance.LostTile((price.type == "baby_tree") ? "Sapling" : "Crop");
                    Destroy(go);
                    return(true);
                }
            }
            else if (moveType == MoveStyle.WADDLE)
            {
                if (price.type == "ranch" && pass == 1)
                {
                    bool okay = false;
                    foreach (AnimalsInWorld aiw in go.GetComponentsInChildren <AnimalsInWorld>(true))
                    {
                        if (aiw.showing)
                        {
                            aiw.KillAnimal();
                            okay = true;
                        }
                    }
                    if (okay)
                    {
                        return(true);
                    }
                }
                if (tile.working && price.type != "fence" && pass == 2)
                {
                    audio.PlayOneShot(attackSound, attack_volume);
                    MesopotamianRandomizer[] people = go.GetComponentsInChildren <MesopotamianRandomizer>();
                    // This is a hack to work (we don't know how many workers are here, so we just count the worker graphics!)
                    foreach (MesopotamianRandomizer person in people)
                    {
                        person.doNotReleaseName = true;
                        ScoreTracker.instance.LostVillager(1, new string[] { person.mesopoNAMEian });
                    }
                    Resources.instance.personLive -= people.Length;
                    tile.working = false;
                    foreach (SpecialStates child in go.GetComponentsInChildren <SpecialStates>(true))
                    {
                        if (child.activeOnWork)
                        {
                            child.gameObject.SetActive(false);
                        }
                    }
                    return(true);
                }
            }
        }
        return(false);
    }