// File: /workspace/github_cpp_makefile_star2_O1/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 $0x28, %rsp
cmpb $0x0, 0xe(%rdi)
jne 0x22824
movq %rdi, %rbx
cmpb $0x0, 0x1c(%rdi)
je 0x22679
leaq 0x8(%rbx), %rsi
leaq 0x2399f(%rip), %rdi     # 0x45fd8
movq %rsi, -0x40(%rbp)
callq 0x21b9c
leaq 0x2261f(%rip), %r13     # 0x44c68
movq (%r13), %rax
movswq 0xa(%rbx), %rcx
movq 0x8(%rax), %rax
leaq (%rcx,%rcx,2), %rcx
movswq 0x8(%rbx), %rdx
movq (%rax,%rcx,8), %rax
andw $-0x41, (%rax,%rdx,4)
movb 0x1c(%rbx), %al
cmpb $0x1, %al
jg 0x22682
incb %al
movb %al, 0x1c(%rbx)
jmp 0x227b9
movb $0x1, 0x1c(%rbx)
jmp 0x22824
leaq -0x2c(%rbp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x2bbe8
leaq 0x2384a(%rip), %rax     # 0x45ee0
movq (%rax), %r14
cmpq %rax, %r14
je 0x227b0
movb $0xf, %r13b
leaq -0x30(%rbp), %r12
cmpb $0x0, 0x1e(%r14)
jne 0x226c6
movq 0x20(%r14), %rax
movl 0xbc(%rax), %eax
movq 0x10(%rbx), %rcx
cmpl 0xbc(%rcx), %eax
jne 0x226cd
xorl %eax, %eax
xorl %r15d, %r15d
jmp 0x226ee
movl 0x18(%r14), %eax
movl %eax, -0x34(%rbp)
leaq -0x34(%rbp), %rdi
movq -0x40(%rbp), %rsi
callq 0x2bc42
movsbl %r13b, %ecx
cmpw %cx, %ax
setl %r15b
movb $0x1, %al
testb %al, %al
je 0x226fb
leaq -0x34(%rbp), %rdi
callq 0x2bbf6
testb %r15b, %r15b
je 0x22730
movl 0x18(%r14), %eax
movl %eax, -0x30(%rbp)
movl %eax, -0x2c(%rbp)
movq %r12, %rdi
callq 0x2bbf6
movl 0x18(%r14), %eax
movl %eax, -0x30(%rbp)
movq %r12, %rdi
movq -0x40(%rbp), %rsi
callq 0x2bc42
movl %eax, %r13d
movq %r12, %rdi
callq 0x2bbf6
movq (%r14), %r14
cmpq 0x1d876(%rip), %r14     # 0x3ffb0
jne 0x226a9
cmpb $0xf, %r13b
leaq 0x2251d(%rip), %r13     # 0x44c68
jge 0x227b0
movl -0x2c(%rbp), %eax
leaq -0x44(%rbp), %rsi
movl %eax, (%rsi)
movq -0x40(%rbp), %rdi
callq 0x2bd30
movl %eax, %r12d
leaq -0x44(%rbp), %rdi
callq 0x2bbf6
movl 0x18(%rbx), %edi
callq 0x2bbcc
leaq 0x18(%rbx), %r15
cmpl %eax, %r12d
jne 0x2278f
callq 0x41d0
testb $0x1, %al
jne 0x227a8
movq %r15, %rdi
callq 0x2bbb4
jmp 0x227b0
movl (%r15), %eax
movl %r12d, %ecx
subl %eax, %ecx
jle 0x227a0
cmpl $0x4, %ecx
jge 0x22785
jmp 0x227a8
subl %r12d, %eax
cmpl $0x3, %eax
jle 0x22785
movq %r15, %rdi
callq 0x2bb9c
leaq -0x2c(%rbp), %rdi
callq 0x2bbf6
movl 0x18(%rbx), %edx
leaq -0x2c(%rbp), %r15
movq %r15, %rdi
movq -0x40(%rbp), %rsi
callq 0x2bc76
movq %rbx, %rdi
movq %r15, %rsi
callq 0x26926
testb %al, %al
jne 0x2281b
movl -0x2c(%rbp), %eax
movq -0x40(%rbp), %rsi
movl %eax, (%rsi)
leaq 0x237ed(%rip), %rdi     # 0x45fd8
callq 0x21b9c
movq (%r13), %rax
movswq 0xa(%rbx), %rcx
movq 0x8(%rax), %rax
leaq (%rcx,%rcx,2), %rcx
movswq 0x8(%rbx), %rdx
movq (%rax,%rcx,8), %rax
orw $0x40, (%rax,%rdx,4)
cmpb $0x3f, 0xd(%rbx)
sete %al
addb $0x3f, %al
movb %al, 0xd(%rbx)
leaq -0x2c(%rbp), %rdi
callq 0x2bbf6
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq -0x44(%rbp), %rdi
jmp 0x22853
jmp 0x2283e
movq %rax, %rbx
jmp 0x22858
movq %rax, %rbx
leaq -0x34(%rbp), %rdi
jmp 0x22853
movq %rax, %rbx
leaq -0x30(%rbp), %rdi
callq 0x2bbf6
leaq -0x2c(%rbp), %rdi
callq 0x2bbf6
movq %rbx, %rdi
callq 0x4750
nop