// File: /workspace/github_cpp_makefile_star2_O3/hobbitsyfeet[P]Turn/chart.cc
// Function: Chart::loadWorld(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
void Chart::loadWorld(string name){
  //INITIALISATION
  vector<vector<container> >::iterator row;
  vector<container>::iterator col;
  //type of block to set it as
  container block, block_reset;
  char inChar;
  int x, y, i;
  int posXPortal = 0,posYPortal = 0,numPortal;
  string option ="";
  //END OF INITIALIZATION;
  //set name of loaded world
  //this->worldName = name;

  ifstream fin;
  fin.open(("./maps/" + name + ".txt").c_str());

  //Prevent crash by selecting an existing file
  while(fin.fail()){
    cout<<"invalid file, enter a file>> ";
    cin>>name;
    fin.open(("./maps/" + name + ".txt").c_str());
  }

  cout<<"Loading map..."<<endl;
  this->worldName = name;
  fin>>x>>y;

  //creates 2D vector of size x,y
  world.clear();
  world.resize(x, vector<container>(y));

  fin>>fogOfWar;
  //number or portals in a map
  option="";
  fin>>numPortal;
  //arrays for multiple portals
  int portalx [numPortal];
  int portaly [numPortal];
  string *portalNames = new string[numPortal];

  //setting portal name and coords into arrays
  for(int i = 0; i<numPortal; i++){
    fin>>posXPortal>>posYPortal>>option;
    portalx[i] = posXPortal;
    portaly[i]=posYPortal;
    portalNames[i] = option;
  }
  // MAP LOADS	//
  //->			//
  //   ->			//
  //		->		//
  //			->	//

  //iterates through and sets type
  //start on the left
  x=1;
  //when reach end of row, go to next, top left
  for(row = world.begin(); row < world.end() ; row++){
    //on each row, go through each column left to right
    for(col = row->begin(); col< row->end(); col++){
      //gets type
      fin.ignore();
      fin>>block.geoType;
      if(block.checkAvailable()==true)
	block.occupied=false;
      else
	block.occupied=true;

      //portal
      //the for loop iterates through portal list
      //so no need to care for initialization order (top left to bottom right)
      for(int i = 0; i<numPortal; i++){
	if( (portalx[i] == x) && (portaly[i] == y) ){
	  block.link = portalNames[i];
	  //dont know why i++ here fixes it but it does...?
	  i++;
	}
	else{
	  block.link = "";
	}
      }
      block.posX = x;
      block.posY = y;
      //assign the map iterator to
      *col= block;
      block = block_reset;

      //move to next column
      x++;
    }
    //start at first column
    x=1;
    //move down a row
    y--;
  }
  delete [] portalNames;
  fin.close();
  cout<<"Done Loading."<<endl;

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x318, %rsp            # imm = 0x318
movq %rsi, %r14
movq %rdi, -0x40(%rbp)
leaq -0xb0(%rbp), %rcx
movq %rcx, -0x10(%rcx)
xorl %eax, %eax
movq %rax, -0x8(%rcx)
movb %al, (%rcx)
leaq -0x110(%rbp), %rcx
movq %rcx, -0x10(%rcx)
movq %rax, -0x8(%rcx)
movb %al, (%rcx)
movl %eax, -0x48(%rbp)
movl %eax, -0x44(%rbp)
leaq -0xe0(%rbp), %rax
movq %rax, -0x10(%rax)
leaq 0x392d(%rip), %rdx      # 0xb4f4
leaq -0xf0(%rbp), %rdi
movq %rdx, %rsi
callq 0x351a
leaq -0x338(%rbp), %rdi
callq 0x2220
leaq 0x3b07(%rip), %rsi      # 0xb6f0
leaq -0x88(%rbp), %rdi
movq %r14, %rdx
callq 0x58c9
leaq 0x3447(%rip), %rsi      # 0xb046
leaq -0x88(%rbp), %rdi
callq 0x2350
leaq -0x58(%rbp), %r13
movq %r13, -0x10(%r13)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x7c2f
movq %rdx, -0x68(%rbp)
movq (%rcx), %rdx
movq %rdx, -0x58(%rbp)
jmp 0x7c37
movups (%rcx), %xmm0
movups %xmm0, (%r13)
movq 0x8(%rax), %rdx
movq %rdx, -0x60(%rbp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movq -0x68(%rbp), %rsi
leaq -0x338(%rbp), %rdi
movl $0x8, %edx
callq 0x2160
movq -0x68(%rbp), %rdi
cmpq %r13, %rdi
je 0x7c78
movq -0x58(%rbp), %rsi
incq %rsi
callq 0x2200
leaq -0x78(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x7c91
movq -0x78(%rbp), %rsi
incq %rsi
callq 0x2200
movq -0x338(%rbp), %rax
movq -0x18(%rax), %rax
testb $0x5, -0x318(%rbp,%rax)
je 0x7d9d
leaq -0x88(%rbp), %rbx
leaq 0x338e(%rip), %r15      # 0xb046
leaq -0x338(%rbp), %r12
movl $0x1d, %edx
movq 0x7305(%rip), %rdi      # 0xefd0
leaq 0x3a26(%rip), %rsi      # 0xb6f8
callq 0x2230
movq 0x7302(%rip), %rdi      # 0xefe0
movq %r14, %rsi
callq 0x2250
movq %rbx, %rdi
leaq 0x3a00(%rip), %rsi      # 0xb6f0
movq %r14, %rdx
callq 0x58c9
movq %rbx, %rdi
movq %r15, %rsi
callq 0x2350
movq %r13, -0x68(%rbp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x7d23
movq %rdx, -0x68(%rbp)
movq (%rcx), %rdx
movq %rdx, -0x58(%rbp)
jmp 0x7d2b
movups (%rcx), %xmm0
movups %xmm0, (%r13)
movq 0x8(%rax), %rdx
movq %rdx, -0x60(%rbp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movq -0x68(%rbp), %rsi
movq %r12, %rdi
movl $0x8, %edx
callq 0x2160
movq -0x68(%rbp), %rdi
cmpq %r13, %rdi
je 0x7d68
movq -0x58(%rbp), %rsi
incq %rsi
callq 0x2200
movq -0x88(%rbp), %rdi
leaq -0x78(%rbp), %rax
cmpq %rax, %rdi
je 0x7d84
movq -0x78(%rbp), %rsi
incq %rsi
callq 0x2200
movq -0x338(%rbp), %rax
movq -0x18(%rax), %rax
testb $0x5, -0x318(%rbp,%rax)
jne 0x7cbf
movq 0x722c(%rip), %rbx      # 0xefd0
leaq 0x396b(%rip), %rsi      # 0xb716
movl $0xe, %edx
movq %rbx, %rdi
callq 0x2230
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x21e0
movsbl %al, %esi
movq 0x71fa(%rip), %rdi      # 0xefd0
callq 0x2040
movq %rax, %rdi
callq 0x2170
movq -0x40(%rbp), %rax
leaq 0x18(%rax), %rdi
movq %r14, %rsi
callq 0x2140
leaq -0x338(%rbp), %rdi
leaq -0x2c(%rbp), %rsi
callq 0x2150
leaq -0x34(%rbp), %rsi
movq %rax, %rdi
callq 0x2150
movq -0x40(%rbp), %rax
movq (%rax), %r14
movq 0x8(%rax), %r15
cmpq %r14, %r15
je 0x7e3b
movq %r14, %rbx
movq %rbx, %rdi
callq 0x7a6e
addq $0x18, %rbx
cmpq %r15, %rbx
jne 0x7e22
movq -0x40(%rbp), %rax
movq %r14, 0x8(%rax)
movslq -0x2c(%rbp), %rbx
movslq -0x34(%rbp), %rsi
leaq -0x68(%rbp), %rdi
leaq -0x88(%rbp), %rdx
callq 0x89cc
leaq -0x68(%rbp), %rdx
movq -0x40(%rbp), %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0x8950
leaq -0x68(%rbp), %rdi
callq 0x7a6e
leaq 0x38(%r14), %rsi
leaq -0x338(%rbp), %rdi
callq 0x21c0
leaq -0xf0(%rbp), %rdi
movq 0x8(%rdi), %rdx
leaq 0x3663(%rip), %rcx      # 0xb4f4
xorl %esi, %esi
xorl %r8d, %r8d
callq 0x22b0
leaq -0x338(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x2150
movq %rsp, -0xf8(%rbp)
movl -0x30(%rbp), %eax
movq %rsp, %rbx
leaq 0xf(,%rax,4), %rax
andq $-0x10, %rax
subq %rax, %rbx
movq %rbx, %rsp
movslq -0x30(%rbp), %r14
movl %r14d, %eax
movq %rsp, %rcx
leaq 0xf(,%rax,4), %rax
andq $-0x10, %rax
subq %rax, %rcx
movq %rcx, -0xa0(%rbp)
movq %rcx, %rsp
movq %r14, %r15
shlq $0x5, %r15
leaq 0x8(%r15), %rax
testq %r14, %r14
movq $-0x1, %rdi
cmovnsq %rax, %rdi
callq 0x2030
movq %rax, %r13
movq %r14, (%rax)
addq $0x8, %rax
movq %rax, -0x98(%rbp)
testl %r14d, %r14d
je 0x7faf
leaq 0x18(%r13), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
addq $0x20, %rax
addq $-0x20, %r15
jne 0x7f29
testl %r14d, %r14d
jle 0x7faf
xorl %r14d, %r14d
leaq -0xf0(%rbp), %r12
movq -0x98(%rbp), %r15
leaq -0x338(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0x2150
movq %rax, %rdi
leaq -0x44(%rbp), %rsi
callq 0x2150
movq %rax, %rdi
movq %r12, %rsi
callq 0x2250
movl -0x48(%rbp), %eax
movl %eax, (%rbx,%r14,4)
movl -0x44(%rbp), %eax
movq -0xa0(%rbp), %rcx
movl %eax, (%rcx,%r14,4)
movq %r15, %rdi
movq %r12, %rsi
callq 0x2140
incq %r14
movslq -0x30(%rbp), %rax
addq $0x20, %r15
cmpq %rax, %r14
jl 0x7f58
movl $0x1, -0x2c(%rbp)
movq -0x40(%rbp), %rax
movq (%rax), %rcx
movq 0x8(%rax), %rax
cmpq %rax, %rcx
jae 0x8125
leaq -0xc0(%rbp), %r15
leaq 0x351c(%rip), %r12      # 0xb4f4
movq %r13, -0x100(%rbp)
movq (%rcx), %r14
cmpq 0x8(%rcx), %r14
jae 0x810e
movq %rcx, -0x90(%rbp)
leaq -0x338(%rbp), %rdi
callq 0x2340
leaq -0x338(%rbp), %rdi
leaq -0xc7(%rbp), %rsi
callq 0x2260
leaq -0xd0(%rbp), %rdi
callq 0x834c
xorb $0x1, %al
movb %al, -0xc8(%rbp)
cmpl $0x0, -0x30(%rbp)
jle 0x8081
xorl %r13d, %r13d
movslq %r13d, %rsi
movl (%rbx,%rsi,4), %eax
cmpl -0x2c(%rbp), %eax
jne 0x8061
movq -0xa0(%rbp), %rax
movl (%rax,%rsi,4), %eax
cmpl -0x34(%rbp), %eax
jne 0x8061
shlq $0x5, %rsi
addq -0x98(%rbp), %rsi
movq %r15, %rdi
callq 0x2140
incl %r13d
jmp 0x8078
movq -0xb8(%rbp), %rdx
movq %r15, %rdi
xorl %esi, %esi
movq %r12, %rcx
xorl %r8d, %r8d
callq 0x22b0
incl %r13d
cmpl -0x30(%rbp), %r13d
jl 0x802f
movl -0x2c(%rbp), %eax
movl %eax, -0xd0(%rbp)
movl -0x34(%rbp), %eax
movl %eax, -0xcc(%rbp)
movzwl -0xc8(%rbp), %eax
movw %ax, 0x8(%r14)
movq -0xd0(%rbp), %rax
movq %rax, (%r14)
leaq 0x10(%r14), %rdi
movq %r15, %rsi
callq 0x2140
movzwl -0x128(%rbp), %eax
movw %ax, -0xc8(%rbp)
movq -0x130(%rbp), %rax
movq %rax, -0xd0(%rbp)
movq %r15, %rdi
leaq -0x120(%rbp), %rsi
callq 0x2140
incl -0x2c(%rbp)
addq $0x30, %r14
movq -0x90(%rbp), %rax
cmpq 0x8(%rax), %r14
movq -0x100(%rbp), %r13
jb 0x7ff3
movq -0x40(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x90(%rbp), %rcx
decl -0x34(%rbp)
movl $0x1, -0x2c(%rbp)
addq $0x18, %rcx
cmpq %rax, %rcx
jb 0x7fdf
movq (%r13), %rax
movq %rax, %r14
shlq $0x5, %r14
leaq 0x8(%r14), %rbx
testq %rax, %rax
je 0x815f
movq %r13, %r15
addq $-0x8, %r15
leaq (%r15,%r14), %rax
movq -0x10(%r15,%r14), %rdi
cmpq %rdi, %rax
je 0x8159
movq (%rax), %rsi
incq %rsi
callq 0x2200
addq $-0x20, %r14
jne 0x8140
movq %r13, %rdi
movq %rbx, %rsi
callq 0x2360
leaq -0x338(%rbp), %rdi
callq 0x2080
movq 0x6e53(%rip), %rbx      # 0xefd0
leaq 0x35a1(%rip), %rsi      # 0xb725
movl $0xd, %edx
movq %rbx, %rdi
callq 0x2230
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x21e0
movsbl %al, %esi
movq 0x6e21(%rip), %rdi      # 0xefd0
callq 0x2040
movq %rax, %rdi
callq 0x2170
movq -0xf8(%rbp), %rsp
leaq -0x338(%rbp), %rdi
callq 0x2090
movq -0xf0(%rbp), %rdi
leaq -0xe0(%rbp), %rax
cmpq %rax, %rdi
je 0x81f1
movq -0xe0(%rbp), %rsi
incq %rsi
callq 0x2200
movq -0x120(%rbp), %rdi
leaq -0x110(%rbp), %rax
cmpq %rax, %rdi
je 0x8213
movq -0x110(%rbp), %rsi
incq %rsi
callq 0x2200
movq -0xc0(%rbp), %rdi
leaq -0xb0(%rbp), %rax
cmpq %rax, %rdi
je 0x8235
movq -0xb0(%rbp), %rsi
incq %rsi
callq 0x2200
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq -0x68(%rbp), %rdi
callq 0x7a6e
jmp 0x82d1
jmp 0x82ce
movq %rax, %rbx
movq -0x68(%rbp), %rdi
cmpq %r13, %rdi
je 0x8271
movq -0x58(%rbp), %rsi
incq %rsi
callq 0x2200
jmp 0x8271
movq %rax, %rbx
leaq -0x78(%rbp), %rax
movq -0x10(%rax), %rdi
jmp 0x82b3
jmp 0x82ce
movq %rax, %rbx
jmp 0x82dd
movq %rax, %rbx
jmp 0x82ff
jmp 0x82ce
jmp 0x82ce
movq %rax, %rbx
movq -0x68(%rbp), %rdi
cmpq %r13, %rdi
je 0x82a8
movq -0x58(%rbp), %rsi
incq %rsi
callq 0x2200
jmp 0x82a8
movq %rax, %rbx
movq -0x88(%rbp), %rdi
leaq -0x78(%rbp), %rax
cmpq %rax, %rdi
je 0x82d1
movq -0x78(%rbp), %rsi
incq %rsi
callq 0x2200
jmp 0x82d1
jmp 0x82ce
jmp 0x82ce
jmp 0x82ce
jmp 0x82ce
movq %rax, %rbx
leaq -0x338(%rbp), %rdi
callq 0x2090
movq -0xf0(%rbp), %rdi
leaq -0xe0(%rbp), %rax
cmpq %rax, %rdi
je 0x82ff
movq -0xe0(%rbp), %rsi
incq %rsi
callq 0x2200
movq -0x120(%rbp), %rdi
leaq -0x110(%rbp), %rax
cmpq %rax, %rdi
je 0x8321
movq -0x110(%rbp), %rsi
incq %rsi
callq 0x2200
movq -0xc0(%rbp), %rdi
leaq -0xb0(%rbp), %rax
cmpq %rax, %rdi
je 0x8343
movq -0xb0(%rbp), %rsi
incq %rsi
callq 0x2200
movq %rbx, %rdi
callq 0x2310
nop