/*------------------------------------------------------------------------*/
/*    TYPE definitions for PlanMap & VGA Planets 3.0                      */
/*    A.M. van den Bos, 1993, 1994.                                       */
/*    Last update: October, 1997.                                         */
/*    Updated: Chris Croughton, Sep 1997                                  */
/*    Updated: Kero van Gelder, Sep/Oct 1997                              */
/*    Update: Roger Burton West, Oct 1997                                 */
/*------------------------------------------------------------------------*/

/*
Below, the header file of PlanMap II is listed. If you know the syntax of
other VGA Planets files, please mail me at bos@cs.utwente.nl.

To prevent cheating, the host of a game should use the VPUTIL toolset.

Change history:

9?.??.?? AMvdB	Original version by A.M. van den Bos.

97.09.?? CC 	Now updated for VGAP version 3.2+, including information 
		from Kero van Gelder's web site.

97.09.?? Kero	And some more changes (in score, and some unknown fields 
		filled).
		Typo laucher several times fixed.

97.10.02 CC	Converted remaining C++ comments to C style, modified change
		history style at top of file, made maximum line length <80 
		characters.

97.10.03 RBW    Some typo's and a dummy-field filled.
		
97.10.09 Kero   Fixed a bug in the transfer cargo to ship/planet

*/

#ifndef PLANET_TYPES
#define PLANET_TYPES

#define NUM_PLANETS        500   /* PLANETS has a fixed number of planets */
#define PLANETNAME_LENGTH  20    /* As in file PLANET.NM */
#define NUM_RACES          11    /* There are 11 races */
#define MAXSHIP            500   /* Maximum number of ships */
#define MAXHULL            120   /* Maximum number of hulls that can be read */
#define MAXBEAM            10    /* Beam specs */
#define MAXTORP            10    /* Torp specs */
#define MAXENG             9     /* Engine specs */
#define MAXMESSAGESIZE  (41*15)  /* 15 lines of 40 characters + CR */
#define MAXMESSAGE         50    /* Max. number of outgoing messages */

/* Length of race names (long form, plural form, adjective form) */
#define RACE_LENGTH(j) (((j)==0)?30:(((j)==1)?20:12))

#define NO_HULL_STR "CANNOT SCAN HULL              "


/**********************************************************************/
/* Maximum number of structures on a planet as function of the number */
/* of clans. (function-like macro; there must be at least 1 clan)     */
/**********************************************************************/

#define MAX_MINES(clans) ( ((clans)<=200) ? (clans) \
                                          : 200+(WORD)(0.5+sqrt((clans)-200)))
#define MAX_FACT(clans)  ( ((clans)<=100) ? (clans) \
                                          : 100+(WORD)(0.5+sqrt((clans)-100)))
#define MAX_DEF(clans)   ( ((clans)<= 50) ? (clans) \
                                          :  50+(WORD)(0.5+sqrt((clans)- 50)))

/**********************************************************************/
/* Crew kill/damage/shields vs Beam/torp kill and mass                */
/**********************************************************************/

#define SQR(x) ((x)*(x))  /* rise to the power of two */
#define CREW_KILL(kill,mass)     \
                      (min(9999L,(LONG)((kill)*(80.0/((mass)+1)))))
#define SHIELD_DAMAGE(expl,mass) \
                      (min(100L,(LONG)((expl)*(80.0/((mass)+1))+1)))
#define SHIP_DAMAGE(expl,mass)   \
                      (min(100L,(LONG)((expl)*SQR(80.0/((mass)+1)))+2))

/**************************************************************************/
/* Colonists/natives status (build-screen VGA Planets)                    */
/**************************************************************************/

#define COL_STATUS(clans,tax,planet,mines,factories)        \
((int) (1000.0-sqrt((float)clans) -80*(tax) -               \
3*abs((int)50-(planet)) -((float)(mines)+(factories))/3))

#define NAV_STATUS(clans,gov,tax,planet,mines,factories)    \
((int) (1000.0-sqrt((float)clans) -85*(tax) -               \
50*((int)10-(gov)) -((float)(mines)+(factories))/2))


#define TEXT_STATUS(status)                      \
((status >=  450) ? "Love you":                  \
 (status >=   50) ? "Like your leadership":      \
 (status >= -100) ? "Are undecided about you":   \
 (status >= -550) ? "Are angry about you":       \
 		    "Hate you!" )

#define SHORT_STATUS(status)     \
((status >=  450) ? "Love":      \
 (status >=   50) ? "Like":      \
 (status >= -100) ? "Neutral":   \
 (status >= -550) ? "Angry":     \
		    "Hate!")


/**************************************************************************/
/* GEN??.DAT file with player's scores, turn number and checksums         */
/* The file is 157 bytes and can be loaded directly in a GENDATA struct.  */
/**************************************************************************/

/* Note: Not tested */

typedef struct              /* Score of a player */
{ WORD wPlanets;
  WORD wCapitalShips;
  WORD wFreighters;
  WORD wBases;
} SCORE;

typedef struct
{ char  sDateHost[10];      /* ASCII string */
  char  sTimeHost[8];       /* ASCII string */
  SCORE Scores[NUM_RACES];  /* Score of each player (player's nr. = index) */
  WORD  wPlayer;            /* player (race) number */
  BYTE  bPassword[10];      /* encrypted password */
  BYTE  bSpecial[10];       /* 10 bytes at the end of each other file */
  BYTE  bSpare;
  LONG  lCS_Ship;           /* BYTE-wise checksum over 
			       SHIP??.DAT & SHIP??.DIS       (offset 0x81) */
  LONG  lCS_Planet;         /* BYTE-wise checksum over 
			       PDATA??.DAT & PDATA??.DIS     (offset 0x85) */
  LONG  lCS_Base;           /* BYTE-wise checksum over 
			       BDATA??.DAT & BDATA??.DIS     (offset 0x89) */
  WORD  wIsNewPwd;          /* Is there a new password? */
  BYTE  bNewPass[10];       /* if so, here is the new password 
			       (rot50 encryption) */
  WORD  wTurnNr;            /* Current turn number           (offset 0x99) */
  WORD  wHostId;            /* Host ID                       (offset 0x9B) */
} GENDATA;

#define TURN_OFFSET      0x99  /* Offset in GEN??.DAT for turn number */


/**************************************************************************/
/* XYPLAN.DAT file with (x,y) coordinates of the 500 planets.             */
/* The file is 3000 bytes and can be loaded directly into a               */
/* PLANET_COORDS[NUM_PLANETS] stucture. The 1-based index is the ID of    */
/* the planet.                                                            */
/* Beware: there is a checksum (998681) over the X-coordinates!           */
/*                                                                        */
/* PLANET.NM file with the 500 planet names. 10000 bytes in size and can  */
/* be loaded directly into a CHAR[NUM_PLANETS][20] structure. A 1-based   */
/* index is the ID of the planet.                                         */
/**************************************************************************/

typedef struct
{  WORD x;
   WORD y;
   WORD owner;    /* Only interesting for some master/config program */
} PLANET_COORDS;


/***************************************************************************/
/* SHIP??.DAT First WORD of file #ships, followed by a list of ships.      */
/* SHIP.HST   First WORD is a dummy, followed by an ARRAY[1..500] OF       */
/*            SHIPDATA. The index is the ship's ID                         */
/***************************************************************************/

typedef struct         
{ WORD wID;                 /* ship's ID */
  WORD wRace;               /* owner of ship  (0=>SHIP.HST => no ship) */
  char sCode[3];            /* Friendly code; three characters */
  WORD wWarp;               /* Speed of ship */
  int  xDis, yDis;          /* Displacement next turn 
			       (tan(bearing) = xDis/yDis) */
  WORD xCoord;              /* Location of ship (xCoord, yCoord) */
  WORD yCoord;
  WORD wDriveLevel;         /* Tech level of engines */
  WORD wShipType;           /* Type of ship (index in HULLSPEC.DAT) */
  WORD wBeamLevel;          /* Tech level of beams */
  WORD wBeamWeapons;        /* Number of beam weapons */
  WORD wFighterBays;        /* Number of fighter bays */
  WORD wTorpLevel;          /* Torp. tech. level */
  WORD wTorps;              /* Number of torps/fighters */
  WORD wTorpsBays;          /* Number of torp. launchers */
  WORD wMission;            /* Mission of the ship */
  WORD wEnemy;              /* Primairy enemy */
  WORD wTowed;	            /* Ship being towed */
  WORD wDamage;             /* Ships damage in % */
  WORD wCrew;               /* Number of crew members on ship */
  WORD wColonists;          /* Number of colonists on ship */
  char sName[20];           /* Name of ship */
  WORD wFuel, wTri,         /* Minerals on ship */
       wDur, wMol;
  WORD wSupplies;           /* Supplies on ship */
  
  WORD wPFuel,  wPTri,      /* Cargo to planet */
       wPDur,   wPMol,
       wPClans, wPSup,
       wPID;                /* ID of planet */

  WORD wSFuel,  wSTri,      /* Cargo to ship */
       wSDur,   wSMol,
       wSClans, wSSup,
       wSID;                /* ID of ship */

  WORD wIntercept;          /* ID of ship to intercept */
  WORD wMoney;              /* MC's on ship */
} SHIPDATA;



/**************************************************************************/
/* TARGET??.DAT file with scanned enemy hulls.                            */
/**************************************************************************/

typedef struct              
{ WORD wID;                /* ID of ship */
  WORD wRace;              /* Owner */
  WORD wWarp;              /* Current speed */
  WORD xCoord, yCoord;     /* Location */
  WORD wHull;              /* Index in HULLSPEC.DAT */
  WORD wBearing;           /* In degrees */
  char sName[20];          /* Name of ship */
} TARGETDATA;


/***********************************************************************/
/* SHIPXY??.DAT & SHIPXY.HST. File with (scanned) enemy ships          */
/* 500 entries, position in file is ship's ID                          */
/***********************************************************************/

typedef struct              
{ WORD xCoord, yCoord;      /* Location of ship */
  WORD wOwner;              /* wOwner = 0 -> no ship scanned with this ID */
  WORD wMass;               /* Mass of ship */
} SHIPXY;



/***************************************************************************/
/* Hull, engine, beam & torpedoes specifications.                          */
/* VGA Planets calculates a single LONG checksum over the specification    */
/* files HULLSPEC.DAT, ENGSPEC.DAT, BEAMSPEC.DAT & TORPSPEC.DAT by summing */
/* the BYTES of each file.                                                 */
/***************************************************************************/

typedef struct              /* HULLSPEC.DAT */
{ char sName [30];          /* Name of the hull */
  WORD wPicture;            /* Picture ID */
  WORD wUnknown;            /* Always 1, perhaps part of Picture ID; 
			       I don't know */
  WORD wTri, wDur, wMol;    /* Minerals needed to build hull */
  WORD wFuel, wCrew;        /* Size of fuel tanks & crew */ 
  WORD wEngines, wMass;     /* Engines needs & Mass */
  WORD wTechLevel, wCargo;  /* Tech level needs and max cargo */
  WORD wFighterBays;        /* Fighter bays */
  WORD wTorpsBays;          /* Torp bays */
  WORD wBeams;              /* Max. number of beams */
  WORD wMoney;              /* Money required to build hull */
} HULLSPEC;

typedef struct              /* BEAMSPEC.DAT */
{ char sName[20];           /* Name of beam weapon */
  WORD wCost;               /* Money to build hull */
  WORD wTri, wDur, wMol;    /* Minerals to build hull */
  WORD wMass;               /* Total mass of beam weapon */
  WORD wTechLevel;          /* Tech level required to build */
  WORD wKill;               /* Kill level of weapon */
  WORD wExplosive;          /* Destructive level of weapon */
} BEAMSPEC;

typedef struct              /* TORPSPEC.DAT */
{ char sName[20];           /* Name of torp. launcher */
  WORD wCostTorp;           /* Costs of one torpedo of this type */
  WORD wCost;               /* Money to build torp. launcher */
  WORD wTri, wDur, wMol;    /* Minerals to build torp. launcher */
  WORD wMass;               /* Total mass of torp. launcher */
  WORD wTechLevel;          /* Tech level required to build torp. launcher */
  WORD wKill;               /* Kill level of weapon */
  WORD wExplosive;          /* Destructive level of weapon */
} TORPSPEC;

/* At the end of the file TORPSPEC.DAT there is trailing garbage.
   This is a checksum-fixer in disguise */

typedef struct              /* ENGSPEC.DAT */
{ char sName[20];           /* Name of engine */
  WORD wCost;               /* Money to build it */
  WORD wTri, wDur, wMol;    /* Minerals to build it */
  WORD wTechLevel;          /* Tech level required to build it. */
  LONG lFuelUse[9];         /* Warp x requires lFuelUse[x] */
} ENGSPEC;


/*************************************************************************/
/* PDATA??.DAT & PDATA.HST first word in file equals #planets or 0 resp. */
/*************************************************************************/

typedef struct              
{ 
  WORD wOwner;              /* Owner (0 = no owner) */
  WORD wID;                 /* ID of planet */
  char sCode[3];            /* Friendly code */
  WORD wMines;              /* Number of mineral mines */
  WORD wFactories;          /* Number of factories */
  WORD wDefense;            /* Defences on planet */

  LONG lFuel, lTri;         /* Mined minerals */
  LONG lDur, lMol;
  LONG lColonists;          /* Number of colonists */
  LONG lSupplies;           /* Supplies on planet */
  LONG lMoney;              /* MC's on planet */

  LONG lFuel_P, lTri_P;     /* Minerals IN planet */
  LONG lDur_P, lMol_P;

  WORD wFuel_D, wTri_D;     /* Density of minerals in planet (in %) */
  WORD wDur_D, wMol_D;

  WORD wColTax;             /* Colonist-taxes in % */
  WORD wNativeTax;          /* Native-taxes in % */
  int  iColStatus;          /* <20 fighting, 20 rioting, 40 very angry, 
			       50 unhappy, 70 calm, 90 happy */
  int  iNativeStatus;       /* same as ColStatus */

  WORD wGov;                /* Government of natives:
			       1 - Anarchy 
			       2 - Pre-Tribal 
			       3 - Early Tribal 
			       4 - Tribal 
			       5 - Feudal
			       6 - Monarchy 
			       7 - Representative 
			       8 - Participatory 
			       9 - Unity
			    */
  LONG lNatives;            /* Number of natives (clans) */
  WORD wRace;               /* Native's race 
			       1 - Humanoid
			       2 - Bovinoid
			       3 - Reptilian
			       4 - Avian
			       5 - Amorphous
			       6 - Insectoid
			       7 - Amphibian
			       8 - Ghipsoldal
			       9 - Siliconoid
			    */
  WORD wPlanet;             /* 100-Temp. Defines planet picture & 
			       color-palette for picture (?) */
  WORD BuildNewbase;        /* Next turn, a base will be here */
} PLANETDATA;



/**************************************************************************/
/* MESS??.DAT file with outgoing messages.                               */
/* First word is #messages in file                                       */
/* Then an ARRAY[50] OF MESSAGE_ENTRY (see below)                        */
/* Then the actual messages, add an offset (+13) to each letter          */
/* Note: no more than 50 messages can be transmitted                     */
/*************************************************************************/

typedef struct
{ LONG lOffset;             /* Start+1 in file (mind the +1, stems from
			       BASIC) */
  WORD wLength;             /* Length of message in bytes */
  WORD iFrom;               /* Sender of message */
  WORD iTo;                 /* Destination of message */
} MESSAGE_ENTRY;


/*************************************************************************/
/* MDATA??.DAT is the file with incoming messages.                       */
/* First word is #messages in file                                       */
/* Then an ARRAY[#messages] OF { LONG lOffset; WORD wLength}             */
/* Then the actual messages, add an offset of -13 to each letter         */
/*************************************************************************/

/* No type defs */


/*************************************************************************/
/* VCR??.DAT. File for the Visual Combat Recorder.                       */
/* The first WORD of the file is #battles.                               */
/* ( Thanks Alistair )                                                   */
/*************************************************************************/

/* Note: Not tested */

typedef struct
{  LONG RandomSeed;         /* Random seed, probably a long */
   WORD wUnknown;           /* Often zero */
   WORD IsPlanet;           /* Tells whether right side is a planet or base */
   WORD wMass1, wMass2;     /* Mass of ships */

   /* Specs. first ship */
   char sName1[20];         /* Name of ship */
   WORD wDamage1;           /* Initial damage of ship */
   WORD Crew1;              /* Initial crew on ship */
   WORD wID1;               /* ID of ship */
   WORD wRace1;             /* Owner of ship */
   WORD wBitmap1;           /* Index in RESOURCE.PLN */
   WORD wBeamTech1;         /* Type of beam weapons */
   WORD wBeams1;            /* Number of beam weapons */
   WORD wBays1;             /* Number of fighter bays */
   WORD wTorpTech1;         /* Type of torp. launchers */
   WORD wTorpFighters1;     /* Initial number of torps. or fighter on ship */
   WORD wTorps1;            /* Number of torp. launchers */

   /* Specs. second ship */
   char sName2[20];         /* Name of ship */
   WORD wdamage2;           /* Initial damage of ship */
   WORD Crew2;              /* Initial crew on ship */
   WORD wID2;               /* ID of ship */
   WORD wRace2;             /* Owner of ship */
   WORD wBitmap2;           /* Index in RESOURCE.PLN */
   WORD wBeamTech2;         /* Type of beam weapons */
   WORD wBeams2;            /* Number of beam weapons */
   WORD wBays2;             /* Number of fighter bays */
   WORD wTorpTech2;         /* Type of torp. launchers */
   WORD wTorpFighters2;     /* Initial number of torps. or fighter on ship */
   WORD wTorps2;            /* Number of torp. launchers */

   WORD wShield1, wShield2; /* Initial shields of both ships. */
} VCR_DATA;


/*************************************************************************/
/* VCR??.DAT. File for the Visual Combat Recorder.                       */
/* The first WORD of the file is #battles.                               */
/* Alternate structures for the data                                     */
/*************************************************************************/

typedef struct
{
   char sName[20];          /* Name of ship */
   WORD wDamage;            /* Initial damage of ship */
   WORD Crew;               /* Initial crew on ship */
   WORD wID;                /* ID of ship */
   WORD wRace;              /* Owner of ship */
   WORD wBitmap;            /* Index in RESOURCE.PLN */
   WORD wBeamTech;          /* Type of beam weapons */
   WORD wBeams;             /* Number of beam weapons */
   WORD wBays;              /* Number of fighter bays */
   WORD wTorpTech;          /* Type of torp. launchers */
   WORD wTorpFighters;      /* Initial number of torps. or fighter on ship */
   WORD wTorps;             /* Number of torp. launchers */
} VCRFOE;

typedef struct
{
  WORD wRandomSeed;	    /* seed for RNG */
  WORD wUnknown[2];         /* Often zero */
  WORD wIsPlanet;           /* Tells whether right side is a planet or ship */
  WORD wMass1, wMass2;      /* Mass of ships */
  VCRFOE foe[2];            /* Spec.s for opponent 1 and 2 */
  WORD wShield1, wShield2;  /* Initial shields of both ships. */
} VCRDATA;


/**************************************************************************/
/* BDATA??.DAT  First WORD #bases, followed by a list of bases.           */
/**************************************************************************/

typedef struct
{ WORD wID;
  WORD wOwner;
  WORD wDefence;       /* Defence of starbase */
  WORD wDamage;        /* Damage in % */

  /* Tech levels */
  WORD wTechEngine;
  WORD wTechHull;
  WORD wTechBeam;
  WORD wTechTorp;

  /* Items on starbase */
  WORD wEngines[9];     /* #engines on starbase index 0=stardrive 1    0x12 */
  WORD wHulls[20];      /* #Hulls, index = index in truehull           0x24 */
  WORD wBeams[10];      /* #beam weapons on starbase index 0=Laser     0x4C */
  WORD wTLaunchers[10]; /* #torp launchers on base, 0=Mark 1           0x60 */
  WORD wTorps[10];      /* #tops on starbase index 0=Mark 1            0x74 */

  WORD wFighters;       /* #fighters on base 0x88 */
  WORD wFixID;          /* ID of ship being fixed or recycled */
  WORD wFixShip;        /* 0=do nothing, 1=fix ship, 2=recycle ship */
  WORD wMission;        /* 1 = Refuel, 2 = Max defence, ... */

  /* Ship being built */
  WORD wShip;           /* Ship being built (index in Hullspec) */
  WORD wEngineLevel;    /* Engine level of ship being built */
  WORD wBeamLevel;      /* Beam level of ship being built */
  WORD wBeamOnShip;     /* Number of beams on ship */
  WORD wTorpLevel;      /* Torp. launcher level */
  WORD wTorpOnShip;     /* Number of torp. launcher on ship */

  WORD wUnknown;        /* equals 0 */

} BASEDATA;

#endif /* PLANET_TYPES */

