def trait_list(cursor, cat=None, page=None, **kwargs): trait_dict = trait_q.get_all_traits(cursor) output = [] output_dict = {} for trait_id, the_trait in trait_dict.items(): if not the_trait.show: continue if the_trait.category not in output_dict: output_dict[the_trait.category] = [] output_dict[the_trait.category].append(""" <strong><a class="clear_link" id="%(js_name)s" href="#%(js_name)s">%(trait_name)s</a></strong> <br /> %(description)s <br /><br />""" % { "js_name": common.js_name(the_trait.name), "trait_name": the_trait.name, "description": the_trait.description, }) for i in range(len(trait.categories)): if output_dict[i] != []: output.append("""<h3><a id="%s" href="#%s">%s</a></h3>""" % ( common.js_name(trait.categories[i]), common.js_name(trait.categories[i]), trait.categories[i], )) output.append("".join(output_dict[i])) return "".join(output)
def get_html(cursor, category, page, level = "public", filter_list = []): level = lore_entry.levels.index(level) data = _filter(cursor, category, page, level, filter_list) if data == None: raise KeyError("%s.%s not found" % (category, page)) return "%s.%s not found" % (category, page) output = [] for i, t in enumerate(data): if t["title"] != "": if i == 0: tag = 1 else: tag = 4 output.append('<h%d><a href="#%s" id="%s">%s</a></h%d>' % ( tag, common.js_name(t['title']), common.js_name(t['title']), t['title'], tag, )) output.append(t['description'].replace("<tab>", " ")) if not t.get('no_break', False): output.append("<br /><br />") return "\n".join(output)
def main(cursor): evolution_dict = evolution_q.get_all_evolutions(cursor) output = [] output_dict = {} for i in range(0,5): output_dict[i] = [] for d, the_evolution in evolution_dict.items(): if the_evolution.category == 3: continue if the_evolution.name == "VOID": continue # self.add_field("cost_per_level", "int") # self.add_field("max_level", "int") # self.add_field("min_level", "int") # self.add_field("category", "int") # self.add_field("physical_change", "double") # self.add_field("combat_relevant", "bool") # self.add_field("description", "blob") output_dict[the_evolution.category].append("""<strong><a class="clear_link" id="%(js_name)s" href="#%(js_name)s">%(evo_name)s</a></strong> Max level: %(max_level)s Min level: %(min_level)s Cost: %(cost)s <br /> %(description)s <br /><br />""" % { "js_name": common.js_name(the_evolution.name), "evo_name": the_evolution.name, "max_level": the_evolution.max_level, "min_level": the_evolution.min_level, "cost": the_evolution.cost_per_level, "description": the_evolution.description, }) for i in range(0,5): if output_dict[i] != []: output.append("""<h3><a id="%s" href="#%s">%s</a></h3>""" % ( common.js_name(evolution.categories[i]), common.js_name(evolution.categories[i]), evolution.categories[i], )) output.append("".join(output_dict[i])) return "".join(output)
def nomadic_city_block(oh, the_team, the_city): output, load_java, run_java = [], [], [] # Supply and demand supply_menu = [] for i, r in enumerate(sad_rules.res_list): if the_city.supply_good == i: supply_menu.append('<option value="" selected="selected">%s (current)</option>' % (r)) else: supply_menu.append('<option value="%s">%s</option>' % (r, r)) # Now to actually make the output output.append(""" <div class="order_box_half"> <table border="0" cellspacing="0" cellpadding="5"> <tr> <td colspan="2" style="font-weight:bold; font-size:1.1em;">%(name)s</td> </tr> <tr> <td>Current location:</td> <td>%(x)s, %(y)s</td> <tr> </tr> <td>New location:</td> <td><input type="text" id="migration_text_%(city_id)s" value="%(x)s, %(y)s" /></td> </tr> <tr> <td>Supply good:</td> <td> <select id="supply_menu_%(city_id)s"> %(supply_menu)s </select> </td> </tr> </table> </div> """ % { "city_id": the_city.id, "name": the_city.name, "x": the_city.x, "y": the_city.y, "supply_menu": "".join(supply_menu), }) # Java run_java.append(""" var temp_location = $('#migration_text_%(city_id)d').val(); if (temp_location != '' && temp_location != '%(loc)s') {migration_orders += 'Move %(city_name)s towards ' + temp_location + '\\n';} var temp_good = $('#supply_menu_%(city_id)s option:selected').val(); if (temp_good != '') { supply_demand_orders += 'Change %(city_name)s supply production to ' + temp_good + '\\n'; }""" % { "city_id": the_city.id, "city_name": common.js_name(the_city.name), "loc": "%s, %s" % (the_city.x, the_city.y), }) return "".join(output), "".join(load_java), "".join(run_java)
def setup(self, true_team_list=[]): # Teams team_dict = self.the_world.teams() if true_team_list == []: true_team_list = team_dict.keys() # We use the full list of teams so that we don't get key errors later for t in team_dict.keys(): self.caches[t] = {} # Team dropdown list for t in true_team_list: if 'team_list' not in self.caches[t]: self.caches[t]['team_list'] = [] self.caches[t]['trade_list'] = [] for team_id, the_team in team_dict.items(): if t == team_id or the_team.dead or not the_team.active: continue if path_f.find_trade_route(self.the_world.cursor, the_team.id, t, the_world=self.the_world) != (-1, -1): self.caches[t]['trade_list'].append('<option value="%s">%s</option>' % ( the_team.name, the_team.name) ) self.caches[t]['team_list'].append('<option value="%s">%s</option>' % (the_team.name, the_team.name)) # World city menu city_dict = self.the_world.cities() self.caches[0]['world_city_menu'] = [] for city_id, the_city in city_dict.items(): if the_city.dead > 0: continue if not team_dict[the_city.team].active: continue self.caches[0]['world_city_menu'].append( '<option value="{0}">{1} ({2})</option>'.format(common.js_name(the_city.name), the_city.name.replace('\\', ''), team_dict[the_city.team].name)) # Army dropdown army_dict = self.the_world.armies() for army_id, the_army in army_dict.items(): if the_army.team not in true_team_list: continue if the_army.garrison > 0: continue if 'army_list' not in self.caches[the_army.team]: self.caches[the_army.team]['army_list'] = [] self.caches[the_army.team]['army_list'].append( '<option value="%s">%s</option>' % (the_army.name, the_army.name) ) # Zip them down into strings true_team_list = list(true_team_list) true_team_list.append(0) for t in true_team_list: for k, v in self.caches[t].items(): if type(v) == list or type(v) == tuple: self.caches[t][k] = "".join(v)
def main(cursor): tech_dict = tech_q.get_all_techs(cursor) output = [] count = 0 for tech_id, the_tech in tech_dict.items(): if the_tech.name == "NONE": continue base_cost = res_dict.Res_dict(the_tech.base_cost) extra_cost = res_dict.Res_dict(the_tech.extra_cost) materials = "%s + L x %s" % (base_cost.get("Materials"), extra_cost.get("Materials")) points = "%s + L x %s" % (base_cost.get("Tech points"), extra_cost.get("Tech points")) count += 1 output.append(""" <tr class='row%(count)s'> <td><a id='%(js_name)s' href='#%(js_name)s'>%(name)s</a></td> <td>%(materials)s</td> <td>%(points)s</td> <td>%(description)s</td> <td><input type='text' id='lvl%(js_name)s' onkeyup="var lvl = $('#lvl%(js_name)s').val(); $('#mat%(js_name)s').html(%(materials_base)s + (lvl * %(materials_extra)s)); $('#pts%(js_name)s').html(%(points_base)s + (lvl * %(points_extra)s));" value='0' size='5'/></td> <td style='width: 50px;'> <span id='mat%(js_name)s'>0</span>, <span id='pts%(js_name)s'>0</span> </td> </tr>""" % { "count": count%2, "name": the_tech.name, "js_name": common.js_name(the_tech.name).replace(" ", ""), "materials": materials, "points": points, "materials_base": base_cost.get("Materials"), "materials_extra": extra_cost.get("Materials"), "points_base": base_cost.get("Tech points"), "points_extra": extra_cost.get("Tech points"), "description": the_tech.description, }) return "".join(output)
def building_list(cursor, cat=None, page=None, **kwargs): building_dict = building_q.get_all_buildings(cursor) output = [] for building_id, the_building in building_dict.items(): if not the_building.public: continue # if the_trait.category not in output_dict: # output_dict[the_trait.category] = [] output.append(""" <strong><a class="clear_link" id="%(js_name)s" href="#%(js_name)s">%(building_name)s</a></strong> <br /> %(description)s <br /><br />""" % { "js_name": common.js_name(the_building.name), "building_name": the_building.name, "description": the_building.description, }) return "".join(output)
def setup(self, true_team_list=[]): # Teams team_dict = self.the_world.teams() if true_team_list == []: true_team_list = team_dict.keys() # We use the full list of teams so that we don't get key errors later for t in team_dict.keys(): self.caches[t] = {} # Wonders cities_with_wonders = self.the_world.cities_with_wonders() city_dict = self.the_world.cities() for c in cities_with_wonders: if 'wonder_menu' not in self.caches[city_dict[c].team]: self.caches[city_dict[c].team]['wonder_menu'] = [] self.caches[city_dict[c].team]['wonder_menu'].append( '<option value="%s">%s</option>' % ( common.js_name(city_dict[c].name), city_dict[c].name ) ) # Founding for c, the_city in city_dict.items(): if the_city.team not in true_team_list: continue if the_city.dead > 0 or the_city.population < 5000: continue if 'founding_dropdown' not in self.caches[the_city.team]: self.caches[the_city.team]['founding_dropdown'] = ['<option value="">All cities</option>'] self.caches[the_city.team]['founding_dropdown'].append( '<option value="%s">%s</option>' % (the_city.name, the_city.name) ) # Relocation, same as founding minus the first item for t in true_team_list: self.caches[t]['relocation_dropdown'] = list(self.caches[t].get('founding_dropdown', '<option value=""></option>')) del(self.caches[t]['relocation_dropdown'][0]) # Army dropdown army_dict = self.the_world.armies() for army_id, the_army in army_dict.items(): if the_army.team not in true_team_list: continue if 'army_list' not in self.caches[the_army.team]: self.caches[the_army.team]['army_list'] = [] self.caches[the_army.team]['army_list'].append( '<option value="%s">%s</option>' % (the_army.name, the_army.name) ) # Unit dropdown unit_dict = self.the_world.units() for unit_id, the_unit in unit_dict.items(): if the_unit.team != 0 and the_unit.team not in true_team_list: continue if 'unit_list' not in self.caches[the_unit.team]: self.caches[the_unit.team]['unit_list'] = [] self.caches[the_unit.team]['unit_list'].append( '<option value="%s">%s %s</option>' % (the_unit.name, the_unit.name, unit_rules.print_unit_cost(the_unit, the_world=self.the_world)) ) # List of _all_ units for t in true_team_list: self.caches[t]['all_unit_list'] = list(self.caches[t].get('unit_list', [])) self.caches[t]['all_unit_list'].extend(self.caches[0]['unit_list']) # Squad dropdown squad_dict = self.the_world.squads() for squad_id, the_squad in squad_dict.items(): if the_squad.team not in true_team_list: continue if 'squad_list' not in self.caches[the_squad.team]: self.caches[the_squad.team]['squad_list'] = [] self.caches[the_squad.team]['squad_list'].append( '<option value="%s,%s">%s (%s)</option>' % (common.js_name(the_squad.name), common.js_name(army_dict[the_squad.army].name), the_squad.name, army_dict[the_squad.army].name) ) # Operative city dropdown city_dict = self.the_world.cities() self.caches[0]['operative_city_dropdown'] = [] for city_id, the_city in city_dict.items(): if the_city.dead > 0: continue if not team_dict[the_city.team].active: continue self.caches[0]['operative_city_dropdown'].append( '<option value="{0}">{1} ({2})</option>'.format(common.js_name(the_city.name), the_city.name.replace('\\', ''), team_dict[the_city.team].name)) # Spell list spell_dict = self.the_world.spells() for s, the_spell in spell_dict.items(): if the_spell.name == "NONE": continue for t in true_team_list: if 'spell_list' not in self.caches[t]: self.caches[t]['spell_list'] = ['<option value=""> </option>'] the_team = team_dict[t] if s in the_team.spell_levels: if the_team.spell_levels[s] >= the_spell.max_level: if the_spell.max_level > 0: self.caches[t]['spell_list'].append( '<option value="" disabled="disabled">%s</option>' % (the_spell.name) ) continue if the_team.spell_levels[s] > 0: points_needed = spell_rules.cost_for_next_level(None, the_spell, level=the_team.spell_levels[s], in_spell_points=True).get("Spell points") self.caches[t]['spell_list'].append( '<option value="%s">%s (%s: %s/%s)</option>' % ( the_spell.name, the_spell.name, the_team.spell_levels[s], the_team.spell_points[s], points_needed ) ) else: self.caches[t]['spell_list'].append( '<option value="%s">%s (%s)</option>' % ( the_spell.name, the_spell.name, the_team.spell_levels[s] ) ) else: self.caches[t]['spell_list'].append( '<option value="%s">%s</option>' % ( the_spell.name, the_spell.name ) ) # Tech list tech_dict = self.the_world.techs() for s, the_tech in tech_dict.items(): if the_tech.name == "NONE": continue for t in true_team_list: if 'tech_list' not in self.caches[t]: self.caches[t]['tech_list'] = ['<option value=""> </option>'] the_team = team_dict[t] if s in the_team.tech_levels: if the_team.tech_levels[s] >= the_tech.max_level: if the_tech.max_level > 0: self.caches[t]['tech_list'].append( '<option value="" disabled="disabled">%s</option>' % (the_tech.name) ) continue if the_team.tech_levels[s] > 0: points_needed = tech_rules.cost_for_next_level(None, the_tech, level=the_team.tech_levels[s]).get("Tech points") self.caches[t]['tech_list'].append( '<option value="%s">%s (%s: %s/%s)</option>' % ( the_tech.name, the_tech.name, the_team.tech_levels[s], the_team.tech_points[s], points_needed ) ) else: self.caches[t]['tech_list'].append( '<option value="%s">%s (%s)</option>' % ( the_tech.name, the_tech.name, the_team.tech_levels[s] ) ) else: self.caches[t]['tech_list'].append( '<option value="%s">%s</option>' % ( the_tech.name, the_tech.name ) ) # Team dropdown list for t in true_team_list: if 'team_list' not in self.caches[t]: self.caches[t]['team_list'] = ['<option value=""> </option>'] self.caches[t]['trade_list'] = ['<option value=""> </option>'] for team_id, the_team in team_dict.items(): if t == team_id or the_team.dead or not the_team.active: continue if path_f.find_trade_route(self.the_world.cursor, the_team.id, t, the_world=self.the_world) != (-1, -1): self.caches[t]['trade_list'].append('<option value="%s">%s</option>' % ( the_team.name, the_team.name) ) self.caches[t]['team_list'].append('<option value="%s">%s</option>' % (the_team.name, the_team.name)) # Monster list monster_list = [] for k, v in self.the_world.monsters().items(): monster_list.append('<option value="%s">%s</option>' % (v.name, v.name)) for t in true_team_list: self.caches[t]['monster_list'] = monster_list # Research trade master_tier = spell.tiers.index("Master") for t in true_team_list: if 'spell_trade' not in self.caches[t]: self.caches[t]['spell_trade'] = ['<option value=""> </option>'] for s, l in team_dict[t].spell_levels.items(): if l < 1: continue if spell_dict[s].tier == master_tier: continue if not spell_dict[s].tradable: continue if spell_dict[s].name == "NONE": continue self.caches[t]['spell_trade'].append( '<option value="%s">%s</option>' % ( common.js_name(spell_dict[s].name), spell_dict[s].name ) ) for t in true_team_list: if 'tech_trade' not in self.caches[t]: self.caches[t]['tech_trade'] = ['<option value=""> </option>'] for s, l in team_dict[t].tech_levels.items(): if l < 1: continue if not tech_dict[s].tradable: continue if tech_dict[s].name == "NONE": continue self.caches[t]['tech_trade'].append( '<option value="%s">%s</option>' % ( common.js_name(tech_dict[s].name), tech_dict[s].name ) ) # Resources dropdowns for t in true_team_list: team_resource = team_dict[t].resources if 'boolean_resources' not in self.caches[t]: self.caches[t]['boolean_resources'] = ['<option value=""> </option>'] self.caches[t]['discrete_resources'] = ['<option value=""> </option>'] for i, r in enumerate(resource_list.data_list): if not r.tradable: continue if r.type == "boolean": if team_resource.value[i] < 1: continue self.caches[t]['boolean_resources'].append('<option value="%s">%s</option>' % (r.name, r.name)) elif r.type == "discrete": if team_resource.value[i] < 1: continue self.caches[t]['discrete_resources'].append('<option value="%s">%s</option>' % (r.name, r.name)) # Zip them down into strings true_team_list = list(true_team_list) true_team_list.append(0) for t in true_team_list: for k, v in self.caches[t].items(): if type(v) == list or type(v) == tuple: self.caches[t][k] = "".join(v)
<td style="padding: 1px;">%(battle_location_text)s</td> </tr> </table> <br /> <input type="submit" value="Perform edit" /> </form> <form id="delete_form" action="exec.py" method="post" accept-charset="utf-8"> <input type="hidden" name="battle" id="battle" value="%(battle_id)s" /> <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)s?') if (answer) $('#delete_form').submit();" /> </form> <br /><br />""" % { "battle_id": battle_id, "name": the_battle.name, "esc_name": common.js_name(the_battle.name,), "battle_turn": the_battle.turn, "name_text": common.text_box("name", the_battle.name, size=20), "battle_turn_text": common.text_box("turn", the_battle.turn, size=5), "battle_city_select": common.option_box( name='city', elements=names, element_order=city_list, custom_id="", selected=the_battle.city, ), "battle_location_text": common.text_box("location", new_location, 10), }) # Now for the participants of the battle #------------------------
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, 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 army_block(oh, the_team, the_army): output, load_java, run_java = [], [], [] # if the_army.id != 870: # return "".join(output), "".join(load_java), "".join(run_java) # unit_dict_c = unit.get_unit_dict_c() # army_dict_c = army.get_army_dict_c() squad_dict = oh.the_world.squads() squads_lookup = oh.the_world.squads_lookup_from_army(the_army.id) squad_java = [] squad_output = [] army_size = 0 for sname, squad_id in squads_lookup.items(): the_squad = squad_dict[squad_id] army_size += the_squad.amount additions = squad_block(oh, the_team, the_squad) squad_output.append(additions[0]) load_java.append(additions[1]) squad_java.append(additions[2]) if the_army.garrison > 0: location = "" delete_army = "" form_spacing = "" rename_field = "" else: location = ' Location: <input type="text" id="location_army_%d" value="%s, %s" />' % (the_army.id, the_army.x, the_army.y) delete_army = 'Delete army: <input type="checkbox" id="delete_army_%d" value="del"/>' % the_army.id form_spacing = "<br /><br />" rename_field = ' - <input type="text" id="rename_army_%d" value="New name?" />' % the_army.id run_java.append(""" var temp_delete_army = $('#delete_army_%(army_id)d').attr("checked"); if (temp_delete_army) { army_delete_orders += 'Delete army: %(army_name)s\\n'; } var temp_army_location = $('#location_army_%(army_id)d').val(); if (temp_army_location != '' && temp_army_location != '%(current_location)s') { army_relocate_orders += 'Relocate army: %(army_name)s, ' + temp_army_location + '\\n'; } var temp_army_name = $('#rename_army_%(army_id)d').val(); if (temp_army_name != '' && temp_army_name != 'New name?' && temp_army_name != '%(army_name)s') { army_rename_orders += 'Rename army: %(army_name)s, ' + temp_army_name + '\\n'; } """ % { "army_name": common.js_name(the_army.name), "army_id": the_army.id, "current_location": "%s, %s" % (the_army.x, the_army.y), }) output.append(""" <div class="order_box"> <a href="#" id="army_hide_%(id)s" onclick="$('#army_box_%(id)s').hide(500); $('#army_hide_%(id)s').hide(); $('#army_show_%(id)s').show(); return false;" class="block_link" style="float:right; margin: -5px;">Hide</a> <a href="#" id="army_show_%(id)s" onclick="$('#army_box_%(id)s').show(500); $('#army_show_%(id)s').hide(); $('#army_hide_%(id)s').show(); return false;" class="block_link" style="float:right; margin: -5px; display:none;">Show</a> <span class="stitle">%(name)s</span> <div class="army_order_box" id="army_box_%(id)s"> <span style=""> Size: %(army_size)s</span> %(rename_field)s %(form_spacing)s %(delete_army)s %(location)s <br /><br /> <div id="%(id)d_squads" style="display:nnone;"> <table border="0" cellspacing="0" cellpadding="5"> <tr> <th>Squad name</th> <th>Type</th> <th>Squad size</th> <th>Amount to add</th> <!--<th>Move to army</th>--> <th> </th> <!--<th colspan="2">Merge</th>--> </tr> """ % { "id": the_army.id, "name": the_army.name, "army_size": format(army_size, ','), "location": location, "delete_army": delete_army, "form_spacing": form_spacing, "rename_field": rename_field, }) output.append("".join(squad_output)) run_java.append(""" var temp_army_recruit_orders = ""; %s if (temp_army_recruit_orders != "") { army_recruit_orders += "\\n\\nSelect army: %s\\n" + temp_army_recruit_orders; } """ % ("".join(squad_java), common.js_name(the_army.name))) output.append(""" </table> </div> </div> </div> """ % { "name": the_army.name, }) return "".join(output), "".join(load_java), "".join(run_java)
def main(cursor): wonder_id = int(common.get_val('wonder', 0)) if wonder_id < 1: return "No wonder selected" the_wonder = wonder_q.get_one_wonder(cursor, wonder_id) cities_dict = city_q.get_live_cities(cursor) teams_dict = team_q.get_real_teams(cursor) names = {} for c, the_city in cities_dict.items(): names[c] = the_city.name # TODO Make this do it properly tnames = {} for t, the_team in teams_dict.items(): tnames[t] = the_team.name output = ["<div style='padding: 5px;'>"] output.append(""" <form action="exec.py" method="post" accept-charset="utf-8"> <input type="hidden" name="mode" id="mode" value="edit_wonder_commit" /> <input type="hidden" name="id" id="id" value="%(wonder_id)s" /> Editing: %(name_text)s <br /><br /> <table border="0" cellspacing="5" cellpadding="5"> <tr> <td><label for="city">City:</label></td> <td>%(city_menu)s</td> <td width="5"> </td> <td><label for="team">Team:</label></td> <td>%(team_menu)s</td> <td width="5"> </td> <td><label for="completed">Completed:</label></td> <td style="padding: 1px;">%(completed)s</td> </tr> <tr> <td><label for="completion">Completion:</label></td> <td style="padding: 1px;">%(completion)s</td> <td width="5"> </td> <td><label for="point_cost">Point cost:</label></td> <td style="padding: 1px;">%(point_cost)s</td> <td width="5"> </td> <td><label for="material_cost">Material cost:</label></td> <td style="padding: 1px;">%(material_cost)s</td> </tr> <tr> <td colspan="10"> Description:<br /> %(description)s </td> </tr> </table> <br /> <input type="submit" value="Perform edit" /> </form> <form id="delete_form" action="exec.py" method="post" accept-charset="utf-8"> <input type="hidden" name="wonder" id="wonder" value="%(wonder_id)s" /> <input type="hidden" name="mode" id="mode" value="remove_wonder" /> <input style="float:right; margin-right:100px;" type="button" value="Delete wonder" onclick="var answer = confirm('Delete %(name_safe)s?') if (answer) $('#delete_form').submit();" /> </form> <br /><br />""" % { "wonder_id": wonder_id, "name_text": common.text_box("name", the_wonder.name), "city_menu": common.option_box( name='city', elements=names, element_order=cities_dict.keys(), custom_id="", selected=the_wonder.city, ), "team_menu": common.option_box( name='team', elements=tnames, element_order=teams_dict.keys(), custom_id="", selected=the_wonder.team, ), "completed": common.check_box("completed", the_wonder.completed), "completion": common.text_box("completion", the_wonder.completion, size=7), "point_cost": common.text_box("point_cost", the_wonder.point_cost, size=7), "material_cost": common.text_box("material_cost", the_wonder.material_cost, size=7), "description": '<textarea name="description" id="description" rows="4" style="width:99%%;">%s</textarea>' % the_wonder.description, "name_safe": common.js_name(the_wonder.name), }) output.append("</div>") return "".join(output)
def normal_city_block(oh, the_team, the_city): output, load_java, run_java = [], [], [] building_menu = [] building_menu_grey = [] wall_menu = [] wall_menu_grey = [] buildings_progress, buildings_amount = the_city.buildings, the_city.buildings_amount selected_building = None selected_wall = None building_dict = oh.the_world.buildings() buildings_requirements = oh.the_world.building_requirements() # Can't cache it because it's unique for each city for b, the_building in building_dict.items(): if not the_building.public: continue if the_building.name == "VOID": continue # Find out if we've already built one... true_amount = buildings_amount.get(b, 0) if b in buildings_requirements: for build_id in buildings_requirements[b]: if build_id in buildings_amount: true_amount += buildings_amount[build_id] if true_amount >= the_building.limit_per_city: if the_building.wall: wall_menu_grey.append("<option disabled='disabled'>%s</option>" % (the_building.name)) else: building_menu_grey.append("<option disabled='disabled'>%s</option>" % (the_building.name)) continue # Don't offer it if we can't upgrade to it if the_building.upgrades > 0: if the_building.upgrades not in buildings_amount: continue if the_building.wall: if buildings_progress.get(b,0) > 0 and selected_wall == None: selected_wall = "selected='selected'" else: if buildings_progress.get(b,0) > 0 and selected_building == None: selected_building = "selected='selected'" if the_building.wall: wall_menu.append("<option value='%s' %s>%s</option>" % (the_building.name, selected_wall, the_building.name)) if selected_wall != None: selected_wall = "" else: building_menu.append("<option value='%s' %s>%s</option>" % (the_building.name, selected_building, the_building.name)) if selected_building != None: selected_building = "" if wall_menu_grey != []: wall_menu_grey.insert(0, '<option disabled="disabled"></option>') if building_menu_grey != []: building_menu_grey.insert(0, '<option disabled="disabled"></option>') # Supply and demand supply_menu = [] for i, r in enumerate(sad_rules.res_list): if the_city.supply_good == i: supply_menu.append('<option value="" selected="selected">%s (current)</option>' % (r)) else: supply_menu.append('<option value="%s">%s</option>' % (r, r)) # Wunders if oh.caches[the_team.id].get('wonder_menu', '') != "": wonder_menu = """ <tr> <td>Wonder:</td> <td> <select id="wonder_menu_%d"> <option value=""></option> %s </select> </td> </tr> """ % (the_city.id, oh.caches[the_team.id].get('wonder_menu', '')) else: wonder_menu = "" # Output output.append(""" <div class="order_box_half"> <table border="0" cellspacing="0" cellpadding="5"> <tr> <td colspan="2" style="font-weight:bold; font-size:1.1em;">%(name)s</td> </tr> <tr> <td>Building:</td> <td> <select id="building_menu_%(city_id)s"> <option value=""></option> %(building_menu)s </select> </td> <tr> <tr> <td>Wall:</td> <td> <select id="wall_menu_%(city_id)s"> <option value=""></option> %(wall_menu)s </select> </td> </tr> <tr> <td>Supply good:</td> <td> <select id="supply_menu_%(city_id)s"> %(supply_menu)s </select> </td> </tr> %(wonder_menu)s </table> </div> """ % { "city_id": the_city.id, "name": the_city.name, "building_menu": "".join(building_menu) + "".join(building_menu_grey), "wall_menu": "".join(wall_menu) + "".join(wall_menu_grey), "supply_menu": "".join(supply_menu), "wonder_menu": wonder_menu, }) # Java run_java.append(""" var temp_building = $('#building_menu_%(city_id)s option:selected').val(); if (temp_building != '') { construction_orders += 'Build ' + temp_building + ' at %(city_name)s\\n'; construction_materials += 5; } var temp_walls = $('#wall_menu_%(city_id)s option:selected').val(); if (temp_walls != '') { construction_orders += 'Build ' + temp_walls + ' at %(city_name)s\\n'; construction_materials += 5; } var temp_good = $('#supply_menu_%(city_id)s option:selected').val(); if (temp_good != '') { supply_demand_orders += 'Change %(city_name)s supply production to ' + temp_good + '\\n'; } """ % { "city_id": the_city.id, "city_name": common.js_name(the_city.name), }) if wonder_menu != "": run_java.append(""" var temp_wonder = $('#wonder_menu_%(city_id)s option:selected').val(); if (temp_wonder != '') { construction_orders += '%(city_name)s assist wonder at ' + temp_wonder + '\\n'; construction_materials += 0; }""" % { "city_id": the_city.id, "city_name": common.js_name(the_city.name), }) return "".join(output), "".join(load_java), "".join(run_java)
def squad_block(oh, the_team, the_squad): output, load_java, run_java = [], [], [] # unit_dict_c = unit.get_unit_dict_c() # army_dict_c = army.get_army_dict_c() # squad_dict_c = squad.get_squad_dict_c() the_unit = oh.the_world.units()[the_squad.unit] the_army = oh.the_world.armies()[the_squad.army] if the_squad.amount <= 0: delete = '<label for="delete_squad_%d">Delete</label> <input type="checkbox" id="delete_squad_%d" value="del" />' % (the_squad.id, the_squad.id) else: delete = '<label for="disband_squad_%d">Disband</label> <input type="checkbox" id="disband_squad_%d" value="disb" />' % (the_squad.id, the_squad.id) output.append(""" <tr> <td>%(name)s</td> <td>%(type)s</td> <td>%(amount)s</td> <td>%(amount_field)s</td> <td>%(delete)s</td> </tr> """ % { "id": the_squad.id, "name": '<input type="text" id="rename_squad_%d" value="%s" />' % (the_squad.id, the_squad.name), "type": the_unit.name, "amount": common.number_format(the_squad.amount), "amount_field": '<input type="text" id="squad_amount_%d" value="" size="7"/>' % the_squad.id, "delete": delete, "merge_amount": '<input type="text" id="merge_amount_%d" value="" size="7"/>' % the_squad.id, }) run_java.append(""" var temp_squad_amount = $('#squad_amount_%(id)d').val(); var temp_delete_squad = $('#delete_squad_%(id)d').attr("checked"); var temp_disband_squad = $('#disband_squad_%(id)d').attr("checked"); if (temp_delete_squad) { squad_delete_orders += 'Delete squad: %(squad_name)s from %(army_name)s\\n'; } else { if (temp_squad_amount != '') { if (temp_disband_squad) { temp_army_recruit_orders += 'Disband squad: %(squad_name)s, ' + temp_squad_amount + '\\n'; } else { temp_army_recruit_orders += 'Reinforce squad: %(squad_name)s, ' + temp_squad_amount + '\\n'; } } } var temp_squad_name = $('#rename_squad_%(id)d').val(); var temp_squad_army = $('#move_field_%(id)d').val(); if (temp_squad_name != '' && temp_squad_name != '%(squad_name)s') { squad_rename_orders += "\\nRename squad: %(squad_name)s in %(army_name)s, " + temp_squad_name; } """ % { "id": the_squad.id, "squad_name": common.js_name(the_squad.name), "army_name": common.js_name(the_army.name), }) return "".join(output), "".join(load_java), "".join(run_java)
def main(cursor): army_id = int(common.get_val('army', 0)) garrison_id = int(common.get_val('garrison', 0)) if army_id < 1 and garrison_id > 0: the_army = army_q.get_one_garrison(cursor, garrison_id) else: the_army = army_q.get_one_army(cursor, army_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_army.x, the_army.y)# default value last_location = "%s,%s" % (the_army.old_x, the_army.old_y) if the_army.garrison > 0: new_location = """ <td><label for="garrison">Garrison:</label></td> <td>%s</td> """ % (city_q.get_one_city(cursor, the_army.garrison).name) else: new_location = """ <td style="padding: 0px;"><a href="web.py?mode=view_map&new_mode=edit_army&army=%s" class="block_link">Location:</a></td> <td style="padding: 1px;">%s</td>""" % (the_army.id, common.text_box("location", new_location)) output = [] output.append("""<div style="float: right; width: 50%%;"> <strong>Squads in army</strong> <div id="army_squads"> </div> </div>""") output.append("<div style='padding: 5px;'>") if the_army.base > 0: base_name = "%s (%d)" % (city_q.get_one_city(cursor, the_army.base).name, the_army.base) else: base_name = "None" output.append(""" <form action="exec.py" id="the_army_form" method="post" accept-charset="utf-8"> <input type="hidden" name="mode" id="mode" value="edit_army_commit" /> <input type="hidden" name="id" id="id" value="%(army_id)s" /> Editing: %(name_text)s <br /><br /> <table border="0" cellspacing="5" cellpadding="5"> <tr> <td><label for="team">Team:</label></td> <td style="padding: 1px;">%(owner_select)s</td> <td width="5"> </td> %(location)s </tr> <tr> <td> </td> <td> </td> <td width="5"> </td> <td>Last location:</td> <td>%(last_location)s</td> </tr> <tr> <td>Base:</td> <td>%(base)s</td> <td width="5"> </td> <td>Distance:</td> <td>%(distance)s</td> </tr> <tr> <td colspan="5" style="padding: 0;"><a class="block_link" href="#" onclick="$('#the_army_form').submit();">Apply changes</a></td> </tr> </table> </form> <form id="delete_form" action="exec.py" method="post" accept-charset="utf-8"> <input type="hidden" name="army" id="army" value="%(army_id)s" /> <input type="hidden" name="mode" id="mode" value="remove_army" /> <input style="float:right; margin-right:100px;" type="button" value="Delete army" onclick="var answer = confirm('Delete %(name_safe)s?') if (answer) $('#delete_form').submit();" /> </form> <br /><br />""" % { "name_safe": common.js_name(the_army.name), "army_id": the_army.id, "name": the_army.name, "name_text": common.text_box("name", the_army.name), "owner_select": team_f.structured_list(cursor, default=the_army.team), "location": new_location, "last_location": last_location, "base": base_name, "distance": the_army.distance, }) output.append(common.onload("$('#army_squads').load('web.py', {'mode':'list_squads','army':'%d', 'ajax':'True'});" % int(the_army.id))) output.append("</div>") page_data['Title'] = "Edit army %s" % the_army.name return "".join(output)
def main(cursor): # Get city Id city_id = int(common.get_val("city", 1)) if city_id < 1: return "No city selected" # Build city item the_city = city_q.get_one_city(cursor, city_id) # Get buildings list building_dict = building_q.get_all_buildings(cursor) # 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_city.x, the_city.y) # default value output = [] output.append( """<div style="float: right; width: 50%;"> <strong>Happiness</strong> <div id="happiness"> </div> </div>""" ) output.append( """<div style='padding: 5px;'> <form action="exec.py" method="post" accept-charset="utf-8"> <input type="hidden" name="mode" id="mode" value="edit_city_commit" /> <input type="hidden" name="id" id="id" value="%(city_id)s" /> Editing: %(name_text)s <a href="web.py?mode=edit_army&garrison=%(city_id)s">Edit garrison</a> <a href="web.py?mode=list_operatives&city=%(city_id)s">Operatives</a> <br /><br /> <table border="0" cellspacing="5" cellpadding="5"> <tr> <td><label for="team">Team:</label></td> <td colspan="4" style="padding: 1px;">%(owner_select)s</td> <td width="5"> </td> <td> </td> <td colspan="6"> </td> </tr> <tr> <td><label for="size">Size:</label></td> <td style="padding: 1px;">%(city_population_text)s</td> <td width="5"> </td> <td><label for="slaves">Slaves:</label></td> <td style="padding: 1px;">%(city_slaves_text)s</td> <td width="5"> </td> <td style="padding: 0px;"> <a class="block_link" href="web.py?mode=view_map&new_mode=edit_city&city=%(city_id)s"">Location:</a> </td> <td style="padding: 1px;">%(city_location_text)s</td> <td> </td> <td> </td> </tr> <tr> <td><label for="port">Port:</label></td> <td>%(city_port_checkbox)s</td> <td><label for="nomadic">Nomadic:</label></td> <td>%(city_nomadic_checkbox)s</td> <td><label for="dead">Dead:</label></td> <td>%(city_dead)s</td> <td><label for="secret">Secret:</label></td> <td>%(city_secret_checkbox)s</td> <td><label for="founded">Founded:</label></td> <td>%(founded_text)s</td> </tr> <tr> <td colspan="10"> Description:<br /> %(city_description_textarea)s </td> </tr> </table> <br /> <input type="submit" value="Perform edit" /> </form> <form id="delete_form" action="exec.py" method="post" accept-charset="utf-8"> <input type="hidden" name="city" id="city" value="%(city_id)s" /> <input type="hidden" name="mode" id="mode" value="remove_city" /> <input style="float:right; margin-right:100px;" type="button" value="Delete city" onclick="var answer = confirm('Delete %(name_safe)s?') if (answer) $('#delete_form').submit();" /> </form> <br /><br />""" % { "city_id": city_id, "name": the_city.name, "name_text": common.text_box("name", the_city.name, size=20), "owner_select": team_f.structured_list(cursor, default=the_city.team, field_name="team"), # "city_location_text": common.text_box("location", "%s,%s" % (the_city.x, the_city.y), 10), "city_location_text": common.text_box("location", new_location, 10), "city_population_text": common.text_box("population", the_city.population, 10), "city_slaves_text": common.text_box( "slaves", the_city.slaves, 10, warn_on=lambda x: (True if int(x) < 0 else False) ), "city_port_checkbox": common.check_box("port", the_city.port), "city_dead": common.text_box("dead", the_city.dead, 5), "city_nomadic_checkbox": common.check_box("nomadic", the_city.nomadic), "city_secret_checkbox": common.check_box("secret", the_city.secret), "city_description_textarea": '<textarea name="description" id="description" rows="4" cols="40">%s</textarea>' % the_city.description, "founded_text": the_city.founded, "name_safe": common.js_name(the_city.name), } ) # Buildings # ---------------------- the_city.get_buildings(cursor) output.append( """ <table style="float:left; margin-right: 25px;" border="0" cellspacing="0" cellpadding="5"> <tr class="row2"> <th>Building</th> <th>Progress</th> <th>Amount</th> <th> </th> <th> </th> </tr> """ ) counter = -1 building_remove_list = [] for building_id, completion in the_city.buildings.items(): counter += 1 building_remove_list.append(building_id) output.append( """ <tr class="row%(row)d"> <form id="b_%(building_id)s" action="exec.py" method="get" accept-charset="utf-8"> <input type="hidden" name="mode" value="set_building" /> <input type="hidden" name="city" value="%(city_id)s" /> <input type="hidden" name="building" value="%(building_id)s" /> <td><label for="%(building_name)s">%(building_name)s</label></td> <td style="padding: 1px;"> %(building_completion_text)s/%(building_build_time)s </td> <td style="padding: 1px;"> %(building_amount_text)s </td> <td style="padding: 0px;"> <!--<a class="block_link" href="#" onclick="$('#b_%(building_id)s').submit();">Edit</a>--> <input type="submit" value="Edit" /> </td> <td style="padding: 0px;"> <a class="block_link" href="exec.py?mode=set_building&building=%(building_id)d&city=%(city_id)d&completion=0&amount=0">Remove</a> </td> </form> </tr>""" % { "row": (counter % 2), "building_name": building_dict[building_id].name, "building_id": building_id, "building_build_time": building_dict[building_id].build_time, "city_id": city_id, "building_completion_text": common.text_box("completion", the_city.buildings[building_id], size=4), "building_amount_text": common.text_box("amount", the_city.buildings_amount[building_id], size=3), } ) output.append( """ <tr class="row%(row)d"> <form id="city_add_building_form" action="exec.py" method="post" accept-charset="utf-8"> <input type="hidden" name="mode" value="set_building" /> <input type="hidden" name="city" value="%(city_id)s" /> <td style="padding:1px;"> <select id="new_building" name="building" onchange="$('#building_completion_span').load('web.py', {mode: 'get_building_build_time', building: document.getElementById('new_building').value, ajax:'True'});"> %(building_option_box)s </select> </td> <td style="padding:1px;"> %(building_completion_text)s/<span id="building_completion_span">000</span> </td> <td style="padding:1px;"> %(building_amount_text)s </td> <td style="padding: 0px;" colspan="2"> <input type="submit" value="Add" /> <!--<a href="#" onclick="$('#city_add_building_form').submit();" class="block_link">Add</a>--> </td> </tr> </form> </table> %(onload)s """ % { "row": ((counter + 1) % 2), "city_id": the_city.id, "building_option_box": building_f.building_option_list(cursor, building_remove_list), "building_completion_text": common.text_box("completion", 0, size=4), "building_amount_text": common.text_box("amount", 0, size=3), "onload": common.onload("$('#new_building').focus();"), } ) output.append( common.onload( "$('#building_completion_span').load('web.py', {mode: 'get_building_build_time', building: document.getElementById('new_building').value, 'ajax':1});" ) ) output.append("<strong>Wonder construction speed</strong>") output.append("<ul>") # Work out city points cities_dict = city_q.get_cities_from_team(cursor, the_city.team) total_points = 0 for city_id2, city2 in cities_dict.items(): if city2.team != the_city.team: continue if city2.dead == True: continue points = city_rules.wonder_build_rate(city2, the_city) if points > 0: output.append("<li>%s: %s</li>" % (city2.name, points)) total_points += points output.append("<li><em>Total: %s</em></li>" % total_points) output.append("</ul>") output.append( common.onload( "$('#happiness').load('web.py', {'mode':'happiness_breakdown','city':'%d', 'ajax':'True'});" % int(the_city.id) ) ) # output.append('''<img src="%simages/grid_25.png" width="0" height="0" onload="">''' % common.data['media_path']) output.append("</div>") page_data["Title"] = "Edit city (%s)" % the_city.name 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 make_report(the_world, the_team): output = [] city_dict = the_world.cities() team_dict = the_world.teams() # Tabs # output.append(tabs(cursor, the_team)) # Date output.append("<h2>Spy report for turn %d</h2><br />\n" % common.current_turn()) # Actual output city_dict = the_world.cities() locations = location_list(the_world, the_team) team_output = {} # Foreign # output.append('<span class="stitle">Foreign reports</span><br />') for city_id, the_city in city_dict.items(): if city_id in locations: if the_city.team != the_team.id: reports = produce_location_report(the_world, the_team, city_id) for r in reports: if r.enemy not in team_output: team_output[r.enemy] = [] team_output[r.enemy].append(r) # output.append(fout) options = [] for k, v in team_output.items(): output.append('<span class="stitle" id="%s">%s</span><br />' % (common.js_name(team_dict[k].name), team_dict[k].name)) # headers.append('<a href="#%s">%s</a>' % (team_dict[k].name, common.js_name(team_dict[k].name))) options.append(team_dict[k].name) last_city = -1 for r in v: if last_city != r.city: output.append("<strong id='%s'>%s</strong>" % (common.js_name(city_dict[r.city].name), city_dict[r.city].name)) options.append(city_dict[r.city].name) last_city = r.city output.append('<div class="spy_report_new">') # output.append(common.bbcode_to_html(r)) output.append(common.bbcode_to_html(r.content)) output.append("</div>") form = """ <div style="cursor: pointer; padding:5px; color: #00A;" onclick=" $(this).hide(500); $('#option_list').show(500);"> Display jump list </div> <div id="option_list" style="display:none;"> %s <br /><br /> </div> """ % "<br />".join(['<a href="#%s">%s</a>' % (common.js_name(o), o) for o in options]) output.insert(1, form) # print("".join(output)) # print("<br />".join(headers)) # exit() # Our cities ''' output.append('<br /><span class="stitle">Internal reports</span><br />') for city_id, the_city in the_world.cities_from_team(the_team.id).items(): output.append(produce_location_report_own_city(the_world, the_team, city_id)) ''' # output.append(operative_list(the_world, the_team)) # output.append() return "".join(output)