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)
def delete_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, "there is no army by the name of '%s'" % groups['army']) else: the_army = army_dict[armies_lookup[groups['army'].lower()]] # More handles 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: 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 result results = order_block.default_line_results(the_line, "%s could not be deleted from %s because" % (the_squad.name, the_army.name)) # Is the squad empty? if the_squad.amount > 0: return order_block.fail(results, "%s still has %s men in it" % (the_squad.name, the_squad.amount)) results['queries'].extend(squad_f.make_delete_query(the_squad.id)) results['results'].append("The squad '%s' was deleted" % the_squad.name) return order_block.success(results)
def delete_army_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, "there is no army by the name of '%s'" % groups['army']) else: the_army = army_dict[armies_lookup[groups['army'].lower()]] # Default result results = order_block.default_line_results(the_line, "%s could not be deleted because" % (the_army.name)) # More handles squad_dict = the_line.the_world.squads() squads_lookup = the_line.the_world.squads_lookup_from_army(the_army.id)# We're not gonna use this the normal way # Are the squads in it empty? for squad_name, squad_id in squads_lookup.items(): results['queries'].extend(squad_f.make_delete_query(squad_id)) if squad_dict[squad_id].amount > 0: return order_block.fail(results, "one of it's squads (%s) is not empty" % squad_dict[squad_id].name) results['queries'].extend(army_f.make_delete_query(the_army.id)) results['results'].append("The army '%s' was deleted" % the_army.name) return order_block.success(results)
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)