Targetting subents

General discussion for players of Oolite.

Moderators: winston, another_commander

Post Reply
User avatar
CommonSenseOTB
---- E L I T E ----
---- E L I T E ----
Posts: 1397
Joined: Wed May 04, 2011 10:42 am
Location: Saskatchewan, Canada

Targetting subents

Post by CommonSenseOTB »

Is there a way through script or AI to have NPC's target a subent of the player ship or of other NPC's instead of the main entity so they would effectively ignore the main entity to attack the subent(s) only?
Take an idea from one person and twist or modify it in a different way as a return suggestion so another person can see a part of it that can apply to the oxp they are working on.


CommonSense 'Outside-the-Box' Design Studios Ltd.
WIKI+OXPs
User avatar
Thargoid
Thargoid
Thargoid
Posts: 5528
Joined: Thu Jun 12, 2008 6:55 pm

Re: Targetting subents

Post by Thargoid »

Not to my knowledge, no.
User avatar
Kaks
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 3009
Joined: Mon Jan 21, 2008 11:41 pm
Location: The Big Smoke

Re: Targetting subents

Post by Kaks »

Sorry, I hadn't noticed this one at the time!

I take it you've already tried this snippet inside your NPC js script:

Code: Select all

this.shipTargetAcquired = function(targetShip){
   if(targetShip.subEntities.length > 0)  this.ship.target = targetShip.subEntities[0];
}
I haven't actually looked into this at all, but I'd have thought there's nothing in trunk (and in 1.75.3) to stop it from working...
Hey, free OXPs: farsun v1.05 & tty v0.5! :0)
User avatar
Eric Walch
Slightly Grand Rear Admiral
Slightly Grand Rear Admiral
Posts: 5536
Joined: Sat Jun 16, 2007 3:48 pm
Location: Netherlands

Re: Targetting subents

Post by Eric Walch »

Kaks wrote:
I haven't actually looked into this at all, but I'd have thought there's nothing in trunk (and in 1.75.3) to stop it from working...
I remember looking in the code and noticed that the code always makes sure it is not targeting subEnts. It selects the mother when tried.
User avatar
Kaks
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 3009
Joined: Mon Jan 21, 2008 11:41 pm
Location: The Big Smoke

Re: Targetting subents

Post by Kaks »

Ok, then all you can do is to specifically override the targetted ship's takingDamage, to transfer all the damage to one of its subentities. Technically it's not the same, but hey, as long as you don't tell anybody... :)

Something along these lines:

Code: Select all

this.ship.target.script.oldDamageEvent = this.ship.target.script.shipTakingDamage
player.thatSpecificShip = this.ship;

this.ship.target.script.shipTakingDamage = function(amount, whom, type)
{
     if(whom.isValid && whom == player.thatSpecificShip && this.ship.subEntities.length > 0){
          // they're targetting subents!!!
          this.ship.energy += amount;
          this.ship.subEntities[0].energy -= amount;
     }
     else if (this.oldDamageEvent) this.oldDamageEvent();
}
Shouldn't be too far from working ok: as long as it's got at least a subent, any hit from 'thatSpecificShip' is going to damage the first subent. Once all subents are gone it'll behave exactly as before! ;)

The extra stuff in the script is to take into account NPC shields & the like. If you don't care about that, then things should get simpler.

NB: the keyword this should refer to different things depending on the context, that's why I used player to transfer the original this.ship value inside the function. To be 'proper' I should have used closures instead, but that could have meant a bit of a longer explanation... :P

Anyway, hope this goes some way towards helping you make your ideas reality! :)
Hey, free OXPs: farsun v1.05 & tty v0.5! :0)
User avatar
CommonSenseOTB
---- E L I T E ----
---- E L I T E ----
Posts: 1397
Joined: Wed May 04, 2011 10:42 am
Location: Saskatchewan, Canada

Re: Targetting subents

Post by CommonSenseOTB »

Thanx Kaks. That should help tremendously down the road. :D
Take an idea from one person and twist or modify it in a different way as a return suggestion so another person can see a part of it that can apply to the oxp they are working on.


CommonSense 'Outside-the-Box' Design Studios Ltd.
WIKI+OXPs
Post Reply