// File: /workspace/github_cpp_makefile_star2_O2/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
leaq -0x48(%rbp), %r14
movq %r14, 0x8(%r14)
movq %r14, (%r14)
andq $0x0, 0x10(%r14)
movq %rdi, %r12
leaq -0xd8(%rbp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
movq 0xa521(%rip), %rdi      # 0x12fd0
leaq 0x40fc(%rip), %rsi      # 0xcbb2
callq 0x31a0
pushq $0x1
popq %rsi
movq %rax, %rdi
callq 0x3230
movq %rax, %rdi
callq 0x30f0
movq 0xa4fb(%rip), %rdi      # 0x12fd0
leaq 0x40dd(%rip), %rsi      # 0xcbb9
callq 0x31a0
movq %rax, %rdi
callq 0x30f0
leaq 0x48(%r12), %r13
leaq -0xe8(%rbp), %rbx
movq %r12, -0x30(%rbp)
movq 0x70(%r12), %rsi
leaq -0x68(%rbp), %r15
movq %r15, %rdi
callq 0xad92
movq %r14, %rdi
movq %r15, %rsi
callq 0x8058
movq %r15, %rdi
callq 0x7fb8
movq %r14, %r12
movq (%r12), %r12
cmpq %r14, %r12
je 0x8e69
movq 0x10(%r12), %rsi
leaq -0x68(%rbp), %r15
movq %r15, %rdi
callq 0x42e0
movq 0xa48b(%rip), %rdi      # 0x12fd0
movq %r15, %rsi
callq 0x3170
movq %rax, %rdi
leaq 0x4081(%rip), %rsi      # 0xcbd8
callq 0x31a0
movq %rax, %rdi
callq 0x30f0
leaq -0x68(%rbp), %rdi
callq 0x30e0
movq 0xa45c(%rip), %rdi      # 0x12fd0
leaq 0x4065(%rip), %rsi      # 0xcbe0
callq 0x31a0
movq %rax, %rdi
callq 0x30f0
movq %r13, %r15
movq (%r15), %r15
cmpq %r13, %r15
je 0x8ba0
movq 0x10(%r15), %rdi
callq 0x4306
testl %eax, %eax
jle 0x8b8b
movq 0xa439(%rip), %rdi      # 0x12fe0
movq %rbx, %rsi
callq 0x31f0
movq %rbx, %rdi
leaq 0x403b(%rip), %rsi      # 0xcbf4
callq 0x5d10
testb %al, %al
je 0x8cbe
movq 0xa403(%rip), %rdi      # 0x12fd0
leaq 0x4026(%rip), %rsi      # 0xcbfa
callq 0x31a0
movq %rax, %rdi
leaq 0x4044(%rip), %rsi      # 0xcc27
callq 0x31a0
movq %rax, %rdi
callq 0x30f0
movq 0xa3e9(%rip), %rdi      # 0x12fe0
movq %rbx, %rsi
callq 0x31f0
movq %rbx, %rdi
leaq 0x4036(%rip), %rsi      # 0xcc3f
callq 0x5d10
testb %al, %al
je 0x8d77
movq 0xa3b3(%rip), %rdi      # 0x12fd0
leaq 0x4022(%rip), %rsi      # 0xcc46
callq 0x31a0
movq %rax, %rdi
leaq 0x4042(%rip), %rsi      # 0xcc75
callq 0x31a0
movq %rax, %rdi
callq 0x30f0
movq 0xa399(%rip), %rdi      # 0x12fe0
movq %rbx, %rsi
callq 0x31f0
xorl %r14d, %r14d
testl %r14d, %r14d
jne 0x8e32
movq %rbx, %rdi
leaq 0x4041(%rip), %rsi      # 0xcca6
callq 0x5d10
movq 0x10(%r12), %r15
testb %al, %al
je 0x8c80
xorl %r14d, %r14d
movq %r15, %rdi
callq 0x4f10
jmp 0x8cad
leaq -0xc8(%rbp), %rdi
movq %rbx, %rsi
callq 0x3200
movq %r15, %rdi
leaq -0xc8(%rbp), %r14
movq %r14, %rsi
callq 0x51e2
movq %r14, %rdi
callq 0x30e0
pushq $0x1
popq %r14
movq 0xa32c(%rip), %rdi      # 0x12fe0
movq %rbx, %rsi
callq 0x31f0
jmp 0x8c52
movq %rbx, %rdi
leaq 0x42b8(%rip), %rsi      # 0xcf80
callq 0x5d10
testb %al, %al
je 0x8d3f
movq 0xa2f8(%rip), %rdi      # 0x12fd0
leaq 0x402d(%rip), %rsi      # 0xcd0c
callq 0x31a0
movq %rax, %rdi
callq 0x30f0
movq 0xa2dd(%rip), %rdi      # 0x12fd0
leaq 0x403e(%rip), %rsi      # 0xcd38
callq 0x31a0
movq %rax, %rdi
callq 0x30f0
movq 0xa2d2(%rip), %rdi      # 0x12fe0
movq %rbx, %rsi
callq 0x31f0
movq %rbx, %rdi
leaq 0x3f86(%rip), %rsi      # 0xcca6
callq 0x5d10
movq 0x10(%r12), %r15
testb %al, %al
je 0x8e3b
movq %r15, %rdi
callq 0x5098
jmp 0x8b20
movq %rbx, %rdi
leaq 0x401f(%rip), %rsi      # 0xcd68
callq 0x5d10
testb %al, %al
je 0x8b20
movq 0x10(%r12), %rdi
movq 0x10(%r15), %rsi
callq 0x5604
movq 0x10(%r15), %rdi
movq 0x10(%r12), %rsi
callq 0x66bc
jmp 0x8b20
movq %rbx, %rdi
leaq 0x3eb8(%rip), %rsi      # 0xcc39
callq 0x5d10
testb %al, %al
je 0x8b20
movq 0xa23b(%rip), %rdi      # 0x12fd0
leaq 0x3f12(%rip), %rsi      # 0xccae
callq 0x31a0
movq %rax, %rdi
leaq 0x3f31(%rip), %rsi      # 0xccdc
callq 0x31a0
movq %rax, %rdi
callq 0x30f0
movq 0xa221(%rip), %rdi      # 0x12fe0
movq %rbx, %rsi
callq 0x31f0
xorl %r14d, %r14d
testl %r14d, %r14d
jne 0x8e32
movq %rbx, %rdi
leaq 0x3ecd(%rip), %rsi      # 0xcca6
callq 0x5d10
movq 0x10(%r12), %r15
testb %al, %al
je 0x8df4
xorl %r14d, %r14d
movq %r15, %rdi
callq 0x4fec
jmp 0x8e21
leaq -0xa8(%rbp), %rdi
movq %rbx, %rsi
callq 0x3200
movq %r15, %rdi
leaq -0xa8(%rbp), %r14
movq %r14, %rsi
callq 0x529e
movq %r14, %rdi
callq 0x30e0
pushq $0x1
popq %r14
movq 0xa1b8(%rip), %rdi      # 0x12fe0
movq %rbx, %rsi
callq 0x31f0
jmp 0x8dca
leaq -0x48(%rbp), %r14
jmp 0x8b20
leaq -0x88(%rbp), %rdi
movq %rbx, %rsi
callq 0x3200
movq %r15, %rdi
leaq -0x88(%rbp), %r15
movq %r15, %rsi
callq 0x53e0
movq %r15, %rdi
callq 0x30e0
jmp 0x8b20
movq -0x30(%rbp), %r12
movq 0x70(%r12), %rdi
callq 0xadb4
cmpl $0x1, %eax
je 0x8e8c
movq %r12, %rdi
callq 0x885a
testl %eax, %eax
je 0x8af9
movq 0x70(%r12), %rdi
callq 0xadb4
cmpl $0x1, %eax
jne 0x8ed9
movq 0xa12e(%rip), %rdi      # 0x12fd0
leaq 0x3ec6(%rip), %rsi      # 0xcd6f
callq 0x31a0
movq %rax, %rdi
callq 0x30f0
movq %r14, %r15
movq (%r15), %r15
cmpq %r14, %r15
je 0x8af9
movq 0x10(%r15), %rdi
callq 0x51c8
movq 0x10(%r15), %rdi
callq 0x567a
jmp 0x8eb9
movq 0xa0f0(%rip), %rdi      # 0x12fd0
leaq 0x3e9a(%rip), %rsi      # 0xcd81
callq 0x31a0
movq %rax, %rdi
callq 0x30f0
movq %r14, %r15
movq (%r15), %r15
cmpq %r14, %r15
je 0x8af9
movq 0x10(%r15), %rdi
callq 0x51c8
movq 0x10(%r15), %rdi
callq 0x5692
jmp 0x8ef7
jmp 0x8f5d
movq %rax, %rbx
leaq -0x88(%rbp), %rdi
jmp 0x8f4e
jmp 0x8f5d
jmp 0x8f5d
jmp 0x8f5d
jmp 0x8f5d
jmp 0x8f5d
movq %rax, %rbx
leaq -0xa8(%rbp), %rdi
jmp 0x8f4e
movq %rax, %rbx
leaq -0x68(%rbp), %rdi
jmp 0x8f4e
movq %rax, %rbx
leaq -0xc8(%rbp), %rdi
callq 0x30e0
jmp 0x8f60
jmp 0x8f5d
jmp 0x8f5d
jmp 0x8f5d
jmp 0x8f5d
movq %rax, %rbx
leaq -0xe8(%rbp), %rdi
callq 0x30e0
leaq -0x48(%rbp), %rdi
callq 0x7fb8
movq %rbx, %rdi
callq 0x3240
nop