mirror of
				https://github.com/OpenMW/openmw.git
				synced 2025-11-04 00:26:39 +00:00 
			
		
		
		
	refactored special variable code
This commit is contained in:
		
							parent
							
								
									f785659297
								
							
						
					
					
						commit
						ac112ef972
					
				
					 7 changed files with 58 additions and 94 deletions
				
			
		| 
						 | 
				
			
			@ -41,7 +41,7 @@ add_openmw_dir (mwscript
 | 
			
		|||
    locals scriptmanagerimp compilercontext interpretercontext cellextensions miscextensions
 | 
			
		||||
    guiextensions soundextensions skyextensions statsextensions containerextensions
 | 
			
		||||
    aiextensions controlextensions extensions globalscripts ref dialogueextensions
 | 
			
		||||
    animationextensions transformationextensions consoleextensions userextensions
 | 
			
		||||
    animationextensions transformationextensions consoleextensions userextensions locals
 | 
			
		||||
    )
 | 
			
		||||
 | 
			
		||||
add_openmw_dir (mwsound
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -13,7 +13,6 @@
 | 
			
		|||
#include "../mwbase/environment.hpp"
 | 
			
		||||
#include "../mwbase/soundmanager.hpp"
 | 
			
		||||
#include "../mwbase/windowmanager.hpp"
 | 
			
		||||
#include "../mwbase/scriptmanager.hpp"
 | 
			
		||||
 | 
			
		||||
#include "../mwworld/containerstore.hpp"
 | 
			
		||||
#include "../mwworld/class.hpp"
 | 
			
		||||
| 
						 | 
				
			
			@ -245,27 +244,10 @@ namespace MWGui
 | 
			
		|||
                invStore.equip(slot, invStore.end());
 | 
			
		||||
                std::string script = MWWorld::Class::get(*it).getScript(*it);
 | 
			
		||||
                
 | 
			
		||||
                /* Unset OnPCEquip Variable on item's script, if it has a script with that variable declared */
 | 
			
		||||
                // Unset OnPCEquip Variable on item's script, if it has a script with that variable declared
 | 
			
		||||
                if(script != "")
 | 
			
		||||
                {
 | 
			
		||||
                    Compiler::Locals locals = MWBase::Environment::get().getScriptManager()->getLocals(script);
 | 
			
		||||
                    int index = locals.getIndex("onpcequip");
 | 
			
		||||
                    char type = locals.getType("onpcequip");
 | 
			
		||||
                    if(index != -1)
 | 
			
		||||
                    {
 | 
			
		||||
                        switch(type)
 | 
			
		||||
                        {
 | 
			
		||||
                            case 's':
 | 
			
		||||
                                (*it).mRefData->getLocals().mShorts.at (index) = 0; break;
 | 
			
		||||
                            
 | 
			
		||||
                            case 'l':
 | 
			
		||||
                                (*it).mRefData->getLocals().mLongs.at (index) = 0; break;
 | 
			
		||||
                            
 | 
			
		||||
                            case 'f':
 | 
			
		||||
                                (*it).mRefData->getLocals().mFloats.at (index) = 0.0; break;
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
                    (*it).mRefData->getLocals().setVarByInt(script, "onpcequip", 0);
 | 
			
		||||
                
 | 
			
		||||
                return;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										41
									
								
								apps/openmw/mwscript/locals.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										41
									
								
								apps/openmw/mwscript/locals.cpp
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,41 @@
 | 
			
		|||
#include "locals.hpp"
 | 
			
		||||
 | 
			
		||||
#include "../mwbase/environment.hpp"
 | 
			
		||||
#include "../mwbase/scriptmanager.hpp"
 | 
			
		||||
#include <components/compiler/locals.hpp>
 | 
			
		||||
 | 
			
		||||
namespace MWScript
 | 
			
		||||
{
 | 
			
		||||
    void Locals::configure (const ESM::Script& script)
 | 
			
		||||
    {
 | 
			
		||||
        mShorts.clear();
 | 
			
		||||
        mShorts.resize (script.mData.mNumShorts, 0);
 | 
			
		||||
        mLongs.clear();
 | 
			
		||||
        mLongs.resize (script.mData.mNumLongs, 0);
 | 
			
		||||
        mFloats.clear();
 | 
			
		||||
        mFloats.resize (script.mData.mNumFloats, 0);
 | 
			
		||||
    }
 | 
			
		||||
        
 | 
			
		||||
    bool Locals::setVarByInt(const std::string& script, const std::string& var, int val)
 | 
			
		||||
    {    
 | 
			
		||||
        Compiler::Locals locals = MWBase::Environment::get().getScriptManager()->getLocals(script);
 | 
			
		||||
        int index = locals.getIndex(var);
 | 
			
		||||
        char type = locals.getType(var);
 | 
			
		||||
        if(index != -1)
 | 
			
		||||
        {
 | 
			
		||||
            switch(type)
 | 
			
		||||
            {
 | 
			
		||||
                case 's':
 | 
			
		||||
                    mShorts.at (index) = val; break;
 | 
			
		||||
                
 | 
			
		||||
                case 'l':
 | 
			
		||||
                    mLongs.at (index) = val; break;
 | 
			
		||||
                
 | 
			
		||||
                case 'f':
 | 
			
		||||
                    mFloats.at (index) = val; break;
 | 
			
		||||
            }
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -8,21 +8,16 @@
 | 
			
		|||
 | 
			
		||||
namespace MWScript
 | 
			
		||||
{
 | 
			
		||||
    struct Locals
 | 
			
		||||
    class Locals
 | 
			
		||||
    {
 | 
			
		||||
        std::vector<Interpreter::Type_Short> mShorts;
 | 
			
		||||
        std::vector<Interpreter::Type_Integer> mLongs;
 | 
			
		||||
        std::vector<Interpreter::Type_Float> mFloats;
 | 
			
		||||
        public:
 | 
			
		||||
            std::vector<Interpreter::Type_Short> mShorts;
 | 
			
		||||
            std::vector<Interpreter::Type_Integer> mLongs;
 | 
			
		||||
            std::vector<Interpreter::Type_Float> mFloats;
 | 
			
		||||
            
 | 
			
		||||
            void configure (const ESM::Script& script);
 | 
			
		||||
            bool setVarByInt(const std::string& script, const std::string& var, int val);
 | 
			
		||||
        
 | 
			
		||||
        void configure (const ESM::Script& script)
 | 
			
		||||
        {
 | 
			
		||||
            mShorts.clear();
 | 
			
		||||
            mShorts.resize (script.mData.mNumShorts, 0);
 | 
			
		||||
            mLongs.clear();
 | 
			
		||||
            mLongs.resize (script.mData.mNumLongs, 0);
 | 
			
		||||
            mFloats.clear();
 | 
			
		||||
            mFloats.resize (script.mData.mNumFloats, 0);
 | 
			
		||||
        }
 | 
			
		||||
    };
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -3,7 +3,6 @@
 | 
			
		|||
#include "../mwbase/environment.hpp"
 | 
			
		||||
#include "../mwbase/world.hpp"
 | 
			
		||||
#include "../mwbase/windowmanager.hpp"
 | 
			
		||||
#include "../mwbase/scriptmanager.hpp"
 | 
			
		||||
 | 
			
		||||
#include <components/compiler/locals.hpp>
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -113,24 +112,6 @@ namespace MWWorld
 | 
			
		|||
        
 | 
			
		||||
        /* Set OnPCEquip Variable on item's script, if the player is equipping it, and it has a script with that variable declared */
 | 
			
		||||
        if(equipped && actor == MWBase::Environment::get().getWorld()->getPlayer().getPlayer() && script != "")
 | 
			
		||||
        {
 | 
			
		||||
            Compiler::Locals locals = MWBase::Environment::get().getScriptManager()->getLocals(script);
 | 
			
		||||
            int index = locals.getIndex("onpcequip");
 | 
			
		||||
            char type = locals.getType("onpcequip");
 | 
			
		||||
            if(index != -1)
 | 
			
		||||
            {
 | 
			
		||||
                switch(type)
 | 
			
		||||
                {
 | 
			
		||||
                    case 's':
 | 
			
		||||
                        (*it).mRefData->getLocals().mShorts.at (index) = 1; break;
 | 
			
		||||
                    
 | 
			
		||||
                    case 'l':
 | 
			
		||||
                        (*it).mRefData->getLocals().mLongs.at (index) = 1; break;
 | 
			
		||||
                    
 | 
			
		||||
                    case 'f':
 | 
			
		||||
                        (*it).mRefData->getLocals().mFloats.at (index) = 1.0; break;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
            (*it).mRefData->getLocals().setVarByInt(script, "onpcequip", 1);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -88,27 +88,10 @@ MWWorld::ContainerStoreIterator MWWorld::ContainerStore::add (const Ptr& ptr)
 | 
			
		|||
        
 | 
			
		||||
        if(&(MWWorld::Class::get (player).getContainerStore (player)) == this)
 | 
			
		||||
        {
 | 
			
		||||
            cell = 0; // Items in players inventory have cell set to 0, so their scripts will never be removed
 | 
			
		||||
            cell = 0; // Items in player's inventory have cell set to 0, so their scripts will never be removed
 | 
			
		||||
           
 | 
			
		||||
            // Set OnPCAdd special variable, if it is declared 
 | 
			
		||||
            Compiler::Locals locals = MWBase::Environment::get().getScriptManager()->getLocals(script);
 | 
			
		||||
            int index = locals.getIndex("onpcadd");
 | 
			
		||||
            char type = locals.getType("onpcadd");
 | 
			
		||||
            
 | 
			
		||||
            if(index != -1)
 | 
			
		||||
            {
 | 
			
		||||
                switch(type)
 | 
			
		||||
                {
 | 
			
		||||
                    case 's':
 | 
			
		||||
                        item.mRefData->getLocals().mShorts.at (index) = 1; break;
 | 
			
		||||
                    
 | 
			
		||||
                    case 'l':
 | 
			
		||||
                        item.mRefData->getLocals().mLongs.at (index) = 1; break;
 | 
			
		||||
                    
 | 
			
		||||
                    case 'f':
 | 
			
		||||
                        item.mRefData->getLocals().mFloats.at (index) = 1.0; break;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            item.mRefData->getLocals().setVarByInt(script, "onpcadd", 1);
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
            cell = player.getCell();
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1277,27 +1277,9 @@ namespace MWWorld
 | 
			
		|||
    {
 | 
			
		||||
        std::string script = MWWorld::Class::get(item).getScript(item);
 | 
			
		||||
        
 | 
			
		||||
        /* Set OnPCDrop Variable on item's script, if it has a script with that variable declared */
 | 
			
		||||
        // Set OnPCDrop Variable on item's script, if it has a script with that variable declared 
 | 
			
		||||
        if(script != "")
 | 
			
		||||
        {
 | 
			
		||||
            Compiler::Locals locals = MWBase::Environment::get().getScriptManager()->getLocals(script);
 | 
			
		||||
            int index = locals.getIndex("onpcdrop");
 | 
			
		||||
            char type = locals.getType("onpcdrop");
 | 
			
		||||
            if(index != -1)
 | 
			
		||||
            {
 | 
			
		||||
                switch(type)
 | 
			
		||||
                {
 | 
			
		||||
                    case 's':
 | 
			
		||||
                        item.mRefData->getLocals().mShorts.at (index) = 1; break;
 | 
			
		||||
                    
 | 
			
		||||
                    case 'l':
 | 
			
		||||
                        item.mRefData->getLocals().mLongs.at (index) = 1; break;
 | 
			
		||||
                    
 | 
			
		||||
                    case 'f':
 | 
			
		||||
                        item.mRefData->getLocals().mFloats.at (index) = 1.0; break;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
            item.mRefData->getLocals().setVarByInt(script, "onpcdrop", 1);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    bool World::placeObject (const Ptr& object, float cursorX, float cursorY)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in a new issue