Hard Light Productions Forums
Modding, Mission Design, and Coding => FS2 Open Coding - The Source Code Project (SCP) => Topic started by: blowfish on April 26, 2008, 10:29:55 pm
-
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 (:nervous:), 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]
-
I like this! A good idea AND code to back it up! :D
For the first, wow, that's probably the simplest and most elegant solution to all the confusion I've ever seen. Somehow "huge" got coopted for this purpose a long time ago and thus the AI doesn't fire Trebuchets at bombers. Somebody at :v: must not have thought that through. This neatly sidesteps all that (granted, it's a new flag so retail won't use it, but what can ya do).
For the second, you're right that AI probably won't be too good at shooting down incoming missiles with just guns. However, this combined with Wanderer's fix for small ships' turrets so that they protect the ship, not just shoot the current target, will become very cool (granted, in mods that end up supporting it). I'm pretty sure I could then also easily make a 'target closest incoming missile' control, once the new pilot file code is ready to accept new controls that is. After all, there's already a function for that which the turret ai uses.
Looking forward to seeing what the others think about these.
-
Excellent, blowfish! :yes:
:nod:
-
Hmm.. it seems almost trivial to add hitpoints for weapons.. Which probably means i have overlooked something :nervous:
From this
///// weapon.cpp //////
// to weapon init section
wip->weapon_init_hitpoints = 0.0f;
// to weapon parse section
if( optional_string("$Weapon Hitpoints:")){
stuff_float(&wip->weapon_init_hitpoints);
}
// to weapon_create section
if (wip->wi_flags & WIF_BOMB)
{
if (wip->weapon_init_hitpoints > 0.0f)
objp->hull_strength = wip->weapon_init_hitpoints;
else
objp->hull_strength = 50.0f;
} else {
objp->hull_strength = 0.0f;
}
///// weapon.h //////
// to weapon_info structure
float weapon_init_hitpoints;
-
Hmm.. it seems almost trivial to add hitpoints for weapons.. Which probably means i have overlooked something :nervous:
We were discussing this on this (http://www.hard-light.net/forums/index.php/topic,52350.0.html) thread. It seemed so easy that I was surprised it hadn't been done before.
-
Heh.. missed that.. Well it looks almost the same
-
I like this! A good idea AND code to back it up! :D
For the first, wow, that's probably the simplest and most elegant solution to all the confusion I've ever seen. Somehow "huge" got coopted for this purpose a long time ago and thus the AI doesn't fire Trebuchets at bombers. Somebody at :v: must not have thought that through. This neatly sidesteps all that (granted, it's a new flag so retail won't use it, but what can ya do).
For the second, you're right that AI probably won't be too good at shooting down incoming missiles with just guns. However, this combined with Wanderer's fix for small ships' turrets so that they protect the ship, not just shoot the current target, will become very cool (granted, in mods that end up supporting it). I'm pretty sure I could then also easily make a 'target closest incoming missile' control, once the new pilot file code is ready to accept new controls that is. After all, there's already a function for that which the turret ai uses.
Looking forward to seeing what the others think about these.
Just because it won't be used automatically by retail would not prevent some enterprising individual from actually tweaking the retail campaign to use it, would it? =)
-
I think the BOMB flag has already been split into targetable vs. destroyable. It might only be in the unstable branch. As for the Trebuchet problem, there's already an ai_profile flag to handle it.
Blowfish has some good ideas, but someone would need to go through the code and make sure they won't break anything else.
-
If they don't break anything, I can add/remove/correct any mission and table data so long as it meets with the teams approval.
-
I think the BOMB flag has already been split into targetable vs. destroyable. It might only be in the unstable branch. As for the Trebuchet problem, there's already an ai_profile flag to handle it.
Nils wrote some code for it for me a while back. As you say I suspect I committed it to the unstable branch but that was so long ago I don't remember. :)
-
Sorry just found out about this...
Can you make this so it only affects the player (for now)?
I need something like this for ROBOTECH (later on), otherwise I will have to turn every missile into a bomb (to be targetable and destroyable).