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

Room Class Reference

Inheritance diagram for Room:

Inheritance graph
[legend]
Collaboration diagram for Room:

Collaboration graph
[legend]

Detailed Description

Room with level.

Definition at line 28 of file Room.h.

Public Member Functions

 Room (int w, int h, const Path &picture, PhaseLocker *locker, Planner *levelScript)
 Create room holder.
 ~Room ()
 Delete field and models.
void setWaves (float amplitude, float periode, float speed)
 Set waves on background.
void addDecor (Decor *new_decor)
void setFastFalling (bool value)
int addModel (Cube *new_model, Unit *new_unit)
 Add model at scene.
CubegetModel (int model_index)
 Return model at index.
CubeaskField (const V2 &loc)
 Return model at location.
bool beginFall (bool interactive=true)
 Begin round.
void nextRound (const InputProvider *input)
 Update all models.
void finishRound (bool interactive=true)
 Let models to release their old position.
void switchFish ()
void controlEvent (const KeyStroke &stroke)
void controlMouse (const MouseStroke &button)
void loadMove (char move)
 Load this move, let object to fall fast.
bool makeMove (char move)
 Try make single move.
bool cannotMove () const
 Returns true when there is no unit which will be able to move.
bool isSolvable () const
 Returns true when all goals can be solved.
bool isSolved () const
 Returns true when all goal all satisfied.
void checkActive ()
void unBusyUnits ()
const StepCounterstepCounter () const
int getW () const
int getH () const
int getCycles () const
void addSound (const std::string &name, const Path &file)
void playSound (const std::string &name, int volume=100)
void setScreenShift (const V2 &shift)
 Shift room content.
void changeBg (const Path &picture)
virtual void drawOn (SDL_Surface *screen)


Constructor & Destructor Documentation

Room::Room int  w,
int  h,
const Path picture,
PhaseLocker locker,
Planner levelScript
 

Create room holder.

Parameters:
w room width
h room height
picture room background
locker shared locker for anim
levelScript shared planner to interrupt

Definition at line 46 of file Room.cpp.

00048 {
00049     m_locker = locker;
00050     m_levelScript = levelScript;
00051     m_fastFalling = false;
00052     m_bg = new WavyPicture(picture, V2(0, 0));
00053     m_field = new Field(w, h);
00054     m_finder = new FinderAlg(w, h);
00055     m_controls = new Controls(m_locker);
00056     m_view = new View(ModelList(&m_models));
00057     m_lastAction = Cube::ACTION_NO;
00058     m_soundPack = new ResSoundPack();
00059     m_startTime = TimerAgent::agent()->getCycles();
00060 }

Room::~Room  ) 
 

Delete field and models.

Definition at line 65 of file Room.cpp.

00066 {
00067     m_soundPack->removeAll();
00068     delete m_soundPack;
00069     m_levelScript->killPlan();
00070     m_levelScript->dialogs()->removeAll();
00071     SubTitleAgent::agent()->removeAll();
00072     delete m_controls;
00073     delete m_view;
00074 
00075     //NOTE: models must be removed before field because they unmask self
00076     Cube::t_models::iterator end = m_models.end();
00077     for (Cube::t_models::iterator i = m_models.begin(); i != end; ++i) {
00078         delete (*i);
00079     }
00080 
00081     delete m_finder;
00082     delete m_field;
00083     delete m_bg;
00084 }


Member Function Documentation

void Room::addDecor Decor new_decor  ) 
 

Definition at line 98 of file Room.cpp.

00099 {
00100     m_view->addDecor(new_decor);
00101 }

int Room::addModel Cube new_model,
Unit new_unit
 

Add model at scene.

Parameters:
new_model new object
new_unit driver for the object or NULL
Returns:
model index

Definition at line 110 of file Room.cpp.

00111 {
00112     new_model->rules()->takeField(m_field);
00113     m_models.push_back(new_model);
00114 
00115     if (new_unit) {
00116         new_unit->takeModel(new_model);
00117         m_controls->addUnit(new_unit);
00118     }
00119 
00120     int model_index = m_models.size() - 1;
00121     new_model->setIndex(model_index);
00122     return model_index;
00123 }

void Room::addSound const std::string &  name,
const Path file
 

Definition at line 492 of file Room.cpp.

00493 {
00494     m_soundPack->addSound(name, file);
00495 }

Cube * Room::askField const V2 loc  ) 
 

Return model at location.

Definition at line 148 of file Room.cpp.

00149 {
00150     return m_field->getModel(loc);
00151 }

bool Room::beginFall bool  interactive = true  ) 
 

Begin round.

Let objects fall. First objects can fall out of room (even upward), when nothing is going out, then objects can fall down by gravity.

Parameters:
interactive whether play sound and do anim
Returns:
true when something was falling

Definition at line 392 of file Room.cpp.

00393 {
00394     prepareRound();
00395     m_lastAction = Cube::ACTION_NO;
00396 
00397     if (fallout(interactive)) {
00398         m_lastAction = Cube::ACTION_MOVE;
00399     }
00400     else {
00401         if (falldown(interactive)) {
00402             m_lastAction = Cube::ACTION_FALL;
00403         }
00404     }
00405     return m_lastAction != Cube::ACTION_NO;
00406 }

bool Room::cannotMove  )  const
 

Returns true when there is no unit which will be able to move.

Definition at line 432 of file Room.cpp.

00433 {
00434     return m_controls->cannotMove();
00435 }

void Room::changeBg const Path picture  ) 
 

Definition at line 517 of file Room.cpp.

00518 {
00519     m_bg->changePicture(picture);
00520 }

void Room::checkActive  ) 
 

Definition at line 350 of file Room.cpp.

00351 {
00352     return m_controls->checkActive();
00353 }

void Room::controlEvent const KeyStroke stroke  ) 
 

Definition at line 327 of file Room.cpp.

00328 {
00329     m_controls->controlEvent(stroke);
00330 }

void Room::controlMouse const MouseStroke button  ) 
 

Definition at line 333 of file Room.cpp.

00334 {
00335     if (button.isLeft()) {
00336         V2 fieldPos = m_view->getFieldPos(button.getLoc());
00337         Cube *model = askField(fieldPos);
00338         m_controls->activateSelected(model);
00339     }
00340 }

void Room::drawOn SDL_Surface *  screen  )  [virtual]
 

Implements Drawable.

Definition at line 523 of file Room.cpp.

00524 {
00525     m_bg->drawOn(screen);
00526     m_view->drawOn(screen);
00527 }

void Room::finishRound bool  interactive = true  ) 
 

Let models to release their old position.

Parameters:
interactive whether ensure phases for motion animation

Definition at line 306 of file Room.cpp.

00307 {
00308     if (interactive) {
00309         m_controls->lockPhases();
00310     }
00311     m_view->noteNewRound(m_locker->getLocked());
00312 
00313     Cube::t_models::iterator end = m_models.end();
00314     for (Cube::t_models::iterator i = m_models.begin(); i != end; ++i) {
00315         (*i)->rules()->finishRound();
00316     }
00317 }

int Room::getCycles  )  const
 

Definition at line 486 of file Room.cpp.

00487 {
00488     return TimerAgent::agent()->getCycles() - m_startTime;
00489 }

int Room::getH  )  const
 

Definition at line 480 of file Room.cpp.

00481 {
00482     return m_field->getH();
00483 }

Cube * Room::getModel int  model_index  ) 
 

Return model at index.

Exceptions:
LogicException when model_index is out of range

Definition at line 130 of file Room.cpp.

00131 {
00132     Cube *result = NULL;
00133     if (0 <= model_index && model_index < (int)m_models.size()) {
00134         result = m_models[model_index];
00135     }
00136     else {
00137         throw LogicException(ExInfo("bad model index")
00138                 .addInfo("model_index", model_index));
00139     }
00140 
00141     return result;
00142 }

int Room::getW  )  const
 

Definition at line 474 of file Room.cpp.

00475 {
00476     return m_field->getW();
00477 }

bool Room::isSolvable  )  const
 

Returns true when all goals can be solved.

Definition at line 441 of file Room.cpp.

00442 {
00443     Cube::t_models::const_iterator end = m_models.end();
00444     for (Cube::t_models::const_iterator i = m_models.begin(); i != end; ++i) {
00445         if ((*i)->isWrong()) {
00446             return false;
00447         }
00448     }
00449     return true;
00450 }

bool Room::isSolved  )  const
 

Returns true when all goal all satisfied.

Right time to ask is after finishRound. NOTE: room is not solved when somethig is still falling

Definition at line 458 of file Room.cpp.

00459 {
00460     if (!isFresh()) {
00461         return false;
00462     }
00463     Cube::t_models::const_iterator end = m_models.end();
00464     for (Cube::t_models::const_iterator i = m_models.begin(); i != end; ++i) {
00465         if (!(*i)->isSatisfy()) {
00466             return false;
00467         }
00468     }
00469     return true;
00470 }

void Room::loadMove char  move  ) 
 

Load this move, let object to fall fast.

Don't play sound.

Exceptions:
LoadException for bad moves

Definition at line 370 of file Room.cpp.

00371 {
00372     static const bool NO_INTERACTIVE = false;
00373     bool falling = true;
00374     while (falling) {
00375         falling = beginFall(NO_INTERACTIVE);
00376         makeMove(move);
00377 
00378         finishRound(NO_INTERACTIVE);
00379     }
00380 }

bool Room::makeMove char  move  ) 
 

Try make single move.

Returns:
true for success or false when something has moved before
Exceptions:
LoadException for bad moves

Definition at line 414 of file Room.cpp.

00415 {
00416     bool result = false;
00417     if (isFresh()) {
00418         if (!m_controls->makeMove(move)) {
00419             throw LoadException(ExInfo("load error - bad move")
00420                     .addInfo("move", std::string(1, move)));
00421         }
00422         m_lastAction = Cube::ACTION_MOVE;
00423         result = true;
00424     }
00425     return result;
00426 }

void Room::nextRound const InputProvider input  ) 
 

Update all models.

Prepare new move, let models fall, let models drive, release old position.

Definition at line 158 of file Room.cpp.

00159 {
00160     if (m_fastFalling) {
00161         while (beginFall()) {
00162             finishRound();
00163         }
00164     }
00165     else {
00166         beginFall();
00167     }
00168 
00169     if (isFresh()) {
00170         if (m_controls->driving(input)) {
00171             m_lastAction = Cube::ACTION_MOVE;
00172         }
00173         else {
00174             MouseControl rat(m_controls, m_view, m_finder);
00175             if (rat.mouseDrive(input)) {
00176                 m_lastAction = Cube::ACTION_MOVE;
00177             }
00178         }
00179     }
00180     finishRound();
00181 }

void Room::playSound const std::string &  name,
int  volume = 100
 

Definition at line 498 of file Room.cpp.

00499 {
00500     if (OptionAgent::agent()->getAsBool("sound", true)) {
00501         SoundAgent::agent()->playSound(
00502             m_soundPack->getRandomRes(name), volume);
00503     }
00504 }

void Room::setFastFalling bool  value  )  [inline]
 

Definition at line 55 of file Room.h.

00055 { m_fastFalling = value; }

void Room::setScreenShift const V2 shift  ) 
 

Shift room content.

NOTE: background is not shifted

Definition at line 511 of file Room.cpp.

00512 {
00513     m_view->setScreenShift(shift);
00514 }

void Room::setWaves float  amplitude,
float  periode,
float  speed
 

Set waves on background.

Definition at line 90 of file Room.cpp.

00091 {
00092     m_bg->setWamp(amplitude);
00093     m_bg->setWperiode(periode);
00094     m_bg->setWspeed(speed);
00095 }

const StepCounter * Room::stepCounter  )  const
 

Definition at line 344 of file Room.cpp.

00345 {
00346     return m_controls;
00347 }

void Room::switchFish  ) 
 

Definition at line 321 of file Room.cpp.

00322 {
00323     m_controls->switchActive();
00324 }

void Room::unBusyUnits  ) 
 

Definition at line 356 of file Room.cpp.

00357 {
00358     Cube::t_models::iterator end = m_models.end();
00359     for (Cube::t_models::iterator i = m_models.begin(); i != end; ++i) {
00360         (*i)->setBusy(false);
00361     }
00362 }


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