Exemple #1
0
void UnitStateMgr::DropAllStates()
{
    DEBUG_FILTER_LOG(LOG_FILTER_AI_AND_MOVEGENSS, "UnitStateMgr:DropAllStates %s drop all active states", GetOwnerStr().c_str());
    DropActionHigherThen(UNIT_ACTION_PRIORITY_IDLE);
    PushAction(UNIT_ACTION_IDLE);
}
Exemple #2
0
void UnitStateMgr::Update(uint32 diff)
{
    if (m_needReinit)
    {
        m_needReinit = false;
        InitDefaults(true);
    }

    ActionInfo* state = CurrentState();

    if (!m_oldAction)
        m_oldAction = state->Action();
    else if (m_oldAction && m_oldAction != state->Action())
    {
        if (ActionInfo* oldAction = GetAction(m_oldAction))
        {
            if (oldAction->HasFlag(ACTION_STATE_ACTIVE) &&
                !oldAction->HasFlag(ACTION_STATE_FINALIZED) &&
                !oldAction->HasFlag(ACTION_STATE_INTERRUPTED))
                oldAction->Interrupt(this);
        }
        // else do nothing - action be deleted without interrupt/finalize (may be need correct?)
        m_oldAction = state->Action();
    }

    if (!state->Update(this, diff))
    {
        DEBUG_FILTER_LOG(LOG_FILTER_AI_AND_MOVEGENSS, "UnitStateMgr: %s finished action %s", GetOwnerStr().c_str(), state->TypeName());
        DropAction(state->priority);
    }
}
Exemple #3
0
void UnitStateMgr::DropAction(UnitActionPriority priority)
{
    // Don't remove action with NONE priority - static
    if (priority < UNIT_ACTION_PRIORITY_IDLE)
        return;

    UnitActionStorage::iterator itr = m_actions.find(priority);

    if (itr != m_actions.end())
    {
        bool bActiveActionChanged = false;
        ActionInfo* oldInfo = CurrentState();
        UnitActionPtr oldAction = oldInfo ? oldInfo->Action() : UnitActionPtr();

        // if dropped current active state...
        if (oldInfo && itr->second.Action() == oldInfo->Action() && !oldInfo->HasFlag(ACTION_STATE_FINALIZED))
            bActiveActionChanged = true;

        // in first - erasing current action, if his active
        if (itr->second.Action() == m_oldAction)
            m_oldAction = UnitActionPtr(NULL);

        // Possible erasing by iterator more fast and logic, but by Key much more safe
        m_actions.erase(priority);

        // Finalized not ActionInfo, but real action (saved before), due to ActionInfo wrapper already deleted.
        if (bActiveActionChanged && oldAction)
        {
            DEBUG_FILTER_LOG(LOG_FILTER_AI_AND_MOVEGENSS, "DropAction: %s finalize (direct) action %s", GetOwnerStr().c_str(), oldAction->Name());
            oldAction->Finalize(*GetOwner());
        }
        // in this point we delete last link to UnitActionPtr, after this UnitAction be auto-deleted...
    }
}
Exemple #4
0
void UnitStateMgr::DropAllStates()
{
    // Assume, that if only one action - that IDLE appears (rechecked later).
    if (m_actions.size() > 1 )
    {
        DEBUG_FILTER_LOG(LOG_FILTER_AI_AND_MOVEGENSS, "UnitStateMgr:DropAllStates %s drop all active states (count = %u)", GetOwnerStr().c_str(), m_actions.size());
        DropActionHigherThen(UNIT_ACTION_PRIORITY_IDLE);
    }
    // Unique action after dropping may be not UNIT_ACTION_IDLE
    if (m_actions.empty() || GetCurrentState() != UNIT_ACTION_IDLE)
        PushAction(UNIT_ACTION_IDLE);
}