Bridge Commander Central

BC Forums => BC Scripting => Topic started by: teleguy on June 04, 2009, 01:51:11 PM

Title: Shieldflare
Post by: teleguy on June 04, 2009, 01:51:11 PM
Is it possible to make shields glow on their own constantly for a certain amount of time?
Title: Re: Shieldflare
Post by: MLeo on June 04, 2009, 01:56:32 PM
In theory, the glow decay should partially control that, but I believe it doesn't do anything. The only other viable method is through an invisible torpedo positioned just outside a shield vector, pointing inwards, that can only hit the ship in question and (eventually) doesn't do any damage. Terribly hackish, but it's the only method I could come up with (last time it was asked).
Title: Re: Shieldflare
Post by: teleguy on June 04, 2009, 02:08:02 PM
Sounds extremely complicated. There has to be a torpedo for every shield arc. How exactly would I do that?
Title: Re: Shieldflare
Post by: MLeo on June 04, 2009, 02:13:30 PM
Like I said, it has been asked before, there may even be some code floating about.

First you define 6 vectors (for the 6 shield arcs), which denote a "normal" for a shield arc. For each vector, you create, position and prepare a torpedo, and let it go. The impact of that torpedo can be nullified through a simple FoundationTech yield.

Positioning is by scaling that arcs vector by the radius of the ship times 1.1, preparation is making sure it can only be hit by the ship itself (is fairly easy to do, EnableCollisionsWith) and that it is relative to the ship (AttachObject), and that it faces the ship (which is the opposite vector for that arc).
Title: Re: Shieldflare
Post by: teleguy on June 04, 2009, 03:59:20 PM
I've found the thread you mentioned. http://bc-central.net/forums/index.php/topic,4534.0.html
I'll take a closer look later.

Meanwhile I tried the glow decay but apperently it has no effect, there are no console errors either.

Code: [Select]
for pShield in range(App.ShieldClass.NUM_SHIELDS):
maxshield = pShields.GetMaxShields

(pShield)
rate = pShields.GetProperty

().GetShieldChargePerSecond(pShield)
glow = pShields.GetShieldGlowDecay()
pShields.GetProperty().SetShieldGlowDecay

(1000000)
pShields.SetCurShields(pShield, maxshield)


Title: Re: Shieldflare
Post by: teleguy on June 04, 2009, 04:23:05 PM
Would it perhaps be possible to attach a Nanofx atmosphere to a ship?
Title: Re: Shieldflare
Post by: MLeo on June 04, 2009, 04:29:04 PM
That's a sphere, shields are not (neccesairly). And it's static, always the same.
Title: Re: Shieldflare
Post by: USS Frontier on June 04, 2009, 04:43:46 PM
A Nanofx atmosphere is more than a sphere...
It's a couple of Sun and Planet objects.

What you want exactly?  Just to make a ship "glow" a little?
Title: Re: Shieldflare
Post by: teleguy on June 04, 2009, 04:50:56 PM
Yes, something like this or this...

Title: Re: Shieldflare
Post by: USS Frontier on June 04, 2009, 05:00:57 PM
Hmmm ok.

I asked because I know a easy way to make a "glow" in a ship, but it still would be a sphere.
It works by creating a torpedo which only purpose is to glow, and attach it to the center of the ship you want. I made something like this in GravityFX. It can be easily modified to use a torpedo with the size, color, textures and flares as you want (and actually color and size are already).
So the restrictions you would had in the effect would be those of a torpedo... Like the fact it is a sphere.

It might work for pulses as well, but I never tried it.
Title: Re: Shieldflare
Post by: teleguy on June 05, 2009, 10:59:12 AM
That sounds promising. Is it possible to make the glow semi transparent? I tried to do that with a gravity torpedo (GladSingularity) but no matter how I set the alpha in the plugin there was no visible effect.
Title: Re: Shieldflare
Post by: LJ on June 05, 2009, 01:26:38 PM
Could'nt just load a glowing sphere model, scale it and attach it to the ship?
Title: Re: Shieldflare
Post by: USS Frontier on June 05, 2009, 02:15:01 PM
Yeah, technically you should be able to make it semi-transparent changing the alpha component of all colors (core color, glow color and flare color). But still depending on size of core and glow, and the flares, the semi-transparent effect might not be easily visible... So you just gotta mess around with the values in the good old trial and error lol

LJ, that would require modeling skills I don't have lol
Since a semi-transparent sphere would be needed, and as far as I know, making such models for BC isn't exactly easy.
Plus, it would require more system resources than a simple, flare-less torpedo wouldn't it?
And finally, with the torpedo we can also easily control size, color and glow (pulse rate and size) :P
Title: Re: Shieldflare
Post by: MLeo on June 05, 2009, 03:02:51 PM
Won't work. If you encapsulate a transparent object over another object, that other object will be invisible, even if you put it outside the transparent model, but behind it, you won't see it.
Title: Re: Shieldflare
Post by: LJ on June 05, 2009, 10:12:24 PM
could you attach it in the following order:

ship -> glowing thing -> ship

I dare say the render tree doesn't do cycle checking - it might work :-)
Title: Re: Shieldflare
Post by: MLeo on June 06, 2009, 06:44:47 AM
I don't think that has anything to do with it, when transparent, they should render the background over the ship.
Title: Re: Shieldflare
Post by: LJ on June 06, 2009, 09:18:50 AM
Won't work. If you encapsulate a transparent object over another object, that other object will be invisible, even if you put it outside the transparent model, but behind it, you won't see it.
hmm..
I don't think that has anything to do with it, when transparent, they should render the background over the ship.


I wouldn't be surprised if BC uses a object based implementation of the painters algorithm.  It couldn't hurt to try subverting the render queue tho :-p  Its better than punishing the physics engine with a torpedo. :P
Title: Re: Shieldflare
Post by: Bren on June 09, 2009, 12:15:10 PM
if you reverse the vertex order of the sphere, the side opposite the camera will render, and the ship will render over that.

No problem.
Title: Re: Shieldflare
Post by: teleguy on June 18, 2009, 11:47:08 AM
Quote
I've found the thread you mentioned. http://bc-central.net/forums/index.php/topic,4534.0.html
I tried to give that a go however I've run into some problems.

This is my function:

Code: [Select]
def pShieldGlow(pObject, pEvent):
pPlayer = MissionLib.GetPlayer()
pGame = App.Game_GetCurrentGame()
pEpisode = pGame.GetCurrentEpisode()
        pShip = App.Game_GetCurrentPlayer()
pShipID = App.NULL_ID
idTarget = pShipID
pHull = pPlayer.GetHull()
radius = pHull.GetRadius()*1.5
kPoint = App.TGPoint3()
kPoint.SetXYZ(0, radius, 0)
kVector = App.TGPoint3()
kVector.SetXYZ(0, -radius, 0)


pTorp = ftb.Tech.ATPFunctions.FireTorpFromPointWithVector(kPoint,

kVector, "Blood Photon", idTarget, pShipID, 50, TGOffset = None)
pShip.AttachObject(pTorp)

And that's what the console says:



EDIT: Figured it out. However when a fire the torpedo the game crashes. How do I add the torpedo script? I tried Tactical.Projectiles.PhotonTorpedo, PhotonTorpedo and the name that shows up ingame.

EDIT2: Ok, firing torpedoes works but they are neither interacting with the ships hull nor the shields.
Title: Re: Shieldflare
Post by: USS Frontier on June 18, 2009, 12:54:36 PM
When you pass the ID of the target (idTarget) to the FireTorpFromPointWithVector function, it expects that it is a valid ID (meaning the ID of a ship that exists).
And quoting your code:
Code: [Select]
pShipID = App.NULL_ID
idTarget = pShipID
So yeah, it'll never work like that lol. You gotta pass a valid ID  (like pTargetShip.GetObjID(), assuming pTargetShip to be a ShipClass obj).
The same applies to the parameter pShipID you're passing, tho if I remember correctly it might not be as necessary as the target ID.

Also, why are you doing this:
Code: [Select]
pPlayer = MissionLib.GetPlayer()
# ...
        pShip = App.Game_GetCurrentPlayer()
???
pPlayer and pShip will be the same object: the player ship.


About the pcTorpScriptName parameter (which in your code is "Blood Photon"), it should be the torpedo script (module) string, like "Tactical.Projectiles.<script name>".


EDIT: lol just now saw your edits :P
Anyway... How do you mean they're not interacting with the hulls/shields? You want your torp to "hit" the shields to show the shield effect?
If that's the case, try these 2 things: make that the ship isn't the torp's parent but the target,  also try to make it without attaching the torpedo to the ship (i've tried that before and the torpedo never detonated).
Title: Re: Shieldflare
Post by: teleguy on June 18, 2009, 01:12:23 PM
Thanks.
If I don't attach the torpedo to the ship the torpedoes just start flying from a random location.

How do I make the ship not the parent but the target?
Title: Re: Shieldflare
Post by: MLeo on June 18, 2009, 04:49:07 PM
Target and parent can be App.NULL_ID

They won't affect the player if the parent is the player.

@Frontier: The wrong projectile name didn't crash BC (and worked) probably because of DiamondBC_Projectiles. ;)
Title: Re: Shieldflare
Post by: teleguy on June 18, 2009, 06:14:19 PM
So this is my function

Code: [Select]
def pShieldGlow(pObject, pEvent):
pPlayer = MissionLib.GetPlayer()
pGame = App.Game_GetCurrentGame()
pEpisode = pGame.GetCurrentEpisode()
pShip = App.Game_GetCurrentPlayer()
pShipID = pShip.GetObjID()
idTarget = pShip.GetObjID()
#pHull = pPlayer.GetHull()
radius = pShip.GetRadius()*1.1
kPoint = App.TGPoint3()
kPoint.SetXYZ(0, radius, 0)
kVector = App.TGPoint3()
kVector.SetXYZ(0, -radius, 0)


pTorp = ftb.Tech.ATPFunctions.FireTorpFromPointWithVector(kPoint,

kVector, "Tactical.Projectiles.Quantum", idTarget, pShipID, 20, TGOffset =

None)

pShip.AttachObject(pTorp)
#pShip.EnableCollisionsWith(pTorp, 1)
#pTorp.EnableCollisionsWith(pShip, 1)

and the movie shows what happens when I fire the torpedo.
Title: Re: Shieldflare
Post by: USS Frontier on June 18, 2009, 06:23:05 PM
Mleo,
Target can be NULL_ID only if you have a version of FTech/ATPFunctions.py I don't have lol
I tho the one in KM1 was the latest?
From the ATPFunctions.py, FireTorpFromPointWithVector function (right at the beggining):
Code: [Select]
pTarget = App.ShipClass_Cast(App.TGObject_GetTGObjectPtr(idTarget))
pSet = pTarget.GetContainingSet()
If the target is NULL_ID, pTarget = None, and "None" has no attribute GetContainingSet()  :P  And that part of code isn't in a "try/catch" block lol
The parent/ship ID can be NULL tho yea...

Dunno if he has the DiamondBC scripts so it's best to assume he hasn't :P
Heck that reminds me I have to get them lol

teleguy,
If you not attach the torp to the ship, it's position (as you set) will be in "space" coords, and not the "local" coords of the ship, that's why they appear off position. You just gotta compensate for that:  start the torp's location vector from the target's world location, then add the appropriate offset (like you're doing) to make it appear a bit to the side of ship and hit her.

OR your problem is like Mleo said: they won't affect the player if the parent is the player.
Which I believe can be generalized to: the torp you fire won't affect the ship X if it's parent is ship X :P

EDIT:
Saw your post now, you made the torp's parent and target the same (like Mleo said). Set the parent as NULL_ID, and see if that works.
Title: Re: Shieldflare
Post by: teleguy on June 18, 2009, 06:29:16 PM
Code: [Select]
pShipID = App.NULL_ID??

If I do that I get a crash to desktop.
Title: Re: Shieldflare
Post by: MLeo on June 18, 2009, 07:48:21 PM
Mleo,
Target can be NULL_ID only if you have a version of FTech/ATPFunctions.py I don't have lol
I tho the one in KM1 was the latest?
Ok, point taken, you need a target. But no parent.
And it's the parent that's important, if a torp from a parent could hit said parent, then it would never leave the hull.

I can't even remember if I ever changed it, so it's the latest.
Title: Re: Shieldflare
Post by: teleguy on June 19, 2009, 05:45:41 AM
I managed to get the torpedoes to do damage but for some reason attaching the torpedo to the ship no longer works.

Code: [Select]
def pShieldGlow(pObject, pEvent):
pPlayer = MissionLib.GetPlayer()
pGame = App.Game_GetCurrentGame()
pEpisode = pGame.GetCurrentEpisode()
pShip = App.Game_GetCurrentPlayer()
pShipID = App.NULL_ID
idTarget = pShip.GetObjID()
pHull = pPlayer.GetHull()
idTargetSubsystem = pHull.GetObjID()
radius = pShip.GetRadius()*1.3
kPoint = App.TGPoint3()
kPoint.SetXYZ(0, radius, 0)
kVector = App.TGPoint3()
kVector.SetXYZ(0, -radius, 0)


#pTorp = ftb.Tech.ATPFunctions.FireTorpFromPointWithVector(kPoint, kVector, "Tactical.Projectiles.QuantumTorpedo", idTarget, pShipID, 20, TGOffset = None)

pTorp = MissionLib.FireTorpFromPoint(None, kPoint, "Tactical.Projectiles.QuantumTorpedo", idTarget, idTargetSubsystem, 20, None)

pShip.AttachObject(pTorp)

Title: Re: Shieldflare
Post by: USS Frontier on June 19, 2009, 12:59:59 PM
That's because the MissionLib function returns 0, and not the torpedo object...
Title: Oh yea!!!
Post by: teleguy on June 19, 2009, 04:50:52 PM
 :D  :dance :dance
(http://bc-central.net/forums/index.php?action=dlattach;topic=5869.0;attach=30028;image)
(http://bc-central.net/forums/index.php?action=dlattach;topic=5869.0;attach=30030;image)

Thank you Mleo and USS Frontier, you rule!


I still have one question though. Would the onYield function remove those small puffs of smoke and the shield impact sounds?

Title: Re: Shieldflare
Post by: teleguy on June 20, 2009, 09:18:43 AM
So is it possible to remove the explosions and the impact sounds? And how can I find out the setname of the ship set?
Title: Re: Shieldflare
Post by: MLeo on June 20, 2009, 09:26:45 AM
Still thinking about the puffs, they seem awfully randomly placed. You did set the lifetime to 0 in the OnYield, right? So the shield doesn't drain?

About the set, from any ship (and nearly any object that you can see) you can call "GetContainingSet" and it will give you the actual set (not just the set name).
Title: Re: Shieldflare
Post by: teleguy on June 20, 2009, 09:56:07 AM
Quote
You did set the lifetime to 0 in the OnYield, right? So the shield doesn't drain?
No I set the damage in the torpedo script to 0.0001.
Quote
About the set, from any ship (and nearly any object that you can see) you can call "GetContainingSet" and it will give you the actual set (not just the set name).
I'm using ATPFunctions.FireTorpFromPoint and that rerquires pcSetName. So far I set it to none.

Quote
Still thinking about the puffs, they seem awfully randomly placed.
Yes, that's the problem. I think that's because the function uses world coordinates to orient the torpedo toward the target and those are srewed up when I move the torpedo into the ship set. Anyhow the torpedoes fly in strange diagonal circles around the ship.










Title: Re: Shieldflare
Post by: MLeo on June 20, 2009, 12:59:08 PM
Quote
You did set the lifetime to 0 in the OnYield, right? So the shield doesn't drain?
No I set the damage in the torpedo script to 0.0001.
If you call pTorp.SetLifetime(0) then you still get the shield effect (possibly also the explosion, not sure) but it won't do any damage at all.

Quote
Quote
About the set, from any ship (and nearly any object that you can see) you can call "GetContainingSet" and it will give you the actual set (not just the set name).
I'm using ATPFunctions.FireTorpFromPoint and that rerquires pcSetName. So far I set it to none.
After you get the set, call GetName() to get the pcSetName.

Quote
Quote
Still thinking about the puffs, they seem awfully randomly placed.
Yes, that's the problem. I think that's because the function uses world coordinates to orient the torpedo toward the target and those are srewed up when I move the torpedo into the ship set. Anyhow the torpedoes fly in strange diagonal circles around the ship.
As soon as you attach the torpedo to the ship, then it's "origin" (coordinate 0, 0, 0) is then the ship itself, instead of the set.

The system won't suddenly change just because you have a different origin.
Title: Re: Shieldflare
Post by: teleguy on June 20, 2009, 01:07:26 PM
Quote
As soon as you attach the torpedo to the ship, then it's "origin" (coordinate 0, 0, 0) is then the ship itself, instead of the set.

The system won't suddenly change just because you have a different origin.
So why are the torpedoes flying in tilted circles if the torpedo is attached?
Title: Re: Shieldflare
Post by: USS Frontier on June 20, 2009, 01:47:48 PM
Perhaps the torp's orientation (forward vector) is wrong. Like it should (from any point around the ship) be pointing at the ship, but isn't.  Since torps move forward, they go in a line which won't hit the ship and thus start turning to actually hit the ship.
And with that you get the feeling they circling the ship :P

You could try changing the torp's attributes like speed, max angular accel and guidance lifetime, to see if it's really a problem with the orientation. If you make the torp have god-like maneuvering, he'll be able to hit the ship with a erroneous orientation and seem like line trajectory (or at least a lot closer to a line trajectory than you're currently having).


And just as a kinda offtopic idea: what if you set the torps to actually damage the ship?
It would be a cool offensive tech lol
Title: Re: Shieldflare
Post by: teleguy on June 20, 2009, 03:08:17 PM
Quote
You could try changing the torp's attributes like speed, max angular accel and guidance lifetime, to see if it's really a problem with the orientation. If you make the torp have god-like maneuvering, he'll be able to hit the ship with a erroneous orientation and seem like line trajectory (or at least a lot closer to a line trajectory than you're currently having).

Guidance Lifetime and AngularAcceleration are already pretty high (30 and 50). I tried with 30 and 200 and it didn't help much.

Quote
Perhaps the torp's orientation (forward vector) is wrong. Like it should (from any point around the ship) be pointing at the ship, but isn't.

Since the vector is created by the function based on the relative positions between torpedo and ship, don't I get the wrong vector if a different set is used? I noticed that the direction of the torpedoes changes as the position of the ship shifts.

Does anybody know why setting pShipID = App.NULL_ID in FireTorpFromPointWithVector crashes the game?






Title: Re: Shieldflare
Post by: MLeo on June 20, 2009, 06:01:49 PM
Probably because you didn't specify the offset (TGOffset in the code).
Title: Re: Shieldflare
Post by: teleguy on June 20, 2009, 08:15:50 PM
Ok, I'm now trying to use the Ftech yield however I don't have any success.


Quote
And just as a kinda offtopic idea: what if you set the torps to actually damage the ship?
It would be a cool offensive tech lol
I've thought about this too.
Title: Re: Shieldflare
Post by: USS Frontier on June 21, 2009, 02:04:19 AM
In that second script, the one I believe is the tech, don't put everything inside a try block. Because what you put in there is essentially the whole script, and if any errors happen within it, because of the except "pass" block, you'll never know what happened... So in this case the console dump is kinda useless because there was no way for anything to appear in it due to that try/except in your script   :?

And about the first script, the torpedo: if your idea is to use the FTech tech only to make the torpedo not do any damage (using the SetLifetime(0)), then you'll only need the onYield method. In your torpedo script, you add the torp to FTech both in the onYield as in the onFire, which in this case is kinda pointless lol
Probably won't change much, but why bother doing something useless right :P
Title: Re: Shieldflare
Post by: teleguy on June 21, 2009, 08:36:44 AM
Code: [Select]
import App
try:
import Foundation
import FoundationTech

except:
print "FTech not found"



class ShieldflareTorpedo(FoundationTech.TechDef):
def __init__(self, name, dict = {}):
FoundationTech.TechDef.__init__(self, name,

FoundationTech.dMode)
self.lYields = []
self.__dict__.update(dict)
self.lFired = []


def OnYield(self, pShip, pInstance, pEvent, pTorp):
pTorp.SetLifetime(0)
Title: Re: Shieldflare
Post by: MLeo on June 21, 2009, 08:43:04 AM
You have inconsistent identation (sp).

Code: [Select]
import App
try:
import Foundation
import FoundationTech

except:
print "FTech not found"



class ShieldflareTorpedo(FoundationTech.TechDef):
def __init__(self, name, dict = {}):
FoundationTech.TechDef.__init__(self, name, FoundationTech.dMode)
self.lYields = []
self.__dict__.update(dict)
self.lFired = []

def OnYield(self, pShip, pInstance, pEvent, pTorp):
pTorp.SetLifetime(0)
Title: Re: Shieldflare
Post by: teleguy on June 21, 2009, 09:36:15 AM
Fixed it. However it's still doing shield damage and explosions.
Title: Re: Shieldflare
Post by: MLeo on June 21, 2009, 10:02:39 AM
I assume you mean with "damage" that the shield still drains?
Is the tech applied to your torpedo?
Title: Re: Shieldflare
Post by: teleguy on June 21, 2009, 10:18:28 AM
The second attachment in my last post is the torpedo script.
Title: Re: Shieldflare
Post by: teleguy on June 21, 2009, 01:51:29 PM
Maybe there's something wrong with my install. I noticed Phased Torpedoes are also doing shield damage.
Title: Re: Shieldflare
Post by: MLeo on June 21, 2009, 01:54:07 PM
Could you please describe what you mean with "shield damage"?

I mean, SetLifetime has worked since, forever.
Title: Re: Shieldflare
Post by: teleguy on June 21, 2009, 01:56:13 PM
I mean the torpedoes are draining the shield.

Did you check if my torpedo script is correct?
Title: Re: Shieldflare
Post by: MLeo on June 21, 2009, 02:19:27 PM
It looks correct. Please try the following in the console (and get a console report afterwards) when you are in game.

Code: [Select]
print App.Torpedo.SetLifetime
Title: Re: Shieldflare
Post by: teleguy on June 21, 2009, 02:29:20 PM
Here is it. And thank you for your patience.

Title: Re: Shieldflare
Post by: teleguy on June 23, 2009, 09:06:53 AM
Does that tell you anything?
Title: Re: Shieldflare
Post by: MLeo on June 25, 2009, 05:59:27 PM
I was hoping to find something there.

If you look in scripts/Custom/Techs/PhasedTorp.py, you can see I use the same thing, and I know it works there.