#include <functions.h>
#include <graphics/gfxbase.h>
#include <graphics/rastport.h>
#include <intuition/intuitionbase.h>
#include <stdio.h>
#include <ctype.h>
#include "defs.h"

#define ABOX(x1,y1,x2,y2) SetAPen(ConPort,GREENPEN);RectFill(ConPort,(long) 10*x1,(long) 5*y1+5,(long) 10*x2+9,(long) 5*y2+9)
#define EBOX(x1,y1,x2,y2) SetAPen(ConPort,BLACKPEN);RectFill(ConPort,(long) 10*x1,(long) 5*y1+5,(long) 10*x2+9,(long) 5*y2+9)

struct NewScreen NScreen =
  {
  0,0,640,200,
  3,
  GREENPEN,WHITEPEN,
  HIRES,
  CUSTOMSCREEN,
  NULL,
  NULL,
  NULL,
  NULL
  };

struct NewWindow NWindow =
  {
  0,0,
  640,200,
  GREENPEN,WHITEPEN,
  VANILLAKEY|MOUSEBUTTONS,
  BORDERLESS|BACKDROP|SIMPLE_REFRESH|NOCAREREFRESH|RMBTRAP|ACTIVATE,
  NULL,
  NULL,
  NULL,
  NULL,
  NULL,
  640,200,
  640,200,
  CUSTOMSCREEN
  };

USHORT CrossPointer[]=
  {
  0,0,
  0x0800,0x0000,
  0x0800,0x0000,
  0x0800,0x0000,
  0x0000,0x0000,
  0xe380,0x0000,
  0x0000,0x0000,
  0x0800,0x0000,
  0x0800,0x0000,
  0x0800,0x0000,
  0,0
  };
struct NStar star[STARNO];
struct NTask task[PLAYERNO][TASKNO+1];
struct NCommData CommData[PLAYERNO];
struct NGeneral general;
struct Screen *ConScreen=NULL;
struct Window *ConWindow=NULL;
struct IntuitionBase *IntuitionBase;
struct GfxBase *GfxBase;
struct RastPort *ConPort;

int growth[PLANETNO]={3,5,7,8,7,6,4,2};

int fline;
int mode=-1,mode2=0,mode3=0;
int file=-1;
int waittime=-1;

struct NShip ship[SHIPNO]=
  {
    {
    "Clearer",/* char name[STRLENGTH];*/
    3, /*int size;*/
    0, /*int capacity;*/
    0, /*int hyprange;*/
    0, /*int hypspeed;*/
    1, /*int speed;*/
    1, /*int attack;*/
    20, /*int attackno;*/
    4, /*int shields;*/
    NOSPEC, /*int special;*/
    100, /*int techcost;*/
    620  /*int techlevel;*/
    },
    {
    "UltraStinger",/* char name[STRLENGTH];*/
    1, /*int size;*/
    0, /*int capacity;*/
    50, /*int hyprange;*/
    50, /*int hypspeed;*/
    3, /*int speed;*/
    7, /*int attack;*/
    1, /*int attackno;*/
    4, /*int shields;*/
    NOSPEC, /*int special;*/
    60,  /*int techcost;*/
    800  /*int techlevel;*/
    },
    {
    "Stinger",/* char name[STRLENGTH];*/
    1, /*int size;*/
    0, /*int capacity;*/
    0, /*int hyprange;*/
    0, /*int hypspeed;*/
    3, /*int speed;*/
    7, /*int attack;*/
    1, /*int attackno;*/
    2, /*int shields;*/
    FASTEJECTABLE, /*int special;*/
    25, /*int techcost;*/
    150  /*int techlevel;*/
    },
    {
    "Light Cruiser",/* char name[STRLENGTH];*/
    5, /*int size;*/
    0, /*int capacity;*/
    6, /*int hyprange;*/
    1, /*int hypspeed;*/
    5, /*int speed;*/
    10, /*int attack;*/
    1, /*int attackno;*/
    10, /*int shields;*/
    NOSPEC, /*int special;*/
    100, /*int techcost;*/
    100  /*int techlevel;*/
    },
    {
    "Space Cannon",/* char name[STRLENGTH];*/
    10, /*int size;*/
    0, /*int capacity;*/
    0, /*int hyprange;*/
    0, /*int hypspeed;*/
    4, /*int speed;*/
    40, /*int attack;*/
    1, /*int attackno;*/
    0, /*int shields;*/
    NOSPEC, /*int special;*/
    120, /*int techcost;*/
    550  /*int techlevel;*/
    },
    {
    "Destroyer",/* char name[STRLENGTH];*/
    12, /*int size;*/
    0, /*int capacity;*/
    9, /*int hyprange;*/
    2, /*int hypspeed;*/
    6, /*int speed;*/
    18, /*int attack;*/
    1, /*int attackno;*/
    10, /*int shields;*/
    NOSPEC, /*int special;*/
    110, /*int techcost;*/
    310  /*int techlevel;*/
    },
    {
    "Battleship",/* char name[STRLENGTH];*/
    25, /*int size;*/
    3, /*int capacity;*/
    8, /*int hyprange;*/
    2, /*int hypspeed;*/
    6, /*int speed;*/
    15, /*int attack;*/
    3, /*int attackno;*/
    18, /*int shields;*/
    FASTEJECTER, /*int special;*/
    150, /*int techcost;*/
    450  /*int techlevel;*/
    },
    {
    "Battlestar",/* char name[STRLENGTH];*/
    950, /*int size;*/
    100, /*int capacity;*/
    9, /*int hyprange;*/
    1, /*int hypspeed;*/
    8, /*int speed;*/
    30, /*int attack;*/
    15, /*int attackno;*/
    40, /*int shields;*/
    FASTEJECTER, /*int special;*/
    900, /*int techcost;*/
    950  /*int techlevel;*/
    },
    {
    "HeavyCruiser",/* char name[STRLENGTH];*/
    8, /*int size;*/
    0, /*int capacity;*/
    8, /*int hyprange;*/
    1, /*int hypspeed;*/
    7, /*int speed;*/
    15, /*int attack;*/
    1, /*int attackno;*/
    14, /*int shields;*/
    NOSPEC, /*int special;*/
    120, /*int techcost;*/
    220  /*int techlevel;*/
    },
    {
    "Mothership",/* char name[STRLENGTH];*/
    100, /*int size;*/
    20, /*int capacity;*/
    11, /*int hyprange;*/
    1, /*int hypspeed;*/
    6, /*int speed;*/
    12, /*int attack;*/
    2, /*int attackno;*/
    24, /*int shields;*/
    NOSPEC, /*int special;*/
    230, /*int techcost;*/
    620  /*int techlevel;*/
    },
    {
    "Satellite",/* char name[STRLENGTH];*/
    2000, /*int size;*/
    0, /*int capacity;*/
    0, /*int hyprange;*/
    0, /*int hypspeed;*/
    9, /*int speed;*/
    12, /*int attack;*/
    1, /*int attackno;*/
    6, /*int shields;*/
    NOSPEC, /*int special;*/
    20, /*int techcost;*/
    660  /*int techlevel;*/
    },
    {
    "Trans III",/* char name[STRLENGTH];*/
    20, /*int size;*/
    8, /*int capacity;*/
    9, /*int hyprange;*/
    2, /*int hypspeed;*/
    10, /*int speed;*/
    0, /*int attack;*/
    0, /*int attackno;*/
    6, /*int shields;*/
    NOSPEC, /*int special;*/
    100, /*int techcost;*/
    360  /*int techlevel;*/
    },
    {
    "UltraTrans",/* char name[STRLENGTH];*/
    40, /*int size;*/
    30, /*int capacity;*/
    50, /*int hyprange;*/
    4, /*int hypspeed;*/
    10, /*int speed;*/
    0, /*int attack;*/
    0, /*int attackno;*/
    8, /*int shields;*/
    NOSPEC, /*int special;*/
    160, /*int techcost;*/
    900  /*int techlevel;*/
    },
    {
    "Glitter",/* char name[STRLENGTH];*/
    20, /*int size;*/
    19, /*int capacity;*/
    0, /*int hyprange;*/
    0, /*int hypspeed;*/
    10, /*int speed;*/
    0, /*int attack;*/
    0, /*int attackno;*/
    0, /*int shields;*/
    NOSPEC, /*int special;*/
    10, /*int techcost;*/
    420  /*int techlevel;*/
    },
    {
    "Scout",/* char name[STRLENGTH];*/
    2, /*int size;*/
    0, /*int capacity;*/
    11, /*int hyprange;*/
    3, /*int hypspeed;*/
    10, /*int speed;*/
    0, /*int attack;*/
    0, /*int attackno;*/
    6, /*int shields;*/
    NOSPEC, /*int special;*/
    50, /*int techcost;*/
    180  /*int techlevel;*/
    },
    {
    "Transporter",/* char name[STRLENGTH];*/
    10, /*int size;*/
    4, /*int capacity;*/
    4, /*int hyprange;*/
    1, /*int hypspeed;*/
    10, /*int speed;*/
    0, /*int attack;*/
    0, /*int attackno;*/
    6, /*int shields;*/
    NOSPEC, /*int special;*/
    40, /*int techcost;*/
    50  /*int techlevel;*/
    },
    {
    "Spy Sat",/* char name[STRLENGTH];*/
    1, /*int size;*/
    0, /*int capacity;*/
    9, /*int hyprange;*/
    1, /*int hypspeed;*/
    10, /*int speed;*/
    0, /*int attack;*/
    0, /*int attackno;*/
    70, /*int shields;*/
    NOSPEC, /*int special;*/
    280, /*int techcost;*/
    750  /*int techlevel;*/
    },
    {
    "Torpedo",/* char name[STRLENGTH];*/
    1, /*int size;*/
    0, /*int capacity;*/
    0, /*int hyprange;*/
    0, /*int hypspeed;*/
    1, /*int speed;*/
    25, /*int attack;*/
    1, /*int attackno;*/
    0, /*int shields;*/
    KAMIKAZE|FASTEJECTABLE, /*int special;*/
    15, /*int techcost;*/
    240 /*int techlevel;*/
    },
    {
    "Pirate",/* char name[STRLENGTH];*/
    10, /*int size;*/
    3, /*int capacity;*/
    9, /*int hyprange;*/
    2, /*int hypspeed;*/
    5, /*int speed;*/
    6, /*int attack;*/
    3, /*int attackno;*/
    14, /*int shields;*/
    NOSPEC, /*int special;*/
    180, /*int techcost;*/
    370 /*int techlevel;*/
    },
    {
    "Carrier",/* char name[STRLENGTH];*/
    30, /*int size;*/
    5, /*int capacity;*/
    7, /*int hyprange;*/
    1, /*int hypspeed;*/
    10, /*int speed;*/
    0, /*int attack;*/
    0, /*int attackno;*/
    28, /*int shields;*/
    FASTEJECTER, /*int special;*/
    100, /*int techcost;*/
    430 /*int techlevel;*/
    },
    {
    "Q-Bomb",/* char name[STRLENGTH];*/
    30, /*int size;*/
    0, /*int capacity;*/
    0, /*int hyprange;*/
    0, /*int hypspeed;*/
    0, /*int speed;*/
    0, /*int attack;*/
    0, /*int attackno;*/
    0, /*int shields;*/
    STARKILLER, /*int special;*/
    350,/*int techcost;*/
    950/*int techlevel;*/
    },
    {
    "Trans II",/* char name[STRLENGTH];*/
    10, /*int size;*/
    4, /*int capacity;*/
    9, /*int hyprange;*/
    1, /*int hypspeed;*/
    0, /*int speed;*/
    0, /*int attack;*/
    0, /*int attackno;*/
    6, /*int shields;*/
    NOSPEC, /*int special;*/
    70, /*int techcost;*/
    210 /*int techlevel;*/
    },
    {
    "",/* char name[STRLENGTH];*/
    1, /*int size;*/
    0, /*int capacity;*/
    0, /*int hyprange;*/
    0, /*int hypspeed;*/
    0, /*int speed;*/
    0, /*int attack;*/
    0, /*int attackno;*/
    0, /*int shields;*/
    NOTPROD, /*int special;*/
    1000, /*int techcost;*/
    1000/*int techlevel;*/
    },
    {
    "",/* char name[STRLENGTH];*/
    1, /*int size;*/
    0, /*int capacity;*/
    0, /*int hyprange;*/
    0, /*int hypspeed;*/
    0, /*int speed;*/
    0, /*int attack;*/
    0, /*int attackno;*/
    0, /*int shields;*/
    NOTPROD, /*int special;*/
    1000, /*int techcost;*/
    1000/*int techlevel;*/
    },
    {
    "",/* char name[STRLENGTH];*/
    1, /*int size;*/
    0, /*int capacity;*/
    0, /*int hyprange;*/
    0, /*int hypspeed;*/
    0, /*int speed;*/
    0, /*int attack;*/
    0, /*int attackno;*/
    0, /*int shields;*/
    NOTPROD, /*int special;*/
    1000, /*int techcost;*/
    1000/*int techlevel;*/
    },
    {
    "Ore Unit",/* char name[STRLENGTH];*/
    1, /*int size;*/
    0, /*int capacity;*/
    0, /*int hyprange;*/
    0, /*int hypspeed;*/
    10, /*int speed;*/
    0, /*int attack;*/
    0, /*int attackno;*/
    0, /*int shields;*/
    NOTPROD, /*int special;*/
    MCOST, /*int techcost;*/
    0  /*int techlevel;*/
    },
    {
    "Pop Unit",/* char name[STRLENGTH];*/
    1, /*int size;*/
    0, /*int capacity;*/
    0, /*int hyprange;*/
    0, /*int hypspeed;*/
    10, /*int speed;*/
    0, /*int attack;*/
    0, /*int attackno;*/
    0, /*int shields;*/
    NOTPROD, /*int special;*/
    20, /*int techcost;*/
    0   /*int techlevel;*/
    }
  };

main()
  {
  /* Opening Libs */
  IntuitionBase = (struct IntuitionBase *) OpenLibrary("intuition.library",LIBRARY_VERSION);
  if(IntuitionBase==NULL) cleanup("Unable to open intuition.library");
  GfxBase = (struct GfxBase *) OpenLibrary("graphics.library",LIBRARY_VERSION);
  if (GfxBase==NULL) cleanup("Unable to open graphics.library");
  /* Opening Screen */
  ConScreen=(struct Screen *) OpenScreen(&NScreen);
  if (ConScreen==NULL) cleanup("Unable to open conscreen");
  ScreenToFront(ConScreen);
  ShowTitle(ConScreen,FALSE);
  SetRGB4(&(ConScreen->ViewPort),BLACKPEN, 0L, 0L, 0L);    /* Black  */
  SetRGB4(&(ConScreen->ViewPort),WHITEPEN,15L,15L,15L);    /* White  */
  SetRGB4(&(ConScreen->ViewPort),GREENPEN, 5L,13L, 0L);    /* Green  */
  SetRGB4(&(ConScreen->ViewPort),OTHERPEN,15L,12L, 0L);    /* Orange */
  SetRGB4(&(ConScreen->ViewPort),PLAYERPEN(0),15L, 2L, 0L);/* Red    */
  SetRGB4(&(ConScreen->ViewPort),PLAYERPEN(1), 7L, 9L,15L);/* Blue   */
  SetRGB4(&(ConScreen->ViewPort),PLAYERPEN(2),15L,15L, 2L);/* Yellow */
  SetRGB4(&(ConScreen->ViewPort),PLAYERPEN(3), 0L,15L, 2L);/* Full Green */
  SetRGB4(&(ConScreen->ViewPort),SPRITEPEN(0), 0L, 0L, 0L);/* Black  */
  SetRGB4(&(ConScreen->ViewPort),SPRITEPEN(1), 5L,13L, 0L);/* Green  */
  SetRGB4(&(ConScreen->ViewPort),SPRITEPEN(2),15L,15L,15L);/* White  */
  SetRGB4(&(ConScreen->ViewPort),SPRITEPEN(3),15L,12L, 0L);/* Orange */
  NWindow.Screen=ConScreen;
  ConWindow=(struct Window *) OpenWindow(&NWindow);
  if(ConWindow==NULL) cleanup("Unable to open ConWindow");
  SetPointer(ConWindow,CrossPointer,9L,9L,-5L,-5L);
  ConPort=ConWindow->RPort;
  title();
  conquest();
  cleanup("OK.");
  }
cleanup(str)
char *str;
  {
  puts(str);
  if (file!=-1) close(file);
  if (ConWindow) CloseWindow(ConWindow);
  if (ConScreen) CloseScreen(ConScreen);
  if (GfxBase) CloseLibrary(GfxBase);
  if (IntuitionBase) CloseLibrary(IntuitionBase);
  exit(1);
  }
title()
  {
  Move(ConPort,232L,10L);
  Text(ConPort,"by",2L);
  ABOX( 8, 0,15,15);
  EBOX(10, 2,15,13);
  ABOX(18, 8,25,15);
  EBOX(20,10,23,13);
  ABOX(24,16,25,16);
  ABOX(28, 7,29,15);
  ABOX(30, 8,33, 9);
  ABOX(36, 2,37,15);
  ABOX(38,14,39,15);
  ABOX( 0,20, 7,35);
  EBOX( 2,22, 7,33);
  ABOX( 2,26, 5,27);
  ABOX(10,28,17,35);
  EBOX(12,30,15,33);
  ABOX(16,22,17,27);
  ABOX(20,27,21,27);
  ABOX(20,28,29,35);
  EBOX(22,30,23,35);
  EBOX(26,30,27,35);
  ABOX(32,28,39,35);
  EBOX(34,30,37,33);
  ABOX(38,36,39,36);
  ABOX(42,28,47,35);
  EBOX(44,30,45,35);
  ABOX(42,27,43,27);
  }
#include "human.c"
