def cities(the_world, the_team): city_dict = the_world.cities_from_team(the_team.id) building_dict = the_world.buildings() artefact_dict = the_world.artefacts() wonder_dict = the_world.wonders() output = {} for city_id, the_city in city_dict.items(): if the_city.dead > 0: continue artefacts = {} buildings = {} wonders = {} # City buildings buildings_progress, buildings_amount = the_city.get_buildings(the_world.cursor) for b, the_building in building_dict.items(): if b not in buildings_progress and b not in buildings_amount: continue buildings[b] = { "building_id": b, "completed": buildings_amount.get(b, 0), "current_progress": buildings_progress.get(b, 0), } # Artefacts for artefact_id, the_artefact in artefact_dict.items(): if the_artefact.city != city_id: continue artefacts[the_artefact.name] = { "name": the_artefact.name, "description": the_artefact.description, } # Wonders for wonder_id, the_wonder in wonder_dict.items(): if the_wonder.city != city_id: continue wonders[the_wonder.name] = { "name": the_wonder.name, "description": the_wonder.description, "progress": the_wonder.completion, "needed_points": the_wonder.point_cost, "needed_materials": the_wonder.material_cost, } # Growth growth_rate, growth_constant = city_rules.city_growth_rate(the_world.cursor, the_team, the_city, the_world) new_population = int((the_city.population * growth_rate) + growth_constant) growth_rate = (growth_rate-1)*100 output[city_id] = { "city_id": city_id, "name": the_city.name, "x": the_city.x, "y": the_city.y, "terrain": map_data.terrain[mapper_q.get_terrain(the_world.cursor, the_city.x, the_city.y)].title(), "port": the_city.port, "nomadic": the_city.nomadic, "population": the_city.population, "new_population": new_population, "growth_rate": growth_rate, "slaves": the_city.slaves, "supply_good": the_city.supply_good, "artefacts": artefacts, "wonders": wonders, "buildings": buildings, } return output
def cities(cursor, the_world, the_team): city_dict = the_world.cities_from_team(the_team.id) building_dict = the_world.buildings() output = [] output.append("""<div class="ti_section" id="cities_div"> <table border="0" cellspacing="0" cellpadding="5" style="width: 100%;"> <tr class="row2"> <th>City name</th> <th>Location</th> <th>Port</th> <!--<th>Secret</th>--> <th>Nomadic</th> <th>Artefacts</th> <th>Population</th> <th>Slaves</th> <th>Production</th> <!--<th>Wealth</th>--> <th>Happiness</th> <th> </th> </tr>""") count = -1 if len(city_dict) > 0: for city_id, the_city in city_dict.items(): if the_city.dead > 0: continue count += 1 # sad_rules.produce_wealth(the_world, the_city) artefacts = the_city.artefacts if len(artefacts) > 0: artefacts = len(artefacts) else: artefacts = "" # Growth growth_rate, growth_constant = city_rules.city_growth_rate(cursor, the_team, the_city, the_world) new_population = int((the_city.population * growth_rate) + growth_constant) growth_rate = round((growth_rate-1)*100,1) # Formatting if growth_rate == int(growth_rate): growth_rate = int(growth_rate) # Happiness happiness = city.happiness_str(the_city.happiness) if happiness == "Rebellious": happiness = '<span style="font-weight:bold;color:#A00;">Rebellious</span>' if happiness == "Utopian": happiness = '<span style="font-weight:bold;color:#0A0;">Utopian</span>' output.append(""" <tr class="row%(row)d" id="%(city_id)d"> <td>%(name)s</td> <td>%(terrain)s %(x)s, %(y)s</td> <td style="text-align: center;">%(port)s</td> <!--<td style="text-align: center;">%(secret)s</td>--> <td style="text-align: center;">%(nomadic)s</td> <td style="text-align: center;">%(artefact)s</td> <td>%(population)sk, %(growth_rate)s%%</td> <td>%(slaves)s</td> <td>%(production)s + %(wealth)s = %(economy)s</td> <!--<td>%(wealth)s</td>--> <td>%(happiness)s</td> <td style="padding: 0px;"> <a href="#" id="city_%(city_id)s_building_show" onclick="$('#city_%(city_id)s_building_show').hide(); $('#city_%(city_id)s_buildings').show(); $('#city_%(city_id)s_building_hide').show(); return false;" class="block_link">Show buildings</a> <a href="#" id="city_%(city_id)s_building_hide" onclick="$('#city_%(city_id)s_building_show').show(); $('#city_%(city_id)s_buildings').hide(); $('#city_%(city_id)s_building_hide').hide(); return false;" class="block_link" style="display: none;">Hide buildings</a> </td> </tr> """ % { 'row': (count % 2), 'city_id': the_city.id, 'name': the_city.name, 'x': the_city.x, 'y': the_city.y, "terrain": map_data.terrain[mapper_q.get_terrain(cursor, the_city.x, the_city.y)].title(), 'port': common.bstr(the_city.port), 'secret': common.bstr(the_city.secret), 'artefact': artefacts, 'nomadic': common.bstr(the_city.nomadic), 'population': round(the_city.population/1000.0,1), 'new_population': round(new_population/1000.0,1), "growth_rate": growth_rate, "wealth": int(the_city.wealth), 'slaves': the_city.slaves, "production": int(team_rules.Materials(cursor, the_team, the_world=the_world, one_city_id=city_id)), "happiness": happiness, "economy": int(the_city.wealth + team_rules.Materials(cursor, the_team, the_world=the_world, one_city_id=city_id)), }) # City buildings output.append("<tr id='city_%s_buildings' style='display: none;'><td style='padding: 5px 20px 10px;' colspan='9'>" % the_city.id) output.append(""" <table border="0" cellspacing="0" cellpadding="5" style="width:100%%;"> <tr class="row2"> <th>Building</th> <th>Progress</th> </tr>""") count2 = -1 buildings_progress, buildings_amount = the_city.get_buildings(cursor) for b, the_building in building_dict.items(): if b not in buildings_progress and b not in buildings_amount: continue if buildings_progress.get(b, 0) > 0: percentage = float(buildings_progress.get(b, 0))/float(the_building.build_time) percentage = int(round(percentage*100)) if buildings_amount.get(b, 0) > 0 and buildings_progress.get(b, 0) > 0: progress = "%s completed and 1 in progress at %s%%" % (buildings_amount[b], percentage) elif buildings_amount.get(b, 0) > 0 and buildings_progress.get(b, 0) == 0: progress = "%s completed" % (buildings_amount[b]) elif buildings_amount.get(b, 0) == 0 and buildings_progress.get(b, 0) > 0: progress = "In progress at %s%%" % (percentage) else: # It's in both but at 0 and 0 so will get removed with the check continue count2 += 1 output.append(""" <tr class="row%(count)s"> <td>%(building_name)s</td> <td>%(progress)s</td> </tr>""" % { "count": count2%2, "building_name": the_building.name, "progress": progress, }) if artefacts != "": output.append("<tr><td colspan='2'>The artefact information is located in the <a href='#' onclick='switch_to_chosen();'>Chosen tab</a></td></tr>") output.append("</table>") output.append('</table></div>') return "".join(output)