Compare commits

...

3 Commits

Author SHA1 Message Date
Richard Bronkhorst
3010a8186d Update central_command.py, commander.py and one other file 2023-07-03 19:13:24 +02:00
Richard Bronkhorst
d6fe1cf183 Add store.md 2023-07-02 15:17:53 +02:00
Richard Bronkhorst
bb64880822 Add Readme.md 2023-07-02 14:33:19 +02:00
5 changed files with 138 additions and 9 deletions

83
Readme.md Normal file
View File

@ -0,0 +1,83 @@
# 0ptr script for spacetraders.io
This is my script for running spacetraders.io. It has been completely written and operated from an iphone.
Because i'm using a less-than-optimal development platform, some 'best-practice' code standards have been thrown out of the window. For instance, some variables have obscure names just to keep them short.
The script offers a command-line interface allowing you to do most ST operations by hand. More importantly, it offers the functionality to assign missions to ships and execute them automatically.
# Getting started
I'm using the [pythonista app](http://omz-software.com/pythonista/) to develop and test the script. Just open main.py and hit run.
To keep the script running for longer periods of time, I'm using a VPS with docker. Start the script like so:
`docker run -v 0ptr:/data -ti 0ptr`
The script will ask for an agent name. Make sure you choose a unique one. After hitting enter, you will be presented with the prompt: `>`
Now you'll want to register. You need to provide your faction:
`> register cosmic`
If all goes well, you should have an account now.
Next is building up our view of the universe: the atlas.
`> universe`
This command will iterate over all systems and obtain all waypoint information. **this will take several hours**. However, if you are impatient, you can stop the process after a couple of minutes by hitting enter. It should at least have indexed your local system to continue.
Now, let's see what ships we own.
`> ships refresh`
This will populate our internal cache of present ships and their state. After this, the state is updated continually by each command that alters it. You should be able to omit the 'refresh' after this.
We should also populate the cache of contracts:
`> contracts refresh`
Same here: you can omit the 'refresh' from now on and view your contracts with the bare `contracts` command without sending a http request.
You are now ready to begin operations.
# Operations
To get a ship to do something, you first have to select it:
```
> ship 1
KILO-1 DOCKED [1035/1200] X1-YU85-03282C
KILO-1>
```
This prints the current state of the ship. Notice that the prompt now includes the name of the ship. Any command you now give will be executed by that ship.
A quick, non-complete list of commands:
* go: intra-system travel to another waypoint
* orbit
* dock
* market: show local market data
* shipyard: show local shipyard data
* jumps: show local jumpgate data
* mission: set ships mission type
* mine: mine and deliver a resource
* probe: find resource prices in nearby markets
* survey: generate surveys in a loop
* travel: travel to any waypoint in the universe using jumpgates (assuming a route is found)
* haul: buy goods at a site and bring them to a destination
* mset: set a mission parameter
* purchase: purchase a ship at a shipyard
* buy: buy a resource at the local market
* sell: sell a resource at the local market
* jump: jump to a remote system using the local jumpgate
* cmine: configures a mining mission for the current contract
* chaul configures a hauling mission for the current contract
* cprobe: configures a probing mission for the current contract
* query: lists nearest markets and buy prices (if known) of a resource
Look in commander.py for more available commands.
# Data storage
The script stores each object in a separate json file in the data directory. The default location for this directory is in your workingdir. The docker image places the data dir in '/data'
If you want to re-register an agent, or there is a sever reset, just delete all data in that directory.

View File

@ -30,14 +30,6 @@ class CentralCommand:
mission = self.missions[ship]
mission.step()
return True
def wait_for_stop(self):
try:
input()
except EOFError:
pass
self.stopping = True
print('stopping...')
def run_interactive(self):
print('auto mode. hit enter to stop')
@ -46,7 +38,17 @@ class CentralCommand:
t.start()
self.run()
print('manual mode')
def wait_for_stop(self):
try:
input()
except EOFError:
pass
self.stopping = True
print('stopping...')
def run(self):
self.update_missions()
while not self.stopping:

View File

@ -123,6 +123,8 @@ class Commander(CommandLine):
def do_chaul(self):
if not self.has_ship(): return
if len(ship.cargo) > 0:
raise CommandError('please dump cargo first')
contract = self.active_contract()
delivery = contract.unfinished_delivery()
if delivery is None:

View File

@ -25,6 +25,7 @@ class Marketplace(SystemMember):
price['symbol'] = symbol
price['buy'] = mg(g, 'purchasePrice')
price['sell'] = mg(g, 'sellPrice')
price['volume'] = mg(g, 'tradeVolume')
prices[symbol] = price
self.prices = prices

41
store.md Normal file
View File

@ -0,0 +1,41 @@
# The store format
This project uses a custom database format just because we can.
The script reads the entire store on startup. Each object can br altered in memory. A 'dirty' status is set when an object is changed. periodically the script will flush the store, writing all changes back to disk.
## Objects
First lets discuss what we are storing.
Objects are identified by type and symbol. A symbol is an uppercase alphanumeric string that optionally contains '-' chars. the type is a lowecase alphanumeric string of length 3.
For each type, the store has a class defined that is used to load objects of that type.
An object identifier is its symbol and type joined with a '.' character.
Some examples of object identifiers:
* X1-J84.sys
* X1-J84-0828772.way
* CAPT-J-1.shp
A waypoint is always part of a system. This is also visible because the waypoint symbol is prefixed by the system symbol. However, this relation is not enforced or used by the store. The symbol is an opaque string.
An object has attributes. Values of attributes can be strings, ints, floats, bools, lists, dicts and references. lists and dicts can also only contain the values listed. References are pointers to other objects in the store.
## Indices
An index is a dict with a string as key and a list of objects as value. The dict is built when loading the store. when the index is iterated, each object is re-checked and removed if necessary.
## API
* store.load(fil) loads all objects
* store.get(type, symbol, create=False) fetches the object. If create==False: None if it wasnt present
* store.all(type) generator for all objects of a goven type
* store.cleanup() removes all expired objects
* store.flush() writes all dirty objects to disk
*
type may be a class or a string containing the name of a class. The type should be a subclass of models.base.Base
# file format
the file format is a header followed by a number of blocks. the size and number of blocks are dictated by the header.