Пример #1
0
void TankAI::brainTick(float seconds) {

	//listen closely and watch out for enemies.
	sense();

	//take a decision
	if (_currentTarget == NULL && _strategy != EXPLORE) {
		switchStrategy(EXPLORE, NULL);
	} else if (_currentTarget != NULL && _strategy != HUNT) {
		switchStrategy(HUNT, _currentTarget);
		delete _path;
		_path = NULL;
	}

	//do what you decided to do
	switch (_strategy) {
	case HUNT: {
		hunt();
		break;
	}
	case EXPLORE: {
		explore();
		break;
	}
	case ESCAPE: {
		escape();
		break;
	}
	}

}
Пример #2
0
void TankAI::sense() {

	//listen
	for (std::vector<Message*>::iterator messageIterator = _aiMessages->_messageSubBus.begin(); messageIterator != _aiMessages->_messageSubBus.end(); messageIterator++) {
		Message* message = *messageIterator;
		switch (message->_messageType) {
		case Message::ATTACKED_BY: {
			AttackedByMessage* abMessage = static_cast<AttackedByMessage*>(message);
			std::cout << "Tank " << " is attacked by Target " << abMessage->_attackingEnemy;
			switchStrategy(ESCAPE, abMessage->_attackingEnemy);
			break;
		}
		case Message::DETONATION_SOUND: {
			DetonationSoundMessage* dsMessage = static_cast<DetonationSoundMessage*>(message);
			if (Utils::distance(_tank->getPosition(), dsMessage->_detonationPoint) < dsMessage->_detonationStrength) {

				std::cout << "Tank " << " heard some detonation at point " << dsMessage->_detonationPoint.x << "," << dsMessage->_detonationPoint.z;

				//if the tank heard a detonation it goes and checks out who's there
				if (_path != NULL) {
					delete _path;
					_path = NULL;
				}
				_path = _scene.getTerrain().findPath(_tank->getPosition(), dsMessage->_detonationPoint);
			}
			break;
		}
		}
	}

	//see
	if (_currentTarget == NULL) {
		std::vector<Target*> targets = _scene.getTargets();
		for (std::vector<Target*>::iterator targetsIter = targets.begin(); targetsIter != targets.end(); targetsIter++) {
			Target* target = *targetsIter;

			//if the target near you is not yourself and it is near enough that you can see it
			if (target != _tank && Utils::distance(_tank->getPosition(), target->getPosition()) < SMALLTANK_VISION_DISTANCE) {
				_currentTarget = target;
				break;
			}
		}
	} else {
		//if the target gets out of sight, we lose it
		if (Utils::distance(_tank->getPosition(), _currentTarget->getPosition()) > SMALLTANK_VISION_DISTANCE) {
			_currentTarget = NULL;
		}
	}

	// the enemy tank does not have enough life left, he tries to escape to regain shield
	if(_tank->_life/SMALLTANK_LIFE < 1/4 && _tank->_shield/SMALLTANK_SHIELD < 1/4 )
	{
		switchStrategy(ESCAPE, _currentTarget);
	}
}
DistanceValue* TextSimilarityServiceImpl::calculateDistance(WordValue &word1, WordValue &word2)
{
	if (!switchStrategy()) return NULL;
	return this->strategy->calculateDistance(word1, word2);
}