Beispiel #1
0
def make_team_stats(cursor, the_world, the_team):
    build_team_stats(cursor, the_team, the_world)
    output = []

    # Tabs
    output.append(tabs(cursor, the_team))

    # Stat table
    output.append(display_stat_table(cursor, the_team.id))

    # War history
    output.append(display_team_losses(cursor, the_world, the_team.id))

    # Results
    output.append(display_team_results(cursor, the_world, the_team.id))

    # Failures
    output.append(display_team_failures(cursor, the_world, the_team.id))

    # Upkeep
    output.append(display_team_upkeep(cursor, the_world, the_team.id))

    # Onload
    # output.append(common.onload("switch_to('war_losses');"))
    output.append(common.onload("switch_to('results');"))

    return "".join(output)
Beispiel #2
0
def main(cursor):
	team_id		= int(common.get_val('team', 0))
	
	if team_id < 1:
		return "<div style='padding: 5px;'>%s</div>%s" % (common.select_team_form(
			cursor, 'orders_helper', dev_mode=1, ajax=1
		), common.onload("$('#select_team_input').focus();"))
	
	the_oh = oh.Oh(cursor)
	the_oh.local_path = True
	the_oh.setup(true_team_list=[team_id])
	
	return the_oh.make_oh(team_id)
Beispiel #3
0
def main(cursor):
	order_id = int(common.get_val("order", -1))
	
	if order_id < 1:
		return "<div style='padding: 5px;'>%s</div>" %  "No order selected"
	
	the_order = intorder_q.get_interactive(cursor, order_id)
	the_order.the_world = world.World(cursor)
	the_order.interactive_setup(cursor)
	
	# Points to make
	points_template = "<label for='pt_{i}'>{p}</label>: <input type='checkbox' id='pt_{i}' value='1' />"
	
	points_template = """
	<tr id="row_{i}" class="">
		<td><label for="pt_{i}" style="width:100%; display:block;">{p}</label></td>
		<td style="padding:2px;"><input type="checkbox" name="pt_{i}" id="pt_{i}" value="True" onchange="if ($('#pt_{i}').attr('checked')) {{$('#row_{i}').addClass('selected_army');}} else {{$('#row_{i}').removeClass('selected_army');}} calc_amount();"/></td>
		<td>&nbsp;</td>
	</tr>
	"""
	
	output = []
	output.append('<div style="padding:10px;">')
	
	# Get to work
	output.append("""
	<div style="border: 1px solid #000;">
		{pre_calculations}
	</div>
	<div style="width: 40%; float:left; border: 1px solid #000;">
		{content}
	</div>
	<div style="width: 30%; float:left; border: 1px solid #000;">
	<table border="0" cellspacing="0" cellpadding="5">
		{points}
	</table>
		<!--{points}-->
	</div>
	<div style="border: 1px solid #000; clear: left;">
		{post_calculations}
		Score: <span id="score">0</span>
		<br /><br />
		
		<form action="web.py" method="post" accept-charset="utf-8">
			<input type="hidden" name="mode" value="direct_query" />
			<textarea name="query" id="query" rows="4" style="font-family:monospace; width: 60%;">-- No queries at present</textarea>
			
			<input type="submit" value="Run query" />
		</form>
		<textarea name="result" id="result" rows="4" style="font-family:monospace; width: 60%;">[o]{title}[/o]\nNo results</textarea>
	</div>
	""".format(
		content	= the_order.interactivity['content'],
		points	= "".join([points_template.format(i=i, p=p) for i, p in enumerate(the_order.interactivity['points'])]),
		pre_calculations = the_order.interactivity['pre_calculations'],
		post_calculations = "",
		title = the_order.title_name,
	))
	
	js_points = "if ($('#pt_%(i)d').attr('checked') == true) {points++;}"
	
	page_data['javascript'] = """
	function calc_amount ()
	{
		multiplier = %(multiplier)d;
		points = 0;
		%(check_points)s
		
		score = ((points*multiplier)/%(max_score)d)*100;
		
		$('#score').html(Math.round(score) + "%%, Muliplier: %(multiplier)s");
		$('#query').html(query_func(score) + "\\nUPDATE interactive_orders SET handled = True WHERE id = %(order_id)d;");
		$('#result').html(result_func(score));
	}
	function query_func (score)
	{
		%(query_func)s
	}
	function result_func (score)
	{
		%(result_func)s
	}
	""" % {
		"order_id":	order_id,
		"check_points":	"\n".join([js_points % {"i":i} for i, p in enumerate(the_order.interactivity['points'])]),
		"multiplier": the_order.interactivity['multiplier'],
		"max_score": len(the_order.interactivity['points']),
		"query_func": the_order.interactivity['query_func'],
		"result_func": the_order.interactivity['result_func'],
		"multiplier": the_order.interactivity['multiplier'],
	}
	
	output.append('</div>%s' % common.onload('calc_amount();'))
	
	return "".join(output)
Beispiel #4
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)
Beispiel #5
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)
Beispiel #6
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)
Beispiel #7
0
def main(cursor):
	# Get team Id
	team_id = int(common.get_val('team', 0))
	
	text_location = common.get_val('location', "")
	
	if team_id < 1:
		return "<div style='padding: 5px;'>{0}</div>".format(common.select_team_form(cursor, 'list_cities'))
	
	cities_dict = city_q.get_cities_from_team(cursor, team = team_id, include_dead = True)
	
	# Work out city points
	total_points = 0
	for city_id, the_city in cities_dict.items():
		if the_city.dead == True: continue
		total_points += the_city.point_value()
	
	output = []
	
	output.append("""
	<table border="0" cellspacing="0" cellpadding="5" style="width: 100%;">
		<tr class="row2">
			<th>City name</th>
			<th colspan="3">Location</th>
			<th>Port</th>
			<th>Secret</th>
			<th>Dead</th>
			<th>Nomadic</th>
			
			<th>Overlap</th>
			
			<th>Wonder speed</th>
			<th>Population</th>
			<th>Slaves</th>
			<th>Happiness</th>
			
			<th colspan="2">&nbsp;</th>
		</tr>""")
	
	# Work out how fast it can build wonders
	city_wonder_speed = {}
	for c1, city1 in cities_dict.items():
		city_wonder_speed[c1] = math.floor((city1.population + city1.slaves)/1000)
		c1_loc = (cities_dict[c1].x, cities_dict[c1].y)
		
		for c2, city2 in cities_dict.items():
			if city2.dead: continue
			
			if c2 != c1:
				amount = city_rules.wonder_build_rate(city2, city1)
				city_wonder_speed[c1] += amount
		
		city_wonder_speed[c1] = common.number_format(int(city_wonder_speed[c1]))
	
	count = -1
	if len(cities_dict) > 0:
		for city_id, the_city in cities_dict.items():
			count += 1
			
			city_share = 0
			if not the_city.dead:
				if total_points > 0:
					city_share = round(the_city.point_value()/total_points*100,1)
			
			# Happiness
			happiness = city.happiness_str(the_city.happiness)
			
			if happiness == "Rebellious":
				happiness = '<span style="font-weight:bold;color:#A00;">Rebellious</span>'
			
			if happiness == "Utopian":
				happiness = '<span style="font-weight:bold;color:#0A0;">Utopian</span>'
			
			output.append("""
			<tr class="row%(row)d" id="%(city_id)d">
				<td>%(name)s</td>
		
				<td>%(x)s</td>
				<td>%(y)s</td>
				<td style="padding: 0px;"><a class="block_link" href="web.py?mode=view_map&amp;%(map_link)s">Map link</a></td>
				
				<td style="text-align: center;">%(port)s</td>
				<td style="text-align: center;">%(secret)s</td>
				<td style="text-align: center;">%(dead)s</td>
				<td style="text-align: center;">%(nomadic)s</td>
				
				<td>%(overlap)s</td>
				
				<td>%(wonder_speed)s</td>
				<td>%(population)s</td>
				<td>%(slaves)s</td>
				
				<td>%(happiness)s</td>
				
				<!--<td style="padding: 0px;"><a class="block_link" href="web.py?mode=view_city_trade&amp;city=%(city_id)d">City trade</a></td>-->
				<td style="padding: 0px;"><a class="block_link" href="web.py?mode=view_city_matrix&amp;city=%(city_id)d">City matrix</a></td>
				<td style="padding: 0px;"><a class="block_link" href="web.py?mode=edit_city&amp;city=%(city_id)d">Edit city</a></td>
			</tr>
			""" % {	'row': (count % 2),
			
					'city_id': the_city.id,
					'name': common.doubleclick_text("cities", "name", the_city.id, the_city.name, "font-weight:bold"),
					'x': common.doubleclick_text("cities", "x", the_city.id, the_city.x, ""),
					'y': common.doubleclick_text("cities", "y", the_city.id, the_city.y, ""),
					"map_link":	the_city.map_link_args(),
					
					'port': common.bstr(the_city.port),
					'secret': common.bstr(the_city.secret),
					'dead': "" if the_city.dead < 1 else common.doubleclick_text("cities", "dead", the_city.id, the_city.dead, "", size=3),
					'nomadic': common.bstr(the_city.nomadic),
				
					'overlap': the_city.overlap,
				
					'population': common.doubleclick_text("cities", "population", the_city.id, the_city.population, ""),
					'slaves': common.doubleclick_text("cities", "slaves", the_city.id, the_city.slaves, ""),
				
					"wonder_speed": city_wonder_speed[the_city.id],
					"happiness":	happiness,
				})


	# Add new city
	count += 1
	output.append("""
	<tr class="row%(row)d">
		<form action="exec.py" id="add_city_form" method="post" accept-charset="utf-8">
		<input type="hidden" name="mode" value="add_city" />
		<input type="hidden" name="team" value="%(team_id)s" />
		<td style="padding: 1px;"><input type="text" name="name" id="new_name" value="" /></td>
		<td style="padding: 0px;" colspan="2">
			<a href="web.py?mode=view_map&amp;new_mode=list_cities&amp;team=%(team_id)s" class="block_link">Location:</a>
		</td>
		<td colspan="1" style="padding:1px;">
			%(location)s
		</td>
		<td style="padding: 2px;"><input type="checkbox" name="port" value="True" /></td>
		<td style="padding: 2px;"><input type="checkbox" name="secret" value="True" /></td>
		<td style="padding: 2px;"><input type="text" name="dead" id="dead" value="0" size="3"/></td>
		<td style="padding: 2px;"><input type="checkbox" name="nomadic" value="True" /></td>
	
		<td>&nbsp;</td>
		
		<td>&nbsp;</td>
	
		<td style="padding: 1px;"><input type="text" name="population" value="" size="10"/></td>
		<td style="padding: 1px;"><input type="text" name="slaves" value="" size="10"/></td>
	
		<td style="padding: 2px;" colspan="3"><input type="submit" value="Add" /></td>
		<!--
		<td style="padding: 0px;" colspan="3"><a class="block_link" href="#" onclick="$('#add_city_form').submit();">Add</a></td>
		-->
		</form>
		%(onload)s
	</tr>
	""" % {	'row': (count % 2),

			"team_id":	team_id,
			"location": common.text_box("text_location", text_location, custom_id="", size="7"),
			"onload":	common.onload("$('#new_name').focus();"),
			})


	output.append("</table>")

	return "".join(output)
Beispiel #8
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)
Beispiel #9
0
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))
Beispiel #10
0
def main(cursor, turn=-1):
	output = ["""<div style="padding: 5px;">"""]
	onload = []
	turn = int(common.get_val("turn", turn))
	
	if turn < 1:
		turn = common.current_turn()
	
	campaign_dict	= campaign_q.get_campaigns_from_turn(cursor, turn)
	team_dict		= team_q.get_all_teams(cursor)
	
	# Form to select a different turn
	output.append("""
	<!--
	<div style="float:right;border:1px solid #000; width: 60%%;" id="turn_info">
		&nbsp;
	</div>
	-->
	
	<form action="web.py" method="get" accept-charset="utf-8">
		<input type="hidden" name="mode" id="mode" value="list_campaigns" />
		Turn: <input type="text" name="turn" value="%s" />
		&nbsp;&nbsp;&nbsp; <input type="submit" value="Show" />
	</form>
	%s
	<br /><br />""" % (
		turn,
		common.onload("$('#turn_info').load('web.py',{'mode':'turn_info','ajax':'True'});")))
	
	# Now the actual table
	output.append("""
	<table border="0" cellspacing="0" cellpadding="5">
		<tr class="row2">
			<th>Turn</th>
			<th>Name</th>
			<th>Sides</th>
			<th>&nbsp;</th>
			<th>&nbsp;</th>
		</tr>""")
	
	count = 1
	for campaign_id, the_campaign in campaign_dict.items():
		count += 1
		
		the_campaign.get_sides_basic(cursor)
		
		team_string = []
		for s in range(1, the_campaign.sides+1):
			teams_on_side = the_campaign.sides_basic[s]
			
			if teams_on_side == []:
				teams_on_side_str = "None"
			else:
				teams_on_side_str = ", ".join([team_dict[t].name for t in teams_on_side])
			
			team_string.append("""{s}: {teams}""".format(
				s=s,
				teams=teams_on_side_str,
			))
		
		team_string = "<br />".join(team_string)
		
		output.append("""
			<tr class="row{count}">
				<td>{turn}</td>
				<td><strong>{name}</strong></td>
				<td>{teams}</td>
				<td style="padding:0px;"><a href="web.py?mode=setup_campaign&amp;campaign={campaign_id}" class="block_link">Setup</a></td>
				<td style="padding:0px;"><a href="web.py?mode=list_battles&amp;campaign={campaign_id}" class="block_link">Battles</a></td>
			</tr>
			<!--
			<tr class="row0">
				<td colspan="5" id="camp_{campaign_id}" style="padding:0px;"></td>
			</tr>
			-->
		""".format(
			turn=turn,
			# count=1,
			count=count%2,
			name=the_campaign.name,
			teams=team_string,
			campaign_id=campaign_id,
		))
		
		
		# onload.append("$('#camp_%(id)d').load('web.py', {'mode':'list_battles', 'ajax':'True', 'campaign':'%(id)d'});" % {
		# 	"id": campaign_id,
		# })
	
	# New campaign
	count += 1
	output.append("""
	<!-- PY -->
	<tr class="row{count}">
		<form action="exec.py" id="add_campaign_form" method="post" accept-charset="utf-8">
		<input type="hidden" name="mode" id="mode" value="add_campaign" />
		<td style="padding: 1px;"><input type="text" name="turn" value="{turn}" size="5"/></td>
		<td style="padding: 1px;"><input type="text" name="name" id="name" value="" /></td>
		<td style="padding: 1px;"><input type="text" name="sides" value="2" size="3"/></td>
		<td style="padding: 0px;" colspan="2">
			<!--
			<a class="block_link" href="#" onclick="$('#add_campaign_form').submit(); return false;">Add</a>
			-->
			<input type="submit" value="Add" />
		</td>
		</form>
		{onload}
	</tr>
	<!-- PYEND -->
	""".format(
		turn=turn,
		count=count%2,
		onload=common.onload("$('#name').focus();%s" % "".join(onload)),
	))
	
	output.append("</table></div>")
	
	return "".join(output)
Beispiel #11
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)
Beispiel #12
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)
Beispiel #13
0
def main(cursor):
	# Get team Id
	team_id = int(common.get_val('team', 0))
	
	if team_id < 1:
		return "<div style='padding: 5px;'>%s</div>" % common.select_team_form(cursor, 'list_spells')
	
	# Build team item
	the_team = team_q.get_one_team(cursor, team_id)
	spell_dict = spell_q.get_all_spells(cursor)
	
	output = []
	
	the_team.get_spells(cursor)
	
	output.append("""
	<table style="width: 100%;" border="0" cellspacing="0" cellpadding="5">
	<tr class="row2">
		<th>#</th>
		<th>&nbsp;</th>
	</tr>
	""")
	
	max_spell_level = 1
	skip_spell_list = {}
	table_dict = {}
	spell_points_spent = 0
	
	for spell_id, spell_level in the_team.spell_levels.items():
		if spell_level not in table_dict:
			table_dict[spell_level]			= []
			skip_spell_list[spell_level]	= []
		max_spell_level = max(max_spell_level, spell_level)
		
		# Total that they've spent
		the_spell = spell_dict[spell_id]
		spell_points_spent += spell_rules.cost_to_get_to_level(cursor, the_spell, spell_level, in_spell_points=True).get("Spell points", 0)
		spell_points_spent += the_team.spell_points[spell_id]
		
		skip_spell_list[spell_level].append(spell_id)
		
		
		table_dict[spell_level].append("""%(name)s <a class="red_link" href="exec.py?mode=set_spell&amp;spell=%(spell_id)s&amp;team=%(team_id)s&amp;level=%(level_down)s&amp;points=0">&nbsp;&lt;&nbsp;</a>
			
			%(points)s/%(points_to_next)s
			
			<a class="green_link" href="exec.py?mode=set_spell&amp;spell=%(spell_id)s&amp;team=%(team_id)s&amp;level=%(level_up)s&amp;points=0">&nbsp;&gt;&nbsp;</a>""" % {
		"name":			the_spell.name,
		"spell_id":		spell_id,
		"team_id":		team_id,
		"points":			the_team.spell_points[spell_id],
		"points_to_next":	spell_rules.cost_for_next_level(cursor, the_spell, spell_level, in_spell_points=True).get("Spell points"),
		"level_down":	spell_level-1,
		"level_up":		spell_level+1,
		})
	
	
	for i in range(0, max_spell_level+1):
		if i not in table_dict:
			table_dict[i] = []
			skip_spell_list[i] = []
		
		output.append("""
		<tr class="row%(row_count)s">
			<td width="15">%(i)s</td>
			<td style="padding: 5px 2px 0 2px;">%(spells)s
			
			<!--
				<form id="spell_form_%(i)s" style="float: right;" action="exec.py" method="post" accept-charset="utf-8">
			<input type="hidden" name="mode" value="set_spell" />
			<input type="hidden" name="team" value="%(team_id)s" />
			<input type="hidden" name="points" value="0" />
			<input type="hidden" name="level" value="%(i)s" />
			<a href="#" onclick="$('#spell_form_%(i)s').submit();" class="block_link" style="float: right;">Add</a>
			<select style="float: right;" name="spell">%(new_spell)s</select></form>
			-->
			</td>
		</tr>
		""" % {
			"i":			i,
			"team_id":		team_id,
			"row_count":	(i%2),
			"spells":		", ".join(table_dict[i]),
			"new_spell":	spell_f.spell_option_list(cursor, skip_spell_list[i]),
		})
	
	# Add spells
	output.append("""
	<tr class="row%(row_count)s">
		<td colspan="2">
			<form action="exec.py" method="post" accept-charset="utf-8">
				<input type="hidden" name="mode" value="set_spell" />
				<input type="hidden" name="team" value="%(team_id)s" />
				<select name="spell" id="new_spell">
					%(spell_list)s
				</select>
				&nbsp;&nbsp;
				L: <input type="text" name="level" id="new_level" value="" onblur="$('#points_to_next').load('web.py', {'ajax':'True','mode':'spell_points_for_next','spell':$('#new_spell').val(), 'level':$('#new_level').val()});" size="5"/>
				&nbsp;&nbsp;
				P: <input type="text" name="points" value="" size="5" />/<span id="points_to_next">0</span>
				<input type="submit" value="Add" />
			</form>
		</td>
	</tr>
	%(onload)s
	""" % {
		"team_id":		team_id,
		"row_count":	((i+1)%2),
		"spell_list":	spell_f.spell_option_list(cursor),
		"onload":		common.onload("$('#new_spell').focus();"),
	})
	
	output.append("</table>")
	
	output.append("<br />&nbsp;&nbsp;&nbsp;Total spell points spent: %d" % spell_points_spent)
	
	return "".join(output)
Beispiel #14
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)
Beispiel #15
0
def main(cursor):
	one_query	= common.get_val('one', False)
	query		= common.get_val('query')
	
	if one_query:
		queries = [query]
	else:
		queries = query.split("\r")
	
	output = ["""
	<form action="web.py?mode=direct_query" method="post" accept-charset="utf-8">
		One query: <input type="checkbox" name="one" value="True" />
		<textarea name="query" id="query" rows="5" style="width:99%%;">%s</textarea>
		<br />
		<input type="submit" value="Run" style="float:right;margin-right: 40px;font-size:1.2em;"/>
		<br /><br />
	</form>
	""" % query]
	
	output.append(common.onload("$('#query').focus();"))
	
	if query != "":
		output.append("<hr /><div id='qrun' style='background-color:#FFC;padding:5px;'>Query run successfully.</div><br /><br />")
		
		first_row = True
		headers = []
		data = []
		
		id_list = []
		i = 0
		
		if len(queries) > 1:
			cursor.execute('BEGIN')
			for q in queries:
				q = q.strip()
				if q == '': continue
				if q[0:2] == '--': continue
			
				try:
					cursor.execute(q)
				except Exception as e:
					print("\nError with '%s'" % q)
					cursor.execute('ROLLBACK')
					raise Exception("Database error: %s\nQuery: %s" % (str(e.args[0]).replace("\n",""), q))
		
			cursor.execute('COMMIT')
		else:
			try:
				cursor.execute(query)
			except Exception as e:
				print("\nError with '%s'" % query)
				cursor.execute('ROLLBACK')
				raise Exception("Database error: %s\nQuery: %s" % (str(e.args[0]).replace("\n",""), query))
			
			totals = {}
			try:
				for row in cursor:
					if "id" in row:
						id_list.append(str(row['id']))

					if first_row:
						for k, v in row.items():
							totals[k] = 0
							headers.append("<th>%s</th>" % k)
				
					data.append("<tr class='row%d'>" % (i % 2))
					for k, v in row.items():
						data.append("<td>%s</td>" % v)
					
						if type(v) in (int, float):
							totals[k] += v
					data.append("</tr>")
				
					first_row = False
					i += 1
			
				output.append("""<div style='padding:5px;'>
				<table border="0" cellspacing="0" cellpadding="5">
					<tr class='row2'>
						{headers}
					</tr>
					{data}
				</table></div>
				""".format(
					headers="".join(headers),
					data="".join(data),
				))

				output.append('&nbsp;Id list: <input type="text" value="%s" style="width: 400px;"/>' % ", ".join(id_list))
			except Exception as e:
				output.append('No result set')
	
	output.append('<br /><br /><table border="0" cellspacing="0" cellpadding="5">')
	for t in templates:
		output.append(
			"""<tr>
				<td onclick="$('#query').text('%s');">%s</td>
			</tr>""" % (t, t)
		)
	output.append('</table>%s' % common.onload("$('#qrun').animate({backgroundColor:'white'}, 3000);"))
	
	return "".join(output)
Beispiel #16
0
	def make_oh(self, team_id):
		the_team = self.the_world.teams()[team_id]
		
		tabs = """
		<div id="tabs" style="border-bottom: 3px solid #EEE; height: 30px;">
			<div class="ti_tab" id="construction_tab" onclick="switch_to('construction');">
				Cities
			</div>
			<div class="ti_tab" id="military_tab" onclick="switch_to('military');">
				Military
			</div>
			<!--
			<div class="ti_tab" id="monsters_tab" onclick="switch_to('monsters');">
				Monsters
			</div>
			-->
			<div class="ti_tab" id="research_tab" onclick="switch_to('research');">
				Research
			</div>
			<div class="ti_tab" id="operative_tab" onclick="switch_to('operative');">
				Operatives
			</div>
			<div class="ti_tab" id="trade_tab" onclick="switch_to('trade');">
				Trades
			</div>
			<div class="ti_tab" id="diplomacy_tab" onclick="switch_to('diplomacy');">
				Diplomacy
			</div>
			<div class="ti_tab" id="advanced_tab" onclick="switch_to('advanced');">
				Advanced
			</div>
			<div class="ti_tab" id="command_tab" onclick="switch_to('command');">
				Commands
			</div>
		</div>
		"""
		
		output = [tabs]
		
		loader_src = '../images/other/loading.gif'
		
		output.append("""
		<div id='loading_div' style='text-align:center;padding-top:20px;'>
			Loading...
			<br /><br />
			<img src='%s'/>
		</div>""" % loader_src)
		
		load_java	= []
		run_java	= []
		
		# CONSTRUCTION - 111
		additions = self.construction_block(the_team)
		output.append(additions[0])
		load_java.append(additions[1])
		run_java.append(additions[2])
		
		# MILITARY - 498
		additions = self.military_block(the_team)
		output.append(additions[0])
		load_java.append(additions[1])
		run_java.append(additions[2])
		
		# MONSTERS
		# additions = self.monsters_block(the_team)
		# output.append(additions[0])
		# load_java.append(additions[1])
		# run_java.append(additions[2])
		
		# RESEARCH - 52
		additions = self.research_block(the_team)
		output.append(additions[0])
		load_java.append(additions[1])
		run_java.append(additions[2])
		
		# OPERATIVES - 221
		additions = self.operative_block(the_team)
		output.append(additions[0])
		load_java.append(additions[1])
		run_java.append(additions[2])
		
		# TRADE - 19
		additions = self.trade_block(the_team)
		output.append(additions[0])
		load_java.append(additions[1])
		run_java.append(additions[2])
		
		# DIPLOMACY - 12
		additions = self.diplomacy_block(the_team)
		output.append(additions[0])
		load_java.append(additions[1])
		run_java.append(additions[2])
		
		# ADVANCED
		additions = self.advanced_block(the_team)
		output.append(additions[0])
		load_java.append(additions[1])
		run_java.append(additions[2])
		
		# COMMANDS
		additions = self.command_block(the_team)
		output.append(additions[0])
		load_java.append(additions[1])
		run_java.append(additions[2])
		
		# bytes = len("".join(output))
		# print("")
		# print("<span style='background-color:#FFF;'>Bytes: %s</span>" % format(round(bytes/1000), ','))
		
		# Setup
		output.append(common.onload("on_load_setup();"))
		
		#	JAVASCRIPT
		#------------------------
		javascript = oh_f.javascript("".join(load_java), "".join(run_java))
		
		#	HEADER AND FOOTER
		#------------------------
		# 892px for .content
		# container has 10px padding so left with 872px
		# 872/2 = 436
		# order_box has 5px side margin, becomes 426 yet somehow only 414 works...
		css = """
		.order_box, .order_box_half
		{
			border:1px solid #600;
			background-color:#FFEFEF;
			margin:10px 5px;
			padding:5px;
		}
	
		.order_box_half
		{
			width: 414px;
			float: left;
		}
		"""
	
		output.insert(0, common.headers(title_name="%s order creation form" % the_team.name, css=css, javascript=javascript, local_path=self.local_path))
	
		tabs = tabs.replace('id="', 'id="bottom_')
	
		output.append("""
		%s
		<br /><hr />
		<div style="padding: 5px;">
			<input type="button" id="build_button" value="Create orders" onclick="build_orders();"/><br /><br />
			<strong>Complete orders</strong><br />
			<textarea id="final_output" style="width:100%%;" rows="20"></textarea>
		</div>""" % tabs)
	
		output.append(common.footers())
		
		# Compress some output
		final_output = "".join(output)#.replace("	", "").replace("  ", " ").replace("	 ", " ")
		return final_output
Beispiel #17
0
def main(cursor):
	# Get team Id
	team_id = int(common.get_val('team', 0))
	
	# Build team
	the_team = team_q.get_one_team(cursor, team_id)
	
	if team_id < 1:
		return "<div style='padding: 5px;'>%s</div>" % common.select_team_form(cursor, 'list_units')
	
	unit_dict = unit_q.get_units_from_team(cursor, team=team_id)
	equipment_dict = equipment_q.get_all_equipment(cursor)
	the_team.get_units(cursor)
	
	output = []
	output.append("""
	<table border="0" cellspacing="0" cellpadding="5" style="width: 100%;">
		<tr class="row2">
			<th>Icon</th>
			<th>Amount</th>
			<th>Name</th>
			<th>Cost</th>
			<th colspan='4'>Categories</th>
			<th>Equipment</th>
			<th style="width:70px;">Edit</th>
			<!--
			<th colspan="2">Add</th>
			-->
		</tr>""")

	names = {}
	count = -1
	if len(unit_dict) > 0:
		# for team_id, team in team_dict.items():
		for unit_id, the_unit in unit_dict.items():
			if unit_id not in the_team.units: the_team.units[unit_id] = 0
			
			names[unit_id] = the_unit.name
			count += 1
			
			output.append("""
			<tr class="row%(row)d" id="%(unit_id)d">
				<td>%(icon)s</td>
				<td>%(count)s</td>
				<td>%(name)s</td>
			
				<td>%(cost)s</td>
				<td>%(weapon_cat)s</td>
				<td>%(armour_cat)s</td>
				<td>%(move_cat)s</td>
				<td>%(training_cat)s</td>
				<td>%(equipment)s</td>
			
				<td style="padding: 0px;"><a class="block_link" href="web.py?mode=edit_unit&amp;unit=%(unit_id)d">Edit unit</a></td>
				<!--
				<td style="padding: 1px;">
					<form action="exec.py" method="post" accept-charset="utf-8">
						<input type="text" name="amount" value="" size="8"/>
						<input type="hidden" name="mode" value="alter_unit_count" />
						<input type="hidden" name="team" value="%(team_id)s" />
						<input type="hidden" name="unit" value="%(unit_id)s" />
					</form>
				</td>
				<td style="padding: 0px;">
					<a class="block_link" href="#" onclick="$('#form_add_%(unit_id)s').submit();">Add unit</a>
				</td>
				-->
			</tr>
			""" % {	'row': (count % 2),
				
					"team_id":		team_id,
					'unit_id':		unit_id,
					'name':	common.doubleclick_text("units", "name", unit_id, the_unit.name, "font-weight:bold"),
					'icon':			"",
					'count':		common.number_format(the_team.units[unit_id]),
					
					'weapon_cat':	unit.weapon_categories[the_unit.weapon_cat],
					'armour_cat':	unit.armour_categories[the_unit.armour_cat],
					'move_cat':	unit.move_categories[the_unit.move_cat],
					'training_cat':	unit.training_categories[the_unit.training_cat],
				
					"cost":			unit_rules.print_unit_cost(the_unit, cursor=cursor, equipment_dict=equipment_dict),
					"equipment":	the_unit.equipment_string,
				
					})
	
	# Add unit type
	# armies_dict = army_q.get_armies_from_team(cursor, team=team_id, include_garrisons=1)
	count += 1
	
	# armies_names = {}
	# has_non_garrison = False
	# for k, v in armies_dict.items():
	# 	armies_names[k] = v.name
	# 	if v.garrison < 0: has_non_garrison = True
	# 
	# armies_order.reverse()
	# armies_order.append("disabled")
	# armies_order.append("XYZ_all_garrisons")
	# if has_non_garrison == True:
	# 	armies_order.append("XYZ_all_non_garrisons")
	# 	armies_order.append("XYZ_all_armies")
	# armies_order.reverse()
	# 
	# if has_non_garrison == True:
	# 	armies_names["XYZ_all_armies"]			= "All armies"
	# 	armies_names["XYZ_all_non_garrisons"]	= "All non garrisons"
	# armies_names["XYZ_all_garrisons"]		= "All garrisons"


	output.append("""
	<tr class="row%(row)d">
		<form action="exec.py" method="post" id="new_unit_form" accept-charset="utf-8">
		<input type="hidden" name="mode" value="create_new_unit" />
		<input type="hidden" name="team" value="%(team_id)s" />
		<td>&nbsp;</td>
		<td style="padding: 1px;">&nbsp;</td>
		<td style="padding: 1px;"><input type="text" name="name" id="name" value="" size="13"/></td>
		<td colspan='4'>&nbsp;</td>
		<td style="padding: 1px;">&nbsp;</td>
		<td style="padding: 2px;">
			<textarea name="equipment_string" id="equipment_string" rows="1" cols="30"></textarea>
		</td>
	
		<td style="padding: 0px;"><a class="block_link" onclick="$('#new_unit_form').submit();" href="#">Add</a></td>
		%(onload)s
		</form>
	</tr>
	""" % {	'row': (count % 2),

			"team_id":		team_id,
			'onload':		common.onload("$('#name').focus();"),
			})

	# Now for solo units
	unit_dict = unit_q.get_units_from_team(cursor, team=0)
	if len(unit_dict) > 0:
		# for team_id, team in team_dict.items():
		for unit_id, the_unit in unit_dict.items():
			if unit_id not in the_team.units: the_team.units[unit_id] = 0
			
			names[unit_id] = the_unit.name
			count += 1
		
			output.append("""
			<tr class="row%(row)d" id="%(unit_id)d">
				<td>%(icon)s</td>
				<td>%(count)s</td>
				<td>%(name)s</td>
			
				<td>%(cost)s</td>
				
				<td colspan='4'>&nbsp;</td>
				
				<td>%(equipment)s</td>
			
				<td style="padding: 0px;"><a class="block_link" href="web.py?mode=edit_unit&amp;unit=%(unit_id)d">Edit unit</a></td>
				<!--
				<td style="padding: 1px;">
					<form action="exec.py" method="post" accept-charset="utf-8">
						<input type="text" name="amount" value="" size="8"/>
						<input type="hidden" name="mode" value="alter_unit_count" />
						<input type="hidden" name="team" value="%(team_id)s" />
						<input type="hidden" name="unit" value="%(unit_id)s" />
					</form>
				</td>
				<td style="padding: 0px;">
					<a class="block_link" href="#" onclick="$('#form_add_%(unit_id)s').submit();">Add unit</a>
				</td>
				-->
			</tr>
			""" % {	'row': (count % 2),
				
					"team_id":		team_id,
					'unit_id':		unit_id,
					'name':	common.doubleclick_text("units", "name", unit_id, the_unit.name, "font-weight:bold"),
					'icon':			"",
					'count':		common.number_format(the_team.units[unit_id]),
				
					"cost":			unit_rules.print_unit_cost(the_unit, cursor=cursor, equipment_dict=equipment_dict),
					"equipment":	the_unit.equipment_string,
				
					})
	
	output.append("</table>")
	page_data['Title'] = "%s unit list" % the_team.name
	return "".join(output)
Beispiel #18
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)
Beispiel #19
0
	def make_wh(self, team_id):
		the_team = self.the_world.teams()[team_id]
		
		tabs = """
		<div id="tabs" style="border-bottom: 3px solid #EEE; height: 30px;">
			<div class="ti_tab" id="overview_tab" onclick="switch_to('overview');">
				Overview
			</div>
			<div class="ti_tab" id="units_tab" onclick="switch_to('units');">
				Units
			</div>
			<div class="ti_tab" id="plan_tab" onclick="switch_to('plan');">
				Plan
			</div>
			<div class="ti_tab" id="feedback_tab" onclick="switch_to('feedback');">
				Feedback
			</div>
		</div>
		"""
		
		output = [tabs]
		
		load_java	= []
		run_java	= []
		
		# OVERVIEW
		additions = self.overview_block(the_team)
		output.append(additions[0])
		load_java.append(additions[1])
		run_java.append(additions[2])
		
		# UNITS
		additions = self.units_block(the_team)
		output.append(additions[0])
		load_java.append(additions[1])
		run_java.append(additions[2])
		
		# PLAN
		additions = self.plan_block(the_team)
		output.append(additions[0])
		load_java.append(additions[1])
		run_java.append(additions[2])
		
		# FEEDBACK
		additions = self.feedback_block(the_team)
		output.append(additions[0])
		load_java.append(additions[1])
		run_java.append(additions[2])
		
		# bytes = len("".join(output))
		# print("")
		# print("<span style='background-color:#FFF;'>Bytes: %s</span>" % format(round(bytes/1000), ','))
		
		# Setup
		output.append(common.onload("on_load_setup();"))
		
		#	JAVASCRIPT
		#------------------------
		javascript = wh_f.javascript("".join(load_java), "".join(run_java))
		
		#	HEADER AND FOOTER
		#------------------------
		# 892px for .content
		# container has 10px padding so left with 872px
		# 872/2 = 436
		# order_box has 5px side margin, becomes 426 yet somehow only 414 works...
		css = """
		.order_box, .order_box_half
		{
			border:1px solid #600;
			background-color:#FFEFEF;
			margin:10px 5px;
			padding:5px;
		}
	
		.order_box_half
		{
			width: 414px;
			float: left;
		}
		"""
	
		output.insert(0, common.headers(title_name="%s war helper" % the_team.name, css=css, javascript=javascript, local_path=self.local_path))
	
		tabs = tabs.replace('id="', 'id="bottom_')
	
		output.append("""
		%s
		<br /><hr />
		<div style="padding: 5px;">
			<input type="button" id="build_button" value="Create orders" onclick="build_orders();"/><br /><br />
			<strong>Complete orders</strong><br />
			<textarea id="final_output" style="width:99%%;" rows="20"></textarea>
		</div>""" % "")#tabs)
	
		output.append(common.footers())
		
		# Compress some output
		final_output = "".join(output)#.replace("	", "").replace("  ", " ").replace("	 ", " ")
		return final_output
Beispiel #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)
Beispiel #21
0
def make_ti(cursor, the_world, the_team, return_stats=False):
	the_stats = {}
	
	start_time = time.time()
	
	# Build team stats
	temp = time.time()
	stat_f.build_team_stats(cursor, the_team, the_world)
	
	# Get some properties
	the_team.get_population(cursor)
	the_stats['stats'] = time.time() - temp
	
	output = []
	
	# Tabs
	output.append(tabs(cursor, the_team))
	
	# Evolutions
	temp = time.time()
	output.append(evolutions(cursor, the_world, the_team))
	the_stats['evolutions'] = time.time() - temp
	
	# Deities
	temp = time.time()
	output.append(deities(cursor, the_world, the_team))
	# output.append(common.onload("switch_to_deities();"))
	the_stats['deities'] = time.time() - temp
	
	# Resources and points
	temp = time.time()
	output.append(resources(cursor, the_world, the_team))
	output.append(common.onload("switch_to_resources();"))
	the_stats['resources'] = time.time() - temp
	
	# Cities
	temp = time.time()
	output.append(cities(cursor, the_world, the_team))
	# output.append(common.onload("switch_to_cities();"))
	the_stats['cities'] = time.time() - temp
	
	# Units
	temp = time.time()
	temp = time.time()
	output.append(units(cursor, the_world, the_team))
	the_stats['units'] = time.time() - temp
	
	# Armies
	temp = time.time()
	output.append(armies(cursor, the_world, the_team))
	# output.append(common.onload("switch_to_armies();"))
	the_stats['armies'] = time.time() - temp
	
	# Operatives
	temp = time.time()
	output.append(operatives(cursor, the_world, the_team))
	# output.append(common.onload("switch_to_operatives();"))
	the_stats['operatives'] = time.time() - temp
	
	# Techs
	temp = time.time()
	output.append(techs(cursor, the_world, the_team))
	the_stats['techs'] = time.time() - temp
	
	# Spells
	temp = time.time()
	output.append(spells(cursor, the_world, the_team))
	the_stats['spells'] = time.time() - temp
	
	# Chosen
	temp = time.time()
	output.append(chosen(cursor, the_world, the_team))
	# output.append(common.onload("switch_to_chosen();"))
	the_stats['chosen'] = time.time() - temp
	
	# Diplomacy
	temp = time.time()
	output.append(diplomacy(cursor, the_world, the_team))
	# output.append(common.onload("switch_to_diplomacy();"))
	the_stats['diplomacy'] = time.time() - temp
	
	the_stats['total'] = time.time() - start_time
	
	# output.append(common.onload("switch_to_resources();"))
	
	return "".join(output)
Beispiel #22
0
		<td>%(x)s</td>
		<td>%(y)s</td>
		<td>&nbsp;</td>
	</tr>
	""" % {
		"count":	count%2,
		"name":		common.doubleclick_text("map_continents", "name", the_cont.id, the_cont.name, size=10),
		"x":		common.doubleclick_text("map_continents", "x", the_cont.id, the_cont.x, size=4),
		"y":		common.doubleclick_text("map_continents", "y", the_cont.id, the_cont.y, size=4),
	})

count += 1
output.append("""
	<tr class="row%(count)s">
		<form action="exec.py" method="post" accept-charset="utf-8">
			<input type="hidden" name="mode" value="add_continent" />
			<td style="padding:1px;"><input type="text" name="name" id="name" value="" /></td>
			<td style="padding:1px;" colspan="2"><input type="text" name="location" value="" /></td>
			<td><input type="submit" value="Add" /></td>
		</form>
		%(onload)s
	</tr>
""" % {
	"count":	count%2,
	"onload":	common.onload("$('#name').focus();"),
})


output.append("</table>")

print("".join(output))
Beispiel #23
0
def main(cursor):
	turn = int(common.get_val("turn", -1))
	
	if turn < 1:
		turn = common.current_turn()
	
	battle_dict	= battle_q.get_battles_from_turn(cursor, turn)
	teams_dict	= team_q.get_all_teams(cursor)
	
	output = []
	
	output.append("""
	<div style="padding: 5px;">
	
	<form action="web.py" method="get" accept-charset="utf-8">
		<a href="list_battles" style="text-align:left;" class="block_link">This turn's battles</a>
		<br />
		<input type="hidden" name="mode" id="mode" value="list_battles" />
		Turn: <input type="text" name="turn" value="%s" />
		&nbsp;&nbsp;&nbsp; <input type="submit" value="Show" />
	</form>
	<br /><br />""" % (turn))
	
	output.append("""<table border="0" cellspacing="0" cellpadding="5">
		<tr class="row2">
			<th>Turn</th>
			<th>Battle name</th>
			<th>Participants</th>
			<th>&nbsp;</th>
			<th>&nbsp;</th>
		</tr>
	""")
	
	count = -1
	for b, the_battle in battle_dict.items():
		participants = the_battle.get_participants(cursor)
		
		participants_list = []
		for t, s in participants.items():
			if s:
				participants_list.append("<em style='color:#555;'>%s</em>" % teams_dict[t].name)
			else:
				participants_list.append(teams_dict[t].name)
		
		count += 1
		
		output.append("""
		<tr class="row%(count)s">
			<td>%(turn)s</td>
			<td>%(name)s</td>
			<td>%(participants)s</td>
			<td style="padding:0px;"><a href="web.py?mode=edit_battle&amp;battle=%(battle_id)s" class="block_link">Edit</a></td>
			<td style="padding:0px;"><a href="view_battle&amp;battle=%(battle_id)s" class="block_link">View</a></td>
		</tr>
		""" % {
			"count":		count%2,
			"turn":			turn,
			"name":	the_battle.name,
			"participants":	", ".join(participants_list),
			"battle_id":	the_battle.id,
		})
	
	count += 1
	output.append("""
	<tr class="row%(count)s">
		<form action="exec.py" id="add_battle_form" method="post" accept-charset="utf-8">
		<input type="hidden" name="mode" id="mode" value="add_battle" />
		<td style="padding: 1px;"><input type="text" name="battle_turn" value="%(turn)s" size="5"/></td>
		<td style="padding: 1px;"><input type="text" name="name" id="name" value="" /></td>
		<td>&nbsp;</td>
		<td style="padding: 0px;" colspan="2"><a class="block_link" href="#" onclick="$('#add_battle_form').submit();">Add</a></td>
		</form>
		%(onload)s
	</tr>
	""" % {
		"turn":			turn,
		"count":		count%2,
		"onload":		common.onload("$('#name').focus();"),
	})
	
	output.append("</table></div>")
	
	return "".join(output)
Beispiel #24
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)
Beispiel #25
0
		"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();"),
		})


# New mission, team targets
count += 1
output.append("""
<tr class="row%(row)d">
	<form action="exec.py" id="add_mission_form_team" method="post" accept-charset="utf-8">
	<input type="hidden" name="mode" value="add_mission" />
	<td style="padding: 1px;">
		%(team)s
	</td>
	<td style="padding: 1px;">
		%(turn)s
	</td>
Beispiel #26
0
	def make_oh(self, team_id):
		the_team = self.the_world.teams()[team_id]
		
		output = [tabs]
		
		# loader_src = '../images/other/loading.gif'
		
		# output.append("""
		# <div id='loading_div' style='text-align:center;padding-top:20px;'>
		# 	Loading...
		# 	<br /><br />
		# 	<img src='%s'/>
		# </div>""" % loader_src)
		
		js_data	= []
		
		# CONSTRUCTION
		js_data.append(self.city_tab(the_team))
		
		# MILITARY - 498
		js_data.append(self.military_tab(the_team))
		
		# RESEARCH - 52
		js_data.append(self.research_tab(the_team))
		
		# OPERATIVES - 221
		js_data.append(self.operative_tab(the_team))
		
		# TRADE - 19
		js_data.append(self.trade_tab(the_team))
		
		# DIPLOMACY - 12
		js_data.append(self.diplomacy_tab(the_team))
		
		"""
		# ADVANCED
		additions = self.advanced_block(the_team)
		output.append(additions[0])
		load_java.append(additions[1])
		run_java.append(additions[2])
		
		# COMMANDS
		additions = self.command_block(the_team)
		output.append(additions[0])
		load_java.append(additions[1])
		run_java.append(additions[2])
		"""
		
		#	JAVASCRIPT
		#------------------------
		# javascript = oh_f.javascript
		javascript = ""
		
		
		if self.local_path:
			data_lib = 'http://woarl.com/data/oh_data.js'
			data_lib = 'oh_data.js'
		else:
			data_lib = '../data/oh_data.js'
		
		#	HEADER AND FOOTER
		#------------------------
		css = """
		.order_box, .order_box_half
		{
			border:1px solid #600;
			background-color:#FFEFEF;
			margin:10px 5px;
			padding:5px;
		}
		
		.order_box_half
		{
			width: 414px;
			float: left;
		}"""
		
		output.insert(0, common.headers(title_name="%s order creation form" % the_team.name, css=css, javascript=javascript, local_path=self.local_path))
		
		output.append(wrappers)
		
		output.append("""
		<div id='loading_div' style='text-align:center;padding-top:20px;'>
			Loading...
		</div>
		%s
		<br /><hr />
		<div style="padding: 5px;">
			<input type="button" id="build_button" value="Create orders" onclick="build_orders();"/><br /><br />
			<strong>Complete orders</strong><br />
			<textarea id="final_output" style="width:100%%;" rows="20"></textarea>
		</div>""" % tabs.replace('id="', 'id="bottom_'))
		
		# JS libs
		output.append("""
		<script type="text/javascript" charset="utf-8" src="%s"></script>
		<script type="text/javascript" charset="utf-8">
			%s
		</script>
		<script type="text/javascript" charset="utf-8" src="oh_new.js"></script>
		""" % (
			data_lib,
			"".join(js_data),
		))
		
		# And to get the ball rolling!
		output.append(common.onload("on_load_setup();"))
		
		output.append(common.footers())
		
		# Compress some output
		final_output = "".join(output)#.replace("	", "").replace("  ", " ").replace("	 ", " ")
		return final_output
Beispiel #27
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)
Beispiel #28
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)