=== Various data about the game itself

=== Player speed

Speed of the player that controls the ball is reduced to 87.5% of capacity
(that's why defenders catch up so easily). When the goal is scored, and the
players are running back to their positions, their speed is reduced to 62.5%
of capacity.

Based on players speed skill (range normalized to 0..7), and whether the game
is in progress or not, effective speed is calculated using the following
tables:
dw 928, 974, 1020, 1066, 1112, 1158, 1204, 1250     ; game in progress
dw 1136, 1152, 1168, 1184, 1200, 1216, 1232, 1248   ; game stopped

1280 seems to be the maximum player speed. Number of game frames between next
animation frame switch is determined by subtracting player speed from maximum
speed (1280). Result is further divided by 128, increased by 6 and that's how a
delay between animation frames for the players is formed. Notice that this
system forces larger delay for slower players.

The highest three bits of offset 35 in the in-game structure determine injury
severity. They are used as an index into the table:
dw 0, -96, -128, -160, -192, -224, -256, -288
and the negative value is added to the player's calculated speed. Computer
players are immune to injuries (presumably because the computer does not know
how to make substitutions :P).

The speed of a tackling player is multiplied by 0.78125, except for a computer
player, when it is multiplied by 0.5.

After a kick, ball speed is reduced to 87.5% for a diagonal direction and to
75% for other directions. After a pass, ball speed is increased to 112.5%.

The controlled player's destination x and y apparently get set through the
kDefaultDestinations table; in the game I saw the controlled player's
destination x set to x +/-1000 regardless of whether he controls the ball. It
appears that destination x/y offsets for both ball and player come from it.


=== Ball after-touch

After-touch is handled in ApplyBallAfterTouch(). The routine handles after
touch in kicks and passes and triggers high kicks (lobs).

Ball after-touch is applied equally to both normal and high kicks.

If a pass is in progress, the code checks whether the opposing goalkeeper has
caught/is holding the ball and whether play is in progress. The spin timer must
be running: value 0 (the spin variables are reset) or greater. If it is less
than zero, spin is not in progress.

Table containing ball destination x and y offsets while spin is in progress:
kPassingSpinFactor dw -16, 0, 16, 0, 0, -11, 11, 0, 0, -16, 0, 16, 11, 0, 0,
    11, 16, 0, -16, 0, 0, 11, -11, 0, 0, 16, 0, -16, -11, 0, 0, -11
It is indexed as follows:
0 - left spin x   \
1 - left spin y    |
2 - right spin x   +-> ball direction 0
3 - right spin y  /
4 - left spin x   \
5 - left spin y    |
6 - right spin x   +-> ball direction 1
7 - right spin y  /
        .
        .
        .

In a more readable form:

 Direction 0  | (up):         left spin(-16, 0), right spin(16, 0)
 Direction 1  / (up-right):   left spin(0, -11), right spin(11, 0)
 Direction 2  - (right):      left spin(0, -16), right spin(0, 16)
 Direction 3  \ (down-right): left spin(11, 0),  right spin(0, 11)
 Direction 4  | (down):       left spin(16, 0),  right spin(-16, 0)
 Direction 5  / (down-left):  left spin(0, 11),  right spin(-11, 0)
 Direction 6  - (left):       left spin(0, 16),  right spin(0, -16)
 Direction 7  \ (up-left):    left spin(-11, 0), right spin(0, -11)

Once the spin type is determined, the values are simply added to the ball's
destination x and y.

=== Kick

The kick is applied after 4 ticks, increasing the ball's delta z. The code also
checks whether the player jerked backward; if so, lob-kick values are used.
Afterward ball speed is reduced to 87.5% for a diagonal direction and to 75%
for other directions.

=== Pass

The AI has a certain chance to botch the pass. It happens only during the game,
and depends on player's passing skill. There's a table with chances:
6, 4, 3, 2, 1, 0, 0, 0
Table is indexed by player's passing skill, and the value is compared to bits
1-4 from current tick counter shifted one position to the right (0..15). If the
value from the table is less than the counter bits value, the pass is botched.
Translated to probabilities:
37.5%, 25%, 18.75%, 12.5%, 6.25%, 0%, 0%, 0%
So the elite passers never make such rookie mistakes ;) Bad pass has an angle
messed up: it's initially aimed to the correct player position, but then one
dimension gets divided by 2 which ruins it. The ball destination x and y are
set to: current ball x/y + (player x/y - ball x/y) * 32, or 16. Whether it's 16
or 32 is decided by game tick counter bit 5: if set multiply x by 32 and y by
16, if clear vice versa. When multiplying with 16, the delta value is first
shifted to the right once, so it losses the least significant bit.

=== Lob kick

Lob kick test starts 4 ticks after kick has been initiated. If controls are
pressed in directions: back, back-left, back-right in regards to the player
controlling the ball, lob kick ensues. In case of perpendicular directions
(left/right), or no direction at all standard kick happens.

=== Ball speed when kicking

[subtract 16 from y coordinates]
A kick is considered a shot on goal when the player's y is <= 342 (attacking
upward), or >= 556 (attacking downward), and he faces roughly that way
(directions 0,1,7 and 4,3,5). There's another condition that decides whether to
use player's shooting or finishing skill: if it's a more precise shot, more
toward the goal -- if x is between 241 and 431 inclusive, and y is < 204
(upward) or > 694 (downward), player's finishing skill would be used as an
index into a kBallSpeedFinishing table:
dw -288, -160, -32, 96, 224, 352, 480, 608  ; stronger shot/higher ball speed
Value from the table is added to base ball kick speed (= 2208) and forms the
final ball speed.
Otherwise, player's shooting skill is used to index into a kBallSpeedKicking
table:
dw -384, -270, -162, -54, 54, 162, 270, 384


=== Tackling

A player spends 55 frames in the tackling state, although it can be fewer if
a certain variable is set. During a tackle, speed is reduced to 78.125% (or
50% for the computer). If the opposing controlled player is more than 9 units
from the ball and the distance between the two players is over 32 units, this
is considered a good tackle (and the good-tackle commentary is played). Units
are: sqr((x1 - x2) ^ 2) + sqr((y1 - y2) ^ 2).


=== Winning the ball/movement

The player must be very close to the ball (d <= 32u), and the ball must be near
the ground (ball z below 8). It appears that a player stops after leaving the
pitch unless a direction leading farther off the pitch is held (perhaps some
inertia). Bounds of the playable area:
79 <= x <= 592
11 <= y <= 111


=== Injuries

Each team has a variable that holds the number of allowed injuries. For a
friendly game 4 injuries are allowed, otherwise number of players unable to
play the match is calculated, and the number of allowed injuries is 4 - num.
disabled players for career, or 2 - n.d.p otherwise.
When sending off the player number of injuries is decremented too (be it direct
red or or double yellow card).


=== Game's coordinate system

x increases to the right, y increases downward, z increases upward (height).

 +--------> x
 |
 |
 |
 v
 y


=== Animation

Special tables are used for player animations. They always start with a word:
the number of frames to wait between images (frame delay). Next comes a list of
pointers. Each points to a list of words (image indices) ending in -999 or -101.
-999 marks the end, after which animation restarts (an infinite-loop animation).
-101 marks the end of a non-repeating animation (I think the last frame remains
displayed). For an index <= -100, 100 is added, converting it to 0, -1, -2,...;
it is then added to the frame index. Thus it is a negative backward index:
return to the nth previous frame, probably for partially repeated animations.
Negative indices in the range -99..-1 specify a new frame-delay value. After
the variables are set, processing continues with the next index.

Main table format:
dw frameDelay
8 pointers to tables for first-team players, one for each direction
           - || -        second team,             - || -
           - || -        first goalkeeper,        - || -
           - || -        second goalkeeper,       - || -

It is indexed for a player by team number * 4 + direction, yielding a pointer
to the image list. I think the goalkeeper section (16 additional pointers) may
be absent if they are certain the table will never be called for him (but if it
is--crash!).

For a standard player in the normal state, playerNormalStandingAnimTable and
playerRunningAnimTable are used. 3200 appears to be the distance at which a
player starts chasing the ball.


=== Ball

The ball bounces according to the pitch type, based on this table (z):
88, 112, 104, 104, 96, 88, 80
When bouncing, speed is multiplied by factors from the following table:
24, 80, 80, 72, 64, 40, 32


Those are the values.

=== Important locations that should be examined in more detail

CalculateDeltaXAndY()
SortSprites()
DrawSprites()
UpdateControlledPlayer()
MovePlayers()
UpdatePlayerWithBall()
CalculateBallNextXYPositions()
UpdateBallWithControllingPlayer()
CalculateNextBallPosition()
AIKick()
UpdatePlayerSpeed()


=== Setting player numbers (above their heads)

Done in SetCurrentPlayerNumber, at offset 0x16c.


=== Limit on the number of leagues in a country

The menu displaying them reserves 10 league entries. Without code changes,
that is the maximum this menu can hold.


=== Main-loop frequency

1193181 (PIT timer frequency) / 17045 = 70.00181871517
Approximately 70 hertz, i.e. 70 frames per second.

=== Game state

The gameState variable:
 0 - ...
 1 - upper-right, lower-left goal kick
 2 - upper-left, lower-right goal kick (treated identically)
 3 - ...
 4 - upper-left, lower-right corner
 5 - upper-right, lower-left corner (treated identically)
 ...
28 - end of the first period of extra time

       y:

left half of the pitch:
15 - [556..753] (right team)
16 - [342..555]
17 - [  0..341]
18 - [  0..341] (left team)
19 - [342..555]
20 - [556..753]

right half of the pitch:
15 - [  0..341] (left team)
16 - [342..555]
17 - [556..753]
18 - [556..753] (right team)
19 - [342..555]
20 - [  0..341]

+-------+-------+
| 18/17 | 15/20 |
+-------+-------+
| 19/16 | 16/19 |
+-------+-------+
| 20/15 | 17/18 |
+-------+-------+

=== Goalkeeper

"Reach": +/-12 along both x and y
Bounds of the goalkeeper's x-axis "wandering": 285..387

When diving, he is inactive for 75 frames.


=== Time keeping

Function UpdateTime is responsible of advancing match timer. It is called each
frame, from core game loop. Game seconds advance based on
secondsSwitchAccumulator variable. In each frame variable timeDelta gets
subtracted from it, and if the result strictly less than zero one game second
has elapsed. timeDelta values depend on game length selected in options:
3 mins - 30, 5 mins - 18, 7 mins - 12, 10 mins - 9. Once accumulator gets below
zero, 54 is added to it. This is actually wrong, and has caused shorter matches
on PC version, which went unnoticed for about 20 years :). Proper value is 70
and it's fixed in SWOS++. It can also be patched with hex editor, file offset
is 0x1038aa, value 0x36 needs to be changed to 0x46.
When game seconds are incremented, they are increased by a value from variable
timerDifference, which represents number of ticks passed between this and last
frame (it will be at least 1).


=== Misc.

allSpritesArray contains all the sprites that the game draws in a single frame.


=== Team ofs 24 for goalkeepers

Indexed based on skill (which is itself calculated based on price):
TODO
