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

Function AIDoMemFrame

Descent3/AImain.cpp:6047–6106  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6045}
6046
6047void AIDoMemFrame(object *obj) {
6048 ai_frame *ai_info = obj->ai_info;
6049 ai_info->mem_time_till_next_update -= Frametime;
6050
6051 if (ai_info->mem_time_till_next_update <= 0.0f) {
6052 int i;
6053
6054 // Compute next analyze time
6055 ai_info->mem_time_till_next_update = 3.0f + (float)ps_rand() / (float)D3_RAND_MAX * 2.0f;
6056
6057 // Do the amount of friends/enemies left and the current shields before running Freud
6058 int16_t near_objs[100];
6059 float dist = 100.0f;
6060
6061 // chrishack -- there must be a better way...
6062 if (ai_info->coop_team * 300.0f > dist) {
6063 dist = ai_info->coop_team * 300.0f > dist;
6064 }
6065
6066 int num_near = fvi_QuickDistObjectList(&obj->pos, obj->roomnum, dist, near_objs, 100, false, true, false, true);
6067
6068 ai_info->memory[0].num_enemies = 0;
6069 ai_info->memory[0].num_friends = 0;
6070
6071 for (i = 0; i < num_near; i++) {
6072 object *check_obj = &Objects[near_objs[i]];
6073
6074 if (check_obj == obj)
6075 continue;
6076
6077 if (AIObjEnemy(obj, check_obj))
6078 ai_info->memory[0].num_enemies++;
6079 else if (AIObjFriend(obj, check_obj))
6080 ai_info->memory[0].num_friends++;
6081 }
6082
6083 ai_info->memory[0].shields = obj->shields;
6084
6085 // Do emotions based on new data
6086 AIDoFreud(obj);
6087
6088 // Move emotions through the stack
6089 for (i = AI_MEM_DEPTH - 1; i > 0; i--) {
6090 ai_info->memory[i] = ai_info->memory[i - 1];
6091 }
6092
6093 // Reset the accumulators
6094
6095 // These are imcremented as this memory time slice is active
6096 ai_info->memory[0].num_enemy_shots_dodged = 0;
6097 ai_info->memory[0].num_enemy_shots_fired = 0;
6098 ai_info->memory[0].num_hit_enemy = 0;
6099 ai_info->memory[0].num_times_hit = 0;
6100
6101 // Dummy values, as these are computed at the end of the time frame (as seen above)
6102 ai_info->memory[0].shields = obj->shields;
6103 ai_info->memory[0].num_enemies = ai_info->memory[1].num_enemies;
6104 ai_info->memory[0].num_friends = ai_info->memory[1].num_friends;

Callers 1

AIDoFrameFunction · 0.85

Calls 5

ps_randFunction · 0.85
fvi_QuickDistObjectListFunction · 0.85
AIObjEnemyFunction · 0.85
AIObjFriendFunction · 0.85
AIDoFreudFunction · 0.85

Tested by

no test coverage detected