TWFiles Version Two, 2/8/1993 - Researched & Typed solely by Jason M. Boyd
Print this file for easy reference (10 pages).

This is a summary of the contents of all files that are contained in the Trade
Wars 2002 package, versions 1.03 and 1.03d, from Martech Software.  Please
don't even subconsciously apply these specs to any other versions or programs;
this can be dangerous.

All information ("this information") contained within this text file is
distributed without any expressed or implied warranties.  You, the user,
assume all risk for the use of this information.  You alone shall be
responsible for any loss of profits, loss of savings, or other incidental or
consequential damages arising out of the correct or incorrect use of this
information, even if I have been advised of the possibility of any damages.  I
do not warrant that this information is complete or accurate. By using this
information you agree to the above limitations.

Though descriptions of all files are included, the meat & purpose of this file
are the detailed maps of the data files.  This information can be used for
illicit editing (ie, unregistered.  This oughtn't be done.  In fact, I forbid
you to do it.) and for changing items that TEDIT can't reach.  It also gives
the necessary information for anyone writing utilities or augmentations for
Trade Wars, and gives an idea of exactly what they have the power to change.

Many items and descriptions in this file will, no doubt, be unclear at first.
There are many general notes and specific footnotes at the end of the file
which will help.  Footnotes are indicated by a letter right here:-----------.
                                                                            |
Good luck, folks... enjoy yer data!                                         v

PROGRAM FILES:
~~~~~~~~~~~~~~
TW2002.EXE - Main game program
TW2002.OVR - Overlay file for TW2002.EXE
TEDIT.EXE - Editor program
TEDIT.OVR - Overlay file for TEDIT.EXE
TWZAPPER.EXE - Erases corrupted data records
INITPORT.EXE - Re-initializes all ports


SEQUENTIAL-FORMAT DATA & TEXT FILES:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ANNOUNCE.DAT - Announcement posted at tavern door
  Line    1   Name of player who posted the announcement                    A
  Lines 2-8   Text of announcement (7 lines maximum)                        B
OATHTEXT.DAT - Bank of oaths uttered by destroyed players
  Line    1   Number of oaths in the file (# of lines minus one)
  Lines   2+  Text of oaths, "@" is the killer, "#" is the killed           B
CONVO.DAT - Straight text of the tavern conversation                        A
TWOPENG.DAT - Straight text of the player's game log                        A
TWGAME.LOG - Straight text of the Sysop's game log
MENUFILE.TXT - All menus, and many descriptions for non-ANSI users          A
TWTRADER.TXT - Player rankings, found in the directory specified with TEDIT,
  updated every time a player gets a ranking from his computer, not every
  time the game is run.
TWHELLO.MSG - Opening screen for non-ANSI users
TWSYSOP.DOC - Sysop docs, installation, problems, error codes
TEDIT.DOC - TEDIT docs, incomplete but full of Very Useful Information
TWINSTR.DOC - User docs, including help screens for menus
TWZAPPER.DOC - Docs for the TWZAPPER data-repairing program
INSTALL.DIR - Instructions for using TW2002 with various BBS software
TWORDER.FRM - Order form for registering TW2002
*.BAT - Batch files to run various programs
*.ANS - ANSI pictures for many, many things


RANDOM-ACCESS TYPE DATA FILES:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
File: TWDATA.DAT
General data - location = Offset + 1
Description                                     Type              Offset
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
--- unknown/unused                              42 Bytes               0
Directory to put score file in                  TW Text 42            42
TriCron champion (player #)                     Integer               84
TriCron high score                              Integer               86
Ferrengi home sector                            Integer               88
StarDock sector                                 Integer               90    G
2nd class 0 port sector                         Integer               92    G
3rd class 0 port sector                         Integer               94    G
Reciprocal of Ferrengi move chance              Integer               96    C
Reciprocal of alien move chance                 Integer               98    C
DesqView configuration (1.03d only)             Integer              100
Security level required for sysop functions     Integer              102
Are players required to use real names?         Integer              104
--- unknown/unused                              2 Bytes              106
Photon missile wave duration (seconds)          Integer              108
Show StarDock location in Game Status?          Integer              110
Maximum ships per FedSpace sector               Integer              112
--- unknown/unused                              6 Bytes              114
TriCron jackpot                                 Pascal 6-Byte Real   120
Registration code                               TW Text 17           126
--- unknown/unused                              25 Bytes             143
Underground password phrase                     TW Text 42           168
Date that game was started                      Integer              210
Use CTS/RTS Hardware Flow Control?              Integer              212
Base moves per day rate                         Integer              214    D
BPS rate at which to lock modem, divided by 100 Integer              216
Maximum # of players in a corporation           Integer              218
Is the local display OFF during remote games?   Integer              220
Initial fighters                                Integer              222
Initial credits                                 Integer              224
Initial holds                                   Integer              226
Time before inactive user is deleted (days)     Integer              228
Date that EXTERN was last run                   Integer              230
Ferrengi regeneration percentage                Integer              232
Fed StarShip Lexington sector location          Integer              234
Maximum # of planets in a sector                Integer              236
Fed StarShip Valiant sector location            Integer              238
Colonists added to Terra per day                Integer              240
Maximum length of daily log (lines)             Integer              242
Fed StarShip Intrepid sector location           Integer              244
--- unknown/unused                              6 Bytes              246
Player data - location = (Player# * 126) + Offset + 1
  149 records for Player#, 2 to 150
Description                                     Type              Offset
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Player's game name or alias                     TW Text 42             0
Player's BBS name                               TW Text 42            42
Date the player last played                     Integer               84
Player # who killed this player (0 if alive)    Integer               86
Turns left today                                Integer               88
Shields                                         Integer               90
Sector location                                 Integer               92    E
Fighters                                        Integer               94
Cargo holds                                     Integer               96
Amount of Ore (holds)                           Integer               98
Amount of Organics (holds)                      Integer              100
Amount of Equipment (holds)                     Integer              102
# of times this player has been blown up        Integer              104
Corp # to which this player belongs             Integer              106
Amount of Colonists (holds)                     Integer              108
Status: 1=active, 0=deleted/vanished            Integer              110    O
Planet # on which player is parked              Integer              112    E
Last sector # player was in                     Integer              114
Player's experience rank                        Integer              116
Player's alignment rank                         Integer              118
Player's credits                                Pascal 6-Byte Real   120
Sector data - location = (Sector# * 126) + Offset + 19027
  1000 Sector#, 1 to 1000
Description                                     Type              Offset
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Name of nebula containing this sector           TW Text 42             0    B
Text of the beacon in this sector               TW Text 42            42    B
Destination sector of warp route A              Integer               84
Destination sector of warp route B              Integer               86
Destination sector of warp route C              Integer               88
Destination sector of warp route D              Integer               90
Destination sector of warp route E              Integer               92
Destination sector of warp route F              Integer               94
Number of the port in this sector               Integer               96    G
--- unknown/unused                              6 Bytes               98
Fighters in sector                              Integer              104
Player # who owns the mines in this sector      Integer              106    H
Mines in sector                                 Integer              108
Player # who owns the fighters in this sector   Integer              110    H
--- unknown/unused                              6 Bytes              112
Fighter mode: 0=defensive, 1=toll, 2=offensive  Integer              118
Tolls collected by fighters                     Pascal 6-Byte Real   120
Port data - location = (Port# * 126) + Offset + 145027
  400 records for Port#, 1 to 400
Description                                     Type              Offset
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Port name                                       TW Text 42             0    B
Name of the last ship to port here for trading  TW Text 42            42
Port class                                      Integer               84
Date that this port was last visited            Integer               86    I
Amount of ore in storage (holds)                Integer               88
Amount of organics in storage (holds)           Integer               90
Amount of equipment in storage (holds)          Integer               92
Amount of ore produced daily (holds)            Integer               94
Amount of organics produced daily (holds)       Integer               96
Amount of equipment produced daily (holds)      Integer               98
Price change factor for ore                     Integer              100    F
Price change factor for organics                Integer              102    F
Price change factor for equipment               Integer              104    F
--- unknown/unused                              4 Bytes              106
Countdown until port is open (negative, days)   Integer              110
--- unknown/unused                              2 Bytes              112
Time of day that this port was last visited     Integer              114
Player # who was last caught robbing            Integer              116
--- unknown/unused, but probably just unknown   2 Bytes              118
Accumulated cash profits (credits)              Pascal 6-Byte Real   120
Planet data - location = (Planet# * 126) + Offset + 195427
  150 records for Planet#, 1 to 150
Description                                     Type              Offset
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Planet name                                     TW Text 42             0    B
Name of player who created planet               TW Text 42            42    B
Date that planet was last visited               Integer               84
Groups of colonists producing ore               Integer               86
Groups of colonists producing organics          Integer               88
Groups of colonists producing equipment         Integer               90
Amount of ore on planet (holds)                 Integer               92
Amount of organics on planet (holds)            Integer               94
Amount of equipment on planet (holds)           Integer               96
Fighter attack/defense level (percent)          Integer               98
Quasar cannon atmospheric level (percent)       Integer              100
Quasar cannon sector level (percent)            Integer              102
Planet class                                    Integer              104
Time that planet was last visited               Integer              106
# of fighters on planet                         Integer              108
Planetary defense level (Citadel level + 1)     Integer              110
Sector location of planet                       Integer              112
Date that next citadel construction will finish Integer              114
Player # who owns planet                        Integer              116    H
# of planetary shields                          Integer              118
Credits in planetary treasury                   Pascal 6-Byte Real   120

File: SHIPFILE.DAT
Players' ship data - location = (Player# * 115) + Offset + 1
  149 records for Player#, 2-150
Description                                     Type              Offset
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Ship name                                       TW Text 46             0
Date ship was manufactured                      TW Text 31            46    B
# of times ship has ported                      Integer               77
--- unknown/unused                              2 bytes               79
Ship type #                                     Integer               81
Ship manufacturer #                             Integer               83
--- unknown/unused                              2 bytes               85
# of cloaking devices                           Integer               87
Scanner type: 0=none, 1=density, 2=holographic  Integer               89
# of genesis torpedos                           Integer               91
# of mines                                      Integer               93
# of ships this ship has destroyed              Integer               95
# of marker beacons                             Integer               97
# of photon missiles                            Integer               99
# of atomic detonators                          Integer              101
Amount of corbomite                             Integer              103
# of ether probes                               Integer              105
# of mine disruptors                            Integer              107
Does this ship have a psychic probe?            Integer              109
Does this ship have a planet scanner?           Integer              111
Ship transfer lock #                            Integer              113    J

File: SHIPSTAT.DAT
Ship type definition - location = (ShipType# * 45) + Offset + 1
  16 records for ShipType#, 0 to 15
Description                                     Type              Offset
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Hold Cost                                       Integer                0
Main Drive Cost                                 Integer                2
Computer Cost                                   Integer                4
Hull Cost                                       Integer                6
Maximum Holds                                   Integer                8
Initial Holds                                   Integer               10
Move-per-day multiplier                         Pascal 6-Byte Real    12    D
Maximum Fighters                                Integer               18
Maximum Shields                                 Integer               20
Combat Odds multiplied by 10                    Integer               22
Maximum Mines                                   Integer               24
Maximum Beacons                                 Integer               26
Maximum Genesis Torpedos                        Integer               28
Can this ship carry a Sector Scanner?           1 Byte                30
Can this ship carry a TransWarp Drive?          1 Byte                31
Can this ship carry a Planetary Scanner?        1 Byte                32
--- unknown/unused                              4 Bytes               33
Maximum Photon Missiles                         Integer               37
Maximum Fighters per attack                     Integer               39
--- unknown/unused                              4 Bytes               41

File: ALIENS.DAT
Aliens' data - location = (Alien# * 76) + Offset + 1
  50 records for Alien#, 1-50
Description                                     Type              Offset
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Alien name                                      TW Text 26             0    B
Ship name                                       TW Text 26            26    B
Sector location                                 Integer               52
Ship type #                                     Integer               54
Ship manufacturer #                             Integer               56
# of shields                                    Integer               58
# of fighters                                   Integer               60
# of holds                                      Integer               62
Amount of corbomite                             Integer               64
Experience points                               Integer               66
Alignment                                       Integer               68
Credits                                         Pascal 6-Byte Real    70

File: FERRENGI.DAT
Ferrengis' data - location = (Ferrengi# * 70) + Offset + 1
  40 records for Ferrengi#, 1-40
Description                                     Type              Offset
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Ferrengi name                                   TW Text 26             0    B
Ship name                                       TW Text 26            26    B
Sector location                                 Integer               52
# of fighters                                   Integer               54
# of shields                                    Integer               56
Amount of corbomite                             Integer               58
Destination sector                              Integer               60    N
Player # who suffers grudge #1                  Integer               62    H
Player # who suffers grudge #2                  Integer               64    H
Player # who suffers grudge #3                  Integer               66    H
Operating mode                                  Integer               68    N

File: TWCORP.DAT
Corporation data - location: (Corp# * 110) + Offset + 111
  50 records for Corp#, 1 to 50
Description                                     Type              Offset
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Corporation name                                TW Text 42            00    B
Game name or alias of corporation's CEO         TW Text 42            42
Founding date for corporation                   TW Text 9             84    B
Corporation password                            TW Text 9             93
--- unknown/unused                              6 Bytes              102
Kills/Medals (not used in game)                 Integer              108    F

File: TRADER.DAT
Tips from the old trader in the tavern - location: (Tip# * 195) + Offset + 1
  Expandable records for Tip#, from 1 on up
Description                                     Type              Offset
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
First trigger keyword                           TW Text 16             0
Second trigger keyword                          TW Text 16            16
Price for this tip (credits)                    Integer               32
Probability that this particular tip is given   Integer               34    M
--- unknown/unused                              1 Byte                36
First line of advice                            TW Text 79            37    B
Second line of advice                           TW Text 79           116    B

File: FEDBOUNT.DAT
Federation bounties - location = (FedBounty# * 14) + Offset + 1
  Expandable records for FedBounty#, from 0 on up
  (Federation bounties are stored by individual bounty number.)
Description                                     Type              Offset
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Player # who placed this bounty                 Integer                0
--- unknown/unused (always 01 00)               2 Bytes                2
Player # this bounty is placed on               Integer                4
Player # who can claim this bounty              Integer                6
Credit amount of bounty                         Pascal 6-Byte Real     8

File: CONTRACT.DAT
Underground bounties - location = (Player# * 10) + Offset - 19
  149 records for Player#, 2 to 150
  (Underground bounties are stored by the player number on whom the
   bounties are placed.)
Description                                     Type              Offset
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Total credit amount of bounties on this player  Pascal 6-Byte Real     0
Total number of bounties on this player         Integer                6
Player # who can claim these bounties           Integer                8

File: AVOIDS.DAT
Players' avoided sectors - location = (Player# * 132) + Offset + 1
   149 records for Player#, 2-150
Description                             Type                      Offset
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
All avoided sectors for this player     125-Byte Sector-data type      0
--- unknown/unused                      7 Bytes                      125

File: TRAVELS.DAT
Players' explored sectors - location = (Player# * 132) + Offset + 1
   149 records for Player#, 2-150
Description                             Type                      Offset
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
All explored sectors for this player    125-Byte Sector-data type      0
--- unknown/unused                      7 Bytes                      125

File: GALABANK.DAT
Players' Galactic Bank accounts - location = (Player# * 6) + Offset - 5
   149 records for Player#, 2-150
Description                                     Type              Offset
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Credits in bank account                         Pascal 6-Byte Real     0    K

File: TWSMF.DAT
Player/game messages - location: (Message# * 186) + Offset + 1
  Expandable records for Message#, from 0 on up
Description                                     Type              Offset
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Message text                                    TW Text 161            0    B
Player # whom the message is to (-1 once read)  Integer              161
Player # whom the message is from               Integer              163    L
Time message was sent                           TW Text 12           165    B
Date message was sent                           TW Text 9            177    B

File: WALLDAT.DAT
Graffiti on the Tavern bathroom wall - location: (Line# * 89) + Offset + 1
  Expandable records for Line#, from 0 on up
Description                                     Type              Offset
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
One line of graffiti (one graffito)             TW Text 80             0    B
Date this line was written                      TW Text 9             80    B


GENERAL NOTES:
~~~~~~~~~~~~~~
Some files shown here will not exist at the beginning of a game, but are
 created as they are needed in the game.
All numbers, unless specified otherwise, are decimal and not hexadecimal or
 binary.
When a description is in question form, the actual data value should be 0 for
 no, and 1 for yes.  Any other values in these fields are untested.
When an item is expressed in certain units (such as "days" or "holds") the
 unit is given in parentheses after the description.
Dates and times are all either in text format or in Integer format.  The text
 format is straightforward enough.  The Integer date is equal to the number of
 days since Jan 1, 2000.  The Integer time is equal to the number of minutes
 past midnight.
Location formulas assume that the first byte of the file is counted as 1.  If
 it's 0, just subtract 1 from the formula.

FOOTNOTES:
~~~~~~~~~~
A - This text, by nature, contains TW color code(s).
B - This text does not ordinarily contain color codes, but putting them in
 won't cause any damage.  (Usually this means that this field is never really
 used by the game, but is only there for players to look at.)
C - If the value is, say, 20, there is a 1/20th chance of movement.
D - The moves that are particular ship will get per day are calculated by
 multiplying the base move rate by the move-multiplier for that ship type.
E - The sector location usually ranges from 1-1000.  To show that a player is
 on a planet, add 1000 to the sector number of the planet for the player's
 sector number AND set the "Planet #" field to the record number, not the
 sector, of the planet.  To indicate that a player is in a sector but cloaked,
 add 2000 to the sector number.
F - I'm not exactly sure how this works yet.
G - To move a port, you must set the "Port #" field in the record of the old
 sector to zero, and set this field in the new sector to the port number.  If
 you are moving the StarDock or the 2nd or 3rd class 0 port, you will have to
 change the proper field in the general data section.  Because this is all
 messy, it's best to use TEDIT to move ports.
H - Player # ranges from 2 to 150.  Values -11 to -60 refer to corporations 1
 to 50 respectively.  For planets, fighters and mines, -2 means rouge
 mercenaries and -1 means Ferrengi.  DO NOT use 1 for the owner of fighters,
 because this will display your registration code as the owner.  Values over
 151 are reported as the nebulae of the sectors, names of ports, and names of
 planets, which are next in the data file.  This is useful if you want to
 place fighters belonging to, say, "The Federation" or "Stardock Alpha I." A
 planet owned by 0 will not defend itself and will be automatically given to
 the first person who lands on it.
I - This is used to determine how much experience is given to a player for
 finding a neglected port.  It is also given by the Grimy Trader when you get
 a player trace.  Note that when a port is robbed, the date and time are
 updated, but the name of the last ship to dock is not.
J - Despite what TEDIT says, the only values used by the game are 0 for locked
 and 1000 for unlocked.  Note that TEDIT will not allow you to enter 1000
 for this number... pity!
K - Though the game limit for the bank account is 100000 credits, it is
 probably safe to put any reasonable amount of credits in here, as long as you
 are running a straight game with no auxiliary programs.
L - 2 to 150 means a player, -3 for ship computers, -2 for Deployed Fighters,
 -1 for the Ferrengi, 1 for the Federation, and 0 for unsigned/undated.
M - Values range from 270 to 2310, with no rhyme or reason that I can detect.
 A value of around 1000 should work.  If this number is too low, the trader
 will offer you advice for 0 credits, then give you two blank lines.
N - Check the TEDIT docs for the specifics here; these are not fully
 functional.
O - I was at one point convinced that a value of 8 held some special deletion
significance, but I can no longer find any evidence for this.  Also, players
with a status of 0 can still play if their real and game names are still
intact.  They will not be seen in the player ranks, and are therefore referred
to as "vanished." under 1.03 vanishing players works fine, but 1.03d
overwrites vanished player records with new ones, so any vanished players must
be given high player numbers.

NOTES ON DATA TYPES:
~~~~~~~~~~~~~~~~~~~~
Integer - An IEEE standard data type, range from -32768 to 32767
Byte - Single-byte integer, range from 0 to 255
TW Text - Standard format for text in Trade Wars, consists of a text string
 with a single-byte prefix equal to the length of the text.  The lengths
 listed in the map equal the maximum string length plus one for the prefix.
 ("TW Text 42" can be a string of any length from 0 to 41, but will always
 occupy 42 bytes in the file.)
Pascal 6-Byte Real - a floating-point data type peculiar to Pascal.  Range
 from 2.9 E-39 to 1.7 E+38, positive and negative.  Internal format is thus:
 Byte #0: Exponent + 128 (80 Hex)
 Byte #1: Least significant byte of mastissa
 Bytes #2-#4: Mantissa bytes of increasing significance
 Byte #5: Most significant byte of mantissa.  The most significant bit of this
  byte is the sign (positive or negative) of the mantissa.
 The number yielded by this process is the base 2 logarithm of the actual
 number represented.  In other words, it is the power to which 2 must be
 raised to find the actual number.  This is a mess, so I drafted the following
 functions to convert the Real type to and from the standard IEEE 8-byte
 double-precision floating-point data type.  The code is compiler-style BASIC.

FUNCTION P6RtoDBL# (P6R$)
    Man# = -1
    P6RtoDBL# = 0
    IF P6R$ = STRING$(6, 0) THEN EXIT FUNCTION
    Ex% = ASC(LEFT$(P6R$, 1)) - 128#
    Man# = (ASC(MID$(P6R$, 6, 1)) AND 127) / 128#
    IF ASC(RIGHT$(P6R$, 1)) > 128 THEN Man# = Man# * -1#
    x# = .0078125
    FOR T% = 5 TO 2 STEP -1
        x# = x# / 256#
        Man# = Man# + (ASC(MID$(P6R$, T%, 1)) * x#)
        NEXT T%
    P6RtoDBL# = (Man# + 1#) * (2# ^ (Ex% - 1))
    END FUNCTION

FUNCTION DBLtoP6R$ (DBL#)
    R$ = STRING$(6, 0)
    IF DBL# = 0 THEN GOTO zero
    Ex% = INT(LOG(ABS(DBL#)) / LOG(2#)) + 129#
    MID$(R$, 1, 1) = CHR$(Ex%)
    Man# = (DBL# / 2 ^ (Ex% - 129) - 1) * 128#
    M% = INT(Man#)
    IF M% < 0 THEN M% = 128 - M%
    MID$(r$, 6, 1) = CHR$(M%)
    FOR T% = 5 TO 2 STEP -1
        Man# = (Man# - M%) * 256#
        M% = INT(Man#)
        MID$(R$, T%, 1) = CHR$(M%)
        NEXT T%
zero:
    DBLtoP6R$ = R$
    END FUNCTION

This is still rather messy, so here are some useful values:

Decimal value             Pascal 6-Byte Real encoding (Hexadecimal)
       0.25               7F 00 00 00 00 00
       0.3                7F 99 99 99 99 19
       0.4                7F CC CC CC CC 4C
       0.5                80 00 00 00 00 00
       0.6                80 99 99 99 99 19
       0.7                80 33 33 33 33 33
       0.75               80 00 00 00 00 40
       0.8                80 CC CC CC CC 4C
       0.9                80 66 66 66 66 66
       1.0                81 00 00 00 00 00
       1.1                81 CC CC CC CC 0C
       1.2                81 99 99 99 99 19
       1.25               81 00 00 00 00 20
       1.5                81 00 00 00 00 40
       1.75               81 00 00 00 00 60
       2.0                82 00 00 00 00 00
       2.5                82 00 00 00 00 20
    1000.0                8A 00 00 00 00 7A
  100000.0                91 00 00 00 50 43
 1000000.0                94 00 00 00 24 74
10000000.0                98 00 00 80 96 18

125-Byte Sector-data Type - This is a very straightforward data arrangement,
 consisting of 1000 consecutive bits, each representing a sector.  A bit value
 of 1 means the sector is explored or avoided (depending on the file) and a
 value of 0 means it is not.  However, despite the simple layout, it is
 relatively difficult to access and change this data, because there are very
 few programs that will do binary editing.  Therefore, I've included some more
 of my own code, again in compiler BASIC (it's actually MicroSoft QuickBASIC
 version 4.5) to translate the 125-Byte Sector-data type in an easier format,
 and translate it back, in case you want to make changes.

DIM AllofThem AS STRING * 125  'Holds the data for a specific player #, lifted
                                 'directly from AVOIDS.DAT or TRAVELS.DAT
DIM Sector(1000) AS STRING * 1 'Array with a byte for each sector, 0 for
                                 'unavoided/unexplored, 1 for avoided/explored

'First read the data from the AVOIDS.DAT file or TRAVELS.DAT file, then
'convert it to an easy-to-manipulate format (the Sector array)
FOR T% = 1 TO 1000  'Transfers the data from AllofThem to the Sector array
    Y$ = MID$(AllofThem, ((T% - 1) \ 8) + 1, 1)
    B% = T% MOD 8 - 1
    IF B% = -1 THEN B% = 7
    B% = 2 ^ B%
    IF ASC(Y$) AND B% THEN Sector(T%) = CHR$(1)
    NEXT T%
'Now digest and manipulate the Sector array.  If you make any changes to the
'array, you will have to re-convert it to the TW format, then re-write it.
FOR C% = 1 TO 125 'Transfers the data from the Sector array to the AllofThem
    B% = 0        'string, which can be written back to the data file
    FOR T% = 1 TO 8
        IF Sector((C% - 1) * 8 + T%) = CHR$(1) THEN B% = B% + 2 ^ (T% - 1)
        NEXT T%
    MID$(AllofThem, C%, 1) = CHR$(B%)
    NEXT C%

TW COLOR CODES:
~~~~~~~~~~~~~~~
Color codes in TradeWars are imbedded in the output strings and take the
format of a tilde (~) plus a letter or number indicating the new color.
~0 -fg=bright white, bg=black
~1 -fg=cyan, bg=black
~2 -fg=yellow, bg=black
~3 -fg=magenta, bg=black
~4 -fg=bright white, bg=blue
~5 -fg=light green, bg=black
~6 -fg=blinking light red, bg=black
~7 -fg=yellow, bg=black
~8 -fg=the old fg blinking, bg=black
~9 -fg=black, bg=old fg (but dark, even if old fg was bright)
~A -fg=grey, bg=black
~B -fg=light red, bg=black
~C -fg=light green, bg=black
~D -fg=yellow, bg=black
~E -fg=light blue, bg=black
~F -fg=light magenta, bg=black
~G -fg=light cyan, bg=black
~H -fg=bright white, bg=black
~I -fg=blue, bg=white (dull white)
~J -fg=red, bg=white (dull white)
~K -fg=yellow, bg=blue
~Z -print 2 blinking red/white spaces, then bg=black
~a -fg=black, bg=black
~b -fg=red, bg=black
~c -fg=green, bg=black
~d -fg=brown, bg=black
~e -fg=blue, bg=black
~f -fg=magenta, bg=black
~g -fg=cyan, bg=black
~h -fg=white (dull white), bg=black
~i -bg=black
~j -bg=red
~k -bg=green
~l -bg=brown
~m -bg=blue
~n -bg=magenta
~o -bg=cyan
~p -bg=white (dull white)
~q -fg=blinking light blue, bg=black
~r -fg=blue, bg=black
~anything else -bg=black
You may use multiple codes in a string.  Codes DO count as part of the string
for length purposes.

ABOUT THE AUTHOR:
~~~~~~~~~~~~~~~~~
I am the author of two utilities for Trade Wars 2002...  Here:
    AEDIT - Edits all the above files that cannot be adequately edited with
            TEDIT or text editors. (Unless I have forgotten something.) Also
            implements optional external features, such as a wandering planet,
            bank interest, random cloaking device failures, planetary shield
            limitations, and evil starship regulation/destruction.
    WEEBANG - A post-BIGBANG treatment for Trade Wars that re-shuffles the
            sectors and nebulae into a 'classic' 40x25 grid, which can be
            mapped much more easily than the BIGBANG universe.  Optionally
            adds custom nebula names and sector coordinates.  Also, gives the
            sysop a convenient map of the universe.

If you need to contact me, I'm available as A Godlike Suffix on a few Dallas-
area boards.  I usually read the FidoNet Trade Wars sub (and not the WWIVNET
Trade Wars sub or any of the others!  So use FidoNet!) so you can address mail
to Jason Boyd and it may well get to me.  The official distribution point for
my programs is the 24-Hour Sushi Bar at 214-458-2419, FidoNet node number
1:124/2166.  Another point is Twilight at the Boreal Feast, 214-262-2329,
where you can use the guest account (GUEST, GUEST, 0000) to check and download
the latest versions.  If you're desperate, use the sturdy US Mail:
         Jason Boyd
         1520 Steinbeck Rd.
         Red Oak, TX 75154

If you want to make a contribution, I'd be most happy, but I require no
registrations for anything.  Good luck, and happy 1993!

                                             JMB
