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

Function AIDetermineTarget

Descent3/AImain.cpp:5912–5987  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5910}
5911
5912void AIDetermineTarget(object *obj) {
5913 ai_frame *ai_info = obj->ai_info;
5914 object *best_obj = NULL;
5915 float best_dot = -1.0f;
5916 float best_dist = MAX_SEE_TARGET_DIST + 1;
5917 int i;
5918
5919 if (Gametime < ai_info->next_target_update_time)
5920 return;
5921
5922 if (ai_info->awareness >= AWARE_BARELY)
5923 ai_info->next_target_update_time =
5924 Gametime + MIN_TARGET_UPDATE_INTERVAL +
5925 ((float)ps_rand() / (float)D3_RAND_MAX) * (MAX_TARGET_UPDATE_INTERVAL - MIN_TARGET_UPDATE_INTERVAL);
5926 else
5927 ai_info->next_target_update_time =
5928 Gametime + 2.0f * MIN_TARGET_UPDATE_INTERVAL +
5929 ((float)ps_rand() / (float)D3_RAND_MAX) * 2.0f * (MAX_TARGET_UPDATE_INTERVAL - MIN_TARGET_UPDATE_INTERVAL);
5930
5931 // Chrishack -- if agression is over a value, NO switching targets!!!!!!!!! Need to implement
5932 // Chrishack -- if frustration is over a value, act as hostile -- temp stuff AIF_TEAM_HOSTILE
5933
5934 // They forget their enemies after a few seconds
5935 if ((ai_info->flags & AIF_TEAM_MASK) == AIF_TEAM_NEUTRAL || (ai_info->flags & AIF_ACT_AS_NEUTRAL_UNTIL_SHOT)) {
5936 best_obj = NULL;
5937 } else if ((ai_info->flags & AIF_TEAM_MASK) != AIF_TEAM_PTMC) {
5938 int16_t list[50];
5939 int num = fvi_QuickDistObjectList(&obj->pos, obj->roomnum, MAX_SEE_TARGET_DIST, list, 50, false, true, false, true);
5940
5941 for (i = 0; i < num; i++) {
5942 AITargetCheck(obj, &Objects[list[i]], &best_obj, &best_dot, &best_dist);
5943 }
5944 } else // Team PTMC :)
5945 {
5946 if (Game_mode & GM_MULTI) {
5947 // Multiplayer targetting (Major difference is that robot will ignore players while infighting in single player)
5948 for (i = 0; i < MAX_PLAYERS; i++) {
5949 if ((NetPlayers[i].flags & NPF_CONNECTED) && (NetPlayers[i].sequence >= NETSEQ_PLAYING)) {
5950 object *target = &Objects[Players[i].objnum];
5951
5952 AITargetCheck(obj, target, &best_obj, &best_dot, &best_dist);
5953 }
5954 }
5955 } else {
5956 object *t = ObjGet(ai_info->target_handle);
5957 bool f_forgive_friend = false;
5958
5959 if ((t) && (t->control_type == CT_AI) && ((t->ai_info->flags & AIF_TEAM_MASK) == AIF_TEAM_PTMC)) {
5960 // Do the divide because we don't want D3_RAND_MAX to go too high
5961 if (ps_rand() / AI_FORGIVE_AGRESSION_MULTIPLIER > ai_info->agression * D3_RAND_MAX) {
5962 f_forgive_friend = true;
5963 }
5964 }
5965
5966 // chrishack -- FUCK a multi-guidebot bug!!!!!!
5967 if (f_forgive_friend || !ai_target_valid(obj) ||
5968 (ai_info->target_handle != OBJECT_HANDLE_NONE && ai_info->target_handle == Buddy_handle[0] &&
5969 ObjGet(Buddy_handle[0])->type != OBJ_GHOST)) {

Callers 1

AIDoFrameFunction · 0.85

Calls 6

ps_randFunction · 0.85
fvi_QuickDistObjectListFunction · 0.85
AITargetCheckFunction · 0.85
ObjGetFunction · 0.85
ai_target_validFunction · 0.85
AISetTargetFunction · 0.85

Tested by

no test coverage detected