Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

unit.h

Go to the documentation of this file.
00001 /***************************************************************************
00002                           unit.h  -  description
00003                              -------------------
00004     begin                : Wed Jul 25 2001
00005     copyright            : (C) 2001 by T Kontkanen
00006     email                : tkontkanen@mail.com
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00018 #ifndef UNIT_H
00019 #define UNIT_H
00020 
00021 class Game;
00022 class Unit;
00023 
00024 #include "game.h"
00025 #include "renderer.h"
00026 //#include "player.h"
00027 //#include "ground.h"
00028 #include "allincludes.h"
00029 #include "gamedefs.h"
00030 #include "vector.h"
00031 
00037 enum UnitTypes { STATIC, BUILDING, BULLET, GROUND_UNIT, AIR_UNIT };
00038 
00039 class Unit {
00040 public:
00041     Unit( Game *pgame );
00042     virtual ~Unit();
00043 
00044     //controls
00046     virtual int action( int actionnum, Vector destpos )=0;
00048     virtual void setPrimaryAction( int actionnum ) { primaryActionNum=actionnum; }
00050     virtual int primaryAction( Vector destpos ) { action( primaryActionNum, destpos ); }
00052     virtual void setUnitPosition( Vector pos )=0;
00054     virtual Vector& getUnitPosition( void )=0;
00056     bool isSelected() { return bIsSelected; }
00058     bool screenSelect( Vector sel1, Vector sel2 );
00059     
00061     Unit *getTarget();
00063     void setTarget( Unit *enemy );
00065     void setTarget( int player, int unitnum );
00066 
00068     enum UnitTypes getUnitType() { return unittype; }
00069     
00071     float getHitpoints() { return hitpoints; }
00073     float getMaxHitpoints() { return hitpoints; }
00075     void setHitpoints( float percent ) { hitpoints=percent*maxhitpoints; }
00077     void decreaseHitpoints( float amount ) { hitpoints-=amount; }
00079     void increaseHitpoints( float amount ) { hitpoints+=amount; }
00081     bool isAlive() { if( hitpoints>0 ) return true; else return false; }
00082 
00083     virtual int render()=0; // render this unit, implementation required in all units
00084     virtual int step()=0; // make a move (called once per frame)
00085 
00086 protected:
00088     void setMaxHitpoints( float maxpoints ) { maxhitpoints=maxpoints; }
00090     void setUnitType( enum UnitTypes type ) { unittype=type; }
00091     
00092 private:
00093 
00094     //needed information
00095     Renderer *uRenderer;
00096     Game *uGame;
00097     Ground *uGround;
00098     Player **uPlayers; //the other players including this
00099     
00100     // unit stuff
00101     int primaryActionNum;
00102     bool bIsSelected;
00103     Unit *uTarget;
00104     int uTargetNum, uTargetPlayer;
00105     float maxhitpoints, hitpoints;
00106     enum UnitTypes unittype;
00107     //unit information
00108 };
00109 
00110 #endif

Generated at Fri Oct 5 20:23:52 2001 for Executor by doxygen1.2.10 written by Dimitri van Heesch, © 1997-2001