def unit_attack_ranged(contubernium: BattleContuberniumInTurn,
                       target_contubernium: BattleContuberniumInTurn):
    for soldier in contubernium.battlesoldierinturn_set.all():
        target_soldier = random.choice(
            target_contubernium.battlesoldierinturn_set.all()[:])
        while (random.random() < 0.3 * soldier.attack_chance_multiplier()):
            if target_soldier.wound_status < BattleSoldierInTurn.DEAD:
                target_soldier.take_hit()
        target_soldier.save()
    contubernium.ammo_remaining -= 1
    if contubernium.ammo_remaining < 0:
        contubernium.ammo_remaining = 0
    contubernium.save()
Esempio n. 2
0
def optimistic_move_desire_formulation(
        battle_contubernium_in_turn: BattleContuberniumInTurn,
        target_distance_function):
    def tile_availability_test(coords: Coordinates):
        return True

    if target_distance_function(battle_contubernium_in_turn.coordinates()) > 0:
        path = find_path(battle_contubernium_in_turn, target_distance_function,
                         tile_availability_test)
        if len(path) > 1:
            battle_contubernium_in_turn.desires_pos = True
            battle_contubernium_in_turn.desired_x_pos = path[1].x
            battle_contubernium_in_turn.desired_z_pos = path[1].z
            battle_contubernium_in_turn.save()
Esempio n. 3
0
def safe_move(battle_contubernium_in_turn: BattleContuberniumInTurn,
              target_distance_function):
    turn = battle_contubernium_in_turn.battle_turn

    def tile_availability_test(coords: Coordinates):
        return True if turn.get_contubernium_in_position(
            coords) is None else False

    if target_distance_function(battle_contubernium_in_turn.coordinates()) > 0:
        path = find_path(battle_contubernium_in_turn, target_distance_function,
                         tile_availability_test)
        if len(path) > 1:
            battle_contubernium_in_turn.moved_this_turn = True
            battle_contubernium_in_turn.x_pos = path[1].x
            battle_contubernium_in_turn.z_pos = path[1].z
            #TODO WARNING: HORRIBLE HACK STARTS HERE
            #(to avoid unique constraint errors when contubs overlap for some reason)
            with transaction.atomic():
                try:
                    battle_contubernium_in_turn.save()
                except django.db.utils.IntegrityError as e:
                    pass
Esempio n. 4
0
def grant_position_desire(desire_getter: BattleContuberniumInTurn):
    desire_getter.desires_pos = False
    desire_getter.moved_this_turn = True
    desire_getter.x_pos = desire_getter.desired_x_pos
    desire_getter.z_pos = desire_getter.desired_z_pos
    desire_getter.save()
Esempio n. 5
0
def grant_position_swap(contubernium1: BattleContuberniumInTurn,
                        contubernium2: BattleContuberniumInTurn):
    contubernium1.x_pos = 31337
    contubernium1.save()
    grant_position_desire(contubernium2)
    grant_position_desire(contubernium1)