Пример #1
0
    public void colorResource()
    {
        for (int i = 0; i < grid.sizeX; i++)
        {
            for (int j = 0; j < grid.sizeY; j++)
            {
                if (grid.getTileAt(i, j) != null)
                {
                    Color color = Color.Lerp(minColor, maxColor, (grid.getTileAt(i, j).currentResource / profile.getComponent <MaxCarry>().maxcarry));
                    setTileColor(color, new Vector3Int(i, j, 0), gameObject.GetComponent <Tilemap>());

                    // Debug.Log(g.getTileAt(i, j).currentResource / g.maxCarry);
                }
            }
        }
    }
Пример #2
0
    IEnumerator colorResourceGrid(ResourceGrid g)
    {
        float allResource = 0;
        float time        = Time.time;

        // grid.updateResource();
        // grid.finishUpdateResource();

        if (timer.month == 1 && timer.year > 1)
        {
            // float resource = g.getTileAt(i, j).currentResource;

            dm.updateYearCatch();
            dm.updateYearProfit();

            foreach (KeyValuePair <Vector3Int, ResourceTile> tile in grid.resourceTiles)
            {
                tile.Value.spawnResource();
            }

            dm.updateTotalResource(grid);
            dm.updateAddedResource(grid);

            dm.writeYearToFile();

            float quota    = dm.calculateQuota(timer.year);
            float capacity = dm.calculateTotalCapacity();

            float quotaPerCapacityUnit = quota / capacity;
            Debug.Log("Quota per capacity unit : " + quotaPerCapacityUnit);
            Debug.Log("respawned resource");

            if (timer.year >= 5)
            {
                assignQuota(quotaPerCapacityUnit);
            }
        }

        for (int i = 0; i < g.sizeX; i++)
        {
            for (int j = 0; j < g.sizeY; j++)
            {
                if (g.getTileAt(i, j) != null)
                {
                    Color color = Color.Lerp(minColor, maxColor, (g.getTileAt(i, j).currentResource / sim.getMaxCarry()));
                    setTileColor(color, new Vector3Int(i, j, 0), resourceMap);

                    allResource += g.getTileAt(i, j).currentResource;

                    // Debug.Log(g.getTileAt(i, j).currentResource / g.maxCarry);
                }
            }
        }


        //Debug.Log("Resource recolored " + allResource);
        yield return(null);

        // Debug.Log("Time remaining: " + (sim.weektime - (Time.time - time)));
        yield return(new WaitForSeconds(sim.weektime - (Time.time - time)));

        StartCoroutine(colorResourceGrid(grid));
    }
Пример #3
0
    private void onMouseClickEvent(Vector3 point)
    {
        Vector3Int cellIndex = resourceMap.WorldToCell(point);


        Destroy(existingHighlight);
        existingHighlight = null;

        foreach (GameObject g in neighborHighlights)
        {
            Destroy(g);
        }
        neighborHighlights.Clear();

        if (grid.getTileAt(cellIndex.x, cellIndex.y) != null)
        {
            GameObject tile = Instantiate(highlight, resourceMap.GetCellCenterLocal(cellIndex), Quaternion.identity);
            if (existingHighlight == null)
            {
                existingHighlight = tile;
            }

            //add neighbor highlights

            ResourceTile target = grid.getTileAt(cellIndex.x, cellIndex.y);


            if (target.neighbors.N != null)
            {
                GameObject ntile = Instantiate(neighborHighlight, resourceMap.GetCellCenterLocal(new Vector3Int(cellIndex.x, cellIndex.y + 1, 0)), Quaternion.identity);
                neighborHighlights.Add(ntile);
            }

            if (target.neighbors.NE != null)
            {
                GameObject ntile = Instantiate(neighborHighlight, resourceMap.GetCellCenterLocal(new Vector3Int(cellIndex.x + 1, cellIndex.y + 1, 0)), Quaternion.identity);
                neighborHighlights.Add(ntile);
            }

            if (target.neighbors.E != null)
            {
                GameObject ntile = Instantiate(neighborHighlight, resourceMap.GetCellCenterLocal(new Vector3Int(cellIndex.x + 1, cellIndex.y, 0)), Quaternion.identity);
                neighborHighlights.Add(ntile);
            }

            if (target.neighbors.SE != null)
            {
                GameObject ntile = Instantiate(neighborHighlight, resourceMap.GetCellCenterLocal(new Vector3Int(cellIndex.x + 1, cellIndex.y - 1, 0)), Quaternion.identity);
                neighborHighlights.Add(ntile);
            }

            if (target.neighbors.S != null)
            {
                GameObject ntile = Instantiate(neighborHighlight, resourceMap.GetCellCenterLocal(new Vector3Int(cellIndex.x, cellIndex.y - 1, 0)), Quaternion.identity);
                neighborHighlights.Add(ntile);
            }

            if (target.neighbors.SW != null)
            {
                GameObject ntile = Instantiate(neighborHighlight, resourceMap.GetCellCenterLocal(new Vector3Int(cellIndex.x - 1, cellIndex.y - 1, 0)), Quaternion.identity);
                neighborHighlights.Add(ntile);
            }

            if (target.neighbors.W != null)
            {
                GameObject ntile = Instantiate(neighborHighlight, resourceMap.GetCellCenterLocal(new Vector3Int(cellIndex.x - 1, cellIndex.y, 0)), Quaternion.identity);
                neighborHighlights.Add(ntile);
            }

            if (target.neighbors.NW != null)
            {
                GameObject ntile = Instantiate(neighborHighlight, resourceMap.GetCellCenterLocal(new Vector3Int(cellIndex.x - 1, cellIndex.y + 1, 0)), Quaternion.identity);
                neighborHighlights.Add(ntile);
            }

            float resource = target.currentResource;
            resourceTileText.GetComponent <Text>().text = "Resource in tile: " + target.currentResource;// resource;

            neighborsText.GetComponent <Text>().text = "Tile neighbors: " + neighborHighlights.Count;

            boatsAtTileText.GetComponent <Text>().text = "Boats: " + target.boatsHere.Count;
        }



        //Debug.Log("Position: " + point + " [" + cellIndex + "]");
        //setTileColor(Random.ColorHSV(), cellIndex, resourceMap);
    }
Пример #4
0
    IEnumerator toBestNeighborDest(Vector3Int tileIndex)
    {
        float             totalTime = sim.weektime;
        List <Vector3Int> neighbors = getNeighbors(tileIndex);
        //float mostResource = 0;
        ResourceTile mostTile = grid.getTileAt(tileIndex.x, tileIndex.y);

        //stagger
        int framerate = (int)(1f / Time.unscaledDeltaTime);
        int stagger   = 0;

        if (timer.month == 1)
        {
            stagger = framerate / 2;

            for (int i = 0; i < stagger; i++)
            {
                totalTime -= Time.deltaTime;
                yield return(null);
            }

            yearCatch  = 0;
            yearProfit = 0;
        }

        else
        {
            stagger = Random.Range(0, (int)(framerate - framerate * .1f));

            for (int i = 0; i < stagger; i++)
            {
                totalTime -= Time.deltaTime;
                yield return(null);
            }
        }

        totalTime -= Time.deltaTime;

        //bit of an exploration chance, the less profit the more likely the exploration;
        float exploration          = Random.Range(0f, 1f);
        float explorationThreshold = currentGrossProfit / (fishPrice * capacity * efficiency);

        if (exploration > explorationThreshold)
        {
            mostTile = bestNeighbor(grid.resourceTiles.ElementAt(Random.Range(0, grid.resourceTiles.Count)).Value);
        }

        else
        {
            mostTile = bestNeighbor(grid.getTileAt(tileIndex));
        }

        //Debug.Log("Most resource: " + mostResource);
        //Debug.Log("Most tile: [" + mostTile.tileIndex().x + ", " + mostTile.tileIndex().y + "]");
        moveBoat(mostTile.tileIndex());

        mostTile.isHere(gameObject);
        //fish(mostTile.tileIndex());
        mostTile.fishingHere(gameObject);
        yield return(null);

        mostTile.getFish(gameObject);

        yearCatch += currentCatch;

        currentGrossProfit = currentCatch * fishPrice;
        currentProfit      = currentCatch * fishPrice - costs;
        yearProfit        += currentProfit;
        totalProfit       += currentProfit;

        yield return(new WaitForSeconds(totalTime));

        mostTile.leftHere(gameObject);

        //yearly reckoning

        if (timer.month == 12)
        {
            if (yearProfit < 150)
            {
                die();
            }
        }

        keepFishing(mostTile.tileIndex());
    }