Beispiel #1
0
	def test_refund_cost(self):
		vals = (
			("Materials:50", "Materials:-25"),
			("Materials:100", "Materials:-50"),
		)
		
		for cost, answer in vals:
			r_answer = res_dict.Res_dict(answer)
			result = unit_rules.disband_cost(res_dict.Res_dict(cost))
			self.assertEqual(r_answer, result)
Beispiel #2
0
def disband_squad_order(the_line, groups, debug=False):
	results = order_block.default_line_results(the_line)
	
	# Check we have an army to select from
	if "army" in the_line.block.line_cache:
		army_id = the_line.block.line_cache["army"]
		the_army = the_line.the_world.armies()[army_id]
	else:
		return order_block.fail(results, "No army has been selected so no squad can be selected")
	
	# More handles
	squad_dict		= the_line.the_world.squads()
	squads_lookup	= the_line.the_world.squads_lookup_from_army(army_id)
	
	try:
		amount = int(groups['amount'])
	except Exception as e:
		return order_block.fail(results, "the value '%s' could not be converted to an integer, how it got this far is beyond me" % (groups['amount']))
	
	# Can we find the squad?
	if groups['squad'].lower() not in squads_lookup:
		return order_block.fail(results, "there is no squad by the name of '%s' in '%s'" % (groups['squad'], the_army.name))
	else:
		the_squad = squad_dict[squads_lookup[groups['squad'].lower()]]
	
	# Default line
	results = order_block.default_line_results(the_line, "%s could not be disbanded from %s in %s because" % (groups['amount'], the_squad.name, the_army.name))
	
	# Check amount
	if amount < 1:
		return order_block.fail(results, "an ammount less than 1 was given")
	
	# Bounds enforcement
	amount = min(amount, the_squad.amount)
	
	# Handles/Aliases
	city_dict	= the_line.the_world.cities_from_team(the_line.block.team)
	the_unit	= the_line.the_world.units()[the_squad.unit]
	the_team	= the_line.the_world.teams()[the_line.block.team]
	
	#	SITUATIONAL
	#------------------------
	# Dead cities can't be the target, set it to no city instead
	city_list = []
	for c, the_city in city_dict.items():
		if the_city.dead < 1:
			city_list.append(c)
	
	# Cost
	results['cost'] = the_unit.get_cost(the_world=the_line.the_world)['material_cost']
	
	if unit.categories[the_unit.type_cat] != "Ship" and \
		unit.categories[the_unit.type_cat] != "Airship":
		results['cost'] *= amount/1000
	else:
		results['cost'] *= amount
	
	# Apply unit_rules to it
	results['cost'] = unit_rules.disband_cost(results['cost'])
		
	# First queries are cost
	results['queries'].append("-- Disbanding: %s %s" % (amount, the_unit.name))
	results['queries'].extend(squad_f.make_disband_query(amount=amount, squad_id=the_squad.id))
	results['queries'].extend(city_f.make_disbanding_queries(amount, city_list))
	results['results'].append("Disbanded %s of %s in %s" % (amount, the_squad.name, the_army.name))
	
	# Update squad
	the_squad.amount -= amount
	if the_squad.amount == 0:
		results['queries'].append("-- Deleting as a result of 0 size")
		results['queries'].extend(squad_f.make_delete_query(the_squad.id))
	
	the_team.resources -= results['cost'].discrete()
	results['line_cache'] = {"army":the_army.id}
	return order_block.success(results)