| Version 2 (modified by quantumstate, 21 months ago) (diff) |
|---|
Unit Summary Page Generator
This script will generate the content for the Unit Summary Table page.
from pyquery import PyQuery as pq
basePath = "C:/Users/Jonathan/0ad/binaries/data/mods/public/simulation/templates/"
def loadData(fileName, basePath, general, cost, attackRanged, attackMelee, armour):
d = pq(filename=basePath + fileName)
if d("Entity").attr("parent") != None:
unitInfo = loadData(d("Entity").attr("parent")+".xml", basePath, general, cost, attackRanged, attackMelee, armour)
else:
unitInfo = {'general':{}, 'cost':[0,0,0,0], 'attackRanged':[0,0,0,0], 'attackMelee':[0,0,0], 'armour':[0,0,0]}
for attr in general:
if d(attr).text() != None:
unitInfo['general'][attr] = d(attr).text()
for i in range(len(cost)):
if d(cost[i]).text() != None:
unitInfo['cost'][i] = float(d(cost[i]).text())
for i in range(len(armour)):
if d(armour[i]).text() != None:
unitInfo['armour'][i] = float(d(armour[i]).text())
for i in range(len(attackRanged)):
if d(attackRanged[i]).text() != None:
unitInfo['attackRanged'][i] = float(d(attackRanged[i]).text())
for i in range(len(attackMelee)):
if d(attackMelee[i]).text() != None:
unitInfo['attackMelee'][i] = float(d(attackMelee[i]).text())
return unitInfo
def printUnit(fileName, basePath):
general = ["GenericName", "SpecificName", "Vision > Range", "Health > Max", "WalkSpeed"]
cost = ["Cost > * > food", "Cost > * > wood", "Cost > * > metal", "Cost > * > stone"]
attackRanged = ["Attack > Ranged > Pierce", "Attack > Ranged > Hack", "Attack > Ranged > Crush", "Attack > Ranged > MaxRange"]
attackMelee = ["Attack > Melee > Pierce", "Attack > Melee > Hack", "Attack > Melee > Crush"]
armour = ["Armour > Pierce", "Armour > Hack", "Armour > Crush"]
generalTitles = ["Unit", "Specific Name", "Line of Sight", "Health"]
costTitles = ["F", "W", "G", "S"]
aTitles = ["P", "H", "C"]
unitStuff = loadData(fileName, basePath, general, cost, attackRanged, attackMelee, armour)
outString = "|| "
for t in general:
if t in unitStuff["general"]:
outString += unitStuff["general"][t] + " || "
else:
outString += " || "
for i in range(4):
if unitStuff["cost"][i] != 0:
outString += costTitles[i] + "{0:g} ".format(unitStuff["cost"][i])
outString += "|| "
if sum(unitStuff["attackRanged"]) > 0:
for i in range(3):
if unitStuff["attackRanged"][i] != 0:
outString += aTitles[i] + "{0:g} ".format(unitStuff["attackRanged"][i])
outString += "(Range {0:g}) ".format(unitStuff["attackRanged"][3])
if sum(unitStuff["attackMelee"]) > 0:
for i in range(3):
if unitStuff["attackMelee"][i] != 0:
outString += aTitles[i] + "{0:g} ".format(unitStuff["attackMelee"][i])
outString += "(Melee) "
outString += "|| "
for i in range(3):
if unitStuff["armour"][i] != 0:
outString += aTitles[i] + "{0:g} ".format(unitStuff["armour"][i])
outString += "||"
return outString
header = "||'''Common Name'''||'''Specific Name'''||'''Line of Sight'''||'''Health'''||'''Speed'''||'''Cost'''||'''Attack'''||'''Armour'''||\n"
f = open('unit_summary_table', 'w')
f.write("= Unit Summary Table =\n\nA more detailed description of the units is avail on the [wiki:Manual_Units units page].\n\nThe following abbreviations are used in this page\n\n F = [wiki:Manual_Terminology#Food food], W = [wiki:Manual_Terminology#Wood wood], M = [wiki:Manual_Terminology#Metal metal], S = stone, H = Hack, P = Pierce, C = Crush\n\n")
f.write("== Hellene Units ==\n")
f.write(header)
f.write(printUnit("units/hele_support_female_citizen.xml", basePath).encode("utf-8")+"\n")
f.write(printUnit("units/hele_infantry_spearman_a.xml", basePath).encode("utf-8")+"\n")
f.write(printUnit("units/hele_infantry_javelinist_a.xml", basePath).encode("utf-8")+"\n")
f.write(printUnit("units/hele_infantry_archer_a.xml", basePath).encode("utf-8")+"\n")
f.write(printUnit("units/hele_cavalry_swordsman_a.xml", basePath).encode("utf-8")+"\n")
f.write(printUnit("units/hele_cavalry_javelinist_a.xml", basePath).encode("utf-8")+"\n")
f.write(printUnit("units/hele_champion_infantry_mace.xml", basePath).encode("utf-8")+"\n")
f.write(printUnit("units/hele_champion_infantry_polis.xml", basePath).encode("utf-8")+"\n")
f.write(printUnit("units/hele_champion_ranged_polis.xml", basePath).encode("utf-8")+"\n")
f.write(printUnit("units/hele_champion_cavalry_mace.xml", basePath).encode("utf-8")+"\n")
f.write(printUnit("units/hele_mechanical_siege_lithobolos.xml", basePath).encode("utf-8")+"\n")
f.write(printUnit("units/hele_mechanical_siege_oxybeles.xml", basePath).encode("utf-8")+"\n")
f.write(printUnit("units/hele_mechanical_siege_tower.xml", basePath).encode("utf-8")+"\n")
f.write(printUnit("units/hele_ship_fishing.xml", basePath).encode("utf-8")+"\n")
f.write(printUnit("units/hele_ship_merchant.xml", basePath).encode("utf-8")+"\n")
f.write(printUnit("units/hele_ship_bireme.xml", basePath).encode("utf-8")+"\n")
f.write(printUnit("units/hele_ship_trireme.xml", basePath).encode("utf-8")+"\n")
f.write("\n== Carthaginian Units =="+"\n")
f.write(header)
f.write(printUnit("units/cart_support_female_citizen.xml", basePath).encode("utf-8")+"\n")
f.write(printUnit("units/cart_infantry_spearman_a.xml", basePath).encode("utf-8")+"\n")
f.write(printUnit("units/cart_infantry_swordsman_a.xml", basePath).encode("utf-8")+"\n")
f.write(printUnit("units/cart_infantry_javelinist_a.xml", basePath).encode("utf-8")+"\n")
f.write(printUnit("units/cart_infantry_archer_a.xml", basePath).encode("utf-8")+"\n")
f.write(printUnit("units/cart_infantry_slinger_a.xml", basePath).encode("utf-8")+"\n")
f.write(printUnit("units/cart_cavalry_swordsman_a.xml", basePath).encode("utf-8")+"\n")
f.write(printUnit("units/cart_cavalry_spearman_a.xml", basePath).encode("utf-8")+"\n")
f.write(printUnit("units/cart_cavalry_javelinist_a.xml", basePath).encode("utf-8")+"\n")
f.write(printUnit("units/cart_champion_infantry.xml", basePath).encode("utf-8")+"\n")
f.write(printUnit("units/cart_champion_cavalry.xml", basePath).encode("utf-8")+"\n")
f.write(printUnit("units/cart_ship_fishing.xml", basePath).encode("utf-8")+"\n")
f.write(printUnit("units/cart_ship_merchant.xml", basePath).encode("utf-8")+"\n")
f.write(printUnit("units/cart_ship_bireme.xml", basePath).encode("utf-8")+"\n")
f.write(printUnit("units/cart_ship_trireme.xml", basePath).encode("utf-8")+"\n")
f.write(printUnit("units/cart_ship_quinquereme.xml", basePath).encode("utf-8")+"\n")
f.write("\n== Celtic Units =="+"\n")
f.write(header)
f.write(printUnit("units/celt_support_female_citizen.xml", basePath).encode("utf-8")+"\n")
f.write(printUnit("units/celt_infantry_spearman_a.xml", basePath).encode("utf-8")+"\n")
f.write(printUnit("units/celt_infantry_javelinist_a.xml", basePath).encode("utf-8")+"\n")
f.write(printUnit("units/celt_cavalry_swordsman_a.xml", basePath).encode("utf-8")+"\n")
f.write(printUnit("units/celt_cavalry_spearman_a.xml", basePath).encode("utf-8")+"\n")
f.write(printUnit("units/celt_cavalry_javelinist_a.xml", basePath).encode("utf-8")+"\n")
f.write(printUnit("units/celt_champion_infantry_brit.xml", basePath).encode("utf-8")+"\n")
f.write(printUnit("units/celt_champion_infantry_gaul.xml", basePath).encode("utf-8")+"\n")
f.write(printUnit("units/celt_champion_cavalry_brit.xml", basePath).encode("utf-8")+"\n")
f.write(printUnit("units/celt_champion_cavalry_gaul.xml", basePath).encode("utf-8")+"\n")
f.write(printUnit("units/celt_mechanical_siege_ram.xml", basePath).encode("utf-8")+"\n")
f.write(printUnit("units/celt_ship_fishing.xml", basePath).encode("utf-8")+"\n")
f.write(printUnit("units/celt_ship_merchant.xml", basePath).encode("utf-8")+"\n")
f.write(printUnit("units/celt_ship_trireme.xml", basePath).encode("utf-8")+"\n")
f.write("\n== Iberian Units =="+"\n")
f.write(header)
f.write(printUnit("units/iber_support_female_citizen.xml", basePath).encode("utf-8")+"\n")
f.write(printUnit("units/iber_infantry_spearman_a.xml", basePath).encode("utf-8")+"\n")
f.write(printUnit("units/iber_infantry_swordsman_a.xml", basePath).encode("utf-8")+"\n")
f.write(printUnit("units/iber_infantry_javelinist_a.xml", basePath).encode("utf-8")+"\n")
f.write(printUnit("units/iber_infantry_slinger_a.xml", basePath).encode("utf-8")+"\n")
f.write(printUnit("units/iber_cavalry_spearman_a.xml", basePath).encode("utf-8")+"\n")
f.write(printUnit("units/iber_champion_infantry.xml", basePath).encode("utf-8")+"\n")
f.write(printUnit("units/iber_champion_cavalry.xml", basePath).encode("utf-8")+"\n")
f.write(printUnit("units/iber_mechanical_siege_ram.xml", basePath).encode("utf-8")+"\n")
f.write(printUnit("units/iber_ship_fishing.xml", basePath).encode("utf-8")+"\n")
f.write(printUnit("units/iber_ship_merchant.xml", basePath).encode("utf-8")+"\n")
f.write("\n\nThis page was generated using this [wiki:Unit_Summary_Table_Generator unit summary table generator script]."+"\n")
