예제 #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
파일: stat_f.py 프로젝트: Teifion/Rob3
def display_team_upkeep(cursor, the_world, team_id):
    output = []
    breakdown = {}
    sub_total = {}
    output.append(
        """
	<div class="ti_section" id="upkeep_div">"""
    )

    stat_f_amount = 0

    # Copy of function: team_f.get_upkeep
    the_team = the_world.teams()[team_id]
    unit_dict = the_world.units()
    army_dict = the_world.armies()
    squad_dict = the_world.squads_from_team(the_team.id)

    # Cache iron, makes it faster
    the_team.get_resources(the_world.cursor)  # force_requery=True)
    if the_team.resources.get("Iron") > 0:
        has_iron = True
    else:
        has_iron = False

    stat_f_amount = 0
    for squad_id, the_squad in squad_dict.items():
        if the_squad.amount < 1:
            continue

        the_unit = unit_dict[the_squad.unit]
        the_army = army_dict[the_squad.army]

        # Get Iron/Material cost
        if has_iron:
            unit_cost = the_unit.get_cost(cursor=the_world.cursor, the_world=the_world)["material_upkeep"].get(
                "Materials", 0
            )
        else:
            unit_cost = the_unit.get_cost(cursor=the_world.cursor, the_world=the_world)["iron_upkeep"].get(
                "Materials", 0
            )

            # Skip it if it's not got any upkeep
        if unit_cost <= 0:
            continue

            # If we haven't started on this army then lets start now!
        if the_squad.army not in breakdown:
            breakdown[the_squad.army] = ['<span class="stitle">%s</span><br />' % army_dict[the_squad.army].name]
            sub_total[the_squad.army] = 0

            # If it's a ship or airship we don't divide by the divisor
        if the_unit.type_cat == unit.categories.index("Ship") or the_unit.type_cat == unit.categories.index("Airship"):
            temp_cost = unit_cost * the_squad.amount
        else:
            temp_cost = unit_cost * the_squad.amount / military_rules.amount_divisor

            # Now we take into account the army type
        if the_army.garrison > 0:
            temp_cost *= military_rules.garrison_upkeep
            unit_cost *= military_rules.garrison_upkeep
        else:
            temp_cost *= military_rules.army_upkeep
            unit_cost *= military_rules.army_upkeep

        stat_f_amount += temp_cost

        # Break it down
        breakdown[the_squad.army].append(
            "{squad}: {amount} x {name} @ {price} = {cost}<br />".format(
                squad=the_squad.name, amount=the_squad.amount, name=the_unit.name, price=unit_cost, cost=temp_cost
            )
        )
        sub_total[the_squad.army] += temp_cost

    stat_f_amount = team_rules.alter_upkeep(the_world.cursor, the_team, stat_f_amount, the_world)

    # We need to confirm that the number we got here is the same as from the function
    team_f_amount = team_f.get_upkeep(the_world.teams()[team_id], the_world)

    if stat_f_amount != team_f_amount:
        output.append(
            '<span style="font-weight:bold;color:#F00;">There is an error in the workings: team_f = %d, stat_f = %d</span><br /><br />'
            % (team_f_amount, stat_f_amount)
        )

        # Now for the actual output
    if has_iron:
        output.append("Calcuated with Iron<br /><br />")
    else:
        output.append("Calcuated without Iron<br /><br />")

    for army_id, the_army in army_dict.items():
        if army_id in breakdown:
            output.append("".join(breakdown[army_id]))
            output.append("<strong>Sub total</strong>: %s<br /><br />" % sub_total[army_id])

    output.append("Grand total: %s" % stat_f_amount)

    output.append("</div>")
    return "".join(output)
예제 #5
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)
예제 #6
0
파일: team_t.py 프로젝트: Teifion/Rob3
	def test_get_upkeep(self):
		import database
		
		w = world.World(database.get_cursor())
		for team_id, the_team in w.active_teams().items():
			team_f.get_upkeep(the_team, w)