Main Page | Class Hierarchy | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

Unit Class Reference

Collaboration diagram for Unit:

Collaboration graph
[legend]

Detailed Description

Unit to drive.

Definition at line 18 of file Unit.h.

Public Member Functions

 Unit (const KeyControl &buttons, const ControlSym &symbols, bool startActive=false)
 Create new driveable unit.
void takeModel (Cube *model)
bool startActive ()
bool canDrive () const
bool willMove () const
 Return true when we can move in future.
char drive (const InputProvider *input)
 Test keys and try move.
char driveBorrowed (const InputProvider *input, const KeyControl &buttons)
 Test keys and try move, use borrowed controls.
void activate ()
 Greet the player.
char mySymbol (SDLKey key) const
 Translate this key to symbol.
char mySymbolBorrowed (SDLKey key, const KeyControl &buttons) const
 Translate this key to symbol, compare with borrowed buttons.
char myOrder (Dir::eDir dir) const
 Returns symbol for this direction.
char driveOrder (char move)
 Make move.
bool isMoving () const
bool isTurning () const
bool isPushing () const
bool equalsModel (const Cube *other) const
 Returns true when models are equal.
V2 getLoc () const
int getW () const
int getH () const
bool isFreePlace (const V2 &loc) const
int countAnimPhases (const std::string &anim) const
bool isPowerful () const


Constructor & Destructor Documentation

Unit::Unit const KeyControl buttons,
const ControlSym symbols,
bool  a_startActive = false
 

Create new driveable unit.

Parameters:
buttons control buttons
symbols move symbols stored in load/save
a_startActive whether unit should be active at start

Definition at line 26 of file Unit.cpp.

00028     : m_buttons(buttons), m_symbols(symbols)
00029 {
00030     m_model = NULL;
00031     m_startActive = a_startActive;
00032 }


Member Function Documentation

void Unit::activate  ) 
 

Greet the player.

Definition at line 90 of file Unit.cpp.

00091 {
00092     m_model->rules()->actionActivate();
00093 }

bool Unit::canDrive  )  const
 

Definition at line 35 of file Unit.cpp.

00036 {
00037     return m_model->isAlive()
00038         && !m_model->isLost()
00039         && !m_model->isBusy();
00040 }

int Unit::countAnimPhases const std::string &  anim  )  const
 

Definition at line 285 of file Unit.cpp.

00286 {
00287     return m_model->anim()->countAnimPhases(anim);
00288 }

char Unit::drive const InputProvider input  ) 
 

Test keys and try move.

Returns:
a symbol when unit has moved

Definition at line 57 of file Unit.cpp.

00058 {
00059     return driveBorrowed(input, m_buttons);
00060 }

char Unit::driveBorrowed const InputProvider input,
const KeyControl buttons
 

Test keys and try move, use borrowed controls.

Returns:
a symbol when unit has moved or SYM_NONE

Definition at line 67 of file Unit.cpp.

00068 {
00069     if (canDrive()) {
00070         if (input->isPressed(buttons.getLeft())) {
00071             return goLeft();
00072         }
00073         if (input->isPressed(buttons.getRight())) {
00074             return goRight();
00075         }
00076         if (input->isPressed(buttons.getUp())) {
00077             return goUp();
00078         }
00079         if (input->isPressed(buttons.getDown())) {
00080             return goDown();
00081         }
00082     }
00083     return ControlSym::SYM_NONE;
00084 }

char Unit::driveOrder char  move  ) 
 

Make move.

Returns:
move symbol or SYM_NONE for bad move

Definition at line 153 of file Unit.cpp.

00154 {
00155     if (canDrive()) {
00156         if (m_symbols.getLeft() == move) {
00157             return goLeft();
00158         }
00159         if (m_symbols.getRight() == move) {
00160             return goRight();
00161         }
00162         if (m_symbols.getUp() == move) {
00163             return goUp();
00164         }
00165         if (m_symbols.getDown() == move) {
00166             return goDown();
00167         }
00168     }
00169     return ControlSym::SYM_NONE;
00170 }

bool Unit::equalsModel const Cube other  )  const
 

Returns true when models are equal.

Definition at line 255 of file Unit.cpp.

00256 {
00257     return m_model == other;
00258 }

int Unit::getH  )  const
 

Definition at line 273 of file Unit.cpp.

00274 {
00275     return m_model->shape()->getH();
00276 }

V2 Unit::getLoc  )  const
 

Definition at line 261 of file Unit.cpp.

00262 {
00263     return m_model->getLocation();
00264 }

int Unit::getW  )  const
 

Definition at line 267 of file Unit.cpp.

00268 {
00269     return m_model->shape()->getW();
00270 }

bool Unit::isFreePlace const V2 loc  )  const
 

Definition at line 279 of file Unit.cpp.

00280 {
00281     return m_model->const_rules()->isFreePlace(loc);
00282 }

bool Unit::isMoving  )  const
 

Definition at line 226 of file Unit.cpp.

00227 {
00228     bool result = false;
00229     if (canDrive()) {
00230         std::string action = m_model->rules()->getAction();
00231         result = action == "move_left" || action == "move_right"
00232             || action == "move_up" || action == "move_down"
00233             || action == "turn";
00234     }
00235     return result;
00236 }

bool Unit::isPowerful  )  const
 

Definition at line 291 of file Unit.cpp.

00291                        {
00292     return m_model->getPower() >= Cube::HEAVY;
00293 }

bool Unit::isPushing  )  const
 

Definition at line 246 of file Unit.cpp.

00247 {
00248     return m_model->rules()->getState() == "pushing";
00249 }

bool Unit::isTurning  )  const
 

Definition at line 239 of file Unit.cpp.

00240 {
00241     std::string action = m_model->rules()->getAction();
00242     return action == "turn";
00243 }

char Unit::myOrder Dir::eDir  dir  )  const
 

Returns symbol for this direction.

Definition at line 131 of file Unit.cpp.

00132 {
00133     switch (dir) {
00134         case Dir::DIR_LEFT:
00135             return m_symbols.getLeft();
00136         case Dir::DIR_RIGHT:
00137             return m_symbols.getRight();
00138         case Dir::DIR_UP:
00139             return m_symbols.getUp();
00140         case Dir::DIR_DOWN:
00141             return m_symbols.getDown();
00142         default:
00143             assert(!"unknown dir");
00144     }
00145     return ControlSym::SYM_NONE;
00146 }

char Unit::mySymbol SDLKey  key  )  const
 

Translate this key to symbol.

Returns:
symbol or SYM_NONE for unknown key

Definition at line 100 of file Unit.cpp.

00101 {
00102     return mySymbolBorrowed(key, m_buttons);
00103 }

char Unit::mySymbolBorrowed SDLKey  key,
const KeyControl buttons
const
 

Translate this key to symbol, compare with borrowed buttons.

Returns:
symbol or SYM_NONE for unknown key

Definition at line 110 of file Unit.cpp.

00111 {
00112     if (key == buttons.getLeft()) {
00113         return m_symbols.getLeft();
00114     }
00115     if (key == buttons.getRight()) {
00116         return m_symbols.getRight();
00117     }
00118     if (key == buttons.getUp()) {
00119         return m_symbols.getUp();
00120     }
00121     if (key == buttons.getDown()) {
00122         return m_symbols.getDown();
00123     }
00124     return ControlSym::SYM_NONE;
00125 }

bool Unit::startActive  )  [inline]
 

Definition at line 33 of file Unit.h.

00033 { return m_startActive; }

void Unit::takeModel Cube model  )  [inline]
 

Definition at line 32 of file Unit.h.

00032 { m_model = model; }

bool Unit::willMove  )  const
 

Return true when we can move in future.

Definition at line 46 of file Unit.cpp.

00047 {
00048     return m_model->isAlive()
00049         && !m_model->isLost();
00050 }


The documentation for this class was generated from the following files:
Generated on Wed Jun 1 09:57:06 2005 for Fish Fillets - Next Generation by  doxygen 1.4.2