Example #1
0
def main(cursor):
	unit_id = int(common.get_val('unit', -1))
	the_unit = unit_q.get_one_unit(cursor, unit_id)
	database.query(cursor, unit_f.delete_unit(unit_id))
	
	# Redirect
	page_data['Redirect'] = 'list_units&team={0:d}'.format(the_unit.team)
Example #2
0
def main(cursor):
	# Get team Id
	unit_id = int(common.get_val('unit', 0))
	
	if unit_id < 1:
		return "No unit selected"
	
	the_unit	= unit_q.get_one_unit(cursor, unit_id)
	army_dict	= army_q.get_all_armies(cursor)#get_armies_from_team(cursor, the_unit.team, include_garrisons=True)
	squad_dict	= squad_q.get_squads_from_team_of_type(cursor, the_unit.team, unit_id)
	equipment_dict = equipment_q.get_all_equipment(cursor)
	
	page_data['Title'] = "Edit unit: %s" % the_unit.name
	
	output = ["<div style='padding: 5px;'>"]
	
	# Unit cost breakdown
	unit_cost_breakdown = unit_rules.print_unit_cost(the_unit, cursor=cursor, breakdown_mode=True)
	
	w = world.World(cursor)
	real_cost = "Post override: %s/%s" % (
		unit_rules.unit_cost_override(w, the_unit, the_unit.costs['material_cost'], w.teams()[the_unit.team]),
		unit_rules.unit_cost_override(w, the_unit, the_unit.costs['iron_cost'], w.teams()[the_unit.team]),
	)
	real_upkeep = "Post override: %s/%s" % (
		unit_rules.unit_upkeep_override(w, the_unit, the_unit.costs['material_cost'], w.teams()[the_unit.team]),
		unit_rules.unit_upkeep_override(w, the_unit, the_unit.costs['iron_cost'], w.teams()[the_unit.team]),
	)
	# real_cost = 0
	# real_upkeep = 0
	
	output.append("""
	<div style="float: right; width: 50%;">
		<strong>Unit cost breakdown</strong><br />
		{cost_breakdown}<br />
		{real_cost}
		<br /><br />
	
		<strong>Unit upkeep breakdown</strong><br />
		{upkeep_breakdown}<br />
		{real_upkeep}
		<br /><br />
		
		<strong>Unit categories</strong><br />
		Type category: {type_cat}<br />
		Weapon category: {weapon_cat}<br />
		
		
		<br />
		<form id="delete_form" action="exec.py" method="post" accept-charset="utf-8">
			<input type="hidden" name="unit" id="unit" value="{unit_id}" />
			<input type="hidden" name="mode" id="mode" value="remove_unit" />
			<input style="float:right; margin-right:100px;" type="button" value="Delete unit" onclick="var answer = confirm('Delete {name}?')
			if (answer) $('#delete_form').submit();" />
		</form>
	</div>
	""".format(
		cost_breakdown		= "<br />".join(unit_cost_breakdown['cost']),
		upkeep_breakdown	= "<br />".join(unit_cost_breakdown['upkeep']),
		real_cost			= real_cost,
		real_upkeep			= real_upkeep,
		
		unit_id				= unit_id,
		name				= the_unit.name,
		
		type_cat			= unit.categories[the_unit.type_cat],
		weapon_cat			= unit.weapon_categories[the_unit.weapon_cat],
	))
	
	# 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_unit_commit" />
		<input type="hidden" name="id" value="%(unit_id)s" />
	
		<table border="0" cellspacing="5" cellpadding="5">
			<tr>
				<td><label for="name">Unit:</label></td>
				<td>%(name_text)s</td>
			
				<td>&nbsp;</td>
			
				<td><label for="team">Team:</label></td>
				<td>
					<select name="team" id="team">
						<option value="0">No team</option>
						%(team_option_box)s
					</select>
				</td>
			</tr>
			<tr>
				<td colspan="5" style="padding: 0px;"><a class="block_link" href="#" onclick="$('#the_unit_form').submit();">Apply changes</a></td>
			</tr>
		</table>
	</form>
	<br />

	""" % {
		"unit_id":			unit_id,
		"name_text":	common.text_box("name", the_unit.name),
		"team_option_box":	team_f.structured_list(cursor, default=the_unit.team),
	})
	
	# Unit equipment
	output.append("""
	<span class="stitle" id="equipment">Equipment</span>
	<table border="0" cellspacing="0" cellpadding="5">
		<tr class="row2">
			<th>Item</th>
			<th>&nbsp;</th>
		</tr>""")

	the_unit.get_equipment(cursor)

	counter = -1
	for e in the_unit.equipment:
		counter += 1
		output.append("""
		<tr class="row%(row)s">
			<td>%(item_name)s</td>
			<td style="padding: 0px;">
				<form action="exec.py" id="form_%(item_id)s" method="post" accept-charset="utf-8">
					<input type="hidden" name="mode" value="remove_equipment" />
					<input type="hidden" name="unit" value="%(unit_id)s" />
					<input type="hidden" name="item" value="%(item_id)s" />
					<a href="#" class="block_link" onclick="$('#form_%(item_id)s').submit();">Remove</a>
				</form>
			</td>
		</tr>""" % {
			"row":			counter%2,
			"item_name":	equipment_dict[e].name,
			"unit_id":		unit_id,
			"item_id":		e,
		})

	counter += 1
	output.append("""
	<tr class="row%(row)s">
		<form action="exec.py" id="new_equipment_form" method="post" accept-charset="utf-8">
			<input type="hidden" name="mode" value="add_equipment" />
			<input type="hidden" name="unit" value="%(unit_id)s" />
			<td>
				<select name="item">
					%(equipment_list)s
				</select>
			</td>
			<td>
				<input type="submit" value="Apply" />
			</td>
		</form>
	</tr>
	""" % {
		"row":				counter%2,
		"unit_id":			unit_id,
		"equipment_list":	equipment_f.equipment_option_list(cursor, remove_list=the_unit.equipment),
	})

	output.append("</table>")
	
	# What squads does the unit appear in?
	output.append("""
	<br /><br />
	<span class="stitle" id="squads">Squads</span>
	<table border="0" cellspacing="0" cellpadding="5">
		<tr class="row2">
			<th>Army</th>
			<th>Squad</th>
			<th>Size</th>
			<th>&nbsp;</th>
			<th>&nbsp;</th>
		</tr>""")

	the_unit.get_equipment(cursor)
	
	counter = -1
	for s, the_squad in squad_dict.items():
		counter += 1
		output.append("""
		<tr class="row%(row)s">
			<td>%(army_name)s</td>
			<td>%(name)s</td>
			<td>%(squad_size)s</td>
			<td style="padding: 0px;">
				<a href="web.py?mode=edit_army&amp;army=%(army_id)s" class="block_link">Edit army</a>
			</td>
			<td style="padding: 0px;">
				<a href="web.py?mode=edit_squad&amp;squad=%(squad_id)s" class="block_link">Edit squad</a>
			</td>
		</tr>""" % {
			"row":			counter%2,
			"army_name":	army_dict[the_squad.army].name,
			"army_id":		the_squad.army,
			"squad_id":		s,
			"name":			the_squad.name,
			"squad_size":	the_squad.amount,
		})
	
	output.append("</table>")
	output.append("</div>")
	
	return "".join(output)
Example #3
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)
Example #4
0
def new_unit_order(the_line, groups, debug=False, confirm=False):
	from checks import military_check
	
	results = order_block.default_line_results(the_line)
	
	# Handles
	unit_dict			= the_line.the_world.units()
	units_lookup		= the_line.the_world.units_lookup_from_team(the_line.block.team)
	squad_dict			= the_line.the_world.squads_from_team(the_line.block.team)
	
	equipment_dict		= the_line.the_world.equipment()
	equipment_lookup	= the_line.the_world.equipment_lookup(lower=True)
	
	the_team			= the_line.the_world.teams()[the_line.block.team]
	
	# Make sure unit does not already exist
	# _check_exists
	if groups['unit_name'].lower() in units_lookup:
		if debug:
			results['debug'].append("Failed at _check_exists")
			results['debug'].append("Exists with unit id: %d" % units_lookup[groups['unit_name'].lower()])
		return order_block.fail(results, "you already have a unit type by the name %s" % (groups['unit_name']))
	
	# Now get equipment
	equipment_list = []
	equipment_list_s = groups['item_list'].split(",")
	for e in equipment_list_s:
		els = e.lower().strip()
		if els in equipment_lookup:
			new_equipment = equipment_lookup[els]
			if equipment_dict[new_equipment].public:
				equipment_list.append(new_equipment)
	
	# Make sure we actually have equipment
	# _empty_equipment_list
	if len(equipment_list) < 1:
		if debug:
			results['debug'].append("Failed at _empty_equipment_list")
		return order_block.fail(results, "none of the equipment listed was able to be found")
	
	# Add unit info to the dictionary, only if confirming it
	if confirm:
		temp_unit = unit.Unit()
		temp_unit.name = groups['unit_name']
		temp_unit.equipment.extend(equipment_list)
		c = temp_unit.get_cost(cursor=None, the_world=the_line.the_world, equipment_dict=None, breakdown_mode=False, force_requery=False)
		
		# We need to actually add the unit + equipment
		unit_id = unit_f.new_unit(the_line.the_world.cursor, the_line.block.team, groups['unit_name'], "", 0, equipment_list)
		
		# Now to add it to the dictionaries
		unit_dict[unit_id] = unit_q.get_one_unit(the_line.the_world.cursor, unit_id)
		the_unit = unit_dict[unit_id]
		the_unit.id = unit_id
		
		units_lookup[the_unit.name.lower()] = unit_id
		
		military_check.check_available(the_line.the_world.cursor, verbose=False)
		
		equip_string = [equipment_dict[e].name for e in temp_unit.equipment]
		results['results'].append("Created new unit: %s" % temp_unit.name)
		results['results'].append("Equipment list: %s" % ", ".join(equip_string))
		results['results'].append("Cost: (%s/%s) (%s/%s)" % (
			c['material_cost'].get('Materials'),
			c['iron_cost'].get('Materials'),
			c['material_upkeep'].get('Materials'),
			c['iron_upkeep'].get('Materials'),
		))
		results['results'].append("This unit has been added successfully, even if in a Rob request")
		results['results'].append("")
		
		# Queries
		# results['queries'].append("-- Changing equipment: %s, %s: %s" % (the_unit.name, otype, groups['item_list']))
		# results['queries'].extend(unit_f.replace_equipment(the_unit.id, the_unit.equipment))
		
		return order_block.success(results)
		
	else:
		temp_unit = unit.Unit()
		temp_unit.name = groups['unit_name']
		temp_unit.equipment.extend(equipment_list)
		
		c = temp_unit.get_cost(cursor=None, the_world=the_line.the_world, equipment_dict=None, breakdown_mode=False, force_requery=False)
		
		equip_string = [equipment_dict[e].name for e in temp_unit.equipment]
		results['results'].append("Template for new unit: %s" % temp_unit.name)
		results['results'].append("Equipment list: %s" % ", ".join(equip_string))
		results['results'].append("Cost: (%s/%s) (%s/%s)" % (
			c['material_cost'].get('Materials'),
			c['iron_cost'].get('Materials'),
			c['material_upkeep'].get('Materials'),
			c['iron_upkeep'].get('Materials'),
		))
		results['results'].append("This unit has not yet been added, you must repeat this order with 'New unit' switched with 'Confirm new unit'")
		results['results'].append("")
		
		return order_block.success(results)