Bridge Commander Central

BC Forums => BC Scripting => Topic started by: cnotsch on May 22, 2008, 08:00:11 AM

Title: access to directory (nt.listdir(***)) / SinglePlayer in QB & Galaxy Charts
Post by: cnotsch on May 22, 2008, 08:00:11 AM
I tryed to use nt.listdir(***) for "scripts/systems/" but it seems like there is no access because it says "Value Error: not allowed" any idea how to solve this?
Title: Re: access to directory (nt.listdir(***))
Post by: MLeo on May 22, 2008, 01:59:55 PM
Read/Write/List through file access is only allowed on scripts/Custom/ and subdirectories.



You either take all the systems from Foundation (every Systems mod needs to .
Or you have to iterate through them using the Load Save Games "screen". But you can't read nor write to them (reading is possible through some "magic" though).


But it largely depends on what you want to do.


As for the load dialog way:
Code: [Select]
pLoadDialog=App.STLoadDialog_Create(0,0)
pFileMenu = pLoadDialog.GetFileMenu()
pFileMenu.SetFilter("*.*")
pFileMenu.SetDir("data\\Models\\Characters\\" + sName)
pLoadDialog.RefreshFileList()
After that, each child of pFileMenu is a file/directory (including .. and . if I remember correctly).
To read the name you will have to do:
Code: [Select]
pName = App.TGString()
App.STButton_Cast(pChild).GetName(pName)
pName.GetCString()
pName.GetCString() will return the Python usable string.
pChild is a child of pFileMenu (pFileMenu.GetNthChild(#)).
Title: Re: access to directory (nt.listdir(***))
Post by: cnotsch on May 22, 2008, 02:17:15 PM
i just had the idea to replace the sytem config in LoadNanoFX.py with one that does that automatically:
Code: [Select]
def NFXCreateSystemMenues(Directory):
FileList = []
list = nt.listdir(Directory)
for item in list:
s = string.split(item, '.')
sExtension = s[-1]
if sExtension != "py" and sExtension != "pyc":
nDir = string.join(s, '.')
nDir = Directory + nDir
try:
sublist = nt.listdir(string.replace(nDir, '.', '/'))
for subitem in sublist:
subs = string.split(subitem, '.')
subsExtension = subs[-1]
subsPluginName = string.join(subs[:-1], '.')
if subsPluginName != "__init__" and subsExtension == "py":
plugin = string.replace(nDir, '/', '.') + '.' + subsPluginName
module = __import__(plugin)
try:
module.CreateMenus()
except:
pass

except:
pass
Title: Re: access to directory (nt.listdir(***))
Post by: MLeo on May 22, 2008, 02:20:35 PM
JWattsjr and I both, independantly, once created something like that (I believe lost somewhere). It's not hard, there are just 2 edge cases (the Drydock and Starbase 12 systems).

Foundation.systemList ought to get you underway. ;)
Title: Re: access to directory (nt.listdir(***))
Post by: USS Frontier on May 22, 2008, 05:52:16 PM
Yeah but not all systems are listed on the foundation.SystemDefs list. Plus it doesn't contain the real path to the script. Thats one of the reasons I've made the system plugins for Galaxy Charts.

But here's something you can use:  (just a real small and fast test I made in the console and copied the text from the console dump =P)
Code: [Select]
import Systems
####

####
print Systems.__dict__.keys()
['SmokeRing', 'Calufrax', 'Earth', 'Ross_128', 'TheGalaxy', 'Betelgeuse', 'Vesuvi', 'Cebalrai', 'Starbase12', 'Romulus', 'Junkyard', 'Serris', 'Ona', 'Utils', 'Riha', 'Vger', 'Obstacles', 'CJones', 'SystemJ25', 'Tathis', 'Arcturus', 'Pleides', 'Cardassia', 'Biranu', 'Vatris', 'Albirea', 'Nursery', 'Alioth', '__name__', 'Borealis', 'KavisAlpha', 'Voltair', 'Itari', 'DeepSpace9', 'Ascella', 'Prendel', 'ArenaA', 'Baqis', 'Badlands', 'Universe', 'Poseidon', 'PsiBlackhole', 'OmegaDraconis', '__doc__', 'Beol', 'Kastra', 'Comet', 'Kronos', 'Vulcan', 'Procyon', 'BeyondTheGalaxy', 'Void', 'Fluid', 'QuickBattle', 'XiEntrades', 'Belaruz', 'Yiles', 'Sol', '__builtins__', 'String', 'DeepSpace', 'Sirius_B', 'DryDock', 'Khan', 'GasGiant', 'Nepenthe', 'BriarPatch', 'Tezle', 'GammaQuadrant', 'Artrus', '__path__', 'Tevron', 'Banzai', 'Geble', 'RedGiant', 'Chambana', 'Wolf359', 'ShakedownCruise', '__file__', 'Hekaras', 'GalaxyEdge', 'Canopus', 'Savoy', 'Rainbow', 'FoundationUtils']
####

####
print Systems.__dict__['Calufrax'].__dict__.keys()
['__path__', '__doc__', 'Calufrax3', '__file__', '__name__', '__builtins__']
####

####
print Systems.__dict__['Belaruz'].__dict__.keys()
['__path__', '__doc__', 'Belaruz4', '__file__', '__name__', '__builtins__']
####

####
print Systems.__dict__['Belaruz'].__dict__['Belaruz4'].__dict__.keys()
['GetSetName', '__doc__', 'Terminate', 'App', '__name__', 'Initialize', '__file__', '__builtins__', 'LoadPlacements', 'GetSet', 'LoadBackdrops']
That way you can go looping thru each script and each of it's variables, and if they have "CreateMenus", use them.
Problem is, i think python only starts listing the scripts in the __dict__ of the parent directory when they have been initialized.

Dunno if this can really help out or not since i'm kinda in a hurry here, but at least it's something to think about.
Title: Re: access to directory (nt.listdir(***))
Post by: MLeo on May 22, 2008, 06:01:38 PM
It doesn't even have to list them. And it will only list them after you have imported them.


True, the systemList elements don't list those information directly, what they do is (at the very least) provide a convention.
If you prepend the name with "System." then you can import it.
Also, the number of systems (min/max) also tell you the the range of numbers you can expect to be there.

It's not as if QuickBattle can do anything but adhere to this convention anyway (please don't break it).

Say, you want to import the second Serris set, well, it's name is Serris, so System.Serris. then you want the second one, so you __import__("System.Serris.Serris2")
Title: Re: access to directory (nt.listdir(***))
Post by: cnotsch on May 23, 2008, 06:41:49 AM
Thanks I'll try that out sometime soon but I got many things to do for school the next time so it may take some time till I continue my projects  :x :x :x
Title: Re: access to directory (nt.listdir(***))
Post by: MLeo on May 23, 2008, 01:25:14 PM
USS Frontier, interrested in continueing the discussion of the better System format? ;P
Title: Re: access to directory (nt.listdir(***))
Post by: USS Frontier on May 24, 2008, 03:23:03 AM
Of course! A friendly and constructive discussion is always welcomed. That's how ideas are born and problems are solved =P   (or at least one of the ways to do that)

But i'll reply about it tomorrow... It's really late here and I want to go to the bed :P

EDIT:
Personally I think the system plugins (along with GC) are a better format (that's kinda obvious right :P). They are much more flexible/dynamic than the SystemDefs and can contain a LOT more info about the systems. And with the plugin creation tool they aren't hard to make.
Plus they are used for a bunch of stuff, while the SystemDefs are there only to add the systems to the QuickBattleSetup System List.
And using the QB setup to create a battle simulation is something that with KM1+GC is kinda useless, since when you just started the QB mode (didn't setup a battle yet), you can already warp with no problems to anywhere, and using AddShips you can add the ships you want in the group that you want.
Title: Re: access to directory (nt.listdir(***))
Post by: cnotsch on May 25, 2008, 05:17:35 AM
i know, it was just a idea out of lazyness to let a script automatically load new installed ships, so don't get too busy with finding a way to do this.

I'm currently trying to port the SP - missions into QB and I succesfully portet the first Episode already, but I got to a problem in E2M0: When creating a WarpAI with no set and no placement the ship turns into a direction to warp but then simply stays there and does nothing. when loading the "Zhukov" with loadspacehelper.createship with the set as well as her starting nav-point set, the game crashes, it works when leaving the nav-point name clear

Code: [Select]
loadspacehelper.CreateShip("Ambassador", pSet, "Zhukov", "", 1)
Any Ideas?

If letting her warp to Starbase12 with the sovereign the sovereign stays there and the zhukov returns to me and follows me everywhere i warp. setting a new AI after arriving in Sb12 changes nothing, so i tried assigning the AI manual to a manually created zhukov (manually -> i mean by console) and it works ???
i solved thisone by destroying her when she enters Sb12  :lol:

Any better Ideas?

NOTE: I use GalaxyCharts
Title: Re: access to directory (nt.listdir(***))
Post by: MLeo on May 25, 2008, 06:58:57 AM
Any newly installed ships will already be known to BC through Foundation.shipList


As for the navpoints, lots of missions declare mission only navpoints or even a custom placements for a system, look in the mission directory for <<systemName>>_P.py for their custom placements.


Also, did you know that QB is just another mission of itself?
Title: Re: access to directory (nt.listdir(***))
Post by: cnotsch on May 25, 2008, 09:28:38 AM
Also, did you know that QB is just another mission of itself?

Shure this is exactly my intention. Look, If I'd try to make every mod I like SP-compatible i woult take years and there are coming more and more so why not trasform SP int o plugin for QB?
Doing so I reach nearly the same mod compatibility in SP as in QB - and I have the work only once...

As for the navpoints, lots of missions declare mission only navpoints or even a custom placements for a system, look in the mission directory for <<systemName>>_P.py for their custom placements.

I know that is what i thaught first too : There is no such navpoint;
BUT, they are there I'm sure and exactly that seems to be the problem. It also works when I set the placementname to "hithisisblabla" - thats the weird thing.

In the meantime I got an Idea for the WarpOut AIs: A sequence tha does the following:
1. PlainAI-RunScript:               Create the Set "DeepSpace" if it does not exist yet      - works
2. PlainAI-Warp:                     Warp to "DeepSpace"                                              - works, i think
3.(version1) PlainAI-RunScript: pShip.SetDeleteMe(1)                                              - does its job the ship dissapears, BEFORE warping
3.(version2) ConditionalInSet:  with the parameters: pShip.GetName(), "DeepSpace" and 3.(version1) as child;  - results in an instant crash of stbc.exe  :? :? :?
Title: Re: access to directory (nt.listdir(***))
Post by: MLeo on May 25, 2008, 09:46:07 AM
I'm not well versed in BC AI code, so I can't really help you there.


As for your E2M0 issue, if a ship warps to no destination, then it ought to warp out and then be removed (deleted). Maybe Galaxy Charts didn't replicate this?

And the Tevron System does have a ZhukovStart navpoint, atleast in the mission specific placements file.
Title: Re: access to directory (nt.listdir(***))
Post by: cnotsch on May 25, 2008, 11:47:58 AM
Quote
There is no such navpoint
sorry i may have not been clear enougth there; This should be my idea but if you are looking into the next line i wrote that they are there;
I wanted to say i can use any navpointname exept the existing ones  :? :? :? -> it HAS to be an invalid navpoint...
Title: Re: access to directory (nt.listdir(***))
Post by: MLeo on May 25, 2008, 12:00:46 PM
Quote
There is no such navpoint
Yes, I thought that was what I read....


Now you read.

I must be blind having read that it says ZhukovStart. -_-
Title: Re: access to directory (nt.listdir(***))
Post by: Mark on May 25, 2008, 05:03:37 PM
ok guys, lets stay focused on the problem at hand..
Title: Re: access to directory (nt.listdir(***))
Post by: cnotsch on May 25, 2008, 07:44:39 PM
sorry there mark, but i want to sort that out i don't want to make anyone angry here!

From my side it was like that:
I wrote my scripts the i got to that weird crashing thing with the zhukov.
Then i THAUGHT there might be no navpoint and for that reason the game crashes.
So i checked this about 10 times everytime with the result there must be a navpoint.
Next i tried setting the placement name to something else wich does not exist.

So i posted that.
Quote
I know that is what i thaught first too : There is no such navpoint;
BUT, they are there I'm sure and exactly that seems to be the problem. It also works when I set the placementname to "hithisisblabla" - thats the weird thing.

Now you told me:
Quote
And the Tevron System does have a ZhukovStart navpoint, atleast in the mission specific placements file.

So i thaught you understood my post as "i still think there is no navpoint" and i wanted to be shure you understood me...

see the problem? i hope you aren't mad  :(

I'm really grateful for your help don't get that wrong.

besides that it was a nice idea with that pic  :lol:

Title: Re: access to directory (nt.listdir(***))
Post by: USS Frontier on May 25, 2008, 11:32:09 PM
The <Ship warping to NONE and being left at the set (that is, not being removed)> is a known bug in GC and has already been fixed in the upcoming patch.

Also GC checks and creates the destination set if it needs, so there is no need for you to do that =P


Now about the placement/navpoint thing I won't say anything because personally I didn't understand what you said  :?
Title: Re: access to directory (nt.listdir(***))
Post by: cnotsch on May 26, 2008, 12:29:14 AM
Quote
The <Ship warping to NONE and being left at the set (that is, not being removed)> is a known bug in GC and has already been fixed in the upcoming patch.
good to hear. there is also the problem that when entering a set after warp you drop out of warp ~1000km from the center planet - did you consider to fix that too?
so lets say the ship enters as near as possible to "Player Start"?
that would make my work a lot easier.
Title: Re: access to directory (nt.listdir(***))
Post by: USS Frontier on May 26, 2008, 06:56:08 PM
there is also the problem that when entering a set after warp you drop out of warp ~1000km from the center planet - did you consider to fix that too?
so lets say the ship enters as near as possible to "Player Start"?
that would make my work a lot easier.
Actually I didn't consider that =P
But it can be arranged as well. I'll see what I can do.

But for the moment, here's something you can do to easily change the location where the player drops out of warp:
Code: [Select]
pPlayer = App.Game_GetCurrentPlayer()
vPosition =  **the point in space (App.TGPoint3 obj) where you want the player to drop out**
pTravel = App.g_kTravelManager.GetTravel(pPlayer)
if pTravel != None:
pTravel.SetExitLocationVector(vPosition)
If that position is empty, the player will drop out of travel there. If there is some kind of obstacle there, GC will pick up a new exit position close to that one that is free.
Note that this code will only work if GC is installed, since the Travel Manager is from GC.

Also in your version of GC (v1.0, because in the patch this aspect is changed), the Travel instance of the player will only be created when he tries to travel. So the best thing to do is listen for a START_WARP_NOTIFY event, and if it's from the player, use the code in the example above to change his exit location.
OR instead of using that "GetTravel" method you can use "CreateTravel", to create the player's travel instance, and then set his exit location. Don't worry doing this since it won't cause any problems, and the exit location will be stored until the player exits warp and uses it  (that is if nothing else changes it. I don't remember exactly but I think some AIs change the exit location, that's why I gave the example of the START_WARP_NOTIFY event, since at that point probably nothing will change that attribute)
Title: Re: access to directory (nt.listdir(***))
Post by: cnotsch on May 26, 2008, 11:55:48 PM
thanks ill try it out asap.
Title: Re: access to directory (nt.listdir(***))
Post by: cnotsch 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:
Title: Re: access to directory (nt.listdir(***))
Post by: USS Frontier 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)
Title: Re: access to directory (nt.listdir(***))
Post by: cnotsch 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?
Title: Re: access to directory (nt.listdir(***))
Post by: MLeo 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?
Title: Re: access to directory (nt.listdir(***))
Post by: cnotsch 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:)
Title: Re: access to directory (nt.listdir(***))
Post by: USS Frontier 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.
Title: Re: access to directory (nt.listdir(***)) / SinglePlayer in QB & Galaxy Charts
Post by: cnotsch on May 30, 2008, 04:38:45 AM
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
Title: Re: access to directory (nt.listdir(***)) / SinglePlayer in QB & Galaxy Charts
Post by: cnotsch on May 30, 2008, 03:46:14 PM
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*
Title: Re: access to directory (nt.listdir(***)) / SinglePlayer in QB & Galaxy Charts
Post by: MLeo on May 30, 2008, 06:04:55 PM
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. ^_^'
Title: Re: access to directory (nt.listdir(***)) / SinglePlayer in QB & Galaxy Charts
Post by: USS Frontier on May 30, 2008, 07:48:16 PM
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.........
Title: Re: access to directory (nt.listdir(***)) / SinglePlayer in QB & Galaxy Charts
Post by: cnotsch on June 05, 2008, 07:16:59 AM
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...
Title: Re: access to directory (nt.listdir(***)) / SinglePlayer in QB & Galaxy Charts
Post by: USS Frontier on June 05, 2008, 09:52:48 PM
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.
Title: Re: access to directory (nt.listdir(***)) / SinglePlayer in QB & Galaxy Charts
Post by: cnotsch on June 06, 2008, 04:49:38 PM
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?
Title: Re: access to directory (nt.listdir(***)) / SinglePlayer in QB & Galaxy Charts
Post by: USS Frontier on June 07, 2008, 09:34:43 PM
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.
Title: Re: access to directory (nt.listdir(***)) / SinglePlayer in QB & Galaxy Charts
Post by: cnotsch on June 08, 2008, 07:15:39 AM
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 ^^
Title: Re: access to directory (nt.listdir(***)) / SinglePlayer in QB & Galaxy Charts
Post by: USS Frontier on June 08, 2008, 12:18:19 PM
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.
Title: Re: access to directory (nt.listdir(***)) / SinglePlayer in QB & Galaxy Charts
Post by: cnotsch on June 08, 2008, 12:54:31 PM
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?
Title: Re: access to directory (nt.listdir(***)) / SinglePlayer in QB & Galaxy Charts
Post by: cnotsch on June 15, 2008, 10:26:40 AM
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 ^^.
Title: Re: access to directory (nt.listdir(***)) / SinglePlayer in QB & Galaxy Charts
Post by: MLeo on June 15, 2008, 01:36:33 PM
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?
Title: Re: access to directory (nt.listdir(***)) / SinglePlayer in QB & Galaxy Charts
Post by: cnotsch on June 15, 2008, 02:59:01 PM
no i didn't add my question afterwards.

what do you mean it does not know where to look?
it works fine in SP;
i gets passed the shipclass-pointer pShip;
it works in QB with the marauder and any other ship wich has warp engines;
it does work in the console  :?;
it does not work in SPinQB  :(

the conditional AI:
Code: [Select]
#########################################
# Creating ConditionalAI WarpEnginesNotDisabled at (302, 287)
## Conditions:
#### Condition WarpDisabled
pWarpDisabled = App.ConditionScript_Create("Conditions.ConditionSystemDisabled", "ConditionSystemDisabled", pShip.GetName(),  App.CT_WARP_ENGINE_SUBSYSTEM, 1)
## Evaluation function:
def EvalFunc(bWarpDisabled):
ACTIVE = App.ArtificialIntelligence.US_ACTIVE
DORMANT = App.ArtificialIntelligence.US_DORMANT
DONE = App.ArtificialIntelligence.US_DONE
if bWarpDisabled:
return DONE
return ACTIVE
## The ConditionalAI:
pWarpEnginesNotDisabled = App.ConditionalAI_Create(pShip, "WarpEnginesNotDisabled")
pWarpEnginesNotDisabled.SetInterruptable(1)
pWarpEnginesNotDisabled.SetContainedAI(pPriorityList)
pWarpEnginesNotDisabled.AddCondition(pWarpDisabled)
pWarpEnginesNotDisabled.SetEvaluationFunction(EvalFunc)
# Done creating ConditionalAI WarpEnginesNotDisabled
#########################################

it is assigned with that line:
Code: [Select]
pMarauder.SetAI(E2M2_AI_MarauderRun.CreateAI(pMarauder, fSpeed))

i've attached the whole AI in case you want to take a look at it
Title: Re: access to directory (nt.listdir(***)) / SinglePlayer in QB & Galaxy Charts
Post by: MLeo on June 15, 2008, 03:01:01 PM
How do you mean it works?
Why say it doesn't if it does?

I meant, maybe the AI doesn't know where to look for the warp engines.
Title: Re: access to directory (nt.listdir(***)) / SinglePlayer in QB & Galaxy Charts
Post by: cnotsch on June 15, 2008, 04:06:09 PM
i said meant it works everywhere (in QB assigned to any ship with WEngines, in the normal SP mission, ...) except in SPinQB (my mod)

how it works? without that problem:  :wink:
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....

meaning the AI works till the end and calls the script action
Title: Re: access to directory (nt.listdir(***)) / SinglePlayer in QB & Galaxy Charts
Post by: MLeo on June 15, 2008, 06:35:42 PM
Are you sure you have managed to attach all the required events?
Title: Re: access to directory (nt.listdir(***)) / SinglePlayer in QB & Galaxy Charts
Post by: cnotsch on June 15, 2008, 07:00:07 PM
I could control that from the main script with events yes, but normally all script actions are called by the AIs and there ate no events. This just drives me crazy that i have to rewrite nearly the whole mission just because of these silly little problems...
Title: Re: access to directory (nt.listdir(***)) / SinglePlayer in QB & Galaxy Charts
Post by: MLeo on June 15, 2008, 07:02:44 PM
Well, it would appear that the AI is only part of it. There is also a weapon fire event in the mission itself.



[EDIT] It would appear to be easier to have a better, and more uniform, mission select menu that handles Foundation correctly for everything.