Beispiel #1
0
def build_unit_equipment_strings(cursor, verbose):
	# Does what it says on the tin
	the_world = world.World(cursor)
	# the_world.units()
	unit_dict = unit_q.get_all_live_units(cursor)
	
	if verbose:
		it = cli_f.progressbar(unit_dict.items(), "military_check.build_unit_equipment_strings: ", 40, with_eta = True)
	else:
		it = unit_dict.items()
	
	for unit_id, the_unit in it:
		unit_f.rebuild_equipment_string(cursor, unit_id, the_world)
Beispiel #2
0
def check_unit_categories(cursor, verbose):
	queries = []
	unit_dict = unit_q.get_all_live_units(cursor)
	equipment_dict = equipment_q.get_all_equipment(cursor)
	
	unit_q.mass_get_unit_equipment(cursor, unit_dict)
	
	# Default
	query = """UPDATE units SET crew = 1;"""
	try: cursor.execute(query)
	except Exception as e:
		raise Exception("Database error: %s\nQuery: %s" % (str(e.args[0]).replace("\n",""), query))
	
	if verbose:
		it = cli_f.progressbar(unit_dict.items(), "military_check.check_unit_categories: ", 40, with_eta = True)
	else:
		it = unit_dict.items()
	
	for unit_id, the_unit in it:
		the_unit.transport = 0
		the_unit.move_type = 0
		the_unit.move_speed = 0
		the_unit.crew = 1
		
		the_unit.weapon_cat = 0
		the_unit.armour_cat = 0
		the_unit.move_cat = 0
		the_unit.training_cat = 0
		
		ranged = False
		melee = False
		
		# Loop through all it's equipment
		for e in the_unit.equipment:
			the_e = equipment_dict[e]
			
			if the_e.range > 2:
				ranged = True
			elif the_e.range == 0:
				melee = True
			
			the_unit.transport = max(the_e.transport, the_unit.transport)
			
			the_unit.crew = max(the_unit.crew, the_e.crew)
			
			# the_unit.move_type = 0
			# the_unit.move_speed = 0
			# the_unit.type_cat = 0
			
			the_unit.armour_cat = max(the_unit.armour_cat, the_e.armour_cat)
			the_unit.move_cat = max(the_unit.move_cat, the_e.move_cat)
			the_unit.training_cat = max(the_unit.training_cat, the_e.training_cat)
			
			if the_e.category == equipment.cat_list.index("Boat hull"):
				the_unit.type_cat = unit.categories.index("Ship")
			elif the_e.category == equipment.cat_list.index("Balloon"):
				the_unit.type_cat = unit.categories.index("Airship")
			else:
				pass
		
		# Work out categories
		if ranged and melee:
			the_unit.weapon_cat = unit.weapon_categories.index("Melee and Ranged")
		elif ranged and not melee:
			the_unit.weapon_cat = unit.weapon_categories.index("Ranged")
		elif melee and not ranged:
			the_unit.weapon_cat = unit.weapon_categories.index("Melee")
		else:
			the_unit.weapon_cat = unit.weapon_categories.index("Neither")
		
		# Query
		queries.append("""UPDATE units SET
			transport = {transport}, move_type = {move_type}, move_speed = {move_speed}, crew = {crew},
			type_cat = {type_cat}, weapon_cat = {weapon_cat}, armour_cat = {armour_cat}, move_cat = {move_cat}, training_cat = {training_cat}
				WHERE id = {id};""".format(
			transport = the_unit.transport,
			move_type = the_unit.move_type,
			move_speed = the_unit.move_speed,
			crew = the_unit.crew,
			type_cat = the_unit.type_cat,
			weapon_cat = the_unit.weapon_cat,
			armour_cat = the_unit.armour_cat,
			move_cat = the_unit.move_cat,
			training_cat = the_unit.training_cat,
			id = the_unit.id,
		))
	
	database.query(cursor, queries)