Skip to content

Instantly share code, notes, and snippets.

@Brianetta
Created March 5, 2012 23:20
Show Gist options
  • Save Brianetta/1981938 to your computer and use it in GitHub Desktop.
Save Brianetta/1981938 to your computer and use it in GitHub Desktop.

Sent: Monday, 05 March, 2012 at 9:45 pm by Brianetta

Benamucki wrote:Hi Brian,

by adding a "break" in those loops you no longer get the minimum and therefore fair price, the calculation of "due" is also broken. These features were actually the intention of the script.

I missed that; you have a lot of very tight logic in there.

The LocalCtr loop does not produce much load. The ExternalCtr loop does produce some load. For that reason I tried to speed up the spath calculation by limiting the radius of the sphere which contains nearby systems. In NearBySystems:init() you can reduce maxSystems.

I put the break in both loops for maintainability. If they continue to resemble each other, there's less to understand.

The load on this loop was extraordinary. On my netbook, it was causing the game to freeze for a second and a half at a time. It would probably be better to generate a bunch of potential ships and destinations at onGameStart and at onEnterSystem, and cache the results as a table indexed by minimum time and destination.

Sent: Monday, 05 March, 2012 at 9:18 pm by Benamucki

Hi Brian,

by adding a "break" in those loops you no longer get the minimum and therefore fair price, the calculation of "due" is also broken. These features were actually the intention of the script.

The LocalCtr loop does not produce much load. The ExternalCtr loop does produce some load. For that reason I tried to speed up the spath calculation by limiting the radius of the sphere which contains nearby systems. In NearBySystems:init() you can reduce maxSystems.

Sent: Saturday, 03 March, 2012 at 11:40 am by Benamucki

A great way to display a system path would be to show it in the star system map. To do that you need an API function which accepts a path. You could attach a timestamp to each node and the display method could fade in or out lines between nodes, e.g. by varying the saturation of the path. The path of the flight log for instance could be greyed out and disappears in the past whereas the calculated delivery path disappears in the future. With time forward/backward buttons similar to those in the planet map you could even visit past and future nodes. Further information passed to the function could be displayed along the path. In order to display serveral paths simultaneously you may assign an unique colour to each and create a legend.

Sent: Saturday, 03 March, 2012 at 12:11 am by Brianetta

Unfortunately, aside from UI.Message() and its brother, you only have the BB and the mission screen. robn is rewriting the UI from scratch right now, so things will get better.

Sent: Friday, 02 March, 2012 at 11:46 pm by Benamucki

I will use the character class next time, Brian.

Thanks for the kudos! It's funny, sometimes you just arrive in time because "due" is rounded up. Even if you are too late you will get some money. The amount paid is related to the urgency factor.

The script also updates the adverts of local jobs. Wait and you can earn more money as less ships will make it in time.

Currently the script does not use the urgency parameter for non-local jobs other than in the calculation of the reward of delayed deliveries. The console displays the best route and the fuel needed. Would be cool to display such information in the mission screen. Is this possible?

I love the idea of the FlightLog! We need a way to display it somehow.

Sent: Friday, 02 March, 2012 at 8:47 pm by Brianetta

Hi Benamucki,

I've made a pull request against your script: pioneerspacesim/pioneer#1041

Briefly, we have a Character class in the game already, so I've replaced the one you defined with ours. You might like to use it in any future scripts.

NaturalDocs documentation is here: http://eatenbyagrue.org/f/pioneer/coded ... s-lua.html

The Wiki page describing the class is here: https://github.com/pioneerspacesim/pion ... nteraction

It's a very lightweight class, inheriting methods and attributes that don't exist, and the serializer is already aware of it, meaning that it saves nicely.

Incidentally, check out data/libs/Characters.lua for an example of how to do that, because I don't think it's properly documented yet. Define class in a class's metatable, and give the class itself Serialize and Unserialize methods; then the serializer will make sure that those two functions are run at save and load.

Your script, by the way, is great. I took on an urgent delivery to Poseidon (local, 30AU) for 500Cr. Stripping my Eagle down to absolutely nothing but the autopilot, I made it with about 15 minutes to spare. I loved that I had the opportunity, but without making those radical changes to my ship I wouldn't have completed it on time. Kudos for that.

Sent: Thursday, 01 March, 2012 at 9:32 pm by Brianetta

Benamucki wrote:That's great, Brian! It's a good idea to add some functions to the API. Usually you do not have a ship object and thus you cannot call its methods.

If you ever need something exposing through the API to make your script better, either log an issue or let me know, and I'll log it for you. The API's design is driven by script requirements, and script development is really only just getting started.

Please use Benamucki as author, hope that's okay?!

It's fine. If you ever want a real name on there in future, do let us know.

Sent: Thursday, 01 March, 2012 at 8:07 pm by Benamucki

That's great, Brian! It's a good idea to add some functions to the API. Usually you do not have a ship object and thus you cannot call its methods.

Please use Benamucki as author, hope that's okay?! That's great, Brian! It's a good idea to add some functions to the API. Usually you do not have a ship object and thus you cannot call its methods.

Please use Benamucki as author, hope that's okay?!

Sent: Thursday, 01 March, 2012 at 9:28 am by Brianetta

Your script got merged, and will make alpha 20, where it can get some play-testing. We saw that you rewrote the hyperspace range and duration calculations in Lua, and the devs are now working on changing things in core such that these only have to exist in one place. Those calculations have been re-balanced before now. So, thanks for that.

We were wondering how you'd like to be credited in AUTHORS.txt? Your script got merged, and will make alpha 20, where it can get some play-testing. We saw that you rewrote the hyperspace range and duration calculations in Lua, and the devs are now working on changing things in core such that these only have to exist in one place. Those calculations have been re-balanced before now. So, thanks for that.

We were wondering how you'd like to be credited in AUTHORS.txt?

Sent: Tuesday, 28 February, 2012 at 10:45 pm by Brianetta

Smashing. I've made a pull request here:

pioneerspacesim/pioneer#1027

That's on my own Github fork, so if you set up a remote tracking branch to Code: Select all ~ git://github.com/Brianetta/pioneer.git

branch Benamucki-DeliverPackage you can pull any commits that might land on top of it from other devs.

If you have further commits, submitting them this way is fine.

Sent: Tuesday, 28 February, 2012 at 8:16 pm by Benamucki

2nd part of the patch!

Sent: Tuesday, 28 February, 2012 at 8:13 pm by Benamucki

Hi Brianetta,

as you suggested I have switched to the pioneer git version (no Github). I noticed that my modifications did no longer work as intended, so I have made some corrections and improvements. The startup of the script was unacceptably slow. I'm now automatically limit the radius of the sphere which contains the inspected systems. This prevents lengthly calculations when searching the shortest path.

Since ships are now accelerating with up to 80g (poor pilots) my intra systems flight times were to short.

Sorry to bother you again, would you please find the patches I've made in the attachment. I created an own branch called benamucki and ran "git format-patch -M origin/master"

Hmm, the attachment exceeds 10 Kib, I need send another PM.

Sent: Wednesday, 22 February, 2012 at 7:38 pm by Benamucki

Brianetta wrote:That's very encouraging.

Rob's impressed with your style. He liked the fact that you wrapped stuff up in classes, and he says it's good code. I can see by your use of syntactic sugar on function defs (we haven't been using that, as a rule) that you have Lua experience from somewhere else. It's pretty cool.

I'm thinking that some of your functions (your pathfinder, and the hyperspace range function to name two) could be put into a library file. The data/libs directory contains Lua libraries, where you could define those functions globally without upsetting anybody. If you do that, have a look at the other Lua files in there to see how our NaturalDoc system interprets Lua comments for documentation.

make codedoc is the incantation to build those.

You don't have a Github account, but do you use Git? If so, and if you have a commit history locally, we're happy to take git format-patch style patches for inclusion in the repository. If not, I'd heartily recommend that you consider using both Git and Github - your changes can (and likely will, judging by dev feedback) be reviewed and integrated quickly.

I'm glad that you like the script:) The library file is a good idea. I would prefer an extented API. If you ever change the C++code my lua implementation will no longer be correct. Your new intra-system fuel calculation is a good example for that.

Git is new to me, Brianetta. I need to read its documentation first. I've downloaded the Zip-File (Version 18) and made some other changes as well. I mentioned them in the Dev Chat, e.g.

const float Game::s_timeAccelRates[] = { 0.0f, // paused 1, 10, 610, 10610, 106106, 24106106 ...

and highlighting the corresponding digit of the clock.

I will probably create a git clone and generate some diffs.

Sent: Tuesday, 21 February, 2012 at 9:28 pm by Benamucki

Brianetta wrote:Does this mean that the offered price will change depending on which ship which the player is flying? Such things shouldn't have any bearing. Distance can matter, of course, but the player is just one of many people who might be looking at the BBS adverts.

Thanks for your reply.

No, is doesn't. Unfortunately some functions are only available for the current ship, for instance the maximum range etc. I've looked these functions up in the c++code and implemented lua versions which allow me to pass mass and acceleration as parameter. It allows also me to calculate the costs for all ships and to select the cheapest one. Of course an O(n^2) shortest path version multiplied by 30 ships can take some time. Even in Lua it should be possible to do this within milliseconds. However, it takes longer, probably due to garbage collection. Therefore I sorted out some ships by checking their mass as well.

Sent: Tuesday, 21 February, 2012 at 8:34 pm by Benamucki

Hi Brianetta,

I have rewritten the delivery script in order to get better prices. Those are now based on the flight time, urgency and risk. The script calculates the flight time by checking thrust and mass. For inter-systems flights it searches the shortest path for all ships from source to destination and calculates the required costs and the amount of fuel. It selects the cheapest one and takes it as price of the offer. Path details are display in the console, would be nice to display them in the mission screen somehow.

As mentioned in the freenode chat, I do not have a Github account yet. Hope, you can take a look into the attachment and if you like it you may want to check in the script. Hi Brianetta,

I have rewritten the delivery script in order to get better prices. Those are now based on the flight time, urgency and risk. The script calculates the flight time by checking thrust and mass. For inter-systems flights it searches the shortest path for all ships from source to destination and calculates the required costs and the amount of fuel. It selects the cheapest one and takes it as price of the offer. Path details are display in the console, would be nice to display them in the mission screen somehow.

As mentioned in the freenode chat, I do not have a Github account yet. Hope, you can take a look into the attachment and if you like it you may want to check in the script.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment