// File: /workspace/github_cpp_makefile_star2_O1/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 0x1e425
movl $0x1, %eax
leaq 0x27483(%rip), %rcx     # 0x457f0
movl $0x18, %edx
movb $0x0, (%rcx,%rdx)
addq $0x17, %rdx
cmpq $0x1fb, %rdx            # imm = 0x1FB
jne 0x1e372
incq %rax
incq %rcx
cmpq $0x16, %rax
jne 0x1e36d
movsbl (%r15), %esi
movq %r15, %rdi
callq 0x1e0e6
movb (%r15), %al
cmpb $0x6, %al
jl 0x1e3d4
je 0x1e3b1
addb $-0x2, %al
movsbl %al, %esi
movq %r15, %rdi
callq 0x1e0e6
movb (%r15), %al
decb %al
movsbl %al, %esi
movq %r15, %rdi
callq 0x1e0e6
cmpb $0xa, (%r15)
jne 0x1e3d4
movq %r15, %rdi
movl $0x6, %esi
callq 0x1e0e6
movb $0x1, 0x2751d(%rip)     # 0x458f8
leaq 0x26886(%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 0x1e41e
leaq 0x2(%r15), %rdi
callq 0x21230
testb %al, %al
je 0x1e425
orb $0x2, 0x274d3(%rip)     # 0x458f8
leaq -0x2c(%rbp), %rdi
xorl %r14d, %r14d
xorl %esi, %esi
xorl %edx, %edx
callq 0x2bbe8
leaq -0x68(%rbp), %rax
movq %rax, 0x8(%rax)
movq %rax, (%rax)
movq %r14, 0x10(%rax)
leaq -0x80(%rbp), %rax
movq %rax, 0x8(%rax)
movq %rax, (%rax)
movq %r14, 0x10(%rax)
leal -0xb(%r14), %eax
movl %eax, -0x50(%rbp)
movw $0xfff5, %r13w          # imm = 0xFFF5
movq %r14, -0x48(%rbp)
movswl %r14w, %eax
movl %eax, -0x4c(%rbp)
xorl %r14d, %r14d
movzwl 0x2(%r15), %eax
addw %r13w, %ax
movw %ax, -0x2c(%rbp)
movzwl 0x4(%r15), %eax
addw -0x50(%rbp), %ax
movw %ax, -0x2a(%rbp)
leaq 0x267da(%rip), %rax     # 0x44c68
movq (%rax), %rdi
leaq -0x2c(%rbp), %rsi
callq 0x1704c
testb %al, %al
je 0x1e4a8
movw $0x3f6d, (%rbx)         # imm = 0x3F6D
jmp 0x1e6ba
leaq 0x267b9(%rip), %rax     # 0x44c68
movq (%rax), %rax
movswq -0x2a(%rbp), %rcx
movq 0x8(%rax), %rax
leaq (%rcx,%rcx,2), %rcx
movswq -0x2c(%rbp), %rdx
movq (%rax,%rcx,8), %rax
movq %rdx, -0x40(%rbp)
movq %rax, -0x38(%rbp)
movzwl (%rax,%rdx,4), %eax
btl $0x8, %eax
jb 0x1e4ef
cmpb $0x0, 0x20(%r15)
je 0x1e56a
movw $0x3f6d, (%rbx)         # imm = 0x3F6D
jmp 0x1e64d
leaq 0x27a9a(%rip), %r12     # 0x45f90
movq %r12, %rdi
leaq -0x2c(%rbp), %rsi
callq 0xfb1c
leaq 0x8(%r12), %rcx
cmpq %rcx, %rax
je 0x1e62b
movb $0x3b, (%rbx)
addq $0x28, %rax
leaq -0xa0(%rbp), %r12
movq %r12, %rdi
leaq 0x10c44(%rip), %rsi     # 0x2f16c
movq %rax, %rdx
callq 0x11dd6
movq -0xb0(%rbp), %rdi
movq %r12, %rsi
callq 0xfcce
movq -0xa0(%rbp), %rdi
leaq -0x90(%rbp), %rax
cmpq %rax, %rdi
je 0x1e649
movq -0x90(%rbp), %rsi
incq %rsi
callq 0x43f0
jmp 0x1e649
movq -0x48(%rbp), %rcx
leaq (%rcx,%r14), %r12
leaq 0x27277(%rip), %rcx     # 0x457f0
movb (%rcx,%r12), %cl
testb %cl, %cl
je 0x1e6d7
testb $0x40, %al
je 0x1e5a5
andb $0x2, %cl
shrb %cl
movzbl %cl, %edx
leaq -0x2c(%rbp), %rdi
movq %rbx, %rsi
callq 0x20f9b
testb %al, %al
jne 0x1e64d
movq -0x40(%rbp), %rax
movq -0x38(%rbp), %rcx
testb $0x40, (%rcx,%rax,4)
je 0x1e73d
leaq 0x27232(%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 -0x68(%rbp), %r8
callq 0x1e9f2
testb %al, %al
je 0x1e73d
leal 0xb(%r13), %eax
movswl %ax, %esi
leaq -0xa0(%rbp), %rdi
movl -0x4c(%rbp), %edx
callq 0x2bbe8
movl $0x18, %edi
callq 0x43e0
movl -0xa0(%rbp), %ecx
movl %ecx, 0x10(%rax)
movq %rax, %rdi
leaq -0x80(%rbp), %rsi
callq 0x4060
incq -0x70(%rbp)
leaq -0xa0(%rbp), %rdi
callq 0x2bbf6
jmp 0x1e64d
leaq 0x2792e(%rip), %rdi     # 0x45f60
leaq -0x2c(%rbp), %rsi
callq 0x1eec2
movl (%rax), %eax
leaq 0x10b2c(%rip), %rcx     # 0x2f170
movb (%rax,%rcx), %al
movb %al, (%rbx)
movb $0x21, 0x1(%rbx)
cmpb $0x0, 0x20(%r15)
jne 0x1e6ba
movq -0x40(%rbp), %rax
movq -0x38(%rbp), %rcx
testb $-0x80, (%rcx,%rax,4)
je 0x1e6ba
movq -0x48(%rbp), %rax
addq %r14, %rax
leaq 0x27180(%rip), %rcx     # 0x457f0
cmpb $0x0, (%rcx,%rax)
je 0x1e6ba
leaq 0x278b3(%rip), %rdi     # 0x45f30
leaq -0x2c(%rbp), %rsi
callq 0x1ef56
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 0x10acf(%rip), %rdx     # 0x2f180
addb -0x10(%rax,%rdx), %cl
addb $0x43, %cl
movb %cl, (%rbx)
addq $0x2, %rbx
addq $0x17, %r14
incl %r13d
cmpq $0x211, %r14            # imm = 0x211
jne 0x1e46d
jmp 0x1e86f
testb $0x40, %al
je 0x1e6f2
movq %r15, %rdi
leaq -0x2c(%rbp), %rsi
movq %rbx, %rdx
callq 0x1e9a2
testb %al, %al
jne 0x1e64d
movswq -0x2a(%rbp), %rax
movq 0x8(%r15), %rcx
leaq (%rax,%rax,2), %rax
movswq -0x2c(%rbp), %rdx
movq (%rcx,%rax,8), %rax
movb 0x3(%rax,%rdx,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 0x1e844
movq %r12, -0xa8(%rbp)
leaq 0x25ad9(%rip), %rax     # 0x44224
movl (%rax), %r12d
cmpl $0x2, %r12d
jne 0x1e788
leaq 0x278bd(%rip), %rax     # 0x46018
movl 0x8(%rax), %eax
movl %eax, -0x30(%rbp)
leaq -0x30(%rbp), %rdi
leaq -0x2c(%rbp), %rsi
callq 0x2bddc
testb %al, %al
je 0x1e788
leaq 0x2788f(%rip), %rax     # 0x46008
leaq 0x24940(%rip), %rcx     # 0x430c0
cmpq %rcx, (%rax)
sete %al
jmp 0x1e78a
xorl %eax, %eax
cmpl $0x2, %r12d
jne 0x1e79f
leaq -0x30(%rbp), %rdi
movl %eax, %r12d
callq 0x2bbf6
movl %r12d, %eax
testb %al, %al
movq -0xa8(%rbp), %r12
je 0x1e7d0
leaq 0x2703f(%rip), %rax     # 0x457f0
movb (%rax,%r12), %al
andb $0x2, %al
shrb %al
movzbl %al, %edx
leaq 0x27855(%rip), %rdi     # 0x46018
movq %rbx, %rsi
callq 0x21f8a
jmp 0x1e64d
movq -0x40(%rbp), %rax
movq -0x38(%rbp), %rcx
movzwl (%rcx,%rax,4), %eax
testb $0x20, %al
jne 0x1e84c
btl $0xb, %eax
jae 0x1e81c
movq 0x28(%r15), %rax
cmpl $0x2, 0xbc(%rax)
je 0x1e81c
leaq 0x26ff6(%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 0x1ec3c
testb %al, %al
jne 0x1e64d
movq -0x40(%rbp), %rdx
movq -0x38(%rbp), %rsi
movzbl 0x3(%rsi,%rdx,4), %eax
leaq 0x26fc0(%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 0x1e64d
leaq 0x26f9d(%rip), %rax     # 0x457f0
movb (%rax,%r12), %al
andb $0x2, %al
shrb %al
movzbl %al, %edx
leaq -0x2c(%rbp), %rdi
movq %rbx, %rsi
callq 0x2113d
jmp 0x1e64d
movq -0x48(%rbp), %r14
incq %r14
cmpq $0x17, %r14
jne 0x1e453
movb $0x0, 0x6(%r15)
movb -0x58(%rbp), %al
movb %al, (%rbx)
leaq -0x68(%rbp), %r12
cmpq %r12, -0x68(%rbp)
je 0x1e8ff
movw $0x1, %r14w
leaq -0x80(%rbp), %r15
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 0x43c0
movq -0x60(%rbp), %rax
movq 0x18(%rax), %rax
addq %rax, %rbx
addq $0x3, %rbx
addl %eax, %r14d
addl $0x3, %r14d
movq -0x78(%rbp), %rsi
movq %r15, %rdi
callq 0x1f57e
movq -0x60(%rbp), %rsi
movq %r12, %rdi
callq 0x1f5b0
cmpq %r12, -0x68(%rbp)
jne 0x1e89d
addl $0x422, %r14d           # imm = 0x422
jmp 0x1e904
movw $0x423, %r14w           # imm = 0x423
leaq -0x80(%rbp), %rdi
callq 0x1dbd2
leaq -0x68(%rbp), %rdi
callq 0x1efea
leaq -0x2c(%rbp), %rdi
callq 0x2bbf6
movl %r14d, %eax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x1e97b
movq %rax, %rbx
leaq -0xa0(%rbp), %rdi
jmp 0x1e949
movq %rax, %rbx
leaq -0x30(%rbp), %rdi
callq 0x2bbf6
jmp 0x1e97e
movq %rax, %rbx
movq -0xa0(%rbp), %rdi
leaq -0x90(%rbp), %rax
cmpq %rax, %rdi
je 0x1e97e
movq -0x90(%rbp), %rsi
incq %rsi
callq 0x43f0
jmp 0x1e97e
jmp 0x1e97b
jmp 0x1e97b
movq %rax, %rbx
leaq -0x80(%rbp), %rdi
callq 0x1dbd2
leaq -0x68(%rbp), %rdi
callq 0x1efea
leaq -0x2c(%rbp), %rdi
callq 0x2bbf6
movq %rbx, %rdi
callq 0x4750
nop