// File: /workspace/github_cpp_makefile_star2_O2/lotuskip[P]yuxtapa/server/occent.cpp
// Function: MM::update()
void MM::update()
{
	if(madevoid)
		return;
	// Don't move on first turn (that's practically always the same turn we're created)
	if(!turns_moved)
	{
		++turns_moved;
		return;
	}
	// else
	event_set.insert(pos); // in any event, moves away
	Game::curmap->mod_tile(pos)->flags &= ~(TF_OCCUPIED);

	if(turns_moved < 2)
		++turns_moved; // and don't change lmd
	else
	{
		// Find the position of the nearest enemy:
		char best_dist = MAX_MM_HOMING_DIST;
		Coords targetc;
		for(list<PCEnt>::iterator it = PCs.begin(); it != PCs.end(); ++it)
		{
			// not void, enemy, closer:
			if(!it->isvoid() && it->get_owner()->team != owner->team
				&& it->getpos().dist_walk(pos) < best_dist)
			{
				targetc = it->getpos();
				best_dist = it->getpos().dist_walk(pos);
			}
		}
		if(best_dist < MAX_MM_HOMING_DIST) // a target was found!
		{
			e_Dir tdir = pos.dir_of(targetc);
			if(tdir == !lmd) // target is right behind us; turn randomly
			{
				if(random()%2) ++lmd;
				else --lmd;
			}
			else // turn lmd "towards" tdir
			{
				if(tdir > lmd)
				{
					if(tdir - lmd <= 3) ++lmd;
					else --lmd;
				}
				else /*tdir < lmd*/ if(lmd - tdir <= 3) --lmd;
				else ++lmd;
			}
		}
		// else just go straight on
	}

	Coords newpos = pos.in(lmd);
	if(missile_coll(this, newpos))
		return; // missile_coll should have voided *this
	// else
	event_set.insert((pos = newpos));
	Game::curmap->mod_tile(pos)->flags |= TF_OCCUPIED;

	cpair = (cpair == C_MM1) ? C_MM2 : C_MM1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
cmpb $0x0, 0xe(%rdi)
jne 0x1d1bb
movq %rdi, %rbx
cmpb $0x0, 0x1c(%rdi)
je 0x1d02a
leaq 0x8(%rbx), %rsi
leaq 0x25fdd(%rip), %rdi     # 0x42fc8
movq %rsi, -0x38(%rbp)
callq 0x1c558
leaq 0x24c5d(%rip), %r14     # 0x41c58
movq (%r14), %rax
movswq 0xa(%rbx), %rcx
movq 0x8(%rax), %rax
imulq $0x18, %rcx, %rcx
movswq 0x8(%rbx), %rdx
movq (%rax,%rcx), %rax
andw $-0x41, (%rax,%rdx,4)
movb 0x1c(%rbx), %al
cmpb $0x1, %al
jg 0x1d033
incb %al
movb %al, 0x1c(%rbx)
jmp 0x1d151
movb $0x1, 0x1c(%rbx)
jmp 0x1d1bb
leaq -0x2c(%rbp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x24d90
movb $0xf, %r12b
leaq 0x25e86(%rip), %r14     # 0x42ed0
leaq -0x30(%rbp), %r15
movq %r14, %r13
movsbl %r12b, %eax
movl %eax, -0x3c(%rbp)
movq (%r13), %r13
cmpq %r14, %r13
je 0x1d0d8
cmpb $0x0, 0x1e(%r13)
jne 0x1d058
movq 0x20(%r13), %rax
movl 0xbc(%rax), %eax
movq 0x10(%rbx), %rcx
cmpl 0xbc(%rcx), %eax
je 0x1d058
movl 0x18(%r13), %eax
movl %eax, -0x30(%rbp)
movq %r15, %rdi
movq -0x38(%rbp), %rsi
callq 0x24dd8
movl %eax, %r12d
movq %r15, %rdi
callq 0x24d9e
cmpw -0x3c(%rbp), %r12w
jge 0x1d058
movl 0x18(%r13), %eax
movl %eax, -0x30(%rbp)
movl %eax, -0x2c(%rbp)
movq %r15, %rdi
callq 0x24d9e
movl 0x18(%r13), %eax
movl %eax, -0x30(%rbp)
movq %r15, %rdi
movq -0x38(%rbp), %rsi
callq 0x24dd8
movl %eax, %r12d
movq %r15, %rdi
callq 0x24d9e
jmp 0x1d051
cmpb $0xf, -0x3c(%rbp)
jge 0x1d141
movl -0x2c(%rbp), %eax
leaq -0x40(%rbp), %rsi
movl %eax, (%rsi)
movq -0x38(%rbp), %rdi
callq 0x24e9e
movl %eax, %r12d
leaq -0x40(%rbp), %rdi
callq 0x24d9e
movl 0x18(%rbx), %edi
callq 0x24d7c
leaq 0x18(%rbx), %r15
cmpl %eax, %r12d
jne 0x1d120
callq 0x41e0
testb $0x1, %al
jne 0x1d139
movq %r15, %rdi
callq 0x24d64
jmp 0x1d141
movl (%r15), %eax
movl %r12d, %ecx
subl %eax, %ecx
jle 0x1d131
cmpl $0x4, %ecx
jge 0x1d116
jmp 0x1d139
subl %r12d, %eax
cmpl $0x3, %eax
jle 0x1d116
movq %r15, %rdi
callq 0x24d4c
leaq -0x2c(%rbp), %rdi
callq 0x24d9e
leaq 0x24b07(%rip), %r14     # 0x41c58
movl 0x18(%rbx), %edx
leaq -0x2c(%rbp), %r15
movq %r15, %rdi
movq -0x38(%rbp), %rsi
callq 0x24e0c
movq %rbx, %rdi
movq %r15, %rsi
callq 0x20c24
testb %al, %al
jne 0x1d1b2
movl -0x2c(%rbp), %eax
movq -0x38(%rbp), %rsi
movl %eax, (%rsi)
leaq 0x25e45(%rip), %rdi     # 0x42fc8
callq 0x1c558
movq (%r14), %rax
movswq 0xa(%rbx), %rcx
movq 0x8(%rax), %rax
imulq $0x18, %rcx, %rcx
movswq 0x8(%rbx), %rdx
movq (%rax,%rcx), %rax
orw $0x40, (%rax,%rdx,4)
cmpb $0x3f, 0xd(%rbx)
sete %al
addb $0x3f, %al
movb %al, 0xd(%rbx)
leaq -0x2c(%rbp), %rdi
callq 0x24d9e
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x1d1dc
movq %rax, %rbx
leaq -0x40(%rbp), %rdi
jmp 0x1d1e3
jmp 0x1d1d7
movq %rax, %rbx
jmp 0x1d1e8
movq %rax, %rbx
leaq -0x30(%rbp), %rdi
callq 0x24d9e
leaq -0x2c(%rbp), %rdi
callq 0x24d9e
movq %rbx, %rdi
callq 0x4710
nop