Exemple #1
0
def operatives(the_world, the_team):
	city_dict = the_world.cities()
	team_dict = the_world.teams()
	
	operatives_dict	= the_world.operatives_from_team(the_team.id)
	reports_dict = {}
	
	if len(operatives_dict) <= 0 and len(reports_dict) <= 0:
		return {}
	
	# Starting the output
	output = {}
	
	# Caught ops
	caught_ops = operative_q.operatives_caught_in_cities(
		the_world.cursor,
		the_world.cities_from_team(the_team.id),
		since=common.current_turn()-3,
	)
	
	if len(caught_ops) > 0:
		for k, the_op in caught_ops.items():
			output[k] = {
				"op_id":	k,
				"name":		the_op.name,
				"team":		the_op.team,
				"city":		the_op.city,
				"caught":	the_op.died,
			}
	
	for o, the_op in operatives_dict.items():
		output[o] = {
			"op_id":	o,
			"name":		the_op.name,
			"team":		the_op.team,
			"city":		the_op.city,
			"caught":	the_op.died,
			
			"size":				the_op.size,
			"arrival":			the_op.arrival,
			"stealth":			the_op.stealth,
			"observation":		the_op.observation,
			"integration":		the_op.integration,
			"sedition":			the_op.sedition,
			"sabotage":			the_op.sabotage,
			"assassination":	the_op.assassination,
		}
	
	return output
Exemple #2
0
def operatives(cursor, the_world, the_team):
	city_dict = the_world.cities()
	team_dict = the_world.teams()
	
	operatives_dict	= the_world.operatives_from_team(the_team.id)
	
	# reports_dict	= spy_report_q.get_reports_from_team(cursor, the_team.id, common.current_turn()-3)
	reports_dict = {}
	
	if len(operatives_dict) <= 0 and len(reports_dict) <= 0:
		return '<div class="ti_section" id="operatives_div">You have no operatives and no spy reports</div>'
	
	# Location stuff
	team_location = {}
	for o, the_op in operatives_dict.items():
		if the_op.died > 0: continue
		
		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)
	
	# Overview numbers
	city_set = set()
	city_count = {}
	operative_count = 0
	recent_deaths = 0
	for operative_id, the_operative in operatives_dict.items():
		if the_operative.died > 0:
			if common.current_turn() - the_operative.died < 3:
				recent_deaths += 1
			continue
		
		city_set.add(the_operative.city)
		
		if the_operative.city not in city_count:
			city_count[the_operative.city] = 0
		
		city_count[the_operative.city] += 1
		operative_count += 1
	
	# Starting the output
	output = []
	output.append('<div class="ti_section" id="operatives_div">')
	
	output.append("""
	You have %s spies spread across %s cities. You have lost %s spies in the last 3 turns.<br /><br />""" % (operative_count, len(city_set), recent_deaths))
	
	spies_out		= []
	couterspies_out	= []
	for city_id, op_count in city_count.items():
		if city_id < 1: continue
		the_city = city_dict[city_id]
		
		if the_city.team == the_team.id:
			couterspies_out.append("""<li>%s at %s</li>""" % (op_count, city_dict[city_id].name))
		else:
			spies_out.append("""<li>%s at %s</li>""" % (op_count, city_dict[city_id].name))
	
	
	# Caught ops
	caught_ops = operative_q.operatives_caught_in_cities(
		cursor,
		the_world.cities_from_team(the_team.id),
		since=common.current_turn()-3,
	)
	
	if len(caught_ops) == 0:
		output.append("<strong>You have caught no spies in the last 3 years</strong>")
	else:
		output.append("<strong>You caught the following spies in the last 3 years:</strong>")
		
		for k, the_op in caught_ops.items():
			output.append("<br />{name} (found in {city}) from {team}, caught in turn {turn}".format(
				name=the_op.name,
				city=city_dict[the_op.city].name,
				team=team_dict[the_op.team].name,
				turn=the_op.died,
			))
		
	output.append("<br /><br />")
		
		# <table border="0" cellspacing="0" cellpadding="5">
		# 	<tr>
		# 		<th>Counterspies</th>
		# 		<th width="100">&nbsp;</th>
		# 		<th>Spies</th>
		# 	</tr>
		# 	<tr>
		# 		<td><ul>%(counterspies)s</ul></td>
		# 		<td width="100">&nbsp;</td>
		# 		<td><ul>%(spies)s</ul></td>
		# 	</tr>
		# </table><br />
		# """ % {
		# 	"counterspies":	"".join(couterspies_out),
		# 	"spies":		"".join(spies_out),
		# })
		
	
	# Operatives overview
	if len(operatives_dict) <= 0:
		output.append("You have no operatives")
	else:
		output.append("""<table border="0" cellspacing="0" cellpadding="5">
			<tr>
				<th>Counterspies</th>
				<th width="100">&nbsp;</th>
				<th>Spies</th>
			</tr>
			<tr>
				<td><ul>%(counterspies)s</ul></td>
				<td width="100">&nbsp;</td>
				<td><ul>%(spies)s</ul></td>
			</tr>
		</table><br />
		""" % {
			"counterspies":	"".join(couterspies_out),
			"spies":		"".join(spies_out),
		})
	
	# Op list
	if len(operatives_dict) > 0:
		output.append("""
		<div style="" id="op_table_link">
			<a href="#" onclick="$('#op_table_link').hide();$('#op_table').show();return false;" class="block_link">Show all operatives</a>
		</div>
		<table border="0" cellspacing="0" cellpadding="5" style="width: 100%; display:none;" id="op_table">
			<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>
			</tr>""")
	
		count = -1
	
		for city_team, op_list in team_location.items():
			for operative_id in op_list:
				the_operative = operatives_dict[operative_id]
			
				count += 1
			
				output.append("""
				<tr class="row{row}" id="op_{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>
				</tr>
				""".format(
						row = (count % 2),
						
						operative_id	= operative_id,
						name		= the_operative.name,
						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,
			))
	
		output.append('</table>')
	output.append('</div>')
	return "".join(output)