Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix the rest of the autoscaled attributes #4929

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions code/ai/ai.h
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,7 @@ typedef struct ai_info {
ai_lua_parameters lua_ai_target;
} ai_info;

int ai_maybe_autoscale(int absolute_index = -1);
int ai_get_autoscale_index(int absolute_index = -1);

// Goober5000
Expand Down
47 changes: 34 additions & 13 deletions code/ai/aicode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,14 @@ int ai_get_autoscale_index(int absolute_index)
return index;
}

int ai_maybe_autoscale(int absolute_index)
{
if (The_mission.ai_profile->flags[AI::Profile_Flags::Adjusted_AI_class_autoscale])
return ai_get_autoscale_index(absolute_index);
else
return absolute_index;
}

/**
* Initialize an AI class's nonrequired values to defaults
* Boolean overrides are unset, others initialized to FLT_MIN or INT_MIN (used as the "not set" state)
Expand Down Expand Up @@ -4989,8 +4997,8 @@ int ai_maybe_fire_afterburner(object *objp, ai_info *aip)
if (!(Ship_info[Ships[objp->instance].ship_info_index].flags[Ship::Info_Flags::Afterburner])) {
return 0;
}
if (aip->ai_aburn_use_factor == INT_MIN && aip->ai_class == 0) {
return 0; // Lowest level never aburners away (unless ai_aburn_use_factor is specified)
if (aip->ai_aburn_use_factor == INT_MIN && ai_maybe_autoscale(aip->ai_class) == 0) {
return 0; // Lowest [autoscaled] level never aburners away (unless ai_aburn_use_factor is specified)
}
else {
// Maybe don't afterburner because of a potential collision with the player.
Expand All @@ -5015,15 +5023,28 @@ int ai_maybe_fire_afterburner(object *objp, ai_info *aip)
}
}

if (aip->ai_aburn_use_factor == INT_MIN && aip->ai_class >= Num_ai_classes-2)
return 1; // Highest two levels always aburner away (unless ai_aburn_use_factor is specified).
else {
//If ai_aburn_use_factor is not specified, calculate a number based on the AI class. Otherwise, use that value.
if (aip->ai_aburn_use_factor == INT_MIN)
return static_rand_timed(OBJ_INDEX(objp), Num_ai_classes - aip->ai_class);
//If ai_aburn_use_factor is not specified, calculate a number based on the AI class. Otherwise, use that value.
if (aip->ai_aburn_use_factor == INT_MIN)
{
if (The_mission.ai_profile->flags[AI::Profile_Flags::Adjusted_AI_class_autoscale])
{
// Highest two levels always aburner away
if (ai_get_autoscale_index(aip->ai_class) >= ai_get_autoscale_index(Num_ai_classes) - 2)
return 1;

return static_rand_timed(OBJ_INDEX(objp), ai_get_autoscale_index(Num_ai_classes) - ai_get_autoscale_index(aip->ai_class));
}
else
return static_rand_timed(OBJ_INDEX(objp), aip->ai_aburn_use_factor);
{
// Highest two levels always aburner away
if (aip->ai_class >= Num_ai_classes-2)
return 1;

return static_rand_timed(OBJ_INDEX(objp), Num_ai_classes - aip->ai_class);
}
}
else
return static_rand_timed(OBJ_INDEX(objp), aip->ai_aburn_use_factor);
}
}

Expand Down Expand Up @@ -8906,7 +8927,7 @@ void ai_chase()
aip->submode_start_time = Missiontime;
} else if ( enemy_sip != NULL && (enemy_sip->is_small_ship()) && (dist_to_enemy < 150.0f) && (dot_from_enemy > dot_to_enemy + 0.5f + aip->ai_courage*.002)) {
float get_away_chance = (aip->ai_get_away_chance == FLT_MIN)
? (float)(aip->ai_class + Game_skill_level)/(Num_ai_classes + NUM_SKILL_LEVELS)
? (float)(ai_maybe_autoscale(aip->ai_class) + Game_skill_level)/(ai_maybe_autoscale(Num_ai_classes) + NUM_SKILL_LEVELS)
: aip->ai_get_away_chance;
if ((Missiontime - aip->last_hit_target_time > i2f(5)) && (frand() < get_away_chance)) {
aip->submode = SM_GET_AWAY;
Expand Down Expand Up @@ -9001,7 +9022,7 @@ void ai_chase()
aip->ai_flags.remove(AI::AI_Flags::Attack_slowly); // Just in case, clear here.

float get_away_chance = (aip->ai_get_away_chance == FLT_MIN)
? (float)(aip->ai_class + Game_skill_level)/(Num_ai_classes + NUM_SKILL_LEVELS)
? (float)(ai_maybe_autoscale(aip->ai_class) + Game_skill_level)/(ai_maybe_autoscale(Num_ai_classes) + NUM_SKILL_LEVELS)
: aip->ai_get_away_chance;

switch (Random::next(5)) {
Expand Down Expand Up @@ -9246,7 +9267,7 @@ void ai_chase()
else
{
float secondary_range_mult = (aip->ai_secondary_range_mult == FLT_MIN)
? (float)(Game_skill_level + 1 + (3 * aip->ai_class/(Num_ai_classes - 1)))/NUM_SKILL_LEVELS
? (float)(Game_skill_level + 1 + (3 * ai_maybe_autoscale(aip->ai_class)/(ai_maybe_autoscale(Num_ai_classes) - 1)))/NUM_SKILL_LEVELS
: aip->ai_secondary_range_mult;

firing_range = MIN((swip->max_speed * swip->lifetime * secondary_range_mult), swip->weapon_range);
Expand Down Expand Up @@ -14313,7 +14334,7 @@ int ai_avoid_shockwave(object *objp, ai_info *aip)
// Don't all react right away.
if (!(aip->ai_flags[AI::AI_Flags::Avoid_shockwave_started])) {
float evadeChance = (aip->ai_shockwave_evade_chance == FLT_MIN)
? ((float) aip->ai_class/4.0f + 0.25f)
? ((float) ai_maybe_autoscale(aip->ai_class)/4.0f + 0.25f)
: aip->ai_shockwave_evade_chance;
if (!rand_chance(flFrametime, evadeChance)) // Chance to avoid in 1 second is 0.25 + ai_class/4
return 0;
Expand Down