void ConditionAttributes::addCondition(Creature* creature, const Condition* addCondition) { if(updateCondition(addCondition)) { setTicks(addCondition->getTicks()); const ConditionAttributes& conditionAttrs = static_cast<const ConditionAttributes&>(*addCondition); //Remove the old condition endCondition(creature, CONDITIONEND_ABORT); //Apply the new one memcpy(skills, conditionAttrs.skills, sizeof(skills)); memcpy(skillsPercent, conditionAttrs.skillsPercent, sizeof(skillsPercent)); memcpy(stats, conditionAttrs.stats, sizeof(stats)); memcpy(statsPercent, conditionAttrs.statsPercent, sizeof(statsPercent)); if(Player* player = creature->getPlayer()) { updatePercentSkills(player); updateSkills(player); updatePercentStats(player); updateStats(player); } } }
void ConditionAttributes::addCondition(Creature* creature, const Condition* condition) { if (updateCondition(condition)) { setTicks(condition->getTicks()); const ConditionAttributes& conditionAttrs = static_cast<const ConditionAttributes&>(*condition); //Remove the old condition endCondition(creature); //Apply the new one memcpy(skills, conditionAttrs.skills, sizeof(skills)); memcpy(specialSkills, conditionAttrs.specialSkills, sizeof(specialSkills)); memcpy(skillsPercent, conditionAttrs.skillsPercent, sizeof(skillsPercent)); memcpy(stats, conditionAttrs.stats, sizeof(stats)); memcpy(statsPercent, conditionAttrs.statsPercent, sizeof(statsPercent)); disableDefense = conditionAttrs.disableDefense; if (Player* player = creature->getPlayer()) { updatePercentSkills(player); updateSkills(player); updatePercentStats(player); updateStats(player); } } }
void BasicGesture::updateStrict() { lastMovement=colours[0]->getIntolerantMovement(); if(currentState==GESTURE_STEP_1){ if(validStrictMovement(lastMovement)){ counter++; if(endCondition()){ counter=0; counterSTILL=0; counterLOST=0; currentState=GESTURE_END; detected++; } } else switch(lastMovement){ case STILL: case STILLe: counterSTILL++; if(counterSTILL==toleranceStill){ counter=0; counterSTILL=0; counterLOST=0; currentState=GESTURE_START; } return; case LOST: counterLOST++; if(counterLOST==toleranceLost){ counter=0; counterSTILL=0; counterLOST=0; currentState=GESTURE_START; } return; default: counter=0; counterSTILL=0; counterLOST=0; currentState=GESTURE_START; return; } } if(currentState==GESTURE_START){ if(validStrictMovement(lastMovement)){ currentState=GESTURE_STEP_1; counter++; } return; } }
bool RDOSimulatorBase::rdoNext() { if (m_mode == RTM_Pause || m_mode == RTM_BreakPoint) { boost::this_thread::sleep(boost::posix_time::milliseconds(1)); return true; } // Если нажата клавиша или активная область, то задержки надо проскачить bool keyboard = isKeyDown(); if (!keyboard) { // Задержка общей скорости моделирования // Это mode == RTM_Jump || mode == RTM_Sync if (m_mode != RTM_MaxSpeed && m_next_delay_count) { ++m_next_delay_current; if (m_next_delay_current < m_next_delay_count) return true; m_next_delay_current = 0; } // Задержка синхронной скорости моделирования (длительность операций) // Тут не надо проверять mode == RTM_Sync, т.к. это уже заложено в msec_wait, // который сбрасывается в setMode и не изменяется далее. if (m_msec_wait > 1) { boost::posix_time::ptime systime_current = boost::posix_time::microsec_clock::local_time(); std::size_t msec_curr = getMSec(systime_current); std::size_t msec_delta; // Милисекунды считаются с учетом часов, но при смене суток часы сбрасываются на ноль, // и текущее время в милисекундах становится меньше предыдущего. Учитываем этот момент // через ветку ELSE. Теперь система сможет учесть переход на один день вперед между // двумя соседники моментами времени, но не сможет учесть на два и более дня. Это // является маразматической ситуаций (ждать слудующего события два дня), но запросто // может потребоваться в системе мониторинга реального времени, которая работает в // автоматическом режиме, обрабатывая информацию с контроллеров. РДО это делать не умеет. // Как решение - отказ от синхронной работы в таких системах, и учет только скорости, или // переход на работу с календарем дней, месяцев и лет. SYSTEMTIME содержит такую информацию. if (msec_curr >= m_msec_prev) { msec_delta = msec_curr - m_msec_prev; } else { msec_delta = UINT_MAX - m_msec_prev + msec_curr; } if (msec_delta <= m_msec_wait) return true; m_msec_wait -= msec_delta; } } // Окончание моделирования - сработало событие конца if (endCondition()) { onEndCondition(); return false; } if (m_currentTime != m_nextTime) { m_currentTime = m_nextTime; onNewTimeNow(); } // Выполнение операции if (doOperation()) { if (breakPoints()) { setMode(RTM_BreakPoint); } return true; } else { // Переход к следующей операции if (!m_timePoints.empty()) { BOPlannedMap::iterator begin = m_timePoints.begin(); double newTime = begin->first; const BOPlannedList& list = begin->second; if (list.empty()) { m_timePoints.erase(begin); } if (m_currentTime > newTime) { newTime = m_currentTime; } if (m_mode == RTM_Sync) { m_msec_wait += (newTime - m_nextTime) * 3600.0 * 1000.0 / m_showRate; if (m_msec_wait > 0) { if (newTime != m_startTime) { if (m_speed > DBL_MIN) { m_msec_wait = m_msec_wait / m_speed; } else { m_msec_wait = m_msec_wait / DBL_MIN; } boost::posix_time::ptime systime_current = boost::posix_time::microsec_clock::local_time(); m_msec_prev = getMSec(systime_current); } else { m_msec_wait = 0; } } } m_nextTime = newTime; return true; } else { // Окончание моделирования - нет больше событий onNothingMoreToDo(); return false; } } }