Peonso
Godly Member
- Joined
- Jan 14, 2008
- Messages
- 1,787
- Solutions
- 30
- Reaction score
- 1,592
I need help with C++, I want to create a new change target behavior. It should always pick the nearby target, if there are more then one at the same range, it picks randomly. I want it to be able to pick the creature that is already target.
Something like this:
Something like this:
Code:
case TARGETSEARCH_RANGEDMONSTER: {
std::list<Creature*> resultMinList;
int32_t minRange = std::numeric_limits<int32_t>::max();
//picks the minimum range
for (Creature* creature : targetList) {
const Position& pos = creature->getPosition();
int32_t distance = Position::getDistanceX(myPos, pos) + Position::getDistanceY(myPos, pos);
if (distance < minRange) {
minRange = distance
}
//add all creatures in the minimum range to the list
for (Creature* creature : targetList) {
const Position& pos = creature->getPosition();
int32_t distance = Position::getDistanceX(myPos, pos) + Position::getDistanceY(myPos, pos);
if (distance = minRange) {
resultMinList.push_back(creature);
}
//sets a random creature from the list as target
if (!resultList.empty()) {
auto it = resultMinList.begin();
std::advance(it, uniform_random(0, resultMinList.size() - 1));
return selectTarget(*it);
}
}