Definition at line 22 of file Controls.h.
Public Member Functions | |
Controls (PhaseLocker *locker) | |
Create list of drivers. | |
~Controls () | |
Delete drivers. | |
void | addUnit (Unit *unit) |
Add unit under our control. | |
const Unit * | getActive () |
Returns active unit or NULL. | |
bool | driving (const InputProvider *input) |
Let drivers to drive. | |
void | lockPhases () |
void | checkActive () |
Check whether active unit can still drive, otherwise make switch. | |
void | switchActive () |
Switch active unit. | |
bool | makeMove (char move) |
Make this move. | |
bool | cannotMove () const |
Returns true when there is no unit which will be able to move. | |
void | controlEvent (const KeyStroke &stroke) |
Obtain first control symbol from keyboard events. | |
bool | activateSelected (const Cube *occupant) |
Activate fish under cursor. | |
virtual int | getStepCount () const |
virtual std::string | getMoves () const |
virtual bool | isPowerful () const |
Returns true when active fish is powerful. |
|
Create list of drivers.
Definition at line 22 of file Controls.cpp. 00023 : m_units(), m_moves() 00024 { 00025 m_locker = locker; 00026 m_active = m_units.begin(); 00027 m_speedup = 0; 00028 m_switch = true; 00029 m_strokeSymbol = ControlSym::SYM_NONE; 00030 }
|
|
Delete drivers.
Definition at line 35 of file Controls.cpp. 00036 { 00037 t_units::iterator end = m_units.end(); 00038 for (t_units::iterator i = m_units.begin(); i != end; ++i) { 00039 delete (*i); 00040 } 00041 }
|
|
Activate fish under cursor.
Definition at line 271 of file Controls.cpp. 00272 { 00273 t_units::iterator end = m_units.end(); 00274 for (t_units::iterator i = m_units.begin(); i != end; ++i) { 00275 if ((*i)->equalsModel(occupant)) { 00276 m_active = i; 00277 m_switch = true; 00278 return true; 00279 } 00280 } 00281 return false; 00282 }
|
|
Add unit under our control.
Definition at line 48 of file Controls.cpp. 00049 { 00050 m_units.push_back(unit); 00051 //NOTE: insertion invalidates m_active 00052 t_units::iterator end = m_units.end(); 00053 for (t_units::iterator i = m_units.begin(); i != end; ++i) { 00054 if ((*i)->startActive()) { 00055 setActive(i); 00056 return; 00057 } 00058 } 00059 setActive(m_units.begin()); 00060 }
|
|
Returns true when there is no unit which will be able to move.
Definition at line 319 of file Controls.cpp. 00320 { 00321 t_units::const_iterator end = m_units.end(); 00322 for (t_units::const_iterator i = m_units.begin(); i != end; ++i) { 00323 if ((*i)->willMove()) { 00324 return false; 00325 } 00326 } 00327 return true; 00328 }
|
|
Check whether active unit can still drive, otherwise make switch.
Definition at line 207 of file Controls.cpp. 00208 { 00209 if (m_active == m_units.end() || !(*m_active)->canDrive()) { 00210 switchActive(); 00211 } 00212 }
|
|
Obtain first control symbol from keyboard events.
Definition at line 244 of file Controls.cpp. 00245 { 00246 SDLKey key = stroke.getKey(); 00247 00248 if (m_strokeSymbol == ControlSym::SYM_NONE) { 00249 if (m_active != m_units.end()) { 00250 m_strokeSymbol = (*m_active)->mySymbolBorrowed(key, m_arrows); 00251 } 00252 00253 if (m_strokeSymbol == ControlSym::SYM_NONE) { 00254 t_units::iterator end = m_units.end(); 00255 for (t_units::iterator i = m_units.begin(); i != end; ++i) { 00256 m_strokeSymbol = (*i)->mySymbol(key); 00257 if (m_strokeSymbol != ControlSym::SYM_NONE) { 00258 return; 00259 } 00260 } 00261 } 00262 } 00263 }
|
|
Let drivers to drive. Only one driver can drive at the same time.
Definition at line 82 of file Controls.cpp. 00083 { 00084 bool moved = false; 00085 if (!useSwitch()) { 00086 if (!useStroke()) { 00087 moved = driveUnit(input); 00088 } 00089 else { 00090 moved = true; 00091 } 00092 } 00093 return moved; 00094 }
|
|
Returns active unit or NULL.
Definition at line 66 of file Controls.cpp. 00067 { 00068 Unit *result = NULL; 00069 if (m_active != m_units.end()) { 00070 result = *m_active; 00071 } 00072 return result; 00073 }
|
|
Implements StepCounter. Definition at line 57 of file Controls.h. 00057 { return m_moves; }
|
|
Implements StepCounter. Definition at line 56 of file Controls.h. 00056 { return m_moves.size(); }
|
|
Returns true when active fish is powerful.
Implements StepCounter. Definition at line 334 of file Controls.cpp. 00335 { 00336 bool result = false; 00337 if (m_active != m_units.end()) { 00338 result = (*m_active)->isPowerful(); 00339 } 00340 return result; 00341 }
|
|
Definition at line 161 of file Controls.cpp. 00162 { 00163 if (m_active != m_units.end() && (*m_active)->isMoving()) { 00164 if ((*m_active)->isPushing()) { 00165 m_speedup = 0; 00166 } 00167 else if (!(*m_active)->isTurning()) { 00168 m_speedup++; 00169 } 00170 00171 m_locker->ensurePhases(getNeededPhases(m_speedup)); 00172 } 00173 else { 00174 m_speedup = 0; 00175 } 00176 }
|
|
Make this move.
Definition at line 302 of file Controls.cpp. 00303 { 00304 t_units::iterator end = m_units.end(); 00305 for (t_units::iterator i = m_units.begin(); i != end; ++i) { 00306 if ((*i)->driveOrder(move) == move) { 00307 setActive(i); 00308 m_moves.push_back(move); 00309 return true; 00310 } 00311 } 00312 return false; 00313 }
|
|
Switch active unit. Activate next driveable unit. Definition at line 219 of file Controls.cpp. 00220 { 00221 if (!m_units.empty()) { 00222 t_units::iterator start = m_active; 00223 00224 do { 00225 if (m_active == m_units.end() || m_active + 1 == m_units.end()) { 00226 m_active = m_units.begin(); 00227 } 00228 else { 00229 ++m_active; 00230 } 00231 } while (m_active != start && !(*m_active)->canDrive()); 00232 00233 if (start != m_active) { 00234 m_speedup = 0; 00235 m_switch = true; 00236 } 00237 } 00238 }
|