Пример #1
0
def units(cursor, the_world, the_team):
	unit_dict = the_world.units_from_team(the_team.id)
	special_unit_dict = the_world.units_from_team(0)
	monster_dict = the_world.monsters()
	
	the_team.get_units(cursor)
	
	output = []
	output.append('''<div class="ti_section" id="units_div">
	<table border="0" cellspacing="0" cellpadding="5" style="width:100%%;">
		<tr class="row2">
			<th>Amount</th>
			<th>Unit name</th>
			<th>Cost</th>
			<th>Equipment</th>
		</tr>''')
	
	unit_row = 	'''
		<tr class="row{count}">
			<td>{amount}</td>
			<td>{name}</td>
			<td>{cost}</td>
			<td>{equipment}</td>
		</tr>
		'''
	
	count = -1
	
	# Team units
	for u, the_unit in unit_dict.items():
		count += 1
		output.append(unit_row.format(
			count =		count%2,
			amount =	common.number_format(the_team.units.get(u, 0)),
			name =		the_unit.name,
			cost =		unit_rules.print_unit_cost(the_unit, cursor=cursor, the_world=the_world),
			equipment =	the_unit.equipment_string,
		))
	
	# Special units
	for u, the_unit in special_unit_dict.items():
		count += 1
		output.append(unit_row.format(
			count =		count%2,
			amount =	common.number_format(the_team.units.get(u, 0)),
			name =		the_unit.name,
			cost =		unit_rules.print_unit_cost(the_unit, cursor=cursor, the_world=the_world),
			equipment =	the_unit.equipment_string,
		))
	
	output.append('</table></div>')
	return "".join(output)
Пример #2
0
		<td>%(resources)s</td>
		<td>%(production)s</td>
		<td>%(army_size)s</td>
		<td>%(navy_size)s</td>
		<td>%(airforce_size)s</td>
		<td>%(operatives)s</td>
		<td>%(mages)s</td>
		<td>%(land_controlled)s</td>
		<td>%(city_count)s</td>
		<td>%(war_losses)s</td>
	</tr>
	""" % {
		"count":			i%2,
		"t":				t,
		"name":				the_team.name,
		"population":		common.number_format(the_stat.population),
		"slaves":			common.number_format(the_stat.slaves),
		"resources":		resources_string,
		"production":		production_string,
		"army_size":		common.number_format(the_stat.army_size),
		"navy_size":		common.number_format(the_stat.navy_size),
		"airforce_size":	common.number_format(the_stat.airforce_size),
		"operatives":		common.number_format(the_stat.operatives),
		"mages":			common.number_format(the_stat.mages),
		"land_controlled":	common.number_format(the_stat.land_controlled),
		"city_count":		common.number_format(the_stat.city_count),
		"war_losses":		common.number_format(the_stat.war_losses),
	})

output.append("</table>")
Пример #3
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)
Пример #4
0
def display_stat_table(cursor, team_id, list_size=10):
    # Get stats dict
    stat_dict = stat_q.get_stats_from_team(cursor, team_id)
    if len(stat_dict) < 1:
        return "The stats for team %d do not exist" % team_id

    teams_dict = team_q.get_all_teams(cursor)
    the_team = teams_dict[team_id]

    output = []

    output.append(
        """
	<div class="ti_section" id="overview_div">
	<table border="0" cellspacing="0" cellpadding="5" style="width:100%;">
		<tr class="row2">
			<th>Turn</th>
			<th>Population</th>
			<th>Slaves</th>
			<th>Resources</th>
			<th>Production</th>
			<th>Upkeep</th>
			<th>Army</th>
			<th>Navy</th>
			<th>Airforce</th>
			<th>Operatives</th>
			<th>Mages</th>
			<th>Land</th>
			<th>Cities</th>
			<th>Losses</th>
		</tr>"""
    )

    i = -1
    for k, the_stat in stat_dict.items():
        i += 1

        if i > list_size:
            continue

        # Currently
        the_res = res_dict.Res_dict(the_stat.resources)
        materials = the_res.get("Materials")
        if materials < 0:
            resources_string = '<strong class="neg">%s</strong>' % format(int(materials), ",")
        else:
            resources_string = format(int(materials), ",")

            # Production
        the_res = res_dict.Res_dict(the_stat.production)
        materials = the_res.get("Materials")
        if materials < 0:
            production_string = '<strong class="neg">%s</strong>' % format(int(materials), ",")
        else:
            production_string = format(int(materials), ",")

        output.append(
            """
		<tr class="row%(count)s">
			<td>Turn %(t)s</td>
			<td>%(population)s</td>
			<td>%(slaves)s</td>
			<td>%(resources)s</td>
			<td>%(production)s</td>
			<td>%(upkeep)s</td>
			<td>%(army_size)s</td>
			<td>%(navy_size)s</td>
			<td>%(airforce_size)s</td>
			<td>%(operatives)s</td>
			<td>%(mages)s</td>
			<td>%(land_controlled)s</td>
			<td>%(city_count)s</td>
			<td>%(war_losses)s</td>
		</tr>
		"""
            % {
                "count": i % 2,
                "t": the_stat.turn,
                "population": common.number_format(the_stat.population),
                "slaves": common.number_format(the_stat.slaves),
                "resources": resources_string,
                "production": production_string,
                "upkeep": common.number_format(int(the_stat.upkeep)),
                "army_size": common.number_format(the_stat.army_size),
                "navy_size": common.number_format(the_stat.navy_size),
                "airforce_size": common.number_format(the_stat.airforce_size),
                "operatives": common.number_format(the_stat.operatives),
                "mages": common.number_format(the_stat.mages),
                "land_controlled": common.number_format(the_stat.land_controlled),
                "city_count": common.number_format(the_stat.city_count),
                "war_losses": common.number_format(the_stat.war_losses),
            }
        )

    output.append("</table></div>")
    return "".join(output)
Пример #5
0
def draw_unit(the_battle, unit_count, unit_losses, the_unit, the_army, lookahead, row_count):
	output = []
	
	# Form JS
	form_js = """$('#ajax_target').load('web.py', {mode: 'add_army_loss', ajax: 'True', battle: %(battle_id)d, army: %(army_id)d, unit: %(unit_id)d, amount: $('#amount_for_%(army_id)d_%(unit_id)d').attr('value')}, function ()
	{
		var loss			= parseInt($('#amount_for_%(army_id)d_%(unit_id)d').attr('value').replace(',', ''));
		var current_loss	= parseInt($('#losses_%(army_id)d_%(unit_id)d').html().replace(',', ''));
		var current_amount	= parseInt($('#amount_%(army_id)d_%(unit_id)d').html().replace(',', ''));
		
		$('#amount_%(army_id)d_%(unit_id)d').html(current_amount - loss);
		$('#losses_%(army_id)d_%(unit_id)d').html(current_loss + loss);
		
		$('#amount_for_%(army_id)d_%(unit_id)d').attr('value', '');
		$('#amount_for_%(army_id)d_%(ahead)d').focus();
	});
	return false;""" % {
		"battle_id":	the_battle.id,
		"unit_id":		the_unit.id,
		"army_id":		the_army.id,
		"ahead":		lookahead,
	};
	
	return """
	<tr class="row{count}" id="row_{army_id}_{unit_id}">
		<td style='font-weight:bold;'>{unit_name}</td>

		<td>{weapon_cat}</td>
		<td>{armour_cat}</td>
		<td>{move_cat}</td>
		<td>{training_cat}</td>

		<td>{equipment}</td>
		<td>{total}</td>
		<td id="amount_{army_id}_{unit_id}">{amount}</td>
		<td id="losses_{army_id}_{unit_id}">{losses}</td>
		<td id="losses_cent_{army_id}_{unit_id}">{losses_cent}%</td>
		<td style="padding:1px;">
			<form action="web.py" method="post" id="" onsubmit="{form_js}" accept-charset="utf-8">
				<input type="hidden" name="mode" value="add_army_loss" />
				<input type="hidden" name="battle" value="{battle_id}" />
				<input type="hidden" name="unit" value="{unit_id}" />
				<input type="hidden" name="army" value="{army_id}" />
				<input type="text" onfocus="{on_focus}" onblur="{on_blur}" name="amount" id="amount_for_{army_id}_{unit_id}" value="" size="5"/>
			</form>
		</td>
	</tr>
	""".format(
		count		= row_count % 2,
		form_js		= form_js,
		army_id		= the_army.id,
		unit_id		= the_unit.id,
		unit_name	= the_unit.name,
		equipment	= the_unit.equipment_string,
		total		= common.number_format(unit_count.get(the_unit.id, 0) + unit_losses.get(the_unit.id, 0)),
		amount		= common.number_format(unit_count.get(the_unit.id, 0)),
		losses		= common.number_format(unit_losses.get(the_unit.id, 0)),
		losses_cent	= round(unit_losses.get(the_unit.id, 0)/(unit_count.get(the_unit.id, 0) + unit_losses.get(the_unit.id, 0))*100),
		battle_id	= the_battle.id,
		team_id		= the_army.team,
		# unit_id		= the_squad.unit,
		on_focus	= "$('#row_{0}_{1}').addClass('row3');".format(the_army.id, the_unit.id),
		on_blur		= "$('#row_{0}_{1}').removeClass('row3');".format(the_army.id, the_unit.id),
		
		weapon_cat		= "",
		armour_cat		= "",
		move_cat		= "",
		training_cat	= "",

		# xweapon_cat		= short_weapon_categories[unit_dict[unit_id].weapon_cat],
		# xarmour_cat		= short_armour_categories[unit_dict[unit_id].armour_cat],
		# xmove_cat		= short_move_categories[unit_dict[unit_id].move_cat],
		# xtraining_cat	= short_training_categories[unit_dict[unit_id].training_cat],
	)
Пример #6
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)
Пример #7
0
def main(cursor):
	# Get team Id
	team_id = int(common.get_val('team', 0))
	if team_id < 1: return "No team selected"
	
	# Build team item
	the_team = team_q.get_one_team(cursor, team_id)
	
	# Get some properties
	the_team.get_population(cursor)
	
	# Lists
	trait_dict = trait_q.get_all_traits(cursor)
	deity_dict = deity_q.get_all_deities(cursor)
	evolution_dict = evolution_q.get_all_evolutions(cursor)
	
	# Is the join turn set?
	if the_team.join_turn == 0:
		the_team.join_turn = common.current_turn()
	
	# First row of check_boxes
	output = ["<div style='padding: 5px;'>"]

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

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

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

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

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

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

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


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

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

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

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

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

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

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

	
	output.append("</div>")
	page_data['Title'] = "Edit team (%s)" % the_team.name
	return "".join(output)
Пример #8
0
	def draw_city(self, cursor, city_id):
		city_is_special = False
		
		# Handles
		the_city = self.city_dict[city_id]
		the_team = self.team_dict[the_city.team]
		
		team_clean_name = the_team.clean_name()
		
		# Test for 1 icon	
		image_size = map_data.map_image_size(the_city.size)
		if image_size == 0:
			return ""
		
		my_left		= (the_city.x - self.left) * 2.5 - (image_size/2.0)
		my_top		= (the_city.y - self.top) * 2.5 - (image_size/2.0)
		
		# Check it's within the picture size of the map
		if (the_city.x - image_size/2) < self.left:		return ""
		if (the_city.x + image_size/2) > self.right:	return ""
		
		if (the_city.y - image_size/2) < self.top:		return ""
		if (the_city.y + image_size/2) > self.bottom:	return ""
		
		#	Mouseover
		#------------------------
		# Name
		# clean_name = the_city.name.lower().replace(' ', '').replace("'", "")
		# clean_name = common.js_name(the_city.name.lower().replace(' ', '').replace("'", ''))
		clean_name = safe_re.sub("", the_city.name)
		# safe_re
		
		# Location
		city_x = the_city.x
		city_y = the_city.y
		
		if the_team.ir:
			city_title = ["<strong>Team</strong>: %s <span style='font-size:0.9em;'>(IR)</span><br />" % the_team.name]
		else:
			city_title = ["<strong>Team</strong>: %s<br />" % the_team.name]
		
		# Port
		if the_city.port == True:
			city_title.append('Is a port')
		else:
			city_title.append('Not a port')
		
		# Nomadic
		if the_city.nomadic == True:
			city_title.append('<br />Nomadic')
		
		# Walls
		team_logo = '%s_unwalled.png' % team_clean_name
		has_harbour_walls = False
		
		# Harbour walls id = 18
		if 18 in the_city.buildings_amount and the_city.buildings_amount[18] > 0:
			has_harbour_walls = True
			city_title.append('<br />Harbour walls')
		
		if the_city.walls != []:
			if len(the_city.walls) > 1:
				if has_harbour_walls:
					city_title.append('<br />%d walls' % (len(the_city.walls)-1))
				else:
					city_title.append('<br />%d walls' % len(the_city.walls))
			else:
				if not has_harbour_walls:
					city_title.append('<br />1 wall')
			team_logo = '%s_walled.png' % team_clean_name
		
		# Supply
		if the_city.supplies != []:
			supply_string = ", ".join([resource_list.data_list[s].name for s in the_city.supplies])
			city_title.append('<br />%s' % supply_string)
		
		# Terrain
		city_title.append('<br />Terrain type: %s' % map_data.terrain[mapper_q.get_terrain(cursor, city_x, city_y)].title())
		
		# Area - Used for debugging overlap
		# area = image_size/2.5
		# area = area * area
		# city_title.append("<br />Area: %s" % area)
		
		# Overlap
		if the_city.overlap > 0:
			city_title.append('<br />Overlap: %s%%' % the_city.overlap)
		
		# Population
		if the_city.team not in self.personalise:
			city_title.append('<br />Size: %s' % common.approx(the_city.size))
			if the_city.slaves > 0:
				city_title.append('<br />Slaves: %s' % common.approx(the_city.slaves))
		else:
			city_title.append('<br />Population: %s' % common.number_format(the_city.population))
			if the_city.slaves > 0:
				city_title.append('<br />Slaves: %s' % common.number_format(the_city.slaves))
		
		# Artefact
		artefact_count = 0
		if city_id in self.cities_with_artefact:
			for a, the_artefact in self.artefact_dict.items():
				if the_artefact.city == city_id:
					artefact_count += 1
					
		if artefact_count > 0:
			city_is_special = True
			if artefact_count > 1:
				city_title.append('<br /><strong>City contains %d artefacts</strong>' % artefact_count)
			else:
				city_title.append('<br /><strong>City contains an artefact</strong>')
		
		# Wonder
		if city_id in self.cities_with_wonder:
			for w, the_wonder in self.wonder_dict.items():
				if the_wonder.city == city_id:
					if the_wonder.completed:
						city_title.append('<br /><strong>City contains a wonder</strong>')
						city_is_special = True
					else:
						city_title.append('<br /><strong>City contains an uncompleted wonder</strong>')
		
		# Description
		if the_city.description != '':
			city_title.append('<br />%s' % the_city.description.replace("\\", ""))
		
		# GM stuff
		if self.gm:
			city_title.append('<br />Image size: %s' % image_size)
		
		# Info only for the team map
		if the_city.team in self.personalise:
			city_title.append("<br />")
			
			# Buildings?
			# in_progress_dict, city_buildings = the_city.get_buildings()
			
			walls		= []
			buildings	= []
			in_progress = []
			
			for b, a in the_city.buildings_amount.items():
				if self.building_dict[b].wall == True: walls.append(self.building_dict[b].name)
				if self.building_dict[b].wall != True: buildings.append(self.building_dict[b].name)
			
			for b, p in the_city.buildings.items():
				if p > 0:
					in_progress.append(self.building_dict[b].name)
			
			if len(buildings) > 0:
				city_title.append("<br /><strong>Buildings</strong>: %s" % ", ".join(buildings))
			
			if len(walls) > 0:
				city_title.append("<br /><strong>Walls</strong>: %s" % ", ".join(walls))
			
			if len(in_progress) > 0:
				city_title.append("<br /><strong>In progress</strong>: %s" % ", ".join(in_progress))
		
		if the_city.founded == common.current_turn():
			new_city_style = "border: 1px solid #FFA;"
			city_title.append("<br />Founded: <strong>Turn %d</strong>" % the_city.founded)
		elif city_is_special:
			# new_city_style = "border: 2px dotted #FFF;"
			new_city_style = ""
			team_logo = '%s_special.png' % team_clean_name
		else:
			new_city_style = ""
			city_title.append("<br />Founded: Turn %d" % the_city.founded)
		
		# Land controlled?
		# control = ""
		# if the_city.team in self.personalise:
		# 	control_image_size = map_control_size(the_city.size)
		# 	if control_image_size == 0:
		# 		return ""
		# 	
		# 	c_left		= (the_city.x - self.left) * 2.5 - (control_image_size/2.0)
		# 	c_top		= (the_city.y - self.top) * 2.5 - (control_image_size/2.0)
		# 	
		# 	control = """<img class="city_icon" src="%(icon_path)scontrol.png" style="top:%(top)spx; left: %(left)spx;" width="%(image_size)s" height="%(image_size)s" />""" % {
		# 		"icon_path":	self.icon_path,
		# 		"top":			c_top,
		# 		"left":			c_left,
		# 		"image_size":	control_image_size,
		# 	}
		
		# # Output - Function float
		# output = """<img class="city_icon" id="{0[clean_name]}" src="{0[icon_path]}{0[team_logo]}" style="top:{0[top]}px; left:{0[left]}px;" width="{0[image_size]}" height="{0[image_size]}" onmouseover="$('#{0[clean_name]}_hover').fadeIn(250);" onmouseout="$('#{0[clean_name]}_hover').hide(250);"/>""".format({
		# 	"icon_path":	self.icon_path,
		# 	"clean_name":	clean_name,
		# 	"top": my_top,
		# 	"left": my_left,
		# 	"image_size": image_size,
		# 	"team_logo": team_logo,
		# })
		
		# Output - Fixed float
		output = """<img class="city_icon" id="{clean_name}" src="{icon_path}{team_logo}" style="top:{top}px; left:{left}px;{new_city}" width="{image_size}" height="{image_size}" onmouseover="$('#{clean_name}_hover').fadeIn(250);" onmouseout="$('#{clean_name}_hover').hide(250);"/>""".format(
			icon_path =		self.icon_path,
			clean_name =	clean_name,
			top =			my_top,
			left =			my_left,
			image_size =	image_size,
			team_logo =		team_logo,
			new_city =		new_city_style,
		)
		
		if self.mouseover == 1:
			hover_top = my_top - 5
			hover_top = min(self.height*2.5 - 125, hover_top)
			
			hover_left = my_left + image_size + 20
			hover_left = max(hover_left, 5)
		
			if hover_left > ((self.width * 2.5) - 350):
				hover_left = my_left - 350
		
			# Floater
			self.append_last.append("""<div id="%(clean_name)s_hover" class="city_hover" style="top:%(hover_top)spx; left:%(hover_left)spx;"><div class="city_title">%(name)s&nbsp;&nbsp;&nbsp;%(city_x)s,%(city_y)s</div>%(city_title)s</div>""" % {
				"name": the_city.name,
				"clean_name": clean_name,
				"hover_top": hover_top,
				"hover_left": hover_left,
				"city_x": the_city.x,
				"city_y": the_city.y,
				"city_title": "".join(city_title),
			})
		
		# Now return it
		return "".join(output)
Пример #9
0
def main(cursor, battle_id=-1):
	battle_id = int(common.get_val('battle', battle_id))
	ships = int(common.get_val('ships', True))
	
	if battle_id < 1:
		return "No battle selected"
	
	the_battle = battle_q.get_one_battle(cursor, battle_id)
	
	# Get some other stuff
	team_dict		= team_q.get_all_teams(cursor)
	the_campaign	= campaign_q.get_one_campaign(cursor, the_battle.campaign)
	
	output = ["""	
	<div style='padding: 5px;'>
	<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={c.id}" class="block_link" style="display:inline;">Setup campaign</a>
	<a href="web.py?mode=list_battles&amp;campaign={c.id}" class="block_link" style="display:inline;">List battles</a>
	<a href="web.py?mode=setup_battle&amp;battle={b.id}" class="block_link" style="display:inline;">Setup battle</a>
	<a href="web.py?mode=perform_by_army&amp;battle={b.id}" class="block_link" style="display:inline;">By army</a>
	<br /><br />
	
	<span class="stitle">{c.name} - {b.name}</span> - <a href="web.py?mode=perform_battle&amp;battle={b.id}&amp;ships=0">No ships</a>
	
	<br />
	<a href="#" onclick="$('.show_evo_wedge').show(); $('.evo_wedge').hide(); return false;">Hide evo wedges</a>
	 - 
	<a href="#" onclick="$('.show_evo_wedge').hide(); $('.evo_wedge').show(); return false;">Show evo wedges</a>
	""".format(
		c = the_campaign,
		b = the_battle,
		turn = common.current_turn(),
	)]
	
	#	Now for some stuff about the participants
	#------------------------
	the_campaign.get_sides_basic(cursor)
	the_campaign.get_armies_basic(cursor)
	the_battle.get_losses(cursor)
	the_battle.get_squads(cursor)
	
	team_list = []
	for s in range(1, the_campaign.sides+1):
		for t in the_campaign.sides_basic[s]:
			team_list.append(t)
	
	unit_dict = unit_q.get_units_from_team_list(cursor, team_list, special_units=True)
	
	evolution_dict = evolution_q.get_all_evolutions(cursor)
	
	# Sort squads by team
	# Doing this makes it O(2n) rather than O(t*n)
	squad_dict = squad_q.get_squads_from_list(cursor, the_battle.squads)
	squads_by_team = {}
	
	for squad_id, the_squad in squad_dict.items():
		if the_squad.team not in squads_by_team: squads_by_team[the_squad.team] = []
		squads_by_team[the_squad.team].append(squad_id)
	
	for s in range(1, the_campaign.sides+1):
		teams_on_side = the_campaign.sides_basic[s]
		
		if len(teams_on_side) > 0:
			output.append('''<table border="1" cellspacing="0" cellpadding="5" width="100%">
			<tr>
				<td class="stitle" colspan="2">{s}</td>
			</tr>'''.format(s=s))
			
			for i, team_id in enumerate(teams_on_side):
				if team_id not in squads_by_team:
					squads_by_team[team_id] = []
				
				# Table tags for team cell
				if i % 2 == 0:	output.append('<tr><td>')
				else:			output.append('<td>')
				
				the_team = team_dict[team_id]
				
				# Team header
				output.append('''
				<span class="stitle">{name}</span>
				 - 
				<a href="web.py?mode=list_units&amp;team={id}">Military</a>
				 - 
				<a href="web.py?mode=list_armies&amp;team={id}">Armies</a>
				 - 
				<a href="#" onclick="$(this).parent().hide(); return false;">Hide</a>
				'''.format(
					name=the_team.name,
					id=team_id,
				))
				
				# Build dictionaries/lists
				team_units = the_team.get_units(cursor)
				total_count = {}
				unit_count = {}
				unit_losses = {}
				
				army_list = the_campaign.get_armies_from_team(cursor, team_id)
				army_dict = army_q.get_armies_from_list(cursor, army_list)
				squad_q.mass_get_squads(cursor, army_dict)
				
				# armies			= the_battle.get_armies()
				# squads			= the_battle.get_squads()
				transport_lost = 0
				transport_capacity = 0
				army_size = 0
				
				for unit_id in team_units.keys():
					unit_count[unit_id] = 0
					unit_losses[unit_id] = 0
				
				for squad_id in squads_by_team[team_id]:
					unit_count[squad_dict[squad_id].unit] += squad_dict[squad_id].amount
					army_size += squad_dict[squad_id].amount
					unit_losses[squad_dict[squad_id].unit] += the_battle.losses.get(squad_id, 0)
				
				
				# print("")
				# print(the_battle.squads, "<br />")
				# print(unit_count, "<br />")
				# print(unit_losses, "<br />")
				# exit()
				
				output.append("""
				<table border="0" cellspacing="0" cellpadding="5" style="width: 100%">
					<tr class="row2">
						<th>Unit</th>
						<th colspan="4">&nbsp;</th>
						<th>Equipment</th>
						<th>Total</th>
						<th>Amount</th>
						<th colspan="2">Losses</th>
						<th>&nbsp;</th>
					</tr>
				""")
				
				
				# Build look-ahead
				lookahead = {}
				last_unit = -1
				for unit_id in team_units.keys():
					if unit_dict[unit_id].type_cat == unit.categories.index("Ship") and ships == False:
						continue
					
					if unit_count[unit_id] == 0 and unit_losses[unit_id] == 0:
						continue
					
					lookahead[last_unit] = unit_id
					last_unit = unit_id
				lookahead[last_unit] = 0
				
				# Unit row
				team_losses = 0
				team_size = 0
				count = -1
				for unit_id, amount in team_units.items():
					if unit_dict[unit_id].type_cat == unit.categories.index("Ship") and ships == False:
						continue
					
					if unit_count[unit_id] == 0 and unit_losses[unit_id] == 0:
						continue
					
					count += 1
					team_losses += unit_losses[unit_id]
					team_size += unit_count[unit_id]
					transport_capacity += (unit_dict[unit_id].transport * unit_count[unit_id])
				
					# Form JS
					form_js = """$('#ajax_target').load('web.py', {mode: 'add_unit_loss', ajax: 'True', battle: %(battle_id)s, unit: %(unit_id)s, team: %(team_id)s, amount: $('#amount_for_%(unit_id)s_%(team_id)s').attr('value')}, function ()
					{
						var loss			= parseInt($('#amount_for_%(unit_id)s_%(team_id)s').attr('value').replace(',', ''));
						var current_loss	= parseInt($('#losses_%(unit_id)s_%(team_id)s').html().replace(',', ''));
						var current_amount	= parseInt($('#amount_%(unit_id)s_%(team_id)s').html().replace(',', ''));
				
						$('#amount_%(unit_id)s_%(team_id)s').html(current_amount - loss);
						$('#losses_%(unit_id)s_%(team_id)s').html(current_loss + loss);
				
						$('#amount_for_%(unit_id)s_%(team_id)s').attr('value', '');
						$('#amount_for_%(ahead)s_%(team_id)s').focus();
					});
					return false;""" % {
						"battle_id":	battle_id,
						"team_id":		team_id,
						"unit_id":		unit_id,
						"ahead":		lookahead[unit_id],
					};
				
					# function add_unit_amount_%(unit_id)s ()
					# {
					# 	$('#amountFor_team').removeAttr('value');
					# 	$('#spanAddUnitFor_team').load('ajax.php', {mode: 'getUnitsNotInWar', team: $team, war: $warId});
					# });
					
					output.append("""
					<tr class="row{count}" id="row_{team_id}_{unit_id}">
						<td style='font-weight:bold;'>{unit_name}</td>
						
						<td>{weapon_cat}</td>
						<td>{armour_cat}</td>
						<td>{move_cat}</td>
						<td>{training_cat}</td>
						
						<td>{equipment}</td>
						<td>{total}</td>
						<td id="amount_{unit_id}_{team_id}">{amount}</td>
						<td id="losses_{unit_id}_{team_id}">{losses}</td>
						<td id="losses_cent_{unit_id}_{team_id}">{losses_cent}%</td>
						<td style="padding:1px;">
							<form action="exec.pyy" method="post" id="" onsubmit="{form_js}" accept-charset="utf-8">
								<input type="hidden" name="mode" id="mode" value="add_unit_loss" />
								<input type="hidden" name="battle" id="battle" value="{battle_id}" />
								<input type="hidden" name="unit" id="unit" value="{unit_id}" />
								<input type="hidden" name="team" id="team" value="{team_id}" />
								<input type="text" onfocus="{on_focus}" onblur="{on_blur}" name="amount" id="amount_for_{unit_id}_{team_id}" value="" size="5"/>
							</form>
						</td>
					</tr>
					""".format(
						count =		count%2,
						form_js =	form_js,
						unit_name =	unit_dict[unit_id].name,
						equipment =	unit_dict[unit_id].equipment_string,
						total		= common.number_format(unit_count[unit_id] + unit_losses[unit_id]),
						amount =	common.number_format(unit_count[unit_id]),
						losses =	common.number_format(unit_losses[unit_id]),
						losses_cent = round(unit_losses[unit_id]/(unit_count[unit_id]+unit_losses[unit_id])*100),
						battle_id =	battle_id,
						team_id =	team_id,
						unit_id =	unit_id,
						on_focus =	"$('#row_{0}_{1}').addClass('row3');".format(team_id, unit_id),
						on_blur =	"$('#row_{0}_{1}').removeClass('row3');".format(team_id, unit_id),
						
						weapon_cat		= "",
						armour_cat		= "",
						move_cat		= "",
						training_cat	= "",
						
						# xweapon_cat		= short_weapon_categories[unit_dict[unit_id].weapon_cat],
						# xarmour_cat		= short_armour_categories[unit_dict[unit_id].armour_cat],
						# xmove_cat		= short_move_categories[unit_dict[unit_id].move_cat],
						# xtraining_cat	= short_training_categories[unit_dict[unit_id].training_cat],
					))
				
				# Size row
				if (team_size+team_losses) == 0:
					losses_cent = ""
				else:
					losses_cent = "%d%%" % round(team_losses/(team_size+team_losses)*100)
				
				count += 1
				output.append("""
				<tr class="row%(count)s">
					<td colspan="6">
						Military size:
					</td>
					<td>
						%(size)s
					</td>
					<td>
						%(losses)s
					</td>
					<td>
						%(losses_cent)s
					</td>
					<td colspan="3">&nbsp;</td>
				</tr>
				<tr class="row%(count_)s">
					<td colspan="6">Transport:</td>
					<td>%(transport_capacity)s</td>
					<td colspan="5">&nbsp;</td>
				</tr>
				""" % {
					"count":	count%2,
					"count_":	(count+1)%2,
					"size":		format(army_size, ','),
					"losses":	team_losses,
					"losses_cent": losses_cent,
					"transport_capacity":	format(transport_capacity, ','),
				})
				count += 1
				
				# Evos row
				evo_output = []
				
				the_team.get_evolutions(cursor)
				for evolution_id in the_team.evolutions:
					the_evo = evolution_dict[evolution_id]
				
					if the_team.evolutions[evolution_id] == 0: continue
					if not the_evo.combat_relevant: continue
				
				
					if the_evo.max_level == 1 and the_team.evolutions[evolution_id] == 1:
						evo_output.append("""<strong>%(evo_name)s</strong><br />""" % {
							"evo_name":	the_evo.name,
						})
					else:
						evo_output.append("""<strong>%(level)sx %(evo_name)s</strong><br />""" % {
							"level":	the_team.evolutions[evolution_id],
							"evo_name":	the_evo.name,
						})
				
				count += 1
				output.append("""
				<tr class="row%(count)s">
					<td colspan="11" style="padding:0px;">
						<div id="show_evos_%(team_id)s" style="display:nnone;" class="show_evo_wedge">
							<a href="#" class="block_link" onclick="$('#show_evos_%(team_id)s').hide(); $('#evos_%(team_id)s').fadeIn(250);return false;">Evos</a>
						</div>
						<div id="evos_%(team_id)s" style="display:none;" class="evo_wedge">
							<a href="#" class="block_link" onclick="$('#show_evos_%(team_id)s').fadeIn(250); $('#evos_%(team_id)s').hide(); return false;">Hide</a><br />
				
							%(evo_output)s
						</div>
					</td>
				</tr>
				""" % {
					"count":		count%2,
					"team_id":		team_id,
					"evo_output":	"".join(evo_output)
				})
				
				# End of team units
				output.append("</table>")
				
				
				# Table tags for team cell
				if i % 2 == 0:	output.append('</td>')
				else:			output.append('</td></tr>')
			
			# Not sure that we need to adhere to W3C specs for tables...
			# if i % 2 == 0:	output.append('<td>&nbsp;</td></tr>')
			
			output.append("</table><br />")
		else:
			output.append('No teams on side {s}'.format(s=s))
	
	# Field for the ids of the armies listed that we need to sort out
	# output.append('</table><br />')
	
	output.append("</div>")
	
	page_data['Title'] = "Perform by unit - %s" % the_battle.name
	return "".join(output)
Пример #10
0
def draw_squad(the_battle, unit_dict, the_squad, lookahead, row_count):
	output = []
	
	# if unit_dict[the_squad.unit].type_cat == unit.categories.index("Ship") and ships == False:
	# 	return ""
	
	if the_squad.amount == 0 and the_battle.losses[the_squad.id] == 0:
		return ""
	
	# team_losses += unit_losses[unit_id]
	# team_size += unit_count[unit_id]
	# transport_capacity += (unit_dict[unit_id].transport * unit_count[unit_id])
	
	# Form JS
	form_js = """$('#ajax_target').load('web.py', {mode: 'add_squad_loss', ajax: 'True', battle: %(battle_id)s, squad: %(squad_id)s, amount: $('#amount_for_%(squad_id)s').attr('value')}, function ()
	{
		var loss			= parseInt($('#amount_for_%(squad_id)s').attr('value').replace(',', ''));
		var current_loss	= parseInt($('#losses_%(squad_id)s').html().replace(',', ''));
		var current_amount	= parseInt($('#amount_%(squad_id)s').html().replace(',', ''));
		
		$('#amount_%(squad_id)s').html(current_amount - loss);
		$('#losses_%(squad_id)s').html(current_loss + loss);
		
		$('#amount_for_%(squad_id)s').attr('value', '');
		$('#amount_for_%(ahead)s').focus();
	});
	return false;""" % {
		"battle_id":	the_battle.id,
		"squad_id":		the_squad.id,
		"ahead":		lookahead,
	};

	# function add_unit_amount_%(unit_id)s ()
	# {
	# 	$('#amountFor_team').removeAttr('value');
	# 	$('#spanAddUnitFor_team').load('ajax.php', {mode: 'getUnitsNotInWar', team: $team, war: $warId});
	# });

	return """
	<tr class="row{count}" id="row_{squad_id}">
		<td style='font-weight:bold;'>{unit_name}: {squad_name}</td>

		<td>{weapon_cat}</td>
		<td>{armour_cat}</td>
		<td>{move_cat}</td>
		<td>{training_cat}</td>

		<td>{equipment}</td>
		<td>{total}</td>
		<td id="amount_{squad_id}">{amount}</td>
		<td id="losses_{squad_id}">{losses}</td>
		<td id="losses_cent_{squad_id}">{losses_cent}%</td>
		<td style="padding:1px;">
			<form action="web.py" method="post" id="" onsubmit="{form_js}" accept-charset="utf-8">
				<input type="hidden" name="mode" id="mode" value="add_squad_loss" />
				<input type="hidden" name="battle" id="battle" value="{battle_id}" />
				<input type="hidden" name="squad" id="squad" value="{squad_id}" />
				<input type="text" onfocus="{on_focus}" onblur="{on_blur}" name="amount" id="amount_for_{squad_id}" value="" size="5"/>
			</form>
		</td>
	</tr>
	""".format(
		count		= row_count % 2,
		form_js		= form_js,
		squad_id	= the_squad.id,
		squad_name	= the_squad.name,
		unit_name	= unit_dict[the_squad.unit].name,
		equipment	= unit_dict[the_squad.unit].equipment_string,
		total		= common.number_format(the_squad.amount + the_battle.losses.get(the_squad.id, 0)),
		amount		= common.number_format(the_squad.amount),
		losses		= common.number_format(the_battle.losses.get(the_squad.id, 0)),
		losses_cent	= round(the_battle.losses.get(the_squad.id, 0)/(the_squad.amount + the_battle.losses.get(the_squad.id, 0))*100),
		battle_id	= the_battle.id,
		team_id		= the_squad.team,
		# unit_id		= the_squad.unit,
		on_focus	= "$('#row_{0}').addClass('row3');".format(the_squad.id),
		on_blur		= "$('#row_{0}').removeClass('row3');".format(the_squad.id),
		
		weapon_cat		= "",
		armour_cat		= "",
		move_cat		= "",
		training_cat	= "",

		# xweapon_cat		= short_weapon_categories[unit_dict[unit_id].weapon_cat],
		# xarmour_cat		= short_armour_categories[unit_dict[unit_id].armour_cat],
		# xmove_cat		= short_move_categories[unit_dict[unit_id].move_cat],
		# xtraining_cat	= short_training_categories[unit_dict[unit_id].training_cat],
	)
Пример #11
0
				<td style="padding:1px;">
					<form action="exec.pyy" method="post" id="" onsubmit="%(form_js)s" accept-charset="utf-8">
						<input type="hidden" name="mode" id="mode" value="add_unit_loss" />
						<input type="hidden" name="battle" id="battle" value="%(battle_id)s" />
						<input type="hidden" name="unit" id="unit" value="%(unit_id)s" />
						<input type="hidden" name="team" id="team" value="%(team_id)s" />
						<input type="text" name="amount" id="amount_for_%(unit_id)s_%(team_id)s" value="" size="5"/>
					</form>
				</td>
			</tr>
			""" % {
                    "count": count % 2,
                    "form_js": form_js,
                    "name": unit_dict_c[unit_id].name,
                    "equipment": unit_dict_c[unit_id].equipment_string,
                    "amount": common.number_format(unit_count[unit_id]),
                    "losses": common.number_format(unit_losses[unit_id]),
                    "battle_id": battle_id,
                    "team_id": team_id,
                    "unit_id": unit_id,
                })

        # Size row
        count += 1
        output.append("""
		<tr class="row%(count)s">
			<td colspan="2">
				Military size:
			</td>
			<td colspan="3">
				%(size)s
Пример #12
0
def main(cursor):
	team_dict = team_q.get_real_active_teams(cursor)
	
	# Caching
	team_q.mass_get_team_resources(cursor, team_dict)
	
	# Defaults
	largest_army_id			= -1
	largest_army_size		= -1
	
	largest_navy_id			= -1
	largest_navy_size		= -1
	
	most_materials_id		= -1
	most_materials_size		= -1
	
	most_population_id		= -1
	most_population_size	= -1
	
	most_slaves_id			= -1
	most_slaves_size		= -1
	
	most_mages_id			= -1
	most_mages_size			= -1
	
	most_operatives_id		= -1
	most_operatives_size	= -1
	
	most_land_id			= -1
	most_land_size			= -1
	
	for t, the_team in team_dict.items():
		#	LARGEST ARMY?
		#------------------------
		size = team_q.get_army_size(cursor, the_team.id)
		if size > largest_army_size:
			largest_army_size	= size
			largest_army_id		= t
	
		#	LARGEST NAVY?
		#------------------------
		size = team_q.get_navy_size(cursor, the_team.id)
		if size > largest_navy_size:
			largest_navy_size	= size
			largest_navy_id		= t
		
		#	RICHEST NATION
		#------------------------
		if the_team.resources.get("Materials") > most_materials_size:
			most_materials_size	= the_team.resources.get("Materials")
			most_materials_id	= t
		
		#	LARGEST POPULATION
		#------------------------
		if the_team.get_population(cursor) > most_population_size:
			most_population_size	= the_team.get_population(cursor)
			most_population_id		= t
		
		#	MOST SLAVES
		#------------------------
		if the_team.get_slaves(cursor) > most_slaves_size:
			most_slaves_size	= the_team.get_slaves(cursor)
			most_slaves_id		= t
		
		#	MOST MAGES
		#------------------------
		size = team_q.get_mage_count(cursor, the_team.id)
		if size > most_mages_size:
			most_mages_size	= size
			most_mages_id	= t
		
		#	MOST OPERATIVES
		#------------------------
		if the_team.operative_count(cursor) > most_operatives_size:
			most_operatives_size	= the_team.operative_count(cursor)
		most_operatives_id	= t
	
		#	LAND CONTROLLED
		#------------------------
		stat_f.check_team_stats(cursor, the_team)
		team_stats = the_team.get_stats(cursor)
		
		if team_stats[common.current_turn()].land_controlled > most_land_size:
			most_land_size	= team_stats[common.current_turn()].land_controlled
			most_land_id	= t
	
	# Formatting
	largest_army_size = common.number_format(largest_army_size)
	largest_navy_size = common.number_format(largest_navy_size)
	
	most_materials_size = common.number_format(int(most_materials_size))
	
	most_population_size = common.number_format(most_population_size)
	most_slaves_size = common.number_format(most_slaves_size)
	
	most_mages_size = common.number_format(most_mages_size)
	most_operatives_size = common.number_format(most_operatives_size)
	
	most_land_size = round(most_land_size, 2)
	
	output = []
	the_world = world.World(cursor)
	for t, the_team in team_dict.items():
		output.append("\n\t%s" % the_team.name)
	
		# Military
		if largest_army_id == t: output.append("1: Largest army (%s)" % largest_army_size)
		if largest_navy_id == t: output.append("1: Largest navy (%s)" % largest_navy_size)
	
		# Resources
		if most_materials_id == t: output.append("1: Richest nation (%s)" % most_materials_size)
	
		produced_resources, new_resources = team_rules.produce_resources(cursor, the_team, the_world)
		
		if new_resources.get("Iron") > 0 and new_resources.get("Stone") > 0 and new_resources.get("Wood") > 0:
			output.append("2: Own a supply of each resource")
	
		# Population
		if most_population_id == t: output.append("1: Most population (%s)" % most_population_size)
		if most_slaves_id == t: output.append("1: Most slaves (%s)" % most_slaves_size)
	
		# Special units
		if most_mages_id == t: output.append("1: Most mages (%s)" % most_mages_size)
		if most_operatives_id == t: output.append("1: Most operatives (%s)" % most_operatives_size)
	
		# Land controlled
		if most_land_id == t: output.append("1: Most land controlled (%s)" % most_land_size)
	
		#	campaigns
		#------------------------
		campaign_dict = campaign_q.get_campaigns_from_team(cursor, t, include_secret=True, since_turn=common.current_turn()-4)
		
		team_war_count = 0
		team_campaign_dict = {}
		
		# if t == 71:
		# 	print("")
		# 	for k, v in campaign_dict.items():
		# 		print(v.name, " - ", v.turn, "<br />")
		
		if campaign_dict != ([], {}):
			for k, the_campaign in campaign_dict.items():
				team_campaign_dict[the_campaign.turn] = True
			
			if len(team_campaign_dict) == 1:
				output.append("1: Only one year with a war")
			
			elif len(team_campaign_dict) > 1:
				output.append("%s: %s years with wars" % (len(team_campaign_dict), len(team_campaign_dict)))
		
		
		
		# Roleplay?
		output.append("? 1: Good roleplay")
	
	return '&nbsp;<textarea rows="40" style="width:99%%;">%s</textarea>' % "\n".join(output)
Пример #13
0
def squad_block(oh, the_team, the_squad):
	output, load_java, run_java = [], [], []
	
	# unit_dict_c		= unit.get_unit_dict_c()
	# army_dict_c		= army.get_army_dict_c()
	# squad_dict_c	= squad.get_squad_dict_c()
	
	the_unit = oh.the_world.units()[the_squad.unit]
	the_army = oh.the_world.armies()[the_squad.army]
	
	if the_squad.amount <= 0:
		delete = '<label for="delete_squad_%d">Delete</label> <input type="checkbox" id="delete_squad_%d" value="del" />' % (the_squad.id, the_squad.id)
	else:
		delete = '<label for="disband_squad_%d">Disband</label> <input type="checkbox" id="disband_squad_%d" value="disb" />' % (the_squad.id, the_squad.id)
	
	output.append("""
	<tr>
		<td>%(name)s</td>
		<td>%(type)s</td>
		<td>%(amount)s</td>
		<td>%(amount_field)s</td>
		<td>%(delete)s</td>
	</tr>
	""" % {
		"id":		the_squad.id,
		"name":		'<input type="text" id="rename_squad_%d" value="%s" />' % (the_squad.id, the_squad.name),
		"type":		the_unit.name,
		"amount":	common.number_format(the_squad.amount),
		
		"amount_field": '<input type="text" id="squad_amount_%d" value="" size="7"/>' % the_squad.id,
		"delete":		delete,
		
		"merge_amount":		'<input type="text" id="merge_amount_%d" value="" size="7"/>' % the_squad.id,
	})
	
	run_java.append("""
	var temp_squad_amount = $('#squad_amount_%(id)d').val();
	var temp_delete_squad = $('#delete_squad_%(id)d').attr("checked");
	var temp_disband_squad = $('#disband_squad_%(id)d').attr("checked");
	
	if (temp_delete_squad)
	{
		squad_delete_orders += 'Delete squad: %(squad_name)s from %(army_name)s\\n';
	}
	else
	{
		if (temp_squad_amount != '')
		{
			if (temp_disband_squad)
			{
				temp_army_recruit_orders += 'Disband squad: %(squad_name)s, ' + temp_squad_amount + '\\n';
			}
			else
			{
				temp_army_recruit_orders += 'Reinforce squad: %(squad_name)s, ' + temp_squad_amount + '\\n';
			}
		}
	}
	
	var temp_squad_name = $('#rename_squad_%(id)d').val();
	var temp_squad_army = $('#move_field_%(id)d').val();
	
	if (temp_squad_name != '' && temp_squad_name != '%(squad_name)s')
	{
		squad_rename_orders += "\\nRename squad: %(squad_name)s in %(army_name)s, " + temp_squad_name;
	}
	""" % {
		"id":			the_squad.id,
		"squad_name":	common.js_name(the_squad.name),
		"army_name":	common.js_name(the_army.name),
	})
	
	return "".join(output), "".join(load_java), "".join(run_java)