예제 #1
0
bool ClawUnitActor::setPathTo(Unit *unit, const VC3 &destination_)
{
	VC3 destination = destination_;
	frozenbyte::ai::Path *path = solvePath(unit, unit->getPosition(), destination);
	
	// luckily, getPath may modify the destination value, if it is blocked
	// so no need to check that here.

	if (path != NULL)
	{
		unit->setPath(path);
		unit->setPathIndex(unit->getPathIndex() + 1);
		// (...path object is now contained within the unit, 
		// unit will handle it's proper deletion)
		unit->setWaypoint(unit->getPosition());
		unit->setFinalDestination(VC3(destination.x, 
			game->gameMap->getScaledHeightAt(destination.x, destination.z), 
			destination.z));
		return true;
	} else {		
		unit->setPath(NULL);
		unit->setFinalDestination(unit->getPosition());
		unit->setWaypoint(unit->getPosition());
		return false;
	} 
}
예제 #2
0
bool SimpleSolve::doSolve(Solver& s, const SolveParams& p) {
	s.stats.reset();
	Enumerator*  enumerator = s.sharedContext()->enumerator();
	bool hasWork    = true, complete = true;
	InitParams  init= p.init;
	SolveLimits lim = getSolveLimits();
	Timer<RealTime> tt; tt.start();
	s.sharedContext()->reportProgress(SolveStateEvent(s, "algorithm"));
	// Remove any existing assumptions and restore solver to a usable state.
	// If this fails, the problem is unsat, even under no assumptions.
	while (s.clearAssumptions() && hasWork) {
		// Add assumptions - if this fails, the problem is unsat 
		// under the current assumptions but not necessarily unsat.
		if (initPath(s, getInitialPath(), init)) {
			complete = (solvePath(s, p, lim) != value_free && s.decisionLevel() == s.rootLevel());
		}
		// finished current work item
		hasWork    = complete && enumerator->optimizeNext();
	}
	setSolveLimits(lim);
	tt.stop();
	s.sharedContext()->reportProgress(SolveStateEvent(s, "algorithm", tt.total()));
	return !complete;
}