// File: 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
subq $0x4c0, %rsp            # imm = 0x4C0
movq %rsi, -0x3f8(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x3f0(%rbp)
leaq -0x18(%rbp), %rdi
callq 0xcbb0
leaq -0x20(%rbp), %rdi
callq 0xcbd0
leaq -0x50(%rbp), %rdi
callq 0xcbf0
leaq -0x80(%rbp), %rdi
callq 0xcbf0
movl $0x0, -0x94(%rbp)
movl $0x0, -0x98(%rbp)
leaq -0xc1(%rbp), %rdi
movq %rdi, -0x3e8(%rbp)
callq 0x3450
movq -0x3e8(%rbp), %rdx
leaq 0x6dcd(%rip), %rsi      # 0x1248b
leaq -0xc0(%rbp), %rdi
callq 0x47d0
jmp 0xb6cc
leaq -0xc1(%rbp), %rdi
callq 0x32d0
leaq -0x2e0(%rbp), %rdi
callq 0x3300
jmp 0xb6e6
movq -0x3f8(%rbp), %rdx
leaq 0x70f4(%rip), %rsi      # 0x127e8
leaq -0x320(%rbp), %rdi
callq 0x7dd0
jmp 0xb702
leaq 0x6909(%rip), %rdx      # 0x12012
leaq -0x300(%rbp), %rdi
leaq -0x320(%rbp), %rsi
callq 0xcc10
jmp 0xb71e
leaq -0x300(%rbp), %rdi
callq 0x3130
movq %rax, %rsi
leaq -0x2e0(%rbp), %rdi
movl $0x8, %edx
callq 0x31d0
jmp 0xb740
leaq -0x300(%rbp), %rdi
callq 0x31c0
leaq -0x320(%rbp), %rdi
callq 0x31c0
movq -0x2e0(%rbp), %rax
movq -0x18(%rax), %rax
leaq -0x2e0(%rbp,%rax), %rdi
callq 0x3030
movb %al, -0x3f9(%rbp)
jmp 0xb778
movb -0x3f9(%rbp), %al
testb $0x1, %al
jne 0xb787
jmp 0xb8ff
movq 0xd842(%rip), %rdi      # 0x18fd0
leaq 0x705b(%rip), %rsi      # 0x127f0
callq 0x3280
jmp 0xb79c
movq -0x3f8(%rbp), %rsi
movq 0xd836(%rip), %rdi      # 0x18fe0
callq 0x3350
jmp 0xb7b1
movq -0x3f8(%rbp), %rdx
leaq 0x7029(%rip), %rsi      # 0x127e8
leaq -0x360(%rbp), %rdi
callq 0x7dd0
jmp 0xb7cd
leaq 0x683e(%rip), %rdx      # 0x12012
leaq -0x340(%rbp), %rdi
leaq -0x360(%rbp), %rsi
callq 0xcc10
jmp 0xb7e9
leaq -0x340(%rbp), %rdi
callq 0x3130
movq %rax, %rsi
leaq -0x2e0(%rbp), %rdi
movl $0x8, %edx
callq 0x31d0
jmp 0xb80b
leaq -0x340(%rbp), %rdi
callq 0x31c0
leaq -0x360(%rbp), %rdi
callq 0x31c0
jmp 0xb758
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xd0(%rbp)
movl %eax, -0xd4(%rbp)
leaq -0xc1(%rbp), %rdi
callq 0x32d0
jmp 0xbfdf
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xd0(%rbp)
movl %eax, -0xd4(%rbp)
jmp 0xbfd3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xd0(%rbp)
movl %eax, -0xd4(%rbp)
jmp 0xbfc7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xd0(%rbp)
movl %eax, -0xd4(%rbp)
jmp 0xb8ab
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xd0(%rbp)
movl %eax, -0xd4(%rbp)
leaq -0x300(%rbp), %rdi
callq 0x31c0
leaq -0x320(%rbp), %rdi
callq 0x31c0
jmp 0xbfc7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xd0(%rbp)
movl %eax, -0xd4(%rbp)
jmp 0xb8ee
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xd0(%rbp)
movl %eax, -0xd4(%rbp)
leaq -0x340(%rbp), %rdi
callq 0x31c0
leaq -0x360(%rbp), %rdi
callq 0x31c0
jmp 0xbfc7
movq 0xd6ca(%rip), %rdi      # 0x18fd0
leaq 0x6f01(%rip), %rsi      # 0x1280e
callq 0x3280
movq %rax, -0x408(%rbp)
jmp 0xb91b
movq -0x408(%rbp), %rdi
movq 0xd697(%rip), %rsi      # 0x18fc0
callq 0x32b0
jmp 0xb930
movq -0x3f8(%rbp), %rsi
movq -0x3f0(%rbp), %rdi
addq $0x18, %rdi
callq 0x3060
jmp 0xb949
leaq -0x2e0(%rbp), %rdi
leaq -0x88(%rbp), %rsi
callq 0x31b0
movq %rax, -0x410(%rbp)
jmp 0xb965
movq -0x410(%rbp), %rdi
leaq -0x8c(%rbp), %rsi
callq 0x31b0
jmp 0xb97a
movq -0x3f0(%rbp), %rdi
callq 0xcc60
movq -0x3f0(%rbp), %rax
movq %rax, -0x430(%rbp)
movslq -0x88(%rbp), %rax
movq %rax, -0x428(%rbp)
movslq -0x8c(%rbp), %rax
movq %rax, -0x420(%rbp)
leaq -0x379(%rbp), %rdi
movq %rdi, -0x418(%rbp)
callq 0xcd30
movq -0x420(%rbp), %rsi
movq -0x418(%rbp), %rdx
leaq -0x378(%rbp), %rdi
callq 0xcd50
jmp 0xb9df
movq -0x428(%rbp), %rsi
movq -0x430(%rbp), %rdi
leaq -0x378(%rbp), %rdx
callq 0xcc80
jmp 0xb9fb
leaq -0x378(%rbp), %rdi
callq 0xb210
leaq -0x379(%rbp), %rdi
callq 0xb470
movq -0x3f0(%rbp), %rsi
addq $0x38, %rsi
leaq -0x2e0(%rbp), %rdi
callq 0x3250
jmp 0xba2c
leaq 0x6a58(%rip), %rsi      # 0x1248b
leaq -0xc0(%rbp), %rdi
callq 0x3380
jmp 0xba41
leaq -0x2e0(%rbp), %rdi
leaq -0x9c(%rbp), %rsi
callq 0x31b0
jmp 0xba56
movl -0x9c(%rbp), %eax
movq %rsp, %rcx
movq %rcx, -0x388(%rbp)
leaq 0xf(,%rax,4), %rdx
andq $-0x10, %rdx
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, -0x450(%rbp)
movq %rcx, %rsp
movq %rax, -0x390(%rbp)
movl -0x9c(%rbp), %eax
leaq 0xf(,%rax,4), %rdx
andq $-0x10, %rdx
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, -0x448(%rbp)
movq %rcx, %rsp
movq %rax, -0x398(%rbp)
movslq -0x9c(%rbp), %rax
movq %rax, -0x440(%rbp)
movl $0x20, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
addq $0x8, %rdi
movq $-0x1, %rax
cmovbq %rax, %rdi
testb %cl, %cl
cmovneq %rax, %rdi
callq 0x3040
movq %rax, -0x438(%rbp)
jmp 0xbaf1
movq -0x440(%rbp), %rax
movq -0x438(%rbp), %rcx
movq %rax, (%rcx)
addq $0x8, %rcx
movq %rcx, -0x458(%rbp)
cmpq $0x0, %rax
je 0xbb6a
movq -0x458(%rbp), %rax
movq -0x440(%rbp), %rdx
shlq $0x5, %rdx
movq %rax, %rcx
addq %rdx, %rcx
movq %rcx, -0x468(%rbp)
movq %rax, -0x460(%rbp)
movq -0x460(%rbp), %rdi
movq %rdi, -0x470(%rbp)
callq 0x3390
movq -0x470(%rbp), %rax
movq -0x468(%rbp), %rcx
addq $0x20, %rax
cmpq %rcx, %rax
movq %rax, -0x460(%rbp)
jne 0xbb39
movq -0x458(%rbp), %rax
movq %rax, -0x3a0(%rbp)
movl $0x0, -0x3a4(%rbp)
movl -0x3a4(%rbp), %eax
cmpl -0x9c(%rbp), %eax
jge 0xbc8b
leaq -0x2e0(%rbp), %rdi
leaq -0x94(%rbp), %rsi
callq 0x31b0
movq %rax, -0x478(%rbp)
jmp 0xbbb0
movq -0x478(%rbp), %rdi
leaq -0x98(%rbp), %rsi
callq 0x31b0
movq %rax, -0x480(%rbp)
jmp 0xbbcc
movq -0x480(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
callq 0x3350
jmp 0xbbe1
movq -0x448(%rbp), %rax
movq -0x450(%rbp), %rcx
movl -0x94(%rbp), %esi
movslq -0x3a4(%rbp), %rdx
movl %esi, (%rcx,%rdx,4)
movl -0x98(%rbp), %edx
movslq -0x3a4(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movq -0x3a0(%rbp), %rdi
movslq -0x3a4(%rbp), %rax
shlq $0x5, %rax
addq %rax, %rdi
leaq -0xc0(%rbp), %rsi
callq 0x3060
jmp 0xbc32
jmp 0xbc34
movl -0x3a4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3a4(%rbp)
jmp 0xbb82
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xd0(%rbp)
movl %eax, -0xd4(%rbp)
jmp 0xbc7a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xd0(%rbp)
movl %eax, -0xd4(%rbp)
leaq -0x378(%rbp), %rdi
callq 0xb210
leaq -0x379(%rbp), %rdi
callq 0xb470
jmp 0xbfc7
movq -0x3f0(%rbp), %rdi
movl $0x1, -0x88(%rbp)
callq 0xcdc0
movq %rax, -0x3b0(%rbp)
movq -0x3b0(%rbp), %rax
movq %rax, -0x18(%rbp)
movq -0x3f0(%rbp), %rdi
callq 0xce30
movq %rax, -0x3b8(%rbp)
leaq -0x18(%rbp), %rdi
leaq -0x3b8(%rbp), %rsi
callq 0xcdf0
testb $0x1, %al
jne 0xbcdf
jmp 0xbeb5
leaq -0x18(%rbp), %rdi
callq 0xce60
movq %rax, %rdi
callq 0xce80
movq %rax, -0x3c0(%rbp)
movq -0x3c0(%rbp), %rax
movq %rax, -0x20(%rbp)
leaq -0x18(%rbp), %rdi
callq 0xce60
movq %rax, %rdi
callq 0xcef0
movq %rax, -0x3c8(%rbp)
leaq -0x20(%rbp), %rdi
leaq -0x3c8(%rbp), %rsi
callq 0xceb0
testb $0x1, %al
jne 0xbd33
jmp 0xbe85
leaq -0x2e0(%rbp), %rdi
callq 0x3490
jmp 0xbd41
leaq -0x47(%rbp), %rsi
leaq -0x2e0(%rbp), %rdi
callq 0x3370
jmp 0xbd53
leaq -0x50(%rbp), %rdi
callq 0xc000
movb %al, -0x481(%rbp)
jmp 0xbd64
movb -0x481(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x1, %eax
jne 0xbd7a
movb $0x0, -0x48(%rbp)
jmp 0xbd7e
movb $0x1, -0x48(%rbp)
movl $0x0, -0x3cc(%rbp)
movl -0x3cc(%rbp), %eax
cmpl -0x9c(%rbp), %eax
jge 0xbe27
movq -0x450(%rbp), %rax
movslq -0x3cc(%rbp), %rcx
movl (%rax,%rcx,4), %eax
cmpl -0x88(%rbp), %eax
jne 0xbdfd
movq -0x448(%rbp), %rax
movslq -0x3cc(%rbp), %rcx
movl (%rax,%rcx,4), %eax
cmpl -0x8c(%rbp), %eax
jne 0xbdfd
movq -0x3a0(%rbp), %rsi
movslq -0x3cc(%rbp), %rax
shlq $0x5, %rax
addq %rax, %rsi
leaq -0x40(%rbp), %rdi
callq 0x3060
jmp 0xbdec
movl -0x3cc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3cc(%rbp)
jmp 0xbe11
leaq -0x40(%rbp), %rdi
leaq 0x6683(%rip), %rsi      # 0x1248b
callq 0x3380
jmp 0xbe0f
jmp 0xbe11
jmp 0xbe13
movl -0x3cc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3cc(%rbp)
jmp 0xbd88
movl -0x88(%rbp), %eax
movl %eax, -0x50(%rbp)
movl -0x8c(%rbp), %eax
movl %eax, -0x4c(%rbp)
leaq -0x20(%rbp), %rdi
callq 0xcf20
movq %rax, %rdi
leaq -0x50(%rbp), %rsi
callq 0xcf40
jmp 0xbe50
leaq -0x50(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0xcf40
jmp 0xbe5f
movl -0x88(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x88(%rbp)
leaq -0x20(%rbp), %rdi
xorl %esi, %esi
callq 0xcf90
movq %rax, -0x3d8(%rbp)
jmp 0xbd02
movl $0x1, -0x88(%rbp)
movl -0x8c(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x8c(%rbp)
leaq -0x18(%rbp), %rdi
xorl %esi, %esi
callq 0xcfd0
movq %rax, -0x3e0(%rbp)
jmp 0xbcb3
movq -0x3a0(%rbp), %rax
movq %rax, -0x490(%rbp)
cmpq $0x0, %rax
je 0xbf4f
movq -0x490(%rbp), %rcx
movq %rcx, %rax
addq $-0x8, %rax
movq %rax, -0x4a8(%rbp)
movq -0x8(%rcx), %rdx
movq %rdx, -0x4a0(%rbp)
shlq $0x5, %rdx
movq %rcx, %rax
addq %rdx, %rax
cmpq %rax, %rcx
movq %rax, -0x498(%rbp)
je 0xbf34
movq -0x498(%rbp), %rdi
addq $-0x20, %rdi
movq %rdi, -0x4b0(%rbp)
callq 0x31c0
movq -0x490(%rbp), %rcx
movq -0x4b0(%rbp), %rax
cmpq %rcx, %rax
movq %rax, -0x498(%rbp)
jne 0xbf03
movq -0x4a8(%rbp), %rdi
movq -0x4a0(%rbp), %rsi
shlq $0x5, %rsi
addq $0x8, %rsi
callq 0x34c0
leaq -0x2e0(%rbp), %rdi
callq 0x30a0
jmp 0xbf5d
movq 0xd06c(%rip), %rdi      # 0x18fd0
leaq 0x68b2(%rip), %rsi      # 0x1281d
callq 0x3280
movq %rax, -0x4b8(%rbp)
jmp 0xbf79
movq -0x4b8(%rbp), %rdi
movq 0xd039(%rip), %rsi      # 0x18fc0
callq 0x32b0
jmp 0xbf8e
movq -0x388(%rbp), %rax
movq %rax, %rsp
leaq -0x2e0(%rbp), %rdi
callq 0x30b0
leaq -0xc0(%rbp), %rdi
callq 0x31c0
leaq -0x80(%rbp), %rdi
callq 0xb390
leaq -0x50(%rbp), %rdi
callq 0xb390
movq %rbp, %rsp
popq %rbp
retq
leaq -0x2e0(%rbp), %rdi
callq 0x30b0
leaq -0xc0(%rbp), %rdi
callq 0x31c0
leaq -0x80(%rbp), %rdi
callq 0xb390
leaq -0x50(%rbp), %rdi
callq 0xb390
movq -0xd0(%rbp), %rdi
callq 0x3440
nopl (%rax)