示例#1
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)
示例#2
0
文件: team_f.py 项目: Teifion/Rob3
def get_upkeep(the_team, the_world):
	"""Returns the upkeep cost of the nation's army"""
	# We need to do this on a per-army basis now
	unit_dict = the_world.units()
	army_dict = the_world.armies()
	squad_dict = the_world.squads_from_team(the_team.id)
	city_dict = the_world.cities_from_team(the_team.id)
	
	the_world.mass_get_city_buildings()
	
	# 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
	
	military_upkeep = 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]
		
		# Don't wanna pay upkeep for units that are not ours!
		if the_unit.team != 0 and the_unit.team != the_team.id:
			continue
		
		# 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)
		
		# Upkeep override for things like magical affinity
		unit_cost = unit_rules.unit_upkeep_override(the_world, the_unit, unit_cost, the_team)
		
		# 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
		else:
			temp_cost *= military_rules.army_upkeep
		
		# Used for debugging
		if temp_cost > 0:
			pass
			# print "%s: %s * %s = %s<br />" % (unit_dict_c[unit_id].name, unit_cost, unit_count, temp_cost)
		
		# if the_army.name == "Kan Putri garrison":
		# 	print(the_squad.name, str(temp_cost), "<br />")
		
		military_upkeep += temp_cost
	
	# exit()
	
	# Now for buildings
	building_upkeep = 0
	# building_upkeep_dict = {}
	# for k, b in the_world.buildings().items():
	# 	building_upkeep_dict[k] = res_dict.Res_dict(b.upkeep)['Materials']
	# 
	# for city_id, the_city in city_dict.items():
	# 	for building_id, amount in the_city.buildings_amount.items():
	# 		building_upkeep += amount * building_upkeep_dict[building_id]
	
	# print str(the_team.resources), " - ", total_cost, "<br />"
	military_upkeep = team_rules.alter_upkeep(the_world.cursor, the_team, military_upkeep, the_world)
	return military_upkeep + building_upkeep