// File: /workspace/github_cpp_makefile_star2_O1/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 -0xa0(%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, -0x50(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0xe8(%rbp), %rax
movq %rax, -0x10(%rax)
leaq 0x3989(%rip), %rdx      # 0xb4f4
leaq -0xf8(%rbp), %rdi
movq %rdx, %rsi
callq 0x34e4
leaq -0x338(%rbp), %rdi
callq 0x2230
leaq 0x3b53(%rip), %rsi      # 0xb6e0
leaq -0x90(%rbp), %rdi
movq %r14, %rdx
callq 0x58b7
leaq 0x34a3(%rip), %rsi      # 0xb046
leaq -0x90(%rbp), %rdi
callq 0x2360
leaq -0x60(%rbp), %r13
movq %r13, -0x10(%r13)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x7bd3
movq %rdx, -0x70(%rbp)
movq (%rcx), %rdx
movq %rdx, -0x60(%rbp)
jmp 0x7bdb
movups (%rcx), %xmm0
movups %xmm0, (%r13)
movq 0x8(%rax), %rdx
movq %rdx, -0x68(%rbp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movq -0x70(%rbp), %rsi
leaq -0x338(%rbp), %rdi
movl $0x8, %edx
callq 0x2160
movq -0x70(%rbp), %rdi
cmpq %r13, %rdi
je 0x7c1c
movq -0x60(%rbp), %rsi
incq %rsi
callq 0x2210
leaq -0x80(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x7c35
movq -0x80(%rbp), %rsi
incq %rsi
callq 0x2210
movq -0x338(%rbp), %rax
movq -0x18(%rax), %rax
testb $0x5, -0x318(%rbp,%rax)
je 0x7d41
leaq -0x90(%rbp), %rbx
leaq 0x33ea(%rip), %r15      # 0xb046
leaq -0x338(%rbp), %r12
movl $0x1d, %edx
movq 0x7361(%rip), %rdi      # 0xefd0
leaq 0x3a72(%rip), %rsi      # 0xb6e8
callq 0x2240
movq 0x735e(%rip), %rdi      # 0xefe0
movq %r14, %rsi
callq 0x2260
movq %rbx, %rdi
leaq 0x3a4c(%rip), %rsi      # 0xb6e0
movq %r14, %rdx
callq 0x58b7
movq %rbx, %rdi
movq %r15, %rsi
callq 0x2360
movq %r13, -0x70(%rbp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x7cc7
movq %rdx, -0x70(%rbp)
movq (%rcx), %rdx
movq %rdx, -0x60(%rbp)
jmp 0x7ccf
movups (%rcx), %xmm0
movups %xmm0, (%r13)
movq 0x8(%rax), %rdx
movq %rdx, -0x68(%rbp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movq -0x70(%rbp), %rsi
movq %r12, %rdi
movl $0x8, %edx
callq 0x2160
movq -0x70(%rbp), %rdi
cmpq %r13, %rdi
je 0x7d0c
movq -0x60(%rbp), %rsi
incq %rsi
callq 0x2210
movq -0x90(%rbp), %rdi
leaq -0x80(%rbp), %rax
cmpq %rax, %rdi
je 0x7d28
movq -0x80(%rbp), %rsi
incq %rsi
callq 0x2210
movq -0x338(%rbp), %rax
movq -0x18(%rax), %rax
testb $0x5, -0x318(%rbp,%rax)
jne 0x7c63
movq 0x7288(%rip), %rbx      # 0xefd0
leaq 0x39b7(%rip), %rsi      # 0xb706
movl $0xe, %edx
movq %rbx, %rdi
callq 0x2240
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x21f0
movsbl %al, %esi
movq 0x7256(%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 -0x30(%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 0x7ddf
movq %r14, %rbx
movq %rbx, %rdi
callq 0x7a14
addq $0x18, %rbx
cmpq %r15, %rbx
jne 0x7dc6
movq -0x40(%rbp), %rax
movq %r14, 0x8(%rax)
movslq -0x30(%rbp), %rbx
movslq -0x34(%rbp), %rsi
leaq -0x70(%rbp), %rdi
leaq -0x90(%rbp), %rdx
callq 0x89aa
leaq -0x70(%rbp), %rdx
movq -0x40(%rbp), %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0x892e
leaq -0x70(%rbp), %rdi
callq 0x7a14
leaq 0x38(%r14), %rsi
leaq -0x338(%rbp), %rdi
callq 0x21d0
leaq -0xf8(%rbp), %rdi
movq 0x8(%rdi), %rdx
leaq 0x36bf(%rip), %rcx      # 0xb4f4
xorl %esi, %esi
xorl %r8d, %r8d
callq 0x22c0
leaq -0x338(%rbp), %rdi
leaq -0x2c(%rbp), %rsi
callq 0x2150
movq %rsp, -0x100(%rbp)
movl -0x2c(%rbp), %eax
movq %rsp, %rbx
leaq 0xf(,%rax,4), %rax
andq $-0x10, %rax
subq %rax, %rbx
movq %rbx, %rsp
movslq -0x2c(%rbp), %r15
movl %r15d, %eax
movq %rsp, %rcx
leaq 0xf(,%rax,4), %rax
andq $-0x10, %rax
subq %rax, %rcx
movq %rcx, -0xd8(%rbp)
movq %rcx, %rsp
movq %r15, %r14
shlq $0x5, %r14
leaq 0x8(%r14), %rax
testq %r15, %r15
movq $-0x1, %rdi
cmovnsq %rax, %rdi
callq 0x2030
movq %rax, -0x48(%rbp)
movq %r15, (%rax)
testl %r15d, %r15d
je 0x7edc
movq -0x48(%rbp), %rax
addq $0x18, %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
addq $0x20, %rax
addq $-0x20, %r14
jne 0x7ec3
movq -0x48(%rbp), %rax
addq $0x8, %rax
movq %rax, -0xd0(%rbp)
cmpl $0x0, -0x2c(%rbp)
movq -0x40(%rbp), %r14
jle 0x7f5d
xorl %r13d, %r13d
leaq -0xf8(%rbp), %r12
movq -0xd0(%rbp), %r15
leaq -0x338(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x2150
movq %rax, %rdi
leaq -0x4c(%rbp), %rsi
callq 0x2150
movq %rax, %rdi
movq %r12, %rsi
callq 0x2260
movl -0x50(%rbp), %eax
movl %eax, (%rbx,%r13,4)
movl -0x4c(%rbp), %eax
movq -0xd8(%rbp), %rcx
movl %eax, (%rcx,%r13,4)
movq %r15, %rdi
movq %r12, %rsi
callq 0x2140
incq %r13
movslq -0x2c(%rbp), %rax
addq $0x20, %r15
cmpq %rax, %r13
jl 0x7f06
movl $0x1, -0x30(%rbp)
movq (%r14), %rax
cmpq 0x8(%r14), %rax
jae 0x80c3
leaq -0xb0(%rbp), %r15
leaq 0x3575(%rip), %r12      # 0xb4f4
movq (%rax), %r13
movq %rax, -0xc8(%rbp)
cmpq 0x8(%rax), %r13
jae 0x80a4
leaq -0x338(%rbp), %rdi
callq 0x2350
leaq -0x338(%rbp), %rdi
leaq -0xb7(%rbp), %rsi
callq 0x2270
leaq -0xc0(%rbp), %rdi
callq 0x82ee
testb %al, %al
je 0x7fcb
movb $0x0, -0xb8(%rbp)
jmp 0x7fd2
movb $0x1, -0xb8(%rbp)
cmpl $0x0, -0x2c(%rbp)
jle 0x802d
xorl %r14d, %r14d
movslq %r14d, %rsi
movl (%rbx,%rsi,4), %eax
cmpl -0x30(%rbp), %eax
jne 0x800d
movq -0xd8(%rbp), %rax
movl (%rax,%rsi,4), %eax
cmpl -0x34(%rbp), %eax
jne 0x800d
shlq $0x5, %rsi
addq -0xd0(%rbp), %rsi
movq %r15, %rdi
callq 0x2140
incl %r14d
jmp 0x8024
movq -0xa8(%rbp), %rdx
movq %r15, %rdi
xorl %esi, %esi
movq %r12, %rcx
xorl %r8d, %r8d
callq 0x22c0
incl %r14d
cmpl -0x2c(%rbp), %r14d
jl 0x7fdb
movl -0x30(%rbp), %eax
movl %eax, -0xc0(%rbp)
movl -0x34(%rbp), %eax
movl %eax, -0xbc(%rbp)
movzwl -0xb8(%rbp), %eax
movw %ax, 0x8(%r13)
movq -0xc0(%rbp), %rax
movq %rax, (%r13)
leaq 0x10(%r13), %rdi
movq %r15, %rsi
callq 0x2140
movq -0x40(%rbp), %r14
movzwl -0x128(%rbp), %eax
movw %ax, -0xb8(%rbp)
movq -0x130(%rbp), %rax
movq %rax, -0xc0(%rbp)
movq %r15, %rdi
leaq -0x120(%rbp), %rsi
callq 0x2140
incl -0x30(%rbp)
addq $0x30, %r13
movq -0xc8(%rbp), %rax
jmp 0x7f89
decl -0x34(%rbp)
movl $0x1, -0x30(%rbp)
movq -0xc8(%rbp), %rax
addq $0x18, %rax
cmpq 0x8(%r14), %rax
jb 0x7f7f
movq -0x48(%rbp), %rax
movq (%rax), %rax
movq %rax, %r14
shlq $0x5, %r14
leaq 0x8(%r14), %rbx
testq %rax, %rax
je 0x8101
movq -0x48(%rbp), %r15
addq $-0x8, %r15
leaq (%r15,%r14), %rax
movq -0x10(%r15,%r14), %rdi
cmpq %rdi, %rax
je 0x80fb
movq (%rax), %rsi
incq %rsi
callq 0x2210
addq $-0x20, %r14
jne 0x80e2
movq -0x48(%rbp), %rdi
movq %rbx, %rsi
callq 0x2370
leaq -0x338(%rbp), %rdi
callq 0x2080
movq 0x6eb0(%rip), %rbx      # 0xefd0
leaq 0x35ee(%rip), %rsi      # 0xb715
movl $0xd, %edx
movq %rbx, %rdi
callq 0x2240
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x21f0
movsbl %al, %esi
movq 0x6e7e(%rip), %rdi      # 0xefd0
callq 0x2040
movq %rax, %rdi
callq 0x2170
movq -0x100(%rbp), %rsp
leaq -0x338(%rbp), %rdi
callq 0x2090
movq -0xf8(%rbp), %rdi
leaq -0xe8(%rbp), %rax
cmpq %rax, %rdi
je 0x8194
movq -0xe8(%rbp), %rsi
incq %rsi
callq 0x2210
movq -0x120(%rbp), %rdi
leaq -0x110(%rbp), %rax
cmpq %rax, %rdi
je 0x81b6
movq -0x110(%rbp), %rsi
incq %rsi
callq 0x2210
movq -0xb0(%rbp), %rdi
leaq -0xa0(%rbp), %rax
cmpq %rax, %rdi
je 0x81d8
movq -0xa0(%rbp), %rsi
incq %rsi
callq 0x2210
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq -0x70(%rbp), %rdi
callq 0x7a14
jmp 0x8274
jmp 0x8271
movq %rax, %rbx
movq -0x70(%rbp), %rdi
cmpq %r13, %rdi
je 0x8214
movq -0x60(%rbp), %rsi
incq %rsi
callq 0x2210
jmp 0x8214
movq %rax, %rbx
leaq -0x80(%rbp), %rax
movq -0x10(%rax), %rdi
jmp 0x8256
jmp 0x8271
movq %rax, %rbx
jmp 0x8280
movq %rax, %rbx
jmp 0x82a2
jmp 0x8271
jmp 0x8271
movq %rax, %rbx
movq -0x70(%rbp), %rdi
cmpq %r13, %rdi
je 0x824b
movq -0x60(%rbp), %rsi
incq %rsi
callq 0x2210
jmp 0x824b
movq %rax, %rbx
movq -0x90(%rbp), %rdi
leaq -0x80(%rbp), %rax
cmpq %rax, %rdi
je 0x8274
movq -0x80(%rbp), %rsi
incq %rsi
callq 0x2210
jmp 0x8274
jmp 0x8271
jmp 0x8271
jmp 0x8271
jmp 0x8271
movq %rax, %rbx
leaq -0x338(%rbp), %rdi
callq 0x2090
movq -0xf8(%rbp), %rdi
leaq -0xe8(%rbp), %rax
cmpq %rax, %rdi
je 0x82a2
movq -0xe8(%rbp), %rsi
incq %rsi
callq 0x2210
leaq -0x110(%rbp), %rax
movq -0x120(%rbp), %rdi
cmpq %rax, %rdi
je 0x82c4
movq -0x110(%rbp), %rsi
incq %rsi
callq 0x2210
movq -0xb0(%rbp), %rdi
leaq -0xa0(%rbp), %rax
cmpq %rax, %rdi
je 0x82e6
movq -0xa0(%rbp), %rsi
incq %rsi
callq 0x2210
movq %rbx, %rdi
callq 0x2320