// File: /workspace/github_cpp_makefile_star2_O2/lotuskip[P]yuxtapa/server/viewpoint.cpp
// Function: ViewPoint::render(char*, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>>&)
short ViewPoint::render(char *target, vector<string> &shouts)
{
	char x, y;
	Tile *tp;
	if(!blinded) // don't do LOS consideration if blind
	{
		// clear the part of the viewtable that is not constant:
		for(y = 1; y < VIEWSIZE-1; ++y)
		{
			for(x = 1; x < VIEWSIZE-1; ++x)
				loslittbl[x][y] = 0;
		}
		// Always fill the table with the full radius:
		fill_loslittbl(LOSrad);
		/* In addition, for the higher radii, in order to cover a few "blind
		 * spots", we have to run with another radius (this could be optimized a
		 * little more, I'm sure, but I haven't bothered figuring that out). */
		if(LOSrad >= 6)
		{
			if(LOSrad > 6)
				fill_loslittbl(LOSrad - 2);
			fill_loslittbl(LOSrad - 1);
			if(LOSrad == 10) // scouts have their own extra blind spots
				fill_loslittbl(6);
		}

		// The center point of the view needs to be checked separately.
		// It is always in LOS!
		loslittbl[VIEWSIZE/2][VIEWSIZE/2] = IN_LOS;
		*(tp = &(ownview[pos.y][pos.x])) = Game::curmap->get_tile(pos);
		if(tp->flags & TF_LIT // statically lit
				|| is_dynlit(pos))
			loslittbl[VIEWSIZE/2][VIEWSIZE/2] |= IS_LIT;
	} // (not blinded)

	// The actual "rendering":
	unsigned char cp;
	Coords c;
	list<string> titles;
	list<Coords> titlecoords;
	map<Coords, string>::const_iterator vit;
	for(y = 0; y < VIEWSIZE; ++y)
	{
		for(x = 0; x < VIEWSIZE; ++x)
		{
			c.x = pos.x + x - VIEWSIZE/2;
			c.y = pos.y + y - VIEWSIZE/2;
			if(Game::curmap->point_out_of_map(c))
			{
				// for out of map points, just print emptyness:
				*(target++) = EMPTY_TILE.cpair;
				*(target++) = EMPTY_TILE.symbol;
			}
			else // point is in map
			{
				tp = Game::curmap->mod_tile(c);
				// A sound overrules anything else (even when blind!),
				// so check for it first:
				if(tp->flags & TF_SOUND)
				{
					vit = voices.find(c);
					if(vit != voices.end()) // Voice?
					{
						*(target++) = VOICE_COLOUR;
						shouts.push_back("!: " + vit->second);
					}
					else // a regular sound!
						*(target++) = sound_col[reg_sounds[c]];
					*(target++) = '!';
				}
				else if(blinded)
				{
					*(target++) = EMPTY_TILE.cpair;
					*(target++) = EMPTY_TILE.symbol;
				}
				// If tile is not in LOS (Note that in this table it cannot be
				// "lit but not in LOS" -- if you don't see it, you can't see
				// that it's lit!)
				else if(!(loslittbl[x][y]))
				{
					if(!(tp->flags & TF_OCCUPIED)
						|| !render_pc_indir(c, target))
					{
						// No sound or PC, take the raw symbol and give dim
						// colour. Note that this symbol is taken from ownview,
						// not directly from the map!
						if(ownview[c.y][c.x].cpair == C_UNKNOWN) // can't be dimmed!
							*(target++) = C_UNKNOWN;
						else
							*(target++) = ownview[c.y][c.x].cpair - NUM_DIM_COLS;
						*(target++) = ownview[c.y][c.x].symbol;
					}
					else target += 2; // a scout-seen PC was rendered
				}
				// else (tile in LOS), if tile is occupied must see who's there
				else if((tp->flags & TF_OCCUPIED) &&
					render_occent_at(c, target, loslittbl[x][y] & IS_LIT))
					target += 2;
				// if render_occent returns false, it must be a PC:
				else if((tp->flags & TF_OCCUPIED) &&
					render_pc_at(c, target, loslittbl[x][y] & IS_LIT, titles))
				{
					target += 2;
					titlecoords.push_back(Coords(x,y));
				}
				// else check for item in steal mode
				else if(gamemode == GM_STEAL && the_item.getpos() == c
					&& pl_with_item == cur_players.end())
				{
					the_item.draw(target, loslittbl[x][y] & IS_LIT);
					target += 2;
				}
				// else check if there is a nonoccupying entity
				else if(tp->flags & TF_NOCCENT)
				{
					render_noccent_at(c, target, loslittbl[x][y] & IS_LIT);
					target += 2;
				}
				// else check for a seen trap
				else if(tp->flags & TF_TRAP && owner->team != T_SPEC // specs don't see traps
					&& render_trap_at(c, target, loslittbl[x][y] & IS_LIT))
					target += 2;
				else // tile in LOS, totally empty or unseen trap/PC
				{
					cp = tp->cpair;
					if(loslittbl[x][y] & IS_LIT)
						cp += NUM_NORM_COLS;
					*(target++) = cp;
					*(target++) = tp->symbol;
				}

				// printed something; now must check for an indicator:
				if(!blinded && tp->flags & TF_ACTION && loslittbl[x][y])
					*(target-2) = C_GREEN_ON_HEAL
						+ (axn_indicators[c]%NUM_ACTIONS)*7
						+ fg_map[*(target-2)-BASE_COLOURS];
			} // point is in map
		} // loop x
	} // loop y
	poschanged = false;

	// Add titles in the form [num of titles (char)][so many titles: [x][y][C-string]]
	*(target++) = titles.size();
	short sizeadd = 1;
	while(!titles.empty())
	{
		*(target++) = titlecoords.back().x;
		*(target++) = titlecoords.back().y;
		strcpy(target, titles.back().c_str());
		target += titles.back().size()+1;
		sizeadd += 3 + titles.back().size();
		titlecoords.pop_back();
		titles.pop_back();
	}
	return VIEWSIZE*VIEWSIZE*2+sizeadd;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %rdx, -0x90(%rbp)
movq %rsi, %rbx
movq %rdi, %r15
cmpb $0x0, 0x20(%rdi)
jne 0x18d24
pushq $0x1
popq %rax
leaq 0x29b75(%rip), %rcx     # 0x427e0
pushq $0x18
popq %rdx
cmpq $0x16, %rax
je 0x18c92
movq %rdx, %rsi
cmpq $0x1fb, %rsi            # imm = 0x1FB
je 0x18c8a
movb $0x0, (%rcx,%rsi)
addq $0x17, %rsi
jmp 0x18c77
incq %rax
incq %rcx
jmp 0x18c6e
movsbl (%r15), %esi
movq %r15, %rdi
callq 0x189fc
movb (%r15), %al
cmpb $0x6, %al
jl 0x18cd7
movb $0x5, %cl
je 0x18cbb
addb $-0x2, %al
movsbl %al, %esi
movq %r15, %rdi
callq 0x189fc
movb (%r15), %cl
decb %cl
movsbl %cl, %esi
movq %r15, %rdi
callq 0x189fc
cmpb $0xa, (%r15)
jne 0x18cd7
pushq $0x6
popq %rsi
movq %r15, %rdi
callq 0x189fc
movb $0x1, 0x29c0a(%rip)     # 0x428e8
leaq 0x28f73(%rip), %rax     # 0x41c58
movq (%rax), %rax
movswq 0x4(%r15), %rcx
movq 0x8(%rax), %rax
imulq $0x18, %rcx, %rcx
movswq 0x2(%r15), %rdx
movq (%rax,%rcx), %rax
movl (%rax,%rdx,4), %eax
movq 0x8(%r15), %rsi
movq (%rsi,%rcx), %rcx
movl %eax, (%rcx,%rdx,4)
testb $0x10, %al
jne 0x18d1d
leaq 0x2(%r15), %rdi
callq 0x1b84e
testb %al, %al
je 0x18d24
orb $0x2, 0x29bc4(%rip)     # 0x428e8
leaq 0x29ab5(%rip), %r14     # 0x427e0
leaq -0x2c(%rbp), %rdi
xorl %r13d, %r13d
xorl %esi, %esi
xorl %edx, %edx
callq 0x24d90
leaq -0x68(%rbp), %r12
movq %r12, 0x8(%r12)
movq %r12, (%r12)
andq $0x0, 0x10(%r12)
leaq -0x80(%rbp), %rax
movq %rax, 0x8(%rax)
movq %rax, (%rax)
andq $0x0, 0x10(%rax)
cmpq $0x17, %r13
je 0x19100
movq %r13, -0x50(%rbp)
leal -0xb(%r13), %eax
movl %eax, -0x44(%rbp)
movq %r14, -0x88(%rbp)
movq %r14, %r12
xorl %r13d, %r13d
cmpq $0x17, %r13
je 0x190e6
movzwl 0x2(%r15), %eax
addl %r13d, %eax
addl $-0xb, %eax
movw %ax, -0x2c(%rbp)
movzwl 0x4(%r15), %eax
addw -0x44(%rbp), %ax
movw %ax, -0x2a(%rbp)
leaq 0x28eab(%rip), %rax     # 0x41c58
movq (%rax), %rdi
leaq -0x2c(%rbp), %rsi
callq 0x1256c
testb %al, %al
je 0x18dc7
movw $0x3f6d, (%rbx)         # imm = 0x3F6D
jmp 0x18f70
leaq 0x28e8a(%rip), %rax     # 0x41c58
movq (%rax), %rcx
movswq -0x2a(%rbp), %rax
movq 0x8(%rcx), %rcx
imulq $0x18, %rax, %rdx
movswq -0x2c(%rbp), %rsi
movq (%rcx,%rdx), %rcx
movq %rsi, -0x38(%rbp)
movq %rcx, -0x40(%rbp)
movzwl (%rcx,%rsi,4), %ecx
movzwl %cx, %edx
btl $0x8, %edx
jb 0x18e0d
cmpb $0x0, 0x20(%r15)
je 0x18e69
movw $0x3f6d, (%rbx)         # imm = 0x3F6D
jmp 0x18f24
leaq 0x2a16c(%rip), %r14     # 0x42f80
movq %r14, %rdi
leaq -0x2c(%rbp), %rsi
callq 0xc534
leaq 0x8(%r14), %rcx
cmpq %rcx, %rax
je 0x18f02
movb $0x3b, (%rbx)
addq $0x28, %rax
leaq -0xb0(%rbp), %r14
movq %r14, %rdi
leaq 0x1034e(%rip), %rsi     # 0x29193
movq %rax, %rdx
callq 0xde6a
movq -0x90(%rbp), %rdi
movq %r14, %rsi
callq 0xc834
movq %r14, %rdi
callq 0x47e8
jmp 0x18f20
movb (%r12), %sil
testb %sil, %sil
je 0x18f80
testb $0x40, %dl
je 0x18ea6
andb $0x2, %sil
shrb %sil
movzbl %sil, %edx
leaq -0x2c(%rbp), %rdi
movq %rbx, %rsi
callq 0x1b61c
testb %al, %al
jne 0x18f24
movq -0x38(%rbp), %rax
movq -0x40(%rbp), %rcx
movzwl (%rcx,%rax,4), %ecx
testb $0x40, %cl
je 0x18fe5
movb (%r12), %al
andb $0x2, %al
shrb %al
movzbl %al, %ecx
movq %r15, %rdi
leaq -0x2c(%rbp), %rsi
movq %rbx, %rdx
leaq -0x68(%rbp), %r8
callq 0x1923e
testb %al, %al
je 0x18fe5
movswl -0x50(%rbp), %edx
movswl %r13w, %esi
leaq -0xb0(%rbp), %r14
movq %r14, %rdi
callq 0x24d90
leaq -0x80(%rbp), %rdi
movq %r14, %rsi
callq 0x19662
movq %r14, %rdi
callq 0x24d9e
jmp 0x18f24
leaq 0x2a047(%rip), %rdi     # 0x42f50
leaq -0x2c(%rbp), %rsi
callq 0x195f8
movl (%rax), %eax
leaq 0x10285(%rip), %rcx     # 0x291a0
movb (%rax,%rcx), %al
movb %al, (%rbx)
movb $0x21, 0x1(%rbx)
cmpb $0x0, 0x20(%r15)
jne 0x18f70
movq -0x38(%rbp), %rax
movq -0x40(%rbp), %rcx
testb $-0x80, (%rcx,%rax,4)
je 0x18f70
cmpb $0x0, (%r12)
je 0x18f70
leaq 0x29fd9(%rip), %rdi     # 0x42f20
leaq -0x2c(%rbp), %rsi
callq 0x19672
movzbl (%rax), %eax
movb $0x6, %cl
divb %cl
movzbl %ah, %eax
imull $0x7, %eax, %eax
movsbq (%rbx), %rcx
leaq 0x10248(%rip), %rdx     # 0x291b0
addb -0x10(%rcx,%rdx), %al
addb $0x43, %al
movb %al, (%rbx)
addq $0x2, %rbx
incq %r13
addq $0x17, %r12
jmp 0x18d80
movq -0x38(%rbp), %rcx
testb $0x40, %dl
je 0x18fa6
movq %r15, %rdi
leaq -0x2c(%rbp), %rsi
movq %rbx, %rdx
callq 0x191ee
testb %al, %al
jne 0x18f24
movswq -0x2a(%rbp), %rax
movswq -0x2c(%rbp), %rcx
movq 0x8(%r15), %rdx
imulq $0x18, %rax, %rax
movq (%rdx,%rax), %rax
movb 0x3(%rax,%rcx,4), %al
leal -0x7(%rax), %ecx
cmpb $0x6d, %al
movzbl %cl, %eax
pushq $0x6d
popq %rcx
cmovel %ecx, %eax
movb %al, (%rbx)
movswq -0x2a(%rbp), %rax
movq 0x8(%r15), %rcx
imulq $0x18, %rax, %rax
movswq -0x2c(%rbp), %rdx
movq (%rcx,%rax), %rax
movb 0x2(%rax,%rdx,4), %al
jmp 0x190c2
leaq 0x28228(%rip), %rax     # 0x41214
cmpl $0x2, (%rax)
jne 0x1905c
leaq 0x2a010(%rip), %rax     # 0x43008
movl 0x8(%rax), %eax
movl %eax, -0xb0(%rbp)
leaq -0xb0(%rbp), %r14
movq %r14, %rdi
leaq -0x2c(%rbp), %rsi
callq 0x24f42
movb %al, %dl
leaq 0x29fdb(%rip), %rax     # 0x42ff8
leaq 0x2708c(%rip), %rcx     # 0x400b0
cmpq %rcx, (%rax)
sete %al
andb %al, %dl
movq %r14, %rdi
movl %edx, %r14d
callq 0x24d9e
cmpb $0x1, %r14b
jne 0x1905c
movb (%r12), %al
andb $0x2, %al
shrb %al
movzbl %al, %edx
leaq 0x29fb9(%rip), %rdi     # 0x43008
movq %rbx, %rsi
callq 0x1c9e6
jmp 0x18f24
movq -0x38(%rbp), %rax
movq -0x40(%rbp), %rcx
movzwl (%rcx,%rax,4), %eax
testb $0x20, %al
jne 0x190ca
btl $0xb, %eax
jae 0x190a1
movq 0x28(%r15), %rax
cmpl $0x2, 0xbc(%rax)
je 0x190a1
movb (%r12), %al
andb $0x2, %al
shrb %al
movzbl %al, %ecx
movq %r15, %rdi
leaq -0x2c(%rbp), %rsi
movq %rbx, %rdx
callq 0x19406
testb %al, %al
jne 0x18f24
movq -0x38(%rbp), %rdx
movq -0x40(%rbp), %rsi
movzbl 0x3(%rsi,%rdx,4), %eax
testb $0x2, (%r12)
leal 0x14(%rax), %ecx
movzbl %cl, %ecx
cmovel %eax, %ecx
movb %cl, (%rbx)
movb 0x2(%rsi,%rdx,4), %al
movb %al, 0x1(%rbx)
jmp 0x18f24
movb (%r12), %al
andb $0x2, %al
shrb %al
movzbl %al, %edx
leaq -0x2c(%rbp), %rdi
movq %rbx, %rsi
callq 0x1b75c
jmp 0x18f24
movq -0x50(%rbp), %r13
incq %r13
movq -0x88(%rbp), %r14
incq %r14
leaq -0x68(%rbp), %r12
jmp 0x18d5e
movb $0x0, 0x6(%r15)
movb -0x58(%rbp), %al
movb %al, (%rbx)
movw $0x1, %r14w
leaq -0x80(%rbp), %r15
cmpq %r12, -0x68(%rbp)
je 0x19166
movq -0x78(%rbp), %rax
movb 0x10(%rax), %al
movb %al, 0x1(%rbx)
movq -0x78(%rbp), %rax
movb 0x12(%rax), %al
leaq 0x3(%rbx), %rdi
movb %al, 0x2(%rbx)
movq -0x60(%rbp), %rax
movq 0x10(%rax), %rsi
callq 0x43d0
movq -0x60(%rbp), %rax
movq 0x18(%rax), %rax
addq %rax, %rbx
addq $0x3, %rbx
addl %eax, %r14d
addl $0x3, %r14d
movq %r15, %rdi
callq 0x196dc
movq %r12, %rdi
callq 0x196ea
jmp 0x19113
addl $0x422, %r14d           # imm = 0x422
leaq -0x80(%rbp), %rdi
callq 0x183c2
leaq -0x68(%rbp), %rdi
callq 0x19766
leaq -0x2c(%rbp), %rdi
callq 0x24d9e
movl %r14d, %eax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x191a1
jmp 0x191c7
movq %rax, %rbx
leaq -0xb0(%rbp), %rdi
callq 0x24d9e
jmp 0x191ca
movq %rax, %rbx
leaq -0xb0(%rbp), %rdi
callq 0x47e8
jmp 0x191ca
jmp 0x191c7
jmp 0x191c7
movq %rax, %rbx
leaq -0x80(%rbp), %rdi
callq 0x183c2
leaq -0x68(%rbp), %rdi
callq 0x19766
leaq -0x2c(%rbp), %rdi
callq 0x24d9e
movq %rbx, %rdi
callq 0x4710
nop