Here's a patch which adds an $On Turret Fired hook, providing hook variables Ship, Weapon and Target. I'll later try to add a handle to the associated subsystem to weapon objects, since I can't pass that as a hook variable (due to subsystems not inheriting from object).
Index: ai/aiturret.cpp
===================================================================
--- ai/aiturret.cpp (revision 8215)
+++ ai/aiturret.cpp (working copy)
@@ -21,6 +21,7 @@
#include "ai/aiinternal.h" //Included last, so less includes are needed
#include "iff_defs/iff_defs.h"
#include "weapon/muzzleflash.h"
+#include "parse/scripting.h"
#include <limits.h>
@@ -1717,6 +1718,12 @@
objp=&Objects[weapon_objnum];
wp=&Weapons[objp->instance];
+ parent_ship->last_fired_turret = turret;
+ turret->last_fired_weapon_info_index = wp->weapon_info_index;
+
+ Script_system.SetHookObjects(3, "Ship", &Objects[parent_objnum], "Weapon", objp, "Target", &Objects[turret->turret_enemy_objnum]);
+ Script_system.RunCondition(CHA_ONTURRETFIRED, 0, NULL, &Objects[parent_objnum]);
+
//nprintf(("AI", "Turret_time_enemy_in_range = %7.3f\n", ss->turret_time_enemy_in_range));
if (weapon_objnum != -1) {
wp->target_num = turret->turret_enemy_objnum;
Index: parse/scripting.cpp
===================================================================
--- parse/scripting.cpp (revision 8215)
+++ parse/scripting.cpp (working copy)
@@ -71,7 +71,8 @@
{"On Weapon Fired", CHA_ONWPFIRED, 0},
{"On Weapon Selected", CHA_ONWPSELECTED, 0},
{"On Weapon Deselected", CHA_ONWPDESELECTED, 0},
- {"On Gameplay Start", CHA_GAMEPLAYSTART, 0}
+ {"On Gameplay Start", CHA_GAMEPLAYSTART, 0},
+ {"On Turret Fired", CHA_ONTURRETFIRED, 0}
};
int Num_script_actions = sizeof(Script_actions)/sizeof(flag_def_list);
@@ -279,7 +280,7 @@
}
case CHC_WEAPONCLASS:
{
- if (!(action == CHA_ONWPSELECTED || action == CHA_ONWPDESELECTED || action == CHA_ONWPEQUIPPED || action == CHA_ONWPFIRED)) {
+ if (!(action == CHA_ONWPSELECTED || action == CHA_ONWPDESELECTED || action == CHA_ONWPEQUIPPED || action == CHA_ONWPFIRED || action == CHA_ONTURRETFIRED )) {
if(objp == NULL || objp->type != OBJ_WEAPON)
return false;
else if(stricmp(Weapon_info[Weapons[objp->instance].weapon_info_index].name, scp->data.name) != 0)
@@ -333,7 +334,13 @@
case CHA_ONWPFIRED: {
if (! (stricmp(Weapon_info[shipp->weapons.primary_bank_weapons[shipp->weapons.current_primary_bank]].name, scp->data.name) == 0 || (stricmp(Weapon_info[shipp->weapons.secondary_bank_weapons[shipp->weapons.current_secondary_bank]].name, scp->data.name) == 0)))
return false;
+ break;
}
+ case CHA_ONTURRETFIRED: {
+ if (! (stricmp(Weapon_info[shipp->last_fired_turret->last_fired_weapon_info_index].name, scp->data.name) == 0))
+ return false;
+ break;
+ }
}
} // case CHC_WEAPONCLASS
Index: parse/scripting.h
===================================================================
--- parse/scripting.h (revision 8215)
+++ parse/scripting.h (working copy)
@@ -66,6 +66,7 @@
#define CHA_ONWPSELECTED 24
#define CHA_ONWPDESELECTED 25
#define CHA_GAMEPLAYSTART 26
+#define CHA_ONTURRETFIRED 27
// management stuff
void scripting_state_init();
Index: ship/ship.h
===================================================================
--- ship/ship.h (revision 8215)
+++ ship/ship.h (working copy)
@@ -310,6 +310,7 @@
float favor_current_facing;
ship_subsys *targeted_subsys; // subsystem this turret is attacking
bool scripting_target_override;
+ int last_fired_weapon_info_index; // which weapon class was last fired
int turret_pick_big_attack_point_timestamp; // Next time to pick an attack point for this turret
vec3d turret_big_attack_point; // local coordinate of point for this turret to attack on enemy
@@ -708,6 +709,7 @@
bool shader_effect_active;
int last_fired_point[MAX_SHIP_PRIMARY_BANKS]; //for fire point cylceing
+ ship_subsys *last_fired_turret; // which turret has fired last
// fighter bay door stuff, parent side
int bay_doors_anim_done_time; // ammount of time to transition from one animation state to another
The ship.h additions were necessary (the other similar workarounds would have been even messier, IMO).
I'm not entirely comfortable committing stuff like this without a chance for someone to review it first, so I'll let this sit here for a day or two first, just in case someone finds something wrong with it.