示例#1
0
        public static Resource GetAverageWithTag(Resource.ResourceTags tag)
        {
            List <Resource> applicable = Resources.Values.Where(resource => resource.Tags.Contains(tag)).ToList();

            applicable.Sort((a, b) =>
            {
                if (a == b)
                {
                    return(0);
                }

                if (a.MoneyValue < b.MoneyValue)
                {
                    return(-1);
                }
                if (a.MoneyValue == b.MoneyValue)
                {
                    return(0);
                }

                return(1);
            });
            if (applicable.Count == 0)
            {
                return(null);
            }

            return(applicable[applicable.Count / 2]);
        }
        public List <ResourceAmount> ListResourcesWithTag(Resource.ResourceTags tag, bool allowHeterogenous = true)
        {
            var resources = ListResources();

            if (allowHeterogenous)
            {
                return((from pair in resources
                        where Library.GetResourceType(pair.Value.Type).Tags.Contains(tag)
                        select pair.Value).ToList());
            }

            ResourceAmount maxAmount = null;

            foreach (var pair in resources)
            {
                var resource = Library.GetResourceType(pair.Value.Type);
                if (!resource.Tags.Contains(tag))
                {
                    continue;
                }
                if (maxAmount == null || pair.Value.Count > maxAmount.Count)
                {
                    maxAmount = pair.Value;
                }
            }
            return(maxAmount != null ? new List <ResourceAmount>()
            {
                maxAmount
            } : new List <ResourceAmount>());
        }
示例#3
0
        public List <ResourceAmount> GenerateResources()
        {
            Dictionary <ResourceLibrary.ResourceType, ResourceAmount> toReturn =
                new Dictionary <ResourceLibrary.ResourceType, ResourceAmount>();

            foreach (var tags in TradeGoods)
            {
                int num = MathFunctions.RandInt(tags.Value - 5, tags.Value + 5);


                List <Resource> resources = ResourceLibrary.GetResourcesByTag(tags.Key);

                if (resources.Count <= 0)
                {
                    continue;
                }

                for (int i = 0; i < num; i++)
                {
                    Resource randResource = Datastructures.SelectRandom(resources);

                    if (randResource.Type == ResourceLibrary.ResourceType.Trinket ||
                        randResource.Type == ResourceLibrary.ResourceType.GemTrinket ||
                        tags.Key == Resource.ResourceTags.Craft)
                    {
                        Resource.ResourceTags craftTag        = Datastructures.SelectRandom(Crafts);
                        List <Resource>       availableCrafts = ResourceLibrary.GetResourcesByTag(craftTag);

                        Resource trinket = ResourceLibrary.GenerateTrinket(
                            Datastructures.SelectRandom(availableCrafts).Type, MathFunctions.Rand(0.1f, 3.0f));

                        if (MathFunctions.RandEvent(0.3f) && Encrustings.Count > 0)
                        {
                            List <Resource> availableGems =
                                ResourceLibrary.GetResourcesByTag(Datastructures.SelectRandom(Encrustings));
                            randResource = ResourceLibrary.EncrustTrinket(trinket.Type,
                                                                          Datastructures.SelectRandom(availableGems).Type);
                        }
                        else
                        {
                            randResource = trinket;
                        }
                    }

                    if (!toReturn.ContainsKey(randResource.Type))
                    {
                        toReturn[randResource.Type] = new ResourceAmount(randResource.Type, 1);
                    }
                    else
                    {
                        toReturn[randResource.Type].NumResources += 1;
                    }
                }
            }

            List <ResourceAmount> resList = toReturn.Select(amount => amount.Value).ToList();

            return(resList);
        }
示例#4
0
 public GetResourcesAct(CreatureAI agent, Resource.ResourceTags resources) :
     base(agent)
 {
     Name      = "Get Resources";
     Resources = new List <Quantitiy <Resource.ResourceTags> >()
     {
         new Quantitiy <Resource.ResourceTags>(resources)
     };
 }
示例#5
0
        public int GetResourceCount(Resource.ResourceTags resourceType)
        {
            int count = 0;

            foreach (var resource in Resources.Values.Where(resource => Library.GetResourceType(resource.Type).Tags.Contains(resourceType)))
            {
                count = Math.Max(count, resource.Count);
            }
            return(count);
        }
示例#6
0
 public int GetNumRequiredResources(Resource.ResourceTags name)
 {
     if (ToBuild.RoomData.RequiredResources.ContainsKey(name))
     {
         return(Math.Max((int)(ToBuild.RoomData.RequiredResources[name].NumResources * VoxelOrders.Count * 0.25f), 1));
     }
     else
     {
         return(0);
     }
 }
示例#7
0
        public bool IsResourceSatisfied(Resource.ResourceTags name)
        {
            int required = GetNumRequiredResources(name);
            int current  = 0;

            if (PutResources.ContainsKey(name))
            {
                current = (int)PutResources[name].NumResources;
            }

            return(current >= required);
        }
        public int CountResourcesWithTag(Resource.ResourceTags tag)
        {
            List <ResourceAmount> resources = ListResourcesWithTag(tag);
            int amounts = 0;

            foreach (ResourceAmount amount in resources)
            {
                amounts += amount.Count;
            }

            return(amounts);
        }
示例#9
0
        public static Resource FindMedianResourceTypeWithTag(Resource.ResourceTags tag)
        {
            InitializeResources();
            var applicable = Resources.Values.Where(resource => resource.Tags.Contains(tag)).ToList();

            if (applicable.Count == 0)
            {
                return(null);
            }
            applicable.Sort((a, b) => (int)a.MoneyValue.Value - (int)b.MoneyValue.Value);
            return(applicable[applicable.Count / 2]);
        }
示例#10
0
        public int CountResourcesWithTags(Resource.ResourceTags tag)
        {
            int toReturn = 0;

            foreach (ResourceAmount resource in Resources.Values)
            {
                if (ResourceLibrary.GetResourceByName(resource.ResourceType).Tags.Contains(tag))
                {
                    toReturn += resource.NumResources;
                }
            }

            return(toReturn);
        }
示例#11
0
        public static Resource GetLeastValuableWithTag(Resource.ResourceTags tag)
        {
            Resource min      = null;
            DwarfBux minValue = decimal.MaxValue;

            foreach (var r in Resources.Values.Where(resource => resource.Tags.Contains(tag)))
            {
                if (r.MoneyValue < minValue)
                {
                    minValue = r.MoneyValue;
                    min      = r;
                }
            }
            return(min);
        }
示例#12
0
 public int GetResourceCount(Resource.ResourceTags resourceType, bool allowHeterogenous = false)
 {
     if (allowHeterogenous)
     {
         return(Resources.Values.Where(resource => ResourceLibrary.GetResourceByName(resource.ResourceType).Tags.Contains(resourceType)).Sum(resource => resource.NumResources));
     }
     else
     {
         int count = 0;
         foreach (var resource in Resources.Values.Where(resource => ResourceLibrary.GetResourceByName(resource.ResourceType).Tags.Contains(resourceType)))
         {
             count = Math.Max(count, resource.NumResources);
         }
         return(count);
     }
 }
示例#13
0
        private static String GetPluralForm(Resource.ResourceTags Tag)
        {
            if (PluralMap == null)
            {
                PluralMap = new Dictionary <Resource.ResourceTags, string>
                {
                    { Resource.ResourceTags.Edible, "edibles" },
                    { Resource.ResourceTags.Material, "materials" },
                    { Resource.ResourceTags.HardMaterial, "hard materials" },
                    { Resource.ResourceTags.Precious, "precious things" },
                    { Resource.ResourceTags.Flammable, "flammable things" },
                    { Resource.ResourceTags.SelfIlluminating, "self illuminating things" },
                    { Resource.ResourceTags.Wood, "wooden things" },
                    { Resource.ResourceTags.Metal, "metal things" },
                    { Resource.ResourceTags.Stone, "stone things" },
                    { Resource.ResourceTags.Fuel, "fuel" },
                    { Resource.ResourceTags.Magical, "magical items" },
                    { Resource.ResourceTags.Soil, "soil" },
                    { Resource.ResourceTags.Grain, "grains" },
                    { Resource.ResourceTags.Fungus, "fungi" },
                    { Resource.ResourceTags.None, "WUT" },
                    { Resource.ResourceTags.AnimalProduct, "animal products" },
                    { Resource.ResourceTags.Meat, "meats" },
                    { Resource.ResourceTags.Gem, "gems" },
                    { Resource.ResourceTags.Craft, "crafts" },
                    { Resource.ResourceTags.Encrustable, "encrustable items" },
                    { Resource.ResourceTags.Alcohol, "alcoholic drinks" },
                    { Resource.ResourceTags.Brewable, "brewed drinks" },
                    { Resource.ResourceTags.Bakeable, "baked goods" },
                    { Resource.ResourceTags.RawFood, "raw foods" },
                    { Resource.ResourceTags.PreparedFood, "prepared foods" },
                    { Resource.ResourceTags.Plantable, "seeds" },
                    { Resource.ResourceTags.AboveGroundPlant, "plants" },
                    { Resource.ResourceTags.BelowGroundPlant, "cave plants" },
                    { Resource.ResourceTags.Bone, "bones" },
                    { Resource.ResourceTags.Gourd, "gourds" },
                    { Resource.ResourceTags.Fruit, "fruits" },
                    { Resource.ResourceTags.Evil, "evil things" }
                };
            }

            return(PluralMap[Tag]);
        }
示例#14
0
        public List <ResourceAmount> GenerateResources(WorldManager world)
        {
            Dictionary <ResourceType, ResourceAmount> toReturn =
                new Dictionary <ResourceType, ResourceAmount>();

            Resource.ResourceTags[] blacklistTags = { Resource.ResourceTags.Money, Resource.ResourceTags.Corpse };
            foreach (var tags in TradeGoods)
            {
                int num = MathFunctions.RandInt(tags.Value - 5, tags.Value + 5);


                IEnumerable <Resource> resources = ResourceLibrary.GetResourcesByTag(tags.Key);

                if (resources.Count() <= 0)
                {
                    continue;
                }

                for (int i = 0; i < num; i++)
                {
                    Resource randResource = Datastructures.SelectRandom(resources);

                    if (randResource.Tags.Any(blacklistTags.Contains))
                    {
                        continue;
                    }

                    if (tags.Key == Resource.ResourceTags.Craft)
                    {
                        Resource.ResourceTags  craftTag        = Datastructures.SelectRandom(Crafts);
                        IEnumerable <Resource> availableCrafts = ResourceLibrary.GetResourcesByTag(craftTag);

                        Resource trinket = ResourceLibrary.GenerateTrinket(
                            Datastructures.SelectRandom(availableCrafts).Name, MathFunctions.Rand(0.1f, 3.0f));

                        if (MathFunctions.RandEvent(0.3f) && Encrustings.Count > 0)
                        {
                            IEnumerable <Resource> availableGems =
                                ResourceLibrary.GetResourcesByTag(Datastructures.SelectRandom(Encrustings));
                            randResource = ResourceLibrary.EncrustTrinket(trinket.Name,
                                                                          Datastructures.SelectRandom(availableGems).Name);
                        }
                        else
                        {
                            randResource = trinket;
                        }
                    }

                    if (!toReturn.ContainsKey(randResource.Name))
                    {
                        toReturn[randResource.Name] = new ResourceAmount(randResource.Name, 1);
                    }
                    else
                    {
                        toReturn[randResource.Name].NumResources += 1;
                    }
                }
            }

            for (int i = 0; i < NumFurniture; i++)
            {
                var randomObject = Datastructures.SelectRandom(CraftLibrary.EnumerateCraftables().Where(type => type.Type == CraftItem.CraftType.Object && type.RequiredResources.All((tags) =>
                                                                                                                                                                                      TradeGoods.Any(good => good.Key == tags.ResourceType))));
                if (randomObject == null)
                {
                    continue;
                }
                List <ResourceAmount> selectedResources = new List <ResourceAmount>();
                foreach (var requirement in randomObject.RequiredResources)
                {
                    IEnumerable <Resource> resources = ResourceLibrary.GetResourcesByTag(requirement.ResourceType);
                    selectedResources.Add(new ResourceAmount(Datastructures.SelectRandom(resources), requirement.NumResources));
                }
                var randResource = randomObject.ToResource(world, selectedResources, Posessive + " ");
                if (!toReturn.ContainsKey(randResource.Name))
                {
                    toReturn[randResource.Name] = new ResourceAmount(randResource.Name, 1);
                }
                else
                {
                    toReturn[randResource.Name].NumResources += 1;
                }
            }

            List <ResourceAmount> resList = toReturn.Select(amount => amount.Value).ToList();

            return(resList);
        }
示例#15
0
 public bool HasResource(Resource.ResourceTags resourceType)
 {
     return(Resources.Values.Any(resource => ResourceLibrary.GetResourceByName(resource.ResourceType).Tags.Contains(resourceType)));
 }
示例#16
0
        public List <ResourceAmount> ListResourcesWithTag(Resource.ResourceTags tag)
        {
            Dictionary <string, ResourceAmount> resources = ListResources();

            return((from pair in resources where ResourceLibrary.GetResourceByName(pair.Value.ResourceType).Tags.Contains(tag) select pair.Value).ToList());
        }
示例#17
0
        public override void Construct()
        {
            Border      = "border-fancy";
            Font        = "font10";
            OnConstruct = (sender) =>
            {
                sender.Root.RegisterForUpdate(sender);

                FilterBox = AddChild(new EditableTextField
                {
                    AutoLayout  = AutoLayout.DockTop,
                    MinimumSize = new Point(0, 24),
                    Text        = ""
                }) as EditableTextField;

                ListView = AddChild(new WidgetListView
                {
                    AutoLayout = AutoLayout.DockFill,
                    SelectedItemForegroundColor = new Vector4(0, 0, 0, 1),
                    ChangeColorOnSelected       = false,
                    Border     = null,
                    ItemHeight = 24
                }) as WidgetListView;

                ListView.Border = null; // Can't make WidgetListView stop defaulting its border without breaking everywhere else its used.
            };

            OnUpdate = (sender, time) =>
            {
                if (sender.Hidden)
                {
                    return;
                }

                var roomsToDisplay = World.EnumerateZones().Where(r => !String.IsNullOrEmpty(FilterBox.Text) ? r.ID.Contains(FilterBox.Text) : true);

                int i = 0;
                ListView.ClearItems();
                foreach (var room in roomsToDisplay)
                {
                    i++;
                    var tag        = room.GuiTag as Widget;
                    var lambdaCopy = room;

                    if (tag != null)
                    {
                        ListView.AddItem(tag);
                    }
                    else
                    {
                        #region Create gui row

                        tag = Root.ConstructWidget(new Widget
                        {
                            Text              = room.GetDescriptionString(),
                            MinimumSize       = new Point(0, 16),
                            Padding           = new Margin(0, 0, 4, 4),
                            TextVerticalAlign = VerticalAlign.Center,
                            Background        = new TileReference("basic", 0),
                            BackgroundColor   = i % 2 == 0 ? new Vector4(0.0f, 0.0f, 0.0f, 0.1f) : new Vector4(0, 0, 0, 0.25f)
                        });

                        tag.OnUpdate = (sender1, args) =>
                        {
                            if (tag.IsAnyParentHidden())
                            {
                                return;
                            }

                            if (sender1.ComputeBoundingChildRect().Contains(Root.MousePosition))
                            {
                                Drawer3D.DrawBox(lambdaCopy.GetBoundingBox(), Color.White, 0.1f, true);
                            }
                        };

                        Root.RegisterForUpdate(tag);

                        tag.AddChild(new Button
                        {
                            Text               = "Destroy",
                            AutoLayout         = AutoLayout.DockRight,
                            MinimumSize        = new Point(16, 0),
                            ChangeColorOnHover = true,
                            TextVerticalAlign  = VerticalAlign.Center,
                            OnClick            = (_sender, args) =>
                            {
                                World.UserInterface.Gui.ShowModalPopup(new Gui.Widgets.Confirm
                                {
                                    Text    = "Do you want to destroy this " + lambdaCopy.Type.Name + "?",
                                    OnClose = (_sender2) => DestroyZoneTool.DestroyRoom((_sender2 as Gui.Widgets.Confirm).DialogResult, lambdaCopy, World)
                                });
                            }
                        });

                        tag.AddChild(new Widget {
                            MinimumSize = new Point(4, 0), AutoLayout = AutoLayout.DockRight
                        });

                        tag.AddChild(new Button
                        {
                            Text               = "Go to",
                            AutoLayout         = AutoLayout.DockRight,
                            ChangeColorOnHover = true,
                            MinimumSize        = new Point(16, 0),
                            TextVerticalAlign  = VerticalAlign.Center,
                            OnClick            = (_sender, args) =>
                            {
                                World.Renderer.Camera.ZoomTargets.Clear();
                                World.Renderer.Camera.ZoomTargets.Add(lambdaCopy.GetBoundingBox().Center());
                            }
                        });

                        if (lambdaCopy is Stockpile && !(lambdaCopy is Graveyard))
                        {
                            tag.AddChild(new Button
                            {
                                Text               = "Resources...",
                                AutoLayout         = AutoLayout.DockRight,
                                ChangeColorOnHover = true,
                                MinimumSize        = new Point(16, 0),
                                TextVerticalAlign  = VerticalAlign.Center,
                                OnClick            = (_sender, args) =>
                                {
                                    List <Resource.ResourceTags> blacklistableResources = new List <Resource.ResourceTags>()
                                    {
                                        Resource.ResourceTags.Alcohol,
                                        Resource.ResourceTags.Meat,
                                        Resource.ResourceTags.Metal,
                                        Resource.ResourceTags.Gem,
                                        Resource.ResourceTags.Magical,
                                        Resource.ResourceTags.Wood,
                                        Resource.ResourceTags.Soil,
                                        Resource.ResourceTags.Sand,
                                        Resource.ResourceTags.Fruit,
                                        Resource.ResourceTags.Gourd,
                                        Resource.ResourceTags.Grain,
                                        Resource.ResourceTags.Fungus,
                                        Resource.ResourceTags.Fuel,
                                        Resource.ResourceTags.Craft,
                                        Resource.ResourceTags.CraftItem,
                                        Resource.ResourceTags.Bone,
                                        Resource.ResourceTags.Potion,
                                        Resource.ResourceTags.PreparedFood,
                                        Resource.ResourceTags.Rail,
                                        Resource.ResourceTags.Seed
                                    }.OrderBy(t => t.ToString()).ToList();
                                    int sqr       = (int)Math.Sqrt(blacklistableResources.Count);
                                    int minWidth  = Math.Min(sqr * 200 + 64, Root.RenderData.VirtualScreen.Width);
                                    int minHeight = Math.Min(sqr * 32 + 232, Root.RenderData.VirtualScreen.Height);
                                    var widget    = Root.ConstructWidget(new Widget()
                                    {
                                        Border = "border-fancy",
                                        Font   = "font10",
                                        Rect   = new Rectangle(Root.RenderData.VirtualScreen.X + (Root.RenderData.VirtualScreen.Width - minWidth) / 2, Root.RenderData.VirtualScreen.Y + (Root.RenderData.VirtualScreen.Height - minHeight) / 2, minWidth, minHeight)
                                    });

                                    widget.AddChild(new Widget()
                                    {
                                        MinimumSize = new Point(120, 32),
                                        Text        = "Allowed Resources",
                                        Font        = "font16",
                                        AutoLayout  = AutoLayout.DockTop,
                                    });

                                    var interiorWidget = widget.AddChild(new Widget()
                                    {
                                        Rect       = new Rectangle(Root.RenderData.VirtualScreen.X + (Root.RenderData.VirtualScreen.Width - minWidth), Root.RenderData.VirtualScreen.Y + (Root.RenderData.VirtualScreen.Height - minHeight), minWidth, minHeight),
                                        AutoLayout = AutoLayout.DockTop
                                    });

                                    var stockpile = lambdaCopy as Stockpile;

                                    var grid = interiorWidget.AddChild(new GridPanel()
                                    {
                                        AutoLayout  = AutoLayout.DockFill,
                                        ItemSize    = new Point(200, 32),
                                        ItemSpacing = new Point(2, 2)
                                    }) as GridPanel;

                                    List <CheckBox> boxes = new List <CheckBox>();
                                    foreach (Resource.ResourceTags tagType in blacklistableResources)
                                    {
                                        var resource  = Library.FindMedianResourceTypeWithTag(tagType);
                                        var resources = Library.EnumerateResourceTypesWithTag(tagType);
                                        Resource.ResourceTags lambdaType = tagType;
                                        var entry = grid.AddChild(new Widget());

                                        if (resource != null)
                                        {
                                            entry.AddChild(new ResourceIcon()
                                            {
                                                MinimumSize = new Point(32, 32),
                                                MaximumSize = new Point(32, 32),
                                                Layers      = resource.GuiLayers,
                                                AutoLayout  = AutoLayout.DockLeft
                                            });
                                        }

                                        var numResourcesInGroup = resources.Count();
                                        var extraTooltip        = numResourcesInGroup > 0 ?  "\ne.g " + TextGenerator.GetListString(resources.Select(s => (string)s.Name).Take(Math.Min(numResourcesInGroup, 4)).ToList()) : "";

                                        boxes.Add(entry.AddChild(new CheckBox()
                                        {
                                            Text               = SplitCamelCase(tagType.ToString()),
                                            Tooltip            = "Check to allow this stockpile to store " + tagType.ToString() + " resources." + extraTooltip,
                                            CheckState         = !stockpile.BlacklistResources.Contains(tagType),
                                            OnCheckStateChange = (checkSender) =>
                                            {
                                                var checkbox = checkSender as CheckBox;
                                                if (checkbox.CheckState && stockpile.BlacklistResources.Contains(lambdaType))
                                                {
                                                    stockpile.BlacklistResources.Remove(lambdaType);
                                                }
                                                else if (!stockpile.BlacklistResources.Contains(lambdaType))
                                                {
                                                    stockpile.BlacklistResources.Add(lambdaType);
                                                }
                                            },
                                            AutoLayout = AutoLayout.DockLeft
                                        }
                                                                 ) as CheckBox);
                                    }


                                    widget.AddChild(new CheckBox()
                                    {
                                        Text               = "Toggle All",
                                        CheckState         = boxes.All(b => b.CheckState),
                                        OnCheckStateChange = (checkSender) =>
                                        {
                                            foreach (var box in boxes)
                                            {
                                                box.CheckState = (checkSender as CheckBox).CheckState;
                                            }
                                        },
                                        AutoLayout = AutoLayout.FloatBottomLeft
                                    });

                                    widget.AddChild(new Button()
                                    {
                                        Text       = "OK",
                                        AutoLayout = AutoLayout.FloatBottomRight,
                                        OnClick    = (sender1, args1) => { widget.Close(); }
                                    });


                                    widget.Layout();
                                    Root.ShowModalPopup(widget);
                                }
                            });
                        }

                        #endregion

                        room.GuiTag = tag;
                        ListView.AddItem(tag);
                    }

                    tag.Text = room.GetDescriptionString();
                }

                ListView.Invalidate();
            };

            base.Construct();
        }
示例#18
0
 public static List <Resource> GetResourcesByTag(Resource.ResourceTags tag)
 {
     return(Resources.Values.Where(resource => resource.Tags.Contains(tag)).ToList());
 }
示例#19
0
 public static IEnumerable <Resource> EnumerateResourceTypesWithTag(Resource.ResourceTags tag)
 {
     InitializeResources();
     return(Resources.Values.Where(resource => resource.Tags.Contains(tag)));
 }
示例#20
0
 public int GetResourceCount(Resource.ResourceTags resourceType)
 {
     return(Resources.Values.Where(resource => ResourceLibrary.GetResourceByName(resource.ResourceType).Tags.Contains(resourceType)).Sum(resource => resource.NumResources));
 }
示例#21
0
 public static IEnumerable <Resource> GetResourcesByTag(Resource.ResourceTags tag)
 {
     return(Resources.Values.Where(resource => resource.Tags.Contains(tag)));
 }
示例#22
0
 public bool HasResource(Resource.ResourceTags resourceType)
 {
     return(Resources.Values.Any(resource => resource.ResourceType.Tags.Contains(resourceType)));
 }