Example #1
0
    void ProjectileManager::moveProjectiles(float duration)
    {
        for (std::vector<ProjectileState>::iterator it = mProjectiles.begin(); it != mProjectiles.end();)
        {
            // gravity constant - must be way lower than the gravity affecting actors, since we're not
            // simulating aerodynamics at all
            it->mVelocity -= osg::Vec3f(0, 0, 627.2f * 0.1f) * duration;

            osg::Vec3f pos(it->mNode->getPosition());
            osg::Vec3f newPos = pos + it->mVelocity * duration;

            osg::Quat orient;
            orient.makeRotate(osg::Vec3f(0,1,0), it->mVelocity);
            it->mNode->setAttitude(orient);
            it->mNode->setPosition(newPos);

            update(*it, duration);

            MWWorld::Ptr caster = it->getCaster();

            // Check for impact
            // TODO: use a proper btRigidBody / btGhostObject?
            MWPhysics::PhysicsSystem::RayResult result = mPhysics->castRay(pos, newPos, caster, 0xff, MWPhysics::CollisionType_Projectile);

            bool underwater = MWBase::Environment::get().getWorld()->isUnderwater(MWMechanics::getPlayer().getCell(), newPos);
            if (result.mHit || underwater)
            {
                if (result.mHit)
                {
                    MWWorld::ManualRef projectileRef(MWBase::Environment::get().getWorld()->getStore(), it->mId);

                    // Try to get a Ptr to the bow that was used. It might no longer exist.
                    MWWorld::Ptr bow = projectileRef.getPtr();
                    if (!caster.isEmpty())
                    {
                        MWWorld::InventoryStore& inv = caster.getClass().getInventoryStore(caster);
                        MWWorld::ContainerStoreIterator invIt = inv.getSlot(MWWorld::InventoryStore::Slot_CarriedRight);
                        if (invIt != inv.end() && Misc::StringUtils::ciEqual(invIt->getCellRef().getRefId(), it->mBowId))
                            bow = *invIt;
                    }

                    if (caster.isEmpty())
                        caster = result.mHitObject;

                    MWMechanics::projectileHit(caster, result.mHitObject, bow, projectileRef.getPtr(), result.mHitPos, it->mAttackStrength);
                }

                if (underwater)
                    mRendering->emitWaterRipple(newPos);

                mParent->removeChild(it->mNode);
                it = mProjectiles.erase(it);
                continue;
            }

            ++it;
        }
    }
Example #2
0
    void InventoryWindow::onAvatarClicked(MyGUI::Widget* _sender)
    {
        if (mDragAndDrop->mIsOnDragAndDrop)
        {
            MWWorld::Ptr ptr = mDragAndDrop->mItem.mBase;
            mDragAndDrop->finish();

            if (mDragAndDrop->mSourceModel != mTradeModel)
            {
                // Move item to the player's inventory
                ptr = mDragAndDrop->mSourceModel->moveItem(mDragAndDrop->mItem, mDragAndDrop->mDraggedCount, mTradeModel);
            }
            useItem(ptr);
        }
        else
        {
            MyGUI::IntPoint mousePos = MyGUI::InputManager::getInstance ().getLastPressedPosition (MyGUI::MouseButton::Left);
            MyGUI::IntPoint relPos = mousePos - mAvatarImage->getAbsolutePosition ();

            MWWorld::Ptr itemSelected = getAvatarSelectedItem (relPos.left, relPos.top);
            if (itemSelected.isEmpty ())
                return;

            for (size_t i=0; i < mTradeModel->getItemCount (); ++i)
            {
                if (mTradeModel->getItem(i).mBase == itemSelected)
                {
                    onItemSelectedFromSourceModel(i);
                    return;
                }
            }
            throw std::runtime_error("Can't find clicked item");
        }
    }
Example #3
0
void OMW::Engine::activate()
{
    std::string handle = mEnvironment.mWorld->getFacedHandle();

    if (handle.empty())
        return;

    MWWorld::Ptr ptr = mEnvironment.mWorld->getPtrViaHandle (handle);

    if (ptr.isEmpty())
        return;

    MWScript::InterpreterContext interpreterContext (mEnvironment,
        &ptr.getRefData().getLocals(), ptr);

    boost::shared_ptr<MWWorld::Action> action =
        MWWorld::Class::get (ptr).activate (ptr, mEnvironment.mWorld->getPlayer().getPlayer(),
        mEnvironment);

    interpreterContext.activate (ptr, action);

    std::string script = MWWorld::Class::get (ptr).getScript (ptr);

    if (!script.empty())
    {
        mEnvironment.mWorld->getLocalScripts().setIgnore (ptr);
        mScriptManager->run (script, interpreterContext);
    }

    if (!interpreterContext.hasActivationBeenHandled())
    {
        interpreterContext.executeActivation();
    }
}
Example #4
0
void AlchemyWindow::update()
{
    MWMechanics::Alchemy::TIngredientsIterator it = mAlchemy.beginIngredients ();
    for (int i=0; i<4; ++i)
    {
        MyGUI::ImageBox* ingredient = mIngredients[i];

        MWWorld::Ptr item;
        if (it != mAlchemy.endIngredients ())
        {
            item = *it;
            ++it;
        }

        if (ingredient->getChildCount())
            MyGUI::Gui::getInstance().destroyWidget(ingredient->getChildAt(0));

        ingredient->setImageTexture("");
        ingredient->clearUserStrings ();

        if (item.isEmpty ())
            continue;

        ingredient->setUserString("ToolTipType", "ItemPtr");
        ingredient->setUserData(item);
        ingredient->setImageTexture(getIconPath(item));

        MyGUI::TextBox* text = ingredient->createWidget<MyGUI::TextBox>("SandBrightText", MyGUI::IntCoord(0, 14, 32, 18), MyGUI::Align::Default, std::string("Label"));
        text->setTextAlign(MyGUI::Align::Right);
        text->setNeedMouseFocus(false);
        text->setTextShadow(true);
        text->setTextShadowColour(MyGUI::Colour(0,0,0));
        text->setCaption(getCountString(ingredient->getUserData<MWWorld::Ptr>()->getRefData().getCount()));
    }

    drawItems();

    std::vector<ESM::ENAMstruct> effects;
    ESM::EffectList list;
    list.mList = effects;
    for (MWMechanics::Alchemy::TEffectsIterator it = mAlchemy.beginEffects (); it != mAlchemy.endEffects (); ++it)
    {
        list.mList.push_back(*it);
    }

    while (mEffectsBox->getChildCount())
        MyGUI::Gui::getInstance().destroyWidget(mEffectsBox->getChildAt(0));

    MyGUI::IntCoord coord(0, 0, mEffectsBox->getWidth(), 24);
    Widgets::MWEffectListPtr effectsWidget = mEffectsBox->createWidget<Widgets::MWEffectList>
            ("MW_StatName", coord, MyGUI::Align::Left | MyGUI::Align::Top);
    effectsWidget->setWindowManager(&mWindowManager);

    Widgets::SpellEffectList _list = Widgets::MWEffectList::effectListFromESM(&list);
    effectsWidget->setEffectList(_list);

    std::vector<MyGUI::Widget*> effectItems;
    effectsWidget->createEffectWidgets(effectItems, mEffectsBox, coord, false, 0);
    effectsWidget->setCoord(coord);
}
Example #5
0
void OMW::Engine::activate()
{
    if (MWBase::Environment::get().getWindowManager()->isGuiMode())
        return;

    MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr();
    if (player.getClass().getCreatureStats(player).getMagicEffects().get(ESM::MagicEffect::Paralyze).getMagnitude() > 0
            || player.getClass().getCreatureStats(player).getKnockedDown())
        return;

    MWWorld::Ptr ptr = MWBase::Environment::get().getWorld()->getFacedObject();

    if (ptr.isEmpty())
        return;

    if (ptr.getClass().getName(ptr) == "") // objects without name presented to user can never be activated
        return;

    if (ptr.getClass().isActor())
    {
        MWMechanics::CreatureStats &stats = ptr.getClass().getCreatureStats(ptr);

        if (stats.getAiSequence().isInCombat() && !stats.isDead())
            return;
    }

    MWBase::Environment::get().getWorld()->activate(ptr, MWBase::Environment::get().getWorld()->getPlayerPtr());
}
Example #6
0
void OMW::Engine::activate()
{
    if (MWBase::Environment::get().getWindowManager()->isGuiMode())
        return;

    MWWorld::Ptr ptr = MWBase::Environment::get().getWorld()->getFacedObject();

    if (ptr.isEmpty())
        return;

    if (ptr.getClass().getName(ptr) == "") // objects without name presented to user can never be activated
        return;

    MWScript::InterpreterContext interpreterContext (&ptr.getRefData().getLocals(), ptr);

    interpreterContext.activate (ptr);

    std::string script = ptr.getClass().getScript (ptr);

    MWBase::Environment::get().getWorld()->breakInvisibility(MWBase::Environment::get().getWorld()->getPlayerPtr());

    if (!script.empty())
    {
        MWBase::Environment::get().getWorld()->getLocalScripts().setIgnore (ptr);
        MWBase::Environment::get().getScriptManager()->run (script, interpreterContext);
    }

    if (!interpreterContext.hasActivationBeenHandled())
    {
        interpreterContext.executeActivation(ptr);
    }
}
Example #7
0
    float InterpreterContext::getDistance (const std::string& name, const std::string& id) const
    {
        // NOTE: id may be empty, indicating an implicit reference

        MWWorld::Ptr ref2;

        if (id.empty())
            ref2 = getReferenceImp();
        else
            ref2 = MWBase::Environment::get().getWorld()->searchPtr(id, true);

        // If either actor is in a non-active cell, return a large value (just like vanilla)
        if (ref2.isEmpty())
            return std::numeric_limits<float>().max();

        const MWWorld::Ptr ref = MWBase::Environment::get().getWorld()->searchPtr(name, true);
        if (ref.isEmpty())
            return std::numeric_limits<float>().max();

        double diff[3];

        const float* const pos1 = ref.getRefData().getPosition().pos;
        const float* const pos2 = ref2.getRefData().getPosition().pos;
        for (int i=0; i<3; ++i)
            diff[i] = pos1[i] - pos2[i];

        return std::sqrt (diff[0]*diff[0] + diff[1]*diff[1] + diff[2]*diff[2]);
    }
Example #8
0
void OMW::Engine::activate()
{
    if (mEnvironment.getWindowManager()->isGuiMode())
        return;

    MWWorld::Ptr player = mEnvironment.getWorld()->getPlayerPtr();
    const MWMechanics::NpcStats &playerStats = player.getClass().getNpcStats(player);
    if (playerStats.isParalyzed() || playerStats.getKnockedDown())
        return;

    MWWorld::Ptr ptr = mEnvironment.getWorld()->getFacedObject();

    if (ptr.isEmpty())
        return;

    if (ptr.getClass().getName(ptr) == "") // objects without name presented to user can never be activated
        return;

    if (ptr.getClass().isActor())
    {
        MWMechanics::CreatureStats &stats = ptr.getClass().getCreatureStats(ptr);

        if (stats.getAiSequence().isInCombat() && !stats.isDead())
            return;
    }

    mEnvironment.getWorld()->activate(ptr, mEnvironment.getWorld()->getPlayerPtr());
}
Example #9
0
void OMW::Engine::activate()
{
    if (MWBase::Environment::get().getWindowManager()->isGuiMode())
        return;

    std::string handle = MWBase::Environment::get().getWorld()->getFacedHandle();

    if (handle.empty())
        return;

    MWWorld::Ptr ptr = MWBase::Environment::get().getWorld()->searchPtrViaHandle (handle);

    if (ptr.isEmpty())
        return;

    MWScript::InterpreterContext interpreterContext (&ptr.getRefData().getLocals(), ptr);

    boost::shared_ptr<MWWorld::Action> action =
        MWWorld::Class::get (ptr).activate (ptr, MWBase::Environment::get().getWorld()->getPlayer().getPlayer());

    interpreterContext.activate (ptr, action);

    std::string script = MWWorld::Class::get (ptr).getScript (ptr);

    if (!script.empty())
    {
        MWBase::Environment::get().getWorld()->getLocalScripts().setIgnore (ptr);
        MWBase::Environment::get().getScriptManager()->run (script, interpreterContext);
    }

    if (!interpreterContext.hasActivationBeenHandled())
    {
        interpreterContext.executeActivation();
    }
}
Example #10
0
    Entry::Entry (const std::string& topic, const std::string& infoId, const MWWorld::Ptr& actor)
    : mInfoId (infoId)
    {
        const ESM::Dialogue *dialogue =
            MWBase::Environment::get().getWorld()->getStore().get<ESM::Dialogue>().find (topic);

        for (ESM::Dialogue::InfoContainer::const_iterator iter (dialogue->mInfo.begin());
            iter!=dialogue->mInfo.end(); ++iter)
            if (iter->mId == mInfoId)
            {
                if (actor.isEmpty())
                {
                    MWScript::InterpreterContext interpreterContext(nullptr, MWWorld::Ptr());
                    mText = Interpreter::fixDefinesDialog(iter->mResponse, interpreterContext);
                }
                else
                {
                    MWScript::InterpreterContext interpreterContext(&actor.getRefData().getLocals(),actor);
                    mText = Interpreter::fixDefinesDialog(iter->mResponse, interpreterContext);
                }

                return;
            }

        throw std::runtime_error ("unknown info ID " + mInfoId + " for topic " + topic);
    }
Example #11
0
void OMW::Engine::updateFocusReport (float duration)
{

    if ((mFocusTDiff += duration)>0.25)
    {
        mFocusTDiff = 0;

        std::string name;

        std::string handle = mEnvironment.mWorld->getFacedHandle();

        if (!handle.empty())
        {
            MWWorld::Ptr ptr = mEnvironment.mWorld->getPtrViaHandle (handle);

            if (!ptr.isEmpty()){
                name = MWWorld::Class::get (ptr).getName (ptr);

            }
        }

        if (name!=mFocusName)
        {
            mFocusName = name;

            if (mFocusName.empty())
                std::cout << "Unfocus" << std::endl;
            else
                std::cout << "Focus: " << name << std::endl;
        }
    }
}
Example #12
0
            virtual void execute (Interpreter::Runtime& runtime)
            {
                MWWorld::Ptr bed = R()(runtime, false);

                if (bed.isEmpty() || !MWBase::Environment::get().getMechanicsManager()->sleepInBed(MWBase::Environment::get().getWorld()->getPlayerPtr(),
                                                                             bed))
                    MWBase::Environment::get().getWindowManager()->pushGuiMode(MWGui::GM_RestBed);
            }
Example #13
0
    void AlchemyWindow::open()
    {
        openContainer(MWBase::Environment::get().getWorld()->getPlayer().getPlayer());
        setFilter(ContainerBase::Filter_Ingredients);

        // pick the best available apparatus
        MWWorld::ContainerStore& store = MWWorld::Class::get(mPtr).getContainerStore(mPtr);

        MWWorld::Ptr bestAlbemic;
        MWWorld::Ptr bestMortarPestle;
        MWWorld::Ptr bestCalcinator;
        MWWorld::Ptr bestRetort;

        for (MWWorld::ContainerStoreIterator it(store.begin(MWWorld::ContainerStore::Type_Apparatus));
            it != store.end(); ++it)
        {
            MWWorld::LiveCellRef<ESM::Apparatus>* ref = it->get<ESM::Apparatus>();
            if (ref->base->mData.mType == ESM::Apparatus::Albemic
            && (bestAlbemic.isEmpty() || ref->base->mData.mQuality > bestAlbemic.get<ESM::Apparatus>()->base->mData.mQuality))
                bestAlbemic = *it;
            else if (ref->base->mData.mType == ESM::Apparatus::MortarPestle
            && (bestMortarPestle.isEmpty() || ref->base->mData.mQuality > bestMortarPestle.get<ESM::Apparatus>()->base->mData.mQuality))
                bestMortarPestle = *it;
            else if (ref->base->mData.mType == ESM::Apparatus::Calcinator
            && (bestCalcinator.isEmpty() || ref->base->mData.mQuality > bestCalcinator.get<ESM::Apparatus>()->base->mData.mQuality))
                bestCalcinator = *it;
            else if (ref->base->mData.mType == ESM::Apparatus::Retort
            && (bestRetort.isEmpty() || ref->base->mData.mQuality > bestRetort.get<ESM::Apparatus>()->base->mData.mQuality))
                bestRetort = *it;
        }

        if (!bestMortarPestle.isEmpty())
        {
            mApparatus1->setUserString("ToolTipType", "ItemPtr");
            mApparatus1->setUserData(bestMortarPestle);
            mApparatus1->setImageTexture(getIconPath(bestMortarPestle));
        }
        if (!bestAlbemic.isEmpty())
        {
            mApparatus2->setUserString("ToolTipType", "ItemPtr");
            mApparatus2->setUserData(bestAlbemic);
            mApparatus2->setImageTexture(getIconPath(bestAlbemic));
        }
        if (!bestCalcinator.isEmpty())
        {
            mApparatus3->setUserString("ToolTipType", "ItemPtr");
            mApparatus3->setUserData(bestCalcinator);
            mApparatus3->setImageTexture(getIconPath(bestCalcinator));
        }
        if (!bestRetort.isEmpty())
        {
            mApparatus4->setUserString("ToolTipType", "ItemPtr");
            mApparatus4->setUserData(bestRetort);
            mApparatus4->setImageTexture(getIconPath(bestRetort));
        }
    }
Example #14
0
bool AiSequence::getCombatTarget(MWWorld::Ptr &targetActor) const
{
    if (getTypeId() != AiPackage::TypeIdCombat)
        return false;
    
    targetActor = mPackages.front()->getTarget();

    return !targetActor.isEmpty();
}
Example #15
0
    void WaitDialog::setPtr(const MWWorld::Ptr &ptr)
    {
        setCanRest(!ptr.isEmpty() || MWBase::Environment::get().getWorld ()->canRest () == 0);

        if (mUntilHealedButton->getVisible())
            MWBase::Environment::get().getWindowManager()->setKeyFocusWidget(mUntilHealedButton);
        else
            MWBase::Environment::get().getWindowManager()->setKeyFocusWidget(mWaitButton);
    }
Example #16
0
    void Player::use()
    {
        MWWorld::InventoryStore& store = MWWorld::Class::get(getPlayer()).getInventoryStore(getPlayer());
        MWWorld::ContainerStoreIterator equipped = store.getSlot(MWWorld::InventoryStore::Slot_CarriedRight);

        if (getDrawState() == MWMechanics::DrawState_Weapon)
        {
            if (equipped != store.end())
            {
                MWWorld::Ptr item = *equipped;
                MWRender::Animation* anim = MWBase::Environment::get().getWorld()->getAnimation(getPlayer());
                MWWorld::Ptr target = MWBase::Environment::get().getWorld()->getFacedObject();

                if (anim->isPriorityActive(MWMechanics::Priority_Weapon))
                    return;

                std::string resultMessage, resultSound;

                if (item.getTypeName() == typeid(ESM::Lockpick).name())
                {
                    if (!target.isEmpty())
                        MWMechanics::Security(getPlayer()).pickLock(target, item, resultMessage, resultSound);
                    anim->play("pickprobe", MWMechanics::Priority_Weapon, MWRender::Animation::Group_UpperBody, true, 1.0f, "start", "stop", 0.0, 0);
                }
                else if (item.getTypeName() == typeid(ESM::Probe).name())
                {
                    if (!target.isEmpty())
                        MWMechanics::Security(getPlayer()).probeTrap(target, item, resultMessage, resultSound);
                    anim->play("pickprobe", MWMechanics::Priority_Weapon, MWRender::Animation::Group_UpperBody, true, 1.0f, "start", "stop", 0.0, 0);
                }

                if (!resultMessage.empty())
                    MWBase::Environment::get().getWindowManager()->messageBox(resultMessage);
                if (!resultSound.empty())
                    MWBase::Environment::get().getSoundManager()->playSound(resultSound,1,1);

                // tool used up?
                if (!item.getRefData().getCount())
                    MWBase::Environment::get().getWindowManager()->unsetSelectedWeapon();
                else
                    MWBase::Environment::get().getWindowManager()->setSelectedWeapon(item);
            }
        }
    }
Example #17
0
bool AiSequence::getCombatTarget(MWWorld::Ptr &targetActor) const
{
    if (getTypeId() != AiPackage::TypeIdCombat)
        return false;
    const AiCombat *combat = static_cast<const AiCombat *>(mPackages.front());
    
    targetActor = combat->getTarget();

    return !targetActor.isEmpty();
}
Example #18
0
 InterpreterContext::InterpreterContext (
     MWScript::Locals *locals, MWWorld::Ptr reference, const std::string& targetId)
 : mLocals (locals), mReference (reference), mTargetId (targetId)
 {
     // If we run on a reference (local script, dialogue script or console with object
     // selected), store the ID of that reference store it so it can be inherited by
     // targeted scripts started from this one.
     if (targetId.empty() && !reference.isEmpty())
         mTargetId = reference.getCellRef().getRefId();
 }
Example #19
0
    bool AiCombat::execute (const MWWorld::Ptr& actor, CharacterController& characterController, AiState& state, float duration)
    {
        // get or create temporary storage
        AiCombatStorage& storage = state.get<AiCombatStorage>();
        
        //General description
        if (actor.getClass().getCreatureStats(actor).isDead())
            return true;

        MWWorld::Ptr target = MWBase::Environment::get().getWorld()->searchPtrViaActorId(mTargetActorId);
        if (target.isEmpty())
            return false;

        if(!target.getRefData().getCount() || !target.getRefData().isEnabled()  // Really we should be checking whether the target is currently registered
                                                                                // with the MechanicsManager
                || target.getClass().getCreatureStats(target).isDead())
            return true;

        if (!storage.isFleeing())
        {
            if (storage.mCurrentAction.get()) // need to wait to init action with its attack range
            {
                //Update every frame. UpdateLOS uses a timer, so the LOS check does not happen every frame.
                updateLOS(actor, target, duration, storage);
                float targetReachedTolerance = 0.0f;
                if (storage.mLOS)
                    targetReachedTolerance = storage.mAttackRange;
                bool is_target_reached = pathTo(actor, target.getRefData().getPosition().pos, duration, targetReachedTolerance);
                if (is_target_reached) storage.mReadyToAttack = true;
            }

            storage.updateCombatMove(duration);
            if (storage.mReadyToAttack) updateActorsMovement(actor, duration, storage);
            storage.updateAttack(characterController);
        }
        else
        {
            updateFleeing(actor, target, duration, storage);
        }
        storage.mActionCooldown -= duration;

        float& timerReact = storage.mTimerReact;
        if (timerReact < AI_REACTION_TIME)
        {
            timerReact += duration;
        }
        else
        {
            timerReact = 0;
            if (attack(actor, target, storage, characterController))
                return true;
        }

        return false;
    }
Example #20
0
    float InterpreterContext::getDistance (const std::string& name, const std::string& id) const
    {
        const MWWorld::Ptr ref2 = getReference (id, false, false);
        // If either actor is in a non-active cell, return a large value (just like vanilla)
        if (ref2.isEmpty())
            return std::numeric_limits<float>().max();

        const MWWorld::Ptr ref = getReference (name, false, false);
        if (ref.isEmpty())
            return std::numeric_limits<float>().max();

        double diff[3];

        const float* const pos1 = ref.getRefData().getPosition().pos;
        const float* const pos2 = ref2.getRefData().getPosition().pos;
        for (int i=0; i<3; ++i)
            diff[i] = pos1[i] - pos2[i];

        return std::sqrt (diff[0]*diff[0] + diff[1]*diff[1] + diff[2]*diff[2]);
    }
Example #21
0
    void adjustWeaponDamage(float &damage, const MWWorld::Ptr &weapon)
    {
        if (weapon.isEmpty())
            return;

        const bool weaphashealth = weapon.getClass().hasItemHealth(weapon);
        if(weaphashealth)
        {
            int weaphealth = weapon.getClass().getItemHealth(weapon);
            int weapmaxhealth = weapon.getClass().getItemMaxHealth(weapon);
            damage *= (float(weaphealth) / weapmaxhealth);
        }
    }
Example #22
0
    void Creature::onHit(const MWWorld::Ptr &ptr, float damage, bool ishealth, const MWWorld::Ptr &object, const MWWorld::Ptr &attacker, bool successful) const
    {
        // NOTE: 'object' and/or 'attacker' may be empty.

        if(!successful)
        {
            // TODO: Handle HitAttemptOnMe script function

            // Missed
            MWBase::Environment::get().getSoundManager()->playSound3D(ptr, "miss", 1.0f, 1.0f);
            return;
        }

        if(!object.isEmpty())
            getCreatureStats(ptr).setLastHitObject(MWWorld::Class::get(object).getId(object));

        if(!attacker.isEmpty() && attacker.getRefData().getHandle() == "player")
        {
            const std::string &script = ptr.get<ESM::Creature>()->mBase->mScript;
            /* Set the OnPCHitMe script variable. The script is responsible for clearing it. */
            if(!script.empty())
                ptr.getRefData().getLocals().setVarByInt(script, "onpchitme", 1);
        }

        if(ishealth)
        {
            if(damage > 0.0f)
                MWBase::Environment::get().getSoundManager()->playSound3D(ptr, "Health Damage", 1.0f, 1.0f);
            float health = getCreatureStats(ptr).getHealth().getCurrent() - damage;
            setActorHealth(ptr, health, attacker);
        }
        else
        {
            MWMechanics::DynamicStat<float> fatigue(getCreatureStats(ptr).getFatigue());
            fatigue.setCurrent(fatigue.getCurrent() - damage);
            getCreatureStats(ptr).setFatigue(fatigue);
        }
    }
Example #23
0
void OMW::Engine::activate()
{
    if (MWBase::Environment::get().getWindowManager()->isGuiMode())
        return;

    MWWorld::Ptr ptr = MWBase::Environment::get().getWorld()->getFacedObject();

    if (ptr.isEmpty())
        return;

    if (ptr.getClass().getName(ptr) == "") // objects without name presented to user can never be activated
        return;

    MWBase::Environment::get().getWorld()->activate(ptr, MWBase::Environment::get().getWorld()->getPlayerPtr());
}
 void EnchantingDialog::setSoulGem(const MWWorld::Ptr &gem)
 {
     if (gem.isEmpty())
     {
         mSoulBox->setItem(MWWorld::Ptr());
         mSoulBox->clearUserStrings();
         mEnchanting.setSoulGem(MWWorld::Ptr());
     }
     else
     {
         mSoulBox->setItem(gem);
         mSoulBox->setUserString ("ToolTipType", "ItemPtr");
         mSoulBox->setUserData(MWWorld::Ptr(gem));
         mEnchanting.setSoulGem(gem);
     }
 }
Example #25
0
    void HUD::updateEnemyHealthBar()
    {
        MWWorld::Ptr enemy = MWBase::Environment::get().getWorld()->searchPtrViaActorId(mEnemyActorId);
        if (enemy.isEmpty())
            return;
        MWMechanics::CreatureStats& stats = enemy.getClass().getCreatureStats(enemy);
        mEnemyHealth->setProgressRange(100);
        // Health is usually cast to int before displaying. Actors die whenever they are < 1 health.
        // Therefore any value < 1 should show as an empty health bar. We do the same in statswindow :)
        mEnemyHealth->setProgressPosition(static_cast<size_t>(stats.getHealth().getCurrent() / stats.getHealth().getModified() * 100));

        static const float fNPCHealthBarFade = MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>().find("fNPCHealthBarFade")->getFloat();
        if (fNPCHealthBarFade > 0.f)
            mEnemyHealth->setAlpha(std::max(0.f, std::min(1.f, mEnemyHealthTimer/fNPCHealthBarFade)));

    }
Example #26
0
 void applyFatigueLoss(const MWWorld::Ptr &attacker, const MWWorld::Ptr &weapon, float attackStrength)
 {
     // somewhat of a guess, but using the weapon weight makes sense
     const MWWorld::Store<ESM::GameSetting>& store = MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>();
     const float fFatigueAttackBase = store.find("fFatigueAttackBase")->getFloat();
     const float fFatigueAttackMult = store.find("fFatigueAttackMult")->getFloat();
     const float fWeaponFatigueMult = store.find("fWeaponFatigueMult")->getFloat();
     CreatureStats& stats = attacker.getClass().getCreatureStats(attacker);
     MWMechanics::DynamicStat<float> fatigue = stats.getFatigue();
     const float normalizedEncumbrance = attacker.getClass().getNormalizedEncumbrance(attacker);
     float fatigueLoss = fFatigueAttackBase + normalizedEncumbrance * fFatigueAttackMult;
     if (!weapon.isEmpty())
         fatigueLoss += weapon.getClass().getWeight(weapon) * attackStrength * fWeaponFatigueMult;
     fatigue.setCurrent(fatigue.getCurrent() - fatigueLoss);
     stats.setFatigue(fatigue);
 }
Example #27
0
 void EnchantingDialog::setItem(const MWWorld::Ptr &item)
 {
     if (item.isEmpty())
     {
         mItemBox->setItem(MWWorld::Ptr());
         mItemBox->clearUserStrings();
         mEnchanting.setOldItem(MWWorld::Ptr());
     }
     else
     {
         mItemBox->setItem(item);
         mItemBox->setUserString ("ToolTipType", "ItemPtr");
         mItemBox->setUserData(item);
         mEnchanting.setOldItem(item);
     }
 }
Example #28
0
                virtual void execute (Interpreter::Runtime &runtime)
                {
                    MWWorld::Ptr actor = R()(runtime);
                    std::string testedTargetId = runtime.getStringLiteral (runtime[0].mInteger);
                    runtime.pop();

                    const MWMechanics::CreatureStats& creatureStats = actor.getClass().getCreatureStats(actor);

                    bool targetsAreEqual = false;
                    MWWorld::Ptr targetPtr;
                    if (creatureStats.getAiSequence().getCombatTarget (targetPtr))
                    {
                        if (!targetPtr.isEmpty() && targetPtr.getCellRef().getRefId() == testedTargetId)
                            targetsAreEqual = true;
                    }
                    runtime.push(int(targetsAreEqual));
                }
Example #29
0
void OMW::Engine::activate()
{
    if (MWBase::Environment::get().getWindowManager()->getMode()!=MWGui::GM_Game)
        return;

    std::string handle = MWBase::Environment::get().getWorld()->getFacedHandle();

    if (handle.empty())
        return;

    // the faced handle is not updated immediately, so on a cell change it might
    // point to an object that doesn't exist anymore
    // therefore, we are catching the "Unknown Ogre handle" exception that occurs in this case
    MWWorld::Ptr ptr;
    try
    {
        ptr = MWBase::Environment::get().getWorld()->getPtrViaHandle (handle);

        if (ptr.isEmpty())
            return;
    }
    catch (std::runtime_error&)
    {
        return;
    }

    MWScript::InterpreterContext interpreterContext (&ptr.getRefData().getLocals(), ptr);

    boost::shared_ptr<MWWorld::Action> action =
        MWWorld::Class::get (ptr).activate (ptr, MWBase::Environment::get().getWorld()->getPlayer().getPlayer());

    interpreterContext.activate (ptr, action);

    std::string script = MWWorld::Class::get (ptr).getScript (ptr);

    if (!script.empty())
    {
        MWBase::Environment::get().getWorld()->getLocalScripts().setIgnore (ptr);
        MWBase::Environment::get().getScriptManager()->run (script, interpreterContext);
    }

    if (!interpreterContext.hasActivationBeenHandled())
    {
        interpreterContext.executeActivation();
    }
}
Example #30
0
 bool applyOnStrikeEnchantment (const MWWorld::Ptr& attacker, const MWWorld::Ptr& victim, const MWWorld::Ptr& object, const osg::Vec3f& hitPosition)
 {
     std::string enchantmentName = !object.isEmpty() ? object.getClass().getEnchantment(object) : "";
     if (!enchantmentName.empty())
     {
         const ESM::Enchantment* enchantment = MWBase::Environment::get().getWorld()->getStore().get<ESM::Enchantment>().find(
                     enchantmentName);
         if (enchantment->mData.mType == ESM::Enchantment::WhenStrikes)
         {
             MWMechanics::CastSpell cast(attacker, victim);
             cast.mHitPosition = hitPosition;
             cast.cast(object, false);
             return true;
         }
     }
     return false;
 }