Author Topic: access to directory (nt.listdir(***)) / SinglePlayer in QB & Galaxy Charts  (Read 7403 times)

Offline cnotsch

  • Posts: 85
  • Cookies: 3
Re: access to directory (nt.listdir(***))
« Reply #20 on: May 26, 2008, 11:55:48 PM »
thanks ill try it out asap.

Offline cnotsch

  • Posts: 85
  • Cookies: 3
Re: access to directory (nt.listdir(***))
« Reply #21 on: May 28, 2008, 03:33:56 PM »
ok i started writing a eventhandler as you said but i came to a problem; i already have the following:
Code: [Select]
def SetWarpExitPointSetup(TGObject, pEvent):
pShip   = App.ShipClass_Cast(pEvent.GetDestination())
pPlayer = MissionLib.GetPlayer()

if not pShip:
return

if pPlayer:
if (pPlayer.GetName() == pShip.GetName()):


elif (pShip.GetName() == "Galaxy")
ExitPos = App.TGPoint3()



TGObject.CallNextHandler(pEvent)
i know it's not that much yet, but how do i get the target set, i mean the set wich the ship travels to?
and i got another problem:

Code: [Select]
def ListObjectsInSet(pSet, j):
import sys
for i in range(j):
Obj = App.Waypoint_Cast(pSet.GetObjectByID(i))
if Obj:
str = repr(Obj.GetName()) + " - " + repr(Obj) + " & "
sys.stderr.write(str)

if I'm right this should list any waypoint in a set but unless i create a waypoint with my own routine:
Code: [Select]
def AddNav():
global kThis
if kThis:
kThis.SetDelete(1)

pPlayer = App.ShipClass_Cast(MissionLib.GetPlayer())
pSet    = pPlayer.GetContainingSet()

kThis = App.Waypoint_Create("PlayerPosition", pSet.GetName(), None)
kThis.SetStatic(1)
kThis.SetNavPoint(1)
kThis.SetTranslate(pPlayer.GetTranslate())
kForward = App.TGPoint3()
kForward.SetXYZ(0.417716, 0.620277, 0.663905)
kUp = App.TGPoint3()
kUp.SetXYZ(-0.898685, 0.389602, 0.201435)
kThis.AlignToVectors(kForward, kUp)
kThis.SetSpeed(25.000000)
kThis.Update(0)

it returns not a single result even when setting the maximum id to 300000, but it should at least return the default placements including "player start";
besides is there a easier way to get a list of objects in a set;

so how do i get now the waypoint from a string for example "Player Start" ???

it's a bit of a shame that i couldn't find out the last one on my own  :oops: :oops: :oops:

Offline USS Frontier

  • Posts: 176
  • Cookies: 562
Re: access to directory (nt.listdir(***))
« Reply #22 on: May 28, 2008, 10:27:55 PM »
To get the destination set, use that example I posted before to get the ship's Travel instance, but also use the following:
Code: [Select]
pInitialShipSet = pTravel.InitialShipSet
pDestinationSet = pTravel.DestSet
:D
the Travel instance has a lot of usefull stuff regarding the entire travelling process, more so with the upcoming patch.
If you want, go to "Custom\GalaxyCharts\" and open "Traveler.py".  It's a big script, but in it you'll find the TravelManager and Travel/Chaser class definitions, and so you can check them to see all the methods you can use. (and like I already mentioned, there A LOT MORE stuff in the patch)
--------------------------------------------------------------------------
To get all objs in a set, use the following:
Code: [Select]
for pShip in pSet.GetClassObjectList(App.CT_SHIP):
*do something*

for pAsField in pSet.GetClassObjectList(App.CT_ASTEROID_FIELD):
*do something*

for pNebula in pSet.GetClassObjectList(App.CT_NEBULA):
*do something*

for pSun in pSet.GetClassObjectList(App.CT_SUN):
*do something*

for pPlanet in pSet.GetClassObjectList(App.CT_PLANET):
                          *do something*

for pPlanet in pSet.GetClassObjectList(App.CT_WAYPOINT):
                          *do something*
You can pretty much pass as the parameter any of the obj identifiers from App (App.CT_*something*) to get all objs from that class in the set.
Let's just say it a *MUCH* better way than the one you were using :P
----------------------------------------------------------------------------------------------------------
To get a obj by name on a specified set, use:
Code: [Select]
App.ObjectClass_GetObject(pSet, "obj name goes here")I think the parameters are pretty self-explanatory right :P
Also, if you pass in pSet as None, it will check for that obj in all sets.
After getting the obj, you can use other functions to change it to a more specialized class, like
Code: [Select]
pWaypoint = App.Waypoint_Cast(pObject)
"Revenge is a dish best served cold"
                    -Old Klingon Proverb
GravityFX Download
Galaxy Charts Download

Offline cnotsch

  • Posts: 85
  • Cookies: 3
Re: access to directory (nt.listdir(***))
« Reply #23 on: May 29, 2008, 04:54:15 AM »
Quote
Let's just say it a *MUCH* better way than the one you were using
..And a LITTLE bit faster  :D :D :D

Thanks that helps a lot.

By the way do you have any Idea when the patch will be released, so if it is going to be released sometime soon i can for example leave out the routines setting the warp exit point.

Oh and i found another bug in GC, when exiting warp the ship still moves with about 5000kph i think it was between forward and right and you can't control this direction until you change the speed, then the ship stabilizes itself; Any Idea?

Offline MLeo

  • Retired Staff
  • Posts: 3636
  • Cookies: 833
  • Software Simian
    • the Programming Pantheon
Re: access to directory (nt.listdir(***))
« Reply #24 on: May 29, 2008, 11:20:14 AM »
Code: [Select]
def SetWarpExitPointSetup(TGObject, pEvent):
if pPlayer:
if (pPlayer.GetName() == pShip.GetName()):

elif (pShip.GetName() == "Galaxy")
ExitPos = App.TGPoint3()
I think you didn't post everything, but if you did, you know this is illegal in Python, right?
I still can't read peoples minds, nor can I read peoples computers, even worse, I can't combine the two to read what is going wrong with your BC install...

"It was filed under 'B' for blackmail." - Morse, Inspector Morse - The dead of Jericho.

Offline cnotsch

  • Posts: 85
  • Cookies: 3
Re: access to directory (nt.listdir(***))
« Reply #25 on: May 29, 2008, 11:45:01 AM »
Code: [Select]
def SetWarpExitPointSetup(TGObject, pEvent):
pShip   = App.ShipClass_Cast(pEvent.GetDestination())
pPlayer = MissionLib.GetPlayer()

if not pShip:
return

if pPlayer:
if (pPlayer.GetName() == pShip.GetName()):
                                <- here is no expression

elif (pShip.GetName() == "Galaxy")                                      <- this ":" was missing
ExitPos = App.TGPoint3()



TGObject.CallNextHandler(pEvent)
was it that if so i know; i just posted this halfway during writing the first ideas from scrach as i got to my problems so i posted it to show you my ideas/status or whatever  8), I'm going to cotinue now and let you know if there are any questions left (wich is very likely  :lol: :lol: :lol:)

Offline USS Frontier

  • Posts: 176
  • Cookies: 562
Re: access to directory (nt.listdir(***))
« Reply #26 on: May 29, 2008, 09:27:23 PM »
By the way do you have any Idea when the patch will be released, so if it is going to be released sometime soon i can for example leave out the routines setting the warp exit point.

Oh and i found another bug in GC, when exiting warp the ship still moves with about 5000kph i think it was between forward and right and you can't control this direction until you change the speed, then the ship stabilizes itself; Any Idea?
Unfortunately I can't really say when it will be out. There isn't much to do in my TODO list until the beta is ready,  but my free time to work on it this whole year is pretty random... Some weeks I have a lot of time, others I don't even open the script...

Yeah if I remember correctly, GC sets the ship to impulse 9, forward vector, when exiting travel, after reseting the ship's impulse engine system attributes.
Dunno why tho you can't really control it until changing the speed to stabilize the ship... I never really saw it as an bug. Maybe i'm not doing it the correct way somehow... dunno really, gotta check it later.
"Revenge is a dish best served cold"
                    -Old Klingon Proverb
GravityFX Download
Galaxy Charts Download

Offline cnotsch

  • Posts: 85
  • Cookies: 3
thanks.

I just dont get it:
Code: [Select]
pPlayer = App.ShipClass_Cast(MissionLib.GetPlayer())
pSet    = pPlayer.GetContainingSet()

kThis = App.Waypoint_Create("PlayerPosition", pSet.GetName(), None)
kThis.SetStatic(1)
kThis.SetNavPoint(1)
kThis.SetTranslate(pPlayer.GetTranslate())
kForward = App.TGPoint3()
kForward.SetXYZ(0.417716, 0.620277, 0.663905)
kUp = App.TGPoint3()
kUp.SetXYZ(-0.898685, 0.389602, 0.2014 35)
kThis.AlignToVectors(kForward, kUp)
kThis.SetSpeed(25.000000)
kThis.Update(0)

Code: [Select]
# Position "Player Start"
kThis = App.Waypoint_Create("Player Start", sSetName, None)
kThis.SetStatic(1)
kThis.SetNavPoint(0)
kThis.SetTranslateXYZ(-32.572227, -226.536850, -0.921197)
kForward = App.TGPoint3()
kForward.SetXYZ(-0.858776, 0.441285, 0.260330)
kUp = App.TGPoint3()
kUp.SetXYZ(0.199461, -0.180069, 0.963219)
kThis.AlignToVectors(kForward, kUp)
kThis.SetSpeed(25.000000)
kThis.Update(0)
kThis = None
# End position "Player Start"

the first one is the routine i wrote in "MyLib/AddNav()" the second is the one in "Belaruz4/LoadPlacements(sSetName)"
I JUST DON'T GET IT WHY DOES MINE WORK BUT NOT THE OREGINAL????
There is no sign of the "Player Start" WP but with "PlayerPosition" it works perfectly...
Even when i call LoadPlacements manually from console it seems to do nothing..... where are this silly WPs......
ANY ideas what could be the error?
NOTE: i use this to search for  the WPs:
Code: [Select]
def ListObjectsInSet(pSet, Type):
for pObject in pSet.GetClassObjectList(Type):
if pObject:
str = repr(pObject.GetName())
print str
with this calls:
Code: [Select]
ListObjectsInSet(MissionLib.GetPlayer().GetContainingSet(), App.CT_WAYPOINT)
ListObjectsInSet(MissionLib.GetPlayer().GetContainingSet(), App.CT_BASE_OBJECT)

Oh and i tried this too:
Code: [Select]
Obj = App.ObjectClass_GetObject(MissionLib.GetPlayer().GetContainingSet(), "Player Start")
print Obj

Result: None     :x :x :x

Offline cnotsch

  • Posts: 85
  • Cookies: 3
I've got another question how do i programm a timer to a part of a class
Code: [Select]
Class A:
    def B(self, pObject, pEvent):
        *Do something*

    def __init__(self, x, y, z):
        *Something here....*
        MissionLib.CreateTimer(myEvent, __name__ + ".B", App.g_kUtopiaModule.GetGameTime() + 1.5, 0, 0)              <-Does that work for classes i don't think so
        *and there*

Offline MLeo

  • Retired Staff
  • Posts: 3636
  • Cookies: 833
  • Software Simian
    • the Programming Pantheon
It doesn't, directly, work for classes.

It will always try to import everything up to the last dot, and then invoke the function. Since you can't directly import a variable (even classes, and their instances are variables) only a module (exception is the from module import statement, but that doesn't get used).


What you can do, is look in MissionLib and basicly copy it, but create it with extra information, say, a TGStringEvent, and then have a redirect function (which is the target of the event/timer) use that extra info to call the right method on an instance.

There is another way, but I haven't used it before, infact, I can't recall anyone ever using it, and to make matters worse, I haven't known about it before a minute ago. ^_^'
I still can't read peoples minds, nor can I read peoples computers, even worse, I can't combine the two to read what is going wrong with your BC install...

"It was filed under 'B' for blackmail." - Morse, Inspector Morse - The dead of Jericho.

Offline USS Frontier

  • Posts: 176
  • Cookies: 562
you're in need of Class Based Timers?  No problem lol! :P
I know you may be getting a little bit bored right now with me saying this all the time but:  check out GC. xD
More specifically, the GalaxyLIB script, and his CreateMethodTimer function (its near the top), and the RandomDefenceForce class in the same script to see an implementation of it. The Travel class in the Traveler.py script also implements it, plus other class based event handlers, but its a little more complicated because its a lot more lines of code :P.
The whole war simulator system in the patch is pretty much based on class based events as well, using pratically the same routines.


Now as for the "missing waypoint" problem, sorry I don't have a clue about what it is... I would guess the LoadPlacements isn't being properly executed, but you said you manually called it from the console and it didn't gave any errors so.........
"Revenge is a dish best served cold"
                    -Old Klingon Proverb
GravityFX Download
Galaxy Charts Download

Offline cnotsch

  • Posts: 85
  • Cookies: 3
Ok i've created a nice routine that creates new navpoints for the exit locations (ill delete the navpoint attribute later) but when setting the SetExitLocationVector of pTravel to its position the ship drops out of warp at this position but moves on from there (the path where the ships slows down after exiting warp) but is it also possible to set it so that the ship arrives there when stopped (so it drops out at a point behind this placement and moves on to the placement itself)
i've also tried to use the SetExitPlacementName function but this seems to do nothing...

Offline USS Frontier

  • Posts: 176
  • Cookies: 562
Yeah that exit location/exit placement is very confusing... It actually was from the regular BC warp system, so when I made the Traveler system I recreated it, mostly because I couldn't think of another way and to maintain compatibility with other scripts that used the system like that.
The Exit Location sets the point in space where the ship will drop out of warp, but after this the ship goes a few kilometers ahead in the dropping out sequence.
The Exit Placement sets the point where the ship will be pointed at when exiting, thus creating an trajectory. And yes it's that function SetExitPlacementName that sets the placement (by name) to use in the destination set.

Both if not defined will be randomly made by the Traveler system. And also with some vector math you can calculate where the 2 points will be to make the ship more or less stay where you want when it drops out of warp.

Actually I never gave, personally, much testing into those 2 functions, and I can't say if the beta testers tried it out somehow... But I can, like I've already done, say what they should do. So if they don't do it,  congrats, you just found a bug :P.
"Revenge is a dish best served cold"
                    -Old Klingon Proverb
GravityFX Download
Galaxy Charts Download

Offline cnotsch

  • Posts: 85
  • Cookies: 3
I think i found another bug,
could it be that you left out something at the warpsequence with no destinationset?

I found out creating a warp is done like this:
pShip .... the ship you want to set the warp up for as App.ShipClass
App.g_kTravelManager.EngageTravelToOfShip(pShip, "Systems.Beol.Beol4")
wich does following:
travel = App.g_kTravelManager.CreateTravel(pShip)
travel.TravelTo("Systems.Beol.Beol4")
the 2nd line does the following:
travel.SetDestination("Systems.Beol.Beol4")
travel.Travel()

so manually i'd type:
travel = App.g_kTravelManager.CreateTravel(pShip)
travel.SetDestination(sDestination)
travel.Travel()

if i don't call the 2nd line travel.DestSet would be None,
according to your comments the ship should now warp out and disapperar - if i got that right...
the problem:
travel.Travel() returns bevore even setting the warp sequence, so i added this bevore calling travel.Travel():
travel.TravelerSequence.SetupSequence()
now the ship does accelerate and creates a warp flash, the only thing left would be to delete the ship and call the App.ET_EXITED_SET after the ship disappears in the flash...

all that seems a bit difficult so i wonder if i have oversight something?
is there a easier way to call that?
if not how to i complete my idea?

Offline USS Frontier

  • Posts: 176
  • Cookies: 562
Of course if you don't call the second line (" travel.SetDestination("system script module") ")  the dest set will be none... How do you want it to be something if you didn't set a destination? O_o   Or you can use "SetDestination(None)" to directly set it as none, incase it isnt.

The method "travel.TravelerSequence.SetupSequence" is used internally by GC so it shouldn't really be called outside :P
The order things are done in a travel sequence is pretty important xD

Anyway, yes the ship should warp out and disappear if the destination is none. However, also like i've said before: it's a known bug in GC v1.0 that ships can't warp to None, since it won't work like it should... Something that has already been corrected in GC's patch.


To complete your idea I think you mean to make a ship warp out and disappear right?
Well... If it's that then I'll check here if I can modify a v1.0 Traveler script with the changes necessary to make the "warp to None" thing work,  and then i'll post it here for you to use.
"Revenge is a dish best served cold"
                    -Old Klingon Proverb
GravityFX Download
Galaxy Charts Download

Offline cnotsch

  • Posts: 85
  • Cookies: 3
Thanks but don't bother i wrote a new one myself into my warpout AI ^^:
Code: [Select]
import App

def WarpShipOutGC(pShip, bForceWarp):
travel = App.g_kTravelManager.CreateTravel(pShip)
travel.TravelerSequence.SetupSequence()
pDelShip = App.TGScriptAction_Create(__name__, "DeleteShip", pShip)
travel.TravelerSequence.EngageWarpSeq.AppendAction(pDelShip)
if travel.Ship.IsDying() or travel.Ship.IsDead():
return 0
if bForceWarp == 1:
pShip.SetCollisionsOn(0)
travel.TravelerSequence.PlayEngagingWarpSeq()
else:
travel.Travel()

def DeleteShip(pTGAction, pShip):
pShip.SetDeleteMe(1)

def CreateAI(pShip, bForceWarp = 0):
#########################################
# Creating PlainAI WarpNowhere at (33, 28)
pWarpNowhere = App.PlainAI_Create(pShip, "WarpNowhere")
pWarpNowhere.SetScriptModule("RunScript")
pWarpNowhere.SetInterruptable(0)
pScript = pWarpNowhere.GetScriptInstance()
pScript.SetScriptModule(__name__)
pScript.SetFunction("WarpShipOutGC")
pScript.SetArguments(pShip, bForceWarp)
# Done creating PlainAI WarpNowhere
#########################################
return pWarpNowhere

In case you thaught the error might be anywwhere else this is was i found in Traveler.Travel.Travel():
Code: [Select]
def Travel(self, pMethodTimerEvent = None):
try:
self.Logger.LogString("Travelling procedures initiated...")
if self.Ship.IsDying() or self.Ship.IsDead():
self.Logger.LogString(" -Ship is dead or dying")
return 0
if self.IsTurning == 1:
self.Logger.LogString(" -Ship is turning to face a good direction")
return 0
if App.g_kTravelManager.IsShipBeingTowed(self.Ship) == 1:
self.Logger.LogString(" -Cancelling, ship is being towed")
return 0
self.UpdateVariables()
if CanShipWarp(self.Ship) == 0:
self.Logger.LogString(" -Cancelling, ship can't warp. ("+dShipNoWarpReason[self.Ship.GetObjID()]+")")
return 0
if self.InitialShipSet == None:
self.Logger.LogString(" -Cancelling, no initial set.")
return 0
if self.IsPlayer == 0 and self.DestSet == None:
self.Logger.LogString(" -Extra path: AI ship warping to None")
# AI Ship is warping to none, it should be deleted.
####### GFX EFFECTS - ENTERING WARP - HERE ###################################
self.TravelerSequence.PlayEngagingWarpSeq()
self.Logger.LogString(" -Extra path: confirmation, she travelled to None")
return 1
-I left it exactly as it was. if you look at the last 'if' - statement it forces the travel sequence to play the sequence before it was even created and so it simply returns after doing nothing^^, so why don't write this routine simply new, no problem but, i had to leave out the 'if CanShipWarp(self.Ship) == 0:' statement wich said 'return 0' when ship is in an asteorid field or a nebula and try it later because i found no way past this with setting someting like 'WarpBlindly' like i think it was called in oreginal bc's AIs.
Maybe this helps good luck on your way to complete your patch, i'll go and try mine on SPinQB as i call it ^^

Offline USS Frontier

  • Posts: 176
  • Cookies: 562
Yup, that is one of the reasons why ships warping to none in GC v1.0 won't work. (the sequence being used before even being created... and some other things)

And the check to see if a ship can warp is done even if the ship is trying to warp to none because if she can't warp, how exactly would she manage to warp somewhere? (even tho warping to None will delete the ship, it still counts as warping somewhere)
And there is no way to ignore that check because it is something that is needed, because like I said, how can a ship warp somewhere if she can't warp? :P

The "WarpBlindly" affects the path the ship will warp out. If warp blindly is 0, and the ship has some kind of obstacle ahead, it will turn around to find a free path to warp out.  If warp blindly is 1, then the ship will simply ignore any obstacles and warp out in the direction she is facing.
"Revenge is a dish best served cold"
                    -Old Klingon Proverb
GravityFX Download
Galaxy Charts Download

Offline cnotsch

  • Posts: 85
  • Cookies: 3
Yup, makes sense, still, in Episode2 Mission 1 the warbird normally warps out completely ignoring anything, meaning for example the asteorid field it is in or the asteorids it is facing towards just to get away fast enough to match with the gameplay... so i had to do something there  8).

Now i got to another problem, again  :oops: :oops:,you know the mission where you have to spy on the marauder class ship called kravis in E2M2, when disabling it's warp engines the AI does not continue so that the marauder stopps attacking, and hails the player, instead it just keeps attacking, if i check manually if the warp engines are down (pShip.GetWarpEngineSubsystem().IsDisabled()) it returns 1, but the conditional AI seems to stay ACTIVE....

Anyone out there who knows a lot about AIs and can help me out here?

Offline cnotsch

  • Posts: 85
  • Cookies: 3
Still noone out here who has an answer?
not too bad it looks like I'll have to wait until the GC Patch is available anyway, so I don't have to start all over again ^^.

Offline MLeo

  • Retired Staff
  • Posts: 3636
  • Cookies: 833
  • Software Simian
    • the Programming Pantheon
I never saw the question for some reason, did you edit your post for that?
In that case, no post notifications are generated when you edit.


It's possible you installed a Marauder mod and now the AI doesn't know where to look?
I still can't read peoples minds, nor can I read peoples computers, even worse, I can't combine the two to read what is going wrong with your BC install...

"It was filed under 'B' for blackmail." - Morse, Inspector Morse - The dead of Jericho.