/********************************************************************
×××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××
##
##      DogFight!_class.h
##
## Defines Fighters, Shots, Coords, and functions on these objects.
##
## V0.6 28-FEB-94
##
×××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××
*********************************************************************/

#include <string.h>
#include <stddef.h>
#include <intuition/intuition.h>
#include <libraries/mathffp.h>

#include <clib/graphics_protos.h>
#include <clib/intuition_protos.h>
#include <clib/mathffp_protos.h>
#include <clib/mathtrans_protos.h>
#include <clib/alib_protos.h>

#include <proto/intuition.h>
#include <proto/graphics.h>
#include <proto/mathffp.h>
#include <proto/mathtrans.h>

extern ULONG scrn_left, scrn_right, scrn_top, scrn_bottom;
extern struct TextAttr topaz8;
extern struct IntuiText PLT[];
extern const int slow[];
extern const int medium[];
extern const int fast[];
extern const int shotspeed[];
extern int game_speed;
extern BOOL vulnerability;

/******************************************
×××××××××××××××××××××××××××××××××××××××××××
        The COORD class handles all of our
        screen positioning, and is screen
        size sensitive (assuming we set the
        correct variables in the DogFight!.h)
        It handles inc/decrementing (movement),
        wraparound, and keeps track of the
        position in floating point.
×××××××××××××××××××××××××××××××××××××××××××
******************************************/

class COORD {
        public:
                float xinc, yinc;
                float fx, fy;
                int x, y;

                COORD();

                void inc();
                //      Increment the coords and check for
                //      wraparound.

                int dist(COORD);
                //      Returns the distance between itself
                //      and the supplied coordinate.

                void set_f(float, float);

};

/******************************************
×××××××××××××××××××××××××××××××××××××××××××
        Our SHOT class.  Since Jets don't
        collide, this is the only way to shoot
        down enemy craft =-).
×××××××××××××××××××××××××××××××××××××××××××
******************************************/

class SHOT {
        COORD c, old_c;                         // Coords for location
        float dir;                                              // direction of travel
        int dist;                                               // dist-ance travelled

        void erase(struct RastPort *);
        void draw(struct RastPort *);

        public:
                int underway;                                   // underway if active

                SHOT();
                void bang(COORD, float, int);

                void move(struct RastPort *);
                //      Responsible for erasing, repositioning,
                //      and redrawing the shot, as well
                //      as checking to see if the shot has moved
                //      it's maximum range.
                //      See FIGHTER::move().

                BOOL collide(COORD);
                //      Check for collision with the supplied
                //      coordinate.
                //      Returns TRUE if collision, and if so,
                //      stops shot.

                void stop();
};

/******************************************
×××××××××××××××××××××××××××××××××××××××××××
        The Jet class.
        We have:
        * 3 coordinates for double-
        buffering (to remember where we _were_),
        * dir for direction, in rads (bleh!)
        * turnrad for rate of turn
        * 2 flags (rf&lf) for remembering in
        which direction we're turning
        * explosions for how big and long we
        explode
        * color to identify the Jet
        * speed for how fast the Jet is
        * deadtime to keep track of how long
        we have to go before we're resurected
        * txt for our Jet identification number.
        * alive for whether we've been shot
        * in_play to tell if the Jet is being
        used
        * killscore for how many jets we've
        shot down
        * and our very own SHOT.
×××××××××××××××××××××××××××××××××××××××××××
******************************************/

class FIGHTER {
        COORD c, old_c;                                         // where to draw and erase
        float dir, turnrad;                                     // direction and turn radius
        BOOL rf, lf;                                                    // if turning right or left
        int explosions, deadtime;                       // counters for non-flight time =-)
        int color, speed;                                               // color and speed of the Jet
        struct IntuiText *txt;                          // the Jet's ID number
        BOOL shootable;                                         // starttime invulnerability

        void draw(struct RastPort *);
        void draw_explode(struct RastPort *);

        public:
                BOOL alive, in_play;                            // if alive, or even in game
                int killscore;                                          // number of enemy kills
                SHOT shot;                                                      // the (renewable) missile

                void erase(struct RastPort *);
                //      Quick erase of the fighter shape.
                //      It would be better to erase just the
                //      shape instead of a block fill, but
                //      it takes too long.

                void move(struct RastPort *);
                //      Responsible for erasing, calculating
                //      the new position, and drawing the Jet
                //      in the supplied RastPort.  Assumes that
                //      we're double buffered; IE, that we're
                //      drawing on exactly two screens (hence
                //      the c, old_c, and oold_c coordinates).
                //      Also calls the explosion routines if
                //      the Jet is in the process of dying.

                void init(int, int);
                //      Set up Jet values.
                //      - 'a' is the player number,
                //      - 'perf' is the Jet type option set in
                //      the prefs window.
                //      Player1 (a=0) starts in the upperleft
                //      screen corner, Player2 (a=1) in the
                //      upperright, etc.
                //      perf=0 means the Jet is not in play,
                //      perf=1 is a compromise Jet, etc.

                void right();
                void left();
                void fire();

                BOOL collide(SHOT *);
                //      Checks to see if the Jet has collided
                //      with the supplied SHOT.

                void resurect(int, int);
                //      Keeps the Jet out of play for a
                //      certain amount of time (deadtime loops),
                //      and then starts him up again.
};
