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. | |
Cube * | getModel (int model_index) |
Return model at index. | |
Cube * | askField (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 StepCounter * | stepCounter () 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) |
|
Create room holder.
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 }
|
|
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 }
|
|
Definition at line 98 of file Room.cpp. 00099 { 00100 m_view->addDecor(new_decor); 00101 }
|
|
Add model at scene.
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 }
|
|
Definition at line 492 of file Room.cpp. 00493 { 00494 m_soundPack->addSound(name, file); 00495 }
|
|
Return model at location.
Definition at line 148 of file Room.cpp. 00149 { 00150 return m_field->getModel(loc); 00151 }
|
|
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.
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 }
|
|
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 }
|
|
Definition at line 517 of file Room.cpp. 00518 { 00519 m_bg->changePicture(picture); 00520 }
|
|
Definition at line 350 of file Room.cpp. 00351 { 00352 return m_controls->checkActive(); 00353 }
|
|
Definition at line 327 of file Room.cpp. 00328 { 00329 m_controls->controlEvent(stroke); 00330 }
|
|
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 }
|
|
Implements Drawable. Definition at line 523 of file Room.cpp.
|
|
Let models to release their old position.
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 }
|
|
Definition at line 486 of file Room.cpp. 00487 {
00488 return TimerAgent::agent()->getCycles() - m_startTime;
00489 }
|
|
Definition at line 480 of file Room.cpp. 00481 { 00482 return m_field->getH(); 00483 }
|
|
Return model at index.
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 }
|
|
Definition at line 474 of file Room.cpp. 00475 { 00476 return m_field->getW(); 00477 }
|
|
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 }
|
|
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 }
|
|
Load this move, let object to fall fast. Don't play sound.
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 }
|
|
Try make single move.
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 }
|
|
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 }
|
|
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 }
|
|
Definition at line 55 of file Room.h. 00055 { m_fastFalling = value; }
|
|
Shift room content. NOTE: background is not shifted Definition at line 511 of file Room.cpp. 00512 { 00513 m_view->setScreenShift(shift); 00514 }
|
|
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 }
|
|
Definition at line 344 of file Room.cpp. 00345 {
00346 return m_controls;
00347 }
|
|
Definition at line 321 of file Room.cpp. 00322 { 00323 m_controls->switchActive(); 00324 }
|
|
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 }
|