Пример #1
0
def main(cursor):
	city_id = int(common.get_val('city', -1))
	the_city = city_q.get_one_city(cursor, city_id)
	database.query(cursor, city_f.delete_city(city_id))
	
	# Redirect
	page_data['Redirect'] = 'list_cities&team={0:d}'.format(the_city.team)
Пример #2
0
def main(cursor):
	team			= int(common.get_val("team", 0))
	name			= common.get_val("name", 0)
	city_location	= common.get_val("city_location", 0)
	text_location	= common.get_val("text_location", "")
	army_type		= int(common.get_val("type", 0))
	
	actual_x = 0
	actual_y = 0
	
	if text_location != "":
		actual_x = re.search(r"(-?[0-9]+)[,:] ?(-?[0-9]+)", text_location).groups()[0]
		actual_y = re.search(r"(-?[0-9]+)[,:] ?(-?[0-9]+)", text_location).groups()[1]
	else:
		the_city = city_q.get_one_city(city_location)
		
		actual_x = the_city['x']
		actual_y = the_city['y']
	
	database.query(cursor,
		army_f.new_army(name, team, actual_x, actual_y, army_type=army_type))
	
	# Redirect
	page_data['Redirect'] = 'list_armies&team={0:d}'.format(team)
	return ""
Пример #3
0
def main(cursor):
	# Artefact settings
	the_artefact = artefact.Artefact()
	the_artefact.get_from_form(common.cgi_form.list)
	
	# Set the team based on the city
	the_city = city_q.get_one_city(cursor, the_artefact.city)
	the_artefact.team = the_city.team
	
	the_artefact.update(cursor)
	
	# Redirect
	page_data['Redirect'] = "list_artefacts&team={0}".format(the_artefact.team)
	return ""
Пример #4
0
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)
Пример #5
0
def main(cursor):
	name		= common.get_val("name", "")
	campaign	= int(common.get_val("campaign", 0))
	start		= int(common.get_val("start", 0))
	duration	= int(common.get_val("duration", 0))
	btype		= int(common.get_val("type", 0))
	location	= common.get_val("location", "")
	city		= int(common.get_val("city", 0))
	
	# Get location
	result = battle.battle_coords.search(location)
	if result != None:
		x = int(result.groups()[0])
		y = int(result.groups()[1])
	else:
		if city > 0:
			the_city = city_q.get_one_city(cursor, city)
			x, y = the_city.x, the_city.y
		else:
			x, y = 0, 0
	
	# If no name is supplied then it may be from a city
	if name == '':
		if city > 0:
			name = the_city.name
		else:
			page_data['Redirect'] = 'setup_campaign&campaign={0}'.format(campaign)
			return ""
	
	# If there is no last battle then we can't use auto pather to work out start time
	last_battle = battle_q.get_last_battle_from_campaign(cursor, campaign)
	if start < 0 and last_battle == None:
		start = 0
	
	# If negative start time then work out travel time
	if start < 0:
		waypoints = ((last_battle.x, last_battle.y), (x, y))
		b_path = path_f.path(cursor, waypoints, move_speed="Marching", move_type="Medium foot")
		start = math.ceil(b_path.time_cost) + last_battle.start + last_battle.duration
	
	database.query(cursor,
		battle_f.new_battle(name, campaign, start, duration, x, y, btype=btype, city=city))
	
	# page_data['Redirect'] = 'list_battles&campaign={0}'.format(campaign)
	page_data['Redirect'] = 'setup_campaign&campaign={0}'.format(campaign)
	return ""
Пример #6
0
def main(cursor):
	army_id = int(common.get_val('army', 0))
	garrison_id = int(common.get_val('garrison', 0))
	
	if army_id < 1 and garrison_id > 0:
		the_army = army_q.get_one_garrison(cursor, garrison_id)
	else:
		the_army = army_q.get_one_army(cursor, army_id)
	
	# If we're being sent the info from the view_map page then this is the new location we need
	new_location = common.get_val('location', "")
	
	if new_location == "":
		new_location = "%s,%s" % (the_army.x, the_army.y)# default value
		last_location = "%s,%s" % (the_army.old_x, the_army.old_y)
	
	if the_army.garrison > 0:
		new_location = """
		<td><label for="garrison">Garrison:</label></td>
		<td>%s</td>
		""" % (city_q.get_one_city(cursor, the_army.garrison).name)
	else:
		new_location = """
		<td style="padding: 0px;"><a href="web.py?mode=view_map&new_mode=edit_army&amp;army=%s" class="block_link">Location:</a></td>
		<td style="padding: 1px;">%s</td>""" % (the_army.id, common.text_box("location", new_location))
	
	output = []
	
	output.append("""<div style="float: right; width: 50%%;">
		<strong>Squads in army</strong>
		<div id="army_squads">
			
		</div>
	</div>""")
	
	output.append("<div style='padding: 5px;'>")
	
	if the_army.base > 0:
		base_name = "%s (%d)" % (city_q.get_one_city(cursor, the_army.base).name, the_army.base)
	else:
		base_name = "None"
	
	output.append("""
	<form action="exec.py" id="the_army_form" method="post" accept-charset="utf-8">
		<input type="hidden" name="mode" id="mode" value="edit_army_commit" />
		<input type="hidden" name="id" id="id" value="%(army_id)s" />
		
		Editing: %(name_text)s
		<br /><br />
		
		<table border="0" cellspacing="5" cellpadding="5">
			<tr>
				<td><label for="team">Team:</label></td>
				<td style="padding: 1px;">%(owner_select)s</td>
				
				<td width="5">&nbsp;</td>
				
				%(location)s
			</tr>
			<tr>
				<td>&nbsp;</td>
				<td>&nbsp;</td>
				
				<td width="5">&nbsp;</td>
				
				<td>Last location:</td>
				<td>%(last_location)s</td>
			</tr>
			<tr>
				<td>Base:</td>
				<td>%(base)s</td>
				
				<td width="5">&nbsp;</td>
				
				<td>Distance:</td>
				<td>%(distance)s</td>
			</tr>
			<tr>
				<td colspan="5" style="padding: 0;"><a class="block_link" href="#" onclick="$('#the_army_form').submit();">Apply changes</a></td>
			</tr>
		</table>
	</form>
	<form id="delete_form" action="exec.py" method="post" accept-charset="utf-8">
		<input type="hidden" name="army" id="army" value="%(army_id)s" />
		<input type="hidden" name="mode" id="mode" value="remove_army" />
		<input style="float:right; margin-right:100px;" type="button" value="Delete army" onclick="var answer = confirm('Delete %(name_safe)s?')
		if (answer) $('#delete_form').submit();" />
	</form>
	<br /><br />""" % {
		"name_safe":		common.js_name(the_army.name),
		"army_id":			the_army.id,
		"name":				the_army.name,
		"name_text":		common.text_box("name", the_army.name),
		"owner_select":		team_f.structured_list(cursor, default=the_army.team),
		"location":			new_location,
		"last_location":	last_location,
		"base":				base_name,
		"distance":			the_army.distance,
	})
	
	output.append(common.onload("$('#army_squads').load('web.py', {'mode':'list_squads','army':'%d', 'ajax':'True'});" % int(the_army.id)))
	
	output.append("</div>")
	
	page_data['Title'] = "Edit army %s" % the_army.name
	return "".join(output)
Пример #7
0
def main(cursor):
    # 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)

    # Get buildings list
    building_dict = building_q.get_all_buildings(cursor)

    # If we're being sent the info from the view_map page then this is the new location we need
    new_location = common.get_val("location", "")

    if new_location == "":
        new_location = "%s,%s" % (the_city.x, the_city.y)  # default value

    output = []

    output.append(
        """<div style="float: right; width: 50%;">
		<strong>Happiness</strong>
		<div id="happiness">
			
		</div>
	</div>"""
    )

    output.append(
        """<div style='padding: 5px;'>
	<form action="exec.py" method="post" accept-charset="utf-8">
		<input type="hidden" name="mode" id="mode" value="edit_city_commit" />
		<input type="hidden" name="id" id="id" value="%(city_id)s" />
		
		Editing: %(name_text)s
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
		<a href="web.py?mode=edit_army&amp;garrison=%(city_id)s">Edit garrison</a>
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
		<a href="web.py?mode=list_operatives&amp;city=%(city_id)s">Operatives</a>
		<br /><br />
		
		<table border="0" cellspacing="5" cellpadding="5">
			<tr>
				<td><label for="team">Team:</label></td>
				<td colspan="4" style="padding: 1px;">%(owner_select)s</td>
				
				<td width="5">&nbsp;</td>
				
				<td>&nbsp;</td>
				<td colspan="6">&nbsp;</td>
			</tr>
			<tr>
				<td><label for="size">Size:</label></td>
				<td style="padding: 1px;">%(city_population_text)s</td>
				
				<td width="5">&nbsp;</td>
				
				<td><label for="slaves">Slaves:</label></td>
				<td style="padding: 1px;">%(city_slaves_text)s</td>
				
				<td width="5">&nbsp;</td>
				<td style="padding: 0px;">
					<a class="block_link" href="web.py?mode=view_map&amp;new_mode=edit_city&amp;city=%(city_id)s"">Location:</a>
				</td>
				<td style="padding: 1px;">%(city_location_text)s</td>
				
				<td>&nbsp;</td>
				<td>&nbsp;</td>
			</tr>
			<tr>
				<td><label for="port">Port:</label></td>
				<td>%(city_port_checkbox)s</td>
				
				<td><label for="nomadic">Nomadic:</label></td>
				<td>%(city_nomadic_checkbox)s</td>
				
				<td><label for="dead">Dead:</label></td>
				<td>%(city_dead)s</td>
				
				<td><label for="secret">Secret:</label></td>
				<td>%(city_secret_checkbox)s</td>
				
				<td><label for="founded">Founded:</label></td>
				<td>%(founded_text)s</td>
			</tr>
			<tr>
				<td colspan="10">&nbsp;&nbsp;&nbsp;Description:<br />
					%(city_description_textarea)s
				</td>
			</tr>
		</table>
		<br />
		<input type="submit" value="Perform edit" />
	</form>
	<form id="delete_form" action="exec.py" method="post" accept-charset="utf-8">
		<input type="hidden" name="city" id="city" value="%(city_id)s" />
		<input type="hidden" name="mode" id="mode" value="remove_city" />
		<input style="float:right; margin-right:100px;" type="button" value="Delete city" onclick="var answer = confirm('Delete %(name_safe)s?')
		if (answer) $('#delete_form').submit();" />
	</form>
	<br /><br />"""
        % {
            "city_id": city_id,
            "name": the_city.name,
            "name_text": common.text_box("name", the_city.name, size=20),
            "owner_select": team_f.structured_list(cursor, default=the_city.team, field_name="team"),
            # "city_location_text":			common.text_box("location", "%s,%s" % (the_city.x, the_city.y), 10),
            "city_location_text": common.text_box("location", new_location, 10),
            "city_population_text": common.text_box("population", the_city.population, 10),
            "city_slaves_text": common.text_box(
                "slaves", the_city.slaves, 10, warn_on=lambda x: (True if int(x) < 0 else False)
            ),
            "city_port_checkbox": common.check_box("port", the_city.port),
            "city_dead": common.text_box("dead", the_city.dead, 5),
            "city_nomadic_checkbox": common.check_box("nomadic", the_city.nomadic),
            "city_secret_checkbox": common.check_box("secret", the_city.secret),
            "city_description_textarea": '<textarea name="description" id="description" rows="4" cols="40">%s</textarea>'
            % the_city.description,
            "founded_text": the_city.founded,
            "name_safe": common.js_name(the_city.name),
        }
    )

    # 	Buildings
    # ----------------------
    the_city.get_buildings(cursor)

    output.append(
        """
	<table style="float:left; margin-right: 25px;" border="0" cellspacing="0" cellpadding="5">
	<tr class="row2">
		<th>Building</th>
		<th>Progress</th>
		<th>Amount</th>
		<th>&nbsp;</th>
		<th>&nbsp;</th>
	</tr>
	"""
    )

    counter = -1
    building_remove_list = []
    for building_id, completion in the_city.buildings.items():
        counter += 1

        building_remove_list.append(building_id)

        output.append(
            """
		<tr class="row%(row)d">
			<form id="b_%(building_id)s" action="exec.py" method="get" accept-charset="utf-8">
				<input type="hidden" name="mode" value="set_building" />
				<input type="hidden" name="city" value="%(city_id)s" />
				<input type="hidden" name="building" value="%(building_id)s" />
				<td><label for="%(building_name)s">%(building_name)s</label></td>
				<td style="padding: 1px;">
					%(building_completion_text)s/%(building_build_time)s
				</td>
				<td style="padding: 1px;">
					%(building_amount_text)s
				</td>
				<td style="padding: 0px;">
					<!--<a class="block_link" href="#" onclick="$('#b_%(building_id)s').submit();">Edit</a>-->
					<input type="submit" value="Edit" />
				</td>
				<td style="padding: 0px;">
					<a class="block_link" href="exec.py?mode=set_building&amp;building=%(building_id)d&amp;city=%(city_id)d&amp;completion=0&amp;amount=0">Remove</a>
				</td>
			</form>
		</tr>"""
            % {
                "row": (counter % 2),
                "building_name": building_dict[building_id].name,
                "building_id": building_id,
                "building_build_time": building_dict[building_id].build_time,
                "city_id": city_id,
                "building_completion_text": common.text_box("completion", the_city.buildings[building_id], size=4),
                "building_amount_text": common.text_box("amount", the_city.buildings_amount[building_id], size=3),
            }
        )

    output.append(
        """
		<tr class="row%(row)d">
		<form id="city_add_building_form" action="exec.py" method="post" accept-charset="utf-8">
			<input type="hidden" name="mode" value="set_building" />
			<input type="hidden" name="city" value="%(city_id)s" />
			<td style="padding:1px;">
				<select id="new_building" name="building" onchange="$('#building_completion_span').load('web.py', {mode: 'get_building_build_time', building: document.getElementById('new_building').value, ajax:'True'});">
					%(building_option_box)s
				</select>
			</td>
			<td style="padding:1px;">
				%(building_completion_text)s/<span id="building_completion_span">000</span>
			</td>
			<td style="padding:1px;">
				%(building_amount_text)s
			</td>
			<td style="padding: 0px;" colspan="2">
				<input type="submit" value="Add" />
				<!--<a href="#" onclick="$('#city_add_building_form').submit();" class="block_link">Add</a>-->
			</td>
		</tr>
		</form>
	</table>
	%(onload)s
	"""
        % {
            "row": ((counter + 1) % 2),
            "city_id": the_city.id,
            "building_option_box": building_f.building_option_list(cursor, building_remove_list),
            "building_completion_text": common.text_box("completion", 0, size=4),
            "building_amount_text": common.text_box("amount", 0, size=3),
            "onload": common.onload("$('#new_building').focus();"),
        }
    )

    output.append(
        common.onload(
            "$('#building_completion_span').load('web.py', {mode: 'get_building_build_time', building: document.getElementById('new_building').value, 'ajax':1});"
        )
    )

    output.append("<strong>Wonder construction speed</strong>")
    output.append("<ul>")

    # Work out city points
    cities_dict = city_q.get_cities_from_team(cursor, the_city.team)
    total_points = 0
    for city_id2, city2 in cities_dict.items():
        if city2.team != the_city.team:
            continue
        if city2.dead == True:
            continue

        points = city_rules.wonder_build_rate(city2, the_city)
        if points > 0:
            output.append("<li>%s: %s</li>" % (city2.name, points))
            total_points += points

    output.append("<li><em>Total: %s</em></li>" % total_points)
    output.append("</ul>")

    output.append(
        common.onload(
            "$('#happiness').load('web.py', {'mode':'happiness_breakdown','city':'%d', 'ajax':'True'});"
            % int(the_city.id)
        )
    )

    # output.append('''<img src="%simages/grid_25.png" width="0" height="0" onload="">''' % common.data['media_path'])
    output.append("</div>")

    page_data["Title"] = "Edit city (%s)" % the_city.name
    return "".join(output)