=== Basics

Sprites and fonts are located in dat files: charset.dat, goal1.dat, team1.dat,
team2.dat etc. Sprite.dat contains offsets for sprites, and after fix up all
that's needed to access any sprite is to index into this file. First 227
sprites are the sprites needed while the menu system is active (fonts, little
player images, faces, etc.).

Sprites are stored in bit-coded form, and they must be "uncrunched" first in
order to be used, which is job of UnchainSprite procedure. Sprites use only 16
colors, and therefore each pixel is represented with 4 bits (2 pixels = 1
byte). This is what the format of the SpriteGraphics structure looks like:

        offset  length   description
        ------  ------   -----------
           0      4      pointer to sprite pixels
           4      6      unknown, always zero in files
          10      2      exact width in pixels (nibbles)
          12      2      number of lines (nlines)
          14      2      width in paragraphs - number of pixels / 16, or
                         number of bytes / 8 (since 1 pixel = 1 nibble)
                         Some formulas:
                         ofs14 << 4 - number of pixels
                         ofs14 << 3 - number of bytes (width when copied to screen)
          16      2      x center, used range: [-8..34]
          18      2      y center, used range: [0..27], these are used only in
                         game sprites, menu sprites have it at zero always
          20      1      so far unknown, perhaps some sort of flags?
          21      1      nlines / 4, haven't seen it used anywhere so far
          22      2      sprite ordinal in sprite.dat file

For example fields 16 and 18 are used as a point in sprite from which ball
bounces off.

sprite.dat:
227 pointers are data from charset.dat (sprites used during the menu)
114 pointers to score.dat
303 pointers to team(1|2|3).dat (usually 1)
303       -||-                  (usually 2)
116 pointers to goal1.dat
116       -||-
155 pointers to bench.dat (or benc2.dat if 16 color mode is on)
1   dword - 0 - marks the end of the file

team1.dat contains pictures of players with shirts with vertical stripes
team2.dat contains pictures of players with colored sleeves
team3.dat contains pictures of players with shirts with horizontal stripes

Players with solid color shirts are created from team1.dat, by using same color
for stripes and shirt base.


   sprite.dat:                   team1.dat - array of sprite structures
(pointers to sprite
    structures)              ptr 0    +------+--------+
   +-----+-----+            +-------->|   x  |        |
   |  x  |  x  |            |         +---|--+--------+
   +--|--+--|--+            |      +--+---+           |
   |  +-----|--+------------+      |  +---------------+
   |        |  |                   +->| sprite 0 data |
   |        +--+------------+         |               |
   |     .     |            | ptr 1   +------+--------+
   |     .     |            +-------->|   x  |        |
         .                            +---|--+--------+
   |           |                   +--+---+           |
   +-----------+                   |  +---------------+
                                   +->| sprite 1 data |
                                      |               |
                                      +---------------|
                                      |       .       |
                                              .
                                              .
                                      |               |
                                      +---------------+

Despite pointers being used here, sprites are actually stored sequentially. In
each .dat file that contains sprites the order is following: sprite structure
first, immediately followed by sprite pixels. Some files differ slightly in
handling the offset fields, but they are here only to improve loading and
drawing performance.
First 227 offsets are relative to charset.dat. After that offsets start from 0
again, but now they are relative to memory block comprised of score.dat,
team1.dat (or team2.dat), team3.dat, goal1.dat (two times) and bench or
benc.dat. End of sprite.dat is marked with zero offset, which also marks the
end of last file (benc[h2].dat).
Offset to data is always relative to beginning of the file, except for
benc[h2].dat file, where offsets are relative to beginning of the joint memory
block.


=== Sprite map

Sprite 1286 has an error: width is mistakingly set to 5 pixels. It should be 16
pixels.

0-112 character set

0-56 small set:
0 - x in a box
1 - '
2 - (
3 - )
4 - ,
5 - -
6 - .
7 - /
8-17  - numbers
18-43 - letters
44 - block (cursor)
45 - *
46 - pound sign
47 - em dash
48 - ?
49 - :
50 - +
51 - %
52 - ;
53 - A with umlaut
54 - U   - // -
55 - O   - // -

56 - vertical bar
57 - invalid character symbol (x in a box)

Big character set follows, to get big character index add 57 to small character
index (except for number 56, that one's unique).

113-122 stars (for visualising player skills)

123 - ball sprite, but I haven't noticed it being used anywhere

small player sprites with team colors and shirt stripes; used in edit tactics
menu (corresponding sprites are copied into them)
124 white
125 ginger
126 black

small goalkeeper sprites, used in tactics editing
(corresponding sprites are copied into them)
127 white
128 ginger
129 black

small player sprites with single-color shirts
130 white
131 ginger
132 black

small player sprites with colored sleeves
133 white
134 ginger
135 black

small player sprites with vertical stripe shirts
136 white
137 ginger
138 black

small player sprites with horizontal stripe shirts
139 white
140 ginger
141 black

small goalkeeper sprites
142 white
143 ginger
144 black

149 - cursor during tactics editing, frame 1
150 -                -||-                  2
151 -                -||-                  3

181 - two empty sprites - they're located in edit teams menu, in invisible
182 - entries near the end

183 - up arrow (for scrolling)
184 - down arrow    -||-

player faces, used during tactics editing (perhaps elsewhere too)
186 - white
187 - ginger
188 - black

189 - empty sprite, also located in edit teams menu, as last, invisible entry

trophies
215 - Premier division champion
216 - Invitation tournament winner
217 - Cup winner
218 - ??? (unknown trophy)
219 - European Champions Cup
220 - Cup Winners Cup
221 - UEFA Cup
222 - World Championship
223 - European Championship

224 - unused game logo from the Amiga version

227-234 first scrolling ad
235-242 second   -||-
243-250 third    -||-

255-270 numbers + player names, written in top left corner of the screen, that
        mark the player with the ball
271-286 numbers + player names for team 2
These sprites are filled before the game, initially they're empty.

287-306 two sets of large digits, for result

307 - first team name
308 - second team name

310-317 - space to use for goal scorers, for team 1
318-325 -         - || -                     team 2

330 - sprite for the current game time ("118 mins." when uninitialized)

During the game, sprites [341..1178] will be adapted to colors of playing
teams. Hair and skin color are handled by having three sets of images, and
using the correct ones for each individual player. Goalkeepers have their own
images, for main and reserve goalkeeper.

team 1
341-441  set 1 (all player images - white)
442-542  set 2 (       -||-       - ginger)
543-643  set 3 (       -||-       - black)

team 2
644-744  set 1 (all player images - white)
745-845  set 2 (       -||-       - ginger)
846-946  set 3 (       -||-       - black)

947-1004  team1 main goalkeeper
1005-1062 team1 reserve goalkeeper

1063-1120 team2 main goalkeeper
1121-1178 team2 reserve goalkeeper

team1 bench players
1310-1315 sitting
    1310 - white goalkeeper
    1311 - ginger goalkeeper
    1312 - black goalkeeper
    1313 - white player
    1314 - ginger player
    1315 - black player
1316-1321 standing

team2 bench players
1322-1327 sitting
1328-1333 standing


=== Sprite decoding algorithm

- line is split in four "planes", 0, 1, 2 i 3 (wquads * 8 / 4)
- each pixel consists of four bits
- each pixel is composed out of one bit from each plane
- first pixel is composed of highest bits from plane 3, 2, 1, 0 in that order
- second pixel is composed of next bits
- we move bit by bit to the right, until the end of the line
- this process is repeated nlines times, until all lines are processed


=== In-game sprite structure

This structure is mostly tied to players but other entities are represented as
well, such as the ball and corner flags.

offset  length  description
------  ------  -----------
   0        2   team number, 1 or 2 for the players; for the ball, referee, corner flag = 3
                0 = sprites that are not shown in the highlights
   2        2   player ordinal (shirt number)
   4        2   ??? (zero during the game)
                perhaps some sort of picture offset for some specific sprite
   6        4   pointer to an animation table, it changes depending if the
                player is running, tackling or heading; can change without
                ball (say rolling on the pitch injured, or getting booked)
                table structure:
                - first word is the number of cycles between image transitions
                - after that the array of 32 pointers to image indices tables
                  follows; they are actually grouped into 4 categories of 8
                  pointers each:
                    0 - player, team 1
                    1 - player, team 2
                    2 - goalkeeper, team 1
                    3 - goalkeeper, team 2
                - inside the category pointer is indexed based on sprite
                  direction 0..7
                - in the table some special values exist:
                    = -999  - reset frame index to zero (start over the animation)
                    = -101  - subtract one from the frame index (effectively pauses the last frame)
                    <= -100 - add 100 + this to the frame index (skip forward this many frames)
                    -99..-1 - negate, add to frame delay and write to timer (seems to be delay value)
                    >= 0    - image index, just assign to sprite
  10        2   initial direction for the animation
  12        1   player state
                - if it's non-zero, player is not marked
                - ball has it 255 constantly (but check this again)
                - known values are:
                    0  - running
                    1  - tackling
                    3  - on the ground (tackled)
                    4  - for the goalkeeper, jumping in place, boxing or catching the ball
                    5  - performing a throw-in
                    6  - for the goalkeeper, diving, low ball
                    7  - for the goalkeeper, diving, high ball
                    9  - heading
                    12 - being booked
                    13 - injured
                    14 - sad, lost the game
                    15 - happy, won the game
                other possible values are: 8, 10, 11 - anything else results in
                program crashing
  13        1   count-down of how long the player will stay on the ground after
                being tackled; actually how long the player will be
                "inoperable"; this field is also used when player takes
                throw-in, heads the ball, etc...
  14        2   ??? (ball has it 0 always)
  16        2   something related to x
  18        2   something related to y
                for referee, player and ball shadow this is a dword, pointer to
                something; dword from sprite table is written here; seems to be
                a pointer to an array of picture indices, extracted from table at offset 6
  20        2   might be continuation of previous field
                seems like field 18 is a pointer to array of indices of
                pictures of sprites that are shown (array of words), array
                seems to end with a negative member
                could be a union, since there are places where ofs18 is used as
                a word
  22        2   index of currently shown picture
  24        2   ??? write first word from sprite tables
                could be number of pictures, or the highest index
  26        2   cyclic timer for images, ticks whenever the sprite is visible
                once it goes down to zero, next frame is drawn
  28        2   unlimited image timer, incremented each time sprite picture is changed
  30        4   x coordinate in fixed point signed word.signed word (+2 offset contains the whole part)
  34        4   y coordinate in fixed point
  38        4   z coordinate in fixed point (makes sense only for the ball)
                -1 when player is controlling the ball
  42        2   player facing direction, 0..7 (0 = up, 4 = down...)
                       0
                   7   |   1
                     \ | /
                  6 ---+--- 2
                     / | \
                   5   |   3
                       4
                for the ball -1 if out of the game
  44        2   sprite speed, signed Q7.9 fixed point (seven upper bits including the sign and nine fractional
                bits). 512 represents one pixel per game tick before platform-specific movement scaling.
                CalculateDeltaXAndY() multiplies this value by a signed Q1.15 direction component and shifts the
                result right by 8, producing a signed 16.16 delta. The original-compatible path shifts the
                direction component first and therefore preserves the original loss of precision.

                The PC movement path subsequently multiplies x/y deltas by 41/64 (0.640625); Amiga movement does
                not. Thus, before PC scaling and for an exact cardinal direction, speed / 512 is the movement in
                pixels per tick. Some speeds for comparison:
                    players: 928, 974, 1020, 1066, 1112, 1158, 1204, 1250
                             (depending on the speed skill)
                    referee = 1024
                    ball kicked = 2560
                    ball high kicked = 2688
                    goalkeeper diving = 1024..2048
                    player after doing static header = 256
                    player after doing strong header = 1726
  46        4   delta x, fixed point word.word (per frame movement by x)
  50        4   delta y, fixed point word.word (per frame movement by y)
  54        4   delta z, fixed point word.word (per frame movement by z)
  58        2   destination x, whole part only
  60        2   destination y, whole part only
  62        6   ??? (ball sprite: 62, 64 = 0, 66 = -1 const.)
  68        2   is sprite visible? !0 - yes, 0 - no
  70        2   sprite picture index, if negative no image
  72        2   save sprite background pixels flag: 1 = don't save, !1 = save
  74        4   sqr(player x - ball x) + sqr(player y - ball y)
  78        4
  82        2   direction (0..255), arranged as direction at offset 42
  84        2   was sprite drawn in previous cycle? 0 = no, 1 = yes
                is ball out of play, or with goalkeeper
  86        2   ??? maybe true for a player, false for a goalkeeper
                always zero in ball sprite
                is goalkeeper playing like an ordinary player
  88        4   ??? always zero in ball sprite
  92        2   direction player is facing 0..7 (0 = up, 4 = down...)
  94        2   if the player is moving, value is 255, if standing 0
                (treated as a byte)
  96        2   0 = tackle started
                to go into states below, player must be at 64 or less units away from the ball, and the ball height
                has to be 8 or less:
                1 = player tackled the ball (or bad tackle?)
                2 = good tackle (opponent has a player that's controlling the ball, but he's 9 or more units away
                from it and distance between two players is more than 32 units -- why 32? maybe takes some time to
                get into perfect tackling position)
                it could be tackle state, 1 if player tackling, 2 for
                successful tackle (player manages to pick up the ball)
  98        2   set to 1 when player is heading (any type)
 100        2   some sort of state when game is stopped, when they're running to their positions
                values: 0,1,2,3
                initialized to 1 when the game is starting
                3 is when they're arrived at their destination and are ready for kick off
                seems to be initialized to 1, if ofs 142 of team != 0 (for players), for goalkeepers = 3
                in MovePlayers(), if the ball is out of play and it's 1, set it to 2
 102        2   if < 0 the player has a red card, if > 0 the player has a yellow card
                if zero no cards
 104        2   seems like something about injuries, seems if -2 => injury
                can be -1 and -2
                injury level, starting value for injury timer (how long the
                player would be rolling on the grass) (byte)
                values 60, 70 and 80 have been observed
 106        2   counter, decreases by 1 while the player is tackling
                can increase by 1, unknown why
                only changes while the player is near the ball
 108        2   was the player sent off? (got a red card)
                (1 = true)

Length 110 bytes.


=== Sprite color conversion

Colors:

 0 - \
 1 - +- no change
 2 - |
 3 - /
 4 - skin color (darker shade) <108, 136, 0>
 5 - skin color (medium shade) <180, 72, 0>
 6 - skin color (brighter shade) <252, 108, 0>
 7 - goes to zero <108, 108, 108>
 8 - no change
 9 - hair color (medium shade) <72, 72, 72>
10 - basic shirt color <252, 0, 0>
11 - shirt stripe color (gets swapped with 10 in case of vertical stripes) <0, 0, 252>
12 - hair color (darker shade) <108, 0, 36>
13 - hair color (brighter shade) <144, 144, 252>
14 - shorts color <36, 144, 0>
15 - socks color <252, 252, 0>

- result digits (287-306) are color converted where only colors 10 and 11 are converted to white
  (weird conversion I might say)
- bench players (1310-1321 team1, 1322-1333 team2):
    2x standing/sitting
    2x goalkeepers/players
    3x skin color (white/ginger/black)
  total: 12
  colors:
    15 - primary shirt color
    11 - shirts are single-color (shirt color == stripes color) ? shorts color : stripes color
- make 3 groups of duplicated player sprites, one for each skin color, and convert colors;
  goalkeepers aren't duplicated, they are converted to real skin/hair color

    341-441  team1 white
    442-542  team1 ginger
    543-643  team1 black
    947-1004 team1 main goalkeeper
   1005-1062 team1 reserve goalkeeper
    644-744  team2 white
    745-845  team2 ginger
    846-946  team2 black
   1063-1120 team2 main goalkeeper
   1121-1178 team2 reserve goalkeeper

  colors converted:
    color 10 - shirt type == vertical stripes ? shirt color : stripes color
    color 11 - shirt type == vertical stripes ? stripes color : shirt color
    color 14 - shorts color
    color 15 - socks color

The split into 3 groups of players according to skin color is later used in
InitializePlayerSpriteFrameIndices(). This routine knows how to select the proper sprite index based on the
player color. As for the goalkeepers there is no need to do that, as they already have their proper skin color
applied.


=== Miscellaneous

- player who scored raises arms in celebration in 78.90625% frames, while his teammates do it in 50%
