def test_calculate_favour(self): return self.test_targets.append(deity_rules.calculate_favour) # Basically to make sure it runs under live data w = world.World(database.get_cursor()) for t, the_team in w.teams().items(): the_team.get_deities(w.cursor) for deity_id, the_deity in w.deities().items(): deity_rules.calculate_favour(w, the_team, the_deity.name) deity_rules.calculate_favour(w, the_team, deity_id)
def record_favour(the_world, the_team): from rules import deity_rules deity_dict = the_world.deities() the_team.get_deities(the_world.cursor) for d in the_team.deities.keys(): new_favour, favour_desc = deity_rules.calculate_favour(the_world, the_team, d) query = """UPDATE team_deities SET favour = %d WHERE team = %d AND deity = %d;""" % (int(new_favour), int(the_team.id), int(d)) try: the_world.cursor.execute(query) except Exception as e: raise Exception("Database error: %s\nQuery: %s" % (str(e.args[0]).replace("\n",""), query)) # Log favour database.query(the_world.cursor, log_f.new_log("team_f.record_favour", "Deity: %d, Favour: %d, Desc: %s" % (int(d), int(new_favour), favour_desc), "", team = the_team.id) ) # Update team item too the_team.deities[d] = new_favour
def deities(the_world, the_team): output = {} # Possible time saver the_team.get_deities(the_world.cursor) if len(the_team.deities.items()) == 0: return {} deity_dict = the_world.deities() city_dict = the_world.cities() servant_dict_c = the_world.servants() deity_favour_info = {} # Get favour for deity_id, deity_favour in the_team.deities.items(): favour_result = deity_rules.calculate_favour(the_world, the_team, deity_id) the_team.deities[deity_id] = favour_result[0] deity_favour_info[deity_id] = favour_result[1] # Get temple points if the_team.temple_points < 0: the_team.temple_points = 0 for city_id, the_city in city_dict.items(): if the_city.team != the_team.id: continue if the_city.population < 15000: continue multiplier = int(math.floor(the_city.population / 15000)) the_team.temple_points += (the_city.get_temple_points(the_world.cursor) * multiplier) deity_servants = {} # Servants for deity_id, deity_favour in the_team.deities.items(): for servant_id, the_servant in servant_dict_c.items(): if the_servant.deity != deity_id: continue # Favour if deity_favour < the_servant.favour_needed: continue # Temple points if the_team.temple_points < the_servant.temple_points: continue # Monotheism if len(the_team.deities.keys()) > 1 and the_servant.monotheistic: continue if deity_id not in deity_servants: deity_servants[deity_id] = {} deity_servants[deity_id][the_servant.name] = { "name": the_servant.name, "description": the_servant.description, "cost": the_servant.summon_cost, "amount": the_servant.summon_amount, } for deity_id, deity_favour in the_team.deities.items(): output[deity_id] = { "deity_id": deity_id, "favour": deity_favour, "servants": deity_servants.get(deity_id, {}), } return output
def deities(cursor, the_world, the_team): output = [] # Possible time saver the_team.get_deities(cursor) if len(the_team.deities.items()) == 0: return "".join('<div class="ti_section" id="deities_div"></div>') deity_dict = the_world.deities() city_dict = the_world.cities() servant_dict_c = the_world.servants() deity_favour_info = {} # Get favour for deity_id, deity_favour in the_team.deities.items(): favour_result = deity_rules.calculate_favour(the_world, the_team, deity_id) the_team.deities[deity_id] = favour_result[0] deity_favour_info[deity_id] = favour_result[1] # Get temple points if the_team.temple_points < 0: the_team.temple_points = 0 for city_id, the_city in city_dict.items(): if the_city.team != the_team.id: continue if the_city.population < 15000: continue multiplier = int(math.floor(the_city.population / 15000.0)) # print "%s: %s * %s<br />" % (the_city.name, the_city.get_temple_points(), multiplier) the_team.temple_points += (the_city.get_temple_points(cursor) * multiplier) output.append('<div class="ti_section" id="deities_div">') output.append("<span class='stitle'>Favour breakdown</span><br /><br />") for deity_id, deity_favour in the_team.deities.items(): output.append("""<strong>%(name)s</strong> %(deity_favour)s favour <br />%(deity_favour_info)s <br /><br />""" % { 'name': deity_dict[deity_id].name, 'deity_favour': deity_favour, 'deity_favour_info': deity_favour_info[deity_id] }) # Servants output.append("""<br /><br /><span class="stitle">Servants</span> Temple points: %s <br /><br />""" % the_team.temple_points) for deity_id, deity_favour in the_team.deities.items(): for servant_id, the_servant in servant_dict_c.items(): if the_servant.deity != deity_id: continue # Favour if deity_favour < the_servant.favour_needed: continue # Temple points if the_team.temple_points < the_servant.temple_points: continue # Monotheism if len(the_team.deities.keys()) > 1 and the_servant.monotheistic: continue # Print servant output.append("""<div class="servant_block"> <strong>%(name)s</strong> Summon cost: %(cost)s Summon amount: %(amount)s<br /> %(description)s </div> """ % { "name": the_servant.name, "description": the_servant.description, "cost": the_servant.summon_cost, "amount": the_servant.summon_amount, }) output.append('</div>') return "".join(output)