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
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)
def main(cursor): show_dead_teams = common.get_val('show_dead') show_unqueued_teams = common.get_val('show_unqueued') # Get the turn we'll want to get stuff for current_turn = common.current_turn() # Get our list team_dict = team_q.get_real_active_teams(cursor, skip_irs=True) output = [] output.append(""" <table border="0" cellspacing="0" cellpadding="5"> <tr class="row2"> <th>Team</th> <th>Materials</th> <th>Food</th> <th>Morale</th> </tr>""") count = -1 for team_id, the_team in team_dict.items(): count += 1 team_res = the_team.get_resources(cursor) # TODO - Make it work out the material requirements correctly # Materials material_amount = int(team_res.get("Materials")) if material_amount < 0: material_style = "background-color:#AAA;color:#A00; font-weight:bold;" if material_amount < -200: material_style = "background-color:#000;color:#F00; font-weight:bold;" else: material_style = "" # Food food_amount = int(team_res.get("Food")) needed = team_rules.resource_needed(cursor, "Food", the_team) food_ratio = round(food_amount/float(needed), 2) if food_ratio < 1: food_style = "background-color:#AAA;color:#A00; font-weight:bold;" if food_ratio < 0.75: food_style = "background-color:#000;color:#F00; font-weight:bold;" else: food_style = "" if food_ratio > 1.5: food_style = "background-color:#AFA;color:#000; font-weight:bold;" output.append(""" <tr class="row%(row)d" id="%(team_id)d"> <td>%(name)s</td> <td style="%(material_style)s">%(materials)s</td> <td style="%(food_style)s">%(food)s</td> <td>%(morale)s</td> </tr> """ % { 'row': (count % 2), 'board_url': common.data['board_url'], 'team_id': the_team.id, 'name': the_team.name, "materials": material_amount, "material_style": material_style, "food": food_ratio, "food_style": food_style, "morale": team_rules.define_nation_morale(team_rules.nation_morale(cursor, the_team)), }) output.append("</table>") return "".join(output)
def get_happiness(w, the_city, with_breakdown=False): trait_lookup = w.traits_lookup() building_lookup = w.buildings_lookup() w.mass_get_team_traits() w.mass_get_team_deities() w.mass_get_city_buildings() w.mass_get_campaign_teams() w.mass_get_army_squads() w.mass_get_team_resources() kills = w.kills_from_turn(common.current_turn()) the_team = w._teams[the_city.team] campaign_dict = w.campaigns() army_dict = w.armies() recent_campaigns = w.recent_campaigns(5) relevant_recent_campaigns = [] for c in recent_campaigns: if the_city.team in campaign_dict[c].teams: relevant_recent_campaigns.append(c) # Base happiness breakdown = [] breakdown.append("+%d basic happiness" % happiness_bonuses["Basic"]) result = happiness_bonuses["Basic"] # Overcrowding if int(the_city.population / 10000) > 0: breakdown.append("-%d for population size" % int(the_city.population / 10000)) result -= int(the_city.population / 10000) # Minus 1 happiness for every war year of war past 2 in the last 5 if trait_lookup["Warlike"] not in the_team.traits: if len(relevant_recent_campaigns) > happiness_bonuses["Allowed wars"]: war_count = (len(relevant_recent_campaigns) - happiness_bonuses["Allowed wars"]) * happiness_bonuses[ "Per war" ] breakdown.append("-%d for wars" % war_count) result -= war_count # GOVERNMENT # ------------------------ # Monarchy if trait_lookup["Monarchy"] in the_team.traits: killed = False for k in kills: if k["victim"] == the_team.leader_id: killed = True if killed: breakdown.append("-%d from monarchy" % happiness_bonuses["Monarchy minus"]) result -= happiness_bonuses["Monarchy minus"] else: breakdown.append("+%d from monarchy" % happiness_bonuses["Monarchy plus"]) result += happiness_bonuses["Monarchy plus"] # Democracy if trait_lookup["Democracy"] in the_team.traits: avg_city_size = 0 for k, v in w.live_cities_from_team(the_team.id).items(): avg_city_size += v.population avg_city_size /= len(w.live_cities_from_team(the_team.id)) avg_city_size /= 1.2 if the_city.population < avg_city_size: breakdown.append("-%d from democracy" % happiness_bonuses["Democracy minus"]) result -= happiness_bonuses["Democracy minus"] else: breakdown.append("+%d from democracy" % happiness_bonuses["Democracy plus"]) result += happiness_bonuses["Democracy plus"] # RELIGION # ------------------------ # National religion if trait_lookup["National religion"] in the_team.traits: all_happy = True for deity_id, favour in the_team.deities.items(): if favour < 0: all_happy = False if not all_happy: breakdown.append("-%d from national religion" % happiness_bonuses["National religion minus"]) result -= happiness_bonuses["National religion minus"] else: breakdown.append("+%d from national religion" % happiness_bonuses["National religion plus"]) result += happiness_bonuses["National religion plus"] # Chosen deity if trait_lookup["Chosen deity"] in the_team.traits: killed = False for k in kills: if k["victim"] == the_team.leader_id: killed = True if killed: breakdown.append("-%d from chosen deity" % happiness_bonuses["Chosen deity minus"]) result -= happiness_bonuses["Chosen deity minus"] else: breakdown.append("+%d from chosen deity" % happiness_bonuses["Chosen deity plus"]) result += happiness_bonuses["Chosen deity plus"] # SOCIETY # ------------------------ # NATURAL FOCUS # ------------------------ # Warlike if trait_lookup["Warlike"] in the_team.traits: if len(relevant_recent_campaigns) < 4: breakdown.append("-%d from lack of wars" % happiness_bonuses["Warlike minus"]) result -= happiness_bonuses["Warlike minus"] # Mercantile if trait_lookup["Mercantile"] in the_team.traits: avg_city_wealth = 0 for k, v in w.live_cities_from_team(the_team.id).items(): avg_city_wealth += v.wealth avg_city_wealth /= len(w.live_cities_from_team(the_team.id)) avg_city_wealth / 1.2 if the_city.wealth < avg_city_wealth: breakdown.append("-%d from mercantile" % happiness_bonuses["Mercantile minus"]) result -= happiness_bonuses["Mercantile minus"] else: breakdown.append("+%d from mercantile" % happiness_bonuses["Mercantile plus"]) result += happiness_bonuses["Mercantile plus"] # Sailors if trait_lookup["Sailors"] in the_team.traits: if not the_city.port: breakdown.append("-%d from sailors" % happiness_bonuses["Sailors minus"]) result -= happiness_bonuses["Chosen deity minus"] else: breakdown.append("+%d from sailors" % happiness_bonuses["Sailors plus"]) result += happiness_bonuses["Sailors plus"] # Educated educated_buildings = ( "University", "Expanded university", "Academy", "Expanded academy", "Academy of Light", "Academy of Dark", "Academy of Abjuration", "Academy of Destruction", "Academy of Daemonic", "Academy of Necromancy", "Academy of Enchantment", "Academy of Alchemy", "Academy of Animation", "Academy of Sourcery", ) if trait_lookup["Educated"] in the_team.traits: happy = False for b in educated_buildings: if the_city.buildings_amount.get(building_lookup[b], 0) > 0: breakdown.append("+%d from educated (%s)" % (happiness_bonuses["Educated plus"], b)) result -= happiness_bonuses["Educated plus"] happy = True if not happy: breakdown.append("-%d from educated" % happiness_bonuses["Educated minus"]) result -= happiness_bonuses["Educated minus"] # Peaceful if trait_lookup["Peaceful"] in the_team.traits: if len(relevant_recent_campaigns) > 2: breakdown.append("-%d from too many wars" % happiness_bonuses["Peaceful minus"]) result -= happiness_bonuses["Peaceful minus"] else: breakdown.append("-%d from peace" % happiness_bonuses["Peaceful plus"]) result -= happiness_bonuses["Peaceful plus"] # Expansionist if trait_lookup["Expansionist"] in the_team.traits: # Age if common.current_turn() - the_city.founded < 5: breakdown.append("+%d from expansionist (young city)" % happiness_bonuses["Expansionist plus"]) result -= happiness_bonuses["Expansionist plus"] # Size if not the_city.size > 30000: breakdown.append("-%d from expansionist" % happiness_bonuses["Expansionist minus"]) result -= happiness_bonuses["Expansionist minus"] else: breakdown.append("+%d from expansionist" % happiness_bonuses["Expansionist plus"]) result += happiness_bonuses["Expansionist plus"] # Paranoid if trait_lookup["Paranoid"] in the_team.traits: garrison = w.garrison(the_city.id) if garrison < 1: garrison_size = 0 else: garrison_size = army_dict[garrison].get_size(w.cursor) if garrison_size < the_city.size / 10: breakdown.append("-%d from paranoid" % happiness_bonuses["Paranoid minus"]) result -= happiness_bonuses["Paranoid minus"] else: breakdown.append("+%d from paranoid" % happiness_bonuses["Paranoid plus"]) result += happiness_bonuses["Paranoid plus"] # Pious if trait_lookup["Pious"] in the_team.traits: if ( the_city.buildings_amount.get(building_lookup["Temple"], 0) > 0 or the_city.buildings_amount.get(building_lookup["Expanded temple"], 0) > 0 ): breakdown.append("+%d from pious" % happiness_bonuses["Pious plus"]) result += happiness_bonuses["Pious plus"] else: breakdown.append("-%d from pious" % happiness_bonuses["Pious minus"]) result -= happiness_bonuses["Pious minus"] # Hygienic if trait_lookup["Hygienic"] in the_team.traits: if ( the_city.buildings_amount.get(building_lookup["Hospital"], 0) > 0 or the_city.buildings_amount.get(building_lookup["Sewer system"], 0) > 0 ): breakdown.append("+%d from hygienic" % happiness_bonuses["Hygienic plus"]) result += happiness_bonuses["Hygienic plus"] else: breakdown.append("-%d from hygienic" % happiness_bonuses["Hygienic minus"]) result -= happiness_bonuses["Hygienic minus"] # Well fed if trait_lookup["Well fed"] in the_team.traits: food_amount = int(the_team.resources.get("Food")) needed = team_rules.resource_needed(w.cursor, "Food", the_team, the_world=w) food_ratio = food_amount / float(needed) if food_ratio < 1.1: breakdown.append("-%d from well fed" % happiness_bonuses["Well fed minus"]) result -= happiness_bonuses["Well fed minus"] else: breakdown.append("+%d from well fed" % happiness_bonuses["Well fed plus"]) result += happiness_bonuses["Well fed plus"] # Zealous, identical to National religion if trait_lookup["Zealous"] in the_team.traits: all_happy = True for deity_id, favour in the_team.deities.items(): if favour < 0: all_happy = False if not all_happy: breakdown.append("-%d from zealous" % happiness_bonuses["Zealous minus"]) result -= happiness_bonuses["Zealous minus"] else: breakdown.append("+%d from zealous" % happiness_bonuses["Zealous plus"]) result += happiness_bonuses["Zealous plus"] if with_breakdown: return result, breakdown return result