Example #1
0
def main(cursor):
	raise Exception("Thought to no longer be used")
	
	team_id = int(common.get_val("team", -1))
	
	if team_id < 1:
		return "<div style='padding: 5px;'>%s</div>" %  common.select_team_form(cursor, 'results')
	
	the_team = team_q.get_one_team(cursor, team_id)
	the_world = world.World(cursor)
	
	output = ['<div style="padding: 5px;">']
	output.append('<span class="stitle">%s results</span>' % the_team.name)
	output.append('<textarea name="results" id="results" rows="13" style="width: 100%;">')
	output.append(team_f.create_results_tail(the_world, the_team))
	output.append('</textarea>Previous results:')
	
	# Now to get the results for the last few turns
	# results_dict = results.get_results_by_team()
	# our_results_dict = results_dict.get(team_id, {})
	# 
	# for t in range(common.current_turn(),common.current_turn()-5,-1):
	# 	if t in our_results_dict:
	# 		output.append("""
	# 		<hr />
	# 		Turn: %d<br />
	# 		%s
	# 		""" % (t, common.bbcode_to_html(our_results_dict[t].strip())))
	
	output.append('<hr /></div>')
	return "".join(output)
Example #2
0
def main(cursor):
	team_id	= int(common.get_val('team', 0))
	build	= int(common.get_val('build', 0))
	
	if team_id < 1:
		return "<div style='padding: 5px;'>%s</div>" % common.select_team_form(cursor, 'team_map', ajax=1)
	
	return _draw_map(cursor, team_id, build)
Example #3
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)
Example #4
0
def main(cursor):
    team_id = int(common.get_val("team", 0))
    turn = int(common.get_val("turn", -1))

    if team_id < 1:
        return "<div style='padding: 5px;'>%s</div>" % common.select_team_form(cursor, "view_orders")

    if turn < 1:
        turn = common.current_turn()

    the_world = world.World(cursor)
    player_dict = the_world.players()

    the_team = team_q.get_one_team(cursor, team_id)
    the_orders = the_team.get_orders(cursor, the_world, "international", turn)

    # output = ["<div style='padding: 5px; font-size: 14px; line-height: 17px;'>"]
    output = ["<div style='padding: 5px;'>"]
    player_updates = {}

    for o in the_orders:
        player_updates[o.player] = o.team

        if o.content == "Orders placeholder":
            continue

        output.append(
            '<br /><hr />Post: <a href="http://woarl.com/board/viewtopic.php?p=%s#p%s">%s</a><br />'
            % (o.post_id, o.post_id, o.post_id)
        )
        output.append(
            'Poster: <a href="http://woarl.com/board/memberlist.php?mode=viewprofile&u=%d">%s</a> - '
            % (o.player, player_dict[o.player].name)
        )
        output.append('<a href="web.py?mode=edit_player&amp;player=%d">Local edit</a><br />' % (o.player))

        output.append(common.bbcode_to_html(o.content.replace('<span class="stitle">', '<hr /><span class="stitle">')))

    output.append("</div>")

    # Update player activity
    if turn == common.current_turn():
        database.query(cursor, player_f.update_player_activity(player_updates))

        # print "<br />".join(output)
    page_data["Title"] = "%s International orders" % the_team.name
    return "".join(output)
Example #5
0
def main(cursor):
	team_id		= int(common.get_val("team", 0))
	turn		= int(common.get_val("turn", -1))
	
	the_world = world.World(cursor)
	the_world.prep_for_orders()
	
	if team_id < 1:
		return "<div style='padding: 5px;'>%s</div>" %  common.select_team_form(cursor, 'view_orders')
	
	if turn < 1:
		turn = common.current_turn()
	
	# the_team = team_q.get_one_team(cursor, team_id)
	# the_team.get_resources(cursor)
	# the_team.get_spells(cursor)
	# the_team.get_techs(cursor)
	the_team = the_world.teams()[team_id]
	the_orders = the_team.get_orders(cursor, the_world, "normal", turn)
	
	output = ["<div style='padding:1px;'>"]
	player_updates = {}
	
	blocks = []
	for o in the_orders:
		o.split()
		blocks.extend(o.blocks)
	
	# Setup
	for b in blocks:
		b.setup()
	
	# Execution
	for b in blocks:
		b.execute()
	
	for b in blocks:
		# Player activity needs to get updated
		if turn == common.current_turn():
			player_updates[b.post.player] = b.post.team
		
		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>
			</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,
		))
	
	# output.append("""
	# Time taken: %(total)s<br /><br />
	# %(joined)s
	# """ % {
	# 	"total":	total_time,
	# 	"joined":	"<br />".join(time_list),
	# })
	# 
	# output.append("""
	# <a href="#" id="all_q_link" style="float: right; padding-right: 10px;" onclick="$('#all_q_div').load('web.py', {'ajax':'True','mode':'run_queries','subject':'Normal orders','queries':$('#all_q_text').val()}); $('#all_q_link').hide(); return false;">Run queries</a>
	# <br />
	# <textarea name="Name" id="Name" rows="8" style="width: 49%%;">%s</textarea>
	# <div style="float: right; width: 49%%; padding-right: 5px;" id="all_q_div">
	# 	<textarea id="all_q_text" name="Name" id="Name" rows="8" style="width: 100%%;">%s</textarea>
	# </div>
	# """ % ("\n".join(total_results), "\n".join(total_queries)))
	
	output.append("</div>")
	
	# Update player activity
	if turn == common.current_turn():
		database.query(cursor, player_f.update_player_activity(player_updates))
	
	page_data['Title'] = "%s normal orders" % the_team.name
	
	return "".join(output)
Example #6
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)
Example #7
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)
Example #8
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)
Example #9
0
def main(cursor):
	team_id = int(common.get_val('team', 0))
	confirm = int(common.get_val('confirm', 0))
	
	if team_id < 1:
		return "<div style='padding: 5px;'>{0}</div>".format(common.select_team_form(cursor, 'purge_team'))
	
	if confirm == 0:
		return """
		<form action="web.py" method="post" accept-charset="utf-8" style="padding: 10px;">
			<input type="hidden" name="mode" id="mode" value="purge_team" />
			<input type="hidden" name="team" id="team" value="{0}" />
			<input type="hidden" name="confirm" id="confirm" value="1" />
			Are you sure?<br /><br />
			<input type="submit" value="Purge team" />
		</form>
		""".format(team_id)
	
	# Query the DB for some info
	city_dict = city_q.get_cities_from_team(cursor, team_id, include_dead=True)
	army_dict = army_q.get_armies_from_team(cursor, team_id, include_garrisons=True)
	squad_dict = squad_q.get_squads_from_team(cursor, team_id)
	
	# Turn the dictionaries into lists
	city_list = [str(c) for c in city_dict]
	army_list = [str(a) for a in army_dict]
	squad_list = [str(s) for s in squad_dict]
	
	queries = []
	
	if len(army_list) > 0:
		# Wipe squads
		queries.append("DELETE FROM squads WHERE army IN (%s)" % ",".join(army_list))
		queries.append("DELETE FROM army_monsters WHERE army IN (%s)" % ",".join(army_list))
		queries.append("DELETE FROM campaign_armies WHERE army IN (%s)" % ",".join(army_list))
		
		# Wipe armies
		queries.append("DELETE FROM armies WHERE id IN (%s)" % ",".join(army_list))
	
	if len(city_list) > 0:
		# Wipe buildings
		queries.append("DELETE FROM city_buildings WHERE city IN (%s)" % ",".join(city_list))
		
		# Wipe garrisons
		# queries.append("DELETE FROM armies WHERE garrison IN (%s)" % ",".join(city_list))
		
		# Wipe cities
		queries.append("UPDATE operatives SET city = 0 WHERE city IN (%s)" % ",".join(city_list))
		queries.append("DELETE FROM cities WHERE id IN (%s)" % ",".join(city_list))
		
		# Wipe buildings
		queries.append("DELETE FROM city_buildings WHERE city IN (%s)" % ",".join(city_list))
	
	if len(squad_list) > 0:
		# Wipe squad battle history
		queries.append("DELETE FROM squad_battle_history WHERE squad IN (%s)" % ",".join(squad_list))
	
	# Operatives
	queries.append("DELETE FROM operatives WHERE team = %s" % team_id)
	
	# Spy reports
	queries.append("DELETE FROM spy_reports WHERE team = %s" % team_id)
	
	# Resources
	queries.append("UPDATE team_resources SET amount = 0 WHERE team = %d" % int(team_id))
	queries.append("UPDATE team_resources SET amount = 1500 WHERE team = %d AND resource = 0" % int(team_id))
	queries.append("UPDATE team_resources SET amount = 300 WHERE team = %d AND resource = 1" % int(team_id))
	
	database.query_batch(cursor, queries)
	
	
	return "<br />".join(queries)
Example #10
0
def main(cursor):
	team_id		= int(common.get_val("team", 0))
	turn		= int(common.get_val("turn", -1))
	
	turn = 81
	team_id = 83# Clan
	team_id = 71# Shrikes
	# team_id = 72# Daninia
	
	# Defaults
	if team_id < 1:
		return "<div style='padding: 5px;'>%s</div>" % common.select_team_form(cursor, 'view_orders')
	
	if turn < 1:
		turn = common.current_turn()
	
	# Build some handles
	the_world = world.World(cursor)
	player_dict = the_world.players()
	
	the_team = team_q.get_one_team(cursor, team_id)
	the_orders = the_team.get_orders(cursor, the_world, "international", turn)
	
	output = ["<div style='padding: 5px;'>"]
	player_updates = {}
	
	# Make sure we have the orders in place
	for o in the_orders:
		intorder_f.create_default(cursor, o)
	
	# Bulk get
	intorders = intorder_q.get_orders_from_posts(cursor, [o.post_id for o in the_orders])
	intorder_q.mass_get_parents(cursor, intorders)
	
	for i, o in intorders.items():
		# if o.parent.content == "Orders placeholder": continue
		
		sections = o.split()
		
		for s in sections:
			output.append("""
			<div class="intorder">
				<a href="http://woarl.com/board/memberlist.php?mode=viewprofile&amp;u={player.id}">{player.name}</a>:
				<a href="http://woarl.com/board/viewtopic.php?p={the_order.post_id}#p{the_order.post_id}">{the_order.post_id}</a>
				<br />
				
				{content}
			</div>""".format(
				intorder = o,
				player = player_dict[o.parent.player],
				the_order = o.parent,
				s = s,
				
				content = common.bbcode_to_html(s.content),
			))
		
		
		# output.append('<br /><hr />Post: <a href="http://woarl.com/board/viewtopic.php?p=%s#p%s">%s</a><br />' % (o.parent.post_id, o.parent.post_id, o.parent.post_id))
		# output.append('Poster: <a href="http://woarl.com/board/memberlist.php?mode=viewprofile&u=%s">%s</a><br />' % (o.parent.player, player_dict[o.parent.player].name))
		# 
		# output.append(common.bbcode_to_html(o.parent.content.replace('{SMILIES_PATH}', 'http://woarl.com/board/images/smilies')))
		# 
		# output.append(str(the_order.parent.topic))
		# output.append("<br />")
	
	output.append("</div>")
	
	# TODO update player activity
	
	# print "<br />".join(output)
	page_data['Title'] = "%s International orders" % the_team.name
	return "".join(output)
Example #11
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)
Example #12
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)