Talk:Random cooking effects

From Caves of Qud Wiki
Jump to navigation Jump to search

Code for processing weights

Made a little script to make the weights and tables automatically:

import xml.etree.ElementTree as ET

data_dir = "../shortcuts/data/StreamingAssets/Base/"
tree = ET.parse(data_dir + "ObjectBlueprints/Data.xml")
objects = tree.getroot()

cooking_objects = {
    obj.attrib['Name'][len('ProceduralCookingIngredient_'):]: obj 
    for obj in objects if obj.attrib['Inherits'] == 'IngredientMapping'}

data = dict()
for name, obj in cooking_objects.items():
    normalTag = obj.find('tag[@Name="RandomWeight"]')
    highTierTag = obj.find('tag[@Name="RandomHighTierWeight"]')
    
    normalWeight = 0 if normalTag == None else int(normalTag.attrib['Value'])
    highTierWeight = 0 if highTierTag == None else int(highTierTag.attrib['Value'])
    
    data[name] = {'RandomWeight': normalWeight, 'RandomHighTierWeight': highTierWeight}

print("=Random=")
print("==Unused Effects==")

unpickedNormal = dict(filter(lambda effect: effect[1]['RandomWeight'] == 0, data.items()))

for effect in unpickedNormal:
    print("* {{CookEffect ID to page|" + effect + "}}")

print("==Weight Table==")

pickedNormal = dict(filter(lambda effect: effect[1]['RandomWeight'] != 0, data.items()))

print("{{Cooking Random Weights")

for effect, weight in pickedNormal.items():
    print("|{{Cooking Random Weights/Row|cookeffect={{CookEffect ID to page|" + effect + "}}|weight=" + str(weight['RandomWeight']) + "}}")

print("}}")

print("=High-Tier Random=")
print("==Unused Effects==")

unpickedNormal = dict(filter(lambda effect: effect[1]['RandomHighTierWeight'] == 0, data.items()))

for effect in unpickedNormal:
    print("* {{CookEffect ID to page|" + effect + "}}")

print("==Weight Table==")

pickedNormal = dict(filter(lambda effect: effect[1]['RandomHighTierWeight'] != 0, data.items()))

print("{{Cooking Random Weights")

for effect, weight in pickedNormal.items():
    print("|{{Cooking Random Weights/Row|cookeffect={{CookEffect ID to page|" + effect + "}}|weight=" + str(weight['RandomHighTierWeight']) + "}}")

print("}}")

Librarianmage (talk) 14:09, 21 May 2023 (UTC)