// File: lotuskip[P]yuxtapa/server/map.cpp
// Function: Map::load_from_file(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&)
bool Map::load_from_file(const string &mapname)
{
	ifstream file((Config::get_mapdir() + mapname).c_str());
	if(!file)
		return false;
	// else:
	string s;
	getline(file, s);
	if(s != mapfile_begin_string)
		return false; // the map is of a different version; can't be certain it will work
	// else:
	getline(file, s); // (skip comment line)
	file >> mapsize;
	if(mapsize < MIN_MAP_SIZE || mapsize > MAX_MAP_SIZE)
		return false; // a corrupt file or something
	// else
	file >> inhabited; // this should work regardless of locale?
	file.seekg(1, ios_base::cur); // skip newline
	getline(file, s);
	char ch;
	for(ch = 0; ch < MAX_MAPTYPE; ++ch)
	{
		if(s == short_mtype_name[ch])
		{
			maptype = e_MapType(ch);
			break;
		}
	}
	if(ch == MAX_MAPTYPE)
		return false; // no recognized maptype found
		
	make_right_size(data);
	vector<Tile>::iterator i;
	short ind;	
	for(rowit it = data.begin(); it != data.end(); ++it)
	{
		getline(file, s);
		if(s.size() != (unsigned short)mapsize)
			return false; // bogus data!
		ind = 0;
		for(i = it->begin(); i != it->end(); ++i)
		{
			if(tile_from_char(s[ind], *i))
				return false; // bogus data
			++ind;
		}
		if(!file)
			return false; // file corrupt or something else wrong
	}

	// Manually edited maps might have something else than undiggable wall on
	// the edges:
	fix_boundary();
	// Update BY_WALLs:
	Coords c;
	c.y = 1;
	while(c.y < mapsize-1)
	{
		c.x = 1;
		while(c.x < mapsize-1)
		{
			upd_by_wall_flag(c);
			c.x++;
		}
		c.y++;
	}
	return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x2f0, %rsp            # imm = 0x2F0
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x2c0(%rbp)
callq 0x1f300
movq %rax, %rsi
movq -0x18(%rbp), %rdx
leaq -0x240(%rbp), %rdi
movq %rdi, -0x2b8(%rbp)
callq 0x24cb0
movq -0x2b8(%rbp), %rdi
callq 0x5200
movq %rax, %rsi
leaq -0x220(%rbp), %rdi
movl $0x8, %edx
callq 0x5970
jmp 0x2c5bf
leaq -0x240(%rbp), %rdi
callq 0x5a48
movq -0x220(%rbp), %rax
movq -0x18(%rax), %rax
leaq -0x220(%rbp,%rax), %rdi
callq 0x5250
movb %al, -0x2c1(%rbp)
jmp 0x2c5eb
movb -0x2c1(%rbp), %al
testb $0x1, %al
jne 0x2c5f7
jmp 0x2c644
movb $0x0, -0x1(%rbp)
movl $0x1, -0x250(%rbp)
jmp 0x2cac5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x248(%rbp)
movl %eax, -0x24c(%rbp)
leaq -0x240(%rbp), %rdi
callq 0x5a48
jmp 0x2caeb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x248(%rbp)
movl %eax, -0x24c(%rbp)
jmp 0x2cadf
leaq -0x270(%rbp), %rdi
movq %rdi, -0x2d0(%rbp)
callq 0x5770
movq -0x2d0(%rbp), %rsi
leaq -0x220(%rbp), %rdi
callq 0x50f0
jmp 0x2c66c
leaq -0x270(%rbp), %rdi
leaq 0x645ce(%rip), %rsi     # 0x90c48
callq 0x2f160
testb $0x1, %al
jne 0x2c685
jmp 0x2c6af
movb $0x0, -0x1(%rbp)
movl $0x1, -0x250(%rbp)
jmp 0x2caa9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x248(%rbp)
movl %eax, -0x24c(%rbp)
jmp 0x2cab7
leaq -0x220(%rbp), %rdi
leaq -0x270(%rbp), %rsi
callq 0x50f0
jmp 0x2c6c4
movq -0x2c0(%rbp), %rsi
leaq -0x220(%rbp), %rdi
callq 0x50a0
jmp 0x2c6d9
movq -0x2c0(%rbp), %rax
movswl (%rax), %eax
cmpl $0x2a, %eax
jl 0x2c6f9
movq -0x2c0(%rbp), %rax
movswl (%rax), %eax
cmpl $0x1ff, %eax            # imm = 0x1FF
jle 0x2c70c
movb $0x0, -0x1(%rbp)
movl $0x1, -0x250(%rbp)
jmp 0x2caa9
movq -0x2c0(%rbp), %rsi
addq $0x2, %rsi
leaq -0x220(%rbp), %rdi
callq 0x5450
jmp 0x2c725
leaq -0x220(%rbp), %rdi
movl $0x1, %esi
movl $0x1, %edx
callq 0x5750
jmp 0x2c73d
leaq -0x220(%rbp), %rdi
leaq -0x270(%rbp), %rsi
callq 0x50f0
jmp 0x2c752
movb $0x0, -0x271(%rbp)
movsbl -0x271(%rbp), %eax
cmpl $0x3, %eax
jge 0x2c7b2
movsbq -0x271(%rbp), %rax
leaq 0x63f6c(%rip), %rsi     # 0x906e0
shlq $0x5, %rax
addq %rax, %rsi
leaq -0x270(%rbp), %rdi
callq 0x18960
testb $0x1, %al
jne 0x2c78d
jmp 0x2c7a0
movq -0x2c0(%rbp), %rax
movsbl -0x271(%rbp), %ecx
movl %ecx, 0x4(%rax)
jmp 0x2c7b2
jmp 0x2c7a2
movb -0x271(%rbp), %al
addb $0x1, %al
movb %al, -0x271(%rbp)
jmp 0x2c759
movsbl -0x271(%rbp), %eax
cmpl $0x3, %eax
jne 0x2c7d1
movb $0x0, -0x1(%rbp)
movl $0x1, -0x250(%rbp)
jmp 0x2caa9
movq -0x2c0(%rbp), %rdi
movq %rdi, %rsi
addq $0x8, %rsi
callq 0x2a3c0
jmp 0x2c7e6
leaq -0x280(%rbp), %rdi
callq 0x2ebe0
movq -0x2c0(%rbp), %rdi
addq $0x8, %rdi
callq 0x2ebb0
movq %rax, -0x290(%rbp)
movq -0x2c0(%rbp), %rdi
addq $0x8, %rdi
callq 0x2ede0
movq %rax, -0x298(%rbp)
leaq -0x290(%rbp), %rdi
leaq -0x298(%rbp), %rsi
callq 0x2eda0
testb $0x1, %al
jne 0x2c83c
jmp 0x2c9cb
leaq -0x220(%rbp), %rdi
leaq -0x270(%rbp), %rsi
callq 0x50f0
jmp 0x2c851
leaq -0x270(%rbp), %rdi
callq 0x5340
movq -0x2c0(%rbp), %rcx
movzwl (%rcx), %ecx
cmpq %rcx, %rax
je 0x2c87f
movb $0x0, -0x1(%rbp)
movl $0x1, -0x250(%rbp)
jmp 0x2caa9
movw $0x0, -0x282(%rbp)
leaq -0x290(%rbp), %rdi
callq 0x2ec00
movq %rax, %rdi
callq 0x2ec20
movq %rax, -0x2a0(%rbp)
movq -0x2a0(%rbp), %rax
movq %rax, -0x280(%rbp)
leaq -0x290(%rbp), %rdi
callq 0x2ec00
movq %rax, %rdi
callq 0x2ec90
movq %rax, -0x2a8(%rbp)
leaq -0x280(%rbp), %rdi
leaq -0x2a8(%rbp), %rsi
callq 0x2ec50
testb $0x1, %al
jne 0x2c8e8
jmp 0x2c979
movswq -0x282(%rbp), %rsi
leaq -0x270(%rbp), %rdi
callq 0x5a10
movq %rax, -0x2d8(%rbp)
jmp 0x2c905
movq -0x2d8(%rbp), %rax
movsbl (%rax), %eax
movl %eax, -0x2e0(%rbp)
leaq -0x280(%rbp), %rdi
callq 0x2ecc0
movl -0x2e0(%rbp), %edi
movq %rax, %rsi
callq 0x2cb00
movb %al, -0x2d9(%rbp)
jmp 0x2c937
movb -0x2d9(%rbp), %al
testb $0x1, %al
jne 0x2c943
jmp 0x2c956
movb $0x0, -0x1(%rbp)
movl $0x1, -0x250(%rbp)
jmp 0x2caa9
movw -0x282(%rbp), %ax
addw $0x1, %ax
movw %ax, -0x282(%rbp)
leaq -0x280(%rbp), %rdi
callq 0x2ed00
jmp 0x2c8b1
movq -0x220(%rbp), %rax
movq -0x18(%rax), %rax
leaq -0x220(%rbp,%rax), %rdi
callq 0x5250
movb %al, -0x2e1(%rbp)
jmp 0x2c999
movb -0x2e1(%rbp), %al
testb $0x1, %al
jne 0x2c9a5
jmp 0x2c9b8
movb $0x0, -0x1(%rbp)
movl $0x1, -0x250(%rbp)
jmp 0x2caa9
jmp 0x2c9ba
leaq -0x290(%rbp), %rdi
callq 0x2ee30
jmp 0x2c809
movq -0x2c0(%rbp), %rdi
callq 0x2b650
leaq -0x2ac(%rbp), %rdi
xorl %edx, %edx
movl %edx, %esi
callq 0x60430
jmp 0x2c9e9
movw $0x1, -0x2aa(%rbp)
movq -0x2c0(%rbp), %rcx
movswl -0x2aa(%rbp), %eax
movswl (%rcx), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0x2ca8f
movw $0x1, -0x2ac(%rbp)
movq -0x2c0(%rbp), %rcx
movswl -0x2ac(%rbp), %eax
movswl (%rcx), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0x2ca78
movq -0x2c0(%rbp), %rdi
leaq -0x2ac(%rbp), %rsi
callq 0x2b890
jmp 0x2ca44
movw -0x2ac(%rbp), %ax
addw $0x1, %ax
movw %ax, -0x2ac(%rbp)
jmp 0x2ca17
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x248(%rbp)
movl %eax, -0x24c(%rbp)
leaq -0x2ac(%rbp), %rdi
callq 0x60460
jmp 0x2cab7
movw -0x2aa(%rbp), %ax
addw $0x1, %ax
movw %ax, -0x2aa(%rbp)
jmp 0x2c9f2
movb $0x1, -0x1(%rbp)
movl $0x1, -0x250(%rbp)
leaq -0x2ac(%rbp), %rdi
callq 0x60460
leaq -0x270(%rbp), %rdi
callq 0x5a48
jmp 0x2cac5
leaq -0x270(%rbp), %rdi
callq 0x5a48
jmp 0x2cadf
leaq -0x220(%rbp), %rdi
callq 0x5170
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x2f0, %rsp            # imm = 0x2F0
popq %rbp
retq
leaq -0x220(%rbp), %rdi
callq 0x5170
movq -0x248(%rbp), %rdi
callq 0x5920
nopw (%rax,%rax)