if($Pref::Marc::eatAmtMult $= "") $Pref::Marc::eatAmtMult = 1.5;
function AIPlayer::getDirVector(%this, %obj) {
	%a = %this.getPosition();
	%b = (isObject(%obj) && isFunction(%obj.getClassName(), getPosition) ? %obj.getPosition() : %obj); // If %obj does not exist, we'll assume it's a position.
	%vector = vectorNormalize(vectorSub(%b, %a));
	%axis   = vectorNormalize(vectorCross("0 1 0", %vector));
	%mag    = mACos(VectorDot("0 1 0", %vector)) * -1;
	return %vector;
}
function AIPlayer::getEatAmt(%this) {
	if(!isObject(%this.holding)) return;
	return ((getWord(%this.getScale(),2)/getWord(%this.holding.getScale(),2))/5)*$Pref::Marc::eatAmtMult;
}

function AIPlayer::randomizeCanSee(%this, %object, %dbg) {
	if(getSimTime()-%this.lastRandomCanSee < 200) return %this.lastRandomSee;
	%this.lastRandomCanSee = getSimTime();
	
	//%dist = vectorDist(%this.getEyePoint(), %object.getPosition());
	
	%max = (vectorDist(%this.getScale(), %object.getScale())*4)-(vectorDist(%object.getVelocity(), "0 0 0")*4);
	//%max += %dist;
	%max = mClamp(%max, 0, 9999);
	
	%rnd = getRandom(0, %max);
	
	%this.lastRandomSee = (%rnd <= getRandom(0, %max/2.4));
	
	//messageClient(findLocalClient(), '', "[PlrScleMod=" @ (vectorDist(%this.getScale(), %object.getScale())*4) @ "]"
	//	@ " [MaxRandom=" @ %max @ "] [SpeedMod=" @ (vectorDist(%object.getVelocity(), "0 0 0")*4) @ "]");
	
	return %this.lastRandomSee;
}

function AIPlayer::wantToEat(%this,%obj) {
	if(%this.getState() $= "Dead") return;
	%this.digestCooldown();
	if(!isObject(%obj)) {
		if(%this.isCrouching()) %this.setCrouching(0);
		if(%this.isJumping()) %this.setJumping(0);
		%this.untilStopMoveX = 0;
		%this.setMoveX(0);
		%this.stopLookingAtPlayer();
		%this.playThread(2,"root");
		%this.setMoveY(0);
		%this.setMoveX(0);
		%this.targ_obj = "";
		cancel(%this.wantToEat);
		%this.loopMarcAI();
		return;
	}
	if(%obj.getState() $= "Dead") {
		if(%this.isCrouching()) %this.setCrouching(0);
		if(%this.isJumping()) %this.setJumping(0);
		%this.untilStopMoveX = 0;
		%this.setMoveX(0);
		%this.stopLookingAtPlayer();
		%this.playThread(2,"root");
		%this.setMoveY(0);
		%this.setMoveX(0);
		cancel(%this.wantToEat);
		%this.loopMarcAI();
		%this.targ_obj = "";
		return;
	}
	// Sounds
	%holdingPlayingInside = 0;
	for(%i=0;%i<%this.getMountedObjectCount();%i++) {
		%mObj  = %this.getMountedObject(%i);
		%mNode = %this.getMountedObjectNode(%i);
		if(%mNode !$= "7") continue;
		%holdingPlayingInside = 1;
		break;
	}
	if(%holdingPlayingInside) {
		if(getRandom(0, 50000) <= 500) {
			%soundTable  = "Gurgle Grbl Groan Grrr Grooooan Brbl Glorp Slosh";
			%randomSound = getWord(%soundTable, getRandom(0, getWordCount(%soundTable)-1));
			doSubTitleText(%this, "(" @ %randomSound @ ")", 3);
		}
	}
	if(!%this.isNotVorist && !%this.trustsObj(%obj)) {
		// We don't want to hurt our other friend's relationships
		if(%obj.getClassName() $= "AIPlayer") {
			for(%i=0;%i<getWordCount(%obj.trustList);%i++) {
				%trusted = getWord(%obj.trustList, %i);
				if(!isObject(%trusted)) continue;
				if(wordPos(%this.trustList, %trusted) != -1) {
					if(%trusted.getClassName() $= "GameConnection") %trName = firstWord(%trusted.getPlayerName());
					else %trName = %trusted.firstName;
					%this.say("One of " @ %trName @ (getSubStr(%trName, 0, 1) $= "s" ? "'" : "'s") @ " friends, huh?");
					%obj.doTrustObj(%this);
					%this.doTrustObj(%obj);
					break;
				}
			}
		} else if(isObject(%obj.client)) {
			for(%i=0;%i<getWordCount(%this.trustList);%i++) {
				%trusted = getWord(%this.trustList, %i);
				if(!isObject(%trusted)) continue;
				if(wordPos(%trusted.trustList, %obj.client) != -1) {
					if(%trusted.getClassName() $= "GameConnection") %trName = firstWord(%trusted.getPlayerName());
					else %trName = %trusted.firstName;
					%this.say("One of " @ %trName @ (getSubStr(%trName, 0, 1) $= "s" ? "'" : "'s") @ " friends, huh?");
					%this.doTrustObj(%obj.client);
					break;
				}
			}
		}
	}
	if(%this.movey_speed == 0 || (isObject(%this.holding) && %this.holding == %obj) || %this.untilStopMoveX-- <= 0) {
		%this.untilStopMoveX = 0;
		%this.setMoveX(0);
	}
	// Check for an easier meal
	if(!%this.isNotVorist && (!isObject(%this.holding) || %this.holding != %obj)) {
		%closestPlayer = %this.findClosestPlayer();
		if(%this.canSeeObject(getWord(%closestPlayer,1))) {
			if(getWord(%closestPlayer, 1) != %obj) {
				if(getWord(%closestPlayer, 0) < 8*getWord(%this.getScale(),2)) {
					if(%this.sizeDiff(getWord(%closestPlayer, 1)) $= "smaller") {
						if(%this.isCrouching()) %this.setCrouching(0);
						if(%this.isJumping()) %this.setJumping(0);
						%this.untilStopMoveX = 0;
						%this.setMoveX(0);
						%this.stopLookingAtPlayer();
						%this.playThread(2,"root");
						%this.setMoveY(0);
						%this.setMoveX(0);
						%this.targ_obj = "";
						cancel(%this.wantToEat);
						%this.loopMarcAI();
						return;
					}
				}
			}
		}
	}
	if(%this.isEmbarrased) {
		if(!isEventPending(%this.stopEmbarrsedSchedule)) %this.isEmbarrased = 0;
		else {
			cancel(%this.wantToEat);
			%this.wantToEat = %this.schedule(60,wantToEat,%obj);
			return;
		}
	}
	if(%this.holdDelay > 0) {
		if(%this.isNotVorist || (%obj.getClassName() $= "AIPlayer" && %obj.trustsObj(%this))) {
			%this.holdDelay = 0;
			cancel(%this.wantToEat);
			%this.wantToEat = %this.schedule(60,wantToEat,%obj);
			return;
		}
		
		if(%this.isCrouching()) %this.setCrouching(0);
		if(%this.isJumping()) %this.setJumping(0);
		%this.setActionThread("sit", 1, 0);
		%this.setMoveY(0);
		
		%lookPoint = vectorAdd(vectorSub(%this.getEyePoint(), "0 0 1"), vectorScale(%this.getEyeVector(), 2));
		%this.setAimLocation(%lookPoint);
		
		if(getSimTime() - %this.lastPoutThreadTime >= 300) {
			%this.lastPoutThreadTime = getSimTime();
			%this.playThread(0, "activate2");
		}
		
		%this.holdDelay--;
		cancel(%this.wantToEat);
		%this.wantToEat = %this.schedule(60,wantToEat,%obj);
		return;
	}
		
	if(%this.isNotVorist && !%obj.membank_obj[%this]) %obj.membank_obj[%this] = 1;
	%this.targ_obj = %obj;
	if(%this.isNotVorist || %this.trustsObj(%obj)) {
		%obj.targeting_obj = %this;
	}
	%dif_x = getWord(%this.getScale(),0)-0.8;
	%dif_y = getWord(%this.getScale(),1)-0.8;
	%dif_z = getWord(%this.getScale(),2)-0.8;
	if(getWord(%obj.getScale(),0) <= %dif_x) {
		if(getWord(%obj.getScale(),1) <= %dif_y) {
			if(getWord(%obj.getScale(),2) <= %dif_z) {
				%continue = 1;
			}
		}
	}
	if(!%continue) {
		%this.setMoveY(0);
		%this.setHeadAngle(0);
		%this.lastEatObj = "";
		%this.loopMarcAI();
		return;
	}
	if(%this.targ_lastLostObj == %obj) {
		%this.targ_lastLostObj = "";
		%this.say("#FOUNDTARGET");
		if(isObject(%obj.client)) {
			%rem = %this.getRemember(%obj.client);
			if(%rem != -1) {
				if(isObject(%obj.lastHeldBy) && %obj.lastHeldBy != %this) {
					%lastDist = vectorDist(%this.getPosition(),%obj.lastHeldBy.getPosition());
				} else {
					%lastDist = 9999;
				}
				if(%this.holdDelay-- <= 0 && %lastDist > (5*getWord(%this.getScale(),2)) && %canSeeObject && %dist < (2*getWord(%this.getScale(),2))) {
					if(getWord(%rem,1) > 10) %this.say("#FOUNDTARGETAFTERLOSS");
					else %this.say("#FOUNDTARGETAFTERLOSS_SMALL");
				} else {
					if(getWord(%rem,1) > 10) %this.say("#FOUNDTARGETAFTERLOSS_LONG");
					else %this.say("#FOUNDTARGET");
				}
			}
		}

	}
	%zdist = vectorDist("0 0" SPC getWord(%this.getPosition(),2),"0 0" SPC getWord(%obj.getPosition(),2));
	%canSeeObject = %this.canSeeObject(%obj);
	if(%canSeeObject) {
		if(!%this.lastCanSee && !%this.randomizeCanSee(%obj)) %canSeeObject = 0;
		//if(%zdist > 40) %canSeeObject = 0;
	}
	if(%canSeeObject) {
		cancel(%this.smoothTurn);
		%this.targ_lastSeenPos = %obj.getPosition();
		%this.targ_startSeen = getSimTime();
	}
	%this.lastCanSee = %canSeeObject;
	%searchingForObject = 0;
	if(!%canSeeObject && !%obj.inMouth) {
		// If we can't find them, let's look for them at the last place we saw them.
		%searchingForObject = 1;
		%distFromLast = vectorDist(%this.getPosition(),%this.targ_lastSeenPos);
		if(!%this.isNotVorist && %distFromLast > (2*getWord(%this.getScale(),2))) {
			if(getSimTime()-%this.targ_startSeen >= 12000) {
				// We can't get to where they last were. Let's look around here, instead.
				%this.targ_lastSeenPos    = %this.getPosition();
			}
			if(!%this.targ_searchingForObject) {
				// Extend the look-for position a bit so that we can see around corners
				%vc = %this.getDirVector(%this.targ_lastSeenPos);
				%this.targ_lastSeenPos = vectorAdd(%this.targ_lastSeenPos, vectorScale(%vc, 2));
				%ray = getRaycastFromObject(%this, $TypeMasks::FxBrickAlwaysObjectType, %vc);
				if(isObject(getField(%ray, 0))) {
					// We don't want to waste time walking into a wall
					%this.targ_lastSeenPos = getField(%ray, 1);
				}
			}
			%brickObj = getWord(getRaycastFromObject(%this, $TypeMasks::FxBrickAlwaysObjectType), 0);
			if(isObject(%brickObj)) {
				%bDist = vectorDist(getWords(%this.getTransform(), 0, 1) SPC "0", getWords(%brickObj.getTransform(), 0, 1) SPC "0");
				if(%bDist < 2*getWord(%this.getScale(), 2)) {
					if(%brickObj.getDataBlock().isDoor && !%brickObj.getDataBlock().isOpen) {
						for(%evIdx=0;%evIdx<%brickObj.numEvents;%evIdx++) {
							if(!%brickObj.eventEnabled[%evIdx]) continue;
							if(%brickObj.eventInput[%evIdx] !$= "onActivate") continue;
							if(%brickObj.eventOutput[%evIdx] !$= "door") continue;
							if(%brickObj.eventOutputParameter[%evIdx@"_1"] $= "4") continue;
							%brickObj.onActivate();
							%this.playThread(1, activate);
							break;
						}
					}
				}
			}
			%this.setAimLocation(%this.targ_lastSeenPos);
			%this.targ_giveUpSearch = 0;
			%this.targsearch_crouchCheck = -1;
			%this.targsearch_crouched = 0;
			%this.setMoveY(0.2);
		} else if(!%this.isNotVorist) {
			// Look around. After a while, give up.
			if(%this.targ_giveUpSearch++ > 500) {
				%this.targ_giveUpSearch = 0;
				%this.targ_lastLostObj = %obj;
				%this.targsearch_doNormal = 0;
				%this.say("#GIVEUPSEARCH");
				%this.loopMarcAI();
				%this.lastEatObj = "";
				%this.targ_obj = "";
				if(isObject(%obj.client)) %this.rememberAvatar(%obj.client,%this.targ_startSeen);
				return;
			}
			if(getRandom(0,50000) < 1000) {
				%this.say("#SEARCHFORTARGET");
			}
			%this.stopLookingAtPlayer();
			if(getWord(%this.targ_lastSeenPos, 2) < getWord(%this.getWorldBoxCenter(), 2)) {
				// The guy was last seen in a place on the ground (presumebly). Let's crouch down.
				if(%this.targsearch_crouchCheck++ <= 60) {
					// Crouch down.
					%this.targsearch_crouched = 1;
					%this.targsearch_doNormal = 0;
					%this.stopLookingAtPlayer();
					if(!%this.isCrouching()) %this.setCrouching(1);
				} else {
					%this.targsearch_crouched = 0;
					%this.targsearch_doNormal = 1;
					if(%this.isCrouching()) %this.setCrouching(0);
				}
			} else %this.targsearch_doNormal = 1;
			if(%this.targsearch_doNormal && getRandom(0,10000) < 1000) %this.smoothTurn(getRandom(0,180));
			%this.setMoveY(0);
		}
	} else {
		if(%this.targsearch_crouched) {
			%this.setCrouching(0);
			%this.targsearch_crouched = 0;
		}
	}
	%this.targ_searchingForObject = %searchingForObject;
	%this.lastCheck_CanSeeObject = %canSeeObject;
	if(%this.movementLogicCheck++ >= 3 && !%this.isCrouching() && %this.movey_speed != 0 && !isObject(%this.holding)) {
		%this.movementLogicCheck = -1;
		if(isObject(%obj.lastHeldBy)) {
			%lastDist = vectorDist(%this.getPosition(),%obj.lastHeldBy.getPosition());
		} else {
			%lastDist = 9999;
		}
		if(%obj.lastHeldBy == %this) %lastDist = 9999;
		%eyeVec = %this.getForwardVector();
		%vector = VectorScale(%eyeVec, 100);
		%mask   = $TypeMasks::FXBrickAlwaysObjectType;
		%calc   = getWord(%this.getScale(),2);
		%side   = vectorCross(vectorNormalize(%this.getForwardVector()), vectorNormalize(%this.getUpVector()));
		%start_UpHalf      = getWords(%this.getWorldBoxCenter(),0,1) SPC getWord(%this.getPosition(),2)+%calc*1.5;
		%start_Center      = getWords(%this.getWorldBoxCenter(),0,1) SPC getWord(%this.getPosition(),2)+%calc;
		%start_LowerHalf   = getWords(%this.getWorldBoxCenter(),0,1) SPC getWord(%this.getPosition(),2)+%calc/2;
		%start_CenterRight = vectorAdd(%start_Center, vectorScale(%side, 0.6*%calc));
		%start_CenterLeft  = vectorSub(%start_Center, vectorScale(%side, 0.6*%calc));
		if($debug != %this) {
			if(isObject(%dbgobj = %this.dbgline1)) %dbgobj.delete();
			if(isObject(%dbgobj = %this.dbgline2)) %dbgobj.delete();
			if(isObject(%dbgobj = %this.dbgline3)) %dbgobj.delete();
			if(isObject(%dbgobj = %this.dbgline4)) %dbgobj.delete();
			if(isObject(%dbgobj = %this.dbgline5)) %dbgobj.delete();
		}
		// Upper half
		%end = VectorAdd(%start_UpHalf, %vector);
		%scanTarg = containerRayCast(%start_UpHalf, %end, %mask, %this);
		%scanTarg_Up = getWord(%scanTarg,0);
		if($debug == %this) %this.dbgline1 = drawLine(%start_UpHalf, %end, (isObject(%this.dbgline1) ? %this.dbgline1 : 0));
		// Center
		%end = VectorAdd(%start_Center, %vector);
		%scanTarg = containerRayCast(%start_Center, %end, %mask, %this);
		%scanTarg_Center = getWord(%scanTarg,0);
		if($debug == %this) %this.dbgline2 = drawLine(%start_Center, %end, (isObject(%this.dbgline2) ? %this.dbgline2 : 0));
		// Lower half
		%end = VectorAdd(%start_LowerHalf, %vector);
		%scanTarg = containerRayCast(%start_LowerHalf, %end, %mask, %this);
		%scanTarg_Lower = getWord(%scanTarg,0);
		if($debug == %this) %this.dbgline3 = drawLine(%start_LowerHalf, %end, (isObject(%this.dbgline3) ? %this.dbgline3 : 0));
		// Center Left
		%end = VectorAdd(%start_CenterLeft, %vector);
		%scanTarg = containerRayCast(%start_CenterLeft, %end, %mask, %this);
		%scanTarg_CenterLeft = getWord(%scanTarg,0);
		if($debug == %this) %this.dbgline4 = drawLine(%start_CenterLeft, %end, (isObject(%this.dbgline4) ? %this.dbgline4 : 0));
		// Center Right
		%end = VectorAdd(%start_CenterRight, %vector);
		%scanTarg = containerRayCast(%start_CenterRight, %end, %mask, %this);
		%scanTarg_CenterRight = getWord(%scanTarg,0);
		if($debug == %this) %this.dbgline5 = drawLine(%start_CenterRight, %end, (isObject(%this.dbgline5) ? %this.dbgline5 : 0));
		// Calculate
		%detectedUp          = 0;
		%detectedLower       = 0;
		%detectedCenter      = 0;
		%detectedCenterLeft  = 0;
		%detectedCenterRight = 0;
		if(isObject(%scanTarg_Up)) {
			%dist = vectorDist(%scanTarg_Up.getPosition(),%this.getPosition());
			if(%dist <= (2*getWord(%this.getScale(),2))) {
				if($debug == %this) %this.dbgline1.setNodeColor("ALL", "1 1 1 0.5");
				%detectedUp = 1;
			} else
				if($debug == %this) %this.dbgline1.setNodeColor("ALL", "1 1 1 1");
		}
		if(isObject(%scanTarg_Center)) {
			%dist = vectorDist(%scanTarg_Center.getPosition(),%this.getPosition());
			if(%dist <= (2*getWord(%this.getScale(),2))) {
				if($debug == %this) %this.dbgline2.setNodeColor("ALL", "1 1 1 0.5");
				%detectedCenter = 1;
			} else
				if($debug == %this) %this.dbgline2.setNodeColor("ALL", "1 1 1 1");
		}
		if(isObject(%scanTarg_Lower)) {
			%dist = vectorDist(%scanTarg_Lower.getPosition(),%this.getPosition());
			if(%dist <= (2*getWord(%this.getScale(),2))) {
				if($debug == %this) %this.dbgline3.setNodeColor("ALL", "1 1 1 0.5");
				%detectedLower = 1;
			} else
				if($debug == %this) %this.dbgline3.setNodeColor("ALL", "1 1 1 1");
		}
		if(isObject(%scanTarg_CenterLeft)) {
			%dist = vectorDist(%scanTarg_CenterLeft.getPosition(),%this.getPosition());
			if(%dist <= (3*getWord(%this.getScale(),2))) {
				if($debug == %this) %this.dbgline4.setNodeColor("ALL", "1 1 1 0.5");
				%detectedCenterLeft = 1;
			} else
				if($debug == %this) %this.dbgline4.setNodeColor("ALL", "1 1 1 1");
		}
		if(isObject(%scanTarg_CenterRight)) {
			%dist = vectorDist(%scanTarg_CenterRight.getPosition(),%this.getPosition());
			if(%dist <= (3*getWord(%this.getScale(),2))) {
				if($debug == %this) %this.dbgline5.setNodeColor("ALL", "1 1 1 0.5");
				%detectedCenterRight = 1;
			} else
				if($debug == %this) %this.dbgline5.setNodeColor("ALL", "1 1 1 1");
		}
		if(%detectedCenterRight && !%detectedCenterLeft) {
			%this.setMoveX(-%this.movey_speed);
			%this.untilStopMoveX = 3;
		} else if(!%detectedCenterRight && %detectedCenterLeft) {
			%this.setMoveX(%this.movey_speed);
			%this.untilStopMoveX = 3;
		} else { %this.setMoveX(0); %this.untilStopMoveX = 0; }
		if(!%detectedUp && %detectedCenter && %detectedLower && getWord(%obj.getPosition(),2) >= getWord(%start_Center,2)) {
			if(%lastDist >= (7*getWord(%this.getScale(),2)) && !%this.isNotVorist) {
				%this.setJumping(1);
				cancel(%this.stopJumping);
				%this.stopJumping = %this.schedule(100,setJumping,0);
			}
		}
		if(getWord(%obj.getPosition(),2) >= getWord(%start_Center,2) && ((%detectedUp && %detectedCenter && %detectedLower) || (!%detectedUp && %detectedCenter && %detectedLower))) {
			if(%lastDist >= (7*getWord(%this.getScale(),2)) && !%this.isNotVorist) {
				%this.setJumping(1);
				cancel(%this.stopJumping);
				%this.stopJumping = %this.schedule(100,setJumping,0);
			}
		}
		if(getWord(%obj.getPosition(),2) <= getWord(%start_LowerHalf,2) && ((%detectedUp && %detectedCenter && !%detectedLower) || (%detectedUp && !%detectedCenter && !%detectedLower) || (!%detectedUp && %detectedCenter && !%detectedLower))) {
			if(%lastDist >= (7*getWord(%this.getScale(),2)) && (!%this.isNotVorist || !%this.dontFollow)) {
				%this.setCrouching(1);
				cancel(%this.stopCrouching);
				%this.stopCrouching = %this.schedule(1500,setCrouching,0);
			}
		}
	}
	if(!isObject(%obj.heldBy) || (%this.isNotVorist && isObject(%obj.heldBy) && %obj.lastHeldBy == %this && %obj.heldBy != %this)) {
		%this.setShapeName(%this.firstName SPC %this.lastName,"8564862");
		if(%this.delayForLookingAtObj-- <= 0) {
			%this.delayForLookingAtObj = 0;
			if(%canSeeObject) if(%this.movey_speed == 0) %this.lookAtPlayer(%obj); else { %this.setHeadAngle(0); cancel(%this.lookAtPlayer); %this.setAimObject(%obj); }
		}
		%dist = vectorDist(%this.getPosition(),%obj.getPosition());
		if(isObject(%obj.lastHeldBy) && %obj.lastHeldBy != %this) {
			%lastDist = vectorDist(%this.getPosition(),%obj.lastHeldBy.getPosition());
		} else {
			%lastDist = 9999;
		}
		if(%obj.lastHeldBy == %this) %lastDist = 9999;
		else if(%lastDist != 9999) {
			if(%this.sizeDiff(%obj.lastHeldBy) $= "smaller") {
				// They can't do anything about this.
				%lastDist = 9999;
			}
		}
		%zdist     = vectorDist("0 0" SPC getWord(%this.getPosition(),2),"0 0" SPC getWord(%obj.getPosition(),2));

		// Get the middle point between the two hands
		%leftPnt   = %this.getMuzzlePoint(0);
		%rightPnt  = %this.getMuzzlePoint(1);
		%middlePnt = vectorScale(vectorAdd(%leftPnt, %rightPnt), 0.5);
		
		%muzDist   = vectorDist(%middlePnt, %obj.getPosition());
		
		// Mouth distance
		%mouthDist = vectorDist(%this.getEyePoint(), %obj.getPosition());
		
		if(%canSeeObject == 2) {
			if(%this.thread_slot[3] !$= "root") {
				%this.playThread(3, "root");
			}
			
			if(getSimTime() - %this.lastStopMove >= 0 && getSimTime() - %this.lastStopMove <= 1000) {
				%this.vore_tease_0 = 0;
			}
			
			if(%dist < (2*getWord(%this.getScale(), 2))) {
				if(getSimTime()-%this.lastStopMove >= 4000) {
					%this.setActionThread("sit", 1, 0);
				}
			}
			
			%this.makeStomachSound(1);
			
			if(getSimTime()-%this.lastStopMove >= 40000 && !%this.vore_tease_0) {
				%this.vore_tease_0 = 1;
				%this.say("You're making me really hungry. Just come out of there already!");
			}
			
			%lastDist = 1;
		}
		// %lastDist = The distance from the last person who held this object
		// %dist     = Our distance from the object
		// %muzDist  = Our hand's distance from the object (must be 0.9 or less)
		// %dist < 3.6 to do armReadyBoth animation
		// %dist < 2 to do crouch
		if(!isObject(%this.holding) && %lastDist > (5*getWord(%this.getScale(),2))) {
			if((!%this.isNotVorist && !%this.trustsObj(%obj)) && %this.holdDelay <= 0 && %canSeeObject) {
				if(%dist < (2*getWord(%this.getScale(), 2))) {
					if(%this.thread_slot[3] !$= "armReadyBoth") {
						%this.playThread(3, "armReadyBoth");
					}
					if(!%this.isCrouching()) { %this.setCrouching(1); if(!%this.pounced && %obj.getVelocity() !$= "0 0 0") { %this.pounced = 1; %this.addVelocity(getWords(vectorScale(%this.getForwardVector(), getWord(%this.getScale(), 2) + 2), 0, 1) SPC "10"); } }
				} else if(%dist < (3.6*getWord(%this.getScale(), 2))) {
					if(%this.thread_slot[3] !$= "armReadyBoth") {
						%this.playThread(3, "armReadyBoth");
					}
				} else {
					if(%this.thread_slot[3] !$= "root") { %this.playThread(3, "root"); }
					if(%this.isCrouching()) { %this.setCrouching(0); %this.pounced = 0;}
				}
			}
			
			// If our buddy is injured, then forcibly stick them in our mouth to heal them.
			// 0 = We haven't asked them.
			// 1 = We asked them, and are awaiting an answer.
			// 2 = They said no
			// 3 = They said yes
			if((%this.isNotVorist || %this.trustsObj(%obj)) && isObject(%obj.client) && %obj.hudBroken && %this.helpBrokenHud[%obj] != 2) {
				if(!%this.helpBrokenHud[%obj] || %this.helpBrokenHud[%obj] != 3) {
					if(%this.helpBrokenHud[%obj] == 0) {
						%this.awaitingAnswer = 2;
						%this.helpBrokenHud[%obj] = 1;
						%this.say("You don't look too good, " @ firstWord(%obj.client.name) @ ".. Do you want some help with that?");
					} else if(%this.helpBrokenHud[%obj] == 1 && %this.awaitingAnswer == -1) {
						%this.awaitingAnswer = 0;
						%this.helpBrokenHud[%obj] = (%this.answer ? 3 : 2);
						if(%this.answer) %this.say("Okay, come on over here.");
						else %this.say("Alright, if you insist..");
						%this.answer         = 0;
					}
				} else {
					if(%dist < (2*getWord(%this.getScale(), 2))) {
						if(%this.thread_slot[3] !$= "armReadyBoth") {
							%this.playThread(3, "armReadyBoth");
						}
						if(!%this.isCrouching()) { %this.setCrouching(1); if(!%this.pounced && %obj.getVelocity() !$= "0 0 0") { %this.pounced = 1; %this.addVelocity(getWords(vectorScale(%this.getForwardVector(), getWord(%this.getScale(), 2) + 2), 0, 1) SPC "10"); } }
					} else if(%dist < (3.6*getWord(%this.getScale(), 2))) {
						if(%this.thread_slot[3] !$= "armReadyBoth") {
							%this.playThread(3, "armReadyBoth");
						}
					} else {
						if(%this.thread_slot[3] !$= "root") { %this.playThread(3, "root"); }
						if(%this.isCrouching()) { %this.setCrouching(0); %this.pounced = 0;}
					}
					
					if(%lastDist > (5*getWord(%this.getScale(),2)) && %canSeeObject && (%mouthDist < 1 || %muzDist < 3)) {
						%this.setcrouching(0);
						%this.stopLookingAtPlayer();
						%this.dontGiveControl = 1;
						Player::holdOtherPlayer(%this, %obj);
						schedule(700, 0, serverCmdMouth, %this);
						schedule(12000, 0, eval, %obj @ ".client.fixHud();" @ %this @ ".helpBrokenHud[" @ %obj @ "] = 0;serverCmdMouth(" @ %this @ ");");
					}
				}
			}
		}
		if(%this.holdDelay-- <= 0 && %lastDist > (5*getWord(%this.getScale(),2)) && %canSeeObject && (%mouthDist < 1 || %muzDist < 3)) {
			// Pick them up
			if(%obj.heldBy != %this && (!%this.isNotVorist && !%this.trustsObj(%obj))) {
				if(%this.isCrouching()) { %this.setCrouching(0); }
				%this.holdDelay = 0;
				%this.stopLookingAtPlayer();
				if(%lastDist > (5*getWord(%this.getScale(),2))) {
					if(%lastDist < (7*getWord(%this.getScale(),2))) {
						%this.say("#CAUGHT_OWNERCLOSE");
						%this.doNotEat = 1;
					} else {
						if(!%obj.membank_obj[%this]) %obj.membank_obj[%this] = 1;
						if(!%this.isNotVorist && !%this.trustsObj(%obj)) %this.say("#CAUGHT");
						else %this.say("#CAUGHT_NOTVORIST");
					}
				} else {
					if(!%obj.membank_obj[%this]) %obj.membank_obj[%this] = 1;
					if(!%this.isNotVorist && !%this.trustsObj(%obj)) %this.say("#CAUGHT");
					else %this.say("#CAUGHT_NOTVORIST");
				}
				Player::holdOtherPlayer(%this, %obj);
			}
		} else {
			if(%canSeeObject && %dist < (50*getWord(%this.getScale(),2)) && %dist > (2*getWord(%this.getScale(),2))) {
				// We can see them; Let's try to go get them!
				if(!%this.isNotVorist && !%this.trustsObj(%obj)) {
					if(%obj.hudBroken) {
						%brokeSpeed = ((vectorLen(%obj.getVelocity())/20)*0.5);
						%speed      = mClampF((%speed/3)+%brokeSpeed+0.1,0,0.3);
					}
					%speed = (%lastDist > (5*getWord(%this.getScale(),2)) ? (%speed !$= "" ? %speed : "0.4") : "0.1");
					%this.setMoveY(%speed);
				} else if(!%this.dontFollow && %dist >= (2.5*getWord(%this.getScale(),2))) {
					if(%dist >= (2.5*getWord(%this.getScale(),2))) %move = "0.1";
					if(%dist >= (3*getWord(%this.getScale(),2))) %move = "0.2";
					if(%dist >= (3.5*getWord(%this.getScale(),2))) %move = "0.3";
					%this.setMoveY((%lastDist > (5*getWord(%this.getScale(),2)) ? %move : "0.1"));
				} else
					%this.setMoveY(0);
				
				%nonZDist = vectorDist(getWords(%this.getPosition(), 0, 1) SPC "0", getWords(%obj.getPosition(), 0, 1) SPC "0");
				if(%canSeeObject != 2 && ((!%this.isNotVorist && !%this.trustsObj(%obj)) || !%this.dontFollow) && %nonZDist < (2*getWord(%this.getScale(),2)) && %zdist > (4*getWord(%this.getScale(),2)) && %zdist < (9*getWord(%this.getScale(),2))) {
					%this.setJumping(1);
					cancel(%this.jump);
					%this.jump = %this.schedule(10,setJumping,0);
				}
			} else if(%canSeeObject) %this.setMoveY(0);
		}
	} else if(%this.holding == %obj) {
		if(isObject(%obj.client)) if(!%this.dontGiveControl && %obj.client.getControlObject() != %this && (%this.isNotVorist || %this.trustsObj(%obj))) {
			%obj.client.oldPlayer = %obj;
			%obj.client.player = %this;
			%obj.client.setControlObject(%this);
		}
		if((%this.trustsObj(%obj) || %this.isNotVorist) && !isObject(%obj.client)) {
			// We're holding a player, and we either trust this player or we are just not into vore.
			if((%this.isNotVorist && !%obj.trustsObj(%this))) {
				// They don't actually trust us; Let's let them go!
				Player::holdOtherPlayer(%this, %obj);
				cancel(%this.wantToEat);
				if($debugsilent) { %this.wantToEat = schedule(60,0,eval,"$Con::logBufferEnabled = 0;"@%this@".wantToEat("@%obj@");$Con::logBufferEnabled = 1;"); return; }
				%this.wantToEat = %this.schedule(60,wantToEat,%obj);
				return;
			} else {
				// They trust us!
				%this.setHeadAngle(-0.5);
			}
		}
		if(isObject(%obj.lastHeldBy)) {
			%lastDist = vectorDist(%this.getPosition(),%obj.lastHeldBy.getPosition());
		} else {
			%lastDist = 9999;
		}
		if(%obj.lastHeldBy == %this) %lastDist = 9999;
		else if(%lastDist != 9999) {
			if(%this.sizeDiff(%obj.lastHeldBy) $= "smaller") {
				// They can't do anything about this.
				%lastDist = 9999;
			}
		}
		%this.setMoveY(0);
		%this.setShapeName(%this.firstName SPC %this.lastName@" - "@%this.eatDelay@"/90","8564862");
		%tbl = "||||||||||||||||||||||||||";
		if(!%this.isNotVorist && !%this.trustsObj(%obj)) {
			%mouth_percent = mFloor((%this.eatDelay/40)*strLen(%tbl));
			if(%mouth_percent >= strLen(%tbl)) %swallow_percent = mFloor(((%this.eatDelay-40)/90)*strLen(%tbl));
			if(%this.eatDelay == -1) {
				%mouth_percent = 0;
				%swallow_percent = 0;
			}
			if(%obj.energyDrinkAmt > 0) %hasDrinkHigh = 1;
			centerPrint(%obj.client,"<br><br><br><just:center><font:Consolas:14>\c6HELD \c0" @ getSubStr(%tbl,0,%mouth_percent)@"\c6"@getSubStr(%tbl,%mouth_percent,strLen(%tbl))@" MOUTH" @ (%hasDrinkHigh ? "\c1" : "\c0") @ " "@getSubStr(%tbl,0,%swallow_percent)@"\c6"@getSubStr(%tbl,%swallow_percent,strLen(%tbl))@" STOMACH",1);
		}
		%this.eatDelay += %this.getEatAmt();
		if(%this.eatDelay < 40) {
			%this.setHeadAngle(-0.5);
			if(%this.doNotEat) {
				if(getSimTime()-%this.lastStopMove >= 4000) {
					%this.setActionThread("sit", 1, 0);
				}
				%this.eatDelay = -1;
			}
			if(%this.trustsObj(%obj) || %this.isNotVorist) %this.eatDelay = -1;
			if(%lastDist > (7*getWord(%this.getScale(),2))) {
				if(%this.doNotEat) {
					%this.say("#CONTEMPLATE");
					%this.doNotEat = 0;
				}
			} else {
				if(!%this.doNotEat) {
					%this.say("#OWNERTOOCLOSE");
					%this.doNotEat = 1;
				}
			}
			if(!%this.isNotVorist && %lastDist < (5*getWord(%this.getScale(),2))) {
				if(%this.doNotEat) %this.say("#CAUGHTHOLDING");
				else %this.say("#CAUGHTHOLDING_EAT");
				%this.setHeadAngle(0);
				Player::holdOtherPlayer(%this);
				%this.eatDelay = -1;
				%this.delayForLookingAtObj = 30;
				%this.setAimObject(%obj.lastHeldBy);
			}
		} else if(%this.eatDelay >= 40 && %this.eatDelay < 130) {
			if(!%obj.inMouth) {
				%obj.canStruggle = 0;
				%this.setHeadAngle(0);
				%this.say("#INMOUTH");
				serverCmdMouth(%this);
			}
		} else if(%this.eatDelay > 40 && %this.eatDelay < 130) {
			if(%lastDist < (5*getWord(%this.getScale(),2))) {
				serverCmdMouth(%this);
				if(%this.doNotEat) %this.say("#CAUGHTHOLDING");
				else %this.say("#CAUGHTHOLDING_EAT");
				%this.setHeadAngle(0);
				Player::holdOtherPlayer(%this);
				%this.eatDelay = -1;
				%this.delayForLookingAtObj = 30;
				%this.setAimObject(%obj.lastHeldBy);
			}
		} else if(%this.eatDelay >= 130) {
			serverCmdSwallow(%this);
			if(%this.becomeNotVorist) {
				%this.becomeNotVorist = 0;
				%this.isNotVorist = 1;
				%obj.stomach_struggle = $CACHE::Marc::StomachStruggle::Max/1.4;
			}
			%this.eatDelay = -1;
			%this.loopMarcAI(%this.firstName SPC %this.lastName, %this.getScale(), %this.personality, %this.isNotVorist);
			return;
		}
	} else if(isObject(%obj.heldBy)) {
		if(!%this.isNotVorist && !%this.trustsObj(%obj.heldBy)) {
			if(%this.sizeDiff(%obj.heldBy) $= "smaller") {
				// Since they can't do anything about it, let's grab it from their hands.
				if(%obj.inMouth) {
					// They have our meal in their mouth!
					Player::holdOtherPlayer(%this,%obj.heldBy);
					%this.say("#SMALLER_HAS_OUR_TARGET_IN_MOUTH");
				} else {
					if(%obj.holding == %obj.heldBy) Player::holdOtherPlayer(%this,%obj.heldBy); if(!%obj.heldBy.notarget) Player::activateStuff(%obj.heldBy);
				}
			} else {
				%this.setAimObject(%obj.heldBy);
				%dist = vectorDist(%this.getPosition(),%obj.heldBy.getPosition());
				if(%dist < (9*getWord(%this.getScale(),2)) && %dist > (4*getWord(%this.getScale(),2)))
					%this.setMoveY(0.4);
				else
					%this.setMoveY(0);
			}
		}
	}
	cancel(%this.wantToEat);
	if($debugsilent) {
		%this.wantToEat = schedule(60,0,eval,"$Con::logBufferEnabled = 0;"@%this@".wantToEat("@%obj@");$Con::logBufferEnabled = 1;");
		return;
	}
	%this.wantToEat = %this.schedule(60,wantToEat,%obj);
}
function AIPlayer::getSideVector(%this) {
	%vec = vectorRotateEuler(%this.getForwardVector(), "0 90 0");
	return %vec;
}
function AIPlayer::movementLogicCheck(%this) {
	%eyeVec = %this.getForwardVector();
	%vector = VectorScale(%eyeVec, 100);
	%mask   = $TypeMasks::FXBrickAlwaysObjectType;
	%calc   = getWord(%this.getScale(),2);
	%start_UpHalf      = getWords(%this.getWorldBoxCenter(),0,1) SPC getWord(%this.getPosition(),2)+%calc*1.5;
	%start_Center      = getWords(%this.getWorldBoxCenter(),0,1) SPC getWord(%this.getPosition(),2)+%calc;
	%start_LowerHalf   = getWords(%this.getWorldBoxCenter(),0,1) SPC getWord(%this.getPosition(),2)+%calc/2;
	if($debug == %this) {
		_1.item.setTransform(%start_UpHalf SPC getWords(%this.getTransform(),3,6));
		_2.item.setTransform(%start_Center SPC getWords(%this.getTransform(),3,6));
		_3.item.setTransform(%start_LowerHalf SPC getWords(%this.getTransform(),3,6));
		%s = %this.getScale();
		_1.item.setScale(%s);
		_2.item.setScale(%s);
		_3.item.setScale(%s);
		_1.item.setShapeName("Top");
		_2.item.setShapeName("Center");
		_3.item.setShapeName("Lower");
	}
	// Upper half
	%end = VectorAdd(%start_UpHalf, %vector);
	%scanTarg = containerRayCast(%start_UpHalf, %end, %mask, %this);
	%scanTarg_Up = getWord(%scanTarg,0);
	// Center
	%end = VectorAdd(%start_Center, %vector);
	%scanTarg = containerRayCast(%start_Center, %end, %mask, %this);
	%scanTarg_Center = getWord(%scanTarg,0);
	// Lower half
	%end = VectorAdd(%start_LowerHalf, %vector);
	%scanTarg = containerRayCast(%start_LowerHalf, %end, %mask, %this);
	%scanTarg_Lower = getWord(%scanTarg,0);
	// Calculate
	%detectedUp     = 0;
	%detectedCenter = 0;
	%detectedLower  = 0;
	if(isObject(%scanTarg_Up)) {
		%dist = vectorDist(%scanTarg_Up.getPosition(),%this.getPosition());
		if(%dist <= (2*getWord(%this.getScale(),2))) {
			if($debug == %this) _1.item.setNodeColor("ALL","1 0 0 1 0.5");
			%detectedUp = 1;
		} else
			if($debug == %this) _1.item.setNodeColor("ALL","1 0 0 1 1");
	}
	if(isObject(%scanTarg_Center)) {
		%dist = vectorDist(%scanTarg_Center.getPosition(),%this.getPosition());
		if(%dist <= (2*getWord(%this.getScale(),2))) {
			if($debug == %this) _2.item.setNodeColor("ALL","0 1 0 0.5");
			%detectedCenter = 1;
		} else
			if($debug == %this) _2.item.setNodeColor("ALL","0 1 0 1");
	}
	if(isObject(%scanTarg_Lower)) {
		%dist = vectorDist(%scanTarg_Lower.getPosition(),%this.getPosition());
		if(%dist <= (2*getWord(%this.getScale(),2))) {
			if($debug == %this) _3.item.setNodeColor("ALL","0 0 1 0.5");
			%detectedLower = 1;
		} else
			if($debug == %this) _3.item.setNodeColor("ALL","0 0 1 1");
	}
	if(!%detectedUp && %detectedCenter && %detectedLower) {
		//%this.setJumping(1);
		cancel(%this.stopJumping);
		%this.stopJumping = %this.schedule(100,setJumping,0);
	}
	if(%detectedUp && %detectedCenter && %detectedLower) {
		//%this.setJumping(1);
		cancel(%this.stopJumping);
		%this.stopJumping = %this.schedule(100,setJumping,0);
	}
	if(((%detectedUp && %detectedCenter && !%detectedLower) || (%detectedUp && !%detectedCenter && !%detectedLower) || (!%detectedUp && %detectedCenter && !%detectedLower))) {
		%this.setCrouching(1);
		cancel(%this.stopCrouching);
		%this.stopCrouching = %this.schedule(1500,setCrouching,0);
	}
	return %detectedUp SPC %detectedCenter SPC %detectedLower SPC %detectedCenterRight SPC %detectedCenterLeft;
}