Exemple #1
0
def main(cursor):
    army_id = int(common.get_val("army", -1))
    the_army = army_q.get_one_army(cursor, army_id)
    database.query(cursor, army_f.make_delete_query(army_id))

    # Redirect
    page_data["Redirect"] = "list_armies&team={0:d}".format(the_army.team)
Exemple #2
0
def create_army_order(the_line, groups, debug=False):
	results = order_block.default_line_results(the_line)
	
	army_dict		= the_line.the_world.armies()
	armies_lookup	= the_line.the_world.armies_lookup_from_team(the_line.block.team)
	
	the_team		= the_line.the_world.teams()[the_line.block.team]
	
	# # Can we find the army?
	if groups['army'].lower() not in armies_lookup:
		# return order_block.fail(results, "could not find an army by the name of '%s'" % (groups['army']))
		pass
		the_army = None
	else:
		the_army = army_dict[armies_lookup[groups['army'].lower()]]
	
	x, y = int(groups['x']), int(groups['y'])
	
	# Check to see if the army exists
	if the_army == None:
		# Input a new army
		army_id = army_q.create_empty_army(the_line.the_world.cursor, groups['army'], the_line.block.team, groups['x'], groups['y'])
		
		# Update caches
		army_dict[army_id] = army_q.get_one_army(the_line.the_world.cursor, army_id)
		the_army = army_dict[army_id]
		the_line.the_world._armies_lookup_from_team[the_team.id][the_army.name.lower()] = army_id
	
	# Right, time to run recruitment
	results['results'].append("Created the army %s at %s" % (the_army.name, str((the_army.x, the_army.y))))
	results['line_cache'] = {"army":the_army.id}
	return order_block.success(results)
Exemple #3
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)
Exemple #4
0
def main(cursor):
	# Get squad Id
	army_id = int(common.get_val('army', 0))
	
	if army_id < 1:
		exit()
	
	the_army = army_q.get_one_army(cursor, army_id)
	squads_dict = squad_q.get_squads_from_army(cursor, army=army_id)
	
	monster_dict = monster_q.get_all_monsters(cursor)
	army_monsters_dict = monster_q.get_monsters_from_army(cursor, army_id)
	
	unit_dict = unit_q.get_units_from_team(cursor, the_army.team, special_units=True)
	
	output = []
	output.append("""
	<table border="0" cellspacing="0" cellpadding="5" style="width: 100%;">
		<tr class="row2">
			<th>Name</th>
			<th>Unit type</th>
			<th>Size</th>
			<th>Exp</th>
			<th>&nbsp;</th>
		</tr>""")
	
	count = -1
	if len(squads_dict) > 0:
		for squad_id, the_squad in squads_dict.items():
			if the_squad.unit not in unit_dict: continue
			
			count += 1
			
			output.append("""
			<tr class="row%(row)d" id="%(squad_id)d">
				<td>%(name)s</td>
				<td>%(unit_type)s</td>
				<td>%(size)s</td>
				<td>%(exp)s</td>
				<td style="padding: 0px;"><a href="web.py?mode=edit_squad&amp;squad=%(squad_id)d" class="block_link">Edit</a></td>
			</tr>
			""" % {	'row': (count % 2),
				
					"squad_id":		squad_id,
					"name":	common.doubleclick_text("squads", "name", squad_id, the_squad.name, "font-weight:bold", size=18),
					"unit_type":	unit_dict[the_squad.unit].name,
					"size":			common.doubleclick_text("squads", "amount", squad_id, the_squad.amount, size=7),
					"exp":			common.doubleclick_text("squads", "experience", squad_id, the_squad.experience, size=7),
					})
	else:
		output.append("""
		<tr class="row0">
			<td colspan="5">No squads in this army</td>
		</tr>""")
		count += 1
	
	
	if len(army_monsters_dict) > 0:
		for monster_id, amount in army_monsters_dict.items():
			if amount < 1: continue
			the_monster = monster_dict[monster_id]
			
			count += 1
			
			output.append("""
			<tr class="row{row}">
				<td>{name}</td>
				<td><em>Monster</em></td>
				<td>{amount}</td>
				<td>&nbsp;</td>
				<td style="padding: 0px;"><a href="web.py?mode=edit_army_monster&amp;army={army_id}&amp;monster={monster_id}" class="block_link">Edit</a></td>
			</tr>
			""".format(
					row			= (count % 2),
					army_id		= army_id,
					monster_id	= monster_id,
					name		= the_monster.name,
					amount		= common.doubleclick_text_full("army_monsters", "amount", "army = %d AND monster = %d" % (army_id, monster_id), amount, size=5),
			))
	
	# Add new squad to army thingie
	names = {}
	for u, the_unit in unit_dict.items():
		names[u] = the_unit.name
	
	count += 1
	output.append("""
	<tr class="row%(row)d">
		<form action="exec.py" id="add_squad_form_%(army_id)d" method="post" accept-charset="utf-8">	
		<td style="padding: 1px;">
			<input type="text" name="name" value=""/>
		
			<input type="hidden" name="team" value="%(team_id)s" />
			<input type="hidden" name="mode" value="add_squad" />
			<input type="hidden" name="army" value="%(army_id)s" />
		</td>
		<td style="padding: 1px;">%(unit_type)s</td>
		<td style="padding: 1px;"><input type="text" name="size" value="" size="5"/></td>
		<td style="padding: 1px;"><input type="text" name="experience" value="" size="5"/></td>
		<td style="padding: 0px;">
			<a class="block_link" href="#" onclick="$('#add_squad_form_%(army_id)d').submit();">Add</a>
		</td>
		</form>
	</tr>
	""" % {	'row': (count % 2),
		
			"army_id":			army_id,
			"team_id":			the_army.team,
			'unit_type':		common.option_box(
				name='unit_type',
				elements=names,
				element_order=unit_dict.keys(),
				custom_id="",
			),
			})
	
	output.append('</table>')
	return "".join(output)
Exemple #5
0
def main(cursor):
	# Get team Id
	monster_id = int(common.get_val('monster', 0))
	army_id = int(common.get_val('army', 0))
	
	if monster_id < 1:
		return "No monster selected"
	
	if army_id < 1:
		return "No army selected"
	
	the_monster	= monster_q.get_one_monster(cursor, monster_id)
	the_army = army_q.get_one_army(cursor, army_id)
	the_army.get_monsters(cursor)
	
	page_data['Title'] = "Edit army monster: %s: %s" % (the_army.name, the_monster.name)
	
	output = ["<div style='padding: 5px;'>"]
	
	# Main unit stuff
	output.append("""
	<form action="exec.py" id="the_unit_form" method="post" accept-charset="utf-8">
		<input type="hidden" name="mode" value="edit_army_monster_commit" />
		<input type="hidden" name="monster" value="{monster_id}" />
		<input type="hidden" name="army" value="{army_id}" />
	
		<table border="0" cellspacing="5" cellpadding="5">
			<tr>
				<td><strong>Monster:</strong></td>
				<td>{m_name}</td>
				
				<td>&nbsp;</td>
			
				<td><strong>Army:</strong></td>
				<td>{a_name}</td>
			</tr>
			<tr>
				<td><label for="amount">Amount:</label></td>
				<td><input type="text" name="amount" id="amount" value="{amount}" /></td>
				
				<td>&nbsp;</td>
			
				<td>&nbsp;</td>
				<td>&nbsp;</td>
			</tr>
			<tr>
				<td colspan="5"><input type="submit" value="Apply" /></td>
			</tr>
		</table>
	</form>
	<br />

	""".format(
		monster_id	= monster_id,
		army_id		= army_id,
		m_name		= the_monster.name,
		a_name		= the_army.name,
		amount		= the_army.monsters.get(monster_id, 0),
	))
	
	output.append("</div>")
	
	return "".join(output)