MCPcopy Create free account
hub / github.com/DescentDevelopers/Descent3 / AIObjFriend

Function AIObjFriend

Descent3/AImain.cpp:5690–5757  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5688}
5689
5690bool AIObjFriend(object *obj, object *target) {
5691 bool f_friend = false;
5692
5693 // If an object isn't an AI object, it isn't a friend
5694 if (!obj || !target || (target->type != OBJ_PLAYER && !target->ai_info) || (obj->type != OBJ_PLAYER && !obj->ai_info))
5695 return false;
5696
5697 if (obj->type == OBJ_GHOST || obj->type == OBJ_POWERUP || (obj->flags & OF_DESTROYED))
5698 return false;
5699
5700 if ((target->control_type == CT_AI) && (target->movement_type == MT_NONE) &&
5701 Poly_models[target->rtype.pobj_info.model_num].num_wbs == 0) {
5702 return false;
5703 }
5704
5705 if (obj->type == OBJ_PLAYER && (Players[obj->id].flags & PLAYER_FLAGS_DEAD))
5706 return false;
5707
5708 int team = AIGetTeam(obj);
5709 int t_team = AIGetTeam(target);
5710
5711 // If this object is targetting you - it is your enemy
5712 if ((target->control_type == CT_AI) && (target->ai_info->target_handle == obj->handle)) {
5713 return false;
5714 }
5715
5716 // If its neutral and not targetting you -- its not an enemy (unless your hostile)
5717 if (team == AIF_TEAM_HOSTILE)
5718 return false;
5719
5720 // Related objects shouldn't kill each other
5721 if (ObjectsAreRelated(OBJNUM(obj), OBJNUM(target))) {
5722 return true;
5723 }
5724
5725 if (obj->parent_handle == target->handle || target->parent_handle == obj->handle) {
5726 return true;
5727 }
5728
5729 switch (team) {
5730 case AIF_TEAM_PTMC:
5731 if (t_team == AIF_TEAM_PTMC) {
5732 f_friend = true;
5733 }
5734 break;
5735
5736 case AIF_TEAM_HOSTILE:
5737 f_friend = false;
5738 break;
5739
5740 case AIF_TEAM_NEUTRAL:
5741
5742 if (t_team == AIF_TEAM_NEUTRAL) {
5743 f_friend = true;
5744 }
5745 break;
5746
5747 // A player team

Callers 4

osipf_AIIsObjFriendFunction · 0.85
AIDoTrackFrameFunction · 0.85
ai_moveFunction · 0.85
AIDoMemFrameFunction · 0.85

Calls 2

AIGetTeamFunction · 0.85
ObjectsAreRelatedFunction · 0.85

Tested by

no test coverage detected