// File: /workspace/github_cpp_makefile_star2_O3/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, -0xb0(%rbp)
movq %rsi, %rbx
movq %rdi, %r15
cmpb $0x0, 0x20(%rdi)
jne 0x1e285
movl $0x1, %eax
leaq 0x27625(%rip), %rcx     # 0x457f0
movl $0x18, %edx
movb $0x0, (%rcx,%rdx)
addq $0x17, %rdx
cmpq $0x1fb, %rdx            # imm = 0x1FB
jne 0x1e1d0
incq %rax
incq %rcx
cmpq $0x16, %rax
jne 0x1e1cb
movsbl (%r15), %esi
movq %r15, %rdi
callq 0x1df4e
movb (%r15), %al
cmpb $0x6, %al
jl 0x1e234
movb $0x5, %cl
je 0x1e216
addb $-0x2, %al
movsbl %al, %esi
movq %r15, %rdi
callq 0x1df4e
movb (%r15), %cl
decb %cl
movsbl %cl, %esi
movq %r15, %rdi
callq 0x1df4e
cmpb $0xa, (%r15)
jne 0x1e234
movq %r15, %rdi
movl $0x6, %esi
callq 0x1df4e
movb $0x1, 0x276bd(%rip)     # 0x458f8
leaq 0x26a26(%rip), %rax     # 0x44c68
movq (%rax), %rax
movswq 0x4(%r15), %rcx
movq 0x8(%rax), %rax
shlq $0x3, %rcx
leaq (%rcx,%rcx,2), %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 0x1e27e
leaq 0x2(%r15), %rdi
callq 0x2106c
testb %al, %al
je 0x1e285
orb $0x2, 0x27673(%rip)     # 0x458f8
leaq -0x2c(%rbp), %rdi
xorl %r14d, %r14d
xorl %esi, %esi
xorl %edx, %edx
callq 0x2b798
leaq -0x88(%rbp), %rax
movq %rax, 0x8(%rax)
movq %rax, (%rax)
movq %r14, 0x10(%rax)
leaq -0xa0(%rbp), %rax
movq %rax, 0x8(%rax)
movq %rax, (%rax)
movq %r14, 0x10(%rax)
leal -0xb(%r14), %eax
movl %eax, -0x70(%rbp)
xorl %r13d, %r13d
movq %r14, -0x48(%rbp)
movswl %r14w, %eax
movl %eax, -0x6c(%rbp)
xorl %r14d, %r14d
movzwl 0x2(%r15), %eax
addw %r14w, %ax
addl $-0xb, %eax
movw %ax, -0x2c(%rbp)
movzwl 0x4(%r15), %eax
addw -0x70(%rbp), %ax
movw %ax, -0x2a(%rbp)
leaq 0x26973(%rip), %rax     # 0x44c68
movq (%rax), %rdi
leaq -0x2c(%rbp), %rsi
callq 0x16f24
testb %al, %al
je 0x1e30f
movw $0x3f6d, (%rbx)         # imm = 0x3F6D
jmp 0x1e519
leaq 0x26952(%rip), %rax     # 0x44c68
movq (%rax), %rcx
movswq -0x2a(%rbp), %rax
movq 0x8(%rcx), %rcx
leaq (%rax,%rax,2), %rdx
movswq -0x2c(%rbp), %rsi
movq (%rcx,%rdx,8), %rcx
movq %rsi, -0x38(%rbp)
movq %rcx, -0x40(%rbp)
movzwl (%rcx,%rsi,4), %ecx
movzwl %cx, %edx
btl $0x8, %edx
jb 0x1e355
cmpb $0x0, 0x20(%r15)
je 0x1e3c4
movw $0x3f6d, (%rbx)         # imm = 0x3F6D
jmp 0x1e4ac
leaq 0x27c34(%rip), %r12     # 0x45f90
movq %r12, %rdi
leaq -0x2c(%rbp), %rsi
callq 0xfa26
leaq 0x8(%r12), %rcx
cmpq %rcx, %rax
je 0x1e48a
movb $0x3b, (%rbx)
addq $0x28, %rax
leaq -0x68(%rbp), %r12
movq %r12, %rdi
leaq 0x10dcf(%rip), %rsi     # 0x2f15a
movq %rax, %rdx
callq 0x11c74
movq -0xb0(%rbp), %rdi
movq %r12, %rsi
callq 0xfbcc
movq -0x68(%rbp), %rdi
leaq -0x58(%rbp), %rax
cmpq %rax, %rdi
je 0x1e4a8
movq -0x58(%rbp), %rsi
incq %rsi
callq 0x43f0
jmp 0x1e4a8
movq -0x48(%rbp), %rsi
leaq (%rsi,%r13), %r12
leaq 0x2741d(%rip), %rsi     # 0x457f0
movb (%rsi,%r12), %sil
testb %sil, %sil
je 0x1e536
testb $0x40, %dl
je 0x1e410
andb $0x2, %sil
shrb %sil
movzbl %sil, %edx
leaq -0x2c(%rbp), %rdi
movq %rbx, %rsi
callq 0x20e39
testb %al, %al
jne 0x1e4ac
movq -0x38(%rbp), %rax
movq -0x40(%rbp), %rcx
movzwl (%rcx,%rax,4), %ecx
testb $0x40, %cl
je 0x1e5a1
leaq 0x273d0(%rip), %rax     # 0x457f0
movb (%rax,%r12), %al
andb $0x2, %al
shrb %al
movzbl %al, %ecx
movq %r15, %rdi
leaq -0x2c(%rbp), %rsi
movq %rbx, %rdx
leaq -0x88(%rbp), %r8
callq 0x1e854
testb %al, %al
je 0x1e5a1
movswl %r14w, %esi
leaq -0x68(%rbp), %rdi
movl -0x6c(%rbp), %edx
callq 0x2b798
movl $0x18, %edi
callq 0x43e0
movl -0x68(%rbp), %ecx
movl %ecx, 0x10(%rax)
movq %rax, %rdi
leaq -0xa0(%rbp), %rsi
callq 0x4060
incq -0x90(%rbp)
leaq -0x68(%rbp), %rdi
callq 0x2b7a6
jmp 0x1e4ac
leaq 0x27acf(%rip), %rdi     # 0x45f60
leaq -0x2c(%rbp), %rsi
callq 0x1ed3a
movl (%rax), %eax
leaq 0x10cbd(%rip), %rcx     # 0x2f160
movb (%rax,%rcx), %al
movb %al, (%rbx)
movb $0x21, 0x1(%rbx)
cmpb $0x0, 0x20(%r15)
jne 0x1e519
movq -0x38(%rbp), %rax
movq -0x40(%rbp), %rcx
testb $-0x80, (%rcx,%rax,4)
je 0x1e519
movq -0x48(%rbp), %rax
addq %r13, %rax
leaq 0x27321(%rip), %rcx     # 0x457f0
cmpb $0x0, (%rcx,%rax)
je 0x1e519
leaq 0x27a54(%rip), %rdi     # 0x45f30
leaq -0x2c(%rbp), %rsi
callq 0x1edd0
movzbl (%rax), %eax
imull $0xab, %eax, %ecx
shrl $0x9, %ecx
andl $-0x2, %ecx
leal (%rcx,%rcx,2), %ecx
subb %cl, %al
movzbl %al, %eax
leal (,%rax,8), %ecx
subl %eax, %ecx
movsbq (%rbx), %rax
leaq 0x10c60(%rip), %rdx     # 0x2f170
addb -0x10(%rax,%rdx), %cl
addb $0x43, %cl
movb %cl, (%rbx)
addq $0x2, %rbx
incl %r14d
addq $0x17, %r13
cmpq $0x211, %r13            # imm = 0x211
jne 0x1e2d1
jmp 0x1e6c3
movq -0x38(%rbp), %rcx
testb $0x40, %dl
je 0x1e560
movq %r15, %rdi
leaq -0x2c(%rbp), %rsi
movq %rbx, %rdx
callq 0x1e804
testb %al, %al
jne 0x1e4ac
movswq -0x2a(%rbp), %rax
movswq -0x2c(%rbp), %rcx
movq 0x8(%r15), %rdx
leaq (%rax,%rax,2), %rax
movq (%rdx,%rax,8), %rax
movb 0x3(%rax,%rcx,4), %al
leal -0x7(%rax), %ecx
cmpb $0x6d, %al
movzbl %cl, %eax
movl $0x6d, %ecx
cmovel %ecx, %eax
movb %al, (%rbx)
movswq -0x2a(%rbp), %rax
movq 0x8(%r15), %rcx
leaq (%rax,%rax,2), %rax
movswq -0x2c(%rbp), %rdx
movq (%rcx,%rax,8), %rax
movb 0x2(%rax,%rdx,4), %al
jmp 0x1e698
leaq 0x25c7c(%rip), %rax     # 0x44224
cmpl $0x2, (%rax)
jne 0x1e624
leaq 0x27a64(%rip), %rax     # 0x46018
movl 0x8(%rax), %eax
movl %eax, -0x68(%rbp)
leaq -0x68(%rbp), %rdi
leaq -0x2c(%rbp), %rsi
callq 0x2b962
testb %al, %al
je 0x1e61b
leaq 0x27a36(%rip), %rax     # 0x46008
movq (%rax), %rax
movq %rax, -0xa8(%rbp)
leaq -0x68(%rbp), %rdi
callq 0x2b7a6
movq -0xa8(%rbp), %rax
cmpq 0x219bd(%rip), %rax     # 0x3ffb0
jne 0x1e624
leaq 0x271f4(%rip), %rax     # 0x457f0
movb (%rax,%r12), %al
andb $0x2, %al
shrb %al
movzbl %al, %edx
leaq 0x27a0a(%rip), %rdi     # 0x46018
movq %rbx, %rsi
callq 0x21d1a
jmp 0x1e4ac
leaq -0x68(%rbp), %rdi
callq 0x2b7a6
movq -0x38(%rbp), %rax
movq -0x40(%rbp), %rcx
movzwl (%rcx,%rax,4), %eax
testb $0x20, %al
jne 0x1e6a0
btl $0xb, %eax
jae 0x1e670
movq 0x28(%r15), %rax
cmpl $0x2, 0xbc(%rax)
je 0x1e670
leaq 0x271a2(%rip), %rax     # 0x457f0
movb (%rax,%r12), %al
andb $0x2, %al
shrb %al
movzbl %al, %ecx
movq %r15, %rdi
leaq -0x2c(%rbp), %rsi
movq %rbx, %rdx
callq 0x1eaa2
testb %al, %al
jne 0x1e4ac
movq -0x38(%rbp), %rdx
movq -0x40(%rbp), %rsi
movzbl 0x3(%rsi,%rdx,4), %eax
leaq 0x2716c(%rip), %rcx     # 0x457f0
testb $0x2, (%rcx,%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 0x1e4ac
leaq 0x27149(%rip), %rax     # 0x457f0
movb (%rax,%r12), %al
andb $0x2, %al
shrb %al
movzbl %al, %edx
leaq -0x2c(%rbp), %rdi
movq %rbx, %rsi
callq 0x20f79
jmp 0x1e4ac
movq -0x48(%rbp), %r14
incq %r14
cmpq $0x17, %r14
jne 0x1e2b9
movb $0x0, 0x6(%r15)
movb -0x78(%rbp), %al
movb %al, (%rbx)
leaq -0x88(%rbp), %r12
cmpq %r12, -0x88(%rbp)
je 0x1e768
movw $0x1, %r14w
leaq -0xa0(%rbp), %r15
movq -0x98(%rbp), %rax
movb 0x10(%rax), %al
movb %al, 0x1(%rbx)
movq -0x98(%rbp), %rax
movb 0x12(%rax), %al
leaq 0x3(%rbx), %rdi
movb %al, 0x2(%rbx)
movq -0x80(%rbp), %rax
movq 0x10(%rax), %rsi
callq 0x43c0
movq -0x80(%rbp), %rax
movq 0x18(%rax), %rax
addq %rax, %rbx
addq $0x3, %rbx
addl %eax, %r14d
addl $0x3, %r14d
movq -0x98(%rbp), %rsi
movq %r15, %rdi
callq 0x1f3ea
movq -0x80(%rbp), %rsi
movq %r12, %rdi
callq 0x1f41c
cmpq %r12, -0x88(%rbp)
jne 0x1e6fa
addl $0x422, %r14d           # imm = 0x422
jmp 0x1e76d
movw $0x423, %r14w           # imm = 0x423
leaq -0xa0(%rbp), %rdi
callq 0x1da22
leaq -0x88(%rbp), %rdi
callq 0x1ee66
leaq -0x2c(%rbp), %rdi
callq 0x2b7a6
movl %r14d, %eax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x1e7d7
jmp 0x1e7a7
movq %rax, %rbx
leaq -0x68(%rbp), %rdi
callq 0x2b7a6
jmp 0x1e7da
movq %rax, %rbx
movq -0x68(%rbp), %rdi
leaq -0x58(%rbp), %rax
cmpq %rax, %rdi
je 0x1e7da
movq -0x58(%rbp), %rsi
incq %rsi
callq 0x43f0
jmp 0x1e7da
jmp 0x1e7d7
jmp 0x1e7d7
movq %rax, %rbx
leaq -0xa0(%rbp), %rdi
callq 0x1da22
leaq -0x88(%rbp), %rdi
callq 0x1ee66
leaq -0x2c(%rbp), %rdi
callq 0x2b7a6
movq %rbx, %rdi
callq 0x4740
nop