[LIB] Find Hub of station

The place to discuss scripting and game modifications for X³: Terran Conflict and X³: Albion Prelude.

Moderators: Moderators for English X Forum, Scripting / Modding Moderators

Post Reply
User avatar
s9ilent
Posts: 2033
Joined: Wed, 29. Jun 05, 01:45
x4

[LIB] Find Hub of station

Post by s9ilent » Mon, 26. Jan 09, 09:23

A basic lib pack for telling if a station is in a hub (true/false?), and what hub a station is in.



[ external image ] stat_hub_check
Hub/Station Checks
stat_hub_check.zip


2 Scripts
lib.stat.findhub
-NO args. Finds the hub that the THIS (station,factory) is attached to. Returns the Hub. Otherwise if there is no hub, then it returns null.

lib.stat.hubsinsect
-1 Arg: sector. Returns an array of all the hubs in a sector, or zero if there aren't any.



As a note, Garbage in garbage out. These are low level lib scripts so there are no error checks
Make sure THIS, is indeed a station.








***old junk below here****
This script doesn't seem that fantastic.. but .. it used to be super complex as I had no idea how to do it and I did some wierd round about way of doing it. But then Gazz is like: Use this command. bang done. So yep.. just the one script now...

*Final note, I removed the , checkinhub
Simply because its a one liner

if not $station docking is possible $smallship (a small ship, or m6 ship, not an object class, but an actual object)
is a station in a hub (not the hub it self thou)
else
is not
endif

The small ship has to be able to land on a station in the first place. And getting a small ship via generic searches are probably as CPU consuming as the findhub command. (The former loops through all sector ships in X3 till it finds a match, the other loops through all stations until it finds a match)
Last edited by s9ilent on Mon, 4. May 09, 03:22, edited 8 times in total.

User avatar
Gazz
Posts: 13244
Joined: Fri, 13. Jan 06, 16:39
x4

Re: [LIB] Hub/Station Checks

Post by Gazz » Mon, 26. Jan 09, 11:18

s9ilent wrote:If it can't find a match (i.e. Its not in a hub) it returns null. The other script is more efficient (I think.... is the search command efficient?) for checking if a station is in a hub or not
If you want to make certain a station is a hub use

= get station array from sector $Hub

If you get results it's a real active hub and then you also get the stations it contains.
Scripts can create a hub without a complex (for whatever reason) so the above way is the only one to make sure.
Last edited by Gazz on Mon, 26. Jan 09, 11:21, edited 1 time in total.
My complete script download page. . . . . . I AM THE LAW!
There is no sense crying over every mistake. You just keep on trying till you run out of cake.

User avatar
s9ilent
Posts: 2033
Joined: Wed, 29. Jun 05, 01:45
x4

Post by s9ilent » Mon, 26. Jan 09, 11:20

Gazz :( I wish I knew that.. like 3 days ago....

*edit*
Wait Gazz, I just tried it, it returns null when I use it on a hub?

Wait.. it works.. just not as I expected.. or.. well strangely.. Ill test it out properlly
Last edited by s9ilent on Mon, 26. Jan 09, 11:27, edited 1 time in total.

Logain Abler
Posts: 2255
Joined: Mon, 31. Oct 05, 08:44
x4

Re: [LIB] Hub/Station Checks

Post by Logain Abler » Mon, 26. Jan 09, 11:26

s9ilent wrote:A basic lib pack for telling if a station is in a hub (true/false?), and what hub a station is in.



[ external image ] stat_hub_check
Hub/Station Checks
stat_hub_check.zip


4 Scripts
  • lib.stat.checkinhub.findsmall -No args. Returns a small ship (required for checkinhub), just any small ship from the entire universe owned by anyone
  • lib.stat.checkinhub -Arg1: a smallship (Any one's any where, use the above if you can't get one). Run on the station your enquiring about. Returns TRUE if THIS is in a hub, returns FALSE if it isn't
  • lib.stat.findhub -NO args. Finds the hub that the THIS (station,factory) is attached to. Returns the station, if multiple matches, returns an array of stations, if no matches, returns null
  • lib.stat.findhub.single -Same as above, but will return the first result, or null (not an array if 2+ results)

As a note, Garbage in garbage out. These are low level lib scripts so there are no error checkers.
N.B. If I say small ships, I actually mean obj class "littleships"
N.B. Complex Hubs are considered to be obj class Complex Hubs, which is a subset of Factories

1. The first script can only fail if there are no flying smallships in the universe. Failure return = null.
(At least I think flying ships don't show up on generic ship searches.. I Could be wrong thou)

2. The second script, make sure that the smallship does exist, and is indeed a small ship, and that THIS is a valid station (factory).
It works by checking if $smallship can dock at THIS. (If not, is hub)
So obviously complex hubs, docks, shipyards, carriers etc. will return false.
If THIS is a ship or something undockable, it will return true. Garbage in Garbage out

3. The third script, make sure THIS is a valid station (factory), and is actually in a hub (other wise ret = null, the other script is better for checking thou.. I think at least.. I have no idea how Egosoft's ship search works).
This script works by checking the current ware quantity and the max quantity of all hubs in THIS's sector, against THIS's current and max quantities.
It can be fooled if you have 2 identical complexes, in which case it will return an array containing both.
If it can't find a match (i.e. Its not in a hub) it returns null. The other script is more efficient (I think.... is the search command efficient?) for checking if a station is in a hub or not
Sounds interesting will have a look.

I hit this issue in my FDN mod/script.

I solved it as follows.

1) Check the is detectable settings as this changes if the factory is part of the Hub
2) Check the Product and level of the factory to see if it’s the same as the Hub. Both Hub & Factory will return the same value on the level of a ware.
3) Check distance of between Hub & Factory.

The above is what I use to group Factories under Complexes as below:

[ external image ]

Was a complete bitch to get right! Strange there’s no inbuilt script command to do it.


LA

User avatar
s9ilent
Posts: 2033
Joined: Wed, 29. Jun 05, 01:45
x4

Post by s9ilent » Mon, 26. Jan 09, 11:31

I don't like distance checking as you can build them upto 35km away (i think.. a long way a way any way) and if you make 2 hubs and connect those, and then those 2 hubs are 35km away, then you can effective get 75km, and so on and so forth

(I linked up all the high yield roids in Ore belt like that... lagged like... well alot thou.. all those pipes... and I think I lost a few hubs to collisions (with the M2 or the roids.. I can't remember)

*Edit* Gazz's way doesn't work, it just returns null




GAH!!!!


Gazz was half right


Get FACTORY array from sector

Does work like a charm <3
Last edited by s9ilent on Mon, 26. Jan 09, 11:38, edited 1 time in total.

Logain Abler
Posts: 2255
Joined: Mon, 31. Oct 05, 08:44
x4

Re: [LIB] Hub/Station Checks

Post by Logain Abler » Mon, 26. Jan 09, 11:35

Gazz wrote:
s9ilent wrote:If it can't find a match (i.e. Its not in a hub) it returns null. The other script is more efficient (I think.... is the search command efficient?) for checking if a station is in a hub or not
If you want to make certain a station is a hub use

= get station array from sector $Hub
It does not work, it returns null :(

I've tried that in X3:R and TX:TC and I've never been able to get it to work.


LA

User avatar
s9ilent
Posts: 2033
Joined: Wed, 29. Jun 05, 01:45
x4

Post by s9ilent » Mon, 26. Jan 09, 11:39

(JUst in case you didn't see my edit to the above post -i edited it like... 7 times??? so it might've changed a bit)

<retvar> = <value i.e the hub your checking> Get factory array from sector


It only works with the factory one, not the sector one.

Logain Abler
Posts: 2255
Joined: Mon, 31. Oct 05, 08:44
x4

Post by Logain Abler » Mon, 26. Jan 09, 11:41

s9ilent wrote:I dont like distance checking as you can build them upto 35km away (i think.. a long way a way any way) and if you make 2 hubs, and then those 2 hubs are 35km away, then you can effective get 75km, and so on and so forth
I've set the distance to something really stupid, like 1000000. Not even sure if it's needed, just that it works :wink:

I could send you the file if your interested, it's not pretty but it's always good to get another view :?:
s9ilent wrote: *Edit* Gazz's way doesn't work, it just returns null
Beat me to it :)


LA

Logain Abler
Posts: 2255
Joined: Mon, 31. Oct 05, 08:44
x4

Post by Logain Abler » Mon, 26. Jan 09, 11:49

s9ilent wrote:(JUst in case you didn't see my edit to the above post -i edited it like... 7 times??? so it might've changed a bit)

<retvar> = <value i.e the hub your checking> Get factory array from sector


It only works with the factory one, not the sector one.
D'oh :!: Now I get it :idea:

User avatar
Gazz
Posts: 13244
Joined: Fri, 13. Jan 06, 16:39
x4

Post by Gazz » Mon, 26. Jan 09, 11:52

s9ilent wrote:Gazz was half right
Get FACTORY array from sector
Does work like a charm <3
Uhh, err... just keeping you on your toes y'know!
My complete script download page. . . . . . I AM THE LAW!
There is no sense crying over every mistake. You just keep on trying till you run out of cake.

User avatar
s9ilent
Posts: 2033
Joined: Wed, 29. Jun 05, 01:45
x4

Post by s9ilent » Mon, 26. Jan 09, 11:55

<3 Gazz

Although... I needed this script like 5 days ago... and it's taken me this long to figure it out.. I don't actually remember what I needed it for any more :S
(Well... 5 days to figure it out sort of right.. and then for Gazz to tell us the answer)

Logain Abler
Posts: 2255
Joined: Mon, 31. Oct 05, 08:44
x4

Post by Logain Abler » Mon, 26. Jan 09, 12:03

s9ilent wrote:<3 Gazz

Although... I needed this script like 5 days ago... and it's taken me this long to figure it out.. I don't actually remember what I needed it for any more :S
(Well... 5 days to figure it out sort of right.. and then for Gazz to tell us the answer)
I know, I lost could of the hours I spent on this. Now I'll be able to cut the code down by about 80 lines :!:

:lol: Cheers Gazz

User avatar
Gazz
Posts: 13244
Joined: Fri, 13. Jan 06, 16:39
x4

Re: [LIB] Find Hub of station

Post by Gazz » Mon, 26. Jan 09, 12:12

s9ilent wrote:*Final note, I removed the , checkinhub
Simply because its a one liner
if not $station docking is possible $smallship (a small ship, or m6 ship, not an object class, but an actual object)
is a station in a hub (not the hub it self thou)
Well.... if you use if docking allowed it works independant of ship class or free docking slots so you can always reference PLAYERSHIP and don't need to find a ship first.
if docking possible returns a diffuse result.

So if docking allowed directly tells you if the station is in any complex or not.

Okay, with AI stations it has notoriety/relation implications but not for your purposes...
My complete script download page. . . . . . I AM THE LAW!
There is no sense crying over every mistake. You just keep on trying till you run out of cake.

User avatar
s9ilent
Posts: 2033
Joined: Wed, 29. Jun 05, 01:45
x4

Post by s9ilent » Mon, 26. Jan 09, 12:30

The ship has to be a small ship/m6 (not big ship)

Pretty much, a station in a hub, can not be docked at (But big ships already can't dock at them so it give null)

User avatar
Gazz
Posts: 13244
Joined: Fri, 13. Jan 06, 16:39
x4

Post by Gazz » Mon, 26. Jan 09, 13:09

s9ilent wrote:The ship has to be a small ship/m6 (not big ship)

Pretty much, a station in a hub, can not be docked at (But big ships already can't dock at them so it give null)
If all docking clamps are all full then docking possible returns null for any ship.
What did you do in case number of free docking bays == 0 ?


Anyway, if I may be so bold as to sug... ahwell. I'll do it anyway!
Some useful possible features:

One script argument.

1) If it's object_ class_sector, the return is null or an array of all active hubs in the sector.
Always null or an array, even if it's only 1 hub.
A find may not guarantee that you get them all and that they are actual hubs but mostly this is a good start for the other functions:

2) If the argument is a vartype_array (sector position) the return is null or the hub closest to this position in the sector.
(for extra trickiness the library can call itself with option 1) to get the hubs in sector first)

3) If the argument is object_ class_factory the return is null or the "master" hub of this factory
(for extra trickiness the library can call itself with option 1) to get the hubs in sector first. That's what libraries are for! =)


Checking if a particular station is a hub or if a particular factory is in a complex are pretty much one liners so no need for a library there.

Using THIS as the argument may sound good but will often be undesirable because you have to start the task on that object and that implies that you have found a free task to run it on.
If you connect a factory to a complex all running scripts on it are killed which further complicates this.
Save yourself the headaches and supply THIS as an argument when apropriate.
My complete script download page. . . . . . I AM THE LAW!
There is no sense crying over every mistake. You just keep on trying till you run out of cake.

User avatar
s9ilent
Posts: 2033
Joined: Wed, 29. Jun 05, 01:45
x4

Post by s9ilent » Mon, 26. Jan 09, 20:44

A free task isn't required unless you use START, other wise it just runs silently in the background.
(Isn't it? as I always run global tasks running on the playership (whilst I'm running Standby on task 0) and it never interupts the task)
I'll give it a test, but I've never had issues with THIS failing before.



After a bit of testing, calling scripts (with out tasks) on different objects, runs on task id -1, and you can have infinite? separate scripts running on it.

My test was..
temp1:
PLAYERSHIP-> call: temp2
ret null

Temp2
wait 7000
$task get taskid
logbook $task
logbook $this
ret null

Then I ran temp1 globally twice (right after each other)

7 seconds later, I've got two sets of
-1
Argon Nova






Next, Is docking possible doesn't count docking slots, nor race relations, it just checks whether the $dock, is physically capable of ever docking $ship. Although... for unknown reasons... it requires an actual ship and not an object class...

User avatar
Gazz
Posts: 13244
Joined: Fri, 13. Jan 06, 16:39
x4

Post by Gazz » Mon, 26. Jan 09, 21:07

That's true but why do I want to find out which hub PLAYERSHIP is connected to?

There must be a task running on the station or you have no THIS.
That would be the task calling the library "without a task".

If I have to write a special script that does nothing but run on the station just so I can call this library and then I have to find a free task on the station everytime I wish to use my special script...
That's a bit of an unusual effort for using a library.
Normally you call them, tell them what you want and get a result.
My complete script download page. . . . . . I AM THE LAW!
There is no sense crying over every mistake. You just keep on trying till you run out of cake.

User avatar
s9ilent
Posts: 2033
Joined: Wed, 29. Jun 05, 01:45
x4

Post by s9ilent » Mon, 26. Jan 09, 21:13

No no no, for example, one of my menu's ran on a ship, needs to create a list of stations and hubs (but not stations in a complex).




So
From the ship (THIS is currently the "ship")
$sta.list Get array of stations in sector [SECTOR]
loop through stations
$sta= $sta.list[count]
$sta-> call script: xxxxxxxxxx (rather than THIS-> call script xxxx arg1: $sta)
...
end


Now from the $sta call script: xxxxxxxxxx
THIS, is the $sta, but it doesn't uses any tasks on the $sta, but rather its tied into the original THIS ($ship). So if the $ship dies, the entire script terminates. It's essentially a way of passing a free argument for the reference object. (But your actually always forced to pass it, just that typically it's THIS)

Although I'm not 100% sure what happens when the station dies, I think it auto-returns null, but considering there are no interupts in this (and this doesn't kill it) it can't happen.




I implemented your idea for.... List hubs in sector, but not find closest hub to position, as you can use one of the generic station search commands to do that. Although its in a separate script. (for limiting cpu-ness)

Post Reply

Return to “X³: Terran Conflict / Albion Prelude - Scripts and Modding”