• Welcome to the new COTI server. We've moved the Citizens to a new server. Please let us know in the COTI Website issue forum if you find any problems.
  • We, the systems administration staff, apologize for this unexpected outage of the boards. We have resolved the root cause of the problem and there should be no further disruptions.

Starshell.py

robject

SOC-14 10K
Admin Award
Marquis
Here's the beginning of Starshell, the T5 ship-builder command-line shell.

(Attached in a zipfile)

Current functionality:
* set hull, jump, maneuver, weapons, sensors
* set via qsp
* long and short-form of quick data entry
* costs and tonnages for drives are (re)calculated on the fly
* set code, count, TL, QREBS, control points, tons, mcr, mount, stage, and range (but no calculations are done on them... yet)

Weapon and sensor data are stored in a YAML config file adapted from my T5 Desktop Shipyard app.
 

Attachments

Last edited:
First comment is you should learn to use string format(). It will make handling the many output strings much easier.

Print str(data[0]) + " tons, type " + str(data[1])

Vs.

Print "{} tons, type {}".format(data[0], data[1])

the format () method has a number of options to make this kind of string creation much simpler and less error prone .
 
I. UPDATES

I'll update the OP as I go. Pretty soon I'll attach the code instead of blasting it inline.


II. PYTHON QUESTION

I have a question about handling dictionaries of dictionaries. Can I compactly set a value in a dictionary's dictionary?

Something like
Code:
   ship[ 'hull' ][ 'tons' ] = 200
   ship[ 'hull' ][ 'config' ] = 'S' # streamlined

...but I don't know the nomenclature for that.


III. CMD

Interesting. I never used cmd before in Python. I'm playing with the code now in Classic Python 2.5.

Just last week I used cmd2 at work, which is a zero-change drop-in for cmd. It's pretty slick. I tried to install it on OSX at home... and failed :( So for the moment I'll work in cmd and see how far it goes.



IV. ANACONDA

...actually, I'll try installing Anaconda Python and see if that makes package management easier.
 
Last edited:
Very very soon, I am going to have to switch to full-on objects for ship components... because there's going to be some recalculation logic and it will need to be encapsulated in order for me to keep my sanity.

But ... I've never done objects in Python. So for instance, a Jump Drive class... is it just as simple as declaring the class and then instantiating one?

Code:
class Component:
   def calculateVolume()
   def calculatePrice()
   def setRating(r)
   ...etc...

class JumpDrive(Component):
   ...etc...
 
Very very soon, I am going to have to switch to full-on objects for ship components... because there's going to be some recalculation logic and it will need to be encapsulated in order for me to keep my sanity.

But ... I've never done objects in Python. So for instance, a Jump Drive class... is it just as simple as declaring the class and then instantiating one?

Code:
class Component:
   def calculateVolume()
   def calculatePrice()
   def setRating(r)
   ...etc...

class JumpDrive(Component):
   ...etc...

Pretty much. You will need to do a constructor (__init__()) at a minimum, and all methods have a 'self' reference as the first parameter. Anything referencing instance variables of the class must explicitly use the self reference (self.foo = 'bar'), and method calls back to other methods need to reference self.
 
I. UPDATES

II. PYTHON QUESTION

I have a question about handling dictionaries of dictionaries. Can I compactly set a value in a dictionary's dictionary?

Something like
Code:
   ship[ 'hull' ][ 'tons' ] = 200
   ship[ 'hull' ][ 'config' ] = 'S' # streamlined

...but I don't know the nomenclature for that.

Yes you can. Exactly as you have written it. There isn't any special nomenclature for this. Python dictionary value (and keys) can be any python value including dictionaries, arrays, or classes.

You just need to make sure you create the default (empty) dictionaries.

Code:
  ship = {}
  ship['hull'] = {}
 
UPDATED 5/21/2018

Starshell now allows the entry of the QSP for quick configuring. The program currently handles:

Hull volume, configuration, and cost.
Jump drive rating, volume, and cost.
M-drive rating, volume, and cost.

It displays the ship design in a compressed format thus:

Code:
Components:
 - Hull H0 1000  0   10 0 00000 0 0 Planetoid Hull
 - Driv J1   30  0   30 0 00000 0 0 Jump Drive
 - Driv M3   29  0   58 0 00000 0 0 Maneuver Drive
 
Update 5/25

Incremental update. QREBS can be set on individual components; in order to do this, each component has a unique 24-bit ID.

In a fit of perversity, I also translated most of the commands ... to Vilani. Yeah it's stupid, but it's stupid in a fun way. I'm sure it'll get annoying and I'll switch back.

Example of a session.
Code:
robs-mac-mini:cli-shipyard rje$ ./starshell.py 
Welcome to Starshell. Type help or ? to list commands.

stsh % j 1
Jump Rating: J1
stsh % m 1
Maneuver Rating: 1G
stsh % sii
Components:
#  ID   Type  CR Tons No.  MCr TL QREBS E C Label
 - r7JQ Hull  H0  200   1   14  9 00000 0 0 Streamlined Hull
 - 3B2+ Driv  J1   10   1   10  9 00000 0 0 Jump Drive
 - kqSm Driv  M1    2   1    4  9 00000 0 0 Maneuver Drive
#  ID   Defen CR Tons No.  MCr TL QREBS E C Label
#  ID   Payld CR Tons No.  MCr TL QREBS E C Label
stsh % limu kqSm
Selected Driv
stsh % help

Documented commands (type help <topic>):
========================================
girzi  help  j  limu  m  qrebs  qsp  save  sii  tl  urgikiim  zim

Undocumented commands:
======================
bye

stsh % help qrebs
USAGE: qrebs <q|r|e|b|s> <-5 to 5>. Set quality for selected component.
stsh % qrebs b -5
b set to -5
stsh % qrebs e 1
e set to 1
stsh % qrebs r 3
r set to 3
stsh % qrebs s -2
s set to -2
stsh % sii
Components:
#  ID   Type  CR Tons No.  MCr TL QREBS E C Label
 - r7JQ Hull  H0  200   1   14  9 00000 0 0 Streamlined Hull
 - 3B2+ Driv  J1   10   1   10  9 00000 0 0 Jump Drive
 - kqSm Driv  M1    2   1    4  9 031EB 0 0 Maneuver Drive
#  ID   Defen CR Tons No.  MCr TL QREBS E C Label
#  ID   Payld CR Tons No.  MCr TL QREBS E C Label
stsh %
 
Major update. Weapon and sensor data are read from a YAML config file borrowed and adapted from my T5 Desktop Shipyard app. So I've brought in all weapons and sensors.
 
Another major update. Mount, Stage, and Range are all settable on drives, sensors, and weapons (but they don't affect price and volume yet, and they aren't validated yet).

OP file updated.

Next step will be to streamline ops, allowing multiple components to be added with one command.
 
Rob, do I need to install the python source code to be able to try this out?

I am fascinated by the notes but my last programming classes were COBOL and FORTRAN. So if I can't help with development I would still like to help with testing.
 
Rob, do I need to install the python source code to be able to try this out?

I am fascinated by the notes but my last programming classes were COBOL and FORTRAN. So if I can't help with development I would still like to help with testing.

Python is usually pretty easy to understand. If you've done COBOL and FORTRAN then you are probably going to pick things up quickly. Since Rob is using Python 2, I think, you can buy a used copy of an older edition of "Learning Python" if you find the language fun.

The biggest hurdle people have to work through is that white space indentation is significant in Python. For example:

Code:
def my_method_ends_with_a_colon:
  statement = indent + text
  another_statement_must_be_indented == the_same
  last_statement_notice_no_braces_or_semi-colons

Honestly, my Ruby and shell code looks a lot like my Python used to. Once you get used to good whitespace usage things look so much cleaner.
 
The biggest hurdle people have to work through is that white space indentation is significant in Python. For example:

Code:
def my_method_ends_with_a_colon:
  statement = indent + text
  another_statement_must_be_indented == the_same
  last_statement_notice_no_braces_or_semi-colons

Honestly, my Ruby and shell code looks a lot like my Python used to. Once you get used to good whitespace usage things look so much cleaner.

LOL! Honestly I am OCD about whitespace and indentations in my code, even when I have braces and brackets.

I think I'll try poking around with Python as well. I have a couple of projects <some Traveller related, but not all>.

Cheers,

Baron Ovka
 
INSTALL

Major B, you'll have to install a couple of extra libraries as well:

simple-yaml
cmd2

If you're on OSX, you might also have to install a readline package. Refer: http://cmd2.readthedocs.io/en/latest/


STYLE

Meh. Like Ovka, I was already compulsive about indentation and not using tabs (I have always loved YAML). Python is a non-event for me, except for learning its libraries, which is true for any language.

Frankly, it's the colon that consistently trips me up. It's not what I would expect to be a block operator.


TEST

Please use it. Just be aware that it is (1) barely functional and (2) I'm not sure it can produce a valid ship design yet. Being able to use the Desktop Shipyard configuration files helped greatly, but there's almost no plumbing in the code so far.
 
Today I've implemented a component factory to test full-data line entry. Once that's working, then a design file can be round-tripped through the system.
 
Today I've implemented a component factory to test full-data line entry. Once that's working, then a design file can be round-tripped through the system.

Cool! I love building very finite frameworks and adding ideas as I can. Working on a merchant-y thing now, a bit at a time.

Any intent on putting this up in github? Or have you and I just missed it?
 
Back
Top