#define DOS_PASCAL_CALLING
#include "dddware.h"
#include "sound.h"
//#include "compat.h"

void game(void);

/* Functions in 3dai.c: */
void speedup_ship(int f);
void slowdown_ship(int f);
void doesitmatter(int f);
void aimship(float dx,float dy,float dz,float accuracy,int fireflag,int f);
void openfire(float fx, float fy, int f);
void check(int f);
void checkshields(int f);
void damageship(int gg, int amount);
void drawturrets(int f);
void killoff(int f);
void projectiles(void);
void calculateheight(int f);

/* Functions in 3dmath.c */
float angle ( float ang1, float ang2 );
float pythag3d(float a,float b,float c);
float pythag2d(float a,float b);
void calculate_ship_angles(float x1, float y1, float z1, float x2, float y2, float z2, float *fx, float *fy);
void rotatesummat(float *x,float *y,float *z,float ax,float ay,float az);
void rotatesummatelse(float *x,float *y,float *z,float cax,float sax,float cay,float say,float caz,float saz);
void rotatenormals(float x[3],float y[3],float z[3],float cax,float sax,float cay,float say,float caz,float saz);
void rotatedddwarestyle(int *x,int *y,int *z,float dx0,float dy0,float dz0,float dx2,float dy2,float dz2);
void calculate_cos_sin(float *x, float *y, float precos, float presin);
int saferandom(int range);
void spinturret(int obj,int g,float aroundx,float aroundy,float aroundz);
void spinhangerzone(int obj,int g,float aroundx,float aroundy,float aroundz);
void spinobject(int obj,   float cx,float cy,float cz,   float aroundx,float aroundy,float aroundz, int free);
void spinprojectile(int obj,     float cx,float cy,float cz,   float aroundx,float aroundy,float aroundz, int free);
void spindebris(int obj,     float cx,float cy,float cz,   float aroundx,float aroundy,float aroundz );
void spincreateobjects(int obj, float cx,float cy,float cz, float aroundx,float aroundy,float aroundz );
void spinguiobject(int obj,     float cx,float cy,float cz,   float aroundx,float aroundy,float aroundz, int free);
void spinground(int obj,     float cx,float cy,float cz,   float aroundx,float aroundy,float aroundz);

/* Functions in 3dfuncs.c */
void allocate_memory_for_everything(void);
void free_memory_for_everything(void);
void free_memory_for_ship(int f);
void turretallocate(int f);
void gunallocate(int f);
void crashzoneallocate(int f);
void hangerzoneallocate(int f);
void initialise_data(void);
void deinitialise_data(void);
void crashout(char reason[80]);
void loadshapes(void);
void load(char filename[20]);
void attach(int f);
void detach(int f);
void reset(void);
void waypoints(void);
void pause(void);
void options(void);
void detailsettings(void);
void calibrate(void);
void playsoundeffect(int f, float dist);
void playtricia(int f);
void prepareyourguns(void);
void palette_set(int percent);
void initsound(void);
void deinitsound(void);
int newpilot(void);
void savepilot(void);

/* Functions in 3ddraw.c */
void safelineellipse(int c, int x, int y, int rx, int ry);
void safefillellipse(int c, int x, int y, int rx, int ry);
void moveyourguns(void);
void printcomputer(int completed, int notcompleted, int critical);
void  addcomputer(char s1[40], int side);
void updatescanner(void);
void drawnicebox(int tlc,int mc,int brc,int x1,int y1,int x2,int y2);
void drawpowerbar(int teamnum, float teampower,int xoffset,int color);
void drawstarfield(float rsx,float rsy,float rsz);
void drawplanets(void);
void displaybriefing(void);
void drawguiobjects(float rsx,float rsy,float rsz);
void drawdebrisfield(void);
void attached(int f);
void glare(int f);
void drawground(void);

/* Functions in 3dcreate.c */
void createtorus(int complexity ,float x, float y, float z, float sx, float sy, float sz);
void createexplosion(int complexity ,float x, float y, float z, float sx, float sy, float sz);
void createcomm(int from, int type, int side, char msg[80]);
void createcommevent( int f, long time, int from, int side, char msg[120] );
void createstarfield(void);
void createstellar(int f,int t,int shape, float x, float y, float z, float rx, float ry, float rz, float rsx,float rsy,float rsz, float sx,float sy,float sz );
void createobject(int type, float x,float y,float z,     float sx,float sy,float sz,  float target,int owner);
void createship(
    int f,int t,int shape, float x, float y, float z, float rx,
    float ry, float rz,
    float rsx,float rsy,float rsz, float sx,float sy,float sz,
    int stubborn, int wingleader, int wingtype,
    float wingx,float wingy,float wingz,
    int destination,
 char name[40], int rank, int target, int mother, int motherhangerzone);
void createobjectevent(int f, long time, int no,
    int type, int doing, int side, int target, int topspeed,
    int toprevs,
    int shields, int maxshields, int armour, int maxarmour,
    int stubborn, int wingleader, int wingtype,
    float wingx,float wingy,float wingz,
    int destination, int rank );
void createcreateobject(int f, long time, int no,
    int shape, int type, int side, int target,
    float cx, float cy, float cz, float sx, float sy, float sz,
    float rx, float ry, float rz, float rsx, float rsy, float rsz,
    int stubborn, int wingleader, int wingtype,
    float wingx,float wingy,float wingz,
    int destination,char name[40], int rank, int mother, int motherhangerzone );
void createguiobject(int f,int t,int shape, float x, float y, float z, float rx, float ry, float rz, float rsx,float rsy,float rsz, float sx,float sy,float sz );
void createdebrisfield(void);
void createground(int type,float height);
void sortgroundout(void);

/* Functions in 3dtemp.c */
void missionchoice(void);

/* Functions in 3dapi.c */
void apiline(int c,int x1,int y1,int x2,int y2);
void apirect(int c,int x1,int y1,int x2,int y2);
void apibox(int c,int x1,int y1,int x2,int y2);
void apiplot(int c,int x1,int y1);
void apiprojectile(char style, VtkObj object, char flags, short Xpos, short Ypos, short Zpos, short Xangle, short Yangle, short Zangle);
void apishape(char style, VtkObj object, char flags, short Xpos, short Ypos, short Zpos, short Xangle, short Yangle, short Zangle);
void apiground(char style, VtkObj object, short Xpos, short Ypos, short Zpos, short Xangle, short Yangle, short Zangle);
void apiguishape(char style, VtkObj object,char flags,short Xpos,short Ypos,short Zpos,short Xangle,short Yangle,short Zangle);
void apismallshape(char style, VtkObj object, char flags, short Xpos, short Ypos, short Zpos, short Xangle, short Yangle, short Zangle);
void apiplanet( VtkObj object, short shape ,short Xpos, short Ypos, short Zpos, short Xangle, short Yangle, short Zangle);
void apicockpitshape(char style, VtkObj object, char flags, short Xpos, short Ypos, short Zpos, short Xangle, short Yangle, short Zangle);
void apigameprint3(char Color, short Xpos, short Ypos, char *text);
void apiniceprint3(char Color, char Color2, short Xpos, short Ypos, char *text);
void apiniceprint4(char Color, char Color2, char Color3,char Color4,short Xpos, short Ypos, char *text);
void apicoolprint3(char Color, char Bk, short Xpos, short Ypos, char *text);
void apigameprint5(char Color, short Xpos, short Ypos, char *text);
long apireadtimer(void);
void apisetviewpos(short x, short y, short z);
void apisetviewangles(short xang, short yang, short zang);
void apiclearcliparea(void);
void apiclearobjects(void);
void apidrawobjects(void);
void apiscreenswap(void);
void apisetpal(void);
void apiprint7(char Color, short Xpos, short Ypos, char *text);
unsigned short apishapeload(char * shape_name);
void apirestore(void);
void apiinstall(void);
void apisetvideo(void);
void apigetmousepos(void);
void apireadjoystick(void);
int apirandom(int input);
MInit();
MCheck();
JCheck();
void installKeyboardHandler(void);
void removeKeyboardHandler(void);
unsigned long read_timer(void);
int jjjtimer_init(unsigned int num_timers);
void jjjtimer_shutdown(void);
int jjjtimer_start(unsigned int tid);
unsigned long jjjtimer_elapsed(unsigned int tid);
int jjjtargt_open(char filename[256]);
char *jjjtargt_tempextract(char filename[]);
char *jjjtargt_permextract(char filename[]);
void jjjLoad(char filename[],VtkObj *object);
void jjjtargt_close(void);

/* Functions in 3dcut.c: */
void newside(void);
void newcampaign(void);
void loadwindowships(void);
int roomlounge(void);
int roomquarters(void);
int roombriefing(void);
int database(void);
int indepth(void);
int pilotinfo(void);
int briefing(void);
void launch(void);
void landing(void);
void launching(void);
void land(void);
int awakenpilot(void);
int complete(void);
void roomdebriefing(void);
void printcredits1(void);
void printcredits2(void);

/* Functions in 3dbelt.c */
void shape10(int f); // Belt Light fighter
void shape13(int f); // Belt Medium fighter
void shape14(int f); // Belt Heavy  fighter  5
void shape15(int f); // Belt Bomber
void attach10(int f); // Belt Light fighter
void attach13(int f); // Belt Medium fighter
void attach14(int f); // Belt Heavy  fighter  5
void attach15(int f); // Belt Bomber
void shape19(int f); // Belt Corvette
void shape21(int f); // The Belt Escort Frigate
void shape23(int f); // Belt Destroyer
void shape25(int f); // The Belt Battleship
void shape28(int f); // Belt Carrier
void attach19(int f); // Belt Corvette
void attach21(int f); // The Belt Escort Frigate
void attach23(int f); // Belt Destroyer
void attach25(int f); // The Belt Battleship
void attach28(int f); // Belt Carrier

/* Functions in 3duea.c */
void shape11(int f); // Govt Light fighter
void shape12(int f); // Govt Assault fighter
void shape16(int f); // Govt Medium Fighter
void shape17(int f); // Govt Heavy  Fighter  8 ship waster
void shape18(int f); // Govt Bomber
void attach11(int f); // Govt Light fighter
void attach12(int f); // Govt Assault fighter
void attach16(int f); // Govt Medium Fighter
void attach17(int f); // Govt Heavy  Fighter  8 ship waster
void attach18(int f); // Govt Bomber
void shape20(int f); // Govt Picket
void shape22(int f); // Govt Frigate
void shape24(int f); // Govt Destroyer
void shape26(int f); // Govt Battleship
void shape27(int f);  // Govt Carrier
void attach20(int f);  // Govt Picket
void attach22(int f);  // Govt Frigate
void attach24(int f);  // Govt Destroyer
void attach26(int f);  // Govt Battleship
void attach27(int f);  // Govt Carrier

/* Functions in 3dother.c */
void shape99(int f); // Mount2
void shape100(int f); // Mount3
void shape90(int f); // Ground bases
void attach90(int f);
void shape91(int f); // Ground bases
void attach91(int f);
void shape92(int f); // Ground bases
void attach92(int f);
void shape93(int f); // Ground bases
void attach93(int f);
void shape98(int f);
void shape87(int f); // The Royal Fighter
void shape88(int f); // The Royal Heavy Fighter
void attach87(int f); // The Royal Fighter
void attach88(int f); // The Royal Heavy Fighter
void shape89(int f); // The Royal Cruiser
void attach89(int f);
void shape84(int f); // The U-Corp. Fighter
void attach84(int f); // The Royal Heavy Fighter
void shape85(int f); // The U-Corp. Attack ship
void attach85(int f);
void shape86(int f); // The U-Corp. Launch
void attach86(int f);
void shape79(int f); // The Rape Class Boarder
void shape77(int f); // The Military Transport
void attach77(int f);
void shape76(int f); // The Alien Attack Fighter
void shape71(int f); // Alien attack destroyer
void shape36(int f); // A Biiig asteroid
void shape37(int f); // A Medium asteroid
void shape38(int f); // A Little asteroid

