Ejemplo n.º 1
0
def main(cursor):
	squad_id = int(common.get_val('squad', -1))
	the_squad = squad_q.get_one_squad(cursor, squad_id)
	database.query(cursor, squad_f.make_delete_query(squad_id))
	
	# Redirect
	page_data['Redirect'] = 'edit_army&army={0:d}'.format(the_squad.army)
Ejemplo n.º 2
0
def main(cursor):
	squad_id = int(common.get_val('squad'))
	
	the_squad = squad_q.get_one_squad(cursor, squad_id)
	armies_dict = army_q.get_armies_from_team(cursor, the_squad.team, include_garrisons=True)
	the_unit = unit_q.get_one_unit(cursor, the_squad.unit)
	
	names = {}
	for a, the_army in armies_dict.items():
		names[a] = the_army.name
	
	output = []
	
	output.append("<div style='padding: 5px;'>")
	
	output.append("""
	<form action="exec.py" id="the_squad_form" method="post" accept-charset="utf-8">
		<input type="hidden" name="mode" id="mode" value="edit_squad_commit" />
		<input type="hidden" name="id" id="id" value="%(squad_id)s" />
		
		<label for="name">Editing:</label> %(name_text)s
		<br /><br />
		
		<table border="0" cellspacing="5" cellpadding="5">
			<tr>
				<td><label for="army">Army:</label></td>
				<td style="padding: 1px;">%(army_select)s</td>
			
				<td width="5">&nbsp;</td>
			
				<td>Type: </td>
				<td>%(unit_type)s</td>
			</tr>
			<tr>
				<td><label for="amount">Amount:</label></td>
				<td>%(amount)s</td>
			
				<td>&nbsp;</td>
			
				<td><label for="experience">Experince:</label></td>
				<td>%(experience)s</td>
			</tr>
			<tr>
				<td colspan="5">
					<strong>%(unit_name)s</strong>: %(unit_description)s
				</td>
			</tr>
			<tr>
				<td colspan="5">
					<input type="submit" value="Apply" />
				</td>
			</tr>
		</table>
	</form>
	<form id="delete_form" action="exec.py" method="post" accept-charset="utf-8">
		<input type="hidden" name="squad" id="squad" value="%(squad_id)s" />
		<input type="hidden" name="mode" id="mode" value="remove_squad" />
		<input style="float:right; margin-right:100px;" type="button" value="Delete squad" onclick="var answer = confirm('Delete %(name)s?')
		if (answer) $('#delete_form').submit();" />
	</form>
	<br /><br />""" % {
		"squad_id":			squad_id,
		"name":				the_squad.name,
		"name_text":		common.text_box("name", the_squad.name),
		"unit_type":		the_unit.name,
		"army_select":		common.option_box(
			name='army',
			elements=names,
			element_order=armies_dict.keys(),
			custom_id="army",
			selected=the_squad.army,
		),
		
		"unit_name":		the_unit.name,
		"unit_description":	the_unit.equipment_string,
		
		"amount":			common.text_box("amount", the_squad.amount),
		"experience":		common.text_box("experience", the_squad.experience),
	})
	
	output.append("</div>")
	
	page_data['Title'] = "Editing squad (%s)" % the_squad.name
	return "".join(output)
Ejemplo n.º 3
0
def create_squad_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)
	
	# 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']))
	else:
		the_army = army_dict[armies_lookup[groups['army'].lower()]]
	
	squad_dict		= the_line.the_world.squads()
	squads_lookup	= the_line.the_world.squads_lookup_from_army(the_army.id)
	
	# Can we find the squad?
	if groups['squad'].lower() not in squads_lookup:
		the_squad = None
	else:
		the_squad = squad_dict[squads_lookup[groups['squad'].lower()]]
	
	# Check amount
	try:
		amount = int(groups['amount'])
	except Exception as e:
		return order_block.fail(results, "the amount '%s' could not be converted into a number" % groups['amount'])
	
	# Unit type
	unit_dict			= the_line.the_world.units()
	units_lookup		= the_line.the_world.units_lookup_from_team(the_line.block.team)
	all_units_lookup	= the_line.the_world.units_lookup_from_team(0)
	
	if groups['unit'].lower() not in units_lookup:
		if groups['unit'].lower() not in all_units_lookup:
			return order_block.fail(results, "no unit by the name of '%s' could be found" % (groups['unit']))
		else:
			the_unit = unit_dict[all_units_lookup[groups['unit'].lower()]]
	else:
		the_unit = unit_dict[units_lookup[groups['unit'].lower()]]
	
	# Check to see if the squad exists
	if the_squad == None:
		# Input a new squad
		squad_id = squad_q.create_empty_squad(the_line.the_world.cursor, groups['squad'], the_army.id, the_unit.id, the_line.block.team)
		
		# Update caches
		squad_dict[squad_id] = squad_q.get_one_squad(the_line.the_world.cursor, squad_id)
		the_squad = squad_dict[squad_id]
		if the_army.id not in the_line.the_world._squads_lookup_from_army:
			the_line.the_world._squads_lookup_from_army[the_army.id] = {}
		the_line.the_world._squads_lookup_from_army[the_army.id][the_squad.name.lower()] = squad_id
		# the_line.the_world.squads_lookup_from_army(the_army.id)# We're not gonna use this the normal way
	else:
		if the_squad.unit != the_unit.id:
			return order_block.fail(results, "the squad %s in %s already exists with a unit type of %s" % (the_squad.name, the_army.name, unit_dict[the_squad.unit].name))
	
	# If no amount then it's a template
	if amount == 0:
		results['input_response'] = "Created empty squad %s in %s of type %s" % (groups['squad'], groups['army'], groups['unit'])
		return results
	
	# Right, time to run recruitment
	return _recruit(the_line, the_squad, the_army, amount, debug)