// File: /workspace/github_cpp_makefile_star2_O2/Teris45[P]Maze-Game/Engine.cpp
// Function: Engine::Engine(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, char*)
Engine::Engine(const string& filename,const string& mybin, char *playersname) :moving(), poterakos(), goblinakos(), traalinakos(),hg(),username(playersname){

    curs_set(0);
    addstr("Welcome to the game young Mpampis\n\n");
    refresh();
    sleep(1);

    int xr,yr;
    getyx(stdscr,yr,xr);
    move(yr,0);
    clrtoeol();
    refresh();

    move(0,0);

    sleep(1);
    ifstream file(filename);
    string str;


    //Iterating through maze, and building it
    int y = 0;
    while (getline(file, str)){
        int x = 0;
        auto *line = new vector<int>;
        for(char i : str) {
            if (i == '*')
                line->insert(line->end(), WALL);
            else if (i == ' ') {
                line->insert(line->end(), DIADROMOS);
                Point p(x,y);
                this->available_points.push_back(p);
            }
            x++;
        }
        y++;
        this->maze.insert(this->maze.end(),*line);
    }
    this->last_row = y;
    this->poterakos.setPoint(available_points);
    this->maze[poterakos.getPoint().getY()][poterakos.getPoint().getX()] = POTERAKOS;


    this->goblinakos.setPoint(available_points);
    this->maze[goblinakos.getPoint().getY()][goblinakos.getPoint().getX()] = GOBLINAKOS;


    this->traalinakos.setPoint(available_points);
    this->maze[traalinakos.getPoint().getY()][traalinakos.getPoint().getX()] = TRAALINAKOS;

    for(auto & gem : this->gems) {
        gem.setPoint(available_points);
        this->maze[gem.getY()][gem.getX()] = GEM;
    }

    this->poterAlive = true;
    this->cntEatenGems = 0;
    this->winner = false;
    this->gameEnded = false;

//    mapUpdate();

    file.close();

    ifstream file2(mybin,ios::binary | ios::in);

    char c = file2.get();
    if(c==EOF){
        file2.close();
    }
    else{
        file2.close();
        ifstream  file3(mybin,ios::binary | ios::in);
        hg.load(file3);
        cout<<hg.toStr();
        file3.close();
    }


}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x688, %rsp            # imm = 0x688
movq %rcx, %r12
movq %rdx, -0x68(%rbp)
movq %rsi, %r15
movq %rdi, %rbx
leaq 0x18(%rdi), %rax
movq %rax, -0x38(%rbp)
addq $0x34, %rdi
xorps %xmm0, %xmm0
movups %xmm0, 0x20(%rbx)
movups %xmm0, 0x10(%rbx)
movups %xmm0, (%rbx)
movq %rbx, -0x30(%rbp)
callq 0x4814
leaq 0x38(%rbx), %rdi
movq %rdi, -0x50(%rbp)
callq 0x475e
leaq 0x50(%rbx), %rdi
movq %rdi, -0x48(%rbp)
callq 0x46f6
leaq 0x68(%rbx), %rdi
movq %rdi, -0x40(%rbp)
callq 0x472a
leaq 0x80(%rbx), %r14
xorl %ebx, %ebx
movq %r14, %rdi
callq 0x4fd0
addq $-0x10, %rbx
addq $0x10, %r14
cmpq $-0xa0, %rbx
jne 0x2a5c
movq -0x30(%rbp), %rbx
leaq 0x120(%rbx), %rdi
movq %rdi, -0x78(%rbp)
callq 0x4fd0
leaq 0x130(%rbx), %rdi
movq %rdi, -0x60(%rbp)
callq 0x50ce
leaq 0x178(%rbx), %rdi
leaq -0x6b0(%rbp), %rdx
movq %rdi, -0x70(%rbp)
movq %r12, %rsi
callq 0x2100
xorl %edi, %edi
callq 0x2190
movq 0x750f(%rip), %rbx      # 0x9fd0
movq (%rbx), %rdi
leaq 0x35b5(%rip), %rsi      # 0x6080
pushq $-0x1
popq %r14
movl %r14d, %edx
callq 0x20c0
callq 0x2370
pushq $0x1
popq %rdi
callq 0x2170
movq (%rbx), %rax
testq %rax, %rax
je 0x2af0
movswl (%rax), %r14d
movl %r14d, %edi
xorl %esi, %esi
callq 0x2160
movq (%rbx), %rdi
callq 0x2230
callq 0x2370
xorl %edi, %edi
xorl %esi, %esi
callq 0x2160
pushq $0x1
popq %rdi
callq 0x2170
leaq -0x6b0(%rbp), %rdi
pushq $0x8
popq %rdx
movq %r15, %rsi
callq 0x2340
leaq -0x88(%rbp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
movq $0x0, -0x58(%rbp)
leaq -0x2a0(%rbp), %r12
leaq -0x6b0(%rbp), %rdi
leaq -0x98(%rbp), %rsi
callq 0x2040
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x2c27
pushq $0x18
popq %rdi
callq 0x2200
movq %rax, %r13
andq $0x0, 0x10(%rax)
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movq -0x98(%rbp), %rbx
movq -0x90(%rbp), %r15
xorl %r14d, %r14d
cmpq %r14, %r15
je 0x2c08
movzbl (%rbx,%r14), %eax
cmpl $0x20, %eax
je 0x2bc7
cmpl $0x2a, %eax
jne 0x2c03
movq 0x8(%r13), %rsi
movl $0x1, -0x2a0(%rbp)
movq %r13, %rdi
movq %r12, %rdx
callq 0x3a62
jmp 0x2c03
movq 0x8(%r13), %rsi
movl $0x2, -0x2a0(%rbp)
movq %r13, %rdi
movq %r12, %rdx
callq 0x3a62
movq %r12, %rdi
movl %r14d, %esi
movq -0x58(%rbp), %rdx
callq 0x4652
movq -0x38(%rbp), %rdi
movq %r12, %rsi
callq 0x3734
movq %r12, %rdi
callq 0x4668
incq %r14
jmp 0x2b98
movq -0x30(%rbp), %rdi
movq 0x8(%rdi), %rsi
movq %r13, %rdx
callq 0x3768
movq -0x58(%rbp), %rax
incl %eax
movq %rax, -0x58(%rbp)
jmp 0x2b4c
movq -0x30(%rbp), %rax
movq -0x58(%rbp), %rcx
movl %ecx, 0x30(%rax)
movq -0x50(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x4590
leaq -0x2a0(%rbp), %rdi
movq -0x50(%rbp), %rsi
callq 0x4612
leaq -0x2a0(%rbp), %rdi
callq 0x4552
cltq
imulq $0x18, %rax, %rbx
movq -0x30(%rbp), %rax
addq (%rax), %rbx
leaq -0x4a8(%rbp), %rdi
movq -0x50(%rbp), %rsi
callq 0x4612
leaq -0x4a8(%rbp), %rdi
callq 0x453e
cltq
movq (%rbx), %rcx
movl $0x3, (%rcx,%rax,4)
leaq -0x4a8(%rbp), %rdi
callq 0x4668
leaq -0x2a0(%rbp), %rdi
callq 0x4668
movq -0x48(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x4590
leaq -0x2a0(%rbp), %rdi
movq -0x48(%rbp), %rsi
callq 0x4612
leaq -0x2a0(%rbp), %rdi
callq 0x4552
cltq
imulq $0x18, %rax, %rbx
movq -0x30(%rbp), %rax
addq (%rax), %rbx
leaq -0x4a8(%rbp), %rdi
movq -0x48(%rbp), %rsi
callq 0x4612
leaq -0x4a8(%rbp), %rdi
callq 0x453e
cltq
movq (%rbx), %rcx
movl $0x4, (%rcx,%rax,4)
leaq -0x4a8(%rbp), %rdi
callq 0x4668
leaq -0x2a0(%rbp), %rdi
callq 0x4668
movq -0x40(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x4590
leaq -0x2a0(%rbp), %rdi
movq -0x40(%rbp), %rsi
callq 0x4612
leaq -0x2a0(%rbp), %rdi
callq 0x4552
cltq
imulq $0x18, %rax, %rbx
movq -0x30(%rbp), %rax
addq (%rax), %rbx
leaq -0x4a8(%rbp), %rdi
movq -0x40(%rbp), %rsi
callq 0x4612
leaq -0x4a8(%rbp), %rdi
callq 0x453e
cltq
movq (%rbx), %rcx
movl $0x5, (%rcx,%rax,4)
leaq -0x4a8(%rbp), %rdi
callq 0x4668
leaq -0x2a0(%rbp), %rdi
callq 0x4668
movl $0x80, %ebx
cmpq $0x120, %rbx            # imm = 0x120
je 0x2dea
movq -0x30(%rbp), %rax
leaq (%rax,%rbx), %r14
movq %r14, %rdi
movq -0x38(%rbp), %rsi
callq 0x4fde
movq %r14, %rdi
callq 0x5056
movl %eax, %r15d
movq -0x30(%rbp), %rax
movq (%rax), %r12
movq %r14, %rdi
callq 0x5060
movslq %r15d, %rcx
imulq $0x18, %rcx, %rcx
cltq
movq (%r12,%rcx), %rcx
movl $0x6, (%rcx,%rax,4)
addq $0x10, %rbx
jmp 0x2d99
movq -0x30(%rbp), %rax
movw $0x1, 0x19c(%rax)
andl $0x0, 0x198(%rax)
movb $0x0, 0x19e(%rax)
leaq -0x6b0(%rbp), %rdi
callq 0x2050
leaq -0x2a0(%rbp), %rdi
pushq $0xc
popq %rdx
movq -0x68(%rbp), %rsi
callq 0x2340
leaq -0x2a0(%rbp), %rdi
callq 0x2270
cmpb $-0x1, %al
jne 0x2e42
leaq -0x2a0(%rbp), %rdi
callq 0x2050
jmp 0x2ea1
leaq -0x2a0(%rbp), %rdi
callq 0x2050
leaq -0x4a8(%rbp), %rdi
pushq $0xc
popq %rdx
movq -0x68(%rbp), %rsi
callq 0x2340
leaq -0x4a8(%rbp), %rsi
movq -0x60(%rbp), %rdi
callq 0x51d4
movq -0x60(%rbp), %rdi
callq 0x52b6
movq 0x7157(%rip), %rdi      # 0x9fd8
movq %rax, %rsi
callq 0x21f0
leaq -0x4a8(%rbp), %rdi
callq 0x2050
leaq -0x4a8(%rbp), %rdi
callq 0x2070
leaq -0x2a0(%rbp), %rdi
callq 0x2070
leaq -0x98(%rbp), %rdi
callq 0x2120
leaq -0x6b0(%rbp), %rdi
callq 0x2070
addq $0x688, %rsp            # imm = 0x688
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x2f61
jmp 0x2fc8
jmp 0x2f03
jmp 0x2fb7
jmp 0x2fb7
jmp 0x2fc8
jmp 0x2f03
jmp 0x2fb7
jmp 0x2fb7
jmp 0x2fc8
movq %rax, %r15
leaq -0x4a8(%rbp), %rdi
callq 0x4668
jmp 0x2fba
jmp 0x2fb7
jmp 0x2fb7
jmp 0x2fc8
jmp 0x2f7e
movq %rax, %r15
jmp 0x2fec
movq %rax, %r15
jmp 0x2ff5
movq %rax, %r15
jmp 0x2ffe
movq %rax, %r15
jmp 0x3023
movq %rax, %r15
jmp 0x302c
movq %rax, %r15
leaq -0x4a8(%rbp), %rdi
callq 0x2070
jmp 0x2f64
movq %rax, %r15
leaq -0x2a0(%rbp), %rdi
callq 0x2070
jmp 0x2fcb
movq %rax, %r15
jmp 0x3035
jmp 0x2fc8
jmp 0x2f7e
movq %rax, %r15
jmp 0x2fe3
jmp 0x2fc8
jmp 0x2fc8
jmp 0x2fc8
movq %rax, %r15
testq %rbx, %rbx
je 0x301a
negq %rbx
movq -0x30(%rbp), %rax
leaq 0x70(%rax), %r14
leaq (%r14,%rbx), %rdi
callq 0x4668
addq $-0x10, %rbx
jne 0x2fa0
jmp 0x301a
jmp 0x2fc8
jmp 0x2fc8
jmp 0x2fc8
movq %rax, %r15
leaq -0x2a0(%rbp), %rdi
callq 0x4668
jmp 0x2fcb
movq %rax, %r15
leaq -0x98(%rbp), %rdi
callq 0x2120
leaq -0x6b0(%rbp), %rdi
callq 0x2070
movq -0x70(%rbp), %rdi
callq 0x2120
movq -0x60(%rbp), %rdi
callq 0x54e6
movq -0x78(%rbp), %rdi
callq 0x4668
movl $0x110, %ebx            # imm = 0x110
movq -0x30(%rbp), %r14
leaq (%r14,%rbx), %rdi
callq 0x4668
addq $-0x10, %rbx
cmpq $0x70, %rbx
jne 0x3007
movq -0x40(%rbp), %rdi
callq 0x462e
movq -0x48(%rbp), %rdi
callq 0x462e
movq -0x50(%rbp), %rdi
callq 0x462e
movq -0x38(%rbp), %rdi
callq 0x3804
movq -0x30(%rbp), %rdi
callq 0x3830
movq %r15, %rdi
callq 0x23b0
nop