AI_COND_002
- //Check Near (1)
- // Count how many allied monsters (same team) near me with within a specified level range
- // Also returns and stores NearChar and FindChar for this monster
- AIP_COND_002
- //count how many aiobj between nLevelDiff and nLevelDiff2 who is btIsAllied within iDistance
- //must be >= wChrNum
- uint32 iDistance //Byte 0
- uint8 btIsAllied //Byte 4
- uint16 nLevelDiff //0xffff - Byte 6
- uint16 nLevelDiff2 //Byte 8
- uint16 wChrNum //Byte 10
- uint32 chrCount = 0
- uint32 eCount = 0
- uint32 checkDistance = 0
- uint32 nearestDistance = 9999999
- CMap* map = GServer->MapList.Index[entity->Position->Map];
- vector <CCharacter*> entityList = map->NearList ( entity, iDistance, entity->Position->current ) //creates a filtered list of entities less than iDistance away
- uint32 entityCount = entityList.size ( )
-
- // Scan the list of entities to find ones that meet the criteria
- for (uint16 j = 0; j < entityList.size(); j++)
- eCount++;
- if ( btIsAllied == ( other->team == entity->team ) ) //other is a member of my own team?
- if ( other->Stats->Level >= ( entity->Stats->Level - nLevelDiff ) && other->Stats->Level <= ( entity->Stats->Level + nLevelDiff2 ) )
- checkDistance = (int)Rose::Math::Distance( other->Position->current, entity->Position->current ); //
- if (checkDistance > iDistance) continue
- chrCount++ //increment the counter
- if (checkDistance < nearestDistance)
- nearestDistance = checkDistance // other is now the nearest
- entity->nearChar = other->clientid // Set the global nearChar variable to point to other
- if (chrCount >= wChrNum) // found enough allies so return success
- entity->findChar = other->clientid // Set the global findChar variable to point to other
- return AI_SUCCESS;
- return AI_FAILURE
This one is a lot more complicated
It specifically counts Allied entities (players and monsters and NPCs) within a specific distance (defined by iDistance which is found at byte 0 in the data array of the AIP file) of the currently focused monster or NPC
When it finds the nearest Allied entity is sets a value equal to the identity of this entity in the subject entity's
entity->nearChar variable. This variable will continue to hold this value to be used in later actions.
The function also sets
entity->findChar. When it reaches the specified count of allys, the very last one will be remembered in this variable until set elsewhere.
What do we mean by
Ally?
This means any other entity that is on the same team as the currently focused entity.
Examples of an Ally would include....
Another summon owned by my owner
Another summon owned by a player in the same party as my owner
All summons owned by clan members while in clan fields
All monsters defined as being on a specified team in special events.
Teams and allies are not well supported in standard osrose server files. The whole system will need to be overhauled in order to make this function properly
Finally the EntityList vector is something that is not supported by anything outside of project 137.
It is basically a class that contains built in filters so that simply creating such an entitylist will automatically populate it from the values passed in during creation.