Instead of using my usual approach (also known as "commit first, ask for forgiveness later"), I decided to post this here for some feedback.
Okay, as you may or may not know, while turrets do have an AI setting, it's basically unused. This patch changes that by introducing a new AI_profiles.tbl flag.
Now, I'm not really sure if ai_profiles is really the right place for it. It would make just as much sense as a missions flag, to be honest. What are your opinions on the subject?
Here's the code: Index: code/ai/ai_profiles.cpp
===================================================================
--- code/ai/ai_profiles.cpp (revision 6314)
+++ code/ai/ai_profiles.cpp (working copy)
@@ -395,6 +395,8 @@
set_flag(profile, "$big ships manage shields:", AIPF2_BIG_SHIELD_MANAGE, AIP_FLAG2);
+ set_flag(profile, "$turrets use separate ai class:", AIPF2_TURRETS_USE_SEPARATE_AI, AIP_FLAG2);
+
// if we've been through once already and are at the same place, force a move
if ( saved_Mp && (saved_Mp == Mp) )
Mp++;
Index: code/ai/ai_profiles.h
===================================================================
--- code/ai/ai_profiles.h (revision 6314)
+++ code/ai/ai_profiles.h (working copy)
@@ -55,6 +55,7 @@
#define AIPF2_NO_SPECIAL_PLAYER_AVOID (1 << 1)
#define AIPF2_PERFORM_LESS_SCREAM_CHECKS (1 << 2)
#define AIPF2_BIG_SHIELD_MANAGE (1 << 3)
+#define AIPF2_TURRETS_USE_SEPARATE_AI (1 << 4)
#define MAX_AI_PROFILES 5
Index: code/ai/aiturret.cpp
===================================================================
--- code/ai/aiturret.cpp (revision 6314)
+++ code/ai/aiturret.cpp (working copy)
@@ -1414,6 +1414,7 @@
matrix turret_orient;
int weapon_objnum;
ai_info *parent_aip;
+ ai_info *turret_aip;
ship *parent_ship;
float flak_range = 0.0f;
weapon_info *wip;
@@ -1438,6 +1439,15 @@
return false;
parent_aip = &Ai_info[Ships[Objects[parent_objnum].instance].ai_index];
+ turret_aip = parent_aip;
+
+ if (The_mission.ai_profile->flags2 & AIPF2_TURRETS_USE_SEPARATE_AI) {
+ init_aip_from_class_and_profile(turret_aip, &Ai_classes[turret->weapons.ai_class], The_mission.ai_profile);
+ //Assertion((turret_aip != NULL), "No AI class set for turret %s", turret->system_info->name);
+ //if (turret_aip == NULL)
+ // turret_aip = parent_aip;
+ }
+
parent_ship = &Ships[Objects[parent_objnum].instance];
wip = get_turret_weapon_wip(&turret->weapons, weapon_num);
int turret_weapon_class = WEAPON_INFO_INDEX(wip);
@@ -1447,8 +1457,10 @@
turret->turret_last_fire_direction = *turret_fvec;
// set next fire timestamp for the turret
- if (last_shot_in_salvo)
+ if (last_shot_in_salvo && !(The_mission.ai_profile->flags2 & AIPF2_TURRETS_USE_SEPARATE_AI))
turret_set_next_fire_timestamp(weapon_num, wip, turret, parent_aip);
+ else
+ turret_set_next_fire_timestamp(weapon_num, wip, turret, turret_aip);
// if this weapon is a beam weapon, handle it specially
if (wip->wi_flags & WIF_BEAM) {
NOTE: No matter what the outcome of this is, this won't be in 3.6.12