示例#1
0
文件: stat_f.py 项目: Teifion/Rob3
def build_team_stats(cursor, the_team, the_world=None):
    current_turn = common.current_turn()

    the_stat = stat.Stat()

    # 	Primary keys
    # ------------------------
    the_stat.turn = current_turn
    the_stat.team = the_team.id

    # 	Team population and slaves
    # ------------------------
    the_stat.population = the_team.get_population(cursor)
    the_stat.slaves = the_team.get_slaves(cursor)

    # 	Resources
    # ------------------------
    the_stat.resources = the_team.get_resources(cursor).as_db_string()
    the_stat.upkeep = float(team_f.get_upkeep(the_team, the_world))
    the_stat.production = team_rules.produce_resources(cursor, the_team, the_world=the_world)[0].as_db_string()

    # 	Military stuff
    # ------------------------
    the_stat.army_size = team_q.get_army_size(cursor, the_team.id)
    the_stat.navy_size = team_q.get_navy_size(cursor, the_team.id)
    the_stat.airforce_size = team_q.get_airforce_size(cursor, the_team.id)

    # 	Solo units
    # ------------------------
    the_stat.operatives = the_team.operative_count(cursor)
    the_stat.mages = team_q.get_mage_count(cursor, the_team.id)

    # 	Other
    # ------------------------
    the_stat.land_controlled = len(mapper_f.team_influence(the_world, the_team.id))

    the_stat.city_count = len(city_q.get_cities_from_team(cursor, the_team.id))
    the_stat.war_losses = battle_q.get_team_losses(cursor, the_team.id)

    # 	Specifics
    # ------------------------
    # the_stat.temple_count		= stat_q.get_temple_count(cursor, the_team.id)

    # Delete (to allow insert)
    delete_stat(cursor, the_team.id, current_turn)

    # Insert
    insert_stat(cursor, the_stat)
示例#2
0
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">&nbsp;</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&amp;%(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&amp;city=%(city_id)d">City trade</a></td>-->
				<td style="padding: 0px;"><a class="block_link" href="web.py?mode=view_city_matrix&amp;city=%(city_id)d">City matrix</a></td>
				<td style="padding: 0px;"><a class="block_link" href="web.py?mode=edit_city&amp;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&amp;new_mode=list_cities&amp;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>&nbsp;</td>
		
		<td>&nbsp;</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)
示例#3
0
文件: team_map.py 项目: Teifion/Rob3
def _draw_map(cursor, team_id, build):
	minx, maxx = 999999, -9999999
	miny, maxy = 999999, -9999999
	
	city_dict = city_q.get_cities_from_team(cursor, team_id, include_dead=False)
	for city_id, the_city in city_dict.items():
		minx = min(minx, the_city.x)
		maxx = max(maxx, the_city.x)
		
		miny = min(miny, the_city.y)
		maxy = max(maxy, the_city.y)
	
	army_dict = army_q.get_armies_from_team(cursor, team_id, include_garrisons=False)
	for army_id, the_army in army_dict.items():
		minx = min(minx, the_army.x)
		maxx = max(maxx, the_army.x)
		
		miny = min(miny, the_army.y)
		maxy = max(maxy, the_army.y)
	
	centre = (int((maxx+minx)/2), int((maxy+miny)/2))
	radius = max((maxx-minx), (maxy-miny)) + 300
	
	the_map = mapper.Map_maker()
	the_map.centre = centre
	the_map.centre_radius = radius
	the_map.personalise	= [team_id]
	
	if build != 0:# Remote mode
		the_map.icon_path = '../map/images/teamIcons/'
	
	onclick_js = """
	var map_x = parseInt(document.getElementById('labelHideX').innerHTML);
	var map_y = parseInt(document.getElementById('labelHideY').innerHTML);
	
	use_map_xy(map_x, map_y);"""
	
	source_dict = {
		"build":				build,
		"onclick_js":			onclick_js,
		
		"output":				the_map.map_grid(cursor),
		
		# 'map_path':				"../map/images/theMap.jpg",
		# 'jquery':				"../includes/jquery.js",
		# 'transparent_path':		"../map/images/trans75.png",
		# 'key_path':				"../map/images/key.png",
	}
	
	source_dict['map_legend']	= ''
	
	source_dict["left"]			= the_map.left * 2.5
	source_dict["right"]		= the_map.right
	source_dict["top"]			= the_map.top * 2.5
	source_dict["bottom"]		= the_map.bottom
	
	source_dict["map_width"]	= the_map.width*2.5
	source_dict["map_height"]	= the_map.height*2.5
	
	x_diff = map_data.dimensions['left'] - the_map.left
	y_diff = map_data.dimensions['top'] - the_map.top
	source_dict["margin_left"]	= (x_diff + map_data.dimensions['margin_left'])*2.5
	source_dict["margin_top"]	= (y_diff + map_data.dimensions['margin_top'])*2.5
	
	if build:
		source_dict['map_path']			= '../map/images/theMap.jpg'
		source_dict['jquery']			= "../includes/jquery.js"
		source_dict['transparent_path']	= "../map/images/trans75.png"
		source_dict['key_path']			= "../map/images/key.png"
	
	output = mapper.map_source(source_dict)
	
	return output
示例#4
0
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>&nbsp;</th>
			<th>&nbsp;</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&amp;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">
						&nbsp;
					</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>&nbsp;</td>
		<td style="padding: 1px;">
			%(city_location)s
			&nbsp;&nbsp;&nbsp;
			%(text_location)s
		</td>
		<td style="padding: 0px;"><a href="web.py?mode=view_map&amp;new_mode=list_armies&amp;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)
示例#5
0
def main(cursor):
	team_id = int(common.get_val('team', 0))
	confirm = int(common.get_val('confirm', 0))
	
	if team_id < 1:
		return "<div style='padding: 5px;'>{0}</div>".format(common.select_team_form(cursor, 'purge_team'))
	
	if confirm == 0:
		return """
		<form action="web.py" method="post" accept-charset="utf-8" style="padding: 10px;">
			<input type="hidden" name="mode" id="mode" value="purge_team" />
			<input type="hidden" name="team" id="team" value="{0}" />
			<input type="hidden" name="confirm" id="confirm" value="1" />
			Are you sure?<br /><br />
			<input type="submit" value="Purge team" />
		</form>
		""".format(team_id)
	
	# Query the DB for some info
	city_dict = city_q.get_cities_from_team(cursor, team_id, include_dead=True)
	army_dict = army_q.get_armies_from_team(cursor, team_id, include_garrisons=True)
	squad_dict = squad_q.get_squads_from_team(cursor, team_id)
	
	# Turn the dictionaries into lists
	city_list = [str(c) for c in city_dict]
	army_list = [str(a) for a in army_dict]
	squad_list = [str(s) for s in squad_dict]
	
	queries = []
	
	if len(army_list) > 0:
		# Wipe squads
		queries.append("DELETE FROM squads WHERE army IN (%s)" % ",".join(army_list))
		queries.append("DELETE FROM army_monsters WHERE army IN (%s)" % ",".join(army_list))
		queries.append("DELETE FROM campaign_armies WHERE army IN (%s)" % ",".join(army_list))
		
		# Wipe armies
		queries.append("DELETE FROM armies WHERE id IN (%s)" % ",".join(army_list))
	
	if len(city_list) > 0:
		# Wipe buildings
		queries.append("DELETE FROM city_buildings WHERE city IN (%s)" % ",".join(city_list))
		
		# Wipe garrisons
		# queries.append("DELETE FROM armies WHERE garrison IN (%s)" % ",".join(city_list))
		
		# Wipe cities
		queries.append("UPDATE operatives SET city = 0 WHERE city IN (%s)" % ",".join(city_list))
		queries.append("DELETE FROM cities WHERE id IN (%s)" % ",".join(city_list))
		
		# Wipe buildings
		queries.append("DELETE FROM city_buildings WHERE city IN (%s)" % ",".join(city_list))
	
	if len(squad_list) > 0:
		# Wipe squad battle history
		queries.append("DELETE FROM squad_battle_history WHERE squad IN (%s)" % ",".join(squad_list))
	
	# Operatives
	queries.append("DELETE FROM operatives WHERE team = %s" % team_id)
	
	# Spy reports
	queries.append("DELETE FROM spy_reports WHERE team = %s" % team_id)
	
	# Resources
	queries.append("UPDATE team_resources SET amount = 0 WHERE team = %d" % int(team_id))
	queries.append("UPDATE team_resources SET amount = 1500 WHERE team = %d AND resource = 0" % int(team_id))
	queries.append("UPDATE team_resources SET amount = 300 WHERE team = %d AND resource = 1" % int(team_id))
	
	database.query_batch(cursor, queries)
	
	
	return "<br />".join(queries)
示例#6
0
def main(cursor):
	artefact_id = int(common.get_val('artefact', 0))
	all_teams	= int(common.get_val('all_teams', 0))
	
	if artefact_id < 1:
		return "No artefact selected"
	
	the_artefact = artefact_q.get_one_artefact(cursor, artefact_id)
	
	names = {}
	if all_teams == 0 and the_artefact.team > 0:
		cities_dict = city_q.get_cities_from_team(cursor, team=the_artefact.team, include_dead=1)
		for c, the_c in cities_dict.items():
			names[c] = the_c.name
	else:
		cities_dict = city_q.get_live_cities(cursor)
		for c, the_c in cities_dict.items():
			names[c] = the_c.name
	
	output = ["<div style='padding: 5px;'>"]
	
	if all_teams != 1:
		output.append("""<a class="block_link" href="web.py?mode=edit_artefact&amp;artefact=%s&amp;all_teams=1">Show all team cities</a>""" % artefact_id)
	else:
		output.append("""<a class="block_link" href="web.py?mode=edit_artefact&amp;artefact=%s&amp;all_teams=0">Show only this team's cities</a>""" % artefact_id)
	
	output.append("""
	<form action="exec.py" method="post" accept-charset="utf-8">
		<input type="hidden" name="mode" id="mode" value="edit_artefact_commit" />
		<input type="hidden" name="id" id="id" value="%(artefact_id)s" />
	
		<table border="0" cellspacing="5" cellpadding="5">
			<tr>
				<td><label for="name">Name:</label></td>
				<td>%(name_text)s</td>
		
				<td width="5">&nbsp;</td>
			
				<td><label for="city">City:</label></td>
				<td>%(city_menu)s</td>
			</tr>
			<tr>
				<td><label for="description">Description:</label></td>
				<td colspan="5">%(artefact_description_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="artefact" id="artefact" value="%(artefact_id)s" />
		<input type="hidden" name="mode" id="mode" value="remove_artefact" />
		<input style="float:right; margin-right:100px;" type="button" value="Delete artefact" onclick="var answer = confirm('Delete %(name)s?')
		if (answer) $('#delete_form').submit();" />
	</form>
	-->
	<br /><br />""" % {
		"artefact_id":					artefact_id,
		"name":				the_artefact.name,
		"city_menu":					common.option_box(
			name='city',
			elements=names,
			element_order=cities_dict.keys(),
			custom_id="",
			selected=the_artefact.city,
		),
		"name_text":			common.text_box("name", the_artefact.name, size=20),
		"artefact_description_text":	'<textarea name="description" id="description" rows="4" cols="40">%s</textarea>' % the_artefact.description,
	})
	
	output.append("</div>")
	
	return "".join(output)
示例#7
0
文件: edit_city.py 项目: Teifion/Rob3
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
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
		<a href="web.py?mode=edit_army&amp;garrison=%(city_id)s">Edit garrison</a>
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
		<a href="web.py?mode=list_operatives&amp;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">&nbsp;</td>
				
				<td>&nbsp;</td>
				<td colspan="6">&nbsp;</td>
			</tr>
			<tr>
				<td><label for="size">Size:</label></td>
				<td style="padding: 1px;">%(city_population_text)s</td>
				
				<td width="5">&nbsp;</td>
				
				<td><label for="slaves">Slaves:</label></td>
				<td style="padding: 1px;">%(city_slaves_text)s</td>
				
				<td width="5">&nbsp;</td>
				<td style="padding: 0px;">
					<a class="block_link" href="web.py?mode=view_map&amp;new_mode=edit_city&amp;city=%(city_id)s"">Location:</a>
				</td>
				<td style="padding: 1px;">%(city_location_text)s</td>
				
				<td>&nbsp;</td>
				<td>&nbsp;</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">&nbsp;&nbsp;&nbsp;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>&nbsp;</th>
		<th>&nbsp;</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&amp;building=%(building_id)d&amp;city=%(city_id)d&amp;completion=0&amp;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)