示例#1
0
    public static WarehouseDistance FindClosestWarehouse(RectInt target)
    {
        WarehouseDistance warehousesInRange = null;

        // loop on poaitions of target
        foreach (Vector2Int minePosition in target.allPositionsWithin)
        {
            // Loop on all warehouses located in a game
            foreach (GameObject warehouse in Helpers.GetWarehouses())
            {
                RectInt warehouseDimensions = warehouse.GetComponent <Details>().dimensions;

                // loop on their positions
                foreach (var warehousePosition in warehouseDimensions.allPositionsWithin)
                {
                    float distanceToWarehouse = Vector3.Distance((Vector3Int)warehousePosition, (Vector3Int)minePosition);
                    // 10 tiles from target to target
                    if (distanceToWarehouse <= distanceFromTargetToTarget)
                    {
                        // if there is any saved closest warahouse and the current, on the loop is closer to target
                        // Then override varaibles
                        if ((warehousesInRange != null && warehousesInRange.distance > distanceToWarehouse) || warehousesInRange == null)
                        {
                            warehousesInRange           = new WarehouseDistance();
                            warehousesInRange.warehouse = warehouse;
                            warehousesInRange.distance  = distanceToWarehouse;
                        }
                    }
                }
            }
        }
        return(warehousesInRange);
    }
示例#2
0
    private void FinalizeProduction()
    {
        ReduceResources();
        ReduceCoins();

        WarehouseDistance warehouseDistance = Warehouses.FindClosestWarehouse(GetComponent <Details>().dimensions);

        print("Distance: " + warehouseDistance.distance);
    }