/// <summary> /// Extract a list of embedded resources to the specified path creating intermediate /// directories if they're required. /// </summary> /// <param name="assembly">Assembly to extract resources from.</param> /// <param name="resourceNameToTargetPaths">Each Key is the resource to extract and each /// Value is the path to extract to. If the resource name (Key) is null or empty, this /// method will attempt to extract a resource matching the filename component of the path. /// </param> /// <returns>true if successful, false otherwise.</returns> public static bool ExtractResources( Assembly assembly, IEnumerable <KeyValuePair <string, string> > resourceNameToTargetPaths, Logger logger) { bool allResourcesExtracted = true; var assemblyModificationTime = File.GetLastWriteTime(assembly.Location); foreach (var resourceNameToTargetPath in resourceNameToTargetPaths) { var targetPath = FileUtils.PosixPathSeparators( Path.GetFullPath(resourceNameToTargetPath.Value)); var resourceName = resourceNameToTargetPath.Key; if (String.IsNullOrEmpty(resourceName)) { resourceName = Path.GetFileName(FileUtils.NormalizePathSeparators(targetPath)); } ExtractedResource resourceToExtract; if (!extractedResourceByPath.TryGetValue(targetPath, out resourceToExtract)) { resourceToExtract = new ExtractedResource(assembly, assemblyModificationTime, resourceName, targetPath); } if (resourceToExtract.Extract(logger)) { extractedResourceByPath[targetPath] = resourceToExtract; } else { allResourcesExtracted = false; } } return(allResourcesExtracted); }
void renderExtractedResource(ExtractedResource r, int x, int y) { Sprite s = null; switch (r.type) { case Resource.Type.OIL: s = sd["oil_ext"]; break; case Resource.Type.ORE: s = sd["ore_ext"]; break; case Resource.Type.WOOD: s = sd["wood_ext"]; break; } tiles[x, y].GetComponent <SpriteRenderer>().sprite = s; }
public void collect(GameState gs, IntVec2 pos) { ExtractedResource r = (gs.getItem(pos) != null && gs.getItem(pos) is ExtractedResource) ? (gs.getItem(pos) as ExtractedResource) : null; if (r == null || r.type != type) { return; } int to_extract = Math.Min(r.amount, MAX_AMOUNT - r.amount); r.amount -= to_extract; amount += to_extract; if (r.amount == 0) { gs.tiles_[pos.x, pos.y] = null; } }
/// <summary> /// Extract a certain amount of metal /// </summary> /// <param name="amount"> /// Float with the amount of resource to be extracted. This value depends of the extractor level /// </param> public ExtractedResource ExtractResource(float amount) { ExtractedResource rv = new ExtractedResource(); rv.type = resourceType; rv.amount = 0.0f; rv.isDrained = resourceDrained; if(!associatedExtractor || resourceLevel <= 0.0f) { return rv; } // extracts an amount of resource resourceLevel -= amount; // Check if we actually have enough resources if(resourceLevel <= 0.0f) { // We tried to extract more than available amount += resourceLevel; // Adjust the amount extracted resourceLevel = 0.0f; // Clean the site resourceDrained = true; } rv.isDrained = resourceDrained; rv.amount = amount; return rv; }