// File: /workspace/github_cpp_makefile_star2_O1/kongrigoriou[P]Text-Based-RPG/src/Grid.cpp
// Function: Grid::battle()
int Grid::battle(){
    int rounds = 1;
    int battleflag = 0;
    list <Hero*>::iterator it;
    list <Monster *>::iterator mit;
    list <Hero*> hr;
    string input;
    cout << "ROUND " << rounds << endl;
    cout << "Choose an action for each hero" << endl;

    while(battleflag == 0){
        hr = team->get_HeroList();
        for(it = hr.begin(); it != hr.end(); ++it){
            cout << (*it)->get_name() << "'s turn" << endl;
            cout << "attack/spell/potion/equip" << endl;
            for(mit = Monsters.begin(); mit != Monsters.end(); ++mit){
                if((*mit)->get_HealthPower() > 0)
                    break;
            }
            
            cin >> input;
            if(input == "equip"){
                cout << "Do you want to equip a Weapon or an Armor? \n"
                        << "Reply with weapon/armor" << endl;
                cin >> input;

                if(input == "weapon"){
                    cout << "Type the name of the weapon you want to equip\n"
                        << "To display the available weapons type 'display' " << endl;
                    cin >> input;
                    int flag = 0;
                    while(flag == 0){
                        if(input == "display"){
                            (*it)->display_Weapons();
                        }else{
                            (*it)->equip_weapon(input);
                            flag = 1;
                        }
                        cin >> input;
                    }

                }else if(input == "armor"){
                    cout << "Type the name of the armor you want to equip\n"
                        << "To display the available armors type 'display' " << endl;
                    cin >> input;
                    int flag = 0;
                    while(flag == 0){
                        if(input == "display"){
                            (*it)->display_Armors();
                        }else{
                            (*it)->equip_armor(input);
                            flag = 1;
                        }
                        cin >> input;
                    }
                }
            }else if(input == "potion"){
                cout << "Type the name of the potion you want to use" << endl;
                cout << "To display the available Potions type 'display'" << endl;
                cin >> input;
                int flag = 0;
                while(flag < 2){
                    if(input == "display"){
                        (*it)->display_Potions();
                        flag++;
                    }else{
                        (*it)->usePotion(input);
                        flag++;
                    }
                    // cin >> input;
                    flag++;
                }
            }else if(input == "attack"){
                (*it)->attack(*mit);
                (*mit)->attack(*it);
            }
        }
        if(team->all_fainted() == 1 || monsters_fainted() == 1){
            battleflag = 1;
            if(team->all_fainted() == 1){
                cout << "Your team lost :(" << endl;
                for(it = hr.begin(); it != hr.end(); ++it){
                   (*it)->hp_tohalf();
                   (*it)->lost_round();
                }
            }else{
                cout << "Gg your team won the monsters!" << endl;
                for(it = hr.begin(); it != hr.end(); ++it){
                   (*it)->hp_tohalf();
                   (*it)->round_won();
                }
            }
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xc8, %rsp
movq %rdi, %r15
leaq -0xe8(%rbp), %rbx
movq %rbx, 0x8(%rbx)
movq %rbx, (%rbx)
xorl %eax, %eax
movq %rax, 0x10(%rbx)
leaq -0x38(%rbp), %rcx
movq %rcx, -0x10(%rcx)
movq %rax, -0x8(%rcx)
movb $0x0, (%rcx)
movq 0x9535(%rip), %rdi      # 0x13fd0
leaq 0x410e(%rip), %rsi      # 0xebb0
movl $0x6, %edx
callq 0x31c0
movq 0x951d(%rip), %rdi      # 0x13fd0
movl $0x1, %esi
callq 0x3210
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x3160
movsbl %al, %esi
movq %r14, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x3100
movq 0x94e2(%rip), %r14      # 0x13fd0
leaq 0x40c2(%rip), %rsi      # 0xebb7
movl $0x1e, %edx
movq %r14, %rdi
callq 0x31c0
movq (%r14), %rax
addq -0x18(%rax), %r14
movq %r14, %rdi
movl $0xa, %esi
callq 0x3160
movsbl %al, %esi
movq 0x94b0(%rip), %rdi      # 0x13fd0
callq 0x3040
movq %rax, %rdi
callq 0x3100
leaq 0x48(%r15), %r13
movq %r15, -0xd0(%rbp)
movq 0x70(%r15), %rsi
leaq -0x68(%rbp), %r14
movq %r14, %rdi
callq 0xdd6a
movq %rbx, %rdi
movq %r14, %rsi
callq 0x9b9a
movq -0x68(%rbp), %rdi
cmpq %r14, %rdi
je 0xab74
movq %r14, %r15
movq (%rdi), %r14
movl $0x18, %esi
callq 0x3190
movq %r14, %rdi
cmpq %r15, %r14
jne 0xab5f
movq -0xe8(%rbp), %r15
cmpq %rbx, %r15
leaq -0x48(%rbp), %r14
je 0xb0c9
movq 0x10(%r15), %rsi
leaq -0x68(%rbp), %rdi
callq 0x489a
movq -0x68(%rbp), %rsi
movq -0x60(%rbp), %rdx
movq 0x942c(%rip), %rdi      # 0x13fd0
callq 0x31c0
movq %rax, %r12
movl $0x7, %edx
movq %rax, %rdi
leaq 0x401b(%rip), %rsi      # 0xebd6
callq 0x31c0
movq (%r12), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x3160
movsbl %al, %esi
movq %r12, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x3100
movq -0x68(%rbp), %rdi
leaq -0x58(%rbp), %rax
cmpq %rax, %rdi
je 0xac01
movq -0x58(%rbp), %rsi
incq %rsi
callq 0x3190
movl $0x19, %edx
movq 0x93c3(%rip), %rdi      # 0x13fd0
leaq 0x3fca(%rip), %rsi      # 0xebde
callq 0x31c0
movq 0x93b0(%rip), %rcx      # 0x13fd0
movq (%rcx), %rax
movq -0x18(%rax), %rdi
addq %rcx, %rdi
movl $0xa, %esi
callq 0x3160
movsbl %al, %esi
movq 0x9392(%rip), %rdi      # 0x13fd0
callq 0x3040
movq %rax, %rdi
callq 0x3100
movq %r13, %r12
movq (%r12), %r12
cmpq %r13, %r12
je 0xac65
movq 0x10(%r12), %rdi
callq 0x48d2
testl %eax, %eax
jle 0xac4e
movq 0x9374(%rip), %rdi      # 0x13fe0
movq %r14, %rsi
callq 0x31e0
movq %r14, %rdi
leaq 0x3f74(%rip), %rsi      # 0xebf2
callq 0x30a0
testl %eax, %eax
je 0xacd6
movq %r14, %rdi
leaq 0x42ed(%rip), %rsi      # 0xef7e
callq 0x30a0
testl %eax, %eax
je 0xae8b
movq %r14, %rdi
leaq 0x40be(%rip), %rsi      # 0xed66
callq 0x30a0
testl %eax, %eax
jne 0xb0bd
movq 0x10(%r15), %rdi
movq 0x10(%r12), %rsi
callq 0x66ae
movq 0x10(%r12), %rdi
movq 0x10(%r15), %rsi
callq 0x7636
jmp 0xb0bd
movl $0x2c, %edx
movq 0x92ee(%rip), %rdi      # 0x13fd0
leaq 0x3f0f(%rip), %rsi      # 0xebf8
callq 0x31c0
movl $0x17, %edx
movq 0x92d6(%rip), %rdi      # 0x13fd0
leaq 0x3f24(%rip), %rsi      # 0xec25
callq 0x31c0
movq 0x92c3(%rip), %rcx      # 0x13fd0
movq (%rcx), %rax
movq -0x18(%rax), %rdi
addq %rcx, %rdi
movl $0xa, %esi
callq 0x3160
movsbl %al, %esi
movq 0x92a5(%rip), %rdi      # 0x13fd0
callq 0x3040
movq %rax, %rdi
callq 0x3100
movq 0x92a1(%rip), %rdi      # 0x13fe0
movq %r14, %rsi
callq 0x31e0
movq %r14, %rdi
leaq 0x3eec(%rip), %rsi      # 0xec3d
callq 0x30a0
testl %eax, %eax
je 0xaf9f
movq %r14, %rdi
leaq 0x3ecf(%rip), %rsi      # 0xec37
callq 0x30a0
testl %eax, %eax
jne 0xb0bd
movl $0x2d, %edx
movq 0x924f(%rip), %rdi      # 0x13fd0
leaq 0x3f24(%rip), %rsi      # 0xecac
callq 0x31c0
movl $0x2f, %edx
movq 0x9237(%rip), %rdi      # 0x13fd0
leaq 0x3f3a(%rip), %rsi      # 0xecda
callq 0x31c0
movq 0x9224(%rip), %rcx      # 0x13fd0
movq (%rcx), %rax
movq -0x18(%rax), %rdi
addq %rcx, %rdi
movl $0xa, %esi
callq 0x3160
movsbl %al, %esi
movq 0x9206(%rip), %rdi      # 0x13fd0
callq 0x3040
movq %rax, %rdi
callq 0x3100
movq 0x9202(%rip), %rdi      # 0x13fe0
movq %r14, %rsi
callq 0x31e0
xorl %r14d, %r14d
testl %r14d, %r14d
leaq -0x48(%rbp), %r14
jne 0xb0bd
movq %r14, %rdi
leaq 0x3ea4(%rip), %rsi      # 0xeca4
callq 0x30a0
movq 0x10(%r15), %r12
testl %eax, %eax
je 0xae6b
leaq -0x98(%rbp), %rax
movq %rax, -0xa8(%rbp)
movq -0x48(%rbp), %rsi
movq -0x40(%rbp), %rdx
addq %rsi, %rdx
leaq -0xa8(%rbp), %rdi
callq 0x47b8
movq %r12, %rdi
leaq -0xa8(%rbp), %rsi
callq 0x61d8
movq -0xa8(%rbp), %rdi
movl $0x1, %r14d
leaq -0x98(%rbp), %rax
cmpq %rax, %rdi
je 0xae76
movq -0x98(%rbp), %rsi
incq %rsi
callq 0x3190
jmp 0xae76
xorl %r14d, %r14d
movq %r12, %rdi
callq 0x5d8c
movq 0x9163(%rip), %rdi      # 0x13fe0
leaq -0x48(%rbp), %rsi
callq 0x31e0
jmp 0xade9
movl $0x2b, %edx
movq 0x9139(%rip), %rdi      # 0x13fd0
leaq 0x3e6c(%rip), %rsi      # 0xed0a
callq 0x31c0
movq 0x9126(%rip), %rcx      # 0x13fd0
movq (%rcx), %rax
movq -0x18(%rax), %rdi
addq %rcx, %rdi
movl $0xa, %esi
callq 0x3160
movsbl %al, %esi
movq 0x9108(%rip), %rdi      # 0x13fd0
callq 0x3040
movq %rax, %rdi
callq 0x3100
movl $0x2f, %edx
movq 0x90ef(%rip), %rdi      # 0x13fd0
leaq 0x3e4e(%rip), %rsi      # 0xed36
callq 0x31c0
movq 0x90dc(%rip), %rcx      # 0x13fd0
movq (%rcx), %rax
movq -0x18(%rax), %rdi
addq %rcx, %rdi
movl $0xa, %esi
callq 0x3160
movsbl %al, %esi
movq 0x90be(%rip), %rdi      # 0x13fd0
callq 0x3040
movq %rax, %rdi
callq 0x3100
movq 0x90ba(%rip), %rdi      # 0x13fe0
movq %r14, %rsi
callq 0x31e0
movq %r14, %rdi
leaq 0x3d6c(%rip), %rsi      # 0xeca4
callq 0x30a0
movq 0x10(%r15), %r12
testl %eax, %eax
je 0xb0b5
leaq -0x78(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x48(%rbp), %rsi
movq -0x40(%rbp), %rdx
addq %rsi, %rdx
leaq -0x88(%rbp), %rdi
callq 0x47b8
movq %r12, %rdi
leaq -0x88(%rbp), %rsi
callq 0x638a
movq -0x88(%rbp), %rdi
leaq -0x78(%rbp), %rax
cmpq %rax, %rdi
je 0xb0bd
movq -0x78(%rbp), %rsi
incq %rsi
callq 0x3190
jmp 0xb0bd
movl $0x2e, %edx
movq 0x9025(%rip), %rdi      # 0x13fd0
leaq 0x3c92(%rip), %rsi      # 0xec44
callq 0x31c0
movl $0x30, %edx
movq 0x900d(%rip), %rdi      # 0x13fd0
leaq 0x3ca9(%rip), %rsi      # 0xec73
callq 0x31c0
movq 0x8ffa(%rip), %rcx      # 0x13fd0
movq (%rcx), %rax
movq -0x18(%rax), %rdi
addq %rcx, %rdi
movl $0xa, %esi
callq 0x3160
movsbl %al, %esi
movq 0x8fdc(%rip), %rdi      # 0x13fd0
callq 0x3040
movq %rax, %rdi
callq 0x3100
movq 0x8fd8(%rip), %rdi      # 0x13fe0
movq %r14, %rsi
callq 0x31e0
xorl %r14d, %r14d
testl %r14d, %r14d
leaq -0x48(%rbp), %r14
jne 0xb0bd
movq %r14, %rdi
leaq 0x3c7a(%rip), %rsi      # 0xeca4
callq 0x30a0
movq 0x10(%r15), %r12
testl %eax, %eax
je 0xb095
leaq -0xb8(%rbp), %rax
movq %rax, -0xc8(%rbp)
movq -0x48(%rbp), %rsi
movq -0x40(%rbp), %rdx
addq %rsi, %rdx
leaq -0xc8(%rbp), %rdi
callq 0x47b8
movq %r12, %rdi
leaq -0xc8(%rbp), %rsi
callq 0x60a4
movq -0xc8(%rbp), %rdi
movl $0x1, %r14d
leaq -0xb8(%rbp), %rax
cmpq %rax, %rdi
je 0xb0a0
movq -0xb8(%rbp), %rsi
incq %rsi
callq 0x3190
jmp 0xb0a0
xorl %r14d, %r14d
movq %r12, %rdi
callq 0x5c16
movq 0x8f39(%rip), %rdi      # 0x13fe0
leaq -0x48(%rbp), %rsi
callq 0x31e0
jmp 0xb013
movq %r12, %rdi
callq 0x5eb2
movq (%r15), %r15
cmpq %rbx, %r15
jne 0xab88
movq -0xd0(%rbp), %r15
movq 0x70(%r15), %rdi
callq 0xdd8c
cmpl $0x1, %eax
je 0xb0ee
movq %r15, %rdi
callq 0xa776
testl %eax, %eax
je 0xab38
movq 0x70(%r15), %rdi
callq 0xdd8c
cmpl $0x1, %eax
jne 0xb169
movl $0x11, %edx
movq 0x8ec8(%rip), %rdi      # 0x13fd0
leaq 0x3c5e(%rip), %rsi      # 0xed6d
callq 0x31c0
movq 0x8eb5(%rip), %rcx      # 0x13fd0
movq (%rcx), %rax
movq -0x18(%rax), %rdi
addq %rcx, %rdi
movl $0xa, %esi
callq 0x3160
movsbl %al, %esi
movq 0x8e97(%rip), %rdi      # 0x13fd0
callq 0x3040
movq %rax, %rdi
callq 0x3100
movq %rbx, %r14
movq (%r14), %r14
cmpq %rbx, %r14
je 0xab38
movq 0x10(%r14), %rdi
callq 0x6088
movq 0x10(%r14), %rdi
callq 0x6760
jmp 0xb149
movl $0x1e, %edx
movq 0x8e5b(%rip), %rdi      # 0x13fd0
leaq 0x3c03(%rip), %rsi      # 0xed7f
callq 0x31c0
movq 0x8e48(%rip), %rcx      # 0x13fd0
movq (%rcx), %rax
movq -0x18(%rax), %rdi
addq %rcx, %rdi
movl $0xa, %esi
callq 0x3160
movsbl %al, %esi
movq 0x8e2a(%rip), %rdi      # 0x13fd0
callq 0x3040
movq %rax, %rdi
callq 0x3100
movq %rbx, %r14
movq (%r14), %r14
cmpq %rbx, %r14
je 0xab38
movq 0x10(%r14), %rdi
callq 0x6088
movq 0x10(%r14), %rdi
callq 0x6778
jmp 0xb1b6
jmp 0xb262
movq %rax, %r14
movq -0x88(%rbp), %rdi
leaq -0x78(%rbp), %rax
cmpq %rax, %rdi
je 0xb265
movq -0x78(%rbp), %rsi
jmp 0xb250
jmp 0xb262
jmp 0xb262
jmp 0xb262
jmp 0xb262
jmp 0xb262
movq %rax, %r14
movq -0xa8(%rbp), %rdi
leaq -0x98(%rbp), %rax
cmpq %rax, %rdi
je 0xb265
movq -0x98(%rbp), %rsi
jmp 0xb250
movq %rax, %r14
movq -0xc8(%rbp), %rdi
leaq -0xb8(%rbp), %rax
cmpq %rax, %rdi
je 0xb265
movq -0xb8(%rbp), %rsi
jmp 0xb250
movq %rax, %r14
movq -0x68(%rbp), %rdi
leaq -0x58(%rbp), %rax
cmpq %rax, %rdi
je 0xb265
movq -0x58(%rbp), %rsi
incq %rsi
callq 0x3190
jmp 0xb265
jmp 0xb262
jmp 0xb262
jmp 0xb262
jmp 0xb262
movq %rax, %r14
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0xb27e
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x3190
movq -0xe8(%rbp), %rdi
cmpq %rbx, %rdi
je 0xb29f
movq (%rdi), %r15
movl $0x18, %esi
callq 0x3190
movq %r15, %rdi
cmpq %rbx, %r15
jne 0xb28a
movq %r14, %rdi
callq 0x3220
nop