Star Corps: Mission Zero - Random Notes

User Interface Sections
  Logo->Title->New Game Settings?->Game Proper

Design Decision: Implement the data structures for the full game?
  Pros:
    I can make better decisions on what's in the demo.
    Code will be more reusable in the full game.
  Cons:
    Getting sucked in to partial implementations of full game.
  Examples:
    Should I implement multiple maps per game?
    How far should I go in implementing skills?

Game Object Components
  Map
  Units
    on the map
    in reserve?
  Items
    on the map
    in characters' inventories
    in reserve?

Characters (Units)
  Attributes:
    Type:
      Needed for graphic (at least) in full game.
      Team can decide graphic in the demo instead.
      Type can help with auto generation.
    Team:
      Teams themselves will include array of units.
      Therefore not needed unless for speed.
      In which case cache would be better.
    Rank: index? or 1..12 characters.
    Name: 1..12 characters.
    Basic stats
      Strength 2..12
      Agility 2..12
      Endurance 2..12
    Changing stats
      Action Points: 0..24? 36?
      Health: 0..24? 36?
    Skills
    Inventory
      Items in use (diamond in interface)
      Items in backpack (rectangle in interface)
      Both could be array of pointers to items.
    Location:
      This would also be reflected on the map.
      So it might not be needed as part of the character.
  Methods:
    Basic set/gets.
    Generate?
      In the full game, might be better as method of Type.
      In the demo game, either
        a method of Unit
	or a method of prototype Type.

Types
  Player
    Marine <- in demo
    Hostage
  Rebels
    Grunt
    Rebel <- in demo
    Leader
  Pirates
  Aliens
  Robots

Items
  Knife <- in demo
  Laser Pistol <- in demo
  Laser Rifle <- in demo
  Medikit <- in demo
  Datacard <- in demo
  Helmet <- in demo
  Armour <- in demo
  Grenade
  Mine?

Skills
  Light Blade <- in demo
  Heavy Blade
  Light Firearms <- in demo
  Heavy Firearms <- in demo
  Medicine <- in demo
  Explosives
  Computing
  Electronics
  Stealth <- in demo?
  Pilot

Furniture & Fittings
  Cabinet
  Computer
  Table <- in demo
  Chair <- in demo
  Door <- in demo
  Locked Door
  Elevator
  Ladder
  Spawner
  Teleporter

Map Object
  Visible aspects
    Level map (from library)
    Unit map (cache)
    Item map (cache)
  Invisible aspects
    Line of sight
    Paths

Line of Sight Algorithm
  Run for each enemy
    Initialise all map squares to "unknown"
    Set enemy's square to "visible"
    For each edge square,
      starting at the top left of the map,
      proceeding clockwise around the edge:
      Initialise last unknown seen
      Initialise last block seen
      For each square between the edge and the enemy,
        stopping at the first square already seen:
	Set last unknown seen to this square
        If square is block:
	  Set last block seen to this square
      For each square between the edge and the last unknown seen:
        If before last block seen,
	  Set this square to "hidden"
	Else
	  Set this square to "visible"
    Copy squares' seen/unseen values to line of sight grid

Tutorial Mode (a Proposal)
  Activated the first time a player enters the game.
  Possibly accessed through the Menu Screen.
    This setting can be changed during a game.
  Popups will appear at key points:
    On entering the map, "Place first unit at the entrance".
    On placing the unit "Move the unit to an adjacent square".
    On moving the unit, "Continue moving, select 'next unit' when done".
    On sighting an enemy, "Enemy has been sighted! Attack or retreat".
    On placing the last unit, "Continue moving, select 'end turn' when done".
    On completing the mission, "Return to the entrance".


Lines of sight at start of turn bug    

Units visible at the end of the last turn are no longer visible on the map.
Moving within sight of the units makes them appear again. If the square my unit was standing on was a door, moving out of the room and back in again will make the units reappear. This proves that the line of sight calculation *is* correctly determining which enemies are visible from the square on which my unit stands.

For some reason, it seems that the overall visibility mask, which I am setting (I logged the proof), isn't staying set when it comes to display the map, and is also unset when we move around the map. i.e. the units aren't drawn, and then the game is once again surprised to see those units that we knew were there.

To do:
- Continue logging the visibiility flags right up until we draw the map.
- See at what point the flags are either reset, or ignored.


Stepping over prone units

Dead units shouldn't be regarded as units (bit 0x80) in the map blocks. This prevents them from blocking movement and vision.

When stepping over a corpse, the unit should remember whose corpse they are standing over. This can be a simple unit pointer in the unit record.

When stepping away from the corpse, the corpse's information should be returned to the map cache, and the unit's "corpse" counter should be updated.


Inventory Cursor

Simple variable recording 0..9 in the first inventory, 10..19/21 in the second.
Algorithm for RIGHT:
  if 0, 3.
  if 1/2, +1.
  if 4/5, +1.
  if 7/8, +1.
  if 3/6/9 and dual, 11/14/17.
  if 3/6/9 and cabinet, 10/16/19.
  if 10 and dual, 13
  if 11/12 and dual, +1.
  if 14/15 and dual, +1.
  if 17/18 and dual, +1.
  if 10/11 and cabinet, +1.
  if 12/13 and cabinet, +1.
  if 15/16 and cabinet, +1.
  if 18/19 and cabinet, +1.
  otherwise fail.
Algorithm for LEFT:
  if 0, 1.
  if 2/3, -1.
  if 5/6, -1.
  if 8/9, -1.
  if 10 and dual, 11.
  if 12/13 and dual, -1.
  if 15/16 and dual, -1.
  if 18/19 and dual, -1.
  if 11/14/17 and dual, 3/6/9.
  if 11/12 and cabinet, -1.
  if 14/15 and cabinet, -1.
  if 17/18 and cabinet, -1.
  if 20/21 and cabinet, -1.
  if 10/13 and cabinet, 3.
  if 16/19 and cabinet, 6/9.
  otherwise fail.
Algorithm for UP:
  if 1/2/3, 0.
  if 4-9, -3.
  if 11/12/13 and dual, 10.
  if 14-19 and dual, -3.
  if 13-19 and cabinet, -3.
  otherwise fail.
Algorithm for DOWN:
  if 0, 2.
  if 1-6, +3.
  if 10 and dual, 12.
  if 11-16 and dual, +3.
  if 10-18 and cabinet, +3.


Opportunity Attacks

Detection
  Maintain a bit-field of who *can* fire (action > 6).
  On each player move,
    And sightlines for htis square with bit field of who can attack.
    For each enemy that can attack:
      process the attack,
      show the animation,
      Reset the can-attack bit for that enemy.


Data Refactoring to Avoid Bug

Freeing the hostage in a Hostage mission means they're no longer a
hostage, which makes the game crash when reprinting the briefing,
because the hostage data is missing. These are the steps to correct
this:

1. Merge the game and mission classes.

2. Don't add hostages to units; leave them where they are.

3. Only include unfreed hostages in player line of sight calculations.

4. Do cycle through both units and hostages for "Next unit"

5. Ensure display->updatemapsquare processes hostages properly: show
   freed hostages automatically; show unfreed hostages only according
   to line-of-sight.

6. Enemy units should shoot freed hostages during opportunity fire.


Surprise

Basic algorithm
  When unit first becomes visible:
    check for initial surprise
  When unit moves within sight of unit:
    check for continued surprise
Check for intiial surprise:
  If stealth successful or natural surprise,
    Unit is surprised
  else
    unit is not surprised
Check for continued surprise:
  If stealth successful,
    Unit is surprised,
  else
    unit is not surprised.


End Game Screen

Layout
  ....................................
  ..............XXXXXXX!..............
  ....................................
  ....................................
  ...........Health:.999%.............
  ....................................
  ............Kills:.999%.............
  ....................................
  .........Hostages:.999%.............
  ....................................
  ............Cards:.999%.............
  ....................................
  ............Speed:.999%.............
  ....................................
  ....................................
  ..........Overall:.999%.............
  ....................................
  ....................................


Ascertaining Victory

Algorithm
  If Assassination,
    Check that character 0 is dead.
  If Annihilation
    Check that any enemies are dead.
  If Hostage
    Check that a hostage is on the team.
  If Rescue
    Check that any hostages are on the team.
  If Retrieval
    Check that a character is carrying a data card.
  If Gathering
    Check that a character is carrying a data card.


Score Table Screen

Layout
  ....................................
  ..SCORES..........Easy..Fair..Hard..
  ....................................
  ..Assassination...###%..###%..###%..
  ....................................
  ..Annihilation....###%..###%..###%..
  ....................................
  ..Hostage.........###%..###%..###%..
  ....................................
  ..Rescue..........###%..###%..###%..
  ....................................
  ..Retrieval.......###%..###%..###%..
  ....................................
  ..Gathering.......###%..###%..###%..
  ....................................
  ....................................
  ..Average.........###%..###%..###%..
  ....................................


New Game Screen

Layout
  ....................................
  ....................................
  ....................................
  ...........Level:.XXXX..............
  ....................................
  ............Type:.XXXXXXXXXXXX......
  ....................................
  ....................................
  ..........Unit.1:.XXXXXXXX..........
  ....................................
  ..........Unit.2:.XXXXXXXX..........
  ....................................
  ..........Unit.3:.XXXXXXXX..........
  ....................................
  ..........Unit.4:.XXXXXXXX..........
  ....................................
  ....................................
  ....................................


AI Structure

General concepts.
  There is an AI structure for each unit.
  The AI for each unit is persistent,
    so needs to be stored in the game object,
    and must be loaded and saved.
  The AI structure needs to be linked to a unit (by ID perhaps).
  It needs to store the current order (Idle, Patrol, Guard).
  It needs to store the current investigate location.


Title Screen Composition

Overview
  Still Life
  Contains objects from the game
  Surface is either:
    plain darkness (background colour), or
    pool of light on a (purple?) coloured or decorated plane.
  Objects
    Helmet
    Medikit
    Laser pistol
    Data card.
Item Descriptions
  Helmet
    Overall cyan colour
    Shape: conical expanding upwards, with a domed top and face cut-out.
    Some kind of red emblem on the forehead.
    Antenna on one side.
    Optional reflective visor, possibly raised?
  Medikit
    Plain white box with groove separating box and lid.
    Red "H" on the front.
    Some kind of cyan clasp.
    Optionally slightly open, revealing some contents.
  Laser Pistol
    1950s style laser pistol design.
    Standard pistol shape.
    Cyan body and handstock.
    Red discs around the barrel.
    Maybe a red or white sphere on the muzzle?
  Datacard
    SIM shape with single cut corner.
    Red overall in colour.
    White coloured grooves as detail.
    Rectangular recess.


Noises

List of noises:
  Movement
    low beep
    Pat:rising Rep:1 Lo:24 Hi:24 Dur:1 Pau:0
  Shooting
    pewpew
    Pat:falling Rep:2 Lo:0 Hi:60 Dur:3 Pau:0
  Stabbing
    high noise/beep?
    Pat:rising Rep:1 Low:48 Hi:60 Dur:2 Pau:0
  Hitting
    low noise/beep?
    Pat:rising Rep:1 Low:24 Hi:36 Dur:2 Pau:0
  Unconsciousness
    low noise/beep?
    Pat:rising Rep:1 Low:12 Hi:24 Dur:2 Pau:0
  Death
    descending beep
    Pat:falling Rep:1 Lo:36 Hi:48 Dur:7 Pau:0
  End of computer turn
    comms noise
    Pat:rising Rep:4 Lo:60 Hi:60 Dur:1 Pau:1


Line Algorithm for Line of Sight

plotLine(x0, y0, x1, y1)
    dx = abs(x1 - x0)
    sx = x0 < x1 ? 1 : -1
    dy = -abs(y1 - y0)
    sy = y0 < y1 ? 1 : -1
    error = dx + dy
    
    while true
        plot(x0, y0)
        if x0 == x1 && y0 == y1 break
        e2 = 2 * error
        if e2 >= dy
            if x0 == x1 break
            error = error + dy
            x0 = x0 + sx
        end if
        if e2 <= dx
            if y0 == y1 break
            error = error + dx
            y0 = y0 + sy
        end if
    end while
