def main(cursor): evolution_dict = evolution_q.get_all_evolutions(cursor) output = [] output_dict = {} for i in range(0,5): output_dict[i] = [] for d, the_evolution in evolution_dict.items(): if the_evolution.category == 3: continue if the_evolution.name == "VOID": continue # self.add_field("cost_per_level", "int") # self.add_field("max_level", "int") # self.add_field("min_level", "int") # self.add_field("category", "int") # self.add_field("physical_change", "double") # self.add_field("combat_relevant", "bool") # self.add_field("description", "blob") output_dict[the_evolution.category].append("""<strong><a class="clear_link" id="%(js_name)s" href="#%(js_name)s">%(evo_name)s</a></strong> Max level: %(max_level)s Min level: %(min_level)s Cost: %(cost)s <br /> %(description)s <br /><br />""" % { "js_name": common.js_name(the_evolution.name), "evo_name": the_evolution.name, "max_level": the_evolution.max_level, "min_level": the_evolution.min_level, "cost": the_evolution.cost_per_level, "description": the_evolution.description, }) for i in range(0,5): if output_dict[i] != []: output.append("""<h3><a id="%s" href="#%s">%s</a></h3>""" % ( common.js_name(evolution.categories[i]), common.js_name(evolution.categories[i]), evolution.categories[i], )) output.append("".join(output_dict[i])) return "".join(output)
def evolution_option_list(cursor, remove_list=[], default=0): """docstring for evolution_option_list""" output = [] evolution_dict = evolution_q.get_all_evolutions(cursor) for evo_id, the_evo in evolution_dict.items(): if evo_id in remove_list: continue if evo_id == default: output.append("<option value='%s' selected='selected'>%s</option>" % (evo_id, the_evo.name)) else: output.append("<option value='%s'>%s</option>" % (evo_id, the_evo.name)) return "".join(output)
def evolutions(cursor): output = {} evolution_dict = evolution_q.get_all_evolutions(cursor) for e, the_evo in evolution_dict.items(): if the_evo.name == "VOID": continue output[e] = { "evolution_id": e, "name": the_evo.name, "cost_per_level": the_evo.cost_per_level, "max_level": the_evo.max_level, "min_level": the_evo.min_level, "description": the_evo.description, "category": evolution.categories[the_evo.category], } return json.dumps(output)
def main(cursor, battle_id=-1): battle_id = int(common.get_val('battle', battle_id)) ships = int(common.get_val('ships', True)) if battle_id < 1: return "No battle selected" the_battle = battle_q.get_one_battle(cursor, battle_id) # Get some other stuff team_dict = team_q.get_all_teams(cursor) the_campaign = campaign_q.get_one_campaign(cursor, the_battle.campaign) output = [""" <div style='padding: 5px;'> <a href="web.py?mode=list_campaigns&turn={turn}" class="block_link" style="display:inline; text-align:left;">Campaigns of this turn</a> <a href="web.py?mode=setup_campaign&campaign={c.id}" class="block_link" style="display:inline;">Setup campaign</a> <a href="web.py?mode=list_battles&campaign={c.id}" class="block_link" style="display:inline;">List battles</a> <a href="web.py?mode=setup_battle&battle={b.id}" class="block_link" style="display:inline;">Setup battle</a> <a href="web.py?mode=perform_battle&battle={b.id}" class="block_link" style="display:inline;">By unit</a> <br /><br /> <span class="stitle">{c.name} - {b.name}</span> - <a href="web.py?mode=perform_battle&battle={b.id}&ships=0">No ships</a> <br /> <a href="#" onclick="$('.show_evo_wedge').show(); $('.evo_wedge').hide(); return false;">Hide evo wedges</a> - <a href="#" onclick="$('.show_evo_wedge').hide(); $('.evo_wedge').show(); return false;">Show evo wedges</a> """.format( c = the_campaign, b = the_battle, turn = common.current_turn(), )] # Now for some stuff about the participants #------------------------ the_campaign.get_sides_basic(cursor) the_campaign.get_armies_basic(cursor) the_battle.get_losses(cursor) the_battle.get_squads(cursor) team_list = [] for s in range(1, the_campaign.sides+1): for t in the_campaign.sides_basic[s]: team_list.append(t) unit_dict = unit_q.get_units_from_team_list(cursor, team_list, special_units=True) evolution_dict = evolution_q.get_all_evolutions(cursor) # Sort squads by team # Doing this makes it O(2n) rather than O(t*n) army_dict = army_q.get_armies_from_list(cursor, the_battle.armies) squad_dict = squad_q.get_all_squads(cursor) squad_q.mass_get_squads(cursor, army_dict) armies_by_team = {} for army_id, the_army in army_dict.items(): if the_army.team not in armies_by_team: armies_by_team[the_army.team] = [] armies_by_team[the_army.team].append(army_id) for s in range(1, the_campaign.sides+1): teams_on_side = the_campaign.sides_basic[s] if len(teams_on_side) > 0: output.append('''<table border="1" cellspacing="0" cellpadding="5" width="100%"> <tr> <td class="stitle" colspan="2">{s}</td> </tr>'''.format(s=s)) for i, team_id in enumerate(teams_on_side): if team_id not in armies_by_team: armies_by_team[team_id] = [] # Table tags for team cell if i % 2 == 0: output.append('<tr><td>') else: output.append('<td>') the_team = team_dict[team_id] # Team header output.append(''' <span class="stitle">{name}</span> - <a href="web.py?mode=list_units&team={id}">Military</a> - <a href="web.py?mode=list_armies&team={id}">Armies</a> - <a href="#" onclick="$(this).parent().hide(); return false;">Hide</a> '''.format( name=the_team.name, id=team_id, )) # Armies for army_id in armies_by_team[team_id]: the_army = army_dict[army_id] army_output = draw_army(the_battle, squad_dict, unit_dict, the_army) if army_output != None: output.append(army_output) output.append("<tr><td colspan='1'> </td></tr>") # Evos row evo_output = [] the_team.get_evolutions(cursor) for evolution_id in the_team.evolutions: the_evo = evolution_dict[evolution_id] if the_team.evolutions[evolution_id] == 0: continue if not the_evo.combat_relevant: continue if the_evo.max_level == 1 and the_team.evolutions[evolution_id] == 1: evo_output.append("""<strong>%(evo_name)s</strong><br />""" % { "evo_name": the_evo.name, }) else: evo_output.append("""<strong>%(level)sx %(evo_name)s</strong><br />""" % { "level": the_team.evolutions[evolution_id], "evo_name": the_evo.name, }) count = 0 output.append(""" <tr class="row%(count)s"> <td colspan="11" style="padding:0px;"> <div id="show_evos_%(team_id)s" style="display:nnone;" class="show_evo_wedge"> <a href="#" class="block_link" onclick="$('#show_evos_%(team_id)s').hide(); $('#evos_%(team_id)s').fadeIn(250);return false;">Evos</a> </div> <div id="evos_%(team_id)s" style="display:none;" class="evo_wedge"> <a href="#" class="block_link" onclick="$('#show_evos_%(team_id)s').fadeIn(250); $('#evos_%(team_id)s').hide(); return false;">Hide</a><br /> %(evo_output)s </div> </td> </tr> """ % { "count": count%2, "team_id": team_id, "evo_output": "".join(evo_output) }) # End of team units output.append("</table>") # Table tags for team cell if i % 2 == 0: output.append('</td>') else: output.append('</td></tr>') # Not sure that we need to adhere to W3C specs for tables... # if i % 2 == 0: output.append('<td> </td></tr>') output.append("</table><br />") else: output.append('No teams on side {s}'.format(s=s)) # Field for the ids of the armies listed that we need to sort out # output.append('</table><br />') output.append("</div>") page_data['Title'] = "Perform by army - %s" % the_battle.name return "".join(output)
def main(cursor): # Get team Id team_id = int(common.get_val('team', 0)) if team_id < 1: return "No team selected" # Build team item the_team = team_q.get_one_team(cursor, team_id) # Get some properties the_team.get_population(cursor) # Lists trait_dict = trait_q.get_all_traits(cursor) deity_dict = deity_q.get_all_deities(cursor) evolution_dict = evolution_q.get_all_evolutions(cursor) # Is the join turn set? if the_team.join_turn == 0: the_team.join_turn = common.current_turn() # First row of check_boxes output = ["<div style='padding: 5px;'>"] output.append(""" <span class="stitle">%(name)s</span> Population: %(team_population)s <br /><br /> <form action="exec.py" method="post" accept-charset="utf-8"> <input type="hidden" name="mode" id="mode" value="edit_team_commit" /> <input type="hidden" name="id" id="id" value="%(team_id)d" /> <input type="hidden" name="requestTime" id="requestTime" value="' . $the_team->requestTime . '" /> <label for="active">Active:</label> %(active_check_box)s <label for="ir">IR:</label> %(ir_check_box)s <label for="hidden">Hidden:</label> %(hidden_check_box)s <label for="not_a_team">Not a team:</label> %(not_a_team_check_box)s <label for="dead">Dead:</label> %(dead_check_box)s <label for="not_in_queue">Not in queue:</label> %(not_in_queue_check_box)s <br /> """ % { 'team_id': team_id, 'name': the_team.name, 'team_population': common.number_format(the_team.population), 'active_check_box': common.check_box('active', the_team.active), 'ir_check_box': common.check_box('ir', the_team.ir), 'hidden_check_box': common.check_box('hidden', the_team.hidden), 'not_a_team_check_box': common.check_box('not_a_team', the_team.not_a_team), 'dead_check_box': common.check_box('dead', the_team.dead), 'not_in_queue_check_box': common.check_box('not_in_queue', the_team.not_in_queue), }) # Row 1 output.append(""" <table border="0" cellspacing="5" cellpadding="5" style="width:100%%;"> <tr> <td><label for="forum_url_id">Forum URL id:</label></td> <td>%(forum_text_box)s</td> <td width="5"> </td> <td><label for="orders_topic">Orders topic:</label></td> <td>%(orders_text_box)s</td> <td width="5"> </td> <td><label for="intorders_topic">Int Orders topic:</label></td> <td>%(intorders_text_box)s</td> </tr>""" % {'forum_text_box': common.text_box('forum_url_id', the_team.forum_url_id, warn_on = lambda x:(True if x < 0 else False)), 'orders_text_box': common.text_box('orders_topic', the_team.orders_topic, warn_on = lambda x:(True if x < 0 else False)), 'intorders_text_box': common.text_box('intorders_topic', the_team.intorders_topic, warn_on = lambda x:(True if x < 0 else False)), }) # Row 2 output.append(""" <tr> <td><label for="results_topic">Results topic:</label></td> <td>{results_topic}</td> <td width="5"> </td> <td><label for="teaminfo_topic">Team info topic:</label></td> <td>{teaminfo_topic}</td> <td width="5"> </td> <td><label for="team_info_first_post">Team info first post:</label></td> <td>{team_info_first_post}</td> </tr>""".format( results_topic = common.text_box('results_topic', the_team.results_topic, warn_on = lambda x:(True if x < 0 else False)), teaminfo_topic = common.text_box('teaminfo_topic', the_team.teaminfo_topic, warn_on = lambda x:(True if x < 0 else False)), team_info_first_post = common.text_box('team_info_first_post', the_team.team_info_first_post, warn_on = lambda x:(True if x < 0 else False)), )) # Row 3 output.append(""" <tr> <td><label for="request_topic">Request topic:</label></td> <td>%(request_topic)s</td> <td width="5"> </td> <td><label for="leader_id">Leader:</label></td> <td>%(leader_id)s</td> <td width="5"> </td> <td>Culture topic:</td> <td>%(culture_topic)s</td> </tr>""" % {'leader_id': common.text_box('leader_id', the_team.leader_id, warn_on = lambda x:(True if x < 1 else False)), 'request_topic': common.text_box('request_topic', the_team.request_topic, warn_on = lambda x:(True if x < 1 else False)), 'culture_topic': common.text_box('culture_topic', the_team.culture_topic, warn_on = lambda x:(True if x < 1 else False)), }) output.append(""" <tr> <td><label for="default_borders">Default borders:</label></td> <td>%(default_borders)s</td> <td width="5"> </td> <td><label for="default_taxes">Default taxes:</label></td> <td>%(default_taxes)s</td> <td width="5"> </td> <td><label for="evo_points">Evo points:</label></td> <td>%(evo_points)s</td> </tr> <tr> <td colspan="8" style="padding:0px;border-bottom:3px #EEE double;"></td> </tr> """ % { "default_borders": common.option_box("default_borders", elements=team.border_states, selected=team.border_states[the_team.default_borders]), "default_taxes": common.text_box('default_taxes', the_team.default_taxes, warn_on = lambda x:(True if int(x) < 0 else False), size=4), "evo_points": common.text_box('evo_points', the_team.evo_points, warn_on = lambda x:(True if int(x) < 0 else False)), }) output.append(""" <!-- <tr> <td>Previous resources:</td> <td>%(previous_resources)s</td> </tr> --> """ % { "previous_resources": the_team.previous_resources, }) # End row output.append(""" <tr> <td>Join turn:</td> <td>%(join_turn)s</td> <td width="5"> </td> <td>Primary:</td> <td>%(primary_colour)s</td> <td width="5"> </td> <td>Secondary:</td> <td>%(secondary_colour)s</td> </tr> </table> <br /> <input type="submit" value="Perform edit" /> <input style="float:right; margin-right:100px;" type="button" value="Purge team" onclick="setTimeout('document.location=\\'web.py?mode=purge_team&team=%(team_id)s\\'', 0);"/> <a class="block_link" href="web.py?mode=ti&post_output=1&team=%(team_id)s">Update my TI</a> <br />""" % { "team_id": team_id, 'join_turn': common.text_box('join_turn', the_team.join_turn), 'previous_resources': common.text_box('previous_resources', the_team.previous_resources, size=56), "primary_colour": common.text_box('primary_colour', the_team.primary_colour), "secondary_colour": common.text_box('secondary_colour', the_team.secondary_colour), }) # Resources #------------------------ the_team.get_resources(cursor) output.append(""" <table style="float:left; margin-right: 25px;" border="0" cellspacing="0" cellpadding="5"> <tr class="row2"> <th>Resource</th> <th>Amount</th> </tr> """) counter = -1 for res_id, the_res in resource_list.data_dict.items(): if the_res.category == resource_list.category['Map terrain feature']: continue # If it's not set then we need to give it a default if not res_id in the_team.resources.value: the_team.resources.value[res_id] = 0 counter += 1 output.append(""" <tr class="row%(row)d"> <td><label for="res_%(res_name)s">%(res_name)s</label></td> <td style="padding:1px;">%(res_amount)s</td> </tr>""" % {'row': (counter % 2), 'res_name': the_res.name, 'res_amount': resource_f.print_form_element(res_id, the_team.resources[res_id]) }) output.append("</table></form>")# Subsequent forms are for other stuff # Deities #---------------------- the_team.get_deities(cursor) output.append(""" <table style="float:left; margin-right: 25px;" border="0" cellspacing="0" cellpadding="5"> <tr class="row2"> <th>Deity</th> <th> </th> </tr> """) counter = -1 for deity_id, team_favour in the_team.deities.items(): counter += 1 output.append(""" <tr class="row%(row)d"> <td><label for="%(name)s">%(name)s</label></td> <td style="padding: 0px;"> <a class="block_link" href="exec.py?mode=remove_deity&deity=%(deity_id)d&team=%(team_id)d">Remove</a> </td> </tr>""" % {'row': (counter % 2), 'name': deity_dict[deity_id].name, 'deity_id': deity_id, 'team_id': team_id }) output.append(""" <tr class="row%(row)d"> <form id="team_add_deity_form" action="exec.py?mode=add_deity" method="post" accept-charset="utf-8"> <input type="hidden" name="mode" value="add_deity" /> <input type="hidden" name="team" value="%(team_id)s" /> <td style="padding:1px;"> <select name="deity"> %(deity_option_box)s </select> </td> <td style="padding: 2px;"> <input type="submit" value="Add" /> <!--<a href="#" onclick="$('#team_add_deity_form').submit(); return false;" class="block_link">Add</a>--> </td> </tr> </form> </table> """ % { 'row': ((counter+1) % 2), 'team_id': the_team.id, 'deity_option_box': deity_f.deity_option_list(cursor, the_team.deities)}) # Evolutions #------------------- the_team.get_evolutions(cursor) output.append(""" <table style="float:left; margin-right: 25px;" border="0" cellspacing="0" cellpadding="5"> <tr class="row2"> <th>Evolution</th> <th> </th> <th> </th> </tr> """) counter = -1 for evo_id, evo_level in the_team.evolutions.items(): counter += 1 output.append(""" <tr class="row%(row)d"> <form id="edit_evo_%(evolution_id)s" action="exec.py" method="post" accept-charset="utf-8"> <input type="hidden" name="mode" value="set_evolution" /> <input type="hidden" name="team" value="%(team_id)s" /> <input type="hidden" name="evolution" value="%(evolution_id)s" /> <td><label for="%(name)s">%(name)s</label></td> <td style="padding:1px;"> %(text_box)s </td> </form> <td style="padding: 0px;"> <a class="block_link" href="exec.py?mode=set_evolution&evolution=%(evolution_id)d&team=%(team_id)d">Remove</a> </td> </tr>""" % {'row': (counter % 2), 'name': evolution_dict[evo_id].name, 'evolution_level': evo_level, 'evolution_id': evo_id, 'team_id': team_id, "text_box": common.text_box("evolution_level", evo_level, custom_id="", size=3, warn_on = lambda e: (True if evolution_dict[evo_id].min_level > e or e > evolution_dict[evo_id].max_level else False)), }) output.append(""" <tr class="row%(row)d"> <form id="team_add_evolution_form" action="exec.py" method="post" accept-charset="utf-8"> <input type="hidden" name="mode" value="set_evolution" /> <input type="hidden" name="team" value="%(team_id)d" /> <td style="padding:1px;"> <select name="evolution"> %(evolution_option_box)s </select> </td> <td style="padding:1px;"> %(evolution_level)s </td> <td style="padding: 0px;"> <a href="#" onclick="$('#team_add_evolution_form').submit();" class="block_link">Add</a> </td> </tr> </form> </table> """ % { 'row': ((counter+1) % 2), 'team_id': the_team.id, 'evolution_level': common.text_box('evolution_level', 0, 4), 'evolution_option_box': evolution_f.evolution_option_list(cursor, the_team.evolutions)}) # Traits #---------------------- the_team.get_traits(cursor) output.append(""" <table style="float:left; margin-right: 25px;" border="0" cellspacing="0" cellpadding="5"> <tr class="row2"> <th>Trait</th> <th> </th> </tr> """) counter = -1 for trait_id in the_team.traits: counter += 1 output.append(""" <tr class="row%(row)d"> <td><label for="%(name)s">%(name)s</label></td> <td style="padding: 0px;"> <a class="block_link" href="exec.py?mode=remove_trait&trait=%(trait_id)d&team=%(team_id)d">Remove</a> </td> </tr>""" % {'row': (counter % 2), 'name': trait_dict[trait_id].name, 'trait_id': trait_id, 'team_id': team_id }) output.append(""" <tr class="row%(row)d"> <form id="team_add_trait_form" action="exec.py?mode=add_trait" method="post" accept-charset="utf-8"> <input type="hidden" name="mode" value="add_trait" /> <input type="hidden" name="team" value="%(team_id)s" /> <td style="padding:1px;"> <select name="trait"> %(trait_option_box)s </select> </td> <td style="padding: 2px;"> <input type="submit" value="Add" /> <!--<a href="#" onclick="$('#team_add_trait_form').submit(); return false;" class="block_link">Add</a>--> </td> </tr> </form> </table> """ % { 'row': ((counter+1) % 2), 'team_id': the_team.id, 'trait_option_box': trait_f.trait_option_list(cursor, the_team.traits)}) # Hashes output.append(""" <table style="float:left; margin-right: 25px;" border="0" cellspacing="0" cellpadding="5"> <tr class="row2"> <th>Turn</th> <th>Hash</th> </tr> """) for i, t in enumerate(range(common.current_turn(), common.current_turn()-5, -1)): output.append(""" <tr class="row{i}"> <td>{t}</td> <td>{hash}</td> </tr>""".format( i = i % 2, t = t, hash = team_f.team_hash(the_team.name, turn=t), )) output.append("</table>") output.append("</div>") page_data['Title'] = "Edit team (%s)" % the_team.name return "".join(output)
def main(cursor, battle_id=-1): battle_id = int(common.get_val('battle', battle_id)) ships = int(common.get_val('ships', True)) if battle_id < 1: return "No battle selected" the_battle = battle_q.get_one_battle(cursor, battle_id) # Get some other stuff team_dict = team_q.get_all_teams(cursor) the_campaign = campaign_q.get_one_campaign(cursor, the_battle.campaign) output = [""" <div style='padding: 5px;'> <a href="web.py?mode=list_campaigns&turn={turn}" class="block_link" style="display:inline; text-align:left;">Campaigns of this turn</a> <a href="web.py?mode=setup_campaign&campaign={c.id}" class="block_link" style="display:inline;">Setup campaign</a> <a href="web.py?mode=list_battles&campaign={c.id}" class="block_link" style="display:inline;">List battles</a> <a href="web.py?mode=setup_battle&battle={b.id}" class="block_link" style="display:inline;">Setup battle</a> <a href="web.py?mode=perform_by_army&battle={b.id}" class="block_link" style="display:inline;">By army</a> <br /><br /> <span class="stitle">{c.name} - {b.name}</span> - <a href="web.py?mode=perform_battle&battle={b.id}&ships=0">No ships</a> <br /> <a href="#" onclick="$('.show_evo_wedge').show(); $('.evo_wedge').hide(); return false;">Hide evo wedges</a> - <a href="#" onclick="$('.show_evo_wedge').hide(); $('.evo_wedge').show(); return false;">Show evo wedges</a> """.format( c = the_campaign, b = the_battle, turn = common.current_turn(), )] # Now for some stuff about the participants #------------------------ the_campaign.get_sides_basic(cursor) the_campaign.get_armies_basic(cursor) the_battle.get_losses(cursor) the_battle.get_squads(cursor) team_list = [] for s in range(1, the_campaign.sides+1): for t in the_campaign.sides_basic[s]: team_list.append(t) unit_dict = unit_q.get_units_from_team_list(cursor, team_list, special_units=True) evolution_dict = evolution_q.get_all_evolutions(cursor) # Sort squads by team # Doing this makes it O(2n) rather than O(t*n) squad_dict = squad_q.get_squads_from_list(cursor, the_battle.squads) squads_by_team = {} for squad_id, the_squad in squad_dict.items(): if the_squad.team not in squads_by_team: squads_by_team[the_squad.team] = [] squads_by_team[the_squad.team].append(squad_id) for s in range(1, the_campaign.sides+1): teams_on_side = the_campaign.sides_basic[s] if len(teams_on_side) > 0: output.append('''<table border="1" cellspacing="0" cellpadding="5" width="100%"> <tr> <td class="stitle" colspan="2">{s}</td> </tr>'''.format(s=s)) for i, team_id in enumerate(teams_on_side): if team_id not in squads_by_team: squads_by_team[team_id] = [] # Table tags for team cell if i % 2 == 0: output.append('<tr><td>') else: output.append('<td>') the_team = team_dict[team_id] # Team header output.append(''' <span class="stitle">{name}</span> - <a href="web.py?mode=list_units&team={id}">Military</a> - <a href="web.py?mode=list_armies&team={id}">Armies</a> - <a href="#" onclick="$(this).parent().hide(); return false;">Hide</a> '''.format( name=the_team.name, id=team_id, )) # Build dictionaries/lists team_units = the_team.get_units(cursor) total_count = {} unit_count = {} unit_losses = {} army_list = the_campaign.get_armies_from_team(cursor, team_id) army_dict = army_q.get_armies_from_list(cursor, army_list) squad_q.mass_get_squads(cursor, army_dict) # armies = the_battle.get_armies() # squads = the_battle.get_squads() transport_lost = 0 transport_capacity = 0 army_size = 0 for unit_id in team_units.keys(): unit_count[unit_id] = 0 unit_losses[unit_id] = 0 for squad_id in squads_by_team[team_id]: unit_count[squad_dict[squad_id].unit] += squad_dict[squad_id].amount army_size += squad_dict[squad_id].amount unit_losses[squad_dict[squad_id].unit] += the_battle.losses.get(squad_id, 0) # print("") # print(the_battle.squads, "<br />") # print(unit_count, "<br />") # print(unit_losses, "<br />") # exit() output.append(""" <table border="0" cellspacing="0" cellpadding="5" style="width: 100%"> <tr class="row2"> <th>Unit</th> <th colspan="4"> </th> <th>Equipment</th> <th>Total</th> <th>Amount</th> <th colspan="2">Losses</th> <th> </th> </tr> """) # Build look-ahead lookahead = {} last_unit = -1 for unit_id in team_units.keys(): if unit_dict[unit_id].type_cat == unit.categories.index("Ship") and ships == False: continue if unit_count[unit_id] == 0 and unit_losses[unit_id] == 0: continue lookahead[last_unit] = unit_id last_unit = unit_id lookahead[last_unit] = 0 # Unit row team_losses = 0 team_size = 0 count = -1 for unit_id, amount in team_units.items(): if unit_dict[unit_id].type_cat == unit.categories.index("Ship") and ships == False: continue if unit_count[unit_id] == 0 and unit_losses[unit_id] == 0: continue count += 1 team_losses += unit_losses[unit_id] team_size += unit_count[unit_id] transport_capacity += (unit_dict[unit_id].transport * unit_count[unit_id]) # Form JS form_js = """$('#ajax_target').load('web.py', {mode: 'add_unit_loss', ajax: 'True', battle: %(battle_id)s, unit: %(unit_id)s, team: %(team_id)s, amount: $('#amount_for_%(unit_id)s_%(team_id)s').attr('value')}, function () { var loss = parseInt($('#amount_for_%(unit_id)s_%(team_id)s').attr('value').replace(',', '')); var current_loss = parseInt($('#losses_%(unit_id)s_%(team_id)s').html().replace(',', '')); var current_amount = parseInt($('#amount_%(unit_id)s_%(team_id)s').html().replace(',', '')); $('#amount_%(unit_id)s_%(team_id)s').html(current_amount - loss); $('#losses_%(unit_id)s_%(team_id)s').html(current_loss + loss); $('#amount_for_%(unit_id)s_%(team_id)s').attr('value', ''); $('#amount_for_%(ahead)s_%(team_id)s').focus(); }); return false;""" % { "battle_id": battle_id, "team_id": team_id, "unit_id": unit_id, "ahead": lookahead[unit_id], }; # function add_unit_amount_%(unit_id)s () # { # $('#amountFor_team').removeAttr('value'); # $('#spanAddUnitFor_team').load('ajax.php', {mode: 'getUnitsNotInWar', team: $team, war: $warId}); # }); output.append(""" <tr class="row{count}" id="row_{team_id}_{unit_id}"> <td style='font-weight:bold;'>{unit_name}</td> <td>{weapon_cat}</td> <td>{armour_cat}</td> <td>{move_cat}</td> <td>{training_cat}</td> <td>{equipment}</td> <td>{total}</td> <td id="amount_{unit_id}_{team_id}">{amount}</td> <td id="losses_{unit_id}_{team_id}">{losses}</td> <td id="losses_cent_{unit_id}_{team_id}">{losses_cent}%</td> <td style="padding:1px;"> <form action="exec.pyy" method="post" id="" onsubmit="{form_js}" accept-charset="utf-8"> <input type="hidden" name="mode" id="mode" value="add_unit_loss" /> <input type="hidden" name="battle" id="battle" value="{battle_id}" /> <input type="hidden" name="unit" id="unit" value="{unit_id}" /> <input type="hidden" name="team" id="team" value="{team_id}" /> <input type="text" onfocus="{on_focus}" onblur="{on_blur}" name="amount" id="amount_for_{unit_id}_{team_id}" value="" size="5"/> </form> </td> </tr> """.format( count = count%2, form_js = form_js, unit_name = unit_dict[unit_id].name, equipment = unit_dict[unit_id].equipment_string, total = common.number_format(unit_count[unit_id] + unit_losses[unit_id]), amount = common.number_format(unit_count[unit_id]), losses = common.number_format(unit_losses[unit_id]), losses_cent = round(unit_losses[unit_id]/(unit_count[unit_id]+unit_losses[unit_id])*100), battle_id = battle_id, team_id = team_id, unit_id = unit_id, on_focus = "$('#row_{0}_{1}').addClass('row3');".format(team_id, unit_id), on_blur = "$('#row_{0}_{1}').removeClass('row3');".format(team_id, unit_id), weapon_cat = "", armour_cat = "", move_cat = "", training_cat = "", # xweapon_cat = short_weapon_categories[unit_dict[unit_id].weapon_cat], # xarmour_cat = short_armour_categories[unit_dict[unit_id].armour_cat], # xmove_cat = short_move_categories[unit_dict[unit_id].move_cat], # xtraining_cat = short_training_categories[unit_dict[unit_id].training_cat], )) # Size row if (team_size+team_losses) == 0: losses_cent = "" else: losses_cent = "%d%%" % round(team_losses/(team_size+team_losses)*100) count += 1 output.append(""" <tr class="row%(count)s"> <td colspan="6"> Military size: </td> <td> %(size)s </td> <td> %(losses)s </td> <td> %(losses_cent)s </td> <td colspan="3"> </td> </tr> <tr class="row%(count_)s"> <td colspan="6">Transport:</td> <td>%(transport_capacity)s</td> <td colspan="5"> </td> </tr> """ % { "count": count%2, "count_": (count+1)%2, "size": format(army_size, ','), "losses": team_losses, "losses_cent": losses_cent, "transport_capacity": format(transport_capacity, ','), }) count += 1 # Evos row evo_output = [] the_team.get_evolutions(cursor) for evolution_id in the_team.evolutions: the_evo = evolution_dict[evolution_id] if the_team.evolutions[evolution_id] == 0: continue if not the_evo.combat_relevant: continue if the_evo.max_level == 1 and the_team.evolutions[evolution_id] == 1: evo_output.append("""<strong>%(evo_name)s</strong><br />""" % { "evo_name": the_evo.name, }) else: evo_output.append("""<strong>%(level)sx %(evo_name)s</strong><br />""" % { "level": the_team.evolutions[evolution_id], "evo_name": the_evo.name, }) count += 1 output.append(""" <tr class="row%(count)s"> <td colspan="11" style="padding:0px;"> <div id="show_evos_%(team_id)s" style="display:nnone;" class="show_evo_wedge"> <a href="#" class="block_link" onclick="$('#show_evos_%(team_id)s').hide(); $('#evos_%(team_id)s').fadeIn(250);return false;">Evos</a> </div> <div id="evos_%(team_id)s" style="display:none;" class="evo_wedge"> <a href="#" class="block_link" onclick="$('#show_evos_%(team_id)s').fadeIn(250); $('#evos_%(team_id)s').hide(); return false;">Hide</a><br /> %(evo_output)s </div> </td> </tr> """ % { "count": count%2, "team_id": team_id, "evo_output": "".join(evo_output) }) # End of team units output.append("</table>") # Table tags for team cell if i % 2 == 0: output.append('</td>') else: output.append('</td></tr>') # Not sure that we need to adhere to W3C specs for tables... # if i % 2 == 0: output.append('<td> </td></tr>') output.append("</table><br />") else: output.append('No teams on side {s}'.format(s=s)) # Field for the ids of the armies listed that we need to sort out # output.append('</table><br />') output.append("</div>") page_data['Title'] = "Perform by unit - %s" % the_battle.name return "".join(output)
import database from classes import world, res_dict from classes import team, city, squad, army, unit from queries import equipment_q, building_q, deity_q, evolution_q, tech_q, spell_q, artefact_q, wonder_q # Need some live data for things like buildings etc temp_cursor = database.get_cursor() equipment_dict = equipment_q.get_all_equipment(temp_cursor) building_dict = building_q.get_all_buildings(temp_cursor) deity_dict = deity_q.get_all_deities(temp_cursor) evolution_dict = evolution_q.get_all_evolutions(temp_cursor) spell_dict = spell_q.get_all_spells(temp_cursor) tech_dict = tech_q.get_all_techs(temp_cursor) artefact_dict = artefact_q.get_all_artefacts(temp_cursor) wonder_dict = wonder_q.get_all_wonders(temp_cursor) def dummy_world(): w = world.World(Dead_cursor()) # LISTS #------------------------ w._equipment = equipment_dict w._buildings = building_dict w._deities = deity_dict w._evolutions = evolution_dict w._spells = spell_dict w._techs = tech_dict w._artefacts = artefact_dict # TEAMS #------------------------