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): 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)) text_location = common.get_val('location', "") if team_id < 1: return "<div style='padding: 5px;'>{0}</div>".format(common.select_team_form(cursor, 'list_cities')) cities_dict = city_q.get_cities_from_team(cursor, team = team_id, include_dead = True) # Work out city points total_points = 0 for city_id, the_city in cities_dict.items(): if the_city.dead == True: continue total_points += the_city.point_value() output = [] output.append(""" <table border="0" cellspacing="0" cellpadding="5" style="width: 100%;"> <tr class="row2"> <th>City name</th> <th colspan="3">Location</th> <th>Port</th> <th>Secret</th> <th>Dead</th> <th>Nomadic</th> <th>Overlap</th> <th>Wonder speed</th> <th>Population</th> <th>Slaves</th> <th>Happiness</th> <th colspan="2"> </th> </tr>""") # Work out how fast it can build wonders city_wonder_speed = {} for c1, city1 in cities_dict.items(): city_wonder_speed[c1] = math.floor((city1.population + city1.slaves)/1000) c1_loc = (cities_dict[c1].x, cities_dict[c1].y) for c2, city2 in cities_dict.items(): if city2.dead: continue if c2 != c1: amount = city_rules.wonder_build_rate(city2, city1) city_wonder_speed[c1] += amount city_wonder_speed[c1] = common.number_format(int(city_wonder_speed[c1])) count = -1 if len(cities_dict) > 0: for city_id, the_city in cities_dict.items(): count += 1 city_share = 0 if not the_city.dead: if total_points > 0: city_share = round(the_city.point_value()/total_points*100,1) # Happiness happiness = city.happiness_str(the_city.happiness) if happiness == "Rebellious": happiness = '<span style="font-weight:bold;color:#A00;">Rebellious</span>' if happiness == "Utopian": happiness = '<span style="font-weight:bold;color:#0A0;">Utopian</span>' output.append(""" <tr class="row%(row)d" id="%(city_id)d"> <td>%(name)s</td> <td>%(x)s</td> <td>%(y)s</td> <td style="padding: 0px;"><a class="block_link" href="web.py?mode=view_map&%(map_link)s">Map link</a></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>%(overlap)s</td> <td>%(wonder_speed)s</td> <td>%(population)s</td> <td>%(slaves)s</td> <td>%(happiness)s</td> <!--<td style="padding: 0px;"><a class="block_link" href="web.py?mode=view_city_trade&city=%(city_id)d">City trade</a></td>--> <td style="padding: 0px;"><a class="block_link" href="web.py?mode=view_city_matrix&city=%(city_id)d">City matrix</a></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, 'name': common.doubleclick_text("cities", "name", the_city.id, the_city.name, "font-weight:bold"), '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': "" if the_city.dead < 1 else common.doubleclick_text("cities", "dead", the_city.id, the_city.dead, "", size=3), 'nomadic': common.bstr(the_city.nomadic), 'overlap': the_city.overlap, 'population': common.doubleclick_text("cities", "population", the_city.id, the_city.population, ""), 'slaves': common.doubleclick_text("cities", "slaves", the_city.id, the_city.slaves, ""), "wonder_speed": city_wonder_speed[the_city.id], "happiness": happiness, }) # Add new city count += 1 output.append(""" <tr class="row%(row)d"> <form action="exec.py" id="add_city_form" method="post" accept-charset="utf-8"> <input type="hidden" name="mode" value="add_city" /> <input type="hidden" name="team" value="%(team_id)s" /> <td style="padding: 1px;"><input type="text" name="name" id="new_name" value="" /></td> <td style="padding: 0px;" colspan="2"> <a href="web.py?mode=view_map&new_mode=list_cities&team=%(team_id)s" class="block_link">Location:</a> </td> <td colspan="1" style="padding:1px;"> %(location)s </td> <td style="padding: 2px;"><input type="checkbox" name="port" value="True" /></td> <td style="padding: 2px;"><input type="checkbox" name="secret" value="True" /></td> <td style="padding: 2px;"><input type="text" name="dead" id="dead" value="0" size="3"/></td> <td style="padding: 2px;"><input type="checkbox" name="nomadic" value="True" /></td> <td> </td> <td> </td> <td style="padding: 1px;"><input type="text" name="population" value="" size="10"/></td> <td style="padding: 1px;"><input type="text" name="slaves" value="" size="10"/></td> <td style="padding: 2px;" colspan="3"><input type="submit" value="Add" /></td> <!-- <td style="padding: 0px;" colspan="3"><a class="block_link" href="#" onclick="$('#add_city_form').submit();">Add</a></td> --> </form> %(onload)s </tr> """ % { 'row': (count % 2), "team_id": team_id, "location": common.text_box("text_location", text_location, custom_id="", size="7"), "onload": common.onload("$('#new_name').focus();"), }) output.append("</table>") return "".join(output)
def main(cursor): # Get squad Id army_id = int(common.get_val('army', 0)) if army_id < 1: exit() the_army = army_q.get_one_army(cursor, army_id) squads_dict = squad_q.get_squads_from_army(cursor, army=army_id) monster_dict = monster_q.get_all_monsters(cursor) army_monsters_dict = monster_q.get_monsters_from_army(cursor, army_id) unit_dict = unit_q.get_units_from_team(cursor, the_army.team, special_units=True) output = [] output.append(""" <table border="0" cellspacing="0" cellpadding="5" style="width: 100%;"> <tr class="row2"> <th>Name</th> <th>Unit type</th> <th>Size</th> <th>Exp</th> <th> </th> </tr>""") count = -1 if len(squads_dict) > 0: for squad_id, the_squad in squads_dict.items(): if the_squad.unit not in unit_dict: continue count += 1 output.append(""" <tr class="row%(row)d" id="%(squad_id)d"> <td>%(name)s</td> <td>%(unit_type)s</td> <td>%(size)s</td> <td>%(exp)s</td> <td style="padding: 0px;"><a href="web.py?mode=edit_squad&squad=%(squad_id)d" class="block_link">Edit</a></td> </tr> """ % { 'row': (count % 2), "squad_id": squad_id, "name": common.doubleclick_text("squads", "name", squad_id, the_squad.name, "font-weight:bold", size=18), "unit_type": unit_dict[the_squad.unit].name, "size": common.doubleclick_text("squads", "amount", squad_id, the_squad.amount, size=7), "exp": common.doubleclick_text("squads", "experience", squad_id, the_squad.experience, size=7), }) else: output.append(""" <tr class="row0"> <td colspan="5">No squads in this army</td> </tr>""") count += 1 if len(army_monsters_dict) > 0: for monster_id, amount in army_monsters_dict.items(): if amount < 1: continue the_monster = monster_dict[monster_id] count += 1 output.append(""" <tr class="row{row}"> <td>{name}</td> <td><em>Monster</em></td> <td>{amount}</td> <td> </td> <td style="padding: 0px;"><a href="web.py?mode=edit_army_monster&army={army_id}&monster={monster_id}" class="block_link">Edit</a></td> </tr> """.format( row = (count % 2), army_id = army_id, monster_id = monster_id, name = the_monster.name, amount = common.doubleclick_text_full("army_monsters", "amount", "army = %d AND monster = %d" % (army_id, monster_id), amount, size=5), )) # Add new squad to army thingie names = {} for u, the_unit in unit_dict.items(): names[u] = the_unit.name count += 1 output.append(""" <tr class="row%(row)d"> <form action="exec.py" id="add_squad_form_%(army_id)d" method="post" accept-charset="utf-8"> <td style="padding: 1px;"> <input type="text" name="name" value=""/> <input type="hidden" name="team" value="%(team_id)s" /> <input type="hidden" name="mode" value="add_squad" /> <input type="hidden" name="army" value="%(army_id)s" /> </td> <td style="padding: 1px;">%(unit_type)s</td> <td style="padding: 1px;"><input type="text" name="size" value="" size="5"/></td> <td style="padding: 1px;"><input type="text" name="experience" value="" size="5"/></td> <td style="padding: 0px;"> <a class="block_link" href="#" onclick="$('#add_squad_form_%(army_id)d').submit();">Add</a> </td> </form> </tr> """ % { 'row': (count % 2), "army_id": army_id, "team_id": the_army.team, 'unit_type': common.option_box( name='unit_type', elements=names, element_order=unit_dict.keys(), custom_id="", ), }) output.append('</table>') return "".join(output)
def main(cursor): # Get team Id team_id = int(common.get_val('team', 0)) # Build team the_team = team_q.get_one_team(cursor, team_id) if team_id < 1: return "<div style='padding: 5px;'>%s</div>" % common.select_team_form(cursor, 'list_units') unit_dict = unit_q.get_units_from_team(cursor, team=team_id) equipment_dict = equipment_q.get_all_equipment(cursor) the_team.get_units(cursor) output = [] output.append(""" <table border="0" cellspacing="0" cellpadding="5" style="width: 100%;"> <tr class="row2"> <th>Icon</th> <th>Amount</th> <th>Name</th> <th>Cost</th> <th colspan='4'>Categories</th> <th>Equipment</th> <th style="width:70px;">Edit</th> <!-- <th colspan="2">Add</th> --> </tr>""") names = {} count = -1 if len(unit_dict) > 0: # for team_id, team in team_dict.items(): for unit_id, the_unit in unit_dict.items(): if unit_id not in the_team.units: the_team.units[unit_id] = 0 names[unit_id] = the_unit.name count += 1 output.append(""" <tr class="row%(row)d" id="%(unit_id)d"> <td>%(icon)s</td> <td>%(count)s</td> <td>%(name)s</td> <td>%(cost)s</td> <td>%(weapon_cat)s</td> <td>%(armour_cat)s</td> <td>%(move_cat)s</td> <td>%(training_cat)s</td> <td>%(equipment)s</td> <td style="padding: 0px;"><a class="block_link" href="web.py?mode=edit_unit&unit=%(unit_id)d">Edit unit</a></td> <!-- <td style="padding: 1px;"> <form action="exec.py" method="post" accept-charset="utf-8"> <input type="text" name="amount" value="" size="8"/> <input type="hidden" name="mode" value="alter_unit_count" /> <input type="hidden" name="team" value="%(team_id)s" /> <input type="hidden" name="unit" value="%(unit_id)s" /> </form> </td> <td style="padding: 0px;"> <a class="block_link" href="#" onclick="$('#form_add_%(unit_id)s').submit();">Add unit</a> </td> --> </tr> """ % { 'row': (count % 2), "team_id": team_id, 'unit_id': unit_id, 'name': common.doubleclick_text("units", "name", unit_id, the_unit.name, "font-weight:bold"), 'icon': "", 'count': common.number_format(the_team.units[unit_id]), 'weapon_cat': unit.weapon_categories[the_unit.weapon_cat], 'armour_cat': unit.armour_categories[the_unit.armour_cat], 'move_cat': unit.move_categories[the_unit.move_cat], 'training_cat': unit.training_categories[the_unit.training_cat], "cost": unit_rules.print_unit_cost(the_unit, cursor=cursor, equipment_dict=equipment_dict), "equipment": the_unit.equipment_string, }) # Add unit type # armies_dict = army_q.get_armies_from_team(cursor, team=team_id, include_garrisons=1) count += 1 # armies_names = {} # has_non_garrison = False # for k, v in armies_dict.items(): # armies_names[k] = v.name # if v.garrison < 0: has_non_garrison = True # # armies_order.reverse() # armies_order.append("disabled") # armies_order.append("XYZ_all_garrisons") # if has_non_garrison == True: # armies_order.append("XYZ_all_non_garrisons") # armies_order.append("XYZ_all_armies") # armies_order.reverse() # # if has_non_garrison == True: # armies_names["XYZ_all_armies"] = "All armies" # armies_names["XYZ_all_non_garrisons"] = "All non garrisons" # armies_names["XYZ_all_garrisons"] = "All garrisons" output.append(""" <tr class="row%(row)d"> <form action="exec.py" method="post" id="new_unit_form" accept-charset="utf-8"> <input type="hidden" name="mode" value="create_new_unit" /> <input type="hidden" name="team" value="%(team_id)s" /> <td> </td> <td style="padding: 1px;"> </td> <td style="padding: 1px;"><input type="text" name="name" id="name" value="" size="13"/></td> <td colspan='4'> </td> <td style="padding: 1px;"> </td> <td style="padding: 2px;"> <textarea name="equipment_string" id="equipment_string" rows="1" cols="30"></textarea> </td> <td style="padding: 0px;"><a class="block_link" onclick="$('#new_unit_form').submit();" href="#">Add</a></td> %(onload)s </form> </tr> """ % { 'row': (count % 2), "team_id": team_id, 'onload': common.onload("$('#name').focus();"), }) # Now for solo units unit_dict = unit_q.get_units_from_team(cursor, team=0) if len(unit_dict) > 0: # for team_id, team in team_dict.items(): for unit_id, the_unit in unit_dict.items(): if unit_id not in the_team.units: the_team.units[unit_id] = 0 names[unit_id] = the_unit.name count += 1 output.append(""" <tr class="row%(row)d" id="%(unit_id)d"> <td>%(icon)s</td> <td>%(count)s</td> <td>%(name)s</td> <td>%(cost)s</td> <td colspan='4'> </td> <td>%(equipment)s</td> <td style="padding: 0px;"><a class="block_link" href="web.py?mode=edit_unit&unit=%(unit_id)d">Edit unit</a></td> <!-- <td style="padding: 1px;"> <form action="exec.py" method="post" accept-charset="utf-8"> <input type="text" name="amount" value="" size="8"/> <input type="hidden" name="mode" value="alter_unit_count" /> <input type="hidden" name="team" value="%(team_id)s" /> <input type="hidden" name="unit" value="%(unit_id)s" /> </form> </td> <td style="padding: 0px;"> <a class="block_link" href="#" onclick="$('#form_add_%(unit_id)s').submit();">Add unit</a> </td> --> </tr> """ % { 'row': (count % 2), "team_id": team_id, 'unit_id': unit_id, 'name': common.doubleclick_text("units", "name", unit_id, the_unit.name, "font-weight:bold"), 'icon': "", 'count': common.number_format(the_team.units[unit_id]), "cost": unit_rules.print_unit_cost(the_unit, cursor=cursor, equipment_dict=equipment_dict), "equipment": the_unit.equipment_string, }) output.append("</table>") page_data['Title'] = "%s unit list" % the_team.name 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)
count = -1 for c in continent_list: count += 1 the_cont = continent_dict[c] output.append(""" <tr class="row%(count)s"> <td>%(name)s</td> <td>%(x)s</td> <td>%(y)s</td> <td> </td> </tr> """ % { "count": count%2, "name": common.doubleclick_text("map_continents", "name", the_cont.id, the_cont.name, size=10), "x": common.doubleclick_text("map_continents", "x", the_cont.id, the_cont.x, size=4), "y": common.doubleclick_text("map_continents", "y", the_cont.id, the_cont.y, size=4), }) count += 1 output.append(""" <tr class="row%(count)s"> <form action="exec.py" method="post" accept-charset="utf-8"> <input type="hidden" name="mode" value="add_continent" /> <td style="padding:1px;"><input type="text" name="name" id="name" value="" /></td> <td style="padding:1px;" colspan="2"><input type="text" name="location" value="" /></td> <td><input type="submit" value="Add" /></td> </form> %(onload)s </tr>
def main(cursor): # Get team Id team_id = int(common.get_val('team', 0)) text_location = common.get_val('location', "") # Build team the_team = team_q.get_one_team(cursor, team_id) cities_dict = city_q.get_cities_from_team(cursor, team=team_id, include_dead=0) if team_id < 1: return "<div style='padding: 5px;'>%s</div>" % common.select_team_form(cursor, 'list_armies') exit() armies_dict = army_q.get_armies_from_team(cursor, team=team_id, include_garrisons=1) output = [] output.append(""" <table border="0" cellspacing="0" cellpadding="5" style="width: 100%;"> <tr class="row2"> <th>Army</th> <th>Location</th> <th>Base</th> <th>Size</th> <th> </th> <th> </th> </tr>""") names = {} if len(armies_dict) > 0: count = -1 # for team_id, team in team_dict.items(): for army_id, the_army in armies_dict.items(): count += 1 city_location = the_army.garrison if the_army.garrison > 0: location = "Garrison" else: location = "%s, %s" % (the_army.x, the_army.y) if the_army.base in cities_dict: base_name = cities_dict[the_army.base].name else: base_name = "N/A" output.append(""" <tr class="row%(row)d" id="%(army_id)d"> <td><strong>%(name)s</strong></td> <td>%(location)s</td> <td>%(base)s</td> <td>%(size)s</td> <td style="padding: 0px;"> <a class="block_link" id="show_squads_%(army_id)d" href="#" onclick="$('#div_%(army_id)d').load('web.py', {'mode':'list_squads', 'ajax':'True', 'army':'%(army_id)d'}, function () {$('#tr_%(army_id)d').fadeIn(0); $('#show_squads_%(army_id)d').fadeOut(0); $('#hide_squads_%(army_id)d').fadeIn(0);}); return false;">Show squads</a> <a id="hide_squads_%(army_id)d" style="display:none;" class="block_link" href="#" onclick="$('#tr_%(army_id)d').fadeOut(0); $('#show_squads_%(army_id)d').fadeIn(0); $('#hide_squads_%(army_id)d').fadeOut(0); return false;">Hide squads</a></td> <td style="padding: 0px;"><a class="block_link" href="web.py?mode=edit_army&army=%(army_id)d">Edit army</a></td> </tr> <tr style="display: none;" id="tr_%(army_id)d"> <td colspan="5" style="padding: 0 10px 10px 10px;"> <div id="div_%(army_id)d"> </div> </td> </tr> """ % { 'row': (count % 2), "army_id": army_id, "name": common.doubleclick_text("armies", "name", army_id, the_army.name, "font-weight:bold", size=18), "base": base_name, "location": location, "size": the_army.get_size(cursor), }) # Add new army thingie names = {} for c, the_city in cities_dict.items(): names[c] = the_city.name count += 1 output.append(""" <tr class="row%(row)d"> <form action="exec.py" id="add_army_form" method="post" accept-charset="utf-8"> <input type="hidden" name="mode" value="add_army" /> <input type="hidden" name="team" value="%(team_id)s" /> <td style="padding: 1px;"><input type="text" id="new_name" name="name" value="" /></td> <td> </td> <td style="padding: 1px;"> %(city_location)s %(text_location)s </td> <td style="padding: 0px;"><a href="web.py?mode=view_map&new_mode=list_armies&team=%(team_id)s" class="block_link">Pick location</a></td> <td colspan="2" style="padding: 0px;"><a class="block_link" href="#" onclick="$('#add_army_form').submit(); return false;">Add</a></td> </form> %(onload)s </tr> """ % { 'row': (count % 2), "team_id": team_id, 'city_location': common.option_box( name='city_location', elements=names, element_order=cities_dict.keys(), custom_id="", ), "text_location": common.text_box("text_location", text_location, custom_id=""), "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)