| 325 | } |
| 326 | |
| 327 | bool Unit::start(String name) { |
| 328 | auto it = _actions.find(name); |
| 329 | if (it != _actions.end()) { |
| 330 | UnitAction* action = it->second.get(); |
| 331 | if (action->isDoing()) return true; |
| 332 | if (action->isAvailable()) { |
| 333 | if (_currentAction && _currentAction->isDoing()) { |
| 334 | if (_currentAction->getPriority() < action->getPriority()) { |
| 335 | _currentAction->stop(); |
| 336 | _currentAction->_status = Behavior::Status::Failure; |
| 337 | } else if (_currentAction->getPriority() == action->getPriority() && !_currentAction->isQueued()) { |
| 338 | _currentAction->stop(); |
| 339 | _currentAction->_status = Behavior::Status::Failure; |
| 340 | } else { |
| 341 | action->_status = Behavior::Status::Failure; |
| 342 | return false; |
| 343 | } |
| 344 | } |
| 345 | action->run(); |
| 346 | if (action->isDoing()) { |
| 347 | action->_status = Behavior::Status::Running; |
| 348 | _currentAction = action; |
| 349 | } else { |
| 350 | action->_status = Behavior::Status::Success; |
| 351 | _currentAction = nullptr; |
| 352 | } |
| 353 | return true; |
| 354 | } |
| 355 | } |
| 356 | return false; |
| 357 | } |
| 358 | |
| 359 | void Unit::stop() { |
| 360 | if (_currentAction && _currentAction->isDoing()) { |
nothing calls this directly
no test coverage detected