Example #1
0
bool CBuilderCAI::MoveInBuildRange(const float3& pos, float radius, const bool checkMoveTypeForFailed)
{
	if (!IsInBuildRange(pos, radius)) {
		if (
			checkMoveTypeForFailed &&
			owner->moveType->progressState == AMoveType::Failed &&
			f3SqDist(goalPos, pos) > 1.0f // check if the AMoveType::Failed belongs to the same goal position
		) {
			// don't call SetGoal() it would reset moveType->progressState and so later code couldn't check if the movecmd failed
			return false;
		}

		// too far away, start a move command
		SetGoal(pos, owner->pos, GetBuildRange(radius) * 0.9f);
		return false;
	}

	if (owner->unitDef->IsAirUnit()) {
		StopMoveAndKeepPointing(pos, radius);
	} else {
		StopMoveAndKeepPointing(goalPos, goalRadius);
	}

	return true;
}
Example #2
0
bool CBuilderCAI::MoveInBuildRange(const float3& objPos, float objRadius, const bool checkMoveTypeForFailed)
{
	if (!IsInBuildRange(objPos, objRadius)) {
		// NOTE:
		//   ignore the fail-check if we are an aircraft, movetype code
		//   is unreliable wrt. setting it correctly and causes (landed)
		//   aircraft to discard orders
		const bool checkFailed = (checkMoveTypeForFailed && !owner->unitDef->IsAirUnit());
		// check if the AMoveType::Failed belongs to the same goal position
		const bool haveFailed = (owner->moveType->progressState == AMoveType::Failed && f3SqDist(goalPos, objPos) > 1.0f);

		if (checkFailed && haveFailed) {
			// don't call SetGoal() it would reset moveType->progressState
			// and so later code couldn't check if the move command failed
			return false;
		}

		// too far away, start a move command
		SetGoal(objPos, owner->pos, GetBuildRange(objRadius) * 0.9f);
		return false;
	}

	if (owner->unitDef->IsAirUnit()) {
		StopMoveAndKeepPointing(objPos, objRadius, false);
	} else {
		StopMoveAndKeepPointing(goalPos, goalRadius, false);
	}

	return true;
}