// File: /workspace/github_cpp_makefile_star2_O2/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 $0x308, %rsp            # imm = 0x308
movq %rsi, %r12
movq %rdi, %rbx
leaq -0x98(%rbp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
xorl %ecx, %ecx
movb %cl, (%rax)
leaq -0x108(%rbp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
andl $0x0, -0x3c(%rbp)
movb %cl, (%rax)
andl $0x0, -0x38(%rbp)
leaq 0x336b(%rip), %rsi      # 0x94f4
leaq -0xf8(%rbp), %rdi
leaq -0x330(%rbp), %rdx
callq 0x2dd8
leaq -0x330(%rbp), %rdi
callq 0x21f0
leaq 0x3529(%rip), %rsi      # 0x96d8
leaq -0xd8(%rbp), %rdi
movq %r12, %rdx
callq 0x47d2
leaq 0x2e81(%rip), %rdx      # 0x9046
leaq -0x70(%rbp), %rdi
leaq -0xd8(%rbp), %rsi
callq 0x6afc
movq -0x70(%rbp), %rsi
leaq -0x330(%rbp), %rdi
pushq $0x8
popq %rdx
callq 0x2150
leaq -0x70(%rbp), %r14
movq %r14, %rdi
callq 0x2100
leaq -0xd8(%rbp), %r15
movq %r15, %rdi
callq 0x2100
pushq $0x8
popq %r13
movq -0x330(%rbp), %rax
movq -0x18(%rax), %rax
testb $0x5, -0x310(%rbp,%rax)
je 0x6287
movq 0x7dad(%rip), %rdi      # 0xdfd0
leaq 0x34b6(%rip), %rsi      # 0x96e0
callq 0x21c0
movq 0x7daa(%rip), %rdi      # 0xdfe0
movq %r12, %rsi
callq 0x2220
movq %r15, %rdi
leaq 0x3490(%rip), %rsi      # 0x96d8
movq %r12, %rdx
callq 0x47d2
movq %r14, %rdi
movq %r15, %rsi
leaq 0x2de9(%rip), %rdx      # 0x9046
callq 0x6afc
movq -0x70(%rbp), %rsi
leaq -0x330(%rbp), %rdi
movl %r13d, %edx
callq 0x2150
movq %r14, %rdi
callq 0x2100
movq %r15, %rdi
callq 0x2100
jmp 0x6207
movq 0x7d42(%rip), %rdi      # 0xdfd0
leaq 0x3469(%rip), %rsi      # 0x96fe
callq 0x21c0
movq %rax, %rdi
callq 0x2110
leaq 0x18(%rbx), %rdi
movq %r12, %rsi
callq 0x2130
leaq -0x330(%rbp), %rdi
leaq -0x2c(%rbp), %rsi
callq 0x2140
leaq -0x34(%rbp), %rsi
movq %rax, %rdi
callq 0x2140
movq %rbx, %rdi
callq 0x6b26
movslq -0x2c(%rbp), %r14
movslq -0x34(%rbp), %rsi
leaq -0x70(%rbp), %rdi
leaq -0xd8(%rbp), %rdx
callq 0x6b7c
leaq -0x70(%rbp), %rdx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x6b34
leaq -0x70(%rbp), %rdi
callq 0x6006
leaq 0x38(%rbx), %rsi
leaq -0x330(%rbp), %rdi
callq 0x2190
leaq 0x31db(%rip), %rsi      # 0x94f4
leaq -0xf8(%rbp), %rdi
callq 0x2350
leaq -0x330(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x2140
movq %rbx, -0x50(%rbp)
movq %rsp, -0x78(%rbp)
movl -0x30(%rbp), %eax
movq %rsp, %r14
leaq 0xf(,%rax,4), %rax
andq $-0x10, %rax
subq %rax, %r14
movq %r14, %rsp
movslq -0x30(%rbp), %r15
movl %r15d, %eax
movq %rsp, %r12
leaq 0xf(,%rax,4), %rax
andq $-0x10, %rax
subq %rax, %r12
movq %r12, %rsp
movq %r15, %rbx
shlq $0x5, %rbx
leaq 0x8(%rbx), %rax
testq %r15, %r15
pushq $-0x1
popq %rdi
cmovnsq %rax, %rdi
callq 0x2030
movq %r15, (%rax)
testl %r15d, %r15d
movq %r15, %rdx
je 0x63b0
leaq 0x18(%rax), %rcx
movq %rcx, -0x10(%rcx)
andq $0x0, -0x8(%rcx)
movb $0x0, (%rcx)
addq $0x20, %rcx
addq $-0x20, %rbx
jne 0x639a
movq %rax, -0x48(%rbp)
leaq 0x8(%rax), %r15
xorl %r13d, %r13d
leaq -0x330(%rbp), %rbx
movq %r15, -0x88(%rbp)
movslq %edx, %rax
cmpq %rax, %r13
jge 0x6421
movq %rbx, %rdi
leaq -0x3c(%rbp), %rsi
callq 0x2140
movq %rax, %rdi
leaq -0x38(%rbp), %rsi
callq 0x2140
movq %rax, %rdi
leaq -0xf8(%rbp), %rsi
callq 0x2220
movl -0x3c(%rbp), %eax
movl %eax, (%r14,%r13,4)
movl -0x38(%rbp), %eax
movl %eax, (%r12,%r13,4)
movq %r15, %rdi
leaq -0xf8(%rbp), %rsi
callq 0x2130
incq %r13
movl -0x30(%rbp), %edx
addq $0x20, %r15
jmp 0x63c9
movl $0x1, -0x2c(%rbp)
movq -0x50(%rbp), %rax
movq (%rax), %rcx
leaq -0x330(%rbp), %r13
leaq 0x30b7(%rip), %r15      # 0x94f4
movq -0x50(%rbp), %rax
cmpq 0x8(%rax), %rcx
jae 0x6539
movq (%rcx), %rax
movq %rcx, -0x80(%rbp)
cmpq 0x8(%rcx), %rax
jae 0x6526
movq %rax, %rbx
movq %r13, %rdi
callq 0x2330
movq %r13, %rdi
leaq -0xaf(%rbp), %rsi
callq 0x2240
leaq -0xb8(%rbp), %rdi
callq 0x6664
xorb $0x1, %al
movb %al, -0xb0(%rbp)
xorl %r13d, %r13d
cmpl -0x30(%rbp), %r13d
jge 0x64d8
movslq %r13d, %rsi
movl (%r14,%rsi,4), %eax
cmpl -0x2c(%rbp), %eax
jne 0x64c4
movl (%r12,%rsi,4), %eax
cmpl -0x34(%rbp), %eax
jne 0x64c4
shlq $0x5, %rsi
addq -0x88(%rbp), %rsi
leaq -0xa8(%rbp), %rdi
callq 0x2130
incl %r13d
jmp 0x64d3
leaq -0xa8(%rbp), %rdi
movq %r15, %rsi
callq 0x2350
incl %r13d
jmp 0x648d
movl -0x2c(%rbp), %eax
movl %eax, -0xb8(%rbp)
movl -0x34(%rbp), %eax
movl %eax, -0xb4(%rbp)
movq %rbx, %rdi
leaq -0xb8(%rbp), %rsi
callq 0x6bce
leaq -0x330(%rbp), %r13
leaq -0xb8(%rbp), %rdi
leaq -0x128(%rbp), %rsi
callq 0x6bce
incl -0x2c(%rbp)
movq %rbx, %rax
addq $0x30, %rax
movq -0x80(%rbp), %rcx
jmp 0x6452
movl $0x1, -0x2c(%rbp)
decl -0x34(%rbp)
addq $0x18, %rcx
jmp 0x643d
movq -0x48(%rbp), %rax
movq (%rax), %rax
movq %rax, %rbx
shlq $0x5, %rbx
leaq 0x8(%rbx), %r14
testq %rax, %rax
je 0x6567
movq -0x48(%rbp), %r15
addq $-0x18, %r15
leaq (%r15,%rbx), %rdi
callq 0x2100
addq $-0x20, %rbx
jne 0x6558
movq -0x48(%rbp), %rdi
movq %r14, %rsi
callq 0x2360
leaq -0x330(%rbp), %rdi
callq 0x2070
movq 0x7a4a(%rip), %rdi      # 0xdfd0
leaq 0x3180(%rip), %rsi      # 0x970d
callq 0x21c0
movq %rax, %rdi
callq 0x2110
movq -0x78(%rbp), %rsp
leaq -0x330(%rbp), %rdi
callq 0x2080
leaq -0xf8(%rbp), %rdi
callq 0x2100
leaq -0x118(%rbp), %rdi
callq 0x2100
leaq -0xa8(%rbp), %rdi
callq 0x2100
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r14
leaq -0x70(%rbp), %rdi
callq 0x6006
jmp 0x662b
jmp 0x6628
jmp 0x6608
jmp 0x6603
jmp 0x6628
movq %rax, %r14
jmp 0x6637
movq %rax, %r14
jmp 0x6643
jmp 0x6628
jmp 0x6628
jmp 0x6628
movq %rax, %r14
jmp 0x6614
movq %rax, %r14
leaq -0x70(%rbp), %rdi
callq 0x2100
leaq -0xd8(%rbp), %rdi
callq 0x2100
jmp 0x662b
jmp 0x6628
jmp 0x6628
jmp 0x6628
movq %rax, %r14
leaq -0x330(%rbp), %rdi
callq 0x2080
leaq -0xf8(%rbp), %rdi
callq 0x2100
leaq -0x118(%rbp), %rdi
callq 0x2100
leaq -0xa8(%rbp), %rdi
callq 0x2100
movq %r14, %rdi
callq 0x2300
nop