// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x238, %rsp            # imm = 0x238
movq %rsi, %r14
movq %rdi, %rbx
callq 0xde53
leaq -0x50(%rbp), %r15
movq %r15, %rdi
movq %rax, %rsi
movq %r14, %rdx
callq 0xfe1f
movq (%r15), %rsi
leaq -0x258(%rbp), %rdi
pushq $0x8
popq %rdx
callq 0x4740
leaq -0x50(%rbp), %rdi
callq 0x47e8
movq -0x258(%rbp), %rax
movq -0x18(%rax), %rax
testb $0x5, -0x238(%rbp,%rax)
je 0x12b52
xorl %r12d, %r12d
jmp 0x12bbe
leaq -0x40(%rbp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq -0x258(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x40a0
leaq 0x2df4f(%rip), %rsi     # 0x40ac8
leaq -0x50(%rbp), %rdi
callq 0x13b84
testb %al, %al
jne 0x12bb2
leaq -0x258(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x40a0
leaq -0x258(%rbp), %rdi
movq %rbx, %rsi
callq 0x4060
movl $0xfffffe00, %eax       # imm = 0xFFFFFE00
addl (%rbx), %eax
cmpw $0xfe2a, %ax            # imm = 0xFE2A
jae 0x12bdf
xorl %r12d, %r12d
leaq -0x50(%rbp), %rdi
callq 0x47e8
leaq -0x258(%rbp), %rdi
callq 0x4110
movl %r12d, %eax
addq $0x238, %rsp            # imm = 0x238
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x2(%rbx), %rsi
leaq -0x258(%rbp), %rdi
callq 0x4350
leaq -0x258(%rbp), %rdi
pushq $0x1
popq %rsi
pushq $0x1
popq %rdx
callq 0x4580
leaq -0x258(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x40a0
leaq 0x2d948(%rip), %r14     # 0x40560
xorl %r12d, %r12d
cmpq $0x3, %r12
je 0x12bb2
movq %r15, %rdi
movq %r14, %rsi
callq 0xb2dd
testb %al, %al
jne 0x12c39
incq %r12
addq $0x20, %r14
jmp 0x12c1b
movl %r12d, 0x4(%rbx)
leaq 0x8(%rbx), %rsi
movq %rbx, %rdi
callq 0x11cc0
movq 0x8(%rbx), %r13
leaq -0x50(%rbp), %r15
leaq 0x13f18(%rip), %r14     # 0x26b70
xorl %r12d, %r12d
cmpq 0x10(%rbx), %r13
je 0x12d86
leaq -0x258(%rbp), %rdi
movq %r15, %rsi
callq 0x40a0
movzwl (%rbx), %eax
cmpq %rax, -0x48(%rbp)
jne 0x12bb2
movq (%r13), %rax
xorl %ecx, %ecx
cmpq 0x8(%r13), %rax
je 0x12d64
movswq %cx, %rdx
movq -0x50(%rbp), %rsi
movb (%rsi,%rdx), %dl
movzbl %dl, %esi
leal -0x20(%rsi), %edi
cmpl $0xe, %edi
jbe 0x12ce7
cmpl $0x3b, %esi
je 0x12d33
cmpl $0x48, %esi
je 0x12d43
cmpl $0x49, %esi
je 0x12d3b
cmpl $0x54, %esi
je 0x12d53
cmpl $0x5c, %esi
je 0x12d2b
cmpl $0x5f, %esi
je 0x12d4b
cmpl $0x7c, %esi
je 0x12cf8
cmpl $0x7e, %esi
jne 0x12bb2
movl $0x1d7e0405, (%rax)     # imm = 0x1D7E0405
jmp 0x12d59
movslq (%r14,%rdi,4), %rsi
addq %r14, %rsi
jmpq *%rsi
movl $0x1c200205, (%rax)     # imm = 0x1C200205
jmp 0x12d59
movl $0x1a7c0004, (%rax)     # imm = 0x1A7C0004
movb %dl, 0x2(%rax)
jmp 0x12d59
movl $0x182e0005, (%rax)     # imm = 0x182E0005
jmp 0x12d59
movl $0x17220007, (%rax)     # imm = 0x17220007
jmp 0x12d59
movl $0x1a230000, (%rax)     # imm = 0x1A230000
jmp 0x12d59
movl $0x1b2b0000, (%rax)     # imm = 0x1B2B0000
jmp 0x12d59
movl $0x192e0005, (%rax)     # imm = 0x192E0005
jmp 0x12d59
movl $0x1b5c0005, (%rax)     # imm = 0x1B5C0005
jmp 0x12d59
movl $0x1a3b0007, (%rax)     # imm = 0x1A3B0007
jmp 0x12d59
movl $0x1a230001, (%rax)     # imm = 0x1A230001
jmp 0x12d59
movl $0x1a231000, (%rax)     # imm = 0x1A231000
jmp 0x12d59
movl $0x1c2e0005, (%rax)     # imm = 0x1C2E0005
jmp 0x12d59
movl $0x17540005, (%rax)     # imm = 0x17540005
incl %ecx
addq $0x4, %rax
jmp 0x12c87
movq -0x258(%rbp), %rax
movq -0x18(%rax), %rax
addq $0x18, %r13
testb $0x5, -0x238(%rbp,%rax)
je 0x12c5b
jmp 0x12bb5
movq %rbx, %rdi
callq 0x123c8
leaq -0x2c(%rbp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x24d90
movzwl (%rbx), %eax
movw $0x1, %cx
leaq -0x2c(%rbp), %r14
movw %cx, -0x2a(%rbp)
movswl %cx, %ecx
movswl %ax, %edx
decl %edx
cmpl %ecx, %edx
jle 0x12de8
movw $0x1, %cx
movw %cx, -0x2c(%rbp)
movswl %cx, %ecx
movswl %ax, %edx
decl %edx
cmpl %ecx, %edx
jle 0x12de0
movq %rbx, %rdi
movq %r14, %rsi
callq 0x12448
movzwl -0x2c(%rbp), %ecx
incl %ecx
movzwl (%rbx), %eax
jmp 0x12dba
movzwl -0x2a(%rbp), %ecx
incl %ecx
jmp 0x12da6
leaq -0x2c(%rbp), %rdi
callq 0x24d9e
movb $0x1, %r12b
jmp 0x12bb5
jmp 0x12e0d
jmp 0x12e0d
jmp 0x12e0d
movq %rax, %rbx
leaq -0x50(%rbp), %rdi
callq 0x47e8
jmp 0x12e33
movq %rax, %rbx
jmp 0x12e1e
movq %rax, %rbx
leaq -0x2c(%rbp), %rdi
callq 0x24d9e
leaq -0x50(%rbp), %rdi
callq 0x47e8
leaq -0x258(%rbp), %rdi
callq 0x4110
movq %rbx, %rdi
callq 0x4710
nop