def tech_option_list(cursor, remove_list=[], default=0): output = [] tech_dict = tech_q.get_all_techs(cursor) for c, s in tech_dict.items(): if c in remove_list: continue if c == default: output.append("<option value='%s' selected='selected'>%s</option>" % (c, s.name)) else: output.append("<option value='%s'>%s</option>" % (c, s.name)) return "".join(output)
def main(cursor): output = [] # Get city Id city_id = int(common.get_val('city', 1)) if city_id < 1: return "No city selected" # Build city item the_city = city_q.get_one_city(cursor, city_id) the_team = team_q.get_one_team(cursor, the_city.team) tech_dict = tech_q.get_all_techs(cursor) output.append(""" <div style="padding:5px;"> <span class="stitle">{name}</span><br /> <table border="0" cellspacing="0" cellpadding="5"> <tr class="row2"> <th>Resource</th> <th>Supply</th> <th>Demand</th> </tr>""".format( name = the_city.name, )) terrain = mapper_q.get_terrain(cursor, the_city.x, the_city.y) team_techs = the_team.get_techs(cursor)[0] techs = {} for k, v in team_techs.items(): techs[tech_dict[k].name] = v for i, r in enumerate(sad_rules.res_list): supply = round(sad_rules.supply[r](city=the_city, terrain=terrain, techs=techs), 2) demand = round(sad_rules.demand[r](city=the_city, terrain=terrain, techs=techs), 2) output.append(""" <tr class="row{i}"> <td>{res}</td> <td>{supply}</td> <td>{demand}</td> </tr>""".format( i = i % 2, res = r, supply = supply, demand = demand, )) page_data['Title'] = "City trade (%s)" % the_city.name output.append("</table></div>") return "".join(output)
def main(cursor): tech_dict = tech_q.get_all_techs(cursor) output = [] count = 0 for tech_id, the_tech in tech_dict.items(): if the_tech.name == "NONE": continue base_cost = res_dict.Res_dict(the_tech.base_cost) extra_cost = res_dict.Res_dict(the_tech.extra_cost) materials = "%s + L x %s" % (base_cost.get("Materials"), extra_cost.get("Materials")) points = "%s + L x %s" % (base_cost.get("Tech points"), extra_cost.get("Tech points")) count += 1 output.append(""" <tr class='row%(count)s'> <td><a id='%(js_name)s' href='#%(js_name)s'>%(name)s</a></td> <td>%(materials)s</td> <td>%(points)s</td> <td>%(description)s</td> <td><input type='text' id='lvl%(js_name)s' onkeyup="var lvl = $('#lvl%(js_name)s').val(); $('#mat%(js_name)s').html(%(materials_base)s + (lvl * %(materials_extra)s)); $('#pts%(js_name)s').html(%(points_base)s + (lvl * %(points_extra)s));" value='0' size='5'/></td> <td style='width: 50px;'> <span id='mat%(js_name)s'>0</span>, <span id='pts%(js_name)s'>0</span> </td> </tr>""" % { "count": count%2, "name": the_tech.name, "js_name": common.js_name(the_tech.name).replace(" ", ""), "materials": materials, "points": points, "materials_base": base_cost.get("Materials"), "materials_extra": extra_cost.get("Materials"), "points_base": base_cost.get("Tech points"), "points_extra": extra_cost.get("Tech points"), "description": the_tech.description, }) return "".join(output)
def techs(cursor): output = {} tech_dict = tech_q.get_all_techs(cursor) for t, the_tech in tech_dict.items(): output[t] = { "tech_id": t, "name": the_tech.name, "base_cost": res_dict.Res_dict(the_tech.base_cost).value, "extra_cost": res_dict.Res_dict(the_tech.extra_cost).value, "max_level": the_tech.max_level, "category": the_tech.category, "tradable": the_tech.tradable, "description": the_tech.description, } return json.dumps(output)
def techs(cursor): output = {} id_list = [] tech_dict = tech_q.get_all_techs(cursor) for t, the_tech in tech_dict.items(): id_list.append(t) output[t] = { "tech_id": t, "name": the_tech.name, # "base_cost": res_dict.Res_dict(the_tech.base_cost).value, # "extra_cost": res_dict.Res_dict(the_tech.extra_cost).value, "max_level": the_tech.max_level, "category": the_tech.category, "tradable": the_tech.tradable, } return "techs = %s; tech_list = %s;" % (json.dumps(output), id_list)
import database from classes import world, res_dict from classes import team, city, squad, army, unit from queries import equipment_q, building_q, deity_q, evolution_q, tech_q, spell_q, artefact_q, wonder_q # Need some live data for things like buildings etc temp_cursor = database.get_cursor() equipment_dict = equipment_q.get_all_equipment(temp_cursor) building_dict = building_q.get_all_buildings(temp_cursor) deity_dict = deity_q.get_all_deities(temp_cursor) evolution_dict = evolution_q.get_all_evolutions(temp_cursor) spell_dict = spell_q.get_all_spells(temp_cursor) tech_dict = tech_q.get_all_techs(temp_cursor) artefact_dict = artefact_q.get_all_artefacts(temp_cursor) wonder_dict = wonder_q.get_all_wonders(temp_cursor) def dummy_world(): w = world.World(Dead_cursor()) # LISTS #------------------------ w._equipment = equipment_dict w._buildings = building_dict w._deities = deity_dict w._evolutions = evolution_dict w._spells = spell_dict w._techs = tech_dict w._artefacts = artefact_dict # TEAMS #------------------------
def main(cursor): # Get team Id team_id = int(common.get_val("team", 0)) if team_id < 1: return "<div style='padding: 5px;'>%s</div>" % common.select_team_form(cursor, "list_techs") # Build team item the_team = team_q.get_one_team(cursor, team_id) tech_dict = tech_q.get_all_techs(cursor) output = [] the_team.get_techs(cursor) output.append( """ <table style="width: 100%;" border="0" cellspacing="0" cellpadding="5"> <tr class="row2"> <th>#</th> <th> </th> </tr> """ ) max_tech_level = 1 skip_tech_list = {} table_dict = {} tech_points_spent = 0 for tech_id, tech_level in the_team.tech_levels.items(): if tech_level not in table_dict: table_dict[tech_level] = [] skip_tech_list[tech_level] = [] max_tech_level = max(max_tech_level, tech_level) # Total that they've spent the_tech = tech_dict[tech_id] tech_points_spent += tech_rules.cost_to_get_to_level(cursor, the_tech, tech_level).get("Tech points", 0) tech_points_spent += the_team.tech_points[tech_id] skip_tech_list[tech_level].append(tech_id) table_dict[tech_level].append( """%(name)s <a class="red_link" href="exec.py?mode=set_tech&tech=%(tech_id)s&team=%(team_id)s&level=%(level_down)s&points=0"> < </a> %(points)s/%(points_to_next)s <a class="green_link" href="exec.py?mode=set_tech&tech=%(tech_id)s&team=%(team_id)s&level=%(level_up)s&points=0"> > </a>""" % { "name": the_tech.name, "tech_id": tech_id, "team_id": team_id, "points": the_team.tech_points[tech_id], "points_to_next": tech_rules.cost_for_next_level(cursor, the_tech, tech_level).get("Tech points"), "level_down": tech_level - 1, "level_up": tech_level + 1, } ) for i in range(0, max_tech_level + 1): if i not in table_dict: table_dict[i] = [] skip_tech_list[i] = [] output.append( """ <tr class="row%(row_count)s"> <td width="15">%(i)s</td> <td style="padding: 5px 2px 0 2px;">%(techs)s <!-- <form id="tech_form_%(i)s" style="float: right;" action="exec.py" method="post" accept-charset="utf-8"> <input type="hidden" name="mode" value="set_tech" /> <input type="hidden" name="team" value="%(team_id)s" /> <input type="hidden" name="points" value="0" /> <input type="hidden" name="level" value="%(i)s" /> <a href="#" onclick="$('#tech_form_%(i)s').submit();" class="block_link" style="float: right;">Add</a> <select style="float: right;" name="tech">%(new_tech)s</select></form> --> </td> </tr> """ % { "i": i, "team_id": team_id, "row_count": (i % 2), "techs": ", ".join(table_dict[i]), "new_tech": tech_f.tech_option_list(cursor, skip_tech_list[i]), } ) # Add techs output.append( """ <tr class="row%(row_count)s"> <td colspan="2"> <form action="exec.py" method="post" accept-charset="utf-8"> <input type="hidden" name="mode" value="set_tech" /> <input type="hidden" name="team" value="%(team_id)s" /> <select name="tech" id="new_tech"> %(tech_list)s </select> L: <input type="text" name="level" id="new_level" value="" onblur="$('#points_to_next').load('web.py', {'ajax':'True','mode':'tech_points_for_next','tech':$('#new_tech').val(), 'level':$('#new_level').val()});" size="5"/> P: <input type="text" name="points" value="" size="5" />/<span id="points_to_next">0</span> <input type="submit" value="Add" /> </form> </td> </tr> %(onload)s """ % { "team_id": team_id, "row_count": ((i + 1) % 2), "tech_list": tech_f.tech_option_list(cursor), "onload": common.onload("$('#new_tech').focus();"), } ) output.append("</table>") output.append("<br /> Total tech points spent: %d" % tech_points_spent) return "".join(output)