Пример #1
0
def main(cursor):
	# Get team Id
	team_id		= int(common.get_val('team', 0))
	recache		= common.get_val('recache', False)
	
	output = []
	
	output.append("""<div style="padding: 5px;">
	<form style="padding: 5px;" action="web.py" method="get" accept-charset="utf-8">
		<input type="hidden" name="mode" id="mode" value="team_stats" />
		<table border="0" cellspacing="5" cellpadding="5">
			<tr>
				<td><label for="team">Team:</label></td>
				<td>%(team_option_box)s</td>
				<td width="10">&nbsp;</td>
				<td><input type="submit" value="Get stats" /></td>
			</tr>
		</table>
	</form>
	<a href="web.py?mode=team_stats&amp;team=%(team_id)s&amp;recache=1" class="block_link">Recache</a>
	<br />""" % {
		"team_option_box":		team_f.structured_list(cursor, default=team_id),
		"last_id":				team_q.get_latest_active_team_id(cursor, skip_irs = True),
		"team_id":				team_id,
	})
	
	if team_id < 1:
		return "".join(output)
	
	ajax = False
	output.append(get_stat_core(cursor, team_id, recache, ajax))
	# output.append("</div>")
	
	return "".join(output)
Пример #2
0
Файл: ti.py Проект: Teifion/Rob3
def main(cursor):
	# Get team Id
	team_id		= int(common.get_val('team', 0))
	post_output = common.get_val('post_output', 0)
	auto_jump	= common.get_val('auto_jump', False)
	dev_mode	= common.get_val('dev_mode', 0)
	recache		= common.get_val('recache', False)
	ajax		= common.get_val('ajax', 0)
	
	output = []
	
	if not ajax:
		output.append("""<div style="padding: 5px;">
		<form style="padding: 5px;" action="web.py" method="get" accept-charset="utf-8">
			<input type="hidden" name="mode" id="mode" value="ti" />
			<table border="0" cellspacing="5" cellpadding="5">
				<tr>
					<td><label for="team">Team:</label></td>
					<td>%(team_option_box)s</td>
					<td><label for="post_output">Post ouput:</label></td>
					<td>%(post_output_checkbox)s</td>
					<td><label for="auto_jump">Auto-jump:</label></td>
					<td>%(auto_jump_checkbox)s</td>
					<td width="10">&nbsp;</td>
					<td><input type="submit" value="Get TI" /></td>
				</tr>
			</table>
		</form>
		<a href="web.py?mode=ti&amp;team=%(last_id)s&amp;post_output=1&amp;auto_jump=1" class="block_link">Update all</a>
		<br />
		
		<a href="web.py?mode=ti&amp;team=%(team_id)s&amp;recache=1" class="block_link">Recache</a>
		<br />""" % {
			"team_option_box":		team_f.structured_list(cursor, default=team_id),
			"post_output_checkbox":	common.check_box('post_output', post_output),
			"auto_jump_checkbox":	common.check_box('auto_jump', auto_jump),
			"last_id":				team_q.get_latest_active_team_id(cursor, skip_irs = True),
			"team_id":				team_id,
		})
	
	
	if team_id < 1:
		return "".join(output)
	
	if post_output:
		output.append(get_bbcode_core(cursor, team_id))
	else:
		output.append(get_ti_core(cursor, team_id, recache, ajax))
	
	if auto_jump:
		new_location = "web.py?mode=ti&post_output=%s&auto_jump=1&team=%d" % (post_output, team_q.get_next_active_team_id(cursor, team_id, skip_irs = True))
		
		if post_output:
			output.append(common.redirect(new_location, 2000))
		else:
			output.append(common.redirect(new_location))
	
	output.append("</div>")
	
	return "".join(output)
Пример #3
0
def select_team_form(cursor, target_mode, **form_values):
	"""Returns a form for selecting a team"""
	
	hidden_values = []
	for k, v in form_values.items():
		hidden_values.append('<input type="hidden" name="%s" value="%s" />' % (k, v))
	
	output = """
	<form id="select_team_form" action="web.py" method="get" accept-charset="utf-8" style="width: 250px;">
		<input type="hidden" name="mode" id="mode" value="%s" />
		%s
		%s
		<!--
		<a class="block_link" href="#" onclick="$('#select_team_form').submit(); return false;">Choose team</a>
		-->
		<input type="submit" value="Choose team" />
	</form>
	""" % (target_mode, team_f.structured_list(cursor, field_id="select_team_input"), "".join(hidden_values))
	
	return output
Пример #4
0
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&amp;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">&nbsp;</td>
				
				%(location)s
			</tr>
			<tr>
				<td>&nbsp;</td>
				<td>&nbsp;</td>
				
				<td width="5">&nbsp;</td>
				
				<td>Last location:</td>
				<td>%(last_location)s</td>
			</tr>
			<tr>
				<td>Base:</td>
				<td>%(base)s</td>
				
				<td width="5">&nbsp;</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)
Пример #5
0
def main(cursor):
	team_id		= int(common.get_val("team", 0))
	orders_str	= common.get_val("orders", "")#.replace("’", "'")
	msn_mode	= int(common.get_val("msn_mode", 0))
	
	if team_id < 1 or orders_str == "":
		return """
		<div style='padding: 5px;'>
			<form action="web.py" id="select_team_form" method="post" accept-charset="utf-8">
				<input type="hidden" name="mode" id="mode" value="test_orders" />
				<label for="msn_mode">MSN mode:</label> <input type="checkbox" id="msn_mode" name="msn_mode" value="1" />
				Team: %s
				<!--
				<a class="block_link" href="#" onclick="$('#select_team_form').submit(); return false;">Run orders</a>
				-->
				<input type="submit" value="Run orders" />
				<br />
				<textarea name="orders" rows="8" style="width: 100%%;">[o]Rob command[/o]
Enable: Overbudget

</textarea>
			</form>
		</div>%s""" % (
			team_f.structured_list(cursor, field_id="team"),
			common.onload("$('#team').focus();"),
		)
	
	the_world = world.World(cursor)
	the_world.prep_for_orders()
	
	the_team = the_world.teams()[team_id]
	produced_resources, new_resources = team_rules.produce_resources(cursor, the_team, the_world, force_requery=True)
	the_team.resources = new_resources
	blocks = request_f.convert_orders(the_world, the_team, orders_str)
	
	output = ["<div style='padding:1px;'>"]
	
	output.append("Running with resources: %s" % str(the_team.resources))
	
	# Setup
	for b in blocks:
		b.setup(msn_order=msn_mode)
	
	# Execution
	for b in blocks:
		b.execute()
	
	debug = []
	for i, b in enumerate(blocks):
		# if b.cost.as_string() != "":
		# 	b.results = b.results.replace("{COST}", " - [neg]Cost: %s[/neg]" % b.cost.as_string())
		# else:
		# 	b.results = b.results.replace("{COST}", "")
		# 
		# # Trade queries are done differently
		# if b.order_type != "trades":
		# 	total_queries.append(b.queries)
		# 	total_results.append(b.results.strip())
		# 	total_results.append("")# To create a gap
		
		if len(b.debug) > 1:
			debug.append(b.debug[0])
			debug.append("\n---\n".join(b.debug[1:len(b.debug)]))
		
		output.append("""
		<div class="orders" style="border-color:{border};background-color:{background};">
			<strong>{title}</strong>: {cost}<br />
			{response}
			<br />
			
			<div style="float: left; width: 50%;">
				<textarea rows="6" style="float:left;width:99%;">{results}</textarea>
			</div>
			
			<div style="float: left; width: 50%;">
				<textarea rows="6" style="float:right;width:99%;">{queries}</textarea>
				<br />
				<a href="web.py?mode=direct_query">Direct query</a>
			</div>
			<div style="clear: left;">
				&nbsp;
			</div>
		</div>
		""".format(
			title		= b.title_name,
			cost		= str(b.cost),
			response	= common.bbcode_to_html("<br />".join(b.input_response)),
			results		= "\n".join(b.results),
			queries		= "\n".join(b.queries),
			
			border		= b.border_colour,
			background	= b.background_colour,
		))
	
	if debug != []:
		output.insert(2, '<br /><strong>Debug:</strong><br /><textarea name="debug" id="debug" rows="6" cols="80">%s</textarea><br />' % "".join(debug))
	
	output.append("Finishing with resources: %s" % str(the_team.resources))
	output.append("</div>")
	
	return "".join(output)
Пример #6
0
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&amp;turn={turn}" class="block_link" style="display:inline; text-align:left;">Campaigns of this turn</a>
	<a href="web.py?mode=list_battles&amp;campaign={id}" class="block_link" style="display:inline;">List battles</a>
	<a href="web.py?mode=perform_battle&amp;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">&nbsp;</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}
						-&gt;
						{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 -&gt; %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>&nbsp;</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;'>&nbsp;</td>"
						elif elsewhere_count == 2:
							elsewhere = "<td style='background-color:#B00;'>&nbsp;</td>"
						elif elsewhere_count > 2:
							elsewhere = "<td style='background-color:#F00;'>&nbsp;</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}&nbsp;&nbsp;</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>
									&nbsp;
								</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&amp;campaign=%d" class="block_link">List battles</a>' % campaign_id)
	output.append("</div>")
	
	return "".join(output)
Пример #7
0
def main(cursor):
	# Get team Id
	unit_id = int(common.get_val('unit', 0))
	
	if unit_id < 1:
		return "No unit selected"
	
	the_unit	= unit_q.get_one_unit(cursor, unit_id)
	army_dict	= army_q.get_all_armies(cursor)#get_armies_from_team(cursor, the_unit.team, include_garrisons=True)
	squad_dict	= squad_q.get_squads_from_team_of_type(cursor, the_unit.team, unit_id)
	equipment_dict = equipment_q.get_all_equipment(cursor)
	
	page_data['Title'] = "Edit unit: %s" % the_unit.name
	
	output = ["<div style='padding: 5px;'>"]
	
	# Unit cost breakdown
	unit_cost_breakdown = unit_rules.print_unit_cost(the_unit, cursor=cursor, breakdown_mode=True)
	
	w = world.World(cursor)
	real_cost = "Post override: %s/%s" % (
		unit_rules.unit_cost_override(w, the_unit, the_unit.costs['material_cost'], w.teams()[the_unit.team]),
		unit_rules.unit_cost_override(w, the_unit, the_unit.costs['iron_cost'], w.teams()[the_unit.team]),
	)
	real_upkeep = "Post override: %s/%s" % (
		unit_rules.unit_upkeep_override(w, the_unit, the_unit.costs['material_cost'], w.teams()[the_unit.team]),
		unit_rules.unit_upkeep_override(w, the_unit, the_unit.costs['iron_cost'], w.teams()[the_unit.team]),
	)
	# real_cost = 0
	# real_upkeep = 0
	
	output.append("""
	<div style="float: right; width: 50%;">
		<strong>Unit cost breakdown</strong><br />
		{cost_breakdown}<br />
		{real_cost}
		<br /><br />
	
		<strong>Unit upkeep breakdown</strong><br />
		{upkeep_breakdown}<br />
		{real_upkeep}
		<br /><br />
		
		<strong>Unit categories</strong><br />
		Type category: {type_cat}<br />
		Weapon category: {weapon_cat}<br />
		
		
		<br />
		<form id="delete_form" action="exec.py" method="post" accept-charset="utf-8">
			<input type="hidden" name="unit" id="unit" value="{unit_id}" />
			<input type="hidden" name="mode" id="mode" value="remove_unit" />
			<input style="float:right; margin-right:100px;" type="button" value="Delete unit" onclick="var answer = confirm('Delete {name}?')
			if (answer) $('#delete_form').submit();" />
		</form>
	</div>
	""".format(
		cost_breakdown		= "<br />".join(unit_cost_breakdown['cost']),
		upkeep_breakdown	= "<br />".join(unit_cost_breakdown['upkeep']),
		real_cost			= real_cost,
		real_upkeep			= real_upkeep,
		
		unit_id				= unit_id,
		name				= the_unit.name,
		
		type_cat			= unit.categories[the_unit.type_cat],
		weapon_cat			= unit.weapon_categories[the_unit.weapon_cat],
	))
	
	# Main unit stuff
	output.append("""
	<form action="exec.py" id="the_unit_form" method="post" accept-charset="utf-8">
		<input type="hidden" name="mode" value="edit_unit_commit" />
		<input type="hidden" name="id" value="%(unit_id)s" />
	
		<table border="0" cellspacing="5" cellpadding="5">
			<tr>
				<td><label for="name">Unit:</label></td>
				<td>%(name_text)s</td>
			
				<td>&nbsp;</td>
			
				<td><label for="team">Team:</label></td>
				<td>
					<select name="team" id="team">
						<option value="0">No team</option>
						%(team_option_box)s
					</select>
				</td>
			</tr>
			<tr>
				<td colspan="5" style="padding: 0px;"><a class="block_link" href="#" onclick="$('#the_unit_form').submit();">Apply changes</a></td>
			</tr>
		</table>
	</form>
	<br />

	""" % {
		"unit_id":			unit_id,
		"name_text":	common.text_box("name", the_unit.name),
		"team_option_box":	team_f.structured_list(cursor, default=the_unit.team),
	})
	
	# Unit equipment
	output.append("""
	<span class="stitle" id="equipment">Equipment</span>
	<table border="0" cellspacing="0" cellpadding="5">
		<tr class="row2">
			<th>Item</th>
			<th>&nbsp;</th>
		</tr>""")

	the_unit.get_equipment(cursor)

	counter = -1
	for e in the_unit.equipment:
		counter += 1
		output.append("""
		<tr class="row%(row)s">
			<td>%(item_name)s</td>
			<td style="padding: 0px;">
				<form action="exec.py" id="form_%(item_id)s" method="post" accept-charset="utf-8">
					<input type="hidden" name="mode" value="remove_equipment" />
					<input type="hidden" name="unit" value="%(unit_id)s" />
					<input type="hidden" name="item" value="%(item_id)s" />
					<a href="#" class="block_link" onclick="$('#form_%(item_id)s').submit();">Remove</a>
				</form>
			</td>
		</tr>""" % {
			"row":			counter%2,
			"item_name":	equipment_dict[e].name,
			"unit_id":		unit_id,
			"item_id":		e,
		})

	counter += 1
	output.append("""
	<tr class="row%(row)s">
		<form action="exec.py" id="new_equipment_form" method="post" accept-charset="utf-8">
			<input type="hidden" name="mode" value="add_equipment" />
			<input type="hidden" name="unit" value="%(unit_id)s" />
			<td>
				<select name="item">
					%(equipment_list)s
				</select>
			</td>
			<td>
				<input type="submit" value="Apply" />
			</td>
		</form>
	</tr>
	""" % {
		"row":				counter%2,
		"unit_id":			unit_id,
		"equipment_list":	equipment_f.equipment_option_list(cursor, remove_list=the_unit.equipment),
	})

	output.append("</table>")
	
	# What squads does the unit appear in?
	output.append("""
	<br /><br />
	<span class="stitle" id="squads">Squads</span>
	<table border="0" cellspacing="0" cellpadding="5">
		<tr class="row2">
			<th>Army</th>
			<th>Squad</th>
			<th>Size</th>
			<th>&nbsp;</th>
			<th>&nbsp;</th>
		</tr>""")

	the_unit.get_equipment(cursor)
	
	counter = -1
	for s, the_squad in squad_dict.items():
		counter += 1
		output.append("""
		<tr class="row%(row)s">
			<td>%(army_name)s</td>
			<td>%(name)s</td>
			<td>%(squad_size)s</td>
			<td style="padding: 0px;">
				<a href="web.py?mode=edit_army&amp;army=%(army_id)s" class="block_link">Edit army</a>
			</td>
			<td style="padding: 0px;">
				<a href="web.py?mode=edit_squad&amp;squad=%(squad_id)s" class="block_link">Edit squad</a>
			</td>
		</tr>""" % {
			"row":			counter%2,
			"army_name":	army_dict[the_squad.army].name,
			"army_id":		the_squad.army,
			"squad_id":		s,
			"name":			the_squad.name,
			"squad_size":	the_squad.amount,
		})
	
	output.append("</table>")
	output.append("</div>")
	
	return "".join(output)
Пример #8
0
def main(cursor):
	player_id	= int(common.get_val('player', 0))
	
	if player_id < 1:
		return "No player selected"
	
	the_player = player_q.get_one_player(cursor, player_id)
	
	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_player_commit" />
		<input type="hidden" name="id" id="id" value="%(player_id)s" />
		
		<table border="0" cellspacing="5" cellpadding="5">
			<tr>
				<td><label for="name">Name:</label></td>
				<td>%(name_text)s</td>
				
				<td colspan="3">&nbsp;</td>
			</tr>
			<tr>
				<td><label for="team">Team:</label></td>
				<td>%(team)s</td>
				
				<td>&nbsp;</td>
				
				<td><label for="ir">IR:</label></td>
				<td>%(ir)s</td>
			</tr>
			<tr>
				<td>&nbsp;</td>
				<td>&nbsp;</td>
				
				<td colspan="3">&nbsp;</td>
			</tr>	
			<tr>
				<td><label for="last_posted">Last posted:</label></td>
				<td>%(last_posted_text)s</td>
				
				<td colspan="3">&nbsp;</td>
			</tr>
			<tr>
				<td><label for="daemon_type">Daemon type:</label></td>
				<td>%(daemon_type)s</td>
				
				<td colspan="3">&nbsp;</td>
			</tr>
			<tr>
				<td><label for="progression">Progression:</label></td>
				<td>%(progression)s</td>
				
				<td colspan="3">&nbsp;</td>
			</tr>
			<tr>
				<td><label for="not_a_player">Not a player:</label></td>
				<td>%(not_a_player)s</td>
				
				<td>&nbsp;</td>
				
				<td><label for="not_surplus">Not surplus:</label></td>
				<td>%(not_surplus)s</td>
			</tr>
		</table>
		<br />
		<input type="submit" value="Perform edit" />
	</form>
	<br /><br />""" % {
		"player_id":		player_id,
		"name":				the_player.name,
		"team":				team_f.structured_list(cursor, default=the_player.team, field_name="team"),
		"name_text":	common.text_box("name", the_player.name, size=20),
		"last_posted_text":	common.text_box("last_posted", the_player.last_posted),
		"not_a_player":		common.check_box("not_a_player", the_player.not_a_player),
	
		"daemon_type":		common.option_box("daemon_type", elements=player.daemon_types, selected=player.daemon_types[the_player.daemon_type]),
		"progression":		common.option_box("progression", elements=player.progressions, selected=player.progressions[the_player.progression]),
		
		"not_surplus":		common.check_box("not_surplus", the_player.not_surplus),
		"ir":				common.check_box("ir", the_player.ir),
		
		# option_box(name, elements = {}, element_order = [], tab_index = -1, onchange="", custom_id = "<>", selected=""):
	})
	
	# This get's ajax'd
	output.append("""
	<div style="clear: left;">
		<br /><br />
		<span class="stitle">Player powers</span>
		<div id="player_powers">
			
		</div>
		<br /><br />
		<span class="stitle">Player kills/deaths</span><br />
		<div id="player_kills" style="float:left; width:49%; border: 0px solid #000;">
			&nbsp;
		</div>
		<div id="player_deaths" style="float:right; width:49%; border: 0px solid #000;">
			&nbsp;
		</div>
		<br /><br />
	</div>""")
	
	# End of padding
	output.append("</div>")
	
	# Load in the player powers
	output.append(common.onload("""
		$('#player_powers').load('web.py', {'mode':'list_powers','player':'%d', 'ajax':'True'});
		$('#player_kills').load('web.py', {'mode':'player_kills','killer':'%d', 'player':'%d', 'ajax':'True'});
		$('#player_deaths').load('web.py', {'mode':'player_kills','victim':'%d', 'player':'%d', 'ajax':'True'});
	""" % (player_id, player_id, player_id, player_id, player_id)))
	
	return "".join(output)
Пример #9
0
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)
Пример #10
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)