Character.h

00001 // ----------------------------------------------------------------------------
00002 //
00003 // tagGame - Example code from the book:
00004 //
00005 //           Artficial Intelligence for Computer Games: An Introduction
00006 //           by John David Funge
00007 //
00008 //           www.ai4games.org
00009 //
00010 // Source code distributed under the Copyright (c) 2003-2007, John David Funge
00011 // Original author: John David Funge (www.jfunge.com)
00012 //
00013 // Licensed under the Academic Free License version 3.0 
00014 // (for details see LICENSE.txt in this directory).
00015 //
00016 // ----------------------------------------------------------------------------
00017 
00018 #ifndef TG_CHARACTER_H
00019 #define TG_CHARACTER_H
00020 
00021 #include "Obstacle.h"
00022 #include "Action.h"
00023 #include "Controller.h"
00024 #include "Shape.h"
00025 
00026 namespace tagGame
00027 {
00028    class Controller;
00029 
00033    class Character : public Obstacle
00034    {
00035    public:
00036       Character(ShapePtr shape, ControllerPtr controller);
00037       ~Character();
00038 
00040       inline ControllerPtr getController();
00042       inline void setController(ControllerPtr controller);
00043 
00044       inline bool getIsTagged() const;
00045       inline int getTaggedTime() const;
00046       // TODO: rename to setTaggedTime
00047       void setTagged(int tagTime);
00048 
00049       inline void setCollideTime(int collideTime);
00050       inline int getCollideTime() const;
00051 
00052       inline void calcAction();
00053       inline Action const& getAction() const;
00054       inline Real getMaxTurnRate() const;
00055       inline Real getMaxSpeed() const;
00056       inline Real getMaxForce() const;
00057 
00058    protected:
00059    private:
00061       ControllerPtr controller;
00062       Action lastAction;
00063       Real maxTurnRate;
00064       Real maxSpeed;
00065       Real maxForce;
00066       // How long since this character was tagged (-1 if not currently tagged).
00067       int tagTime;
00068       // How long since this character collided with something (-1 if never collided).
00069       int collideTime;
00070    };
00071 
00072    typedef SharedPtr<Character>::type CharacterPtr;
00073    typedef std::vector<CharacterPtr> CharacterList;
00074    typedef CharacterList::const_iterator CharacterIteratorConst;
00075    typedef CharacterList::iterator CharacterIterator;
00076 
00077    void Character::calcAction()
00078    {
00079       controller->calcAction();
00080       // Controller's can be shared, so save this character's last computed action
00081       // in the class
00082       lastAction = controller->getAction();
00083    }
00084    
00085    Action const& Character::getAction() const
00086    {
00087       return lastAction;
00088    }
00089 
00090    bool Character::getIsTagged() const
00091    {
00092       return 0 <= tagTime;
00093    }
00094    
00095    int Character::getTaggedTime() const
00096    {
00097       return tagTime;
00098    }
00099    
00100    Real Character::getMaxTurnRate() const
00101    {
00102       return maxTurnRate;
00103    }
00104    
00105    Real Character::getMaxSpeed() const
00106    {
00107       if (getIsTagged()) { return 0.8 * maxSpeed; }
00108       return maxSpeed;
00109    }
00110    
00111    Real Character::getMaxForce() const
00112    {
00113       return maxForce;
00114    }
00115    
00116    ControllerPtr Character::getController()
00117    {
00118       return controller;
00119    }
00120    
00121    void Character::setController(ControllerPtr controller)
00122    {
00123       this->controller = controller;
00124    }
00125    
00126    void Character::setCollideTime(int collideTime)
00127    {
00128       this->collideTime = collideTime;
00129    }
00130    
00131    int Character::getCollideTime() const
00132    {
00133       return collideTime;
00134    }
00135 }
00136 
00137 #endif

Generated on Sat Mar 31 22:30:54 2007 for tagGame by  doxygen 1.5.1