public static ResourceTemplate RenderResourceType(ResourceTypeInfo info, string[] exts, Palette p) { var image = info.SpriteNames[0]; using (var s = FileSystem.OpenWithExts(image, exts)) { var shp = new ShpReader(s); var frame = shp[shp.ImageCount - 1]; var bitmap = new Bitmap(shp.Width, shp.Height, PixelFormat.Format8bppIndexed); bitmap.Palette = p.AsSystemPalette(); var data = bitmap.LockBits(bitmap.Bounds(), ImageLockMode.WriteOnly, PixelFormat.Format8bppIndexed); unsafe { byte *q = (byte *)data.Scan0.ToPointer(); var stride = data.Stride; for (var i = 0; i < shp.Width; i++) { for (var j = 0; j < shp.Height; j++) { q[j * stride + i] = frame.Image[i + shp.Width * j]; } } } bitmap.UnlockBits(data); return(new ResourceTemplate { Bitmap = bitmap, Info = info, Value = shp.ImageCount - 1 }); } }
public static ResourceTemplate RenderResourceType(ResourceTypeInfo info, string[] exts, Palette p) { var image = info.EditorSprite; using (var s = FileSystem.OpenWithExts(image, exts)) { // TODO: Do this properly var shp = new ShpReader(s) as ISpriteSource; var frame = shp.Frames.Last(); var bitmap = new Bitmap(frame.Size.Width, frame.Size.Height, PixelFormat.Format8bppIndexed); bitmap.Palette = p.AsSystemPalette(); var data = bitmap.LockBits(bitmap.Bounds(), ImageLockMode.WriteOnly, PixelFormat.Format8bppIndexed); unsafe { byte *q = (byte *)data.Scan0.ToPointer(); var stride = data.Stride; for (var i = 0; i < frame.Size.Width; i++) { for (var j = 0; j < frame.Size.Height; j++) { q[j * stride + i] = frame.Data[i + frame.Size.Width * j]; } } } bitmap.UnlockBits(data); return(new ResourceTemplate { Bitmap = bitmap, Info = info, Value = shp.Frames.Count() - 1 }); } }
public static ResourceTemplate RenderResourceType(ResourceTypeInfo info, TileSet tileset, IPalette p) { var image = ResolveFilename(info.EditorSprite, tileset); using (var s = GlobalFileSystem.Open(image)) { // TODO: Do this properly var shp = new ShpTDSprite(s); var frame = shp.Frames.Last(); var bitmap = new Bitmap(frame.Size.Width, frame.Size.Height, PixelFormat.Format8bppIndexed); bitmap.Palette = p.AsSystemPalette(); var data = bitmap.LockBits(bitmap.Bounds(), ImageLockMode.WriteOnly, PixelFormat.Format8bppIndexed); unsafe { var q = (byte *)data.Scan0.ToPointer(); var stride = data.Stride; for (var i = 0; i < frame.Size.Width; i++) { for (var j = 0; j < frame.Size.Height; j++) { q[j * stride + i] = frame.Data[i + frame.Size.Width * j]; } } } bitmap.UnlockBits(data); return(new ResourceTemplate { Bitmap = bitmap, Info = info, Value = shp.Frames.Count - 1 }); } }
//called each time a faction resource amount is updated if the mission type is set to "collectResource" private void OnFactionResourceUpdated(ResourceTypeInfo resourceType, int factionID, int amount) { if (factionID == GameManager.PlayerFactionID && amount > 0 && resourceType.GetName() == targetResource.GetName()) //only if the amount is > 0 and the source faction is the player's faction { OnProgress(amount); } }
public void OnEnable() { SmallButtonLayout = new GUILayoutOption[] { GUILayout.Width(20.0f), GUILayout.Height(20.0f) }; Target = (ResourceTypeInfo)target; SOTarget = new SerializedObject(Target); }
public EditorResourceBrush(EditorViewportControllerWidget editorWidget, ResourceTypeInfo resource, WorldRenderer wr) { this.editorWidget = editorWidget; ResourceType = resource; worldRenderer = wr; world = wr.World; editorActionManager = world.WorldActor.Trait <EditorActionManager>(); editorCursor = world.WorldActor.Trait <EditorCursorLayer>(); action = new AddResourcesEditorAction(world.Map, ResourceType); cursorToken = editorCursor.SetResource(wr, resource); }
private void InitializeTypes() { var flagInfo = new ResourceTypeInfo("flag", TileInfo.FlagNear, TileInfo.FlagFar); var fuelDepotInfo = new ResourceTypeInfo("fuel", TileInfo.FuelDepotNear, TileInfo.FuelDepotFar); smallFlag = new ResourceType(flagInfo, Directory.GetFiles("Templates/SmallFlag").Select(ObjectTemplate.ReadFromFile).ToArray()); largeFlag = new ResourceType(flagInfo, Directory.GetFiles("Templates/LargeFlag").Select(ObjectTemplate.ReadFromFile).ToArray()); smallFuelDepot = new ResourceType(fuelDepotInfo, Directory.GetFiles("Templates/SmallFuelDepot").Select(ObjectTemplate.ReadFromFile).ToArray()); largeFuelDepot = new ResourceType(fuelDepotInfo, Directory.GetFiles("Templates/LargeFuelDepot").Select(ObjectTemplate.ReadFromFile).ToArray()); villages = Directory.GetFiles("Templates/Village").Select(ObjectTemplate.ReadFromFile).Select(CreateVillageTemplate).ToList(); }
/// <summary> /// Attempts to find an idle resource instance of a certain type. /// </summary> /// <param name="resourceType">The ResourceTypeInfo instance that represents the type of resource to search for?</param> /// <returns>Resource instance that matches the requested type if found, otherwise null.</returns> public Resource GetIdleResourceOfType(ResourceTypeInfo resourceType) { //go through the idle resources foreach (Resource ir in idleResources) { if (ir.GetResourceType() == resourceType) //if the resource type matches. { return(ir); } } return(null); }
/// <summary> /// Check whether a resource type (defined by its ResourceTypeInfo instance) can be collected by the resource collector. /// </summary> /// <param name="resourceType">ResourceTypeInfo instance that defines the resource type.</param> /// <param name="useDic">Set to true only if the source unit has been already initialized, when calling this on a prefab, set to false.</param> /// <returns>True if the resource type can be collected, otherwise false.</returns> public bool CanCollectResourceType(ResourceTypeInfo resourceType, bool useDic = true) { if (useDic) //the dictionary can be only used if the source unit has already been initialized. { return(collectionObjectsDic.ContainsKey(resourceType)); } else { foreach (CollectionObject co in collectionObjects) { if (co.resourceType == resourceType) { return(true); } } return(false); } }
/// <summary> /// Activates the main NPCUnitRegulator instance for the main resource collector unit. /// </summary> /// <param name="resourceType"></param> /// <param name="collectorMonitor"></param> private void ActivateCollectorRegulator(ResourceTypeInfo resourceType, NPCActiveRegulatorMonitor collectorMonitor) { collectorMonitor.Init(factionMgr); //Go ahead and add the resource collector regulator (if there's one).. foreach (ResourceCollector collector in collectors) { Assert.IsNotNull(collector, $"[NPCResourceCollector] NPC Faction ID: {factionMgr.FactionID} 'Collectors' list has some unassigned elements."); NPCUnitRegulator nextRegulator = null; //as soon a collector prefab produces a valid unit regulator instance (matches the faction type and faction npc manager), add it to monitor component if (collector.CanCollectResourceType(resourceType, false) && //also make sure the resource collector can collect this resource type. (nextRegulator = npcMgr.GetNPCComp <NPCUnitCreator>().ActivateUnitRegulator(collector.GetComponent <Unit>())) != null) { collectorMonitor.Replace("", nextRegulator.Code); } } Assert.IsTrue(collectorMonitor.GetCount() > 0, $"[NPCBuildingConstructor] NPC Faction ID: {factionMgr.FactionID} doesn't have a resource collector regulator assigned for resource type: {resourceType.GetName()}!"); }
public EditorResourceBrush(EditorViewportControllerWidget editorWidget, ResourceTypeInfo resource, WorldRenderer wr) { this.editorWidget = editorWidget; ResourceType = resource; worldRenderer = wr; world = wr.World; preview = editorWidget.Get <SpriteWidget>("DRAG_LAYER_PREVIEW"); preview.Palette = resource.Palette; preview.GetScale = () => worldRenderer.Viewport.Zoom; preview.IsVisible = () => editorWidget.CurrentBrush == this; var variant = resource.Variants.FirstOrDefault(); var sequence = wr.World.Map.Rules.Sequences.GetSequence("resources", variant); var sprite = sequence.GetSprite(resource.MaxDensity - 1); preview.GetSprite = () => sprite; // The preview widget may be rendered by the higher-level code before it is ticked. // Force a manual tick to ensure the bounds are set correctly for this first draw. Tick(); }
} //Whenever a resource is missing, we start searching for it from a faction center. This variable holds the last ID of the faction center that we started the search from. //constructor public MapResource(ResourceTypeInfo type) { this.type = type; this.currAmount = this.type.GetStartingAmount(); }
//Faction-resource events: public static void OnFactionResourceUpdate(ResourceTypeInfo resourceType, int factionID, int amount) { FactionResourceUpdated(resourceType, factionID, amount); }
public ResourceType(ResourceTypeInfo info, params ObjectTemplate[] templates) { Info = info; Templates = templates; }
public AddResourcesEditorAction(Map map, ResourceTypeInfo resourceType) { this.map = map; this.resourceType = resourceType; }
private static IEnumerable <ResourceTypeInfo> resourceTypes = null; //holds currently available ResourceTypeInfo asset files. /// <summary> /// Gets the cached ResourceTypeInfo assets in the project and refreshes the cache if necessary. /// </summary> /// <param name="requireTest">When true, a test will determine whether testResourceType is cached or not. If already cached, the cache will not be refreshed.</param> /// <param name="testResourceType">The ResourceTypeInfo instance to test.</param> /// <returns>Diciontary instance where each key is the code cached ResourceTypeInfo assets and each value is the actual asset instance that matches the key type</returns> public static Dictionary <string, ResourceTypeInfo> GetResourceTypes(bool requireTest = false, ResourceTypeInfo testResourceType = null) { //only refresh if.. if (resourceTypes == null || //cache hasn't been assigned yet. (requireTest == true && !resourceTypes.Contains(testResourceType))) //or test is required while test resource type is not in the cached list { CacheAssetFiles(out resourceTypes, "t:ResourceTypeInfo"); } return(resourceTypes.ToDictionary(type => type == null ? "Unassigned" : type.GetName())); }
public TransportResources(Actor self, Target target, int payload, ResourceTypeInfo typeInfo) : base(self, target, Color.Yellow) { this.payload = payload; this.typeInfo = typeInfo; }