I was just thinking about these features and how they might be accomplished. They are both weapon flags that would allow certain functionality to be controlled independently (right now its not). The first is adding a "large" flag to weapons so that a weapon can damage large ships but the AI can still use it against small ships (think Trebuchet). This would be pretty easy, I think (

), and would be accomplished something like this
weapon.h
#define WIF_HURTS_BIG_SHIPS (WIF_BOMB | WIF_BEAM | WIF_HUGE | WIF_BIG_ONLY | WIF_LARGE)
The second, a "targetable" flag does something similar for targetability. Would be useful for stuff like BtRL. This is much trickier. Allowing the player to target missiles is easy, but getting the AI to do it correctly is altogether more difficult. There is also the question of whether you want turrets to target this weapon. To get it to be targetable:
hudtarget.cpp
void hud_target_common()
...
if (A->type == OBJ_WEAPON) {
if ( !(Weapon_info[Weapons[A->instance].weapon_info_index].wi_flags & (WIF_BOMB | WIF_TARGETABLE) ) )
continue;
void hud_target_missile()
...
if ( !(wip->wi_flags & (WIF_BOMB | WIF_TARGETABLE) ) ) {
continue;
}
void hud_target_in_reticle_new()
...
if ( A->type == OBJ_WEAPON ) {
if ( !(Weapon_info[Weapons[A->instance].weapon_info_index].wi_flags & (WIF_BOMB | WIF_TARGETABLE) ) ){
continue;
void hud_target_in_reticle_old()
...
if ( A->type == OBJ_WEAPON ) {
if ( !(Weapon_info[Weapons[A->instance].weapon_info_index].wi_flags & (WIF_BOMB | WIF_TARGETABLE) ) ){
continue;
void hud_show_lead_indicator()
...
if ( targetp->type == OBJ_WEAPON ) {
if ( !(Weapon_info[Weapons[targetp->instance].weapon_info_index].wi_flags & (WIF_BOMB | WIF_TARGETABLE) ) ) {
return;
void hud_show_lead_indicator_quick()
...
if ( targetp->type == OBJ_WEAPON ) {
if ( !(Weapon_info[Weapons[targetp->instance].weapon_info_index].wi_flags & (WIF_BOMB | WIF_TARGETABLE) ) ) {
return;
also radar.cpp
case OBJ_WEAPON:
{
// if not a bomb, return
if ( !(Weapon_info[Weapons[objp->instance].weapon_info_index].wi_flags & (WIF_BOMB | WIF_TARGETABLE) ) )
return;
and to make it actually destroy:
weapon.cpp [code]
if (wip->wi_flags & WIF_BOMB){
objp->hull_strength = 50.0f;
else if (wip->wi_flags & WIF_TARGETABLE){
objp->hull_strength = 20.0f;
} else {
objp->hull_strength = 0.0f;
}
I figure non bombs should be more easily destroyable.
On a side note, hopefully that custom HP for bombs mod will be committed soon.
and collideweaponweapon.cpp
int collide_weapon_weapon()
...
if (wipA->wi_flags & (WIF_BOMB | WIF_TARGETABLE) ) {
A_radius *= 2; // Makes bombs easier to hit
if (wipA->wi_flags & WIF_BOMB)
if (wipA->lifetime - wpA->lifeleft < BOMB_ARM_TIME)
return 0;
}
if (wipB->wi_flags & (WIF_BOMB | WIF_TARGETABLE) ) {
B_radius *= 2; // Makes bombs easier to hit
if (wipA->wi_flags & WIF_BOMB)
if (wipB->lifetime - wpB->lifeleft < BOMB_ARM_TIME)
return 0;
}
...
if (wipA->wi_flags & (WIF_BOMB | WIF_TARGETABLE) ) {
if (wipB->wi_flags & (WIF_BOMB | WIF_TARGETABLE) ) { // Two bombs collide, detonate both.
Weapons[A->instance].lifeleft = 0.01f;
Weapons[B->instance].lifeleft = 0.01f;
Weapons[A->instance].weapon_flags |= WF_DESTROYED_BY_WEAPON;
Weapons[B->instance].weapon_flags |= WF_DESTROYED_BY_WEAPON;
} else {
A->hull_strength -= wipB->damage;
if (A->hull_strength < 0.0f) {
Weapons[A->instance].lifeleft = 0.01f;
Weapons[A->instance].weapon_flags |= WF_DESTROYED_BY_WEAPON;
}
}
} else if (wipB->wi_flags & (WIF_BOMB | WIF_TARGETABLE) ) {
B->hull_strength -= wipA->damage;
if (B->hull_strength < 0.0f) {
Weapons[B->instance].lifeleft = 0.01f;
Weapons[B->instance].weapon_flags |= WF_DESTROYED_BY_WEAPON;
}
}
I figured that the last 1.5 seconds for non-bomb weapons should matter (it doesn't for bombs).
Now, the AI is more difficult. You probably want it to destroy missiles that are targeting itself, but I doubt that this would work correctly until the AI can use glide effectively. What you can do is make it target missiles firing at something it is supposed to protect:
aicode.cpp
int ai_guard_find_nearby_bomb()
...
if ( !(wip->wi_flags & (WIF_BOMB | WIF_TARGETABLE) ) ) {
continue;
}
It would be difficult to get turrets to hit non-bombs correctly, as you would probably want it to calculate its probability of hitting a missile before actually targeting it (small, fast missiles = not worth targeting).
I'm sure I forgot something here, but at least its a starting point. Also, the flags would have to be added to the parse code etc, but that is pretty easy.[/code]