// File: /workspace/github_cpp_makefile_star2_O1/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 0x5a10
leaq 0x38(%rbx), %rdi
movq %rdi, -0x50(%rbp)
callq 0x5976
leaq 0x50(%rbx), %rdi
movq %rdi, -0x48(%rbp)
callq 0x58fa
leaq 0x68(%rbx), %rdi
movq %rdi, -0x40(%rbp)
callq 0x5938
leaq 0x80(%rbx), %r14
xorl %ebx, %ebx
movq %r14, %rdi
callq 0x61e4
addq $-0x10, %rbx
addq $0x10, %r14
cmpq $-0xa0, %rbx
jne 0x3b5e
movq -0x30(%rbp), %rbx
leaq 0x120(%rbx), %rdi
movq %rdi, -0x90(%rbp)
callq 0x61e4
leaq 0x130(%rbx), %rdi
movq %rdi, -0x60(%rbp)
callq 0x62d4
leaq 0x178(%rbx), %rdi
leaq -0x6a8(%rbp), %rdx
movq %r12, %rsi
callq 0x3110
xorl %edi, %edi
callq 0x31c0
movq 0x640e(%rip), %rbx      # 0x9fd0
movq (%rbx), %rdi
leaq 0x34b4(%rip), %rsi      # 0x7080
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x30d0
callq 0x33b0
movl $0x1, %edi
callq 0x3190
movq (%rbx), %rax
testq %rax, %rax
je 0x3bf2
movswl (%rax), %edi
jmp 0x3bf7
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
xorl %esi, %esi
callq 0x3170
movq (%rbx), %rdi
callq 0x3260
callq 0x33b0
xorl %edi, %edi
xorl %esi, %esi
callq 0x3170
movl $0x1, %edi
callq 0x3190
leaq -0x6a8(%rbp), %rbx
movq %rbx, %rdi
movq %r15, %rsi
movl $0x8, %edx
callq 0x3370
leaq -0x78(%rbp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
movq $0x0, -0x58(%rbp)
leaq -0x298(%rbp), %r13
movq -0x6a8(%rbp), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3220
movsbl %al, %edx
movq %rbx, %rdi
leaq -0x88(%rbp), %rsi
callq 0x3410
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x3d57
movl $0x18, %edi
callq 0x3230
movq %rax, %r12
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movq $0x0, 0x10(%rax)
movq -0x80(%rbp), %rbx
testq %rbx, %rbx
je 0x3d31
movq -0x88(%rbp), %r15
xorl %r14d, %r14d
movzbl (%r15,%r14), %eax
cmpl $0x20, %eax
je 0x3cec
cmpl $0x2a, %eax
jne 0x3d29
movq 0x8(%r12), %rsi
movl $0x1, -0x298(%rbp)
movq %r12, %rdi
movq %r13, %rdx
callq 0x4daa
jmp 0x3d29
movq 0x8(%r12), %rsi
movl $0x2, -0x298(%rbp)
movq %r12, %rdi
movq %r13, %rdx
callq 0x4daa
movq %r13, %rdi
movl %r14d, %esi
movq -0x58(%rbp), %rdx
callq 0x5826
movq -0x38(%rbp), %rdi
movq %r13, %rsi
callq 0x49ba
movq %r13, %rdi
callq 0x583c
incq %r14
cmpq %r14, %rbx
jne 0x3cc1
movq -0x30(%rbp), %rdi
movq 0x8(%rdi), %rsi
movq %r12, %rdx
callq 0x49ee
movq -0x58(%rbp), %rax
incl %eax
movq %rax, -0x58(%rbp)
leaq -0x6a8(%rbp), %rbx
jmp 0x3c57
movq -0x30(%rbp), %rax
movq -0x58(%rbp), %rcx
movl %ecx, 0x30(%rax)
movq -0x50(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x575a
leaq -0x298(%rbp), %rdi
movq -0x50(%rbp), %rsi
callq 0x57e0
leaq -0x298(%rbp), %rdi
callq 0x571c
cltq
leaq (%rax,%rax,2), %rbx
shlq $0x3, %rbx
movq -0x30(%rbp), %rax
addq (%rax), %rbx
leaq -0x4a0(%rbp), %rdi
movq -0x50(%rbp), %rsi
callq 0x57e0
leaq -0x4a0(%rbp), %rdi
callq 0x5708
cltq
movq (%rbx), %rcx
movl $0x3, (%rcx,%rax,4)
leaq -0x4a0(%rbp), %rdi
callq 0x583c
leaq -0x298(%rbp), %rdi
callq 0x583c
movq -0x48(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x575a
leaq -0x298(%rbp), %rdi
movq -0x48(%rbp), %rsi
callq 0x57e0
leaq -0x298(%rbp), %rdi
callq 0x571c
cltq
leaq (%rax,%rax,2), %rbx
shlq $0x3, %rbx
movq -0x30(%rbp), %rax
addq (%rax), %rbx
leaq -0x4a0(%rbp), %rdi
movq -0x48(%rbp), %rsi
callq 0x57e0
leaq -0x4a0(%rbp), %rdi
callq 0x5708
cltq
movq (%rbx), %rcx
movl $0x4, (%rcx,%rax,4)
leaq -0x4a0(%rbp), %rdi
callq 0x583c
leaq -0x298(%rbp), %rdi
callq 0x583c
movq -0x40(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x575a
leaq -0x298(%rbp), %rdi
movq -0x40(%rbp), %rsi
callq 0x57e0
leaq -0x298(%rbp), %rdi
callq 0x571c
cltq
leaq (%rax,%rax,2), %rbx
shlq $0x3, %rbx
movq -0x30(%rbp), %rax
addq (%rax), %rbx
leaq -0x4a0(%rbp), %rdi
movq -0x40(%rbp), %rsi
callq 0x57e0
leaq -0x4a0(%rbp), %rdi
callq 0x5708
cltq
movq (%rbx), %rcx
movl $0x5, (%rcx,%rax,4)
leaq -0x4a0(%rbp), %rdi
callq 0x583c
leaq -0x298(%rbp), %rdi
callq 0x583c
movl $0x80, %ebx
movq -0x30(%rbp), %rax
leaq (%rax,%rbx), %r14
movq %r14, %rdi
movq -0x38(%rbp), %rsi
callq 0x61f2
movq %r14, %rdi
callq 0x626a
movl %eax, %r15d
movq -0x30(%rbp), %rax
movq (%rax), %r12
movq %r14, %rdi
callq 0x6274
movslq %r15d, %rcx
leaq (%rcx,%rcx,2), %rcx
cltq
movq (%r12,%rcx,8), %rcx
movl $0x6, (%rcx,%rax,4)
addq $0x10, %rbx
cmpq $0x120, %rbx            # imm = 0x120
jne 0x3ed5
movq -0x30(%rbp), %rax
movw $0x1, 0x19c(%rax)
movl $0x0, 0x198(%rax)
movb $0x0, 0x19e(%rax)
leaq -0x6a8(%rbp), %rdi
callq 0x3050
leaq -0x298(%rbp), %rdi
movq -0x68(%rbp), %rsi
movl $0xc, %edx
callq 0x3370
leaq -0x298(%rbp), %rdi
callq 0x32c0
cmpb $-0x1, %al
jne 0x3f84
leaq -0x298(%rbp), %rdi
callq 0x3050
jmp 0x4018
leaq -0x298(%rbp), %rdi
callq 0x3050
leaq -0x4a0(%rbp), %rdi
movq -0x68(%rbp), %rsi
movl $0xc, %edx
callq 0x3370
leaq -0x4a0(%rbp), %rsi
movq -0x60(%rbp), %rdi
callq 0x646c
movq -0x60(%rbp), %rdi
callq 0x65a2
movq %rax, %r14
testq %rax, %rax
je 0x3fe2
movq %r14, %rdi
callq 0x3130
movq 0x6003(%rip), %rdi      # 0x9fd8
movq %r14, %rsi
movq %rax, %rdx
callq 0x3280
jmp 0x4000
movq 0x5fef(%rip), %rax      # 0x9fd8
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
leaq (%rax,%rcx), %rdi
movl 0x20(%rax,%rcx), %esi
orl $0x1, %esi
callq 0x33a0
leaq -0x4a0(%rbp), %rdi
callq 0x3050
leaq -0x4a0(%rbp), %rdi
callq 0x3060
leaq -0x298(%rbp), %rdi
callq 0x3060
movq -0x88(%rbp), %rdi
leaq -0x78(%rbp), %rax
cmpq %rax, %rdi
je 0x4040
movq -0x78(%rbp), %rsi
incq %rsi
callq 0x3240
leaq -0x6a8(%rbp), %rdi
callq 0x3060
addq $0x688, %rsp            # imm = 0x688
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x40e8
jmp 0x4152
jmp 0x408a
jmp 0x4141
jmp 0x4141
jmp 0x4152
jmp 0x408a
jmp 0x4141
jmp 0x4141
jmp 0x4152
movq %rax, %r15
leaq -0x4a0(%rbp), %rdi
callq 0x583c
jmp 0x4144
jmp 0x4141
jmp 0x4141
jmp 0x4152
jmp 0x4105
movq %rax, %r15
jmp 0x419e
movq %rax, %r15
jmp 0x41a7
movq %rax, %r15
jmp 0x41b3
movq %rax, %r15
jmp 0x41d8
movq %rax, %r15
jmp 0x41e1
movq %rax, %r15
leaq -0x4a0(%rbp), %rdi
callq 0x3060
jmp 0x40eb
movq %rax, %r15
leaq -0x298(%rbp), %rdi
callq 0x3060
jmp 0x4155
movq %rax, %r15
jmp 0x41ea
jmp 0x4152
jmp 0x4105
movq %rax, %r15
jmp 0x417d
jmp 0x4152
jmp 0x4152
movq %rax, %r15
testq %rbx, %rbx
je 0x41cf
negq %rbx
movq -0x30(%rbp), %rax
leaq 0x70(%rax), %r14
leaq (%r14,%rbx), %rdi
callq 0x583c
addq $-0x10, %rbx
jne 0x4125
jmp 0x41cf
jmp 0x4152
jmp 0x4152
jmp 0x4152
jmp 0x4152
movq %rax, %r15
leaq -0x298(%rbp), %rdi
callq 0x583c
jmp 0x4155
movq %rax, %r15
movq -0x88(%rbp), %rdi
leaq -0x78(%rbp), %rax
cmpq %rax, %rdi
je 0x4171
movq -0x78(%rbp), %rsi
incq %rsi
callq 0x3240
leaq -0x6a8(%rbp), %rdi
callq 0x3060
movq -0x30(%rbp), %rax
movq 0x178(%rax), %rdi
addq $0x188, %rax            # imm = 0x188
cmpq %rax, %rdi
je 0x419e
movq (%rax), %rsi
incq %rsi
callq 0x3240
movq -0x60(%rbp), %rdi
callq 0x6b44
movq -0x90(%rbp), %rdi
callq 0x583c
movl $0x110, %ebx            # imm = 0x110
movq -0x30(%rbp), %r14
leaq (%r14,%rbx), %rdi
callq 0x583c
addq $-0x10, %rbx
cmpq $0x70, %rbx
jne 0x41bc
movq -0x40(%rbp), %rdi
callq 0x57fc
movq -0x48(%rbp), %rdi
callq 0x57fc
movq -0x50(%rbp), %rdi
callq 0x57fc
movq -0x38(%rbp), %rdi
callq 0x4aa4
movq -0x30(%rbp), %rdi
callq 0x4af4
movq %r15, %rdi
callq 0x33f0