Пример #1
0
	def test_make_supply_change_query(self):
		vals = (
			(1, 1, ["UPDATE cities SET supply_good = 1 WHERE id = 1;"]),
			(9, 5, ["UPDATE cities SET supply_good = 5 WHERE id = 9;"]),
		)
		
		for city, res, expected in vals:
			self.assertEqual(expected, trade_f.make_supply_change_query(city, res))
Пример #2
0
def supply_change_order(the_line, groups, debug=False):
	results = order_block.default_line_results(the_line)
	
	city_dict		= the_line.the_world.cities()
	cities_lookup	= the_line.the_world.cities_lookup(lower=True)
	
	# _find_city
	if groups['city'].lower() not in cities_lookup:
		if debug:
			results['debug'].append("Failed at _find_city")
		return order_block.fail(results, "there is no city by the name of '%s'" % groups['city'])
	else:
		the_city = city_dict[cities_lookup[groups['city'].lower()]]
	
	# _ownership
	if the_city.team != the_line.block.team:
		if debug:
			results['debug'].append("Failed at _ownership")
		return order_block.fail(results, "%s is not your city" % the_city.name)
	
	# _find_res
	resource_id = -1
	for i, r in enumerate(sad_rules.res_list):
		if r.lower() == groups['res_item'].lower():
			resource_id = i
	
	if resource_id < 0:
		if debug:
			results['debug'].append("Failed at _find_res")
		return order_block.fail(results, "%s is not a valid resource" % groups['res_item'])
	
	# Queries
	results['queries'].append("-- Supply change for %s to %s for team:%d, city:%d" % (
		the_city.name, sad_rules.res_list[resource_id], the_line.block.team, the_city.id))
	results['queries'].extend(trade_f.make_supply_change_query(the_city.id, resource_id))
	
	# Result
	results['results'].append("%s is now producing %s" % (the_city.name, sad_rules.res_list[resource_id]))
	
	# Update city points
	the_city.supply_good = resource_id
	
	return order_block.success(results)