// File: 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
subq $0xd0, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x80(%rbp)
testb $0x1, 0xe(%rax)
je 0x4e122
jmp 0x4e609
movq -0x80(%rbp), %rax
cmpb $0x0, 0x1c(%rax)
jne 0x4e13e
movq -0x80(%rbp), %rax
movb 0x1c(%rax), %cl
addb $0x1, %cl
movb %cl, 0x1c(%rax)
jmp 0x4e609
movq -0x80(%rbp), %rsi
addq $0x8, %rsi
leaq 0x44ffb(%rip), %rdi     # 0x93148
callq 0x4a010
movq -0x80(%rbp), %rsi
movq %rax, -0x18(%rbp)
movb %dl, -0x10(%rbp)
leaq 0x43c74(%rip), %rax     # 0x91dd8
movq (%rax), %rdi
addq $0x8, %rsi
callq 0x3d2d0
movq %rax, %rcx
movq -0x80(%rbp), %rax
movzwl (%rcx), %edx
andl $-0x41, %edx
movw %dx, (%rcx)
movsbl 0x1c(%rax), %eax
cmpl $0x2, %eax
jge 0x4e19b
movq -0x80(%rbp), %rax
movb 0x1c(%rax), %cl
addb $0x1, %cl
movb %cl, 0x1c(%rax)
jmp 0x4e506
movb $0xf, -0x19(%rbp)
leaq -0x20(%rbp), %rdi
xorl %edx, %edx
movl %edx, %esi
callq 0x60430
leaq 0x44e9d(%rip), %rdi     # 0x93050
callq 0x3cfb0
movq %rax, -0x28(%rbp)
leaq 0x44e8d(%rip), %rdi     # 0x93050
callq 0x3d010
movq %rax, -0x30(%rbp)
leaq -0x28(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x3cfe0
testb $0x1, %al
jne 0x4e1e2
jmp 0x4e3b9
leaq -0x28(%rbp), %rdi
callq 0x3d040
movq %rax, %rdi
movb $0x0, -0x4d(%rbp)
callq 0x3ce40
movb %al, -0x81(%rbp)
jmp 0x4e1ff
movb -0x81(%rbp), %cl
xorl %eax, %eax
testb $0x1, %cl
movb %al, -0x82(%rbp)
jne 0x4e2c4
jmp 0x4e218
leaq -0x28(%rbp), %rdi
callq 0x3d040
movq %rax, %rdi
callq 0x3d0f0
movq %rax, -0x90(%rbp)
jmp 0x4e232
movq -0x90(%rbp), %rax
movq %rax, -0x48(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x1b050
movq -0x80(%rbp), %rdi
movl 0xac(%rax), %eax
movl %eax, -0x94(%rbp)
addq $0x10, %rdi
callq 0x1b050
movl -0x94(%rbp), %ecx
movq %rax, %rdx
xorl %eax, %eax
cmpl 0xac(%rdx), %ecx
movb %al, -0x82(%rbp)
je 0x4e2c4
leaq -0x28(%rbp), %rdi
callq 0x3d040
movq %rax, %rsi
leaq -0x4c(%rbp), %rdi
callq 0x1b190
jmp 0x4e28f
movq -0x80(%rbp), %rsi
movb $0x1, -0x4d(%rbp)
addq $0x8, %rsi
leaq -0x4c(%rbp), %rdi
callq 0x604f0
movw %ax, -0x96(%rbp)
jmp 0x4e2ad
movw -0x96(%rbp), %ax
cwtl
movsbl -0x19(%rbp), %ecx
cmpl %ecx, %eax
setl %al
movb %al, -0x82(%rbp)
movb -0x82(%rbp), %al
movb %al, -0x97(%rbp)
testb $0x1, -0x4d(%rbp)
jne 0x4e2d8
jmp 0x4e2e1
leaq -0x4c(%rbp), %rdi
callq 0x60460
movb -0x97(%rbp), %al
testb $0x1, %al
jne 0x4e2f0
jmp 0x4e3a9
leaq -0x28(%rbp), %rdi
callq 0x3d040
movq %rax, %rsi
leaq -0x52(%rbp), %rdi
callq 0x1b190
jmp 0x4e307
movl -0x52(%rbp), %eax
movl %eax, -0x20(%rbp)
leaq -0x52(%rbp), %rdi
callq 0x60460
leaq -0x28(%rbp), %rdi
callq 0x3d040
movq %rax, %rsi
leaq -0x56(%rbp), %rdi
callq 0x1b190
jmp 0x4e32d
movq -0x80(%rbp), %rsi
addq $0x8, %rsi
leaq -0x56(%rbp), %rdi
callq 0x604f0
movw %ax, -0x9a(%rbp)
jmp 0x4e347
movw -0x9a(%rbp), %ax
movb %al, -0x19(%rbp)
leaq -0x56(%rbp), %rdi
callq 0x60460
jmp 0x4e3a9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x4e4f8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
testb $0x1, -0x4d(%rbp)
jne 0x4e381
jmp 0x4e38a
leaq -0x4c(%rbp), %rdi
callq 0x60460
jmp 0x4e4f8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x56(%rbp), %rdi
callq 0x60460
jmp 0x4e4f8
jmp 0x4e3ab
leaq -0x28(%rbp), %rdi
callq 0x3d110
jmp 0x4e1bc
movsbl -0x19(%rbp), %eax
cmpl $0xf, %eax
jge 0x4e4ed
movq -0x80(%rbp), %rdi
addq $0x8, %rdi
movl -0x20(%rbp), %eax
movl %eax, -0x60(%rbp)
leaq -0x60(%rbp), %rsi
callq 0x60710
movl %eax, -0xa0(%rbp)
jmp 0x4e3e5
leaq -0x60(%rbp), %rdi
callq 0x60460
movl -0xa0(%rbp), %ecx
movq -0x80(%rbp), %rax
movl %ecx, -0x5c(%rbp)
movl -0x5c(%rbp), %ecx
movl %ecx, -0xa8(%rbp)
movl 0x18(%rax), %edi
callq 0x60410
movl %eax, -0xa4(%rbp)
jmp 0x4e414
movl -0xa8(%rbp), %eax
movl -0xa4(%rbp), %ecx
cmpl %ecx, %eax
jne 0x4e477
callq 0x5270
movl $0x2, %ecx
cqto
idivq %rcx
cmpq $0x0, %rdx
je 0x4e464
movq -0x80(%rbp), %rdi
addq $0x18, %rdi
callq 0x60390
jmp 0x4e448
jmp 0x4e475
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x60(%rbp), %rdi
callq 0x60460
jmp 0x4e4f8
movq -0x80(%rbp), %rdi
addq $0x18, %rdi
callq 0x603d0
jmp 0x4e473
jmp 0x4e475
jmp 0x4e4eb
movq -0x80(%rbp), %rcx
movl -0x5c(%rbp), %eax
cmpl 0x18(%rcx), %eax
jle 0x4e4b6
movq -0x80(%rbp), %rcx
movl -0x5c(%rbp), %eax
subl 0x18(%rcx), %eax
cmpl $0x3, %eax
jg 0x4e4a3
movq -0x80(%rbp), %rdi
addq $0x18, %rdi
callq 0x60390
jmp 0x4e4a1
jmp 0x4e4b4
movq -0x80(%rbp), %rdi
addq $0x18, %rdi
callq 0x603d0
jmp 0x4e4b2
jmp 0x4e4b4
jmp 0x4e4e9
movq -0x80(%rbp), %rax
movl 0x18(%rax), %eax
subl -0x5c(%rbp), %eax
cmpl $0x3, %eax
jg 0x4e4d6
movq -0x80(%rbp), %rdi
addq $0x18, %rdi
callq 0x603d0
jmp 0x4e4d4
jmp 0x4e4e7
movq -0x80(%rbp), %rdi
addq $0x18, %rdi
callq 0x60390
jmp 0x4e4e5
jmp 0x4e4e7
jmp 0x4e4e9
jmp 0x4e4eb
jmp 0x4e4ed
leaq -0x20(%rbp), %rdi
callq 0x60460
jmp 0x4e506
leaq -0x20(%rbp), %rdi
callq 0x60460
jmp 0x4e612
movq -0x80(%rbp), %rax
movq %rax, %rsi
addq $0x8, %rsi
movl 0x18(%rax), %edx
leaq -0x64(%rbp), %rdi
movq %rdi, -0xb8(%rbp)
callq 0x60550
movq -0x80(%rbp), %rdi
movq -0xb8(%rbp), %rsi
callq 0x563c0
movb %al, -0xa9(%rbp)
jmp 0x4e53c
movb -0xa9(%rbp), %al
testb $0x1, %al
jne 0x4e548
jmp 0x4e56e
movl $0x1, -0x68(%rbp)
jmp 0x4e600
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x64(%rbp), %rdi
callq 0x60460
jmp 0x4e612
movq -0x80(%rbp), %rax
movq %rax, %rsi
addq $0x8, %rsi
movl -0x64(%rbp), %ecx
movl %ecx, 0x8(%rax)
leaq 0x44bc2(%rip), %rdi     # 0x93148
callq 0x4a010
movb %dl, -0xc1(%rbp)
movq %rax, -0xc0(%rbp)
jmp 0x4e59a
movq -0x80(%rbp), %rsi
movb -0xc1(%rbp), %al
movq -0xc0(%rbp), %rcx
movq %rcx, -0x78(%rbp)
movb %al, -0x70(%rbp)
leaq 0x4381f(%rip), %rax     # 0x91dd8
movq (%rax), %rdi
addq $0x8, %rsi
callq 0x3d2d0
movq %rax, -0xd0(%rbp)
jmp 0x4e5ce
movq -0x80(%rbp), %rax
movq -0xd0(%rbp), %rcx
movzwl (%rcx), %edx
orl $0x40, %edx
movw %dx, (%rcx)
movsbl 0xd(%rax), %esi
movl $0x3f, %ecx
movl $0x40, %edx
cmpl $0x3f, %esi
cmovel %edx, %ecx
movb %cl, 0xd(%rax)
movl $0x0, -0x68(%rbp)
leaq -0x64(%rbp), %rdi
callq 0x60460
addq $0xd0, %rsp
popq %rbp
retq
movq -0x38(%rbp), %rdi
callq 0x5920
nopl (%rax,%rax)