Exemplo n.º 1
0
    private void PlaceObject(CollectableResource prefab, int i, int j)
    {
        float height = World[i, j].Height;
        CollectableResource resource = Instantiate(prefab, new Vector3(i - halfSize, height, j - halfSize), Quaternion.identity);

        resource.Initialize(World[i, j], World);
    }
Exemplo n.º 2
0
    private void ScatterObject(CollectableResource prefab, float percent)
    {
        float seed = Random.Range(0f, 10000f);

        for (int i = 0; i < worldSize; ++i)
        {
            for (int j = 0; j < worldSize; ++j)
            {
                if (!World[i, j].IsBuildable)
                {
                    continue;
                }
                if (World[i, j].Height > 1.2f) //only allow stuff a little up the mountain
                {
                    continue;
                }
                float noise = Mathf.PerlinNoise(i / 3f + seed, j / 3f + seed);

                if (noise < percent)
                {
                    PlaceObject(prefab, i, j);
                }
            }
        }
    }
Exemplo n.º 3
0
        protected CollectableResource GetShortestDistance(Vector3 position, List <CollectableResource> objects, int radius)
        {
            CollectableResource tree = objects[0];
            float dist = radius;

            for (int i = 0; i < objects.Count; i++)
            {
                float tempDist = Vector3.Distance(position, objects[i].transform.position);
                if (tempDist < dist)
                {
                    dist = tempDist;
                    tree = objects[i];
                }
            }

            return(tree);
        }
Exemplo n.º 4
0
 public override void WorkerAssigned(PersonAI aI)
 {
     base.WorkerAssigned(aI);
     aI.transform.position = spawnSpot.position;
     aI.UpdateCurrentTile();
     stoneNearby = CheckNearbyResources(this.transform.position);
     if (stoneNearby.Count == 0)
     {
         SetBuildingEmpty(stones);
         this.maxWorkers = 0;
         aI.Idle();
         return;
     }
     nearestStone        = GetShortestDistance(this.transform.position, stoneNearby, checkStoneRadius);
     nearestTile         = CheckNearbyTiles(nearestStone.placedTile, world);
     nearestStone.Worker = aI;
     aI.MoveToPosition(nearestTile);
 }
Exemplo n.º 5
0
 public override void DoWork(PersonAI aI)
 {
     if (nearestStone == null)
     {
         aI.ReachedDestination = false;
         stoneNearby           = CheckNearbyResources(this.transform.position);
         if (stoneNearby.Count == 0)
         {
             SetBuildingEmpty(stones);
             this.maxWorkers = 0;
             aI.Idle();
             return;
         }
         nearestStone = GetShortestDistance(this.transform.position, stoneNearby, checkStoneRadius);
         nearestTile  = CheckNearbyTiles(nearestStone.placedTile, world);
         aI.MoveToPosition(nearestTile);
     }
     if (aI.ReachedDestination)
     {
         if (nearestStone == null || nearestStone.Worker != aI)
         {
             aI.ReachedDestination = false;
             stoneNearby           = CheckNearbyResources(this.transform.position);
             if (stoneNearby.Count == 0)
             {
                 SetBuildingEmpty(stones);
                 this.maxWorkers = 0;
                 aI.Idle();
                 return;
             }
             nearestStone = GetShortestDistance(this.transform.position, stoneNearby, checkStoneRadius);
             nearestTile  = CheckNearbyTiles(nearestStone.placedTile, world);
             aI.MoveToPosition(nearestTile);
         }
         GameplayController.instance.CurrentResources.Stone += stonePerWork;
         if (nearestStone.Anim != null)
         {
             nearestStone.Anim.Play();
         }
         nearestStone.Amount -= stonePerWork;
     }
 }
Exemplo n.º 6
0
 public void RemoveResource(CollectableResource resource)
 {
     collectableResources.Remove(resource);
 }
Exemplo n.º 7
0
 public void AddResource(CollectableResource resource)
 {
     collectableResources.Add(resource);
 }