Author Topic: A Couple of Features That Might Be Useful  (Read 2912 times)

0 Members and 1 Guest are viewing this topic.

Offline blowfish

  • 211
  • Join the cult of KILL MY ROUTER!!!!!!!!!!1
A Couple of Features That Might Be Useful
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
Code: [Select]
#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
Code: [Select]
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
Code: [Select]
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
Code: [Select]
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
Code: [Select]

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]

 

Offline Backslash

  • 29
  • Bring Our Might To Bear
Re: A Couple of Features That Might Be Useful
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.

 

Offline Mobius

  • Back where he started
  • 213
  • Porto l'azzurro Dolce Stil Novo nella fantascienza
    • Skype
    • Twitter
    • The Lightblue Ribbon | Cultural Project
Re: A Couple of Features That Might Be Useful
Excellent, blowfish! :yes:

:nod:
The Lightblue Ribbon

Inferno: Nostos - Alliance
Series Resurrecta: {{FS Wiki Portal}} -  Gehenna's Gate - The Spirit of Ptah - Serendipity (WIP) - <REDACTED> (WIP)
FreeSpace Campaign Restoration Project
A tribute to FreeSpace in my book: Riflessioni dall'Infinito

 

Offline Wanderer

  • Wiki Warrior
  • 211
  • Mostly harmless
Re: A Couple of Features That Might Be Useful
Hmm.. it seems almost trivial to add hitpoints for weapons.. Which probably means i have overlooked something  :nervous:

From this
Code: [Select]
///// 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;
Do not meddle in the affairs of coders for they are soggy and hard to light

 

Offline blowfish

  • 211
  • Join the cult of KILL MY ROUTER!!!!!!!!!!1
Re: A Couple of Features That Might Be Useful
Hmm.. it seems almost trivial to add hitpoints for weapons.. Which probably means i have overlooked something  :nervous:

We were discussing this on this thread.  It seemed so easy that I was surprised it hadn't been done before.

 

Offline Wanderer

  • Wiki Warrior
  • 211
  • Mostly harmless
Re: A Couple of Features That Might Be Useful
Heh.. missed that.. Well it looks almost the same
Do not meddle in the affairs of coders for they are soggy and hard to light

 

Offline MP-Ryan

  • Makes General Discussion Make Sense.
  • Global Moderator
  • 210
  • Keyboard > Pen > Sword
Re: A Couple of Features That Might Be Useful
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? =)
"In the beginning, the Universe was created.  This made a lot of people very angry and has widely been regarded as a bad move."  [Douglas Adams]

 

Offline Goober5000

  • HLP Loremaster
  • Moderator
  • 214
    • Goober5000 Productions
Re: A Couple of Features That Might Be Useful
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.

 

Offline Zacam

  • Magnificent Bastard
  • Administrator
  • 211
  • I go Sledge-O-Matic on Spammers
    • Steam
    • Twitter
    • ModDB Feature
Re: A Couple of Features That Might Be Useful
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.
Report MediaVP issues, now on the MediaVP Mantis! Read all about it Here!
Talk with the community on Discord
"If you can keep a level head in all this confusion, you just don't understand the situation"

¤[D+¬>

[08/01 16:53:11] <sigtau> EveningTea: I have decided that I am a 32-bit registerkin.  Pronouns are eax, ebx, ecx, edx.
[08/01 16:53:31] <EveningTea> dhauidahh
[08/01 16:53:32] <EveningTea> sak
[08/01 16:53:40] * EveningTea froths at the mouth
[08/01 16:53:40] <sigtau> i broke him, boys

 

Offline karajorma

  • King Louie - Jungle VIP
  • Administrator
  • 214
    • Karajorma's Freespace FAQ
Re: A Couple of Features That Might Be Useful
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. :)
Karajorma's Freespace FAQ. It's almost like asking me yourself.

[ Diaspora ] - [ Seeds Of Rebellion ] - [ Mind Games ]

  

Offline Getter Robo G

  • 211
  • Elite Super Robot Pilot
Re: A Couple of Features That Might Be Useful
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).

"Don't think of it as being out-numbered, think of it as having a WIDE target selection!"

"I am the one and ONLY Star Dragon..."
Proof for the noobs:  Member Search

[I'm Just an idea guy, NOT: a modeler, texturer, or coder... Word of advice, "Watch out for the ducks!"]

Robotech II - Continuing...
FS2 Trek - Snails move faster than me...
Star Blazers: Journey to Iscandar...
FS GUNDAM - The Myth lives on... :)