// File: /workspace/github_cpp_makefile_star2_O3/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 0x225a2
movq %rdi, %rbx
cmpb $0x0, 0x1c(%rdi)
je 0x223f1
leaq 0x8(%rbx), %r13
leaq 0x23c25(%rip), %rdi     # 0x45fd8
movq %r13, %rsi
callq 0x21934
leaq 0x228a6(%rip), %r14     # 0x44c68
movq (%r14), %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 0x223fa
incb %al
movb %al, 0x1c(%rbx)
jmp 0x22538
movb $0x1, 0x1c(%rbx)
jmp 0x225a2
leaq -0x2c(%rbp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x2b798
leaq 0x23ad2(%rip), %r14     # 0x45ee0
movq (%r14), %r15
cmpq %r14, %r15
je 0x22528
movb $0xf, %al
movw %ax, -0x2e(%rbp)
leaq -0x34(%rbp), %r12
movq %rbx, -0x48(%rbp)
cmpb $0x0, 0x1e(%r15)
jne 0x224b4
movq 0x20(%r15), %rax
movl 0xbc(%rax), %eax
movq 0x10(%rbx), %rcx
cmpl 0xbc(%rcx), %eax
je 0x224b4
movq %r14, %rbx
movl 0x18(%r15), %eax
movl %eax, -0x34(%rbp)
movq %r12, %rdi
movq %r13, %r14
movq %r13, %rsi
callq 0x2b7e4
movl %eax, %r13d
movsbl -0x2e(%rbp), %eax
movl %eax, -0x3c(%rbp)
movq %r12, %rdi
callq 0x2b7a6
cmpw -0x3c(%rbp), %r13w
movq %r14, %r13
movq %rbx, %r14
movq -0x48(%rbp), %rbx
jge 0x224b4
movl 0x18(%r15), %eax
movl %eax, -0x34(%rbp)
movl %eax, -0x2c(%rbp)
movq %r12, %rdi
callq 0x2b7a6
movl 0x18(%r15), %eax
movl %eax, -0x34(%rbp)
movq %r12, %rdi
movq %r13, %rsi
callq 0x2b7e4
movw %ax, -0x2e(%rbp)
movq %r12, %rdi
callq 0x2b7a6
movq (%r15), %r15
cmpq %r14, %r15
jne 0x22428
cmpb $0xf, -0x2e(%rbp)
jge 0x22528
movl -0x2c(%rbp), %eax
leaq -0x38(%rbp), %rsi
movl %eax, (%rsi)
movq %r13, %rdi
callq 0x2b8b6
movl %eax, %r12d
leaq -0x38(%rbp), %rdi
callq 0x2b7a6
movl 0x18(%rbx), %edi
callq 0x2b77c
leaq 0x18(%rbx), %r15
cmpl %eax, %r12d
jne 0x22507
callq 0x41d0
testb $0x1, %al
jne 0x22520
movq %r15, %rdi
callq 0x2b764
jmp 0x22528
movl (%r15), %eax
movl %r12d, %ecx
subl %eax, %ecx
jle 0x22518
cmpl $0x4, %ecx
jge 0x224fd
jmp 0x22520
subl %r12d, %eax
cmpl $0x3, %eax
jle 0x224fd
movq %r15, %rdi
callq 0x2b74c
leaq -0x2c(%rbp), %rdi
callq 0x2b7a6
leaq 0x22730(%rip), %r14     # 0x44c68
movl 0x18(%rbx), %edx
leaq -0x2c(%rbp), %r15
movq %r15, %rdi
movq %r13, %rsi
callq 0x2b818
movq %rbx, %rdi
movq %r15, %rsi
callq 0x26713
testb %al, %al
jne 0x22599
movl -0x2c(%rbp), %eax
movl %eax, (%r13)
leaq 0x23a71(%rip), %rdi     # 0x45fd8
movq %r13, %rsi
callq 0x21934
movq (%r14), %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 0x2b7a6
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq -0x38(%rbp), %rdi
jmp 0x225ca
jmp 0x225be
jmp 0x225c3
movq %rax, %rbx
jmp 0x225cf
movq %rax, %rbx
leaq -0x34(%rbp), %rdi
callq 0x2b7a6
leaq -0x2c(%rbp), %rdi
callq 0x2b7a6
movq %rbx, %rdi
callq 0x4740