def check_operative_locations(cursor, verbose): """Finds operatives in dead cities and relocates them""" teams_dict = team_q.get_all_teams(cursor) operatives_dict = operative_q.get_all_operatives(cursor) city_dict = city_q.get_all_cities(cursor) # Get a list of the dead cities dead_city_list = [] for c_id, the_city in city_dict.items(): if the_city.dead > 0 or not teams_dict[the_city.team].active: dead_city_list.append(str(c_id)) # Find operatives in those cities query = """SELECT id FROM operatives WHERE city in (%s) and died < 1""" % ",".join(dead_city_list) try: cursor.execute(query) except Exception as e: raise Exception("Database error: %s\nQuery: %s" % (str(e.args[0]).replace("\n",""), query)) move_op_list = {} for row in cursor: o = row['id'] t = operatives_dict[o].team if not teams_dict[t].active: continue if t not in move_op_list: move_op_list[t] = [] move_op_list[t].append(str(o)) # Find out which teams we need to get a city for teams_cities = {} for t in move_op_list.keys(): teams_cities[t] = -1 # Find cities for those teams if verbose: it = cli_f.progressbar(city_dict.items(), "ops_check.check_operative_locations: ", 40, with_eta = True) else: it = city_dict.items() for c_id, the_city in it: if the_city.team in teams_cities and not teams_dict[the_city.team].dead: teams_cities[the_city.team] = c_id # Now run the queries queries = [] for t, c in teams_cities.items(): query = "UPDATE operatives SET city = %d, arrival = %d WHERE id in (%s)" % ( c, common.current_turn(), ",".join(move_op_list[t]), ) try: cursor.execute(query) except Exception as e: raise Exception("Database error: %s\nQuery: %s" % (str(e.args[0]).replace("\n",""), query))
def main(cursor): output = [] city_id = int(common.get_val('city', 1)) if city_id < 1: return "No city selected" # Build city item team_dict = team_q.get_all_teams(cursor) city_dict = city_q.get_live_cities(cursor) if city_id not in city_dict: return "You must select live cities" the_city = city_dict[city_id] output.append(""" <div style="padding:5px;"> <span class="stitle">{name}</span><br /> <table border="0" cellspacing="0" cellpadding="5"> <tr class="row2"> <th>Partner</th> <th colspan="2">Distance</th> </tr>""".format( name = the_city.name, )) query = """SELECT city_2, distance FROM trade_distances WHERE city_1 = %d ORDER BY distance ASC""" % city_id try: cursor.execute(query) except Exception as e: raise Exception("Database error: %s\nQuery: %s" % (str(e.args[0]).replace("\n",""), query)) for i, row in enumerate(cursor): if city_dict[row['city_2']].team == the_city.team: style = "color: #070;font-weight:bold;" else: style = "color: #007;" tr_row = i % 2 output.append(""" <tr class="row{tr_row}"> <td><a class="clear_link" href="web.py?mode=view_city_matrix&city={partner_id}">{partner}</a> (<em style="{style}">{team}</em>)</td> <td>{distance}</td><td><em>{real_distance}</em></td> </tr> """.format( tr_row = tr_row, style = style, partner_id = row['city_2'], partner = city_dict[row['city_2']].name, team = team_dict[city_dict[row['city_2']].team].name, distance = row['distance'], real_distance = int(sad_rules.reverse_trade_distance(row['distance'])), )) page_data['Title'] = "City matrix (%s)" % the_city.name output.append("</table></div>") return "".join(output)
def teams(cursor): output = {} id_list = [] team_dict = team_q.get_all_teams(cursor) for t, the_team in team_dict.items(): id_list.append(t) output[t] = { "team_id": t, "name": the_team.name, "ir": the_team.ir, "join_turn": the_team.join_turn, } return "teams = %s; team_list = %s;" % (json.dumps(output), id_list)
def teams(cursor): output = {} team_dict = team_q.get_all_teams(cursor) player_dict = player_q.get_active_players(cursor, turn_count=5) seconds = {} for p, the_player in player_dict.items(): if p != team_dict[the_player.team].leader_id: if the_player.team not in seconds: seconds[the_player.team] = [] seconds[the_player.team].append(p) deities = [] evolutions = [] for t, the_team in team_dict.items(): if the_team.dead: continue if the_team.not_in_queue: continue if the_team.hidden: continue if the_team.not_a_team: continue output[t] = { "team_id": t, "name": the_team.name, "leader": the_team.leader_id, "seconds": seconds.get(t, []), "culture": the_team.culture_topic, "ir": the_team.ir, "join_turn": the_team.join_turn, "deities": list(the_team.get_deities(cursor).keys()), "evolutions": the_team.get_evolutions(cursor), } 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): return "" output = ["""<div style="padding: 5px;">"""] ajax = common.get_val('ajax', 0) if not ajax: page_data['Headers'] = False battle_dict = battle_q.get_battles_from_turn(cursor, common.current_turn()) team_dict = team_q.get_all_teams(cursor) city_dict = city_q.get_all_cities(cursor) output.append("""<table border="0" cellspacing="0" cellpadding="5"> <tr class="row2"> <th>Battle</th> <th>Time</th> <th>Location</th> </tr>""") # Display battles i = -1 for battle_id, the_battle in battle_dict.items(): i += 1 location = "%d, %d" % (the_battle.x, the_battle.y) if i == 0: days_since = "" time_taken = "" distance = "" else: waypoints = ((last_battle.x, last_battle.y), (the_battle.x, the_battle.y)) b_path = path_f.path(cursor, waypoints, move_speed="Marching", move_type="Medium foot") days_since = "Days since last battle: {0}".format(the_battle.start - last_battle.ended) time_taken = "Time taken to travel: {0} days".format(b_path.time_cost) distance = "Distance from last battle: {0}km".format(format(b_path.walk_distance, ',')) output.append(""" <tr class="row0"> <td><strong>{name}</strong></td> <td>{start} : {ended}</td> <td>{location}</td> </tr> <tr class="row1"> <td colspan="3"> {days_since}<br /> {time_taken}<br /> {distance}<br /> </td> </tr> """.format( i=i%2, name=the_battle.name, start=the_battle.start, ended=the_battle.ended, location=location, days_since = days_since, time_taken = time_taken, distance = distance, id=battle_id, )) # Use this to record stuff for the next battle last_battle = the_battle output.append("</table></div>") return "".join(output)
def main(cursor): cities_dict = city_q.get_new_cities(cursor) teams_dict = team_q.get_all_teams(cursor) output = [] output.append(""" <table border="0" cellspacing="0" cellpadding="5" style="width: 100%;"> <tr class="row2"> <th>City name</th> <th> </th> <th>X</th> <th>Y</th> <th>Port</th> <th>Secret</th> <th>Dead</th> <th>Nomadic</th> <th>Population</th> <th>Slaves</th> <th> </th> </tr>""") count = -1 if len(cities_dict) > 0: for city_id, the_city in cities_dict.items(): count += 1 output.append(""" <tr class="row%(row)d" id="%(city_id)d"> <td>%(city_name)s (%(team_name)s)</td> <td style="padding: 0px;"><a class="block_link" href="web.py?mode=view_map&%(map_link)s">Map link</a></td> <td>%(x)s</td> <td>%(y)s</td> <td style="text-align: center;">%(port)s</td> <td style="text-align: center;">%(secret)s</td> <td style="text-align: center;">%(dead)s</td> <td style="text-align: center;">%(nomadic)s</td> <td>%(population)s</td> <td>%(slaves)s</td> <td style="padding: 0px;"><a class="block_link" href="web.py?mode=edit_city&city=%(city_id)d">Edit city</a></td> </tr> """ % { 'row': (count % 2), 'city_id': the_city.id, 'city_name': common.doubleclick_text("cities", "name", the_city.id, the_city.name, "font-weight:bold"), "map_name": the_city.name.replace(" ", "").lower(), 'team_name': teams_dict[the_city.team].name, 'x': common.doubleclick_text("cities", "x", the_city.id, the_city.x, ""), 'y': common.doubleclick_text("cities", "y", the_city.id, the_city.y, ""), "map_link": the_city.map_link_args(), 'port': common.bstr(the_city.port), 'secret': common.bstr(the_city.secret), 'dead': common.bstr(the_city.dead), 'nomadic': common.bstr(the_city.nomadic), 'population': common.doubleclick_text("cities", "population", the_city.id, the_city.population, ""), 'slaves': common.doubleclick_text("cities", "slaves", the_city.id, the_city.slaves, ""), }) output.append("</table>") return "".join(output)
def main(cursor): output = ["""<div style="padding: 5px;">"""] campaign_id = int(common.get_val('campaign', 0)) ajax = common.get_val('ajax', 0) # Used to let us know if there is an issue with the campaign errors = False if campaign_id < 1: return "No campaign selected" if not ajax: page_data['Headers'] = False the_campaign = campaign_q.get_one_campaign(cursor, campaign_id) battle_dict = battle_q.get_battles_from_campaign(cursor, campaign_id) team_dict = team_q.get_all_teams(cursor) city_dict = city_q.get_all_cities(cursor) output.append("""<table border="0" cellspacing="0" cellpadding="5"> <tr class="row2"> <th>Battle</th> <th>Time</th> <th>Location</th> <th colspan="4"> </th> </tr>""") # Display battles i = -1 total_waypoints = [] for battle_id, the_battle in battle_dict.items(): i += 1 location = "%d, %d" % (the_battle.x, the_battle.y) total_waypoints.append((the_battle.x, the_battle.y)) if i == 0: days_since = "" time_taken = "" distance = "" path_map_link = " " else: waypoints = ((last_battle.x, last_battle.y), (the_battle.x, the_battle.y)) b_path = path_f.path(cursor, waypoints, move_speed="Marching", move_type="Medium foot") w_path = path_f.path(cursor, waypoints, move_speed="Sailing", move_type="Sail") if w_path != None: if b_path.time_cost > w_path.time_cost: b_path = w_path days_since = "Days since last battle: {0}".format(the_battle.start - (last_battle.start + last_battle.duration)) time_taken = "Time taken to travel: {0} days".format(int(b_path.time_cost)) distance = "Distance from last battle: {0}km".format(format(b_path.walk_distance, ',')) # Formatting for time taken? if b_path.time_cost > (the_battle.start - (last_battle.start + last_battle.duration)): time_taken = "<span class='neg' style='font-weight:bold;'>%s</span>" % time_taken days_since = "<span class='neg' style='font-weight:bold;'>%s</span>" % days_since errors = True points = str(waypoints).replace('(', '').replace(')', '')#.replace(',', '%2C') path_map_link = '<a href="web.py?mode=path_map&points=%s&move_speed=Marching&move_type=Medium foot" class="block_link">Path link</a>' % points # Battle start start_str = the_battle.start dur_str = the_battle.duration if (the_battle.start + the_battle.duration) > 365: start_str = '<span class="neg" style="font-weight:bold;">%s</span>' % the_battle.start dur_str = '<span class="neg" style="font-weight:bold;">%s</span>' % the_battle.duration errors = True output.append(""" <tr class="row0"> <td><strong>{name}</strong></td> <td>{start} : {duration}</td> <td>{location}</td> <td width="5"> </td> <td colspan="3"> </td> </tr> <tr class="row1"> <td colspan="3"> {days_since}<br /> {time_taken}<br /> {distance}<br /> </td> <td width="5"> </td> <td colspan="3" style="padding:0px;"> {path_map_link} </td> </tr> """.format( i=i%2, name=the_battle.name, start=start_str, duration=dur_str, location=location, days_since = days_since, time_taken = time_taken, distance = distance, path_map_link = path_map_link, id=battle_id, )) # Use this to record stuff for the next battle last_battle = the_battle if errors: error_str = "ERRORS FOUND" else: error_str = "" points = str(tuple(total_waypoints)).replace('(', '').replace(')', '')#.replace(',', '%2C') output.append(""" <tr class="row0"> <td colspan="3" style="font-weight:bold;font-size:1.5em;text-align:center;color:#F00;padding:10px;"> {error_str} </td> <td> </td> <td colspan="3" style="padding:0px;"> {path_link} </td> </tr>""".format( path_link = '<a href="web.py?mode=path_map&points=%s&move_speed=Marching&move_type=Medium foot" class="block_link">Path link</a>' % points, error_str = error_str, )) output.append("</table>") output.append("</div>") return "".join(output)
def main(cursor): output = [] # Team select team_select = team_f.structured_list(cursor, include_irs = False, default=-1, field_name="team", field_id="team_select", skip=[]) team_select = team_select.replace(">", '><option value="-1" selected="selected">GM report</option>', 1) # City select city_names = {} cities_dict = city_q.get_live_cities(cursor) team_dict = team_q.get_all_teams(cursor) for c, the_c in cities_dict.items(): if the_c.dead > 0: continue city_names[c] = "{0} (<em>{1}</em>)".format(the_c.name, team_dict[the_c.team].name) # Selection output output.append(""" <form action="web.py?mode=generate_report" method="post" accept-charset="utf-8"> <table border="0" cellspacing="0" cellpadding="5"> <tr> <td>Team:</td> <td style="padding:1px;">{team_select}</td> </tr> <tr> <td>Target team:</td> <td>{target_team_select}</td> </tr> <tr> <td colspan="2"> <input type="submit" value="Continue →" /> </td> </tr> </table> </form> <br /><br /> <form action="web.py?mode=generate_report" id="report_form" method="post" accept-charset="utf-8"> <table border="0" cellspacing="0" cellpadding="5"> <tr> <td>Team:</td> <td style="padding:1px;">{team_select}</td> </tr> <tr> <td>Target city:</td> <td>{city_select}</td> </tr> <tr> <td>Target area:</td> <td><input type="text" name="area" id="area_select" value="" size="10"/> <input type="text" name="radius" id="radius" value="1" size="5"/></td> </tr> <tr> <td colspan="2"> <input type="submit" value="Continue →" /> </td> </tr> </table> </form> {onload} """.format( team_select = team_select, target_team_select = team_f.structured_list(cursor, include_irs = False, default=-1, field_name="target_team", field_id="target_team", skip=[]), city_select = common.option_box( name = 'city', elements = city_names, element_order = cities_dict.keys(), # custom_id="", # selected=the_artefact.city, ), onload = common.onload("$('#team_select').focus();") )) return "".join(output)
def main(cursor, campaign_id = -1): output = ["""<div style="padding: 5px;">"""] campaign_id = int(common.get_val('campaign', campaign_id)) battle_id = int(common.get_val('battle', 0)) ajax = common.get_val('ajax', 0) if campaign_id < 1: if battle_id < 1: return "No campaign selected" else: the_battle = battle_q.get_one_battle(cursor, battle_id) campaign_id = the_battle.campaign the_campaign = campaign_q.get_one_campaign(cursor, campaign_id) battle_dict = battle_q.get_battles_from_campaign(cursor, campaign_id) team_dict = team_q.get_all_teams(cursor) city_dict = city_q.get_all_cities(cursor) if not ajax: output.append(""" <div style="float:right;border:0px solid #000; width: 50%;"> <form id="delete_form" action="exec.py" method="post" accept-charset="utf-8"> <input type="hidden" name="campaign" id="campaign" value="{id}" /> <input type="hidden" name="mode" id="mode" value="remove_campaign" /> <input style="float:right; margin-right:100px;" type="button" value="Delete campaign" onclick="var answer = confirm('Delete {esc_name}?') if (answer) $('#delete_form').submit();" /> </form> <div id="campaign_info"> </div> </div> <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={camp}" class="block_link" style="display:inline;">Setup campaign</a> <br /><br /> <span class="stitle">{name}</span> <br /><br /> <table border="0" cellspacing="0" cellpadding="5"> """.format( turn = common.current_turn(), camp = the_campaign.id, name = the_campaign.name, id = campaign_id, esc_name = common.js_name(the_campaign.name), )) else: output.append("""<table border="0" cellspacing="0" cellpadding="5" width="100%">""") output.append(""" <tr class="row2"> <th>Battle</th> <th>Time</th> <th>Location</th> <th>Type</th> <th>Result</th> <th> </th> <th colspan="2">Perform</th> </tr>""") # Display battles i = -1 for battle_id, the_battle in battle_dict.items(): i += 1 location = "%d, %d" % (the_battle.x, the_battle.y) city_link = "" if the_battle.city > 0: city_link = '<!-- PY --> <a href="web.py?mode=edit_city&city=%d">Edit city</a><!-- PYEND -->' % the_battle.city output.append(""" <tr class="row{i}"> <td>{name} ({battle_id}){city_link}</td> <td>{start} : {duration}</td> <td>{location} {city}</td> <td>{type}</td> <td>{result}</td> <td style="padding:0px;"><a href="web.py?mode=setup_battle&battle={battle_id}" class="block_link">Setup</a></td> <td style="padding:0px;"><a href="web.py?mode=perform_battle&battle={battle_id}" class="block_link">By unit</a></td> <td style="padding:0px;"><a href="web.py?mode=perform_by_army&battle={battle_id}" class="block_link">By army</a></td> </tr> """.format( i=i%2, city_link = city_link, name=common.doubleclick_text("battles", "name", battle_id, the_battle.name, label_style="font-weight:bold;"), start=common.doubleclick_text("battles", "start", battle_id, the_battle.start, size=2), duration=common.doubleclick_text("battles", "duration", battle_id, the_battle.duration, size=2), location=location, battle_id=battle_id, city = city_dict[the_battle.city].name, type = battle.battle_types[the_battle.type], result = battle.result_types[the_battle.result], )) if ajax: onload = "" else: onload = common.onload("$('#form_city').focus();") # Add new battle i += 1 output.append(""" <tr class="row{i}"> <form action="exec.py" id="add_battle_form" method="post" accept-charset="utf-8"> <input type="hidden" name="mode" value="add_battle" /> <input type="hidden" name="campaign" value="{campaign_id}" /> <td style="padding: 1px;"><input type="text" name="name" id="new_name" value="" /></td> <td style="padding: 1px;"> <input type="text" name="start" value="-1" size="2"/> <input type="text" name="duration" value="" size="2"/> </td> <td style="padding: 1px;"> <input type="text" name="location" value="" size="8"/> </td> <td style="padding: 1px;"> {type} </td> <td> </td> <td colspan="3" style="padding: 0px;"> <!--<a class="block_link" href="#" onclick="$('#add_battle_form').submit();">Add</a>--> <input type="submit" value="Add" /> </td> </form> </tr>""".format( i=i%2, campaign_id=campaign_id, type = common.option_box("type", elements = battle.battle_types, element_order = [], custom_id = ""), )) # Add by city city_dict = city_q.get_cities_for_dropdown(cursor) keys, names = [], {} for c, the_city in city_dict.items(): if the_city.dead > 0: continue if not team_dict[the_city.team].active: continue keys.append(c) names[c] = the_city.name i += 1 output.append(""" <tr class="row{i}"> <form action="exec.py" id="add_battle_form" method="post" accept-charset="utf-8"> <input type="hidden" name="mode" value="add_battle" /> <input type="hidden" name="campaign" value="{campaign_id}" /> <td style="padding: 1px;">{city_list}</td> <td style="padding: 1px;"> <input type="text" name="start" value="-1" size="2"/> <input type="text" name="duration" value="" size="2"/> </td> <td> </td> <td style="padding: 1px;"> {type} </td> <td> </td> <td colspan="3" style="padding: 0px;"> <!--<a class="block_link" href="#" onclick="$('#add_battle_form').submit();">Add</a>--> <input type="submit" value="Add" /> </td> </form> {onload} </tr> </table> <br /><br /> """.format( i=i%2, campaign_id=campaign_id, onload=onload, city_list = common.option_box( name='city', elements=names, element_order=keys, custom_id="form_city", ), type = common.option_box("type", elements = battle.battle_types, element_order = [], custom_id = ""), )) # Chosen kills output.append(""" <div style="float:right;border:0px solid #000; width: 60%;"> <div id="player_kills"> </div> </div> """) # Now for moving all the armies output.append(""" <!-- PY --> <table border="0" cellspacing="0" cellpadding="5"> <!-- <tr class="row2"> <th>Team</th> <th colspan="3">Move</th> <th> </th> </tr> -->""") the_campaign.get_sides_full(cursor) for s in range(1, the_campaign.sides+1): teams_on_side = the_campaign.sides_full[s] if len(teams_on_side) > 0: i = 0 output.append("<tr class='row2'><td colspan='5' style='text-align:center;'>Side %d</td></tr>" % s) for t in teams_on_side: i += 1 output.append(""" <tr class="row{i}"> <td>{team}</td> <td style='padding:0px;'> <!-- <a class="block_link" href="#" onclick="$.get('exec.py', {{mode: 'move_armies', team:{team_id}, campaign:{campaign}, location: ''}}, function () {{$('#ajax_result_{team_id}').html('Moved to location of final battle').val());}}); return false;">Final battle</a> --> <a class="block_link" href="exec.py?mode=move_armies&team={team_id}&campaign={campaign}">Final battle</a> </td> <td style='padding:0px;'> <a class="block_link" href="#" onclick="$.get('exec.py', {{mode: 'move_armies', team:{team_id}, campaign:{campaign}, location: $('#location_{team_id}').value}}, function () {{$('#ajax_result_{team_id}').html('Moved to ' + $('#location_{team_id}').val());}}); return false;">Location:</a> </td> <td style="padding:2px;"> <form action="exec.py" method="post" accept-charset="utf-8" id="team_form_{team_id}"> <input type="hidden" name="mode" value="move_armies" /> <input type="hidden" name="team" value="{team_id}" /> <input type="hidden" name="campaign" value="{campaign}" /> <input type="text" name="location" id="location_{team_id}" value="" size="6"/> </form> </td> <td id="ajax_result_{team_id}"> </td> </tr> """.format( i = i % 2, team_id = t['team'], team = team_dict[t['team']].name, campaign = campaign_id, )) output.append("</table><!-- PYEND -->") output.append("</div><!-- PY -->%s<!-- PYEND -->" % common.onload(""" $('#campaign_info').load('web.py',{'mode':'campaign_info','ajax':'True','campaign':'%d'}); $('#player_kills').load('web.py',{'mode':'player_kills','ajax':'True','campaign':'%d'}); """ % (campaign_id, campaign_id))) if ajax: output.append("<br />") 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)
def main(cursor): output = [] all_teams = common.get_val('all_teams', False) # Get the turn we'll want to get stuff for current_turn = common.current_turn() # Get our list if not all_teams: team_dict = team_q.get_real_teams(cursor) else: team_dict = team_q.get_all_teams(cursor) if len(team_dict) < 1: raise Exception("No teams found") output.append(""" <table border="0" cellspacing="0" cellpadding="0" style="width: 100%;"> <tr class="row2"> <th style="padding: 5px;">Team name</th> <th colspan="6">Forum</th> <th> </th> <th colspan="10">Rob</th> <th> </th> <th colspan="5">Internal</th> <th> </th> <th colspan="1"> </th> </tr>""") count = -1 last_active = 1 last_ir = 0 last_queue = 0 # for team_id, team in team_dict.items(): # print(team_dict) for team_id, the_team in team_dict.items(): count += 1 if last_active != the_team.active or last_ir != the_team.ir or last_queue != the_team.not_in_queue: output.append(""" <tr> <td colspan="24"> </td> </tr>""") last_active = the_team.active last_ir = the_team.ir last_queue = the_team.not_in_queue name_image = '<img src="http://localhost/woa/images/teams/%s.png" alt="%s"/>' % (the_team.name.replace(' ', '_').replace("'", '').lower(), the_team.name) output.append(""" <tr class="row%(row)d" id="%(team_id)d"> <td><strong class="block_cell">%(name)s</strong></td> <td><a class="block_link" href="%(board_url)sviewforum.php?f=%(team_forum)d">F</a></td> <td><a class="block_link" href="%(board_url)sviewtopic.php?t=%(team_orders)d">O</a></td> <td><a class="block_link" href="%(board_url)sviewtopic.php?t=%(team_intorders)d">IO</a></td> <td><a class="block_link" href="%(board_url)sviewtopic.php?t=%(team_results)d">R</a></td> <td><a class="block_link" href="%(board_url)sviewtopic.php?t=%(team_teaminfo)d">TI</a></td> <td><a class="block_link" href="%(board_url)sviewtopic.php?t=%(team_culture)d">C</a></td> <td width="10"> </td> <td><a class="block_link" href="web.py?mode=list_cities&team=%(team_id)d">Cit</a></td> <td><a class="block_link" href="web.py?mode=list_spells&team=%(team_id)d">Mag</a></td> <td><a class="block_link" href="web.py?mode=list_techs&team=%(team_id)d">Tech</a></td> <td><a class="block_link" href="web.py?mode=list_units&team=%(team_id)d">Mil</a></td> <td><a class="block_link" href="web.py?mode=list_armies&team=%(team_id)d">Arm</a></td> <td><a class="block_link" href="web.py?mode=list_operatives&team=%(team_id)d">Op</a></td> <td><a class="block_link" href="web.py?mode=results&team=%(team_id)d">Res</a></td> <td><a class="block_link" href="web.py?mode=list_artefacts&team=%(team_id)d">Art</a></td> <td><a class="block_link" href="web.py?mode=team_stats&team=%(team_id)d">Stat</a></td> <td><a class="block_link" href="web.py?mode=list_players&team=%(team_id)d">Plyr</a></td> <td width="10"> </td> <td><a class="block_link" href="web.py?mode=view_borders&team=%(team_id)d">Bord</a></td> <td><a class="block_link" href="web.py?mode=view_orders&turn=%(current_turn)d&team=%(team_id)d&topic_id=%(team_orders)d">Ord</a></td> <td><a class="block_link" href="web.py?mode=view_intorders&team=%(team_id)d&turn=%(current_turn)d&topic_id=%(team_intorders)d">Int</a></td> <td><a class="block_link" href="web.py?mode=ti&team=%(team_id)d">TI</a></td> <td><a class="block_link" href="web.py?mode=spyrep&team=%(team_id)d">Spy Rep</a></td> <td width="10"> </td> <td><a class="block_link" href="web.py?mode=edit_team&team=%(team_id)d">Edit team</a></td> </tr> """ % { 'current_turn': current_turn, 'row': (count % 2), 'board_url': common.data['board_url'], 'team_id': the_team.id, 'name': the_team.name, "name_image": name_image, 'team_forum': the_team.forum_url_id, 'team_orders': the_team.orders_topic, 'team_intorders': the_team.intorders_topic, 'team_results': the_team.results_topic, 'team_teaminfo': the_team.teaminfo_topic, 'team_culture': the_team.culture_topic, }) output.append("</table><br /><br />") output.append(""" <a href="get_teams">Check for more teams</a> <br /> """) return "".join(output)
def main(cursor, campaign_id=-1): output = ['<div style="padding: 5px;">'] grab_coords = common.get_val('coords', '') radius = int(common.get_val('radius', 10)) if grab_coords != '' and radius > 0: # 138, 1224 grabbed_armies = grab_armies(cursor, grab_coords, radius) else: grabbed_armies = "" campaign_id = int(common.get_val('campaign', campaign_id)) if campaign_id < 1: return "No city selected" # Get stuff from DB the_campaign = campaign_q.get_one_campaign(cursor, campaign_id) team_dict = team_q.get_all_teams(cursor) city_dict = city_q.get_cities_for_dropdown(cursor) battle_dict = battle_q.get_battles_from_campaign(cursor, campaign_id) if len(battle_dict) < 1: return common.redirect("web.py?mode=list_battles&campaign=%d" % campaign_id) # last_battle = battle_dict[list(battle_dict.keys())[-1]] last_battle = battle_q.get_last_battle_from_campaign(cursor, campaign_id) if not last_battle: return common.redirect("web.py?mode=list_battles&campaign=%d" % campaign_id) # coords_cities coords_cities = ['<select name="coords">'] for city_id, the_city in city_dict.items(): if city_id == last_battle.city: coords_cities.append("<option value='%s,%s' selected='selected'>%s</option>" % (the_city.x, the_city.y, the_city.name)) else: coords_cities.append("<option value='%s,%s'>%s</option>" % (the_city.x, the_city.y, the_city.name)) coords_cities.append("</select>") coords_cities = "".join(coords_cities) output.append(""" <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=list_battles&campaign={id}" class="block_link" style="display:inline;">List battles</a> <a href="web.py?mode=perform_battle&battle={last_battle}" class="block_link" style="display:inline;">Last battle</a> <br /><br /> <form action="exec.py" id="mass_add_army_form" method="post" accept-charset="utf-8" style="display:block; float:right; border: 0px solid #000; margin-right:20px;"> <strong>Mass add units</strong><br /> <input type="hidden" name="mode" value="mass_add_armies" /> <input type="hidden" name="campaign" value="{id}" /> {team_list} <br /> <textarea name="army_names" rows="10" cols="40">{grabbed_armies}</textarea> <br /> <input type="submit" value="Add armies" /> <br /><br /> </form> <form action="web.py" id="grab_armies_form_cities" method="get" accept-charset="utf-8" style="display:block; float:right; border: 0px solid #000; margin-right:20px;"> <strong>Grab armies</strong><br /> <input type="hidden" name="mode" value="setup_campaign" /> <input type="hidden" name="campaign" value="{id}" /> <label for="coords">Coords: </label>{coords_cities}<br /> <label for="radius">Radius: </label><input type="text" name="radius" id="radius" value="10" /><br /> <input type="submit" value="Grab armies" /> <br /><br /> </form> <form action="web.py" id="grab_armies_form" method="get" accept-charset="utf-8" style="display:block; float:right; border: 0px solid #000; margin-right:20px;"> <strong>Grab armies</strong><br /> <input type="hidden" name="mode" value="setup_campaign" /> <input type="hidden" name="campaign" value="{id}" /> <label for="coords">Coords: </label><input type="text" name="coords" id="coords" value="{default_coods}" /><br /> <label for="radius">Radius: </label><input type="text" name="radius" id="radius" value="10" /><br /> <input type="submit" value="Grab armies" /> <br /><br /> </form> <form action="exec.py" method="post" accept-charset="utf-8"> <input type="hidden" name="mode" id="mode" value="setup_campaign_commit" /> <input type="hidden" name="id" id="id" value="{id}" /> Editing: {name_text} <br /><br /> <table border="0" cellspacing="5" cellpadding="5"> <tr> <td><label for="turn">Turn:</label></td> <td style="padding: 1px;">{turn_text}</td> <td width="5"> </td> <td><label for="turn">Sides:</label></td> <td style="padding: 1px;">{sides_text}</td> </tr> </table> <br /> <input type="submit" value="Perform edit" /> </form> <br /><br />""".format( id = campaign_id, name = the_campaign.name, turn = the_campaign.turn, name_text = common.text_box("name", the_campaign.name, size=20), turn_text = common.text_box("turn", the_campaign.turn, size=5), sides_text = common.text_box("sides", the_campaign.sides, size=5), team_list = team_f.structured_list(cursor, include_irs=True), grabbed_armies = grabbed_armies, last_battle = last_battle.id, coords_cities = coords_cities, default_coods = "%s, %s" % (last_battle.x, last_battle.y), )) # Sides and teams side_form = ['<select id="side_menu">'] for s in range(1, the_campaign.sides+1): side_form.append('<option value="{s}">{s}</option>'.format(s=s)) side_form.append("</select>") side_form = "".join(side_form) # Form JS js = """ var side = $("#side_menu").attr("value"); var team_id = $("#new_team").attr("value"); var team_name = $("#new_team :selected").text(); team_list_content = $("#team_list_" + side).html(); if (team_list_content != "") { $("#team_list_" + side).html(team_list_content + ", " + team_name); } else { $("#team_list_" + side).html(team_name); } $("#ajax_target").load("exec.py", {mode: "add_team_to_campaign", campaign: %s, side: side, team: team_id}); $("#new_team").focus(); return false; """ % campaign_id js = js.replace("\t", "").replace("\n", "") output.append(''' <form action="" onsubmit='{js}' method="post" accept-charset="utf-8"> {team_list} {side} <input type="submit" value="Add" /> </form> <!-- PY --> <form action="exec.py" method="post" accept-charset="utf-8"> <input type="hidden" name="mode" value="edit_campaign_armies" /> <input type="hidden" name="campaign" value="{c}" /> <input type="submit" value="Apply armies" /> <!-- PYEND --> <table border="0" cellspacing="0" cellpadding="5" style="width:99%"> <tr class="row2"> <th width="15">#</th> <th>Teams</th> </tr> '''.format( c=campaign_id, team_list=team_f.structured_list(cursor, include_irs=True, field_id="new_team"), side=side_form, js=js, )) army_ids = [] the_campaign.get_sides_full(cursor) the_campaign.get_armies_full(cursor) campaign_armies = campaign_q.get_campaign_armies_from_turn(cursor, the_campaign.turn) teams_on_side_str = [] for s in range(1, the_campaign.sides+1): teams_on_side = the_campaign.sides_full[s] if len(teams_on_side) > 0: teams_on_side_str = ['<table border="0" cellspacing="0" cellpadding="5" width="100%">'] for t in teams_on_side: where = "campaign=%d and team=%d" % (campaign_id, t['team']) # Display "make secret" or "make public" public_display, secret_display = "", "" if t['secret']: secret_display = "display: none;" else: public_display = "display: none;" teams_on_side_str.append(""" <tr id="team_row_{t}" class="row1"> <td width="100">{name}</td> <td width="65"> {started} -> {finished} </td> <td>{remove}</td> <td> <a href="#" id="team_public_{t}" onclick="$('#ajax_target').load('web.py', {{mode:'campaign_team_public', team:{t}, campaign:{c}}}); {show_hide} return false;" class="mini_link" style="{public_display}">Make public</a> <a href="#" id="team_secret_{t}" onclick="$('#ajax_target').load('web.py', {{mode:'campaign_team_secret', team:{t}, campaign:{c}}}); {show_hide} return false;" class="mini_link" style="{secret_display}'">Make secret</a> </td> </tr> """.format( t = t['team'], c = campaign_id, name=team_dict[t['team']].name, started=common.doubleclick_text_full("campaign_teams", "started", where, t['started'], size=2), finished=common.doubleclick_text_full("campaign_teams", "finished", where, t['finished'], size=2), remove='''<a href="#" onclick='$("#ajax_target").load("exec.py", {mode: "remove_team_from_campaign", campaign: %d, team: %d, side: %d}); $("#team_row_%d").hide(); return false;'>Remove</a>''' % (campaign_id, t['team'], s, t['team']), show_hide = "$('#team_public_%d').toggle(); $('#team_secret_%d').toggle();" % (t['team'], t['team']), public_display = public_display, secret_display = secret_display, )) # Now to put in the armies form army_form = [] garrison_form = [] team_armies = army_q.get_armies_from_team(cursor, t['team'], include_garrisons=True) # the_campaign.get_armies_full for army_id, the_army in team_armies.items(): selected = False start_finish = "" if army_id in the_campaign.armies_full: selected = True where = "campaign=%d and army=%d" % (campaign_id, army_id) start_finish = "%s -> %s" % ( common.doubleclick_text_full("campaign_armies", "started", where, the_campaign.armies_full[army_id]['started'], size=2), common.doubleclick_text_full("campaign_armies", "finished", where, the_campaign.armies_full[army_id]['finished'], size=2)) # Is it selected? if selected: checked = "checked='checked'" rclass = "selected_army" else: checked = "" rclass = "" # Is it being used elsewhere this turn? elsewhere = "<td> </td>" if army_id in campaign_armies: if campaign_id in campaign_armies[army_id]: elsewhere_count = len(campaign_armies[army_id]) - 1 else: elsewhere_count = len(campaign_armies[army_id]) if elsewhere_count == 1: elsewhere = "<td style='background-color:#700;'> </td>" elif elsewhere_count == 2: elsewhere = "<td style='background-color:#B00;'> </td>" elif elsewhere_count > 2: elsewhere = "<td style='background-color:#F00;'> </td>" army_s = '''<tr id="row_{a}" class="{rclass}"> <td><label for="a_{a}" style="width:100%; display:block;">{name}</label></td> <td><input type="checkbox" name="a_{a}" id="a_{a}" value="True" onchange="if ($('#a_{a}').attr('checked')) {{$('#row_{a}').addClass('selected_army');}} else {{$('#row_{a}').removeClass('selected_army');}}" {checked}/></td> <td>{start_finish} </td> {elsewhere} </tr>'''.format( a = army_id, name = the_army.name, # cb = common.check_box("a_%d" % army_id, checked=selected), start_finish=start_finish, checked = checked, rclass = rclass, elsewhere = elsewhere, ) if the_army.garrison: garrison_form.append(army_s) else: army_form.append(army_s) army_ids.append(army_id) teams_on_side_str.append(""" <tr> <td colspan="4"> <table border="0" cellspacing="0" cellpadding="0"> <tr> <td width="300"> <table border="0" cellspacing="0" cellpadding="3"> {armies} </table> </td> <td> <table border="0" cellspacing="0" cellpadding="3"> {garrisons} </table> </td> <td> </td> </tr> </table> </td> </tr>""".format( armies = "".join(army_form), garrisons = "".join(garrison_form), c_id = campaign_id, team = t['team'], )) teams_on_side_str.append("</table>") output.append(""" <tr> <td colspan="2"><hr /></td> </tr> <tr> <td><strong>{s}</strong></td> <td> {teams} <br /> <span id="team_list_{s}"></span> </td> </tr> """.format( s=s, teams="".join(teams_on_side_str), # teams=", ".join([team_dict[t].name for t in teams_on_side]), )) # Field for the ids of the armies listed that we need to sort out output.append('<input type="hidden" name="army_ids" value="%s" />' % ",".join([str(a) for a in army_ids])) output.append('<!-- PY --><tr><td colspan="2"><input type="submit" value="Apply armies" /></td></tr><!-- PYEND -->') output.append('''</table> <!-- PY --></form><!-- PYEND --> <br />''') # Delete button output.append(""" <form id="delete_form" action="exec.py" method="post" accept-charset="utf-8"> <input type="hidden" name="campaign" id="campaign" value="{id}" /> <input type="hidden" name="mode" id="mode" value="remove_campaign" /> <input style="float:right; margin-right:100px;" type="button" value="Delete campaign" onclick="var answer = confirm('Delete {esc_name}?') if (answer) $('#delete_form').submit();" /> </form>""".format( id = campaign_id, esc_name = common.js_name(the_campaign.name), )) output.append(common.onload("$('#new_team').focus();")) output.append('<a href="web.py?mode=list_battles&campaign=%d" class="block_link">List battles</a>' % campaign_id) output.append("</div>") return "".join(output)
def main(cursor, turn=-1): output = ["""<div style="padding: 5px;">"""] onload = [] turn = int(common.get_val("turn", turn)) if turn < 1: turn = common.current_turn() campaign_dict = campaign_q.get_campaigns_from_turn(cursor, turn) team_dict = team_q.get_all_teams(cursor) # Form to select a different turn output.append(""" <!-- <div style="float:right;border:1px solid #000; width: 60%%;" id="turn_info"> </div> --> <form action="web.py" method="get" accept-charset="utf-8"> <input type="hidden" name="mode" id="mode" value="list_campaigns" /> Turn: <input type="text" name="turn" value="%s" /> <input type="submit" value="Show" /> </form> %s <br /><br />""" % ( turn, common.onload("$('#turn_info').load('web.py',{'mode':'turn_info','ajax':'True'});"))) # Now the actual table output.append(""" <table border="0" cellspacing="0" cellpadding="5"> <tr class="row2"> <th>Turn</th> <th>Name</th> <th>Sides</th> <th> </th> <th> </th> </tr>""") count = 1 for campaign_id, the_campaign in campaign_dict.items(): count += 1 the_campaign.get_sides_basic(cursor) team_string = [] for s in range(1, the_campaign.sides+1): teams_on_side = the_campaign.sides_basic[s] if teams_on_side == []: teams_on_side_str = "None" else: teams_on_side_str = ", ".join([team_dict[t].name for t in teams_on_side]) team_string.append("""{s}: {teams}""".format( s=s, teams=teams_on_side_str, )) team_string = "<br />".join(team_string) output.append(""" <tr class="row{count}"> <td>{turn}</td> <td><strong>{name}</strong></td> <td>{teams}</td> <td style="padding:0px;"><a href="web.py?mode=setup_campaign&campaign={campaign_id}" class="block_link">Setup</a></td> <td style="padding:0px;"><a href="web.py?mode=list_battles&campaign={campaign_id}" class="block_link">Battles</a></td> </tr> <!-- <tr class="row0"> <td colspan="5" id="camp_{campaign_id}" style="padding:0px;"></td> </tr> --> """.format( turn=turn, # count=1, count=count%2, name=the_campaign.name, teams=team_string, campaign_id=campaign_id, )) # onload.append("$('#camp_%(id)d').load('web.py', {'mode':'list_battles', 'ajax':'True', 'campaign':'%(id)d'});" % { # "id": campaign_id, # }) # New campaign count += 1 output.append(""" <!-- PY --> <tr class="row{count}"> <form action="exec.py" id="add_campaign_form" method="post" accept-charset="utf-8"> <input type="hidden" name="mode" id="mode" value="add_campaign" /> <td style="padding: 1px;"><input type="text" name="turn" value="{turn}" size="5"/></td> <td style="padding: 1px;"><input type="text" name="name" id="name" value="" /></td> <td style="padding: 1px;"><input type="text" name="sides" value="2" size="3"/></td> <td style="padding: 0px;" colspan="2"> <!-- <a class="block_link" href="#" onclick="$('#add_campaign_form').submit(); return false;">Add</a> --> <input type="submit" value="Add" /> </td> </form> {onload} </tr> <!-- PYEND --> """.format( turn=turn, count=count%2, onload=common.onload("$('#name').focus();%s" % "".join(onload)), )) output.append("</table></div>") return "".join(output)
def display_stat_table(cursor, team_id, list_size=10): # Get stats dict stat_dict = stat_q.get_stats_from_team(cursor, team_id) if len(stat_dict) < 1: return "The stats for team %d do not exist" % team_id teams_dict = team_q.get_all_teams(cursor) the_team = teams_dict[team_id] output = [] output.append( """ <div class="ti_section" id="overview_div"> <table border="0" cellspacing="0" cellpadding="5" style="width:100%;"> <tr class="row2"> <th>Turn</th> <th>Population</th> <th>Slaves</th> <th>Resources</th> <th>Production</th> <th>Upkeep</th> <th>Army</th> <th>Navy</th> <th>Airforce</th> <th>Operatives</th> <th>Mages</th> <th>Land</th> <th>Cities</th> <th>Losses</th> </tr>""" ) i = -1 for k, the_stat in stat_dict.items(): i += 1 if i > list_size: continue # Currently the_res = res_dict.Res_dict(the_stat.resources) materials = the_res.get("Materials") if materials < 0: resources_string = '<strong class="neg">%s</strong>' % format(int(materials), ",") else: resources_string = format(int(materials), ",") # Production the_res = res_dict.Res_dict(the_stat.production) materials = the_res.get("Materials") if materials < 0: production_string = '<strong class="neg">%s</strong>' % format(int(materials), ",") else: production_string = format(int(materials), ",") output.append( """ <tr class="row%(count)s"> <td>Turn %(t)s</td> <td>%(population)s</td> <td>%(slaves)s</td> <td>%(resources)s</td> <td>%(production)s</td> <td>%(upkeep)s</td> <td>%(army_size)s</td> <td>%(navy_size)s</td> <td>%(airforce_size)s</td> <td>%(operatives)s</td> <td>%(mages)s</td> <td>%(land_controlled)s</td> <td>%(city_count)s</td> <td>%(war_losses)s</td> </tr> """ % { "count": i % 2, "t": the_stat.turn, "population": common.number_format(the_stat.population), "slaves": common.number_format(the_stat.slaves), "resources": resources_string, "production": production_string, "upkeep": common.number_format(int(the_stat.upkeep)), "army_size": common.number_format(the_stat.army_size), "navy_size": common.number_format(the_stat.navy_size), "airforce_size": common.number_format(the_stat.airforce_size), "operatives": common.number_format(the_stat.operatives), "mages": common.number_format(the_stat.mages), "land_controlled": common.number_format(the_stat.land_controlled), "city_count": common.number_format(the_stat.city_count), "war_losses": common.number_format(the_stat.war_losses), } ) output.append("</table></div>") return "".join(output)
def check_army_bases(cursor, verbose): team_dict = team_q.get_all_teams(cursor) army_dict = army_q.get_armies_from_team_list(cursor, list(team_dict.keys())) city_dict = city_q.get_live_cities(cursor) relations = team_q.get_relations(cursor)# [Host][Visitor] # Build up a shortlist dict of cities by team city_by_team = {} for team_id, the_team in team_dict.items(): if team_id not in city_by_team: city_by_team[team_id] = [] for city_id, the_city in city_dict.items(): if the_city.team == team_id or relations.get(the_city.team, {}).get(team_id, {}).get('border', team_dict[the_city.team].default_borders) >= team.border_states.index("Allied"): city_by_team[team_id].append(city_id) # Now to run through the armies and find their paths new_bases = set() # for i in progressbar(range(15), "Computing: ", 40): # for army_id, the_army in army_dict.items(): if verbose: it = cli_f.progressbar(army_dict.items(), "military_check.check_army_bases: ", 40, with_eta = True) else: it = army_dict.items() for army_id, the_army in it: army_terrain = mapper_q.get_terrain(cursor, the_army.x, the_army.y) for city_id in city_by_team[the_army.team]: if army_terrain < 1: if not the_city.port: continue the_city = city_dict[city_id] if the_city.dead > 0: continue dist = path_f.pythagoras((the_army.x, the_army.y), (the_city.x, the_city.y)) if dist < 10: the_army.base = city_id the_army.distance = (dist/map_data.movement_speeds['Marching'])*10# Distance over speed in km, 1 distance unit is 10k new_bases.add(army_id) # Extend the search a little if army_id not in new_bases: for city_id in city_by_team[the_army.team]: if army_terrain < 1: if not the_city.port: continue the_city = city_dict[city_id] dist = path_f.pythagoras((the_army.x, the_army.y), (the_city.x, the_city.y)) if dist < 30: the_army.base = city_id the_army.distance = (dist/map_data.movement_speeds['Marching'])*10# Distance over speed in km, 1 distance unit is 10k new_bases.add(army_id) # Extend the search a little if army_id not in new_bases: for city_id in city_by_team[the_army.team]: if army_terrain < 1: if not the_city.port: continue the_city = city_dict[city_id] dist = path_f.pythagoras((the_army.x, the_army.y), (the_city.x, the_city.y)) if dist < 60: the_army.base = city_id the_army.distance = (dist/map_data.movement_speeds['Marching'])*10# Distance over speed in km, 1 distance unit is 10k new_bases.add(army_id) # If we can't find an easy solution we start pathing if army_id not in new_bases: fastest_path = (-1, 9999999) for city_id in city_by_team[the_army.team]: the_city = city_dict[city_id] # Small cities won't support an army a long way away right? if the_city.size < 5000: continue # Is it a fleet? if army_terrain < 1: if not the_city.port: continue # Now lets try water dist = path_f.path(cursor, ((the_army.x, the_army.y), (the_city.x, the_city.y)), move_speed="Sailing", move_type="Sail") if dist.time_cost < fastest_path[1]: fastest_path = (city_id, dist.time_cost) else: # I'm sure there's a way to improve this... dist = path_f.path(cursor, ((the_army.x, the_army.y), (the_city.x, the_city.y)), move_speed="Marching", move_type="Medium foot") if dist.time_cost == 0: continue # if army_id == 960 and city_id == 1098: # print("") # print(dir(dist)) # print(((the_army.x, the_army.y), (the_city.x, the_city.y))) # print(dist.time_cost) # print(dist.walk_distance) # print(len(dist.steps)) # print("") if dist.time_cost < fastest_path[1]: fastest_path = (city_id, dist.time_cost) the_army.base = fastest_path[0] the_army.distance = fastest_path[1] new_bases.add(army_id) # Reset all armies query = """UPDATE armies SET base = -1, distance = -1 WHERE garrison = 0;""" try: cursor.execute(query) except Exception as e: raise Exception("Database error: %s\nQuery: %s" % (str(e.args[0]).replace("\n",""), query)) for a in new_bases: query = """UPDATE armies SET base = %d, distance = %d WHERE id = %d;""" % (army_dict[a].base, army_dict[a].distance, a) try: cursor.execute(query) except Exception as e: raise Exception("Database error: %s\nQuery: %s" % (str(e.args[0]).replace("\n",""), query)) # Garrisons automatically go to their city query = """UPDATE armies SET base = garrison, distance = 0 WHERE garrison > 0;""" try: cursor.execute(query) except Exception as e: raise Exception("Database error: %s\nQuery: %s" % (str(e.args[0]).replace("\n",""), query))
def main(cursor, battle_id = -1): battle_id = int(common.get_val('battle', battle_id)) if battle_id < 1: return "No battle selected" the_battle = battle_q.get_one_battle(cursor, battle_id) # If we're being sent the info from the view_map page then this is the new location we need new_location = common.get_val('location', "") if new_location == "": new_location = "%s,%s" % (the_battle.x, the_battle.y)# default value # Get some other stuff cities_dict = city_q.get_live_cities(cursor) team_dict = team_q.get_all_teams(cursor) the_campaign = campaign_q.get_one_campaign(cursor, the_battle.campaign) names = {0:"No city"} for c, the_city in cities_dict.items(): names[c] = the_city.name city_keys = [0] city_keys.extend(list(cities_dict.keys())) output = ["<div style='padding: 5px;'>"] # output.append('<a href="web.py?mode=perform_battle&battle={0}" class="block_link">Perform</a>'.format(battle_id)) output.append(""" <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={campaign_id}" class="block_link" style="display:inline;">Setup campaign</a> <a href="web.py?mode=list_battles&campaign={campaign_id}" class="block_link" style="display:inline;">List battles</a> <a href="web.py?mode=perform_battle&battle={battle_id}" class="block_link" style="display:inline;">Perform</a> <br /><br /> <!-- PY --> <form action="exec.py" method="post" accept-charset="utf-8"> <!-- PYEND --> <input type="hidden" name="mode" value="edit_battle_commit" /> <input type="hidden" name="id" value="{battle_id}" /> <input type="hidden" name="campaign" value="{campaign_id}" /> Editing: {name_text} <br /><br /> <table border="0" cellspacing="5" cellpadding="5"> <tr> <td><label for="start">Start:</label></td> <td style="padding: 1px;">{battle_start_text}</td> <td width="5"> </td> <td><label for="duration">Duration:</label></td> <td style="padding: 1px;">{battle_duration_text}</td> </tr> <tr> <td style="padding: 0px;"> <a class="block_link" href="web.py?mode=view_map&new_mode=setup_battle&battle={battle_id}"">Location:</a> </td> <td style="padding: 1px;">{battle_location_text}</td> <td> </td> <td><label for="city">City:</label></td> <td style="padding: 1px;">{city_menu}</td> </tr> <tr> <td><label for="type">Type:</label></td> <td style="padding: 1px;">{type}</td> <td> </td> <td><label for="result">Result:</label></td> <td style="padding: 1px;">{result}</td> </tr> </table> <!-- PY --> <br /> <input type="submit" value="Perform edit" /> </form> <!-- PYEND --> <form id="delete_form" action="exec.py" method="post" accept-charset="utf-8"> <input type="hidden" name="battle" id="battle" value="{battle_id}" /> <input type="hidden" name="mode" id="mode" value="remove_battle" /> <input style="float:right; margin-right:100px;" type="button" value="Delete battle" onclick="var answer = confirm('Delete {esc_name}?') if (answer) $('#delete_form').submit();" /> </form> <br /><br />""".format( turn = common.current_turn(), battle_id = battle_id, campaign_id = the_battle.campaign, name = the_battle.name, esc_name = common.js_name(the_battle.name), name_text = common.text_box("name", the_battle.name, size=20), battle_location_text = common.text_box("location", new_location, 10), battle_start_text = common.text_box("start", the_battle.start, 3), battle_duration_text = common.text_box("duration", the_battle.duration, 3), city_menu = common.option_box( name='city', elements=names, element_order=city_keys, custom_id="", selected=the_battle.city, ), type = common.option_box("type", elements = battle.battle_types, element_order = [], selected=battle.battle_types[the_battle.type]), result = common.option_box("result", elements = battle.result_types, element_order = [], selected=battle.result_types[the_battle.result]), )) output.append("</div>") return "".join(output)
def main(cursor): turn = int(common.get_val("turn", -1)) if turn < 1: turn = common.current_turn() battle_dict = battle_q.get_battles_from_turn(cursor, turn) teams_dict = team_q.get_all_teams(cursor) output = [] output.append(""" <div style="padding: 5px;"> <form action="web.py" method="get" accept-charset="utf-8"> <a href="list_battles" style="text-align:left;" class="block_link">This turn's battles</a> <br /> <input type="hidden" name="mode" id="mode" value="list_battles" /> Turn: <input type="text" name="turn" value="%s" /> <input type="submit" value="Show" /> </form> <br /><br />""" % (turn)) output.append("""<table border="0" cellspacing="0" cellpadding="5"> <tr class="row2"> <th>Turn</th> <th>Battle name</th> <th>Participants</th> <th> </th> <th> </th> </tr> """) count = -1 for b, the_battle in battle_dict.items(): participants = the_battle.get_participants(cursor) participants_list = [] for t, s in participants.items(): if s: participants_list.append("<em style='color:#555;'>%s</em>" % teams_dict[t].name) else: participants_list.append(teams_dict[t].name) count += 1 output.append(""" <tr class="row%(count)s"> <td>%(turn)s</td> <td>%(name)s</td> <td>%(participants)s</td> <td style="padding:0px;"><a href="web.py?mode=edit_battle&battle=%(battle_id)s" class="block_link">Edit</a></td> <td style="padding:0px;"><a href="view_battle&battle=%(battle_id)s" class="block_link">View</a></td> </tr> """ % { "count": count%2, "turn": turn, "name": the_battle.name, "participants": ", ".join(participants_list), "battle_id": the_battle.id, }) count += 1 output.append(""" <tr class="row%(count)s"> <form action="exec.py" id="add_battle_form" method="post" accept-charset="utf-8"> <input type="hidden" name="mode" id="mode" value="add_battle" /> <td style="padding: 1px;"><input type="text" name="battle_turn" value="%(turn)s" size="5"/></td> <td style="padding: 1px;"><input type="text" name="name" id="name" value="" /></td> <td> </td> <td style="padding: 0px;" colspan="2"><a class="block_link" href="#" onclick="$('#add_battle_form').submit();">Add</a></td> </form> %(onload)s </tr> """ % { "turn": turn, "count": count%2, "onload": common.onload("$('#name').focus();"), }) output.append("</table></div>") return "".join(output)
def main(cursor): team_id = int(common.get_val('team', 0)) if team_id < 1: player_dict = player_q.get_all_players(cursor) else: player_dict = player_q.get_players_from_team(cursor, team_id) team_dict = team_q.get_all_teams(cursor) last_turn_count = 0 last_three_turns_count = 0 output = [""]# That's later swapped out for something else output.append(' <a href="web.py?mode=get_players">Get new players</a>') output.append(""" <table border="0" cellspacing="0" cellpadding="5" style="width: 100%;"> <tr class="row2"> <th>Player name</th> <th>Team</th> <th>Last posted</th> <th>Daemonic</th> <th colspan="2"> </th> </tr>""") current_turn = common.current_turn() count = -1 if len(player_dict) > 0: for player_id, the_player in player_dict.items(): if the_player.last_posted >= current_turn: last_turn_count += 1 if the_player.last_posted >= current_turn-3: last_three_turns_count += 1 count += 1 if the_player.team in team_dict: team_name = team_dict[the_player.team].name else: team_name = "None" output.append(""" <tr class="row%(row)d" id="%(player_id)d"> <td>%(name)s</td> <td>%(team)s</td> <td>%(daemon)s</td> <td>%(last_posted)s</td> <td style="padding:0px;"><a href="http://woarl.com/board/ucp.php?i=pm&mode=compose&u=%(player_id)s" class="block_link">PM</a></td> <td style="padding: 0px;"><a class="block_link" href="web.py?mode=edit_player&player=%(player_id)d">Edit</a></td> </tr> """ % { 'row': (count % 2), 'player_id': the_player.id, 'name': the_player.name, 'team': team_name, 'last_posted': the_player.last_posted, "daemon": "%s, %s" % (player.progressions[the_player.progression], player.daemon_types[the_player.daemon_type]), }) output.append("</table>") output[0] = "Last turn: %s, Last 3 turns: %s" % (last_turn_count, last_three_turns_count) return "".join(output)
def main(cursor): wonders_dict = wonder_q.get_all_wonders(cursor) cities_dict = city_q.get_all_cities(cursor) teams_dict = team_q.get_all_teams(cursor) output = [] output.append(""" <table border="0" cellspacing="0" cellpadding="5" style="width: 100%;"> <tr class="row2"> <th>Wonder name</th> <th>City</th> <th>Points</th> <th>Materials</th> <th>Description</th> <th> </th> </tr>""") count = -1 if len(wonders_dict) > 0: for wonder_id, the_wonder in wonders_dict.items(): count += 1 # May need a key-exception try-catch block around this the_city = cities_dict[the_wonder.city] # city_string = "%s <em>(%s)</em>" % (the_city.name, teams_dict[the_city.team].name) output.append(""" <tr class="row%(row)d" id="%(wonder_id)d"> <td>%(name)s</td> <td>%(city)s <em>%(team)s</em></td> <td>%(completion)s/%(point_cost)s</td> <td>%(material_cost)s</td> <td>%(description)s</td> <td style="padding: 0px;"><a class="block_link" href="web.py?mode=edit_wonder&wonder=%(wonder_id)d">Edit wonder</a></td> </tr> """ % { 'row': (count % 2), 'wonder_id': the_wonder.id, 'name': common.doubleclick_text("wonders", "name", the_wonder.id, the_wonder.name, "font-weight:bold"), "completion": common.doubleclick_text("wonders", "completion", the_wonder.id, the_wonder.completion, size=5), "point_cost": common.doubleclick_text("wonders", "point_cost", the_wonder.id, the_wonder.point_cost, size=5), "material_cost": common.doubleclick_text("wonders", "material_cost", the_wonder.id, the_wonder.material_cost, size=5), "description": the_wonder.description, 'city': the_city.name, "team": teams_dict[the_wonder.team].name, }) cities_dict = city_q.get_live_cities(cursor) names = {} for c, the_city in cities_dict.items(): names[c] = the_city.name # Add new wonder count += 1 output.append(""" <tr class="row%(row)d"> <form action="exec.py" id="add_wonder_form" method="post" accept-charset="utf-8"> <input type="hidden" name="mode" value="add_wonder" /> <td style="padding: 1px;"><input type="text" name="name" id="new_name" value="" /></td> <td style="padding: 0px;">%(city_menu)s</td> <td style="padding: 2px;"><input type="text" name="point_cost" value="" size="7"/></td> <td style="padding: 2px;"><input type="text" name="material_cost" value="" size="7"/></td> <td style="padding: 2px;"><input type="text" style="width:95%%;" name="description" value=""/></td> <td style="padding: 0px;"><a class="block_link" href="#" onclick="$('#add_wonder_form').submit();">Add</a></td> </form> %(onload)s </tr> """ % { 'row': (count % 2), "city_menu": common.option_box( name='city', elements=names, element_order=cities_dict.keys(), custom_id="", # selected=the_artefact.city, ), "onload": common.onload("$('#new_name').focus();"), }) output.append("</table>") return "".join(output)
def main(cursor): # Get team Id team_id = int(common.get_val('team', 0)) city_id = int(common.get_val('city', 0)) if team_id < 1 and city_id < 1: return "<div style='padding: 5px;'>%s</div>" % common.select_team_form(cursor, 'list_operatives') # Handles for later city_dict = city_q.get_all_cities(cursor) team_dict = team_q.get_all_teams(cursor) # Build team the_team = team_dict[team_id] if team_id > 0: operatives_dict = operative_q.get_operatives_from_team(cursor, team=team_id) elif city_id > 0: operatives_dict = operative_q.get_operatives_from_city(cursor, city=city_id) # So we can sort them by team team_location = {} for o, the_op in operatives_dict.items(): o_team = city_dict[the_op.city].team if o_team not in team_location: team_location[o_team] = [] team_location[o_team].append(o) output = [] output.append(""" <table border="0" cellspacing="0" cellpadding="5" style="width: 100%;"> <tr class="row2"> <th>Id</th> <th>Size</th> <th>Stealth</th> <th>Observation</th> <th>Integration</th> <th>Sedition</th> <th>Sabotage</th> <th>Assassination</th> <th>Location</th> <th>Arrival</th> <th> </th> <th> </th> </tr>""") count = -1 if len(operatives_dict) > 0: for city_team, op_list in team_location.items(): for operative_id, the_operative in operatives_dict.items(): if the_operative.id not in op_list: continue count += 1 # Is it dead? if the_operative.died == 0: life_action = '<a href="exec.py?mode=kill_operative&operative=%d" class="block_link">Kill</a>' % operative_id life_action = '''<a href="#" class="block_link" onclick="$.get('exec.py', {mode: 'kill_operative', operative:%d}, function () {$('#life_%d').html('<div class=\\'block_link\\'>Killed</div>');}); return false;">Kill</a>''' % (operative_id, operative_id) else: life_action = '<a href="exec.py?mode=revive_operative&operative=%d" class="block_link">Revive (%d)</a>' % (operative_id, the_operative.died) life_action = '''<a href="#" class="block_link" onclick="$.get('exec.py', {mode: 'revive_operative', operative:%d}, function () {$('#life_%d').html('<div class=\\'block_link\\'>Revived</div>');}); return false;">Revive (%d)</a>''' % (operative_id, operative_id, the_operative.died) output.append(""" <tr class="row{row}" id="{operative_id}"> <td>{name}</td> <td>{size}</td> <td>{stealth}</td> <td>{observation}</td> <td>{integration}</td> <td>{sedition}</td> <td>{sabotage}</td> <td>{assassination}</td> <td>{city} ({city_team})</td> <td>{arrival}</td> <td style="padding: 0px;" id="life_{operative_id}">{life_action}</td> <td style="padding: 0px;"><a href="web.py?mode=edit_operative&operative={operative_id}" class="block_link">Edit</a></td> </tr> """.format( row = (count % 2), team_id = team_id, operative_id = operative_id, name = common.doubleclick_text("operatives", "name", operative_id, the_operative.name, "font-weight:bold"), size = the_operative.size, arrival = the_operative.arrival, stealth = the_operative.stealth, observation = the_operative.observation, integration = the_operative.integration, sedition = the_operative.sedition, sabotage = the_operative.sabotage, assassination = the_operative.assassination, city = city_dict[the_operative.city].name, city_team = team_dict[city_team].name, life_action = life_action, )) # Add unit type city_dict = city_q.get_live_cities(cursor) names = {} for c, the_city in city_dict.items(): names[c] = the_city.name if count <= 20: onload = common.onload("$('#size').focus();") else: onload = '' count += 1 if team_id > 0: output.append(""" <tr class="row%(row)d"> <form action="exec.py" method="post" id="new_operative_form" accept-charset="utf-8"> <input type="hidden" name="mode" value="create_new_operative" /> <input type="hidden" name="team" value="%(team_id)s" /> <td style="padding: 1px;"> <input type="text" name="name" id="name" value="" size="6"/> </td> <td style="padding: 1px;"> <input type="text" name="size" id="size" value="1" size="3"/> </td> <td style="padding: 1px;"> <input type="text" name="stealth" id="stealth" value="1" size="3"/> </td> <td style="padding: 1px;"> <input type="text" name="observation" id="observation" value="1" size="3"/> </td> <td style="padding: 1px;"> <input type="text" name="integration" id="integration" value="1" size="3"/> </td> <td style="padding: 1px;"> <input type="text" name="sedition" id="sedition" value="1" size="3"/> </td> <td style="padding: 1px;"> <input type="text" name="sabotage" id="sabotage" value="1" size="3"/> </td> <td style="padding: 1px;"> <input type="text" name="assassination" id="assassination" value="1" size="3"/> </td> <td style="padding: 1px;">%(location)s</td> <td style="padding: 1px;"><input type="text" name="arrival" id="arrival" value="%(arrival)s" size="4"/></td> <td colspan="2" style="padding: 0px;"><a class="block_link" onclick="$('#new_operative_form').submit(); return false;" href="#">Add</a></td> %(onload)s </form> </tr> """ % { 'row': (count % 2), "team_id": team_id, 'location': common.option_box( name='city', elements=names, element_order=city_dict.keys(), custom_id="", ), "arrival": common.current_turn(), 'onload': onload, }) output.append("</table>") if team_id > 0: page_data['Title'] = "List operatives from %s" % team_dict[team_id].name elif city_id > 0: page_data['Title'] = "List operatives from %s (%s)" % (city_dict[city_id].name, team_dict[city_dict[city_id].team].name) return "".join(output)