示例#1
0
文件: edit_team.py 项目: Teifion/Rob3
def main(cursor):
	# Get team Id
	team_id = int(common.get_val('team', 0))
	if team_id < 1: return "No team selected"
	
	# Build team item
	the_team = team_q.get_one_team(cursor, team_id)
	
	# Get some properties
	the_team.get_population(cursor)
	
	# Lists
	trait_dict = trait_q.get_all_traits(cursor)
	deity_dict = deity_q.get_all_deities(cursor)
	evolution_dict = evolution_q.get_all_evolutions(cursor)
	
	# Is the join turn set?
	if the_team.join_turn == 0:
		the_team.join_turn = common.current_turn()
	
	# First row of check_boxes
	output = ["<div style='padding: 5px;'>"]

	output.append("""
	<span class="stitle">%(name)s</span>
	&nbsp;&nbsp;&nbsp;
	Population: %(team_population)s

	<br /><br />
	<form action="exec.py" method="post" accept-charset="utf-8">
		<input type="hidden" name="mode" id="mode" value="edit_team_commit" />
		<input type="hidden" name="id" id="id" value="%(team_id)d" />
	
		<input type="hidden" name="requestTime" id="requestTime" value="' . $the_team->requestTime . '" />
	
		<label for="active">Active:</label>&nbsp;&nbsp;
		%(active_check_box)s
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

		<label for="ir">IR:</label>&nbsp;&nbsp;
		%(ir_check_box)s
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

		<label for="hidden">Hidden:</label>&nbsp;&nbsp;
		%(hidden_check_box)s
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
	
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
	
		<label for="not_a_team">Not a team:</label>&nbsp;&nbsp;
		%(not_a_team_check_box)s
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

		<label for="dead">Dead:</label>&nbsp;&nbsp;
		%(dead_check_box)s
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

		<label for="not_in_queue">Not in queue:</label>&nbsp;&nbsp;
		%(not_in_queue_check_box)s
		<br />
		""" % {	'team_id':					team_id,
				'name':				the_team.name,
				'team_population':			common.number_format(the_team.population),
				'active_check_box':			common.check_box('active', the_team.active),
				'ir_check_box':				common.check_box('ir', the_team.ir),
				'hidden_check_box':			common.check_box('hidden', the_team.hidden),
				'not_a_team_check_box':		common.check_box('not_a_team', the_team.not_a_team),
				'dead_check_box':			common.check_box('dead', the_team.dead),
				'not_in_queue_check_box':	common.check_box('not_in_queue', the_team.not_in_queue),
				})

	# Row 1
	output.append("""
		<table border="0" cellspacing="5" cellpadding="5" style="width:100%%;">
			<tr>
				<td><label for="forum_url_id">Forum URL id:</label></td>
				<td>%(forum_text_box)s</td>
		
				<td width="5">&nbsp;</td>
		
				<td><label for="orders_topic">Orders topic:</label></td>
				<td>%(orders_text_box)s</td>
		
				<td width="5">&nbsp;</td>
		
				<td><label for="intorders_topic">Int Orders topic:</label></td>
				<td>%(intorders_text_box)s</td>
			</tr>""" % {'forum_text_box':		common.text_box('forum_url_id', the_team.forum_url_id, warn_on = lambda x:(True if x < 0 else False)),
						'orders_text_box':		common.text_box('orders_topic', the_team.orders_topic, warn_on = lambda x:(True if x < 0 else False)),
						'intorders_text_box':	common.text_box('intorders_topic', the_team.intorders_topic, warn_on = lambda x:(True if x < 0 else False)),
						})


	# Row 2
	output.append("""
			<tr>
				<td><label for="results_topic">Results topic:</label></td>
				<td>{results_topic}</td>
			
				<td width="5">&nbsp;</td>
			
				<td><label for="teaminfo_topic">Team info topic:</label></td>
				<td>{teaminfo_topic}</td>
			
				<td width="5">&nbsp;</td>
			
				<td><label for="team_info_first_post">Team info first post:</label></td>
				<td>{team_info_first_post}</td>
			</tr>""".format(
			results_topic			= common.text_box('results_topic', the_team.results_topic, warn_on = lambda x:(True if x < 0 else False)),
			teaminfo_topic			= common.text_box('teaminfo_topic', the_team.teaminfo_topic, warn_on = lambda x:(True if x < 0 else False)),
			team_info_first_post	= common.text_box('team_info_first_post', the_team.team_info_first_post, warn_on = lambda x:(True if x < 0 else False)),
			))

	# Row 3
	output.append("""
			<tr>
				<td><label for="request_topic">Request topic:</label></td>
				<td>%(request_topic)s</td>
			
				<td width="5">&nbsp;</td>
			
				<td><label for="leader_id">Leader:</label></td>
				<td>%(leader_id)s</td>
			
				<td width="5">&nbsp;</td>
		
				<td>Culture topic:</td>
				<td>%(culture_topic)s</td>
			</tr>""" % {'leader_id':		common.text_box('leader_id', the_team.leader_id, warn_on = lambda x:(True if x < 1 else False)),
						'request_topic':	common.text_box('request_topic', the_team.request_topic, warn_on = lambda x:(True if x < 1 else False)),
						'culture_topic':	common.text_box('culture_topic', the_team.culture_topic, warn_on = lambda x:(True if x < 1 else False)),
					})
	
	output.append("""
	<tr>
		<td><label for="default_borders">Default borders:</label></td>
		<td>%(default_borders)s</td>
		
		<td width="5">&nbsp;</td>
		
		<td><label for="default_taxes">Default taxes:</label></td>
		<td>%(default_taxes)s</td>
		
		<td width="5">&nbsp;</td>
		
		<td><label for="evo_points">Evo points:</label></td>
		<td>%(evo_points)s</td>
	</tr>
	<tr>
		<td colspan="8" style="padding:0px;border-bottom:3px #EEE double;"></td>
	</tr>
	""" % {
		"default_borders":		common.option_box("default_borders", elements=team.border_states, selected=team.border_states[the_team.default_borders]),
		"default_taxes":		common.text_box('default_taxes', the_team.default_taxes, warn_on = lambda x:(True if int(x) < 0 else False), size=4),
		"evo_points":			common.text_box('evo_points', the_team.evo_points, warn_on = lambda x:(True if int(x) < 0 else False)),
	})
	
	output.append("""
			<!--
			<tr>
				<td>Previous resources:</td>
				<td>%(previous_resources)s</td>
			</tr>
			-->
	""" % {
		"previous_resources":	the_team.previous_resources,
		})
	
	# End row
	output.append("""
			<tr>
				<td>Join turn:</td>
				<td>%(join_turn)s</td>

				<td width="5">&nbsp;</td>

				<td>Primary:</td>
				<td>%(primary_colour)s</td>
			
				<td width="5">&nbsp;</td>

				<td>Secondary:</td>
				<td>%(secondary_colour)s</td>
			</tr>
		</table>
		<br />
	
		<input type="submit" value="Perform edit" />
		<input style="float:right; margin-right:100px;" type="button" value="Purge team" onclick="setTimeout('document.location=\\'web.py?mode=purge_team&team=%(team_id)s\\'', 0);"/>
	<a class="block_link" href="web.py?mode=ti&amp;post_output=1&amp;team=%(team_id)s">Update my TI</a>

	<br />""" % {
		"team_id":				team_id,
		'join_turn':			common.text_box('join_turn', the_team.join_turn),
		'previous_resources':	common.text_box('previous_resources', the_team.previous_resources, size=56),
	
		"primary_colour":		common.text_box('primary_colour', the_team.primary_colour),
		"secondary_colour":		common.text_box('secondary_colour', the_team.secondary_colour),
		})
		
	#	Resources
	#------------------------
	the_team.get_resources(cursor)
	
	output.append("""
	<table style="float:left; margin-right: 25px;" border="0" cellspacing="0" cellpadding="5">
	<tr class="row2">
		<th>Resource</th>
		<th>Amount</th>
	</tr>
	""")
	
	counter = -1
	for res_id, the_res in resource_list.data_dict.items():
		if the_res.category == resource_list.category['Map terrain feature']:
			continue
		
		# If it's not set then we need to give it a default
		if not res_id in the_team.resources.value:
			the_team.resources.value[res_id] = 0
		
		counter += 1
		
		output.append("""
		<tr class="row%(row)d">
			<td><label for="res_%(res_name)s">%(res_name)s</label></td>
			<td style="padding:1px;">%(res_amount)s</td>
		</tr>""" % {'row':			(counter % 2),
					'res_name':		the_res.name,
					'res_amount':	resource_f.print_form_element(res_id, the_team.resources[res_id])
					})
	
	output.append("</table></form>")# Subsequent forms are for other stuff
	
	#	Deities
	#----------------------
	the_team.get_deities(cursor)
	
	output.append("""
	<table style="float:left; margin-right: 25px;" border="0" cellspacing="0" cellpadding="5">
	<tr class="row2">
		<th>Deity</th>
		<th>&nbsp;</th>
	</tr>
	""")
	
	counter = -1
	for deity_id, team_favour in the_team.deities.items():
		counter += 1
		
		output.append("""
		<tr class="row%(row)d">
			<td><label for="%(name)s">%(name)s</label></td>
			<td style="padding: 0px;">
				<a class="block_link" href="exec.py?mode=remove_deity&amp;deity=%(deity_id)d&amp;team=%(team_id)d">Remove</a>
			</td>
		</tr>""" % {'row':			(counter % 2),
					'name':	deity_dict[deity_id].name,
					'deity_id':		deity_id,
					'team_id':		team_id
					})
	
	output.append("""
		<tr class="row%(row)d">
		<form id="team_add_deity_form" action="exec.py?mode=add_deity" method="post" accept-charset="utf-8">
			<input type="hidden" name="mode" value="add_deity" />
			<input type="hidden" name="team" value="%(team_id)s" />
			<td style="padding:1px;">
				<select name="deity">
					%(deity_option_box)s
				</select>
			</td>
			<td style="padding: 2px;">
				<input type="submit" value="Add" />
				<!--<a href="#" onclick="$('#team_add_deity_form').submit(); return false;" class="block_link">Add</a>-->
			</td>
		</tr>
		</form>
	</table>
	""" % {	'row':				((counter+1) % 2),
			'team_id':			the_team.id,
			'deity_option_box': deity_f.deity_option_list(cursor, the_team.deities)})
	
	
	#	Evolutions
	#-------------------
	the_team.get_evolutions(cursor)
	
	output.append("""
	<table style="float:left; margin-right: 25px;" border="0" cellspacing="0" cellpadding="5">
	<tr class="row2">
		<th>Evolution</th>
		<th>&nbsp;</th>
		<th>&nbsp;</th>
	</tr>
	""")
	
	counter = -1
	for evo_id, evo_level in the_team.evolutions.items():
		counter += 1
		
		output.append("""
		<tr class="row%(row)d">
			<form id="edit_evo_%(evolution_id)s" action="exec.py" method="post" accept-charset="utf-8">
			<input type="hidden" name="mode" value="set_evolution" />
			<input type="hidden" name="team" value="%(team_id)s" />
			<input type="hidden" name="evolution" value="%(evolution_id)s" />
			<td><label for="%(name)s">%(name)s</label></td>
			<td style="padding:1px;">
				%(text_box)s
			</td>
			</form>
			<td style="padding: 0px;">
				<a class="block_link" href="exec.py?mode=set_evolution&amp;evolution=%(evolution_id)d&amp;team=%(team_id)d">Remove</a>
			</td>
		</tr>""" % {'row':				(counter % 2),
					'name':				evolution_dict[evo_id].name,
					'evolution_level':	evo_level,
					'evolution_id':		evo_id,
					'team_id':			team_id,
					
					"text_box": common.text_box("evolution_level", evo_level, custom_id="", size=3,
						warn_on = lambda e: (True if evolution_dict[evo_id].min_level > e or e > evolution_dict[evo_id].max_level else False)),
					})
	
	output.append("""
		<tr class="row%(row)d">
		<form id="team_add_evolution_form" action="exec.py" method="post" accept-charset="utf-8">
			<input type="hidden" name="mode" value="set_evolution" />
			<input type="hidden" name="team" value="%(team_id)d" />
			<td style="padding:1px;">
				<select name="evolution">
					%(evolution_option_box)s
				</select>
			</td>
			<td style="padding:1px;">
				%(evolution_level)s
			</td>
			<td style="padding: 0px;">
				<a href="#" onclick="$('#team_add_evolution_form').submit();" class="block_link">Add</a>
			</td>
		</tr>
		</form>
	</table>
	""" % {	'row':				((counter+1) % 2),
			'team_id':			the_team.id,
			'evolution_level':	common.text_box('evolution_level', 0, 4),
			'evolution_option_box': evolution_f.evolution_option_list(cursor, the_team.evolutions)})
	
	
	#	Traits
	#----------------------
	the_team.get_traits(cursor)
	
	output.append("""
	<table style="float:left; margin-right: 25px;" border="0" cellspacing="0" cellpadding="5">
	<tr class="row2">
		<th>Trait</th>
		<th>&nbsp;</th>
	</tr>
	""")
	
	counter = -1
	for trait_id in the_team.traits:
		counter += 1
		
		output.append("""
		<tr class="row%(row)d">
			<td><label for="%(name)s">%(name)s</label></td>
			<td style="padding: 0px;">
				<a class="block_link" href="exec.py?mode=remove_trait&amp;trait=%(trait_id)d&amp;team=%(team_id)d">Remove</a>
			</td>
		</tr>""" % {'row':			(counter % 2),
					'name':			trait_dict[trait_id].name,
					'trait_id':		trait_id,
					'team_id':		team_id
					})
	
	output.append("""
		<tr class="row%(row)d">
		<form id="team_add_trait_form" action="exec.py?mode=add_trait" method="post" accept-charset="utf-8">
			<input type="hidden" name="mode" value="add_trait" />
			<input type="hidden" name="team" value="%(team_id)s" />
			<td style="padding:1px;">
				<select name="trait">
					%(trait_option_box)s
				</select>
			</td>
			<td style="padding: 2px;">
				<input type="submit" value="Add" />
				<!--<a href="#" onclick="$('#team_add_trait_form').submit(); return false;" class="block_link">Add</a>-->
			</td>
		</tr>
		</form>
	</table>
	""" % {	'row':				((counter+1) % 2),
			'team_id':			the_team.id,
			'trait_option_box': trait_f.trait_option_list(cursor, the_team.traits)})
	
	
	# Hashes
	output.append("""
	<table style="float:left; margin-right: 25px;" border="0" cellspacing="0" cellpadding="5">
	<tr class="row2">
		<th>Turn</th>
		<th>Hash</th>
	</tr>
	""")

	for i, t in enumerate(range(common.current_turn(), common.current_turn()-5, -1)):
		output.append("""
		<tr class="row{i}">
			<td>{t}</td>
			<td>{hash}</td>
		</tr>""".format(
			i = i % 2,
			t = t,
			hash = team_f.team_hash(the_team.name, turn=t),
	))
	
	output.append("</table>")
	
	
	

	
	output.append("</div>")
	page_data['Title'] = "Edit team (%s)" % the_team.name
	return "".join(output)
示例#2
0
def main(cursor):
	player_id	= int(common.get_val('player', 0))
	killer		= int(common.get_val('killer', 0))
	victim		= int(common.get_val('victim', 0))
	battle_id	= int(common.get_val('battle', 0))
	ajax		= bool(common.get_val('ajax', False))
	
	battle_dict = battle_q.get_all_battles(cursor)
	player_dict = player_q.get_all_players(cursor)
	active_dict = player_q.get_active_players(cursor)
	
	battle_dict[0] = battle.Battle({"name":"None"})
	
	if killer > 0:
		kill_list = player_q.get_kills(cursor, killer=killer)
	elif victim > 0:
		kill_list = player_q.get_kills(cursor, victim=victim)
	elif battle_id > 0:
		kill_list = player_q.get_kills(cursor, battle=battle_id)
	else:
		kill_list = player_q.get_kills(cursor)
	
	output = []
	
	output.append("""
	<table border="0" cellspacing="0" cellpadding="5" style="width: 100%;">
		<tr class="row2">
			<th>Killer</th>
			<th>Victim</th>
			<th>Battle</th>
			<th>Turn</th>
			<th>&nbsp;</th>
		</tr>""")
	
	count = -1
	for kill in kill_list:
		count += 1
		
		output.append("""
		<tr class="row%(row)d">
			<td><a href="web.py?mode=edit_player&amp;player=%(k_id)s">%(killer)s</a></td>
			<td><a href="web.py?mode=edit_player&amp;player=%(v_id)s">%(victim)s</a></td>
			<td>%(battle)s <em>(%(c_id)s)</em></td>
			<td>%(turn)s</td>
			
			<td style="padding: 0px;"><a class="block_link" href="exec.py?mode=remove_kill&amp;victim=%(v_id)s&amp;killer=%(k_id)s&amp;turn=%(turn)s&amp;battle=%(c_id)s%(p_id)s">Remove</a></td>
		</tr>
		""" % {	'row': (count % 2),
				
				'v_id':			kill['victim'],
				'k_id':			kill['killer'],
				'c_id':			kill['battle'],
				'p_id':			("&amp;player=%d" % player_id if player_id > 0 else ""),
				
				'killer':		player_dict[kill['killer']].name,
				'victim':		player_dict[kill['victim']].name,
				"battle":		battle_dict[kill['battle']].name,
				
				'turn':			kill['turn'],
			})
	
	# Add new power
	names = {}
	for p, the_p in active_dict.items():
		names[p] = the_p.name
	
	if not ajax:
		onload = common.onload("$('#killer').focus();")
	else:
		onload = ""
	
	count += 1
	output.append("""
	<tr class="row%(row)d">
		<form action="exec.py" id="add_kill_form" method="post" accept-charset="utf-8">
		<td style="padding: 1px;">%(killer)s</td>
		<td style="padding: 1px;">%(victim)s</td>
		<td style="padding: 0px;">%(battle)s</td>
		<td style="padding: 0px;">%(turn)s</td>
		
		<td style="padding: 1px;">
			<input type="hidden" name="mode" value="add_kill" />
			%(player_id)s
			<input type="submit" value="Add" />
		</td>
		</form>
		%(onload)s
	</tr>
	""" % {	'row': (count % 2),
			'killer':	common.option_box(
				name='killer',
				elements=names,
				element_order=active_dict.keys(),
				selected = killer if killer > 0 else "",
			),
			'victim':	common.option_box(
				name='victim',
				elements=names,
				element_order=active_dict.keys(),
				selected = victim if victim > 0 else "",
			),
			"turn":		'<input type="text" name="turn" id="turn" value="%d" />' % common.current_turn(),
			"battle":	'<input type="text" name="battle" id="battle" value="%d" />' % battle_id,
			"onload":	onload,
			"player_id": ('<input type="hidden" name="player" value="%d" />' % player_id if player_id > 0 else ""),
			})
	
	output.append("</table>")
	return "".join(output)
示例#3
0
	<input type="hidden" name="battle" id="battle" value="%(battle_id)s" />
	<input type="hidden" name="mode" id="mode" value="remove_battle" />
	<input style="float:right; margin-right:100px;" type="button" value="Delete battle" onclick="var answer = confirm('Delete %(esc_name)s?')
	if (answer) $('#delete_form').submit();" />
</form>
<br /><br />""" % {
	"battle_id":					battle_id,
	"name":					the_battle.name,
	"esc_name":				common.js_name(the_battle.name,),
	"battle_turn":					the_battle.turn,
	"name_text":				common.text_box("name", the_battle.name, size=20),
	"battle_turn_text":				common.text_box("turn", the_battle.turn, size=5),
	"battle_city_select":			common.option_box(
		name='city',
		elements=names,
		element_order=city_list,
		custom_id="",
		selected=the_battle.city,
	),
	"battle_location_text":			common.text_box("location", new_location, 10),
})

#	Now for the participants of the battle
#------------------------
teams_dict		= team.get_teams_dict()
army_dict		= army.get_army_dict()
participants	= the_battle.get_participants()

output.append("""
<hr />
<form action="exec.py" method="post" id="add_team_form" accept-charset="utf-8">
示例#4
0
def main(cursor):
	equipment_dict	= equipment_q.get_all_equipment(cursor)
	
	output = []
	
	count = -1
	
	weapons, weapons_dict	= ["0:0:"], {"0:0:":""}
	armour, armour_dict		= ["0:0:"], {"0:0:":""}
	shields, shields_dict	= ["0:0:"], {"0:0:":""}
	mounts, mounts_dict		= ["0:0:"], {"0:0:":""}
	beasts, beasts_dict		= ["0:0:"], {"0:0:":""}
	boats, boats_dict		= [], {}
	training, training_dict	= [], {}

	for e, the_equipment in equipment_dict.items():
		if the_equipment.public == False: continue
	
		cat = equipment.cat_list[the_equipment.category]
		line = equipment_line(the_equipment)
	
		if cat in ('Sword','Axe','Hammer','Flail','Polearm','Dagger','Bow','Crossbow','Thrown','Gunpowder',):
			weapons_dict[line] = the_equipment.name
			weapons.append(line)
	
		elif cat == 'Armour':
			armour_dict[line] = the_equipment.name
			armour.append(line)
	
		elif cat == 'Shield':
			shields_dict[line] = the_equipment.name
			shields.append(line)
	
		elif cat == 'Mount':
			mounts_dict[line] = the_equipment.name
			mounts.append(line)
	
		elif cat == 'Beast':
			beasts_dict[line] = the_equipment.name
			beasts.append(line)
	
		elif cat == 'Boat hull':
			boats_dict[line] = the_equipment.name
			boats.append(line)
	
		elif cat == 'Training':
			line = """%(material)s:%(name)s""" % {
				"material": res_dict.Res_dict(the_equipment.cost_multiplier).get("Materials"),
				"name":		the_equipment.name,
			}
		
			training_dict[line] = the_equipment.name
			training.append(line)
	
		elif cat in ('Custom','Balloon','Siege engine','Seabourne mount'):
			pass
	
		else:
			raise Exception("No handler for type %s" % cat)

	# Army stuff
	output.append("""
	<table border="0" cellspacing="5" cellpadding="5">
		<tr>
			<td>Unit name:</td>
			<td><input type="text" id="name" value="" onkeyup="calc_army();"/></td>
		
			<td>&nbsp;</td>
		
			<td>Training:</td>
			<td>%(training)s</td>
		</tr>
		<tr>
			<td>Weapon 1:</td>
			<td>%(first_weapon)s</td>
		
			<td>&nbsp;</td>
		
			<td>Weapon 2:</td>
			<td>%(second_weapon)s</td>
		</tr>
	
		<tr>
			<td>Armour 1:</td>
			<td>%(first_armour)s</td>
		
			<td>&nbsp;</td>
		
			<td>Armour 2:</td>
			<td>%(second_armour)s</td>
		</tr>
	
		<tr>
			<td>Shield:</td>
			<td>%(shield)s</td>
		
			<td>&nbsp;</td>
		
			<td>Beast:</td>
			<td>%(beast)s</td>
		</tr>
	
		<tr>
			<td>Mount:</td>
			<td colspan="4">%(mount)s</td>
		</tr>
	</table>
	<div class="armyblock" id="army_bbcode">
		Awaiting your input
	</div>
	""" % {
		"training": common.option_box("",
			elements=training_dict,
			element_order=training,
			onchange="calc_army();",
			custom_id="army_training",
			selected="1:1:Standard training"),
	
		"first_weapon": common.option_box("",
			elements=weapons_dict,
			element_order=weapons,
			onchange="calc_army();",
			custom_id="first_weapon"),
		"second_weapon": common.option_box("",
			elements=weapons_dict,
			element_order=weapons,
			onchange="calc_army();",
			custom_id="second_weapon"),
	
		"first_armour": common.option_box("",
			elements=armour_dict,
			element_order=armour,
			onchange="calc_army();",
			custom_id="first_armour"),
		"second_armour": common.option_box("",
			elements=armour_dict,
			element_order=armour,
			onchange="calc_army();",
			custom_id="second_armour"),
	
		"shield": common.option_box("",
			elements=shields_dict,
			element_order=shields,
			onchange="calc_army();",
			custom_id="shield"),
		
		"mount": common.option_box("",
			elements=mounts_dict,
			element_order=mounts,
			onchange="calc_army();",
			custom_id="mount"),
		
		"beast": common.option_box("",
			elements=beasts_dict,
			element_order=beasts,
			onchange="calc_army();",
			custom_id="beast"),
	})

	# Navy stuff
	output.append("""
	<table border="0" cellspacing="5" cellpadding="5">
		<tr>
			<td>Ship name:</td>
			<td><input type="text" id="navy_name" value="" onkeyup="calc_navy();"/></td>
		
			<td>&nbsp;</td>
		
			<td>Training:</td>
			<td>
				<select id="navy_training" onchange="calc_navy();">
					<option value="1:Standard training">Standard training</option>
					<option value="1.5:Good training">Good training</option>
				</select>
			</td>
		</tr>
		<tr>
			<td>Hull 1:</td>
			<td>%(hull)s</td>
		</tr>
	</table>
	<div class="navyblock" id="navy_bbcode">
		Awaiting your input
	</div>
	""" % {	
		"hull": common.option_box("",
			elements=boats_dict,
			element_order=boats,
			onchange="calc_navy();",
			custom_id="hull"),
	})

	return "".join(output)
示例#5
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)
示例#6
0
def main(cursor):
	# Get squad Id
	army_id = int(common.get_val('army', 0))
	
	if army_id < 1:
		exit()
	
	the_army = army_q.get_one_army(cursor, army_id)
	squads_dict = squad_q.get_squads_from_army(cursor, army=army_id)
	
	monster_dict = monster_q.get_all_monsters(cursor)
	army_monsters_dict = monster_q.get_monsters_from_army(cursor, army_id)
	
	unit_dict = unit_q.get_units_from_team(cursor, the_army.team, special_units=True)
	
	output = []
	output.append("""
	<table border="0" cellspacing="0" cellpadding="5" style="width: 100%;">
		<tr class="row2">
			<th>Name</th>
			<th>Unit type</th>
			<th>Size</th>
			<th>Exp</th>
			<th>&nbsp;</th>
		</tr>""")
	
	count = -1
	if len(squads_dict) > 0:
		for squad_id, the_squad in squads_dict.items():
			if the_squad.unit not in unit_dict: continue
			
			count += 1
			
			output.append("""
			<tr class="row%(row)d" id="%(squad_id)d">
				<td>%(name)s</td>
				<td>%(unit_type)s</td>
				<td>%(size)s</td>
				<td>%(exp)s</td>
				<td style="padding: 0px;"><a href="web.py?mode=edit_squad&amp;squad=%(squad_id)d" class="block_link">Edit</a></td>
			</tr>
			""" % {	'row': (count % 2),
				
					"squad_id":		squad_id,
					"name":	common.doubleclick_text("squads", "name", squad_id, the_squad.name, "font-weight:bold", size=18),
					"unit_type":	unit_dict[the_squad.unit].name,
					"size":			common.doubleclick_text("squads", "amount", squad_id, the_squad.amount, size=7),
					"exp":			common.doubleclick_text("squads", "experience", squad_id, the_squad.experience, size=7),
					})
	else:
		output.append("""
		<tr class="row0">
			<td colspan="5">No squads in this army</td>
		</tr>""")
		count += 1
	
	
	if len(army_monsters_dict) > 0:
		for monster_id, amount in army_monsters_dict.items():
			if amount < 1: continue
			the_monster = monster_dict[monster_id]
			
			count += 1
			
			output.append("""
			<tr class="row{row}">
				<td>{name}</td>
				<td><em>Monster</em></td>
				<td>{amount}</td>
				<td>&nbsp;</td>
				<td style="padding: 0px;"><a href="web.py?mode=edit_army_monster&amp;army={army_id}&amp;monster={monster_id}" class="block_link">Edit</a></td>
			</tr>
			""".format(
					row			= (count % 2),
					army_id		= army_id,
					monster_id	= monster_id,
					name		= the_monster.name,
					amount		= common.doubleclick_text_full("army_monsters", "amount", "army = %d AND monster = %d" % (army_id, monster_id), amount, size=5),
			))
	
	# Add new squad to army thingie
	names = {}
	for u, the_unit in unit_dict.items():
		names[u] = the_unit.name
	
	count += 1
	output.append("""
	<tr class="row%(row)d">
		<form action="exec.py" id="add_squad_form_%(army_id)d" method="post" accept-charset="utf-8">	
		<td style="padding: 1px;">
			<input type="text" name="name" value=""/>
		
			<input type="hidden" name="team" value="%(team_id)s" />
			<input type="hidden" name="mode" value="add_squad" />
			<input type="hidden" name="army" value="%(army_id)s" />
		</td>
		<td style="padding: 1px;">%(unit_type)s</td>
		<td style="padding: 1px;"><input type="text" name="size" value="" size="5"/></td>
		<td style="padding: 1px;"><input type="text" name="experience" value="" size="5"/></td>
		<td style="padding: 0px;">
			<a class="block_link" href="#" onclick="$('#add_squad_form_%(army_id)d').submit();">Add</a>
		</td>
		</form>
	</tr>
	""" % {	'row': (count % 2),
		
			"army_id":			army_id,
			"team_id":			the_army.team,
			'unit_type':		common.option_box(
				name='unit_type',
				elements=names,
				element_order=unit_dict.keys(),
				custom_id="",
			),
			})
	
	output.append('</table>')
	return "".join(output)
示例#7
0
	<td style="padding: 1px;">%(type)s</td>
	<td style="padding: 1px;">%(target)s</td>
	
	<!--
	<td>&nbsp;</td>
	-->
	
	<td style="padding: 0px;" colspan="2"><a class="block_link" href="#" onclick="$('#add_mission_form').submit();">Add</a></td>
	</form>
	%(onload)s
</tr>
""" % {	'row':			(count % 2),
		
		"team":			team_f.structured_list(field_name="team", field_id="new_mission_team"),
		"turn":			common.text_box('turn', text=common.current_turn(), size=5),
		"state":		common.option_box("state", mission.mission_states),
		
		"type":			common.option_box("type",
			elements=city_missions_dict,
			element_order=city_missions_list,
		),
		"target":		common.option_box(
			name='target',
			elements=names,
			element_order=cities_order,
		),
		
		"time_posted":	int(time.time()),
		"onload":		common.onload("$('#new_mission_team').focus();"),
		})
示例#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
文件: path_map.py 项目: Teifion/Rob3
def main(cursor):
	points			= common.get_val('points', "")
	move_speed		= common.get_val('move_speed', "Marching")
	move_type		= common.get_val('move_type', "Medium foot")
	
	if points == "":
		page_data['Header'] = True
		page_data['Title'] = "Path map"
		
		# name, elements = {}, element_order = [], tab_index = -1, onchange="", custom_id = "<>", selected=""
		speed_dropdown = common.option_box('move_speed', map_data.move_speed_list, selected="Marching")
		type_dropdown = common.option_box('move_type', map_data.move_type_list, selected="Medium foot")
		
		return """
		<form action="web.py" method="get" accept-charset="utf-8" style="padding:5px;">
			<input type="hidden" name="mode" value="path_map" />
			<table border="0" cellspacing="0" cellpadding="5">
				<tr>
					<td><label for="points">Waypoints:</label></td>
					<td><input type="text" id="points" name="points" value="" size="40"/></td>
				</tr>
				<tr>
					<td><label for="move_speed">Speed:</label></td>
					<td>
						{move_speed}
					</td>
				</tr>
				<tr>
					<td><label for="move_type">Type:</label></td>
					<td>
						{move_type}
					</td>
				</tr>
				<tr>
					<td><input type="submit" value="View" /></td>
					<td>&nbsp;</td>
				</tr>
			</table>
		</form>
		{onload}
		""".format(
			move_speed=speed_dropdown,
			move_type=type_dropdown,
			onload=common.onload("$('#points').focus();")
		)
	
	try:
		move_speed		= map_data.move_speed_list[int(move_speed)]
	except Exception as e:
		pass
	
	try:
		move_type		= map_data.move_type_list[int(move_type)]
	except Exception as e:
		pass
	
	waypoints = []
	points_list = points.split(",")
	for p in range(0, len(points_list), 2):
		waypoints.append((int(points_list[p]), int(points_list[p+1])))

	path_data = path_f.path(cursor, waypoints, move_speed=move_speed, move_type=move_type)
	
	
	float_div = """<div style="background-color:#CCC;position:absolute;top:0px;left:0px;padding:5px;">
	<a href="web.py?mode=path_map">Reset</a><br />
	Distance: {distance}<br />
	Time taken: {time}<br />
	</div>""".format(
		distance = format(path_data.walk_distance, ','),
		time = path_data.time_cost,
	)
	
	
	dimensions = {
		"left":		999999,
		"top":		999999,
		"right":	-999999,
		"bottom":	-999999,
	}

	# Need to work out how big the map will actually be
	radius = 300
	for s in path_data.steps:
		dimensions['left'] = min(dimensions['left'], s['tile'][0] - radius)
		dimensions['right'] = max(dimensions['right'], s['tile'][0] + radius)
	
		dimensions['top'] = min(dimensions['top'], s['tile'][1] - radius)
		dimensions['bottom'] = max(dimensions['bottom'], s['tile'][1] + radius)

	# Make map object
	the_map = mapper.Map_maker()
	the_map.path_data = path_data

	the_map.left	= max(dimensions['left'], the_map.left)
	the_map.right	= min(dimensions['right'], the_map.right)

	the_map.top		= max(dimensions['top'], the_map.top)
	the_map.bottom	= min(dimensions['bottom'], the_map.bottom)


	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":				False,
		"onclick_js":			onclick_js,
	
		# "map_click_handler":	map_click_handler,
	
		"output":				the_map.map_grid(cursor),
	}

	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

	return "%s%s" % (float_div, mapper.map_source(source_dict))
示例#10
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)
示例#11
0
def main(cursor):
	player_id	= int(common.get_val('player', 0))
	ajax		= bool(common.get_val('ajax', False))
	
	if player_id < 1:
		power_dict = power_q.get_all_powers(cursor)
	else:
		power_dict = power_q.get_powers_from_player(cursor, player_id)
	
	player_dict	= player_q.get_all_players(cursor)
	
	player_dict[0] = player.Player()
	player_dict[0].name = "None"
	
	output = []
	
	output.append("""
	<table border="0" cellspacing="0" cellpadding="5" style="width: 100%;">
		<tr class="row2">
			<th>Power name</th>
			<th>Player</th>
			<th>Type</th>
			<th>Description</th>
			<th>&nbsp;</th>
		</tr>""")
	
	count = -1
	if len(power_dict) > 0:
		for power_id, the_power in power_dict.items():
			count += 1
			
			output.append("""
			<tr class="row%(row)d" id="%(power_id)d">
				<td>%(name)s</td>
				<td>%(player_name)s</td>
				<td>%(type)s</td>
				<td>%(description)s</td>
				
				<td style="padding: 0px;"><a class="block_link" href="web.py?mode=edit_power&amp;power=%(power_id)d">Edit</a></td>
			</tr>
			""" % {	'row': (count % 2),
				
					'power_id':		the_power.id,
					'name':			the_power.name,
					"type":			power.power_types[the_power.type],
					'player_name':	player_dict[the_power.player].name,
					'description':	the_power.description,
				})
	
	# Add new power
	names = {}
	for p, the_p in player_dict.items():
		names[p] = the_p.name
	
	# players_order.insert(0, 2)
	# names[2] = "Teifion"
	
	# ajax = bool(common.get_val('ajax', False))
	if not ajax:
		onload = common.onload("$('#new_name').focus();")
	else:
		onload = ""
	
	count += 1
	output.append("""
	<tr class="row%(row)d">
		<form action="exec.py" id="add_power_form" method="post" accept-charset="utf-8">
		<input type="hidden" name="mode" value="add_power" />
		<td style="padding: 1px;"><input type="text" name="name" id="new_name" value="" size="12"/></td>
		<td style="padding: 1px;">%(player_menu)s</td>
		<td style="padding: 1px;">%(type)s</td>
		<td style="padding: 1px;"><input type="text" name="power_description" value="" style="width: 98%%;" /></td>
	
		<td style="padding: 1px;"><input type="submit" value="Continue &rarr;" /></td>
		</form>
		%(onload)s
	</tr>
	""" % {	'row': (count % 2),
			'player_menu':	common.option_box(
				name='player',
				elements=names,
				element_order=player_dict.keys(),
				custom_id="",
			),
			"type":	common.option_box(
				"type",
				power.power_types,
			),
			"onload":	onload,
			})
	
	output.append("</table>")
	return "".join(output)
示例#12
0
					<input type="hidden" name="mode" value="compare_teams" />
					<input type="hidden" name="battle" value="%(battle_id)s" />
					<input type="hidden" name="t1" value="%(team_id)s" />
					%(team_list)s - 
					<a href="#" onclick="$('#compare_form_%(team_id)s').submit(); return false;">Compare</a>
				</form>
			</td>
		</tr>
		""" % {
                "count":
                count % 2,
                "team_id":
                team_id,
                "battle_id":
                battle_id,
                "team_list":
                common.option_box(
                    "t2", elements=teams_dict, element_order=participants)
            })

        output.append("</table><br /><br />")

    output.append("</div>")

    # Spacer between columns
    output.append("<div style='float:left;width:50px;'>&nbsp;</div>")

output.append("</div>")

print "".join(output)
示例#13
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)
示例#14
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)
示例#15
0
def main(cursor):
	squad_id = int(common.get_val('squad'))
	
	the_squad = squad_q.get_one_squad(cursor, squad_id)
	armies_dict = army_q.get_armies_from_team(cursor, the_squad.team, include_garrisons=True)
	the_unit = unit_q.get_one_unit(cursor, the_squad.unit)
	
	names = {}
	for a, the_army in armies_dict.items():
		names[a] = the_army.name
	
	output = []
	
	output.append("<div style='padding: 5px;'>")
	
	output.append("""
	<form action="exec.py" id="the_squad_form" method="post" accept-charset="utf-8">
		<input type="hidden" name="mode" id="mode" value="edit_squad_commit" />
		<input type="hidden" name="id" id="id" value="%(squad_id)s" />
		
		<label for="name">Editing:</label> %(name_text)s
		<br /><br />
		
		<table border="0" cellspacing="5" cellpadding="5">
			<tr>
				<td><label for="army">Army:</label></td>
				<td style="padding: 1px;">%(army_select)s</td>
			
				<td width="5">&nbsp;</td>
			
				<td>Type: </td>
				<td>%(unit_type)s</td>
			</tr>
			<tr>
				<td><label for="amount">Amount:</label></td>
				<td>%(amount)s</td>
			
				<td>&nbsp;</td>
			
				<td><label for="experience">Experince:</label></td>
				<td>%(experience)s</td>
			</tr>
			<tr>
				<td colspan="5">
					<strong>%(unit_name)s</strong>: %(unit_description)s
				</td>
			</tr>
			<tr>
				<td colspan="5">
					<input type="submit" value="Apply" />
				</td>
			</tr>
		</table>
	</form>
	<form id="delete_form" action="exec.py" method="post" accept-charset="utf-8">
		<input type="hidden" name="squad" id="squad" value="%(squad_id)s" />
		<input type="hidden" name="mode" id="mode" value="remove_squad" />
		<input style="float:right; margin-right:100px;" type="button" value="Delete squad" onclick="var answer = confirm('Delete %(name)s?')
		if (answer) $('#delete_form').submit();" />
	</form>
	<br /><br />""" % {
		"squad_id":			squad_id,
		"name":				the_squad.name,
		"name_text":		common.text_box("name", the_squad.name),
		"unit_type":		the_unit.name,
		"army_select":		common.option_box(
			name='army',
			elements=names,
			element_order=armies_dict.keys(),
			custom_id="army",
			selected=the_squad.army,
		),
		
		"unit_name":		the_unit.name,
		"unit_description":	the_unit.equipment_string,
		
		"amount":			common.text_box("amount", the_squad.amount),
		"experience":		common.text_box("experience", the_squad.experience),
	})
	
	output.append("</div>")
	
	page_data['Title'] = "Editing squad (%s)" % the_squad.name
	return "".join(output)
示例#16
0
def main(cursor):
	power_id	= int(common.get_val('power', 0))
	
	if power_id < 1:
		return "No power selected"
	
	the_power = power_q.get_one_power(cursor, power_id)
	
	output = ["<div style='padding: 5px;'>"]
	
	# Used for the player select menu
	player_dict = player_q.get_all_players(cursor)
	recent_dict = player_q.get_active_players(cursor)
	
	names = {}
	for p in recent_dict.keys():
		names[p] = player_dict[p].name
	
	if the_power.player not in names:
		# recent_dict[the_power.id] = the_power.player
		names[the_power.player] = player_dict[the_power.player].name
	
	
	output.append("""
	<form action="exec.py" method="post" accept-charset="utf-8">
		<input type="hidden" name="mode" id="mode" value="edit_power_commit" />
		<input type="hidden" name="id" id="id" value="%(power_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="player">Player:</label></td>
				<td>%(player_select)s</td>
			</tr>
			<tr>
				<td><label for="type">Type:</label></td>
				<td>%(type)s</td>
			
				<td width="5">&nbsp;</td>
			
				<td>&nbsp;</td>
				<td>&nbsp;</td>
			</tr>
			<tr>
				<td colspan="5"><label for="description">Description:</label><br />
				<textarea name="description" rows="4" cols="60">%(description)s</textarea></td>
			</tr>
		</table>
		<br />
		<input type="submit" value="Perform edit" />
	</form>
	<br /><br />""" % {
		"power_id":			power_id,
		"name":		the_power.name,
		"description":		the_power.description,
		"name_text":	common.text_box("name", the_power.name, size=20),
		"player_select":	common.option_box(
			name='player',
			elements=names,
			element_order=recent_dict.keys(),
			selected=the_power.player,
			custom_id="",
		),
		"type":	common.option_box(
			name='type',
			elements=power.power_types,
			selected=power.power_types[the_power.type],
		),
	})


	# End of padding
	output.append("</div>")

	return "".join(output)
示例#17
0
count += 1
output.append("""
<tr class="row%(row)d">
	<form action="exec.py" id="add_achievement_form" method="post" accept-charset="utf-8">
	<input type="hidden" name="mode" value="add_kill" />
	<td style="padding: 1px;">%(killer_select)s</td>
	<td style="padding: 1px;">%(victim_select)s</td>
	<td style="padding: 1px;"><input type="text" name="turn" value="%(turn)s" /></td>
	
	<td style="padding: 0px;"><a class="block_link" href="#" onclick="$('#add_achievement_form').submit();">Add</a></td>
	</form>
</tr>
""" % {	'row': (count % 2),
		"killer_select":	common.option_box(
			name='killer',
			elements=names,
			element_order=recent_list,
			custom_id="",
		),
		"victim_select":	common.option_box(
			name='victim',
			elements=names,
			element_order=recent_list,
			custom_id="",
		),
		'turn':				common.current_turn(),
	})


output.append("</table>")

print("".join(output))
示例#18
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)
示例#19
0
%(1)d x grade 1
%(2)d x grade 2
%(3)d x grade 3
%(4)d x grade 4""" % couterspy_dict


#	FORM ELEMENTS
#------------------------
# Selecting which set of info is sent
allied_ops_str_list = [str(x) for x in the_mission.allied_ops]

info_input = common.option_box(
	'info',
	elements = {
		correct_info:	"Correct",
		real_info: 		"Fudged",
		"No information was returned":	"Failure",
	},
	element_order = [correct_info,real_info,"No information was returned"],
	selected = real_info)

# Selecting what losses are used
loss_input = common.option_box(
	'loss',
	elements = {
		",".join(allied_ops_str_list): 	"All",
		",".join(caught_list):				"Real",
		",":								"None",
	},
	element_order = [",".join(allied_ops_str_list), ",".join(caught_list), ","],
	selected = ",".join(caught_list))
示例#20
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)
示例#21
0
def main(cursor, campaign_id = -1):
	output = ["""<div style="padding: 5px;">"""]
	
	campaign_id	= int(common.get_val('campaign', campaign_id))
	battle_id	= int(common.get_val('battle', 0))
	ajax = common.get_val('ajax', 0)
	
	if campaign_id < 1:
		if battle_id < 1:
			return "No campaign selected"
		else:
			the_battle = battle_q.get_one_battle(cursor, battle_id)
			campaign_id = the_battle.campaign
	
	the_campaign	= campaign_q.get_one_campaign(cursor, campaign_id)
	battle_dict		= battle_q.get_battles_from_campaign(cursor, campaign_id)
	team_dict		= team_q.get_all_teams(cursor)
	city_dict		= city_q.get_all_cities(cursor)
	
	if not ajax:
		output.append("""
		<div style="float:right;border:0px solid #000; width: 50%;">
			<form id="delete_form" action="exec.py" method="post" accept-charset="utf-8">
				<input type="hidden" name="campaign" id="campaign" value="{id}" />
				<input type="hidden" name="mode" id="mode" value="remove_campaign" />
				<input style="float:right; margin-right:100px;" type="button" value="Delete campaign" onclick="var answer = confirm('Delete {esc_name}?')
				if (answer) $('#delete_form').submit();" />
			</form>
			<div id="campaign_info">
				&nbsp;
			</div>
			&nbsp;
		</div>
		
		<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={camp}" class="block_link" style="display:inline;">Setup campaign</a>
		<br /><br />
		
		<span class="stitle">{name}</span>
		<br /><br />
		<table border="0" cellspacing="0" cellpadding="5">
		""".format(
			turn			= common.current_turn(),
			camp			= the_campaign.id,
			name			= the_campaign.name,
			id				= campaign_id,
			esc_name		= common.js_name(the_campaign.name),
		))
		
	else:
		output.append("""<table border="0" cellspacing="0" cellpadding="5" width="100%">""")
	
	output.append("""
		<tr class="row2">
			<th>Battle</th>
			<th>Time</th>
			<th>Location</th>
			<th>Type</th>
			<th>Result</th>
			<th>&nbsp;</th>
			<th colspan="2">Perform</th>
		</tr>""")
	
	# Display battles
	i = -1
	for battle_id, the_battle in battle_dict.items():
		i += 1
		
		location = "%d, %d" % (the_battle.x, the_battle.y)
		city_link = ""
		
		if the_battle.city > 0:
			city_link = '<!-- PY --> <a href="web.py?mode=edit_city&amp;city=%d">Edit city</a><!-- PYEND -->' % the_battle.city
		
		
		output.append("""
		<tr class="row{i}">
			<td>{name} ({battle_id}){city_link}</td>
			<td>{start} : {duration}</td>
			<td>{location} &nbsp; {city}</td>
			<td>{type}</td>
			<td>{result}</td>
			<td style="padding:0px;"><a href="web.py?mode=setup_battle&amp;battle={battle_id}" class="block_link">Setup</a></td>
			<td style="padding:0px;"><a href="web.py?mode=perform_battle&amp;battle={battle_id}" class="block_link">By unit</a></td>
			<td style="padding:0px;"><a href="web.py?mode=perform_by_army&amp;battle={battle_id}" class="block_link">By army</a></td>
		</tr>
		""".format(
			i=i%2,
			city_link = city_link,
			name=common.doubleclick_text("battles", "name", battle_id, the_battle.name, label_style="font-weight:bold;"),
			start=common.doubleclick_text("battles", "start", battle_id, the_battle.start, size=2),
			duration=common.doubleclick_text("battles", "duration", battle_id, the_battle.duration, size=2),
			location=location,
			battle_id=battle_id,
			city = city_dict[the_battle.city].name,
			
			type = battle.battle_types[the_battle.type],
			result = battle.result_types[the_battle.result],
		))
		
	
	if ajax:
		onload = ""
	else:
		onload = common.onload("$('#form_city').focus();")
	
	# Add new battle
	i += 1
	output.append("""
	<tr class="row{i}">
		<form action="exec.py" id="add_battle_form" method="post" accept-charset="utf-8">
		<input type="hidden" name="mode" value="add_battle" />
		<input type="hidden" name="campaign" value="{campaign_id}" />
		<td style="padding: 1px;"><input type="text" name="name" id="new_name" value="" /></td>
		<td style="padding: 1px;">
			<input type="text" name="start" value="-1" size="2"/>
			<input type="text" name="duration" value="" size="2"/>
		</td>
		<td style="padding: 1px;">
			<input type="text" name="location" value="" size="8"/>
		</td>
		
		<td style="padding: 1px;">
			{type}
		</td>
		<td>&nbsp;</td>
		
		<td colspan="3" style="padding: 0px;">
			<!--<a class="block_link" href="#" onclick="$('#add_battle_form').submit();">Add</a>-->
			<input type="submit" value="Add" />
		</td>
		</form>
	</tr>""".format(
		i=i%2,
		campaign_id=campaign_id,
		type = common.option_box("type", elements = battle.battle_types, element_order = [], custom_id = ""),
	))
	
	# Add by city
	city_dict = city_q.get_cities_for_dropdown(cursor)
	keys, names = [], {}
	for c, the_city in city_dict.items():
		if the_city.dead > 0: continue
		if not team_dict[the_city.team].active: continue
		
		keys.append(c)
		names[c] = the_city.name
	
	i += 1
	output.append("""
	<tr class="row{i}">
		<form action="exec.py" id="add_battle_form" method="post" accept-charset="utf-8">
		<input type="hidden" name="mode" value="add_battle" />
		<input type="hidden" name="campaign" value="{campaign_id}" />
		<td style="padding: 1px;">{city_list}</td>
		<td style="padding: 1px;">
			<input type="text" name="start" value="-1" size="2"/>
			<input type="text" name="duration" value="" size="2"/>
		</td>
		<td>
			&nbsp;
		</td>
		
		<td style="padding: 1px;">
			{type}
		</td>
		<td>&nbsp;</td>
		
		<td colspan="3" style="padding: 0px;">
			<!--<a class="block_link" href="#" onclick="$('#add_battle_form').submit();">Add</a>-->
			<input type="submit" value="Add" />
		</td>
		</form>
		{onload}
	</tr>
	</table>
	<br /><br />
	""".format(
		i=i%2,
		campaign_id=campaign_id,
		onload=onload,
		city_list = common.option_box(
			name='city',
			elements=names,
			element_order=keys,
			custom_id="form_city",
		),
		type = common.option_box("type", elements = battle.battle_types, element_order = [], custom_id = ""),
	))
	
	
	# Chosen kills
	output.append("""
	<div style="float:right;border:0px solid #000; width: 60%;">
		<div id="player_kills">
			&nbsp;
		</div>
	</div>
	""")
	
	
	# Now for moving all the armies
	output.append("""
	<!-- PY -->
	<table border="0" cellspacing="0" cellpadding="5">
	<!--
		<tr class="row2">
			<th>Team</th>
			<th colspan="3">Move</th>
			<th>&nbsp;</th>
		</tr>
	-->""")
	
	the_campaign.get_sides_full(cursor)
	for s in range(1, the_campaign.sides+1):
		teams_on_side = the_campaign.sides_full[s]
		
		if len(teams_on_side) > 0:
			i = 0
			output.append("<tr class='row2'><td colspan='5' style='text-align:center;'>Side %d</td></tr>" % s)
			
			for t in teams_on_side:
				i += 1
				
				output.append("""
				<tr class="row{i}">
					<td>{team}</td>
					<td style='padding:0px;'>
						<!--
						<a class="block_link" href="#" onclick="$.get('exec.py', {{mode: 'move_armies', team:{team_id}, campaign:{campaign}, location: ''}}, function () {{$('#ajax_result_{team_id}').html('Moved to location of final battle').val());}}); return false;">Final battle</a>
						-->
						<a class="block_link" href="exec.py?mode=move_armies&team={team_id}&campaign={campaign}">Final battle</a>
					</td>
					<td style='padding:0px;'>
						<a class="block_link" href="#" onclick="$.get('exec.py', {{mode: 'move_armies', team:{team_id}, campaign:{campaign}, location: $('#location_{team_id}').value}}, function () {{$('#ajax_result_{team_id}').html('Moved to ' + $('#location_{team_id}').val());}}); return false;">Location:</a>
					</td>
					<td style="padding:2px;">
						<form action="exec.py" method="post" accept-charset="utf-8" id="team_form_{team_id}">
							<input type="hidden" name="mode" value="move_armies" />
							<input type="hidden" name="team" value="{team_id}" />
							<input type="hidden" name="campaign" value="{campaign}" />
							<input type="text" name="location" id="location_{team_id}" value="" size="6"/>
						</form>
					</td>
					<td id="ajax_result_{team_id}">
						&nbsp;
					</td>
				</tr>
				""".format(
					i = i % 2,
					team_id = t['team'],
					team = team_dict[t['team']].name,
					campaign = campaign_id,
				))
	output.append("</table><!-- PYEND -->")
	
	output.append("</div><!-- PY -->%s<!-- PYEND -->" % common.onload("""
		$('#campaign_info').load('web.py',{'mode':'campaign_info','ajax':'True','campaign':'%d'});
		$('#player_kills').load('web.py',{'mode':'player_kills','ajax':'True','campaign':'%d'});
	""" % (campaign_id, campaign_id)))
	
	if ajax:
		output.append("<br />")
	
	return "".join(output)
示例#22
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)
示例#23
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)
示例#24
0
output = []

# If it's not closed then time = 0
if the_mission.time_closed == 0:
	closed_string = "<span class='neg'>Still open</span>"
else:
	closed_string = time.strftime("%A, %d %B %Y", time.localtime(the_mission.time_closed))

# Target stuff
if mission.mission_types[the_mission.type] in mission.city_targets:
	cities_order, cities_dict = city_q.get_live_cities()
	names = {}
	for c in cities_order:
		names[c] = cities_dict[c].name
	
	target_string = common.option_box(name='target', elements=names, element_order=cities_order, selected=the_mission.target)
elif mission.mission_types[the_mission.type] in mission.team_targets:
	target_string = team_f.structured_list(field_name="target", default=the_mission.target)



output.append("""
<form action="exec.py" method="post" accept-charset="utf-8" style="padding:10px;">
	<input type="hidden" name="mode" id="mode" value="edit_mission_commit" />
	<input type="hidden" name="id" id="id" value="%(mission_id)d" />
	
	<input type="hidden" name="requestTime" id="requestTime" value="' . $the_team->requestTime . '" />
	<table border="0" cellspacing="5" cellpadding="5">
		<tr>
			<td><label for="team">Team:</label></td>
			<td style="padding: 1px;">%(team)s</td>