예제 #1
0
	def major():
		upkeep = team_f.get_upkeep(the_team, the_world)
		income = team_rules.produce_resources(the_world.cursor, the_team, the_world)[0].get("Materials")
		
		if income == 0:
			percentage = 100
		else:
			percentage = round(upkeep/float(income)*100, 2)
		
		if income <= (upkeep * 4):
			info.append("<span class='pos'>Major:</span> Your military upkeep is at least 25%% of your income (%s%%)" % percentage)
			return favour_rewards["major_pos"]
		else:
			info.append("<span class='neg'>Major:</span> Your military upkeep is less that 25%% of your income (%s%%)" % percentage)
			return favour_rewards["major_neg"]
예제 #2
0
파일: stat_f.py 프로젝트: Teifion/Rob3
def build_team_stats(cursor, the_team, the_world=None):
    current_turn = common.current_turn()

    the_stat = stat.Stat()

    # 	Primary keys
    # ------------------------
    the_stat.turn = current_turn
    the_stat.team = the_team.id

    # 	Team population and slaves
    # ------------------------
    the_stat.population = the_team.get_population(cursor)
    the_stat.slaves = the_team.get_slaves(cursor)

    # 	Resources
    # ------------------------
    the_stat.resources = the_team.get_resources(cursor).as_db_string()
    the_stat.upkeep = float(team_f.get_upkeep(the_team, the_world))
    the_stat.production = team_rules.produce_resources(cursor, the_team, the_world=the_world)[0].as_db_string()

    # 	Military stuff
    # ------------------------
    the_stat.army_size = team_q.get_army_size(cursor, the_team.id)
    the_stat.navy_size = team_q.get_navy_size(cursor, the_team.id)
    the_stat.airforce_size = team_q.get_airforce_size(cursor, the_team.id)

    # 	Solo units
    # ------------------------
    the_stat.operatives = the_team.operative_count(cursor)
    the_stat.mages = team_q.get_mage_count(cursor, the_team.id)

    # 	Other
    # ------------------------
    the_stat.land_controlled = len(mapper_f.team_influence(the_world, the_team.id))

    the_stat.city_count = len(city_q.get_cities_from_team(cursor, the_team.id))
    the_stat.war_losses = battle_q.get_team_losses(cursor, the_team.id)

    # 	Specifics
    # ------------------------
    # the_stat.temple_count		= stat_q.get_temple_count(cursor, the_team.id)

    # Delete (to allow insert)
    delete_stat(cursor, the_team.id, current_turn)

    # Insert
    insert_stat(cursor, the_stat)
예제 #3
0
파일: ti_j.py 프로젝트: Teifion/Rob3
def resources(the_world, the_team):
	output = {
		"current":		{},
		"produce":		{},
		"upkeep":		{},
		"availiable":	{},
	}
	
	# We need to do this to predict them correctly
	team_resources = the_team.get_resources(the_world.cursor, force_requery=False)
	produced_resources, new_resources = team_rules.produce_resources(the_world.cursor, the_team, the_world, force_requery=False)
	
	# Now we repeat this to display the current amounts correctly
	the_team.resources = team_resources
	
	count = -1
	for res_id, the_res in enumerate(resource_list.data_list):
		if res_id not in the_team.resources.value:
			the_team.resources.value[res_id] = 0
		
		# If all of them are 0 then there's no need to show it
		if the_team.resources.value[res_id] == 0:
			if produced_resources.get(res_id) == 0:
				if new_resources.get(res_id) == 0:
					continue
		
		if the_res.name == "Materials":
			upkeep_amount = int(team_f.get_upkeep(the_team, the_world))
			future_amount = int(new_resources.value[res_id]-int(upkeep_amount))
			
		elif the_res.name == "Food":
			upkeep_amount = team_rules.resource_needed(the_world.cursor, "Food", the_team)
			upkeep_amount = round(upkeep_amount, 2)
			future_amount = int(new_resources.value[res_id]-int(upkeep_amount))
			
			upkeep_amount = int(upkeep_amount)
		else:
			upkeep_amount = ""
			future_amount = int(new_resources.value[res_id])
		
		output['current'][res_id]		= int(the_team.resources.value.get(res_id, 0))
		output['produce'][res_id]		= int(produced_resources.value.get(res_id, 0))
		output['upkeep'][res_id]		= upkeep_amount
		output['availiable'][res_id]	= future_amount
	
	return output
예제 #4
0
파일: test_orders.py 프로젝트: Teifion/Rob3
def main(cursor):
	team_id		= int(common.get_val("team", 0))
	orders_str	= common.get_val("orders", "")#.replace("’", "'")
	msn_mode	= int(common.get_val("msn_mode", 0))
	
	if team_id < 1 or orders_str == "":
		return """
		<div style='padding: 5px;'>
			<form action="web.py" id="select_team_form" method="post" accept-charset="utf-8">
				<input type="hidden" name="mode" id="mode" value="test_orders" />
				<label for="msn_mode">MSN mode:</label> <input type="checkbox" id="msn_mode" name="msn_mode" value="1" />
				Team: %s
				<!--
				<a class="block_link" href="#" onclick="$('#select_team_form').submit(); return false;">Run orders</a>
				-->
				<input type="submit" value="Run orders" />
				<br />
				<textarea name="orders" rows="8" style="width: 100%%;">[o]Rob command[/o]
Enable: Overbudget

</textarea>
			</form>
		</div>%s""" % (
			team_f.structured_list(cursor, field_id="team"),
			common.onload("$('#team').focus();"),
		)
	
	the_world = world.World(cursor)
	the_world.prep_for_orders()
	
	the_team = the_world.teams()[team_id]
	produced_resources, new_resources = team_rules.produce_resources(cursor, the_team, the_world, force_requery=True)
	the_team.resources = new_resources
	blocks = request_f.convert_orders(the_world, the_team, orders_str)
	
	output = ["<div style='padding:1px;'>"]
	
	output.append("Running with resources: %s" % str(the_team.resources))
	
	# Setup
	for b in blocks:
		b.setup(msn_order=msn_mode)
	
	# Execution
	for b in blocks:
		b.execute()
	
	debug = []
	for i, b in enumerate(blocks):
		# if b.cost.as_string() != "":
		# 	b.results = b.results.replace("{COST}", " - [neg]Cost: %s[/neg]" % b.cost.as_string())
		# else:
		# 	b.results = b.results.replace("{COST}", "")
		# 
		# # Trade queries are done differently
		# if b.order_type != "trades":
		# 	total_queries.append(b.queries)
		# 	total_results.append(b.results.strip())
		# 	total_results.append("")# To create a gap
		
		if len(b.debug) > 1:
			debug.append(b.debug[0])
			debug.append("\n---\n".join(b.debug[1:len(b.debug)]))
		
		output.append("""
		<div class="orders" style="border-color:{border};background-color:{background};">
			<strong>{title}</strong>: {cost}<br />
			{response}
			<br />
			
			<div style="float: left; width: 50%;">
				<textarea rows="6" style="float:left;width:99%;">{results}</textarea>
			</div>
			
			<div style="float: left; width: 50%;">
				<textarea rows="6" style="float:right;width:99%;">{queries}</textarea>
				<br />
				<a href="web.py?mode=direct_query">Direct query</a>
			</div>
			<div style="clear: left;">
				&nbsp;
			</div>
		</div>
		""".format(
			title		= b.title_name,
			cost		= str(b.cost),
			response	= common.bbcode_to_html("<br />".join(b.input_response)),
			results		= "\n".join(b.results),
			queries		= "\n".join(b.queries),
			
			border		= b.border_colour,
			background	= b.background_colour,
		))
	
	if debug != []:
		output.insert(2, '<br /><strong>Debug:</strong><br /><textarea name="debug" id="debug" rows="6" cols="80">%s</textarea><br />' % "".join(debug))
	
	output.append("Finishing with resources: %s" % str(the_team.resources))
	output.append("</div>")
	
	return "".join(output)
예제 #5
0
파일: request_f.py 프로젝트: Teifion/Rob3
def msn_run_orders(cursor, team_id):
	the_team = team_q.get_one_team(cursor, team_id)
	
	# Get orders
	getter_data = "p=%s&mode=latest_rr&topic=%s" % (common.data['getterPass'], the_team.request_topic)
	orders_str = urllib.request.urlopen(common.data['getter_url'], getter_data).read().strip()
	# print(common.data['getter_url'], getter_data)
	# return orders_str.decode('utf-8')
	
# 	orders_str = b"""-POST_SEPERATOR-                                                                                                                                                                             
# -START OF POST-
# post id:48143
# poster id:2
# -START OF ORDER 48143-
# 
# [o]Construction[/o]
# Build 25k Fortifications at Ashkar
# Build Border forts at Candor
# 
# [o]Military[/o]
# 
# Select army: Expeditionary fleet
# Reinforce squad: the Divine Wind, 100
# 
# [o]Research[/o]
# Architecture
# Covert training
# Dazzle
# Fireball
# 
# -END OF ORDER 48143-
# -END OF POST-
# """
	
	orders_str = orders_str.decode('utf-8')
	orders_str = re.sub(r'-END OF ORDER [0-9]*-', '', orders_str)
	orders_str = orders_str.replace('-END OF POST-', '')
	
	# Prep world
	the_world = world.World(cursor)
	the_world.prep_for_orders()
	
	the_team = the_world.teams()[team_id]
	produced_resources, new_resources = team_rules.produce_resources(cursor, the_team, the_world, force_requery=True)
	the_team.resources = new_resources
	
	blocks = convert_orders(the_world, the_team, orders_str)
	output = []
	
	# Setup
	for b in blocks:
		b.setup(msn_order=True)
	
	# Execution
	for b in blocks:
		b.execute()
	
	for b in blocks:
		output.append("""
[o]{name}[/o]
{input}\n
[fullbox={background},{border}]{results}[/fullbox]
""".format(
			name=b.title_name,
			cost=str(b.cost),
			input="\n".join(b.input_response).strip(),
			results="\n".join(b.results).strip(),
			background=b.background_colour,
			border=b.border_colour,
		))
	
	# return "".join(output)
	post_request_result(the_team, "".join(output))
	return "Orders run (%s)" % the_team.name
예제 #6
0
파일: ti_f.py 프로젝트: Teifion/Rob3
def resources(cursor, the_world, the_team):
	output = []
	
	# We need to do this to predict them correctly
	# TODO Confirm that this does/does not need to be force_requery
	team_resources = the_team.get_resources(cursor, force_requery=False)
	
	produced_resources, new_resources = team_rules.produce_resources(cursor, the_team, the_world, force_requery=False)
	
	# Now we repeat this to display the current amounts correctly
	the_team.resources = team_resources
	
	output.append('''<div class="ti_section" id="resources_div">
	<table border="0" cellspacing="0" cellpadding="5">
		<tr class="row2">
			<th>Resource</th>
			<th>Currently availiable</th>
			<th>Production</th>
			<th>Upkeep</th>
			<th>Predicted to be availiable</th>
		</tr>''')
	
	count = -1
	for res_id, the_res in enumerate(resource_list.data_list):
		if res_id not in the_team.resources.value:
			the_team.resources.value[res_id] = 0
		
		# If all of them are 0 then there's no need to show it
		if the_team.resources.value[res_id] == 0:
			if produced_resources.get(res_id) == 0:
				if new_resources.get(res_id) == 0:
					continue
		
		if the_res.name == "Materials":
			upkeep_amount = int(team_f.get_upkeep(the_team, the_world))
			future_amount = int(new_resources.value[res_id]-int(upkeep_amount))
			
		elif the_res.name == "Food":
			upkeep_amount = team_rules.resource_needed(cursor, "Food", the_team)
			upkeep_amount = round(upkeep_amount, 2)
			future_amount = int(new_resources.value[res_id]-int(upkeep_amount))
			
			upkeep_amount = int(upkeep_amount)
		else:
			upkeep_amount = ""
			future_amount = int(new_resources.value[res_id])
		
		count += 1
		output.append('''
		<tr class="row%(count)s">
			<td>%(resource_name)s</td>
			<td>%(current_amount)s</td>
			<td>%(produce_amount)s</td>
			<td>%(upkeep_amount)s</td>
			<td>%(future_amount)s</td>
		</tr>
		''' % {
			"count":			count%2,
			"resource_name":	the_res.name,
			"current_amount":	int(the_team.resources.value.get(res_id, 0)),
			"produce_amount":	int(produced_resources.value.get(res_id, 0)),
			"upkeep_amount":	upkeep_amount,
			"future_amount":	future_amount,
		})
	
	output.append('</table></div>')
	return "".join(output)
예제 #7
0
파일: evo_points.py 프로젝트: Teifion/Rob3
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)