/// <summary> /// Checks if there is a road connected. /// Checks if there are houses reachable via that road that need processedItem and that are in distributionRange. /// If so, outputs processedItem to the road. /// </summary> /// <param name="handle"></param> private void tryDistribute(IVoxelHandle handle) { if (getAvailableResources(handle).Count == 0) { return; } var housesInRange = handle.GetRange(distributionRange).Where(e => e.Type is HouseType); foreach (var house in housesInRange) { var roadPiece = Road.IsConnected(handle, house); if (roadPiece == null) { continue; } var availableResources = getAvailableResources(handle); if (availableResources.Count == 0) { return; } var itemToTransport = availableResources[rnd.Next(availableResources.Count)]; if (house.CanAcceptItemType(handle, itemToTransport)) { Road.DeliverItem(roadPiece, handle, house, itemToTransport); } } }
private void trySupplyWorkers(IVoxelHandle handle) { if (getNbWorkersSupplied(handle) >= maxNbWorkers || !isSupplied(handle)) { return; } var voxelsInRange = handle.GetRange(workerSupplyRange); foreach (var vh in voxelsInRange) { if (vh.CanAddWorker()) { vh.Data.WorkerCount++; handle.Data.DataValue++; return; } } }
private void removeSuppliedWorkers(IVoxelHandle handle) { var nbWorkersSupplied = getNbWorkersSupplied(handle); var voxelsInRange = handle.GetRange(workerSupplyRange); foreach (var vh in voxelsInRange) { if (nbWorkersSupplied == 0) { return; } var nbw = vh.Data.WorkerCount; if (nbw <= 0) { continue; } if (nbw > nbWorkersSupplied) { vh.Data.WorkerCount -= nbWorkersSupplied; nbWorkersSupplied = 0; } else { vh.Data.WorkerCount = 0; nbWorkersSupplied -= nbw; } } if (nbWorkersSupplied == 0) { return; } throw new Exception("Worker leak!!"); }
private IEnumerable <IVoxelHandle> getWareHousesInRange(IVoxelHandle handle) { return(handle.GetRange(collectRange).Where(v => v.Type is WarehouseType)); }
private IEnumerable <IVoxelHandle> getHarvestableVoxels(IVoxelHandle handle) { return(handle.GetRange(harvestRange).Where(e => e.Type is ForestType)); }