- Provides an object to store local variables on. The execution time of GetLocal* or SetLocal* functions increases linearly with the number of local variables on an object. By providing each system with its own storage object, we reduce the execution time of those functions when using that object. The "private" nature of many of these objects means that there is no chance of other systems creating conflicting local variable names, so shorter names can be used, increasing speed and decreasing memory use.
- Provides a source for applying effects. In nwscript, the only way to differentiate two identical effects is to compare their creators with GetEffectCReator(). So if you want to tell the difference between a EFFECT_TYPE_CONCEALMENT from a darkness spell or the weather system, you need to call GetEffectCreator(). Local variables attached to the storage object can describe the source of the effect (see the persistant effects system), so that intelligent choices on removal can be made. I'm not sure what the best way to configure this system would be, so I've left it as a simple boolean removable/unremovable flag for now.
- The storage object can store items as well, as they have inventories.
Code: Select all
////////////////////////////////////////////////////////////////////////////////
//
// System Name : ALFA Core Rules
// Filename : acr_storage_obj_i
// Version : 0.1
// Date : 5/4/06
// Author : Ronan
//
// Local Variable Prefix = ACR_STO
//
// Dependencies external of nwscript:
// Requires a placable blueprint resref to exist, as defined by the
// _ACR_STO_OBJECT_RESREF constant. Also requires a waypoint containing the tag
// of the _ACR_STO_WAYPOINT_TAG constant to exist.
//
// Description
// NWN stores variables by placing them on objects. For this reason, a system
// to organize the objects they store these variables on is needed. In NWN1,
// local variable mean access time increases linearly with the number of
// variables stored on an object (as dumb as that is).
// Also, this system can be used as a way to track effects on a creature,
// by use of GetEffectCreator().
//
// Revision History
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// Includes ////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
#include "acr_debug_i"
////////////////////////////////////////////////////////////////////////////////
// Constants ///////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// Blueprint resref for the storage object.
const string _ACR_STO_OBJECT_RESREF = "acr_sto_obj";
// Waypoint tag for the location the objects are created at.
const string _ACR_STO_WAYPOINT_TAG = "acr_sto_wp";
// Signifies that effects applied by this object should be removable through
// normal means.
const int STORAGE_ITEM_EFFECTS_REMOVABLE = 1;
// Signifies that effects applied by this object should not be removable through
// normal means.
const int STORAGE_ITEM_EFFECTS_UNREMOVALBE = 2;
// The local int for the above constants.
const string _EFFECTS_REMOVABLE_LI = "ACR_STO_EFFRMV";
////////////////////////////////////////////////////////////////////////////////
// Structures //////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// Global Variables ////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
int _storageDebugSystem;
////////////////////////////////////////////////////////////////////////////////
// Function Prototypes /////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// Initializes the storage object system. Usually called from OnModuleLoad.
void InitializeStorageObjects();
// Creates and returns a storage object, a medium for storing local variables.
// bEffectsRemovable should be defined as,
// STORAGE_ITEM_EFFECTS_REMOVABLE
// Signifies that effects applied by this object should be removable through
// normal means. Or,
// STORAGE_ITEM_EFFECTS_UNREMOVALBE
// Signifies that effects applied by this object should not be removable through
// normal means.
object CreateStorageObject(string sName = "", int bEffectsRemovable = STORAGE_ITEM_EFFECTS_REMOVABLE);
// Returns 1 if effects applied from oObject are removable, 0 otherwise.
int CanRemoveEffectsFrom(object oObject);
////////////////////////////////////////////////////////////////////////////////
// Function Definitions ////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
void InitializeStorageObjects() {
_storageDebugSystem = CreateDebugSystem("Storage object: ", DEBUG_TARGET_NONE, DEBUG_TARGET_LOG, DEBUG_TARGET_LOG);
}
object CreateStorageObject(string sName = "", int bEffectsRemovable = STORAGE_ITEM_EFFECTS_REMOVABLE) {
PrintDebugMessage("Creating storage object named: " + sName, _storageDebugSystem, DEBUG_LEVEL_INFO);
object wp = GetObjectByTag(_ACR_STO_WAYPOINT_TAG);
if(!GetIsObjectValid(wp)) {
PrintDebugMessage("Error finding creation waypoint. Tag looked for: " + _ACR_STO_WAYPOINT_TAG, _storageDebugSystem, DEBUG_LEVEL_FATAL);
return OBJECT_INVALID;
}
if( !GetIsObjectValid(GetObjectByTag(_ACR_STO_WAYPOINT_TAG, 1)) ) {
PrintDebugMessage("Multiple storage object waypoints found! There should only be one. Tag looked for: " + _ACR_STO_WAYPOINT_TAG, _storageDebugSystem, DEBUG_LEVEL_WARNING);
}
object obj;
obj = CreateObject(OBJECT_TYPE_PLACEABLE, _ACR_STO_OBJECT_RESREF, GetLocation(wp), FALSE, sName);
if(sName != "") {
SetName(obj, sName);
}
if(!GetHasInventory(obj)) {
PrintDebugMessage("Storage object does not have an inventory.", _storageDebugSystem, DEBUG_LEVEL_FATAL);
}
if(!GetIsObjectValid(obj)) {
PrintDebugMessage("Error creating object of resref " + _ACR_STO_OBJECT_RESREF, _storageDebugSystem, DEBUG_LEVEL_FATAL);
return OBJECT_INVALID;
}
SetPlotFlag(obj, 1);
AssignCommand(obj, SetIsDestroyable(0, 0, 0));
SetLocalInt(obj, _EFFECTS_REMOVABLE_LI, bEffectsRemovable);
return obj;
}
int CanRemoveEffectsFrom(object oObject) {
return GetLocalInt(oObject, _EFFECTS_REMOVABLE_LI);
}