Space Trader for Violyx
=======================

by Merecete, 2026 - based on the Palm OS game Space Trader by Pieter Spronck

Space Trader is a trading and space combat game: buy goods cheap, fly them to
another solar system, sell them where they fetch more, and deal with police,
pirates and traders on the way - until you can buy a moon to retire to.

The game itself is the original C code of Space Trader 1.2.2 (2000-2005),
unchanged apart from a few lines marked "Violyx". Below it sits a small Palm
OS made for Violyx (port/palm.c): the forms, buttons, alerts, menus,
databases and the event loop the game was written for, drawn in the text grid
of a Violyx window.

  Space Trader for Violyx   Copyright (C) 2026 Merecete
  Original game             Copyright (C) 2000-2005 Pieter Spronck,
                            with Sam Anderson and Samuel Goldstein
                            http://www.spronck.net/spacetrader

Thanks to Pieter Spronck for the game, for releasing its source code under
the GPL and for his friendly reply to this version.

Free software under the GNU General Public License, version 2 or (at your
option) any later version, like the original. See LICENSE.

The pictures of the Palm version (by Alexander Lawrence) are not part of the
GPL release and are not used: the title, the ships and the end screens are
drawn new as text.


Files
-----
  spacetrader.c   the whole game in one file, ready for the Violyx compiler
  spacetrader.vpk the finished program (icon: Saturn, a picture from Violyx
                  0.3.5 on, text in older versions)
  port/           the Violyx part and the tools that make spacetrader.c
  original/       the original source code of Space Trader 1.2.2


Build on Violyx
---------------
Put spacetrader.c into your home folder, open Commands and type:

    cc spacetrader.c -s 76x20 -t "Space Trader"

Enter in the compiler window starts the game. The package from cc gets the
icon of the compiler; spacetrader.vpk has the Saturn (port/icon.png, packed
with mkvpk.py --icon-png).


Keys
----
  Arrow keys      move between the buttons
                  on the charts: from star to star
  Enter, Space    press the button, choose the star
  Tab             next button (on the charts: between chart and buttons)
  M               the menu (Game, Command, Help)
  H               help for the current screen
  O               options

The letters of the Palm version work on every docked screen:

  B buy cargo     S sell cargo      Y ship yard        W short range chart
  E buy equipm.   Q sell equipm.    P personnel        G galactic chart
  K bank          I system info     C commander status

  1-4             the four Palm buttons (shortcuts, see Game > Shortcuts)
  PgUp, PgDn      previous/next system on the target and price screens and
                  on the galactic chart
  Backspace       in a number field: delete; in a dialog: the default button

In dialogs and in encounters the first letter of a button presses it
(A attack, F flee, I ignore, S submit ...). In an encounter the peaceful choice
(Ignore, Submit, Flee ...) has the focus first, and every alert starts on the
button the original chose as its default, so Enter never starts a fight or a
new game by accident.

Esc closes the window as always. The game is saved every time it waits for
a key, so it goes on where you left it. F5 zooms the window; the charts grow
with it.


Saving
------
In the data folder of the program:

  game.sav               the current game (saved after every move)
  SpaceTraderSave.db     Game > Snapshot
  SpaceTraderSwitch.db   Game > Switch Game (a second, parallel game)
  SpaceTraderDB.db       the high scores

Files are written to a .tmp file first and then renamed, so an interrupted
save never destroys a game.


Changes to the original code (2026, Merecete)
---------------------------------------------
port/mkport.py makes spacetrader.c from the original sources and applies
these changes, each marked "Violyx" in the code:

  - the ships in an encounter are drawn as text in a colour for each type,
    with coloured bars for hull and shields (glue.c), not as pictures
  - the retirement screen shows a sunset over the sea, drawn in pixel cells
  - DisplayPage breaks text between words for the wider screen
  - the names on the short range chart are centred on their star
  - sqrt of Math.c is called IntSqrt (the C library has its own sqrt)
  - multi-character constants ('STra', 'Data') written as numbers
  - SpecialEvent is no longer const (the game changes it)
  - Rand() avoids a signed overflow
  - the title screen and the About box name the Violyx version first and the
    original game second

Everything else that differs from the Palm (screen, keys, files) is in
port/palm.c and port/glue.c.


Building spacetrader.c again (Linux)
------------------------------------
  cd port
  python3 mkport.py          writes ../spacetrader.c

st_rsc.h and st_forms.h hold the texts, forms and menus of the original
resources. gen_rsc.py and gen_forms.py make them from
original/Rsc/Resource.frk/Merchant.rsrc, which is in the original source
package (SpaceTraderSource_1.2.2.zip) and not included here, because that file
also holds the pictures.

host.c runs the game on Linux for tests, with keys from a script:

  gcc -DVX_LIBC -DHOSTTEST -I<violyx>/sdk ../spacetrader.c \
      <violyx>/sdk/violyx.c host.c -o st
  mkdir data out; SCRIPT="Enter dump" ./st

render.py turns the dumped frames into PNG pictures (needs Pillow and the
Spleen font of Violyx, set SPLEEN to its .bdf file).
