// File: arisKoutsou[P]oopproj/./src/game_utils.cpp
// Function: handleBattleCase()
void handleBattleCase(void) {
  createMonsters();
  int rounds = 1;
  clearScreen();
  while (true) {    
    int livingsPlayed = 0;
    size_t heroIndex = 0U;
    size_t prevHero = 0U;
    bool heroesTurn = true;

    cout << endl << "ROUND " << rounds;
    while (monsters.size() != 0 && livingsPlayed != (monsters.size() + heroesAlive())) {
      if (heroesTurn) {
	while (heroes[heroIndex]->getHealthPower() == 0) ++heroIndex;
        heroes[heroIndex]->battle(monsters);
	if (quitGame) return;
	prevHero = heroIndex;
	heroIndex = (heroIndex + 1) % heroes.size();
	if (prevHero != heroIndex) clearScreen();
	heroesTurn = false;        
      } else {
	size_t monsterIndex = rng.fromMintoMax(0, monsters.size() - 1);
        list<Monster*> :: const_iterator it = monsters.begin();
        while (monsterIndex-- != 0) ++it;
        size_t heroToAttackIndex;
        do {
          heroToAttackIndex = rng.fromMintoMax(0, heroes.size() - 1);
        } while (heroes[heroToAttackIndex]->getHealthPower() == 0);
        (*it)->attack(heroes[heroToAttackIndex]);
        heroesTurn = true;
      }
      ++livingsPlayed;
    }
    if (heroesWon()) {
      claimRewards();
      break;
    } else if (monstersWon()) {
      receivePenalty();
      break;
    }
    regenerateStats();
    updatePotionsAndNerfs();
    ++rounds;
  }
  restoreHeroes();
  cleanupMonsters();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
callq 0xe870
movl $0x1, -0x4(%rbp)
callq 0xe550
movl $0x0, -0x8(%rbp)
movq $0x0, -0x10(%rbp)
movq $0x0, -0x18(%rbp)
movb $0x1, -0x19(%rbp)
movq 0x319a5(%rip), %rdi     # 0x3ffc0
movq 0x3197e(%rip), %rsi     # 0x3ffa0
callq 0x5330
movq %rax, %rdi
leaq 0x20237(%rip), %rsi     # 0x2e868
callq 0x52f0
movq %rax, %rdi
movl -0x4(%rbp), %esi
callq 0x5540
leaq 0x31d78(%rip), %rdi     # 0x403c0
callq 0x133a0
movq %rax, %rcx
xorl %eax, %eax
cmpq $0x0, %rcx
movb %al, -0x41(%rbp)
je 0xe691
movslq -0x8(%rbp), %rax
movq %rax, -0x50(%rbp)
leaq 0x31d56(%rip), %rdi     # 0x403c0
callq 0x133a0
movq %rax, -0x58(%rbp)
callq 0xeea0
movq -0x58(%rbp), %rcx
movl %eax, %edx
movq -0x50(%rbp), %rax
movslq %edx, %rdx
addq %rdx, %rcx
cmpq %rcx, %rax
setne %al
movb %al, -0x41(%rbp)
movb -0x41(%rbp), %al
testb $0x1, %al
jne 0xe69d
jmp 0xe821
testb $0x1, -0x19(%rbp)
je 0xe749
jmp 0xe6a9
movq -0x10(%rbp), %rsi
leaq 0x31c7c(%rip), %rdi     # 0x40330
callq 0x133d0
movq (%rax), %rdi
callq 0x298a0
cmpl $0x0, %eax
jne 0xe6d4
movq -0x10(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x10(%rbp)
jmp 0xe6a9
movq -0x10(%rbp), %rsi
leaq 0x31c51(%rip), %rdi     # 0x40330
callq 0x133d0
movq (%rax), %rdi
leaq 0x31cd2(%rip), %rsi     # 0x403c0
callq 0x266d0
testb $0x1, 0x31c0f(%rip)     # 0x40309
je 0xe701
jmp 0xe869
movq -0x10(%rbp), %rax
movq %rax, -0x18(%rbp)
movq -0x10(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x60(%rbp)
leaq 0x31c14(%rip), %rdi     # 0x40330
callq 0x133f0
movq %rax, %rcx
movq -0x60(%rbp), %rax
xorl %edx, %edx
divq %rcx
movq %rdx, -0x10(%rbp)
movq -0x18(%rbp), %rax
cmpq -0x10(%rbp), %rax
je 0xe740
callq 0xe550
movb $0x0, -0x19(%rbp)
jmp 0xe813
leaq 0x31c70(%rip), %rdi     # 0x403c0
callq 0x133a0
subq $0x1, %rax
movl %eax, %esi
xorl %edi, %edi
callq 0x6040
cltq
movq %rax, -0x28(%rbp)
leaq 0x31c51(%rip), %rdi     # 0x403c0
callq 0x13410
movq %rax, -0x38(%rbp)
leaq -0x30(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x13440
movq -0x28(%rbp), %rax
movq %rax, %rcx
addq $-0x1, %rcx
movq %rcx, -0x28(%rbp)
cmpq $0x0, %rax
je 0xe7a5
leaq -0x30(%rbp), %rdi
callq 0x13460
jmp 0xe785
jmp 0xe7a7
leaq 0x31b82(%rip), %rdi     # 0x40330
callq 0x133f0
subq $0x1, %rax
movl %eax, %esi
xorl %edi, %edi
callq 0x6040
cltq
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rsi
leaq 0x31b5f(%rip), %rdi     # 0x40330
callq 0x133d0
movq (%rax), %rdi
callq 0x298a0
cmpl $0x0, %eax
je 0xe7a7
leaq -0x30(%rbp), %rdi
callq 0x13480
movq (%rax), %rax
movq %rax, -0x68(%rbp)
movq -0x40(%rbp), %rsi
leaq 0x31b32(%rip), %rdi     # 0x40330
callq 0x133d0
movq -0x68(%rbp), %rdi
movq (%rax), %rsi
callq 0x2a300
movb $0x1, -0x19(%rbp)
movl -0x8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8(%rbp)
jmp 0xe641
callq 0xef20
testb $0x1, %al
jne 0xe82c
jmp 0xe833
callq 0xef40
jmp 0xe85f
callq 0xf130
testb $0x1, %al
jne 0xe83e
jmp 0xe845
callq 0xf1d0
jmp 0xe85f
jmp 0xe847
callq 0xf260
callq 0xf590
movl -0x4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4(%rbp)
jmp 0xe5f9
callq 0xf640
callq 0xf6e0
addq $0x70, %rsp
popq %rbp
retq
nop