示例#1
0
def port_cities(cursor):
	output = []
	
	city_dict = city_q.get_live_cities(cursor)
	for k, c in city_dict.items():
		if not c.port: continue
		
		landlocked = True
		
		if landlocked and mapper_q.get_terrain(cursor, c.x - 10, c.y - 10) == 0: landlocked = False
		if landlocked and mapper_q.get_terrain(cursor, c.x, c.y - 10) == 0: landlocked = False
		if landlocked and mapper_q.get_terrain(cursor, c.x + 10, c.y - 10) == 0: landlocked = False
		
		if landlocked and mapper_q.get_terrain(cursor, c.x - 10, c.y) == 0: landlocked = False
		if landlocked and mapper_q.get_terrain(cursor, c.x + 10, c.y) == 0: landlocked = False
		
		if landlocked and mapper_q.get_terrain(cursor, c.x - 10, c.y + 10) == 0: landlocked = False
		if landlocked and mapper_q.get_terrain(cursor, c.x, c.y + 10) == 0: landlocked = False
		if landlocked and mapper_q.get_terrain(cursor, c.x + 10, c.y + 10) == 0: landlocked = False
		
		if landlocked:
			output.append("%s (%d)" % (c.name, k))
	
	if output != []:
		output.insert(0, "[r]Landlocked ports[/r]")
		output.append("\n")
	
	return "\n".join(output)
示例#2
0
def main(cursor):
	output = []
	
	city_id = int(common.get_val('city', 1))
	if city_id < 1: return "No city selected"
	
	# Build city item
	team_dict = team_q.get_all_teams(cursor)
	city_dict = city_q.get_live_cities(cursor)
	if city_id not in city_dict:
		return "You must select live cities"
	
	the_city = city_dict[city_id]
	
	output.append("""
	<div style="padding:5px;">
	<span class="stitle">{name}</span><br />
	<table border="0" cellspacing="0" cellpadding="5">
		<tr class="row2">
			<th>Partner</th>
			<th colspan="2">Distance</th>
		</tr>""".format(
			name = the_city.name,
		))
	
	query = """SELECT city_2, distance FROM trade_distances WHERE city_1 = %d ORDER BY distance ASC""" % city_id
	try: cursor.execute(query)
	except Exception as e:
		raise Exception("Database error: %s\nQuery: %s" % (str(e.args[0]).replace("\n",""), query))
	for i, row in enumerate(cursor):
		if city_dict[row['city_2']].team == the_city.team:
			style = "color: #070;font-weight:bold;"
		else:
			style = "color: #007;"
			
		tr_row = i % 2
		
		output.append("""
		<tr class="row{tr_row}">
			<td><a class="clear_link" href="web.py?mode=view_city_matrix&amp;city={partner_id}">{partner}</a> (<em style="{style}">{team}</em>)</td>
			<td>{distance}</td><td><em>{real_distance}</em></td>
		</tr>
		""".format(
			tr_row = tr_row,
			style = style,
			partner_id = row['city_2'],
			partner = city_dict[row['city_2']].name,
			team = team_dict[city_dict[row['city_2']].team].name,
			
			distance = row['distance'],
			real_distance = int(sad_rules.reverse_trade_distance(row['distance'])),
		))
	
	page_data['Title'] = "City matrix (%s)" % the_city.name
	output.append("</table></div>")
	return "".join(output)
示例#3
0
def city_terrain(cursor, verbose):
	queries = []
	city_dict = city_q.get_live_cities(cursor)
	
	if verbose:
		it = cli_f.progressbar(city_dict.items(), "cities_check.city_terrain: ", 40, with_eta = True)
	else:
		it = city_dict.items()
	
	for k, c in it:
		t = mapper_q.get_terrain(cursor, c.x, c.y)
		
		if t != c.terrain:
			queries.append("UPDATE cities SET terrain = %d WHERE id = %d;" % (t, k))
	
	database.query(cursor, *queries)
示例#4
0
def overlapping_cities(cursor, verbose):
	city_dict = city_q.get_live_cities(cursor)
	
	checked = []
	overlap_dict = {}
	
	for id1, c1 in city_dict.items():
		c1.overlap = 0
	
	# Cache some stuff
	if verbose:
		it = cli_f.progressbar(city_dict.items(), "cities_check.overlapping_cities: ", 40, with_eta = True)
	else:
		it = city_dict.items()
	
	for id1, c1 in it:
		checked.append(id1)
		
		for id2, c2 in city_dict.items():
			if id2 in checked: continue
			
			amount = city_f.overlap(c1, c2)
			
			c1.overlap += city_f.overlap_percentage(c1, amount)
			c2.overlap += city_f.overlap_percentage(c2, amount)
	
	# Reset all cities
	query = """UPDATE cities SET overlap = 0"""
	try: cursor.execute(query)
	except Exception as e:
		raise Exception("Database error: %s\nQuery: %s" % (str(e.args[0]).replace("\n",""), query))
	
	updates = 0
	for id1, c1 in city_dict.items():
		if c1.overlap >= 1:
			updates += 1
			
			query = "UPDATE cities SET overlap = %d WHERE id = %d;" % (c1.overlap, id1)
			# print("%s - %s" % (query, c1.name))
			# continue
			
			try: cursor.execute(query)
			except Exception as e:
				raise Exception("Database error: %s\nQuery: %s" % (str(e.args[0]).replace("\n",""), query))
示例#5
0
def build_supplies(cursor, verbose):
	city_dict = city_q.get_live_cities(cursor)
	city_supply_dict = {}
	
	for k, v in city_dict.items():
		v.icon_size = map_data.map_image_size(v.population+v.slaves)/4
	
	if verbose:
		it = cli_f.progressbar(map_resources.data_list, "cities_check.build_supplies: ", 40, with_eta = True)
	else:
		it = map_resources.data_list
	
	for r, x, y in it:
		this_city = (-1, 9999)
		
		for k, v in city_dict.items():
			dist = path_f.pythagoras((v.x, v.y), (x, y))
			if dist < v.icon_size:
				if this_city[1] > v.founded:
					this_city = (k, v.founded)
		
		if this_city[0] > 0:
			if this_city[0] not in city_supply_dict:
				city_supply_dict[this_city[0]] = []
			city_supply_dict[this_city[0]].append(r)
	
	query = "UPDATE cities SET str_supplies = '';"
	try: cursor.execute(query)
	except Exception as e:
		raise Exception("Database error: %s\nQuery: %s" % (str(e.args[0]).replace("\n",""), query))
	
	for k, v in city_supply_dict.items():
		vset = [str(r) for r in set(v)]
		
		query = "UPDATE cities SET str_supplies = '{0}' WHERE id = {1:d};".format(
			",".join(vset), k,
		)
		
		try: cursor.execute(query)
		except Exception as e:
			raise Exception("Database error: %s\nQuery: %s" % (str(e.args[0]).replace("\n",""), query))
示例#6
0
def water_cities(cursor):
	sea = []
	lakes = []
	
	city_dict = city_q.get_live_cities(cursor)
	for k, c in city_dict.items():
		t = mapper_q.get_terrain(cursor, c.x, c.y)
		
		if t == 0:
			sea.append("%s (%d)" % (c.name, k))
		if t == map_data.terrain.index("lake"):
			lakes.append("%s (%d)" % (c.name, k))
	
	if sea != []:
		sea.insert(0, "[r]Sea based cities[/r]")
		sea.append("\n")
	
	if lakes != []:
		lakes.insert(0, "[r]Lake based cities[/r]")
		lakes.append("\n")
	
	return "%s%s" % ("\n".join(sea), "\n".join(lakes))
示例#7
0
def main(cursor):
	wonders_dict = wonder_q.get_all_wonders(cursor)
	cities_dict = city_q.get_all_cities(cursor)
	teams_dict = team_q.get_all_teams(cursor)
	
	output = []
	
	output.append("""
	<table border="0" cellspacing="0" cellpadding="5" style="width: 100%;">
		<tr class="row2">
			<th>Wonder name</th>
			<th>City</th>
			<th>Points</th>
			<th>Materials</th>
			<th>Description</th>
			<th>&nbsp;</th>
		</tr>""")
	
	count = -1
	if len(wonders_dict) > 0:
		for wonder_id, the_wonder in wonders_dict.items():
			count += 1
			
			# May need a key-exception try-catch block around this
			the_city = cities_dict[the_wonder.city]
			# city_string = "%s <em>(%s)</em>" % (the_city.name, teams_dict[the_city.team].name)
		
			output.append("""
			<tr class="row%(row)d" id="%(wonder_id)d">
				<td>%(name)s</td>
				<td>%(city)s <em>%(team)s</em></td>
			
				<td>%(completion)s/%(point_cost)s</td>
				<td>%(material_cost)s</td>
			
				<td>%(description)s</td>
			
				<td style="padding: 0px;"><a class="block_link" href="web.py?mode=edit_wonder&amp;wonder=%(wonder_id)d">Edit wonder</a></td>
			</tr>
			""" % {	'row': (count % 2),
				
					'wonder_id':	the_wonder.id,
					'name':			common.doubleclick_text("wonders", "name", the_wonder.id, the_wonder.name, "font-weight:bold"),
				
					"completion":		common.doubleclick_text("wonders", "completion", the_wonder.id, the_wonder.completion, size=5),
					"point_cost":		common.doubleclick_text("wonders", "point_cost", the_wonder.id, the_wonder.point_cost, size=5),
					"material_cost":	common.doubleclick_text("wonders", "material_cost", the_wonder.id, the_wonder.material_cost, size=5),
				
					"description":		the_wonder.description,
				
					'city':		the_city.name,
					"team":		teams_dict[the_wonder.team].name,
				})



	cities_dict = city_q.get_live_cities(cursor)
	names = {}
	for c, the_city in cities_dict.items():
		names[c] = the_city.name

	# Add new wonder
	count += 1
	output.append("""
	<tr class="row%(row)d">
		<form action="exec.py" id="add_wonder_form" method="post" accept-charset="utf-8">
		<input type="hidden" name="mode" value="add_wonder" />
	
		<td style="padding: 1px;"><input type="text" name="name" id="new_name" value="" /></td>
		<td style="padding: 0px;">%(city_menu)s</td>
		<td style="padding: 2px;"><input type="text" name="point_cost" value="" size="7"/></td>
		<td style="padding: 2px;"><input type="text" name="material_cost" value="" size="7"/></td>
	
		<td style="padding: 2px;"><input type="text" style="width:95%%;" name="description" value=""/></td>
	
		<td style="padding: 0px;"><a class="block_link" href="#" onclick="$('#add_wonder_form').submit();">Add</a></td>
		</form>
		%(onload)s
	</tr>
	""" % {	'row': (count % 2),
		
			"city_menu":					common.option_box(
				name='city',
				elements=names,
				element_order=cities_dict.keys(),
				custom_id="",
				# selected=the_artefact.city,
			),
			"onload":	common.onload("$('#new_name').focus();"),
			})


	output.append("</table>")

	return "".join(output)
示例#8
0
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&amp;battle={0}" class="block_link">Perform</a>'.format(battle_id))
	output.append("""
	<a href="web.py?mode=list_campaigns&amp;turn={turn}" class="block_link" style="display:inline; text-align:left;">Campaigns of this turn</a>
	<a href="web.py?mode=setup_campaign&amp;campaign={campaign_id}" class="block_link" style="display:inline;">Setup campaign</a>
	<a href="web.py?mode=list_battles&amp;campaign={campaign_id}" class="block_link" style="display:inline;">List battles</a>
	<a href="web.py?mode=perform_battle&amp;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">&nbsp;</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&amp;new_mode=setup_battle&amp;battle={battle_id}"">Location:</a>
				</td>
				<td style="padding: 1px;">{battle_location_text}</td>
				
				<td>&nbsp;</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>&nbsp;</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)
示例#9
0
def check_army_bases(cursor, verbose):
	team_dict = team_q.get_all_teams(cursor)
	army_dict = army_q.get_armies_from_team_list(cursor, list(team_dict.keys()))
	city_dict = city_q.get_live_cities(cursor)
	relations = team_q.get_relations(cursor)# [Host][Visitor]
	
	# Build up a shortlist dict of cities by team
	city_by_team = {}
	for team_id, the_team in team_dict.items():
		if team_id not in city_by_team:
			city_by_team[team_id] = []
		
		for city_id, the_city in city_dict.items():
			if the_city.team == team_id or relations.get(the_city.team, {}).get(team_id, {}).get('border', team_dict[the_city.team].default_borders) >= team.border_states.index("Allied"):
				city_by_team[team_id].append(city_id)
	
	# Now to run through the armies and find their paths
	new_bases = set()
	# for i in progressbar(range(15), "Computing: ", 40):
	# for army_id, the_army in army_dict.items():
	
	if verbose:
		it = cli_f.progressbar(army_dict.items(), "military_check.check_army_bases: ", 40, with_eta = True)
	else:
		it = army_dict.items()
	
	for army_id, the_army in it:
		army_terrain = mapper_q.get_terrain(cursor, the_army.x, the_army.y)
		
		for city_id in city_by_team[the_army.team]:
			if army_terrain < 1:
				if not the_city.port: continue
			
			the_city = city_dict[city_id]
			if the_city.dead > 0: continue
			dist = path_f.pythagoras((the_army.x, the_army.y), (the_city.x, the_city.y))
			
			if dist < 10:
				the_army.base = city_id
				the_army.distance = (dist/map_data.movement_speeds['Marching'])*10# Distance over speed in km, 1 distance unit is 10k
				new_bases.add(army_id)
			
		# Extend the search a little
		if army_id not in new_bases:
			for city_id in city_by_team[the_army.team]:
				if army_terrain < 1:
					if not the_city.port: continue
				
				the_city = city_dict[city_id]
				dist = path_f.pythagoras((the_army.x, the_army.y), (the_city.x, the_city.y))
			
				if dist < 30:
					the_army.base = city_id
					the_army.distance = (dist/map_data.movement_speeds['Marching'])*10# Distance over speed in km, 1 distance unit is 10k
					new_bases.add(army_id)
		
		# Extend the search a little
		if army_id not in new_bases:
			for city_id in city_by_team[the_army.team]:
				if army_terrain < 1:
					if not the_city.port: continue
				
				the_city = city_dict[city_id]
				dist = path_f.pythagoras((the_army.x, the_army.y), (the_city.x, the_city.y))
			
				if dist < 60:
					the_army.base = city_id
					the_army.distance = (dist/map_data.movement_speeds['Marching'])*10# Distance over speed in km, 1 distance unit is 10k
					new_bases.add(army_id)
		
		# If we can't find an easy solution we start pathing
		if army_id not in new_bases:
			fastest_path = (-1, 9999999)
			
			for city_id in city_by_team[the_army.team]:
				the_city = city_dict[city_id]
				
				# Small cities won't support an army a long way away right?
				if the_city.size < 5000: continue
				
				# Is it a fleet?
				if army_terrain < 1:
					if not the_city.port: continue
					
					# Now lets try water
					dist = path_f.path(cursor, ((the_army.x, the_army.y), (the_city.x, the_city.y)), move_speed="Sailing", move_type="Sail")
					
					if dist.time_cost < fastest_path[1]:
						fastest_path = (city_id, dist.time_cost)
				
				else:
					# I'm sure there's a way to improve this...
					dist = path_f.path(cursor, ((the_army.x, the_army.y), (the_city.x, the_city.y)), move_speed="Marching", move_type="Medium foot")
					
					if dist.time_cost == 0:
						continue
					
					# if army_id == 960 and city_id == 1098:
					# 	print("")
					# 	print(dir(dist))
					# 	print(((the_army.x, the_army.y), (the_city.x, the_city.y)))
					# 	print(dist.time_cost)
					# 	print(dist.walk_distance)
					# 	print(len(dist.steps))
					# 	print("")
					
					if dist.time_cost < fastest_path[1]:
						fastest_path = (city_id, dist.time_cost)
				
			the_army.base = fastest_path[0]
			the_army.distance = fastest_path[1]
			new_bases.add(army_id)
	
	# Reset all armies
	query = """UPDATE armies SET base = -1, distance = -1 WHERE garrison = 0;"""
	try: cursor.execute(query)
	except Exception as e:
		raise Exception("Database error: %s\nQuery: %s" % (str(e.args[0]).replace("\n",""), query))
	
	for a in new_bases:
		query = """UPDATE armies SET base = %d, distance = %d WHERE id = %d;""" % (army_dict[a].base, army_dict[a].distance, a)
		try: cursor.execute(query)
		except Exception as e:
			raise Exception("Database error: %s\nQuery: %s" % (str(e.args[0]).replace("\n",""), query))
	
	# Garrisons automatically go to their city
	query = """UPDATE armies SET base = garrison, distance = 0 WHERE garrison > 0;"""
	try: cursor.execute(query)
	except Exception as e:
		raise Exception("Database error: %s\nQuery: %s" % (str(e.args[0]).replace("\n",""), query))
示例#10
0
def main(cursor):
	operative_id = int(common.get_val('operative'))
	
	the_operative = operative_q.get_one_operative(cursor, operative_id)
	
	city_dict = city_q.get_live_cities(cursor)
	
	names = {}
	for c, the_city in city_dict.items():
		names[c] = the_city.name
	
	output = []
	
	output.append("<div style='padding: 5px;'>")
	
	output.append("""
	<form action="exec.py" id="the_operative_form" method="post" accept-charset="utf-8">
		<input type="hidden" name="mode" id="mode" value="edit_operative_commit" />
		<input type="hidden" name="id" id="id" value="{operative_id}" />
		<input type="hidden" name="team" id="team" value="{team}" />
		
		<table border="0" cellspacing="5" cellpadding="5">
			<tr>
				<td><label for="name">Identifier:</label></td>
				<td style="padding: 1px;">{name}</td>
		
				<td width="5">&nbsp;</td>
				
				<td>&nbsp;</td>
				<td>&nbsp;</td>
				
				<td width="5">&nbsp;</td>
				
				<td>&nbsp;</td>
				<td>&nbsp;</td>
			</tr>
			<tr>
				<td><label for="location">Location:</label></td>
				<td style="padding: 1px;">{city_select}</td>
			
				<td width="5">&nbsp;</td>
			
				<td><label for="arrival">Arrival:</label></td>
				<td style="padding: 2px;">{arrival}</td>
				
				<td width="5">&nbsp;</td>
				
				<td><label for="size">Size:</label></td>
				<td style="padding: 2px;">{size}</td>
			</tr>
			<tr>
				<td><label for="stealth">Stealth:</label></td>
				<td style="padding: 2px;">{stealth}</td>
				
				<td>&nbsp;</td>
				
				<td><label for="observation">Observation:</label></td>
				<td style="padding: 2px;">{observation}</td>
				
				<td>&nbsp;</td>
				
				<td><label for="integration">Integration:</label></td>
				<td style="padding: 2px;">{integration}</td>
			</tr>
			<tr>
				<td><label for="sedition">Sedition:</label></td>
				<td style="padding: 2px;">{sedition}</td>
				
				<td>&nbsp;</td>
				
				<td><label for="sabotage">Sabotage:</label></td>
				<td style="padding: 2px;">{sabotage}</td>
				
				<td>&nbsp;</td>
				
				<td><label for="assassination">Assassination:</label></td>
				<td style="padding: 2px;">{assassination}</td>
			</tr>
			<tr>
				<td colspan="8" style="padding: 0;">
					<a class="block_link" href="#" onclick="$('#the_operative_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="operative" id="operative" value="{operative_id}" />
		<input type="hidden" name="mode" id="mode" value="remove_operative" />
		<input style="float:right; margin-right:100px;" type="button" value="Delete operative" onclick="var answer = confirm('Delete operative?')
		if (answer) $('#delete_form').submit();" />
	</form>
	<br /><br />""".format(
		operative_id	= operative_id,
		team			= the_operative.team,
		size			= common.text_box("size", the_operative.size),
		arrival			= common.text_box("arrival", the_operative.arrival, size=3),
		name		= common.text_box("name", the_operative.name),
		
		stealth			= common.text_box("stealth", the_operative.stealth, size=3),
		observation		= common.text_box("observation", the_operative.observation, size=3),
		integration		= common.text_box("integration", the_operative.integration, size=3),
		sedition		= common.text_box("sedition", the_operative.sedition, size=3),
		sabotage		= common.text_box("sabotage", the_operative.sabotage, size=3),
		assassination	= common.text_box("assassination", the_operative.assassination, size=3),
		
		city_select		= common.option_box(
			name='city',
			elements=names,
			element_order=city_dict.keys(),
			custom_id="",
			selected=the_operative.city
		),
	))
	
	output.append("</div>")
	
	return "".join(output)
示例#11
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)
示例#12
0
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">&nbsp;</td>
			
				<td><label for="team">Team:</label></td>
				<td>%(team_menu)s</td>
			
				<td width="5">&nbsp;</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">&nbsp;</td>
			
				<td><label for="point_cost">Point cost:</label></td>
				<td style="padding: 1px;">%(point_cost)s</td>
			
				<td width="5">&nbsp;</td>
			
				<td><label for="material_cost">Material cost:</label></td>
				<td style="padding: 1px;">%(material_cost)s</td>
			</tr>
			<tr>
				<td colspan="10">&nbsp;&nbsp;&nbsp;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)
示例#13
0
def main(cursor):
	output = []
	
	# Team select
	team_select = team_f.structured_list(cursor, include_irs = False, default=-1, field_name="team", field_id="team_select", skip=[])
	team_select = team_select.replace(">", '><option value="-1" selected="selected">GM report</option>', 1)
	
	# City select
	city_names = {}
	cities_dict = city_q.get_live_cities(cursor)
	team_dict = team_q.get_all_teams(cursor)
	for c, the_c in cities_dict.items():
		if the_c.dead > 0: continue
		city_names[c] = "{0} (<em>{1}</em>)".format(the_c.name, team_dict[the_c.team].name)
	
	# Selection output
	output.append("""
	<form action="web.py?mode=generate_report" method="post" accept-charset="utf-8">
		<table border="0" cellspacing="0" cellpadding="5">
			<tr>
				<td>Team:</td>
				<td style="padding:1px;">{team_select}</td>
			</tr>
			<tr>
				<td>Target team:</td>
				<td>{target_team_select}</td>
			</tr>
			<tr>
				<td colspan="2">
					<input type="submit" value="Continue &rarr;" />
				</td>
			</tr>
		</table>
	</form>
	<br /><br />
	
	<form action="web.py?mode=generate_report" id="report_form" method="post" accept-charset="utf-8">
		<table border="0" cellspacing="0" cellpadding="5">
			<tr>
				<td>Team:</td>
				<td style="padding:1px;">{team_select}</td>
			</tr>
			<tr>
				<td>Target city:</td>
				<td>{city_select}</td>
			</tr>
			<tr>
				<td>Target area:</td>
				<td><input type="text" name="area" id="area_select" value="" size="10"/>
					<input type="text" name="radius" id="radius" value="1" size="5"/></td>
			</tr>
			<tr>
				<td colspan="2">
					<input type="submit" value="Continue &rarr;" />
				</td>
			</tr>
		</table>
	</form>
	{onload}
	""".format(
		team_select = team_select,
		target_team_select = team_f.structured_list(cursor, include_irs = False, default=-1, field_name="target_team", field_id="target_team", skip=[]),
		city_select = common.option_box(
			name			= 'city',
			elements		= city_names,
			element_order	= cities_dict.keys(),
			# custom_id="",
			# selected=the_artefact.city,
		),
		onload = common.onload("$('#team_select').focus();")
	))
	
	return "".join(output)
示例#14
0
def main(cursor):
	# Get team Id
	team_id = int(common.get_val('team', 0))
	city_id = int(common.get_val('city', 0))
	
	if team_id < 1 and city_id < 1:
		return "<div style='padding: 5px;'>%s</div>" % common.select_team_form(cursor, 'list_operatives')
	
	# Handles for later
	city_dict = city_q.get_all_cities(cursor)
	team_dict = team_q.get_all_teams(cursor)
	
	# Build team
	the_team = team_dict[team_id]
	
	if team_id > 0:
		operatives_dict = operative_q.get_operatives_from_team(cursor, team=team_id)
	elif city_id > 0:
		operatives_dict = operative_q.get_operatives_from_city(cursor, city=city_id)
	
	# So we can sort them by team
	team_location = {}
	for o, the_op in operatives_dict.items():
		o_team = city_dict[the_op.city].team
		if o_team not in team_location:
			team_location[o_team] = []
		
		team_location[o_team].append(o)
	
	output = []
	output.append("""
	<table border="0" cellspacing="0" cellpadding="5" style="width: 100%;">
		<tr class="row2">
			<th>Id</th>
			<th>Size</th>
			
			<th>Stealth</th>
			<th>Observation</th>
			<th>Integration</th>
			<th>Sedition</th>
			<th>Sabotage</th>
			<th>Assassination</th>
			
			<th>Location</th>
			<th>Arrival</th>
			
			<th>&nbsp;</th>
			<th>&nbsp;</th>
		</tr>""")
	
	count = -1
	if len(operatives_dict) > 0:
		for city_team, op_list in team_location.items():
			for operative_id, the_operative in operatives_dict.items():
				
				if the_operative.id not in op_list:
					continue
				
				count += 1
				
				# Is it dead?
				if the_operative.died == 0:
					life_action = '<a href="exec.py?mode=kill_operative&amp;operative=%d" class="block_link">Kill</a>' % operative_id
					
					life_action = '''<a href="#" class="block_link" onclick="$.get('exec.py', {mode: 'kill_operative', operative:%d}, function () {$('#life_%d').html('<div class=\\'block_link\\'>Killed</div>');}); return false;">Kill</a>''' % (operative_id, operative_id)
				else:
					life_action = '<a href="exec.py?mode=revive_operative&amp;operative=%d" class="block_link">Revive (%d)</a>' % (operative_id, the_operative.died)
					
					life_action = '''<a href="#" class="block_link" onclick="$.get('exec.py', {mode: 'revive_operative', operative:%d}, function () {$('#life_%d').html('<div class=\\'block_link\\'>Revived</div>');}); return false;">Revive (%d)</a>''' % (operative_id, operative_id, the_operative.died)
				
				output.append("""
				<tr class="row{row}" id="{operative_id}">
					<td>{name}</td>
					<td>{size}</td>
					
					<td>{stealth}</td>
					<td>{observation}</td>
					<td>{integration}</td>
					<td>{sedition}</td>
					<td>{sabotage}</td>
					<td>{assassination}</td>
					
					<td>{city} ({city_team})</td>
					<td>{arrival}</td>
					
					<td style="padding: 0px;" id="life_{operative_id}">{life_action}</td>
				
					<td style="padding: 0px;"><a href="web.py?mode=edit_operative&amp;operative={operative_id}" class="block_link">Edit</a></td>
				</tr>
				""".format(
						row = (count % 2),
						
						team_id			= team_id,
						operative_id	= operative_id,
						name		= common.doubleclick_text("operatives", "name", operative_id, the_operative.name, "font-weight:bold"),
						size			= the_operative.size,
						
						arrival			= the_operative.arrival,
						stealth			= the_operative.stealth,
						observation		= the_operative.observation,
						integration		= the_operative.integration,
						sedition		= the_operative.sedition,
						sabotage		= the_operative.sabotage,
						assassination	= the_operative.assassination,
						
						city		= city_dict[the_operative.city].name,
						city_team	= team_dict[city_team].name,
						
						life_action	= life_action,
		))
	
	# Add unit type
	city_dict = city_q.get_live_cities(cursor)
	names = {}
	for c, the_city in city_dict.items():
		names[c] = the_city.name
	
	if count <= 20:
		onload = common.onload("$('#size').focus();")
	else:
		onload = ''
	
	count += 1
	if team_id > 0:
		output.append("""
		<tr class="row%(row)d">
			<form action="exec.py" method="post" id="new_operative_form" accept-charset="utf-8">
			<input type="hidden" name="mode" value="create_new_operative" />
			<input type="hidden" name="team" value="%(team_id)s" />
			<td style="padding: 1px;">
				<input type="text" name="name" id="name" value="" size="6"/>
			</td>
		
			<td style="padding: 1px;">
				<input type="text" name="size" id="size" value="1" size="3"/>
			</td>
		
			<td style="padding: 1px;">
				<input type="text" name="stealth" id="stealth" value="1" size="3"/>
			</td>
			<td style="padding: 1px;">
				<input type="text" name="observation" id="observation" value="1" size="3"/>
			</td>
			<td style="padding: 1px;">
				<input type="text" name="integration" id="integration" value="1" size="3"/>
			</td>
			<td style="padding: 1px;">
				<input type="text" name="sedition" id="sedition" value="1" size="3"/>
			</td>
			<td style="padding: 1px;">
				<input type="text" name="sabotage" id="sabotage" value="1" size="3"/>
			</td>
			<td style="padding: 1px;">
				<input type="text" name="assassination" id="assassination" value="1" size="3"/>
			</td>
		
			<td style="padding: 1px;">%(location)s</td>
			<td style="padding: 1px;"><input type="text" name="arrival" id="arrival" value="%(arrival)s" size="4"/></td>
			<td colspan="2" style="padding: 0px;"><a class="block_link" onclick="$('#new_operative_form').submit(); return false;" href="#">Add</a></td>
			%(onload)s
			</form>
		</tr>
		""" % {	'row': (count % 2),

				"team_id":		team_id,
				'location':		common.option_box(
					name='city',
					elements=names,
					element_order=city_dict.keys(),
					custom_id="",
				),
				"arrival":	common.current_turn(),
				'onload':	onload,
				})
	
	output.append("</table>")
	
	if team_id > 0:
		page_data['Title'] = "List operatives from %s" % team_dict[team_id].name
	elif city_id > 0:
		page_data['Title'] = "List operatives from %s (%s)" % (city_dict[city_id].name, team_dict[city_dict[city_id].team].name)
	
	return "".join(output)