Definition at line 16 of file Rules.h.
Public Member Functions | |
Rules (Cube *model) | |
Create new rules for model. | |
~Rules () | |
Unmask from field. | |
void | takeField (Field *field) |
Connect model with field. | |
void | occupyNewPos () |
Accomplish last move in m_dir direction. | |
bool | checkDead (Cube::eAction lastAction) |
Check dead fishes. | |
void | changeState () |
Finish events from last round. | |
void | finishRound () |
Unmask from old position. | |
int | actionOut () |
Let model to go out of room. | |
void | actionFall () |
Let model fall. | |
bool | clearLastFall () |
Unset falling flag. | |
bool | actionMoveDir (Dir::eDir dir) |
Try to move. | |
void | actionTurnSide () |
void | actionActivate () |
Dir::eDir | getDir () const |
Dir::eDir | getTouchDir () const |
std::string | getAction () const |
Return what we do the last round. | |
std::string | getState () const |
Return how we have feel the last round. | |
bool | isOnStrongPad (Cube::eWeight weight) |
Whether object is direct or undirect on Wall or on powerful fish. | |
bool | isAtBorder () const |
bool | isFreePlace (const V2 &loc) const |
const Cube::t_models | getResist (Dir::eDir dir) const |
|
Create new rules for model.
Definition at line 26 of file Rules.cpp. 00027 { 00028 m_readyToDie = false; 00029 m_readyToTurn = false; 00030 m_readyToActive = false; 00031 m_dir = Dir::DIR_NO; 00032 m_pushing = false; 00033 m_outDepth = 0; 00034 m_touchDir = Dir::DIR_NO; 00035 00036 m_model = model; 00037 m_mask = NULL; 00038 m_lastFall = false; 00039 }
|
|
Unmask from field.
Definition at line 44 of file Rules.cpp. 00045 { 00046 if (m_mask) { 00047 m_mask->unmask(); 00048 delete m_mask; 00049 } 00050 }
|
|
Definition at line 66 of file Rules.h. 00066 { m_readyToActive = true; }
|
|
Let model fall.
Definition at line 266 of file Rules.cpp. 00267 { 00268 m_dir = Dir::DIR_DOWN; 00269 m_lastFall = true; 00270 }
|
|
Try to move. Only m_dir will be set. NOTE: we can move all resist or none
Definition at line 561 of file Rules.cpp. 00562 { 00563 bool result = false; 00564 if (canMoveOthers(dir, m_model->getPower())) { 00565 moveDirBrute(dir); 00566 result = true; 00567 } 00568 else { 00569 if (touchSpec(dir)) { 00570 result = true; 00571 } 00572 else { 00573 setTouched(dir); 00574 } 00575 } 00576 00577 return result; 00578 }
|
|
Let model to go out of room.
Definition at line 238 of file Rules.cpp. 00239 { 00240 if (!m_model->isWall() && !m_model->isLost() 00241 && !m_model->isBusy()) 00242 { 00243 //NOTE: normal objects are not allowed to go out of screen 00244 if (m_model->shouldGoOut()) { 00245 Dir::eDir borderDir = m_mask->getBorderDir(); 00246 if (borderDir != Dir::DIR_NO) { 00247 m_dir = borderDir; 00248 m_outDepth += 1; 00249 } 00250 else { 00251 if (m_outDepth > 0) { 00252 m_model->change_goOut(); 00253 m_outDepth = -1; 00254 } 00255 } 00256 } 00257 } 00258 00259 return m_outDepth; 00260 }
|
|
Definition at line 65 of file Rules.h. 00065 { m_readyToTurn = true; }
|
|
Finish events from last round. Change model state. Definition at line 210 of file Rules.cpp. 00211 { 00212 m_dir = Dir::DIR_NO; 00213 00214 if (!m_model->isLost() && m_model->isDisintegrated()) { 00215 m_mask->unmask(); 00216 m_model->change_remove(); 00217 } 00218 00219 if (m_readyToTurn) { 00220 m_readyToTurn = false; 00221 m_model->change_turnSide(); 00222 } 00223 00224 m_readyToActive = false; 00225 00226 if (m_readyToDie) { 00227 m_readyToDie = false; 00228 m_model->change_die(); 00229 } 00230 }
|
|
Check dead fishes. Fish is dead:
Definition at line 110 of file Rules.cpp. 00111 { 00112 //NOTE: after falling phase is sufficient to check only DeadFall 00113 bool dead = false; 00114 00115 if (m_model->isAlive()) { 00116 switch (lastAction) { 00117 case Cube::ACTION_FALL: 00118 dead = checkDeadFall(); 00119 break; 00120 case Cube::ACTION_MOVE: 00121 dead = checkDeadMove(); 00122 if (!dead) { 00123 dead = checkDeadStress(); 00124 } 00125 break; 00126 default: 00127 dead = false; 00128 break; 00129 } 00130 00131 if (dead) { 00132 m_readyToDie = true; 00133 } 00134 } 00135 00136 return dead; 00137 }
|
|
Unset falling flag.
Definition at line 277 of file Rules.cpp. 00278 { 00279 bool last = m_lastFall; 00280 m_lastFall = false; 00281 return last; 00282 }
|
|
Unmask from old position.
Definition at line 288 of file Rules.cpp. 00289 { 00290 freeOldPos(); 00291 }
|
|
Return what we do the last round. Useful for script functions. NOTE: dead is not action Definition at line 611 of file Rules.cpp. 00612 { 00613 if (m_readyToTurn) { 00614 return "turn"; 00615 } 00616 else if (m_readyToActive) { 00617 return "activate"; 00618 } 00619 else if (m_model->isBusy()) { 00620 return "busy"; 00621 } 00622 00623 switch (m_dir) { 00624 case Dir::DIR_LEFT: return "move_left"; 00625 case Dir::DIR_RIGHT: return "move_right"; 00626 case Dir::DIR_UP: return "move_up"; 00627 case Dir::DIR_DOWN: return "move_down"; 00628 case Dir::DIR_NO: return "rest"; 00629 default: assert(!"unknown dir"); break; 00630 } 00631 00632 return "rest"; 00633 }
|
|
Definition at line 68 of file Rules.h. 00068 { return m_dir; }
|
|
Definition at line 679 of file Rules.cpp. 00680 { 00681 return m_mask->getResist(dir); 00682 }
|
|
Return how we have feel the last round. Useful for script functions. States: "goout" ... go out of room "dead" ... is dead "talking" ... is talking "pushing" ... is pushing "normal" ... is alive and resting Definition at line 647 of file Rules.cpp. 00648 { 00649 if (m_outDepth == 1) { 00650 return "goout"; 00651 } 00652 else if (!m_model->isAlive()) { 00653 return "dead"; 00654 } 00655 else if (m_model->isTalking()) { 00656 return "talking"; 00657 } 00658 else if (m_pushing) { 00659 return "pushing"; 00660 } 00661 else { 00662 return "normal"; 00663 } 00664 }
|
|
Definition at line 69 of file Rules.h. 00069 { return m_touchDir; }
|
|
Definition at line 667 of file Rules.cpp. 00668 { 00669 return m_mask->getBorderDir() != Dir::DIR_NO; 00670 }
|
|
Definition at line 673 of file Rules.cpp. 00674 { 00675 return m_mask->getPlacedResist(loc).empty(); 00676 }
|
|
Whether object is direct or undirect on Wall or on powerful fish.
Definition at line 368 of file Rules.cpp. 00369 { 00370 return isOnCond(OnStrongPad(weight)); 00371 }
|
|
Accomplish last move in m_dir direction. Mask to a new position. Change model position. Definition at line 83 of file Rules.cpp. 00084 { 00085 m_touchDir = Dir::DIR_NO; 00086 if (m_dir != Dir::DIR_NO) { 00087 m_pushing = false; 00088 00089 V2 shift = Dir::dir2xy(m_dir); 00090 V2 oldLoc = m_model->getLocation(); 00091 m_model->change_setLocation(oldLoc.plus(shift)); 00092 00093 m_mask->mask(); 00094 } 00095 }
|
|
Connect model with field.
Definition at line 57 of file Rules.cpp. 00058 { 00059 if (m_mask) { 00060 m_mask->unmask(); 00061 delete m_mask; 00062 m_mask = NULL; 00063 } 00064 00065 m_mask = new MarkMask(m_model, field); 00066 Cube::t_models resist = m_mask->getResist(Dir::DIR_NO); 00067 if (!resist.empty()) { 00068 throw LayoutException(ExInfo("position is occupied") 00069 .addInfo("model", m_model->toString()) 00070 .addInfo("resist", resist.front()->toString())); 00071 } 00072 00073 m_mask->mask(); 00074 }
|