// File: /workspace/github_cpp_makefile_star2_O3/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 0x94b3(%rip), %rdi      # 0x13fd0
leaq 0x408c(%rip), %rsi      # 0xebb0
movl $0x6, %edx
callq 0x31c0
movq 0x949b(%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 0x9460(%rip), %r14      # 0x13fd0
leaq 0x4040(%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 0x942e(%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 0xdde2
movq %rbx, %rdi
movq %r14, %rsi
callq 0x9c4e
movq -0x68(%rbp), %rdi
cmpq %r14, %rdi
je 0xabf6
movq %r14, %r15
movq (%rdi), %r14
movl $0x18, %esi
callq 0x3190
movq %r14, %rdi
cmpq %r15, %r14
jne 0xabe1
movq -0xe8(%rbp), %r15
cmpq %rbx, %r15
leaq -0x48(%rbp), %r14
je 0xb14b
movq 0x10(%r15), %rsi
leaq -0x68(%rbp), %rdi
callq 0x489e
movq -0x68(%rbp), %rsi
movq -0x60(%rbp), %rdx
movq 0x93aa(%rip), %rdi      # 0x13fd0
callq 0x31c0
movq %rax, %r12
movl $0x7, %edx
movq %rax, %rdi
leaq 0x3f99(%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 0xac83
movq -0x58(%rbp), %rsi
incq %rsi
callq 0x3190
movl $0x19, %edx
movq 0x9341(%rip), %rdi      # 0x13fd0
leaq 0x3f48(%rip), %rsi      # 0xebde
callq 0x31c0
movq 0x932e(%rip), %rcx      # 0x13fd0
movq (%rcx), %rax
movq -0x18(%rax), %rdi
addq %rcx, %rdi
movl $0xa, %esi
callq 0x3160
movsbl %al, %esi
movq 0x9310(%rip), %rdi      # 0x13fd0
callq 0x3040
movq %rax, %rdi
callq 0x3100
movq %r13, %r12
movq (%r12), %r12
cmpq %r13, %r12
je 0xace7
movq 0x10(%r12), %rdi
callq 0x48d6
testl %eax, %eax
jle 0xacd0
movq 0x92f2(%rip), %rdi      # 0x13fe0
movq %r14, %rsi
callq 0x31e0
movq %r14, %rdi
leaq 0x3ef2(%rip), %rsi      # 0xebf2
callq 0x30a0
testl %eax, %eax
je 0xad58
movq %r14, %rdi
leaq 0x426b(%rip), %rsi      # 0xef7e
callq 0x30a0
testl %eax, %eax
je 0xaf0d
movq %r14, %rdi
leaq 0x403c(%rip), %rsi      # 0xed66
callq 0x30a0
testl %eax, %eax
jne 0xb13f
movq 0x10(%r15), %rdi
movq 0x10(%r12), %rsi
callq 0x66b2
movq 0x10(%r12), %rdi
movq 0x10(%r15), %rsi
callq 0x763e
jmp 0xb13f
movl $0x2c, %edx
movq 0x926c(%rip), %rdi      # 0x13fd0
leaq 0x3e8d(%rip), %rsi      # 0xebf8
callq 0x31c0
movl $0x17, %edx
movq 0x9254(%rip), %rdi      # 0x13fd0
leaq 0x3ea2(%rip), %rsi      # 0xec25
callq 0x31c0
movq 0x9241(%rip), %rcx      # 0x13fd0
movq (%rcx), %rax
movq -0x18(%rax), %rdi
addq %rcx, %rdi
movl $0xa, %esi
callq 0x3160
movsbl %al, %esi
movq 0x9223(%rip), %rdi      # 0x13fd0
callq 0x3040
movq %rax, %rdi
callq 0x3100
movq 0x921f(%rip), %rdi      # 0x13fe0
movq %r14, %rsi
callq 0x31e0
movq %r14, %rdi
leaq 0x3e6a(%rip), %rsi      # 0xec3d
callq 0x30a0
testl %eax, %eax
je 0xb021
movq %r14, %rdi
leaq 0x3e4d(%rip), %rsi      # 0xec37
callq 0x30a0
testl %eax, %eax
jne 0xb13f
movl $0x2d, %edx
movq 0x91cd(%rip), %rdi      # 0x13fd0
leaq 0x3ea2(%rip), %rsi      # 0xecac
callq 0x31c0
movl $0x2f, %edx
movq 0x91b5(%rip), %rdi      # 0x13fd0
leaq 0x3eb8(%rip), %rsi      # 0xecda
callq 0x31c0
movq 0x91a2(%rip), %rcx      # 0x13fd0
movq (%rcx), %rax
movq -0x18(%rax), %rdi
addq %rcx, %rdi
movl $0xa, %esi
callq 0x3160
movsbl %al, %esi
movq 0x9184(%rip), %rdi      # 0x13fd0
callq 0x3040
movq %rax, %rdi
callq 0x3100
movq 0x9180(%rip), %rdi      # 0x13fe0
movq %r14, %rsi
callq 0x31e0
xorl %r14d, %r14d
testl %r14d, %r14d
leaq -0x48(%rbp), %r14
jne 0xb13f
movq %r14, %rdi
leaq 0x3e22(%rip), %rsi      # 0xeca4
callq 0x30a0
movq 0x10(%r15), %r12
testl %eax, %eax
je 0xaeed
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 0x61de
movq -0xa8(%rbp), %rdi
movl $0x1, %r14d
leaq -0x98(%rbp), %rax
cmpq %rax, %rdi
je 0xaef8
movq -0x98(%rbp), %rsi
incq %rsi
callq 0x3190
jmp 0xaef8
xorl %r14d, %r14d
movq %r12, %rdi
callq 0x5d90
movq 0x90e1(%rip), %rdi      # 0x13fe0
leaq -0x48(%rbp), %rsi
callq 0x31e0
jmp 0xae6b
movl $0x2b, %edx
movq 0x90b7(%rip), %rdi      # 0x13fd0
leaq 0x3dea(%rip), %rsi      # 0xed0a
callq 0x31c0
movq 0x90a4(%rip), %rcx      # 0x13fd0
movq (%rcx), %rax
movq -0x18(%rax), %rdi
addq %rcx, %rdi
movl $0xa, %esi
callq 0x3160
movsbl %al, %esi
movq 0x9086(%rip), %rdi      # 0x13fd0
callq 0x3040
movq %rax, %rdi
callq 0x3100
movl $0x2f, %edx
movq 0x906d(%rip), %rdi      # 0x13fd0
leaq 0x3dcc(%rip), %rsi      # 0xed36
callq 0x31c0
movq 0x905a(%rip), %rcx      # 0x13fd0
movq (%rcx), %rax
movq -0x18(%rax), %rdi
addq %rcx, %rdi
movl $0xa, %esi
callq 0x3160
movsbl %al, %esi
movq 0x903c(%rip), %rdi      # 0x13fd0
callq 0x3040
movq %rax, %rdi
callq 0x3100
movq 0x9038(%rip), %rdi      # 0x13fe0
movq %r14, %rsi
callq 0x31e0
movq %r14, %rdi
leaq 0x3cea(%rip), %rsi      # 0xeca4
callq 0x30a0
movq 0x10(%r15), %r12
testl %eax, %eax
je 0xb137
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 0x6398
movq -0x88(%rbp), %rdi
leaq -0x78(%rbp), %rax
cmpq %rax, %rdi
je 0xb13f
movq -0x78(%rbp), %rsi
incq %rsi
callq 0x3190
jmp 0xb13f
movl $0x2e, %edx
movq 0x8fa3(%rip), %rdi      # 0x13fd0
leaq 0x3c10(%rip), %rsi      # 0xec44
callq 0x31c0
movl $0x30, %edx
movq 0x8f8b(%rip), %rdi      # 0x13fd0
leaq 0x3c27(%rip), %rsi      # 0xec73
callq 0x31c0
movq 0x8f78(%rip), %rcx      # 0x13fd0
movq (%rcx), %rax
movq -0x18(%rax), %rdi
addq %rcx, %rdi
movl $0xa, %esi
callq 0x3160
movsbl %al, %esi
movq 0x8f5a(%rip), %rdi      # 0x13fd0
callq 0x3040
movq %rax, %rdi
callq 0x3100
movq 0x8f56(%rip), %rdi      # 0x13fe0
movq %r14, %rsi
callq 0x31e0
xorl %r14d, %r14d
testl %r14d, %r14d
leaq -0x48(%rbp), %r14
jne 0xb13f
movq %r14, %rdi
leaq 0x3bf8(%rip), %rsi      # 0xeca4
callq 0x30a0
movq 0x10(%r15), %r12
testl %eax, %eax
je 0xb117
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 0x60a8
movq -0xc8(%rbp), %rdi
movl $0x1, %r14d
leaq -0xb8(%rbp), %rax
cmpq %rax, %rdi
je 0xb122
movq -0xb8(%rbp), %rsi
incq %rsi
callq 0x3190
jmp 0xb122
xorl %r14d, %r14d
movq %r12, %rdi
callq 0x5c1a
movq 0x8eb7(%rip), %rdi      # 0x13fe0
leaq -0x48(%rbp), %rsi
callq 0x31e0
jmp 0xb095
movq %r12, %rdi
callq 0x5eb6
movq (%r15), %r15
cmpq %rbx, %r15
jne 0xac0a
movq -0xd0(%rbp), %r15
movq 0x70(%r15), %rdi
callq 0xde04
cmpl $0x1, %eax
je 0xb170
movq %r15, %rdi
callq 0xa7f8
testl %eax, %eax
je 0xabba
movq 0x70(%r15), %rdi
callq 0xde04
cmpl $0x1, %eax
jne 0xb1eb
movl $0x11, %edx
movq 0x8e46(%rip), %rdi      # 0x13fd0
leaq 0x3bdc(%rip), %rsi      # 0xed6d
callq 0x31c0
movq 0x8e33(%rip), %rcx      # 0x13fd0
movq (%rcx), %rax
movq -0x18(%rax), %rdi
addq %rcx, %rdi
movl $0xa, %esi
callq 0x3160
movsbl %al, %esi
movq 0x8e15(%rip), %rdi      # 0x13fd0
callq 0x3040
movq %rax, %rdi
callq 0x3100
movq %rbx, %r14
movq (%r14), %r14
cmpq %rbx, %r14
je 0xabba
movq 0x10(%r14), %rdi
callq 0x608c
movq 0x10(%r14), %rdi
callq 0x6764
jmp 0xb1cb
movl $0x1e, %edx
movq 0x8dd9(%rip), %rdi      # 0x13fd0
leaq 0x3b81(%rip), %rsi      # 0xed7f
callq 0x31c0
movq 0x8dc6(%rip), %rcx      # 0x13fd0
movq (%rcx), %rax
movq -0x18(%rax), %rdi
addq %rcx, %rdi
movl $0xa, %esi
callq 0x3160
movsbl %al, %esi
movq 0x8da8(%rip), %rdi      # 0x13fd0
callq 0x3040
movq %rax, %rdi
callq 0x3100
movq %rbx, %r14
movq (%r14), %r14
cmpq %rbx, %r14
je 0xabba
movq 0x10(%r14), %rdi
callq 0x608c
movq 0x10(%r14), %rdi
callq 0x677c
jmp 0xb238
jmp 0xb2e4
movq %rax, %r14
movq -0x88(%rbp), %rdi
leaq -0x78(%rbp), %rax
cmpq %rax, %rdi
je 0xb2e7
movq -0x78(%rbp), %rsi
jmp 0xb2d2
jmp 0xb2e4
jmp 0xb2e4
jmp 0xb2e4
jmp 0xb2e4
jmp 0xb2e4
movq %rax, %r14
movq -0xa8(%rbp), %rdi
leaq -0x98(%rbp), %rax
cmpq %rax, %rdi
je 0xb2e7
movq -0x98(%rbp), %rsi
jmp 0xb2d2
movq %rax, %r14
movq -0xc8(%rbp), %rdi
leaq -0xb8(%rbp), %rax
cmpq %rax, %rdi
je 0xb2e7
movq -0xb8(%rbp), %rsi
jmp 0xb2d2
movq %rax, %r14
movq -0x68(%rbp), %rdi
leaq -0x58(%rbp), %rax
cmpq %rax, %rdi
je 0xb2e7
movq -0x58(%rbp), %rsi
incq %rsi
callq 0x3190
jmp 0xb2e7
jmp 0xb2e4
jmp 0xb2e4
jmp 0xb2e4
jmp 0xb2e4
movq %rax, %r14
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0xb300
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x3190
movq -0xe8(%rbp), %rdi
cmpq %rbx, %rdi
je 0xb321
movq (%rdi), %r15
movl $0x18, %esi
callq 0x3190
movq %r15, %rdi
cmpq %rbx, %r15
jne 0xb30c
movq %r14, %rdi
callq 0x3220
nop