Module:Utility
From Against the Storm Official Wiki
Documentation for this module may be created at Module:Utility/doc
------------------------------------------------------------------------------- -- This module provides utility functions for several other modules, so that -- there are not require/dependency loops. -- -- The template requires at least one of its two arguments. The first is called -- "product". and the second is called "building". Both are passed to the -- RecipeData module, which returns one or more recipes. -- -- Using the recipe data returned, this module creates an HTML table that -- displays the recipes, which replaces the template, whereever it is written -- in the wiki markup. The table will have exactly one row if both the product -- and building are specified. If either is missing, then expect a table with -- multiple rows. -- @module Utility local Utility = {} ------------------------------------------------------------------------------- -- Normalizes a building name for use as the key in other lookup tables. -- -- This function at least makes the argument lowercase, since keys are -- lowercase to reduce the number of similarities to normalize. -- @param buildingName the in-game name -- @return a normalized name for use as a key function Utility.normalizeBuildingName(buildingName) -- no matter what, we want to return the lowercase version buildingName = string.lower(buildingName) -- No other functions should have this lookup table, so it's defined -- locally to this function. The keys are the possible ways the name could -- be written. The values are the normalized string that are used as keys. local tBuildingSimilarities = { -- Starting Buildings ["ancienthearth"] = "ancient hearth", ["ancienthearths"] = "ancient hearth", ["ancient hearths"] = "ancient hearth", ["mainwarehouse"] = "main warehouse", ["mainwarehouses"] = "main warehouse", ["main warehouses"] = "main warehouse", -- Camps ["forager"] = "foragers' camp", ["foragerscamp"] = "foragers' camp", ["forager'scamp"] = "foragers' camp", ["foragers'camp"] = "foragers' camp", ["forager camp"] = "foragers' camp", ["forager's camp"] = "foragers' camp", ["foragers"] = "foragers' camp", ["foragerscamps"] = "foragers' camp", ["forager'scamps"] = "foragers' camp", ["foragers'camps"] = "foragers' camp", ["forager camps"] = "foragers' camp", ["forager's camps"] = "foragers' camp", ["harvester"] = "harvesters' camp", ["harvesterscamp"] = "harvesters' camp", ["harvester'scamp"] = "harvesters' camp", ["harvesters'camp"] = "harvesters' camp", ["harvester camp"] = "harvesters' camp", ["harvester's camp"] = "harvesters' camp", ["harvesters"] = "harvesters' camp", ["harvesterscamps"] = "harvesters' camp", ["harvester'scamps"] = "harvesters' camp", ["harvesters'camps"] = "harvesters' camp", ["harvester camps"] = "harvesters' camp", ["harvester's camps"] = "harvesters' camp", ["herbalist"] = "herbalists' camp", ["herbalistscamp"] = "herbalists' camp", ["herbalist'scamp"] = "herbalists' camp", ["herbalists'camp"] = "herbalists' camp", ["herbalist camp"] = "herbalists' camp", ["herbalist's camp"] = "herbalists' camp", ["herbalists"] = "herbalists' camp", ["herbalistscamps"] = "herbalists' camp", ["herbalist'scamps"] = "herbalists' camp", ["herbalists'camps"] = "herbalists' camp", ["herbalist camps"] = "herbalists' camp", ["herbalist's camps"] = "herbalists' camp", ["stonecutter"] = "stonecutters' camp", ["stonecutterscamp"] = "stonecutters' camp", ["stonecutter'scamp"] = "stonecutters' camp", ["stonecutters'camp"] = "stonecutters' camp", ["stonecutter camp"] = "stonecutters' camp", ["stonecutter's camp"] = "stonecutters' camp", ["stonecutters"] = "stonecutters' camp", ["stonecutterscamps"] = "stonecutters' camp", ["stonecutter'scamps"] = "stonecutters' camp", ["stonecutters'camps"] = "stonecutters' camp", ["stonecutter camps"] = "stonecutters' camp", ["stonecutter's camps"] = "stonecutters' camp", ["trapper"] = "trappers' camp", ["trapperscamp"] = "trappers' camp", ["trapper'scamp"] = "trappers' camp", ["trappers'camp"] = "trappers' camp", ["trapper camp"] = "trappers' camp", ["trapper's camp"] = "trappers' camp", ["trappers"] = "trappers' camp", ["trapperscamps"] = "trappers' camp", ["trapper'scamps"] = "trappers' camp", ["trappers'camps"] = "trappers' camp", ["trapper camps"] = "trappers' camp", ["trapper's camps"] = "trappers' camp", ["woodcutter"] = "woodcutters' camp", ["woodcutterscamp"] = "woodcutters' camp", ["woodcutter'scamp"] = "woodcutters' camp", ["woodcutters'camp"] = "woodcutters' camp", ["woodcutter camp"] = "woodcutters' camp", ["woodcutter's camp"] = "woodcutters' camp", ["woodcutters"] = "woodcutters' camp", ["woodcutterscamps"] = "woodcutters' camp", ["woodcutter'scamps"] = "woodcutters' camp", ["woodcutters'camps"] = "woodcutters' camp", ["woodcutter camps"] = "woodcutters' camp", ["woodcutter's camps"] = "woodcutters' camp", -- Farms ["field"] = "farm field", ["fields"] = "farm field", ["farmfield"] = "farm field", ["farmfields"] = "farm field", ["farm fields"] = "farm field", ["greenhouses"] = "greenhouse", ["green house"] = "greenhouse", ["green houses"] = "greenhouse", ["herbgarden"] = "herb garden", ["herbgardens"] = "herb garden", ["herb gardens"] = "herb garden", ["plantations"] = "plantation", ["farm"] = "small farm", ["farms"] = "small farm", ["smallfarm"] = "small farm", ["smallfarms"] = "small farm", ["small farms"] = "small farm", -- Food Production ["baker"] = "bakery", ["bakers"] = "bakery", ["bakeries"] = "bakery", ["butchers"] = "butcher", ["celler"] = "cellar", ["cellers"] = "cellar", ["cellars"] = "cellar", ["cookhouses"] = "cookhouse", ["cook house"] = "cookhouse", ["cook houses"] = "cookhouse", ["fieldkitchen"] = "field kitchen", ["fieldkitchens"] = "field kitchen", ["field kitchens"] = "field kitchen", ["granaries"] = "granary", ["grills"] = "grill", ["ranches"] = "ranch", ["smokehouses"] = "smokehouse", ["smoke house"] = "smokehouse", ["smoke housea"] = "smokehouse", -- Housing ["house"] = "shelter", ["houses"] = "shelter", ["bighouse"] = "big shelter", ["bighouses"] = "big shelter", ["bigshelter"] = "big shelter", ["bigshelters"] = "big shelter", ["humanhouse"] = "human house", ["humanhouses"] = "human house", ["human'shouse"] = "human house", ["humans'house"] = "human house", ["human houses"] = "human house", ["human's house"] = "human house", ["humans' house"] = "human house", ["human's houses"] = "human house", ["humans' houses"] = "human house", ["beaverhouse"] = "beaver house", ["beaverhouses"] = "beaver house", ["beaver'shouse"] = "beaver house", ["beavers'house"] = "beaver house", ["beaver'shouses"] = "beaver house", ["beavers'houses"] = "beaver house", ["beaver houses"] = "beaver house", ["beaver's houses"] = "beaver house", ["beavers' houses"] = "beaver house", ["lizardhouse"] = "lizard house", ["lizardhouses"] = "lizard house", ["lizard'shouse"] = "lizard house", ["lizards'house"] = "lizard house", ["lizard'shouses"] = "lizard house", ["lizards'houses"] = "lizard house", ["lizard houses"] = "lizard house", ["lizard's houses"] = "lizard house", ["lizards' houses"] = "lizard house", ["harpyhouse"] = "harpy house", ["harpyhouses"] = "harpy house", ["harpy'shouse"] = "harpy house", ["harpys'house"] = "harpy house", ["harpy'shouses"] = "harpy house", ["harpys'houses"] = "harpy house", ["harpy houses"] = "harpy house", ["harpy's houses"] = "harpy house", ["harpys' houses"] = "harpy house", ["harpieshouse"] = "harpy house", ["harpieshouses"] = "harpy house", ["harpies'house"] = "harpy house", ["harpies houses"] = "harpy house", ["harpies' houses"] = "harpy house", -- Industry ["crudeworkstation"] = "crude workstation", ["crudeworkstations"] = "crude workstation", ["crude workstations"] = "crude workstation", ["makeshiftpost"] = "makeshift post", ["makeshiftposts"] = "makeshift post", ["makeshift posts"] = "makeshift post", ["advancedraincollector"] = "advanced rain collector", ["advancedraincollectors"] = "advanced rain collector", ["advanced rain collectors"] = "advanced rain collector", ["alchemist"] = "alchemist's hut", ["alchemists"] = "alchemist's hut", ["alchemisthut"] = "alchemist's hut", ["alchemisthuts"] = "alchemist's hut", ["alchemistshut"] = "alchemist's hut", ["alchemistshuts"] = "alchemist's hut", ["alchemist'shut"] = "alchemist's hut", ["alchemist'shuts"] = "alchemist's hut", ["alchemists'hut"] = "alchemist's hut", ["alchemists'huts"] = "alchemist's hut", ["alchemist hut"] = "alchemist's hut", ["alchemist huts"] = "alchemist's hut", ["alchemists hut"] = "alchemist's hut", ["alchemists huts"] = "alchemist's hut", ["alchemists' hut"] = "alchemist's hut", ["alchemists' huts"] = "alchemist's hut", ["apothacary"] = "apothecary", ["apothecaries"] = "apothecary", ["artisans"] = "artisan", ["brewer"] = "brewery", ["brewers"] = "brewery", ["breweries"] = "brewery", ["brickoven"] = "brick oven", ["brickovens"] = "brick oven", ["brick ovens"] = "brick oven", ["brickyards"] = "brickyard", ["brick yard"] = "brickyard", ["brick yards"] = "brickyard", ["carpenters"] = "carpenter", ["clothiers"] = "clothier", ["cooper"] = "cooperage", ["coopers"] = "cooperage", ["cooperages"] = "cooperage", ["druid"] = "druid's hut", ["druids"] = "druid's hut", ["druidhut"] = "druid's hut", ["druidhuts"] = "druid's hut", ["druid'shut"] = "druid's hut", ["druid'shuts"] = "druid's hut", ["druids'hut"] = "druid's hut", ["druids'huts"] = "druid's hut", ["druid hut"] = "druid's hut", ["druid huts"] = "druid's hut", ["druids' hut"] = "druid's hut", ["druids' huts"] = "druid's hut", ["druid's huts"] = "druid's hut", ["flawlessbrewery"] = "flawless brewery", ["flawlessbreweries"] = "flawless brewery", ["flawless breweries"] = "flawless brewery", ["flawlessrainmill"] = "flawless rain mill", ["flawlessrainmills"] = "flawless rain mill", ["flawless rainmill"] = "flawless rain mill", ["flawless rainmills"] = "flawless rain mill", ["flawless rain mills"] = "flawless rain mill", ["furnaces"] = "furnace", ["kilns"] = "kiln", ["leatherworkers"] = "leatherworker", ["leather worker"] = "leatherworker", ["leather workers"] = "leatherworker", ["lumbermill"] = "lumber mill", ["lumbermills"] = "lumber mill", ["lumber mills"] = "lumber mill", ["mines"] = "mine", ["presses"] = "press", ["provisioners"] = "provisioner", ["raincollector"] = "rain collector", ["raincollectors"] = "rain collector", ["rain collectors"] = "rain collector", ["rainmill"] = "rain mill", ["rainmills"] = "rain mill", ["rain mills"] = "rain mill", ["scribes"] = "scribe", ["smelters"] = "smelter", ["smeltery"] = "smelter", ["smelteries"] = "smelter", ["tool shop"] = "toolshop", ["weavers"] = "weaver", -- City buildings ["archaeologyoffice"] = "archaeologist's office", ["archeologyoffice"] = "archaeologist's office", ["archaeologistoffice"] = "archaeologist's office", ["archeologistoffice"] = "archaeologist's office", ["archaeologistsoffice"] = "archaeologist's office", ["archeologistsoffice"] = "archaeologist's office", ["archaeologist'soffice"] = "archaeologist's office", ["archeologist'soffice"] = "archaeologist's office", ["archeologists'office"] = "archaeologist's office", ["archaeology office"] = "archaeologist's office", ["archeology office"] = "archaeologist's office", ["archaeologist office"] = "archaeologist's office", ["archeologist office"] = "archaeologist's office", ["archaeologists office"] = "archaeologist's office", ["archeologists office"] = "archaeologist's office", ["archeologist's office"] = "archaeologist's office", ["archaeologists' office"] = "archaeologist's office", ["archeologists' office"] = "archaeologist's office", ["smallhearth"] = "small hearth", ["smallhearths"] = "small hearth", ["small hearths"] = "small hearth", ["warehouses"] = "warehouse", ["ware house"] = "warehouse", ["ware houses"] = "warehouse", ["traderpost"] = "trading post", ["traderposts"] = "trading post", ["trader posts"] = "trading post", ["tradingpost"] = "trading post", ["tradingposts"] = "trading post", ["trading posts"] = "trading post", ["blightpost"] = "blight post", ["blightposts"] = "blight post", ["blight posts"] = "blight post", ["hydrants"] = "hydrant", ["forsakenaltar"] = "forsaken altar", ["forsakenalter"] = "forsaken altar", ["foresakenaltar"] = "forsaken altar", ["foresakenalter"] = "forsaken altar", ["forsakenaltars"] = "forsaken altar", ["forsakenalters"] = "forsaken altar", ["foresakenaltars"] = "forsaken altar", ["foresakenalters"] = "forsaken altar", ["forsaken altars"] = "forsaken altar", ["forsaken alters"] = "forsaken altar", ["foresaken altars"] = "forsaken altar", ["foresaken alters"] = "forsaken altar", -- Service Buildings ["bath"] = "bath house", ["baths"] = "bath house", ["bathhouse"] = "bath house", ["bathhouses"] = "bath house", ["bath houses"] = "bath house", ["clan"] = "clan hall", ["clans"] = "clan hall", ["clanhall"] = "clan hall", ["clanhalls"] = "clan hall", ["clan halls"] = "clan hall", ["explorer"] = "explorers' lodge", ["explorers"] = "explorers' lodge", ["explorerlodge"] = "explorers' lodge", ["explorerslodge"] = "explorers' lodge", ["explorerlodges"] = "explorers' lodge", ["explorerslodges"] = "explorers' lodge", ["explorers'lodges"] = "explorers' lodge", ["explorer'slodges"] = "explorers' lodge", ["explorer lodge"] = "explorers' lodge", ["explorers lodge"] = "explorers' lodge", ["explorer lodges"] = "explorers' lodge", ["explorers lodges"] = "explorers' lodge", ["explorer's lodges"] = "explorers' lodge", ["guild"] = "guild house", ["guilds"] = "guild house", ["guildhouse"] = "guild house", ["guildhouses"] = "guild house", ["guild houses"] = "guild house", ["monestary"] = "monastery", ["monastary"] = "monastery", ["monestery"] = "monastery", ["monestaries"] = "monastery", ["monastaries"] = "monastery", ["monesteries"] = "monastery", ["taverns"] = "tavern", ["temples"] = "temple" } -- the end of the huge tBuildingSimilarities -- If nothing is found, the result of the lookup will be nil, so just -- return whatever was passed in as the argument (now lowercase). we can -- assume that the input argument is fine and another function will worry -- about whether it's valid. return tBuildingSimilarities[buildingName] or buildingName end ------------------------------------------------------------------------------- -- Normalizes a resource name for use as the key in other lookup tables. -- -- This function at least makes the argument lowercase, since keys are -- lowercase to reduce the number of similarities to normalize. -- @param resourceName the in-game name -- @return a normalized name for use as a key function Utility.normalizeResourceName(resourceName) -- no matter what, we want to return the lowercase version resourceName = string.lower(resourceName) -- No other functions should have this lookup table, so it's defined -- locally to this function. The keys are the possible ways the name could -- be written. The values are the normalized string that are used as keys. local tResourceSimilarities = { -- Raw Food ["berry"] = "berries", ["egg"] = "eggs", ["insect"] = "insects", ["meats"] = "meat", ["mushroom"] = "mushrooms", ["root"] = "roots", ["vegetable"] = "vegetables", --Complex Food ["biscuit"] = "biscuits", ["pickledgoods"] = "pickled goods", ["pickledgood"] = "pickled goods", ["pickled good"] = "pickled goods", ["pies"] = "pie", ["skewer"] = "skewers", -- Building Materials ["brick"] = "bricks", ["fabrics"] = "fabric", ["pipe"] = "pipes", ["plank"] = "planks", ["part"] = "parts", ["wildfireessence"] = "wildfire essence", ["wild fire essence"] = "wildfire essence", ["wildfireessences"] = "wildfire essence", ["wild fire essences"] = "wildfire essence", -- Consumable items ["coat"] = "coats", ["ales"] = "ale", ["cosmetic"] = "cosmetics", ["incenses"] = "incense", ["insense"] = "incense", ["scroll"] = "scrolls", ["traininggear"] = "training gear", ["traininggears"] = "training gear", ["training gears"] = "training gear", ["wines"] = "wine", -- Crafting materials ["clays"] = "clay", ["copperore"] = "copper ore", ["copperores"] = "copper ore", ["copper ores"] = "copper ore", ["crystalizeddew"] = "crystalized dew", ["crystalizeddews"] = "crystalized dew", ["crystallizeddew"] = "crystalized dew", ["crystallizeddews"] = "crystalized dew", ["crystalized dews"] = "crystalized dew", ["crystallized dew"] = "crystalized dew", ["crystallized dews"] = "crystalized dew", ["grains"] = "grain", ["herb"] = "herbs", ["leathers"] = "leather", ["flax"] = "plant fiber", ["plantfiber"] = "plant fiber", ["plantfibers"] = "plant fiber", ["plant fibers"] = "plant fiber", ["reed"] = "reeds", ["stones"] = "stone", -- Refined crafting materials ["barrel"] = "barrels", ["barrell"] = "barrels", ["barrells"] = "barrels", ["copperbar"] = "copper bars", ["copperbars"] = "copper bars", ["copper bar"] = "copper bars", ["flours"] = "flour", ["pigments"] = "pigment", ["waterskin"] = "waterskins", ["water skin"] = "waterskins", ["water skins"] = "waterskins", -- Trade goods ["ambers"] = "amber", ["coin"] = "amber", ["tablet"] = "ancient tablet", ["tablets"] = "ancient tablet", ["ancienttablet"] = "ancient tablet", ["ancienttablets"] = "ancient tablet", ["ancient tablets"] = "ancient tablet", ["buildingmaterial"] = "pack of building materials", ["buildingmaterials"] = "pack of building materials", ["building material"] = "pack of building materials", ["building materials"] = "pack of building materials", ["packofbuildingmaterial"] = "pack of building materials", ["packofbuildingmaterials"] = "pack of building materials", ["pack of building materials"] = "pack of building materials", ["packsofbuildingmaterial"] = "pack of building materials", ["packsofbuildingmaterials"] = "pack of building materials", ["packs of building materials"] = "pack of building materials", ["crop"] = "pack of crops", ["crops"] = "pack of crops", ["packofcrop"] = "pack of crops", ["packofcrops"] = "pack of crops", ["pack of crop"] = "pack of crops", ["packsofcrop"] = "pack of crops", ["packsofcrops"] = "pack of crops", ["packs of crop"] = "pack of crops", ["luxury"] = "pack of luxury goods", ["luxuries"] = "pack of luxury goods", ["luxurygood"] = "pack of luxury goods", ["luxurygoods"] = "pack of luxury goods", ["luxury good"] = "pack of luxury goods", ["luxury goods"] = "pack of luxury goods", ["packofluxuries"] = "pack of luxury goods", ["packofluxurygood"] = "pack of luxury goods", ["packofluxurygoods"] = "pack of luxury goods", ["pack of luxury good"] = "pack of luxury goods", ["packsofluxuries"] = "pack of luxury goods", ["packsofluxurygood"] = "pack of luxury goods", ["packsofluxurygoods"] = "pack of luxury goods", ["packs of luxury good"] = "pack of luxury goods", ["provision"] = "pack of provisions", ["provisions"] = "pack of provisions", ["packofprovision"] = "pack of provisions", ["packofprovisions"] = "pack of provisions", ["pack of provision"] = "pack of provisions", ["packsofprovision"] = "pack of provisions", ["packsofprovisions"] = "pack of provisions", ["packs of provision"] = "pack of provisions", ["tradegood"] = "pack of trade goods", ["tradegoods"] = "pack of trade goods", ["trade good"] = "pack of trade goods", ["trade goods"] = "pack of trade goods", ["packoftradegood"] = "pack of trade goods", ["packoftradegoods"] = "pack of trade goods", ["pack of trade good"] = "pack of trade goods", ["packsoftradegood"] = "pack of trade goods", ["packsoftradegoods"] = "pack of trade goods", ["packs of trade good"] = "pack of trade goods", -- Meta resources ["artifact"] = "artifacts", ["metaartifact"] = "artifacts", ["metaartifacts"] = "artifacts", ["meta artifact"] = "artifacts", ["meta artifacts"] = "artifacts", ["food"] = "food stockpiles", ["foods"] = "food stockpiles", ["metafood"] = "food stockpiles", ["metafoods"] = "food stockpiles", ["meta food"] = "food stockpiles", ["meta foods"] = "food stockpiles", ["foodstockpile"] = "food stockpiles", ["foodstockpiles"] = "food stockpiles", ["food stockpile"] = "food stockpiles", ["meta foodstockpile"] = "food stockpiles", ["meta foodstockpiles"] = "food stockpiles", ["meta food stockpile"] = "food stockpiles", ["meta food stockpiles"] = "food stockpiles", ["machinary"] = "machinery", ["metamachinery"] = "machinery", ["meta machinery"] = "machinery", -- Fuel & Exploration ["coals"] = "coal", ["oils"] = "oil", ["seamarrow"] = "sea marrow", ["seamarrows"] = "sea marrow", ["sea marrows"] = "sea marrow", ["woods"] = "wood", ["simpletool"] = "simple tools", ["simpletools"] = "simple tools", ["simple tool"] = "simple tools", ["infusedtool"] = "infused tools", ["infusedtools"] = "infused tools", ["infused tool"] = "infused tools", ["purgingfire"] = "purging fire", ["purgingfires"] = "purging fire", -- Rain ["clearancewater"] = "clearance water", ["clearencewater"] = "clearance water", ["clearence water"] = "clearance water", ["drizzlewater"] = "drizzle water", ["stormwater"] = "storm water" } -- the end of the huge tResourceSimilarities -- If nothing is found, the result of the lookup will be nil, so just -- return whatever was passed in as the argument (now lowercase). we can -- assume that the input argument is fine and another function will worry -- about whether it's valid. return tResourceSimilarities[resourceName] or resourceName end -- return this class when required into another module. return Utility