#!/usr/bin/env python3 def write_animation(out, aa, name): c = [0, 0] for a in aa: count_animations(out, name, a, c) if c[1] > 1: out.write("%d (%d)" % (c[0], c[1])) else: out.write("%d" % c[0]) def count_animations(out, name, a, c): frames = a.get_all(tag = "frame") if frames: c[0] += len(frames) c[1] += 1 for a2 in a.get_all(tag = "animation"): count_animations(out, name, a2, c) for a2 in a.get_all(tag = "if"): count_animations(out, name, a2, c) for a2 in a.get_all(tag = "else"): count_animations(out, name, a2, c) def write_table_row(out, unit, color, name = None): # See the list at the beginning of src/unit_animation.cpp anim_types = [ "attack_anim", "defend", "death", "idle_anim", "movement_anim", "leading_anim", "teleport_anim", "standing_anim", "healing_anim", "victory_anim", "poison_anim", "healed_anim", "recruit_anim", "levelin_anim", "levelout_anim", "extra_anim", "animation", "resistance_anim", "recruiting_anim", "pre_movement_anim", "post_movement_anim", "draw_weapon_anim", "sheath_weapon_anim" ] needed = {} for at in anim_types: needed[at] = True needed["healing_anim"] = False needed["leading_anim"] = False needed["teleport"] = False for abil in unit.get_all(tag = "abilities"): if abil.get_all(tag = "heals"): needed["healing_anim"] = True if abil.get_all(tag = "leadership"): needed["leading_anim"] = True if abil.get_all(tag = "teleport"): needed["teleport"] = True if name is None: name = unit.id out.write("%s" % (color and "c1" or "c2", name)) for t in anim_types: if needed[t]: aa = unit.get_all(tag = t) if t == "extra_anim": out.write("") else: out.write("" % (aa and "ok" or "not")) write_animation(out, aa, t) out.write("") else: out.write("-") out.write("\n") female = unit.get_all(tag = "female") if female: write_table_row(out, female[0], color, name + "[f]") for variation in unit.get_all(tag = "variation"): write_table_row(out, variation, color, name + "[%s]" % variation.get_text_val("variation_name")) def put_units(f, us): f.write("\n") f.write("\n") f.write(""" """.lstrip()) f.write("\n") def by_race(u): return u.rid + u.id us.sort(key = by_race) race = None color = 0 for u in us: if u.race != race: race = u.race color ^= 1 write_table_row(f, u, color) f.write("
id attack defend death idle movement leading teleport standing healing victory poison healed recruit level in level out extra animation resistance recruiting pre movement post movement draw weapon sheath weapon
\n") def write_table(f, wesnoth): f.write(""" """.lstrip()) f.write("

animation statistics

\n") f.write("total frames (number of animations)\n") f.write("

Mainline

\n") us = [x for x in list(wesnoth.unit_lookup.values()) if x.campaigns[0] == "mainline"] put_units(f, us) #f.write("

Campaigns and Addons

\n") #us = [x for x in wesnoth.unit_lookup.values() if x.campaigns[0] != "mainline"] #put_units(f, us) f.write("") f.close()