#include "defs.h"

#ifdef WINDOWS
extern Dword QUADWORDS;
#else
extern Word QUADWORDS;
#endif

#ifndef WINDOWS
extern Uchar far *adaptor;
#endif

extern Uchar far *adapted;
extern void reach_your_dir (void);
extern void _320_200_256 (void);
extern void _80_25_C (void);
extern Word attendi_pressione_tasto (void);
extern Word tasto_premuto (void);
extern Uchar range8088[64*3];
extern Uchar tmppal[768];
extern Uchar return_palette[768];
extern Uchar surface_palette[768];
extern Uchar old_surface_palette[768];
extern void tavola_colori (Uchar *nuova_tavolozza,
		    Uword colore_di_partenza, Uword nr_colori,
		    char filtro_rosso, char filtro_verde, char filtro_blu);
extern Word mdltx, mdlty, mx, my, mpul;
extern void mouse_input (void);
extern char test_and_init_mouse (void);
extern void pcopy (Uchar maybefar *dest, Uchar maybefar *sorg);
extern void pclear (Uchar maybefar *target, Uchar pattern);
extern void areacopy (Uchar maybefar *dest, Uchar maybefar *sorg,
		      Word x, Word y, Word l, Word h);
extern void areaclear (Uchar maybefar *dest, Word x, Word y,
		       Word x2, Word y2, Word l, Word h, Uchar pattern);
extern void psmooth_grays (Uchar maybefar *target);
extern void pfade (Uchar maybefar *target, Uword segshift, Uchar speed);
extern void psmooth_64 (Uchar maybefar *target, Uword segshift);
extern void smootharound_64 (Uchar maybefar *target, Dword cx, Dword cy, Dword r, char diffuse);
extern void mask_pixels (Uchar maybefar *target, Uchar mask);

const TEXTURE_XSIZE = 256; // Larghezza delle BMP.
const TEXTURE_YSIZE = 256; // Altezza delle BMP.
extern Dword XSIZE, YSIZE; // calibrazione BMP.
extern float uneg;
extern float alfa, beta, gamma;
extern float cam_x, cam_y, cam_z;
extern float dpp;
extern Dword H_MATRIXS, V_MATRIXS;
#ifdef WINDOWS
extern Udword riga[200];	//NOTVALID: Increase the length of this if we increase the display size.
#else
extern Uword riga[200];
#endif
extern void initscanlines (void);
extern Uword ptr;
extern Udword xp, yp, xa, ya;
extern Udword global_x, global_y;
extern void Segmento (void);
extern char flares;
extern float x2, y2, z2;
extern float xx, yy, zz;
extern Dword lbxl;
extern Dword ubxl;
extern Dword lbyl;
extern Dword ubyl;
extern float lbxf;
extern float ubxf;
extern float lbyf;
extern float ubyf;
extern float x_centro_f;
extern float y_centro_f;
extern float opt_pcosbeta;
extern float opt_psinbeta;
extern float opt_tcosbeta;
extern float opt_tsinbeta;
extern float opt_pcosalfa;
extern float opt_psinalfa;
extern float opt_tcosalfa;
extern float opt_tsinalfa;
extern void change_angle_of_view (void);
extern void change_camera_lens (void);
extern void change_txm_repeating_mode (void);
extern Uchar entity;
extern void poly3d (float *x, float *y, float *z,
	     Uword nrv, Uchar colore);
extern void Forward (float delta);
extern float pnx, pny, pnz;
extern void pnorm (float *x, float *y, float *z);
extern Uchar maybehuge *txtr;
extern Uword  maybehuge *wtxtr;
extern float x_antialias, y_antialias, z_antialias;
extern char culling_needed, halfscan_needed;
extern Uchar escrescenze;
extern void polymap (float *x, float *y, float *z, char nv, Uchar tinta);
extern void polymap2 (float *x, float *y, float *z, char nv, Uchar tinta);
extern Dword _x_, _y_;
extern char getcoords (float x, float y, float z);
extern char facing (float *x, float *y, float *z);

extern char   *situation_file;
extern char   *starmap_file;
extern char   *starmap3_file;
extern char   *starmap3b_file;
extern char   *goesoutputfile;
extern char *surface_file;
extern FILEPTR    sfh;

extern char   sync;
extern char   anti_rad;
extern char   pl_search;
extern char   field_amplificator;
extern char   ilight;
extern char   ilightv;
extern char   charge;
extern char   revcontrols;
extern char   ap_targetting;
extern char   ap_targetted;
extern char   ip_targetting;
extern char   ip_targetted;
extern char   ip_reaching;
extern char   ip_reached;
extern char   ap_target_spin;
extern char   ap_target_r;
extern char   ap_target_g;
extern char   ap_target_b;
extern char   nearstar_spin;
extern char   nearstar_r;
extern char   nearstar_g;
extern char   nearstar_b;
extern char   gburst;
extern char   menusalwayson;
extern char   depolarize;
extern Word    sys;
extern Word    pwr;
extern Word    dev_page;
extern Word    ap_target_class;
extern Word    f_ray_elapsed;
extern Word    nearstar_class;
extern Word    nearstar_nop;
extern float  pos_x;
extern float  pos_y;
extern float  pos_z;
extern float  user_alfa;
extern float  user_beta;
extern float  navigation_beta;
extern float  ap_target_ray;
extern float  nearstar_ray;
extern double dzat_x;
extern double dzat_y;
extern double dzat_z;
extern double ap_target_x;
extern double ap_target_y;
extern double ap_target_z;
extern double nearstar_x;
extern double nearstar_y;
extern double nearstar_z;
extern double helptime;
extern double ip_target_initial_d;
extern double requested_approach_coefficient;
extern double current_approach_coefficient;
extern double reaction_time;
extern char   fcs_status[11];
extern Word    fcs_status_delay;
extern Word    psys;
extern double ap_target_initial_d;
extern double requested_vimana_coefficient;
extern double current_vimana_coefficient;
extern double vimana_reaction_time;
extern char   lithium_collector;
extern char   autoscreenoff;
extern char   ap_reached;
extern Word    lifter;
extern double secs;
extern char   data;
extern char   surlight;
//Additional variables: (SL)
extern char   option_speedup;
extern char   option_temperature;
extern double nearstar_mass;
extern double nearstar_surfaceTemperature;
extern double nearstar_temperatureTransmission;
extern char   option_temperature_units;
extern char	  option_flying_lander;
extern char   option_antialias_in_stardrifter;
extern char   option_center_outerring_pointer;
extern char   option_x_axis_pointer;
extern char   option_y_axis_pointer;
extern char   option_z_axis_pointer;
extern char   option_multiplayer;
extern char   option_invis_sd;
extern char   option_change_over_time;
extern Dword   lastSnapshot;
extern char   option_mouseLook;
extern Dword ap_target_sx;		//41
extern Dword ap_target_sy;		//45
extern Dword ap_target_sz;		//49
extern Dword nearstar_sx;		//53
extern Dword nearstar_sy;		//57
extern Dword nearstar_sz;		//61
extern char option_3dbrackets;	//65
extern char option_controlset;	//66
extern char current_galaxy;		//67

extern char fcs_status_extended[42];

extern Word old_currentbin_length;
extern Word new_currentbin_length;

extern char   land_now;
extern char   landing_point;
extern Word    landing_pt_lon;
extern Word    landing_pt_lat;
extern Word    rotation;
extern char seconds[3], minutes[3], hours[3], n_day[3], n_month[3], n_year[5];
extern Word  epoc;
extern Uchar cyclon[384];
extern char          ctb[512];
extern char	      _delay;
extern char          stspeed;
extern char          bright;
extern char   	     elight;
extern Uword      gl_start;
#ifdef WINDOWS
extern Udword      point;
extern Udword      vptr;
#else
extern Uword      point;
extern Uword      vptr;
#endif
extern Word           infoarea;
extern Word           s_control;
extern Word           s_command;
extern Word           isecs, p_isecs;
extern double	     fsecs;
extern Word	     gl_fps;
extern Word	     fps;
extern float         dlt_alfa;
extern float	     dlt_beta;
extern float	     dlt_nav_beta;
extern float	     step;
extern float slide;
extern float	     shift;
extern double        s_m;
extern double	     plx, ply, plz;
extern double        pxx, pyy;
extern double        delta_x, delta_y;
extern double 	     nearstar_identity;
extern Word	     nearstar_nob;
extern Word	     nearstar_labeled;
extern Word 	     npcs;
extern char   	     ontheroof;
extern Word	     datasheetscroll;
extern Word	     datasheetdelta;
extern char 	cloudFilter;
extern char		terrainFilter;

extern char *ord[21];
extern char *star_description[12];
extern char class_rgb[3*star_classes];
extern Word class_ray[star_classes];
extern Word class_rayvar[star_classes];
extern Word class_act[star_classes];
extern char class_planets[star_classes];
extern char   nearstar_p_type       [ng_maxbodies];
extern Word    nearstar_p_owner	    [ng_maxbodies];
extern char   nearstar_p_moonid     [ng_maxbodies];
extern char   nearstar_p_mapped     [ng_maxbodies];
extern double nearstar_p_ring       [ng_maxbodies];
extern double nearstar_p_tilt       [ng_maxbodies];
extern double nearstar_p_ray        [ng_maxbodies];
extern double nearstar_p_orb_ray    [ng_maxbodies];
extern double nearstar_p_orb_tilt   [ng_maxbodies];
extern double nearstar_p_orb_orient [ng_maxbodies];
extern double nearstar_p_orb_ecc    [ng_maxbodies];
extern double nearstar_p_orb_seed   [ng_maxbodies];
extern Word    nearstar_p_rtperiod   [ng_maxbodies];
extern Word    nearstar_p_rotation   [ng_maxbodies];
extern Word    nearstar_p_term_start [ng_maxbodies];
extern Word    nearstar_p_term_end   [ng_maxbodies];
extern Word    nearstar_p_qsortindex [ng_maxbodies];
extern float  nearstar_p_qsortdist  [ng_maxbodies];
extern char *planet_description[10];
extern Uchar planet_rgb_and_var[40];
extern Word planet_possiblemoons[10];
extern float mindiff;
extern Uchar maybefar  *p_background;
extern Uchar maybefar  *s_background;
extern Uchar maybehuge *p_surfacemap;
extern quadrant      maybefar  *objectschart;
extern Uchar maybefar  *ruinschart; // come objectschart, ma dichiarato in bytes
extern Uchar maybefar  *pvfile;
extern Uchar maybefar  *n_offsets_map;
extern char maybefar           *n_globes_map;
extern Uword	    seg_adapted;
extern char sky_red_filter;
extern char sky_grn_filter;
extern char sky_blu_filter;
extern char gnd_red_filter;
extern char gnd_grn_filter;
extern char gnd_blu_filter;
extern float planet_grav;
extern float rainy;
extern Word albedo;
extern Word raw_albedo;
extern Word old_albedo;
extern Uchar sky_brightness;
extern Uchar horiz_brt;
extern Uword m200[200];
extern Uword wtl;
extern float	rwp;
extern float    iwp;
extern float    wp;
extern float    wdir;
extern float    wdirsin;
extern float    wdircos;
extern char landed;
extern char lifter_homing;
extern char lifter_vertical;
extern Dword atl_x, atl_z, atl_x2, atl_z2, atl_y;
extern double atl_xx, atl_zz;
extern double qid;
extern FILEPTR fn;
extern Uchar maybefar *fnv, *fcolor;
extern float maybefar *fx, *inv_fx, *fy, *fz;
extern Word vhn;
extern float maybefar *vhx, *vhy, *vhz;
extern float maybefar *vhxm, *vhym, *vhzm, *vh_mdq;
extern Uchar maybefar *vhnv, *vhcolor, *vhindex;
extern Word in;
extern float maybefar *ix, *iy, *iz;
extern Uchar maybefar *inv, *icolor;
extern Word alpha_n;
extern Uchar maybefar *alpha_nv;
extern float maybefar *alpha_x, *alpha_y, *alpha_z;
extern Dword flat_rnd_seed;
extern void fast_srand (Dword seed);
extern Dword fast_random (Dword mask);
extern Word ranged_fast_random (Word range);
extern FILEPTR sa_open (Dword offset_of_virtual_file);
extern void shade (Uchar maybefar *palette_buffer,
		   Word first_color, Word number_of_colors,
		   float start_r,  float start_g,  float start_b,
		   float finish_r, float finish_g, float finish_b);
extern char snapfilename[24];
extern void snapshot (Word forcenumber, char showdata);
extern char helpfile_hlp[13];
extern char *helpfile_img[13];
extern void readline (Word tfh);
extern void from_vehicle (void);
extern void from_user (void);
extern void from_both();
extern void watch (double cam_x, double cam_y, double cam_z,
	    double see_x, double see_y, double see_z);
extern char xy (double cam_x, double cam_y, double cam_z,
	 double point_x, double point_y, double point_z);
extern void p_Forward (float delta);
extern void copia (Uchar maybefar *dest, Uchar maybefar *sorg, Uword x, Uword y, Word l, Word a);
extern void setfx (char fx);
extern void chgfx (char fx);
extern void resetfx (void);
extern void Stick (Udword xp, Udword yp,
	    Udword xa, Udword ya);
extern Dword fpx;
extern Dword fpy;
extern float p_rx, p_ry, p_rz;
extern float stick_uneg;
extern void stick3d (float p_x, float p_y, float p_z,
	      float x, float y, float z);
extern void link3d (float x, float y, float z);
extern void fline (Dword fx, Dword fy,
	    Dword lx, Dword ly);
//--------------------------------------------------------------------------//
extern Uchar map_color_a;
extern Uchar map_color_b;
extern Uchar map_color_c;
extern Uchar map_color_d;
extern void randomic_mapper (float x0,
		      float y0,
		      float z0,
		      float x1,
		      float y1,
		      float z1,
		      float x2,
		      float y2,
		      float z2,
		      char divisions);
extern void unloadpv (Word handle);
extern void unloadallpv (void);
extern char loadpv (Word   handle, Dword virtual_file_position,
		    float xscale, float yscale, float zscale,
		    float xmove,  float ymove,  float zmove,
		    Uchar base_color,   char depth_sort);
extern char loadpvs (Word   handle, const char *filename,
	     float xscale, float yscale, float zscale,
	     float xmove,  float ymove,  float zmove,
	     Uchar base_color,   char depth_sort);
extern char loadpvf (Word handle, int filename,
	     float xscale, float yscale, float zscale,
	     float xmove,  float ymove,  float zmove,
	     Uchar base_color,   char depth_sort);
extern void QuickSort (Word maybefar *index, float maybefar *mdist, Word start, Word end);
extern void drawpv (Word handle, Word mode, Word rm_iterations,
		    float center_x, float center_y, float center_z,
		    char use_depth_sort);
extern void copypv (Word dest_handle, Word src_handle);
extern void workpv (Word dest_handle, Word src_handle);
extern float getUpmostYFromPV(Word handle);
extern float getDownmostYFromPV(Word handle);
extern float getLowXFromPV(Word handle);
extern float getLowZFromPV(Word handle);
extern float getHighXFromPV(Word handle);
extern float getHighZFromPV(Word handle);
extern void modpv (Word handle, Word polygon_id, Word vertex_id,
		   float x_scale, float y_scale, float z_scale,
		   float x_angle, float y_angle, float z_angle,
		   pvlist *vertexs_to_affect);
//--------------------------------------------------------------------------//
extern char *alphavalue (double value);
extern void background (Uword start,
		 Uchar maybefar *target,
		 Uchar maybefar *background,
		 Uchar maybefar *offsetsmap,
		 Uword total_map_bytes,
		 Uword screenshift);
extern void sky (Uword limits);
extern double laststar_x, laststar_y, laststar_z;
extern char isthere (double star_id);
extern Uchar glass_bubble;
extern void globe (Uword start,
	    Uchar maybefar *target,
	    Uchar maybefar *tapestry,
	    Uchar maybefar *offsetsmap,
	    Uword total_map_bytes,
	    double x, double y, double z,
	    float mag_factor, char colormask,
	    char globe_saturation);
extern void glowinglobe (Word start,
	    Uchar maybefar *target,
	    Uchar maybefar *offsetsmap,
	    Uword total_map_bytes,
	    double x, double y, double z, float mag_factor,
	    Word terminator_start, Word terminator_end, Uchar color);
extern void whiteglobe (Uchar maybefar *target,
	    double x, double y, double z,
	    float mag_factor, float fgm_factor);
extern double xsun_onscreen;
extern void whitesun (Uchar maybefar *target,
	    double x, double y, double z,
	    float mag_factor, float fgm_factor);
extern float maybefar lft_sin[361];
extern float maybefar lft_cos[361];
extern char lens_flares_init (void);
extern void lens_flares_for (double cam_x, double cam_y, double cam_z,
		      double xlight, double ylight, double zlight,
		      double step, Word added, char on_hud, char condition,
		      Word xshift, Word yshift);
extern void single_pixel_at_ptr (Uword ptr, Uchar pixel_color);
extern char far_pixel_at (double xlight, double ylight, double zlight, double radii, Uchar unconditioned_color);
extern Udword maybefar *digimap2;
extern void cupola (float y_or, float brk);
extern void polycupola (float y_or, char textured);
//extern void alogena (void);
//extern void qsel (float *x, float *y, float *z, Uword n, Uchar c);
//extern void reflexes (void);
//extern void squaredot (float x, float y, float size, Uchar color);
//extern void digit_at (char digit, float x, float y, float size, Uchar color);
//extern void screen (void);
//extern void frame (float x, float y, float l, float h, float borderwidth, Uchar color);
//extern void pointer_cross_for (double xlight, double ylight, double zlight);
//extern void cline (Word line, char *text);
//extern void other (char *text);
//extern void control (Word line, char *text);
//extern void command (Word nr, char *text);
//extern void clear_onboard_screen (void);
//--------------------------------------------------------------------------//
//extern Uchar reset_signal;
//extern char active_screen;
//extern void build_osscreen (void);
//extern void mslocate (Word screen_id, Word cursor_x, Word cursor_y);
//extern void mswrite (Word screen_id, char* text);
//--------------------------------------------------------------------------//
//extern void show_planetary_map ();
//extern Word goesk_a;
//extern Word goesk_e;
//extern void vehicle (float opencapcount);
//extern void other_vehicle_at (double ovhx, double ovhy, double ovhz);
extern void getsecs (void);
extern void extract_ap_target_infos (void);
extern float zrandom (Word range);
extern Word starnop (double star_x, double star_y, double star_z);
extern void prepare_nearstar (FastBool option);
extern void ssmooth (Uchar maybefar *target);
extern void lssmooth (Uchar maybefar *target);
extern Word      c, gr, r, g, b, cr, cx, cy;
extern char     lave, crays;
extern float    kfract;
extern Uword px, py;
extern float    a;
extern void spot (void);
extern void permanent_storm (void);
extern void crater (void);
extern void band (void);
extern void wave (void);
extern void fracture (Uchar maybefar *target, float max_latitude);
extern void volcano (void);
extern void contrast (float kt, float kq, float thrshld);
extern void randoface (Word range, Word upon);
extern void negate (void);
extern void crater_juice (void);
extern void cirrus (void);
extern void atm_cyclon (void);
extern void storm (void);
extern void planet_xyz (Word n);
extern float rtp (Word n);
extern Word planet_viewpoint (double obs_x, double obs_z);
extern void surface (Word logical_id, Word type, double seedval, Uchar colorbase);
extern Word nightzone, crepzone, sun_x_factor;
extern void planets ();
extern void ring (void);
extern void init_FP_segments (void);
extern FILEPTR smh;
extern double idscale;
extern double laststar_x, laststar_y, laststar_z;
extern Dword laststar_sx, laststar_sy, laststar_sz;
extern char isthere (double star_id);
#ifdef OLD_STARMAP
extern Dword search_id_code (double id_code, char type);
#else
#ifdef WINDOWS
extern Dword planet_labelled (Udword tgt_starFP, Dword bodyNum, Dword owner, Dword moonId, Dword pType, FastBool tgt_deleted, Udword galaxy);
extern Dword system_labelled (Dword tgt_sx, Dword tgt_sy, Dword tgt_sz, Udword galaxy);
extern Dword deleted_system_labelled (Dword tgt_sx, Dword tgt_sy, Dword tgt_sz, Udword galaxy);
extern Dword something_labelled (char *tgt_name, Udword galaxy);
extern Dword something_pointing_alt_to (Udword tgt_nextAlternateFP, Udword galaxy);
extern Dword something_pointing_star_to (Udword tgt_starFP, Udword galaxy);
extern Dword labelled_system_number (Udword num, Udword galaxy);
#else
extern Dword planet_labelled (Udword tgt_starFP, Dword bodyNum, Dword owner, Dword moonId, Dword pType, FastBool tgt_deleted);
extern Dword system_labelled (Dword tgt_sx, Dword tgt_sy, Dword tgt_sz);
extern Dword deleted_system_labelled (Dword tgt_sx, Dword tgt_sy, Dword tgt_sz);
extern Dword something_labelled (char *tgt_name);
extern Dword something_pointing_alt_to (Udword tgt_nextAlternateFP);
extern Dword something_pointing_star_to (Udword tgt_starFP);
extern Dword labelled_system_number (Udword num);
#endif
#endif
extern Dword tgt_collect_lastpos;
extern Word targets;
extern Word topmost_target;
extern Word target_line;
extern char update_targets;
extern char collecting_targets;
#ifdef OLD_STARMAP
extern double targets_table_id[50];
#else
extern Dword targets_table_sx[50];
extern Dword targets_table_sy[50];
extern Dword targets_table_sz[50];
#endif
extern double targets_table_px[50];
extern double targets_table_py[50];
extern double targets_table_pz[50];
extern void collect_targets (void);
extern void status (const char *status_description, Word message_delay);

extern float flandom ();
extern float fast_flandom ();

extern clock_t gtime;
extern void sync_start ();
extern void sync_stop ();

extern Dword   global_surface_seed, local_surface_seed, global_surface_seed_raw;
extern float  ppos_x, ppos_y, ppos_z;
extern double dsd, dsdSq;

extern void load_starface ();
extern void load_QVRmaps ();
extern void load_digimap2 ();

extern char outhudbuffer[81];
extern void wrouthud (Uword x, Uword y, Uword l, char *text, Word color = 191);
extern void surrounding (char compass_on, Word openhudcount);

extern float	pp_gravity;
extern float	pp_temp;
extern float	pp_pressure;
extern float    pp_pulse;

extern void additional_consumes (void);

extern Word resident_map1, resident_map2;	//records the body #s which have resident maps or something like that. We need to clear them when changing sectors to prevent palette bugs (We also have to change 'npcs' to -12345, and we also do that elsewhere also to fix the duplicate-planet-appearance bug).

extern Word class_surfacetemp_mult[star_classes];
extern Word class_surfacetemp_add[star_classes];
extern char dfm[13];

extern char ip_vimana;