Пример #1
0
    public void GenChunk(Vector2 offset, MapController _mapController)
    {
        resourceSeed       = Random.Range(-100000, 100000);
        genResourcesSeed   = Random.Range(-100000, 100000);
        resourcesYieldSeed = Random.Range(-100000, 100000);
        noiseOffset        = offset;
        mapController      = _mapController;
        parent             = this.transform;
        seed              = mapController.seed;
        width             = mapController.chunkSize;
        height            = mapController.chunkSize;
        scale             = mapController.noiseScale;
        persistance       = mapController.persistance;
        lacunarity        = mapController.lacunarity;
        octaves           = mapController.octaves;
        float[,] noiseMap = Noise.GenerateNoiseMap(width, height, scale, octaves, persistance, lacunarity, seed, offset);
        float[,] underGroundResourcesNoiseMap      = Noise.GenerateNoiseMap(width, height, scale, octaves, persistance, lacunarity, resourceSeed, offset);
        float[,] underGroundResourcesYieldNoiseMap = Noise.GenerateNoiseMap(width, height, 7f, octaves, persistance, lacunarity, resourcesYieldSeed, offset);
        float[,] genResourcesNoiseMap = Noise.GenerateNoiseMap(width, height, 10f, octaves, persistance, lacunarity, genResourcesSeed, offset);
        tiles     = new Tile[width, height];
        resources = new Resource[width, height];
        for (int x = 0; x < width; x++)
        {
            for (int y = 0; y < height; y++)
            {
                tiles[x, y] = new Tile(this, x, y, Util.getTileFromPerlin(noiseMap[x, y]));
            }
        }

        for (int x = 0; x < width; x++)
        {
            for (int y = 0; y < height; y++)
            {
                GameObject objectPrefab = Util.getGameObjectFromFile(GetTileAt(x, y).type);
                GameObject tile_GO      = GameObject.Instantiate(objectPrefab, parent, true);
                tile_GO.name = "Tile_" + x + "_" + y;
                tile_GO.transform.position = new Vector3(x, Util.getYHeight(tiles[x, y].type), y);
                bool boolGenResource = Util.checkGenResource(x, y, genResourcesNoiseMap, tiles[x, y].type);
                if (boolGenResource == true)
                {
                    Resource.ResourceType type        = Util.getUnderGroundResource(x, y, underGroundResourcesNoiseMap);
                    GameObject            prefab      = Util.getGameObjectFromFile(type);
                    GameObject            resource_GO = GameObject.Instantiate(prefab, parent, true);
                    resource_GO.name = "Resource: " + type.ToString();
                    resource_GO.transform.position = new Vector3(x, Util.getYHeight(tiles[x, y].type), y);
                    resources[x, y] = new Resource(x, y, prefab, tiles[x, y], type, underGroundResourcesYieldNoiseMap[x, y]);
                }
                GetTileAt(x, y).Prefab = tile_GO;
            }
        }

        //Debug.Log("Chunk Created, Width: " + width + ", Height: " + height + ", Seed: " + seed);
    }
Пример #2
0
    public void AddResource(Resource.ResourceType resourceType, int num)
    {
        switch (resourceType)
        {
        case Resource.ResourceType.Wood:
            WoodAmount += num;
            break;

        case Resource.ResourceType.Stone:
            StoneAmount += num;
            break;

        case Resource.ResourceType.Gold:
            GoldAmount += num;
            break;

        default:
            Debug.Log("Added strange type: " + resourceType.ToString());
            break;
        }
        UIManager.instance.UpdateResourceCount();
    }
Пример #3
0
    /// <summary>
    /// used specifically for dropping off resources at the correcct building
    /// </summary>
    /// <returns>The building resource drop.</returns>
    /// <param name="character">Character requesting path.</param>
    /// <param name="buildingType">Building type.</param>
    /// <param name="resourceType">Resource type.</param>
    public Building FindBuildingResourceDrop(AI_Character character, Building.Structure buildingType, Resource.ResourceType resourceType)
    {
        int         num  = -1;
        float       dist = 9999;
        NavMeshPath path = new NavMeshPath();

        for (int i = 0; i < buildingsList.Count; i++)
        {
            //check for right structure
            if (buildingsList [i].structure != buildingType)
            {
                continue;
            }


            //check for right drop type
            if (buildingsList [i].dropType != Building.ResourceDropType.All && buildingsList [i].dropType.ToString() != resourceType.ToString())
            {
                continue;
            }


            if (!Distance.GetPath(character.transform.position, buildingsList [i].buildingTarget.transform.position, NavMesh.AllAreas, path))
            {
                continue;
            }
            else
            {
                if (Distance.GetPathLength(path) < dist)
                {
                    dist = Distance.GetPathLength(path);
                    num  = i;
                }
            }
        }

        if (num == -1)
        {
            return(null);
        }
        return(buildingsList [num]);
    }