Ok, I made the correct changes by adding a new float array into the ai_profiles structure and then put the code to load that variable from the ai_profiles table into memory. As well as implemented the threshold by referencing this variable in the missile-lock code. Note: Variable defaults to zero (ie. pixels must match identically (the original version))
//Hudlock.h
//append this code to the file just before the "#endif"
//08/20/07 - TheTempest -
bool hud_lock_is_within_threshold();
//helper fucntions
float distance_f(float x1, float y1, float x2, float y2);
//Hudlock.cpp
#include "freespace2/freespace.h"
//find this line:
if (Players[Player_num].lock_indicator_x == Player->current_target_sx) && (Players[Player_num].lock_indicator_y == Player->current_target_sy) {
//and replace it with this
if ( hud_lock_is_within_threshold()) {
//append this code to the end of the file
//==================================
//08/20/07 - TheTempest - is if the distance between the target and the lock indictor is within the given threshold, then return true. Return false otherwise.
bool hud_lock_is_within_threshold()
{
float dist;
dist = distance_f(Players[Player_num].lock_indicator_x, Players[Player_num].lock_indicator_y, Player->current_target_sx, Player->current_target_sy);
//08/23/07 - TheTempest - Use the new ap_profile option and check the distance between the coordinates
if(dist < The_mission.ai_profile->missile_lock_threshold_in_pixels[Game_skill_level])
return true;
else
return false;
}
//08/20/07 - TheTempest - simple distance formula
float distance_f(float x1, float y1, float x2, float y2)
{
float dist;
dist = sqrt(pow((x2 - x1), 2.0f) + pow((y2 - y1),2.0f));
return dist;
}
//==================================
//ai_profiles.cpp
//find this line:
parse_float_list(profile->shield_manage_delay, NUM_SKILL_LEVELS);
//and add this just after that line
//08/23/07 - TheTempest - Add - Read pixel width threshold setup for missle lock from the ai_profile table
if (optional_string("$Missile Lock Threshold In Pixels:"))
parse_float_list(profile->missile_lock_threshold_in_pixels, NUM_SKILL_LEVELS);
//ai_profiles.h
//find this line
float shield_manage_delay[NUM_SKILL_LEVELS]; // how long before AI manages shields (note that the player's team always uses the average skill's
//and add this after it
float missile_lock_threshold_in_pixels[NUM_SKILL_LEVELS]; // max distance between target indicator and target position that the computer can still lock on (in pixels) - 08/23/07 - TheTempest