|
| 1 | +/// @addtogroup snapshot Snapshot |
| 2 | +/// @brief Functions to create cool object snapshots with filters! |
| 3 | +/// @{ |
| 4 | +/// @file nwnx_snapshot.nss |
| 5 | +#include "nwnx" |
| 6 | + |
| 7 | +const string NWNX_Snapshot = "NWNX_Snapshot"; ///< @private |
| 8 | + |
| 9 | +const int NWNX_SNAPSHOT_COMPARISON_EQUALS = 0; |
| 10 | +const int NWNX_SNAPSHOT_COMPARISON_NOT_EQUALS = 1; |
| 11 | +const int NWNX_SNAPSHOT_COMPARISON_GREATER_THAN = 2; |
| 12 | +const int NWNX_SNAPSHOT_COMPARISON_LESSER_THAN = 3; |
| 13 | +const int NWNX_SNAPSHOT_COMPARISON_GREATER_THAN_OR_EQUALS = 4; |
| 14 | +const int NWNX_SNAPSHOT_COMPARISON_LESSER_THAN_OR_EQUALS = 5; |
| 15 | + |
| 16 | + |
| 17 | +const int NWNX_SNAPSHOT_FILTER_TYPE_TAG = 1; |
| 18 | +const int NWNX_SNAPSHOT_FILTER_TYPE_LOCALVAR = 2; |
| 19 | +const int NWNX_SNAPSHOT_FILTER_TYPE_CREATURESTATS = 3; |
| 20 | + |
| 21 | + |
| 22 | +const int NWNX_SNAPSHOT_FILTER_SUBTYPE_DEFAULT = 0; |
| 23 | +const int NWNX_SNAPSHOT_FILTER_SUBTYPE_STRING_REGEX = 1; |
| 24 | +const int NWNX_SNAPSHOT_FILTER_SUBTYPE_LOCALVAR_INT = 1; |
| 25 | +const int NWNX_SNAPSHOT_FILTER_SUBTYPE_LOCALVAR_FLOAT = 2; |
| 26 | +const int NWNX_SNAPSHOT_FILTER_SUBTYPE_LOCALVAR_OBJECT = 3; |
| 27 | +const int NWNX_SNAPSHOT_FILTER_SUBTYPE_LOCALVAR_STRING = 4; |
| 28 | +const int NWNX_SNAPSHOT_FILTER_SUBTYPE_CREATURESTATS_ABILITY = 1; |
| 29 | +const int NWNX_SNAPSHOT_FILTER_SUBTYPE_CREATURESTATS_ABILITY_MOD = 2; |
| 30 | +const int NWNX_SNAPSHOT_FILTER_SUBTYPE_CREATURESTATS_HAS_CLASS = 3; |
| 31 | + |
| 32 | +struct NWNX_Snapshot_Filter |
| 33 | +{ |
| 34 | + int nType; |
| 35 | + int nSubtype; |
| 36 | + int nComparison; |
| 37 | + int bInvert; |
| 38 | + |
| 39 | + int nParam1; |
| 40 | + int nParam2; |
| 41 | + string sParam1; |
| 42 | + string sParam2; |
| 43 | + float fParam1; |
| 44 | + float fParam2; |
| 45 | + object oParam1; |
| 46 | + object oParam2; |
| 47 | +}; |
| 48 | + |
| 49 | +/// @brief Create a snapshot of objects that are within a shape. |
| 50 | +/// @param nShape One of SHAPE_* |
| 51 | +/// @param fSize Depends on nShape: |
| 52 | +/// SHAPE_SPHERE: the radius of the sphere. |
| 53 | +/// SHAPE_SPELLCYLINDER: the length of the cylinder. Spell Cylinder's always have a radius of 1.5m. |
| 54 | +/// SHAPE_CONE: the widest radius of the cone. |
| 55 | +/// SHAPE_SPELLCONE: the length of the cone in the direction of locTarget. Spell cones are always 60 degrees with the origin at OBJECT_SELF. |
| 56 | +/// SHAPE_CUBE: half the length of one of the sides of the cube. |
| 57 | +/// @param locTarget This is the centre of the effect, usually GetSpellTargetLocation(), or the end of a cylinder or cone. |
| 58 | +/// @param bLineOfSight Controls whether to do a line-of-sight check on the object returned. The line of sight check is done from origin to target object at a height 1m above the ground. |
| 59 | +/// @param nObjectFilter This allows you to filter out undesired object types, using bitwise "or". For example, to return only creatures and doors, the value for this parameter would be OBJECT_TYPE_CREATURE | OBJECT_TYPE_DOOR. |
| 60 | +/// @param vOrigin This is only used for cylinders and cones, and specifies the origin of the effect(normally the spell-caster's position). |
| 61 | +/// @param nSnapshotID An optional ID for this snapshot. Useful if you want to nest calls to this function. |
| 62 | +/// @return The amount of objects in the snapshot. |
| 63 | +int NWNX_Snapshot_CreateAreaShapeSnapshot(int nShape, float fSize, location locTarget, int bLineOfSight = FALSE, int nObjectFilter = OBJECT_TYPE_CREATURE, vector vOrigin = [0.0f,0.0f,0.0f], int nSnapshotID = 0); |
| 64 | + |
| 65 | +/// @brief Create a snapshot of objects that are within an area. |
| 66 | +/// @param oArea The area. |
| 67 | +/// @param nObjectFilter This allows you to filter out undesired object types, using bitwise "or". For example, to return only creatures and doors, the value for this parameter would be OBJECT_TYPE_CREATURE | OBJECT_TYPE_DOOR. |
| 68 | +/// @param nSnapshotID An optional ID for this snapshot. Useful if you want to nest calls to this function. |
| 69 | +/// @return The amount of objects in the snapshot. |
| 70 | +int NWNX_Snapshot_CreateAreaSnapshot(object oArea, int nObjectFilter = OBJECT_TYPE_CREATURE, int nSnapshotID = 0); |
| 71 | + |
| 72 | +/// @brief Create a snapshot of objects that are within the whole module. |
| 73 | +/// @note Does not include player characters. |
| 74 | +/// @param nObjectFilter This allows you to filter out undesired object types, using bitwise "or". For example, to return only creatures and doors, the value for this parameter would be OBJECT_TYPE_CREATURE | OBJECT_TYPE_DOOR. |
| 75 | +/// @param nSnapshotID An optional ID for this snapshot. Useful if you want to nest calls to this function. |
| 76 | +/// @return The amount of objects in the snapshot. |
| 77 | +int NWNX_Snapshot_CreateModuleSnapshot(int nObjectFilter = OBJECT_TYPE_CREATURE, int nSnapshotID = 0); |
| 78 | + |
| 79 | +/// @brief Gets the object at nIndex from a snapshot. |
| 80 | +/// @param nIndex The index of the object to get. |
| 81 | +/// @param nSnapshotID An optional ID to get objects from a specific snapshot. |
| 82 | +/// @return The object at nIndex or OBJECT_INVALID; |
| 83 | +object NWNX_Snapshot_GetObjectFromSnapshot(int nIndex, int nSnapshotID = 0); |
| 84 | + |
| 85 | +/// @brief Prune all invalid objects from a snapshot. |
| 86 | +/// @param nSnapshotID An optional ID to prune a specific snapshot. |
| 87 | +/// @return The number of objects in the snapshot after pruning. |
| 88 | +int NWNX_Snapshot_PruneSnapshot(int nSnapshotID = 0); |
| 89 | + |
| 90 | +/// @brief Clear a snapshot, removing all objects. |
| 91 | +/// @param nSnapshotID An optional snapshot ID. |
| 92 | +void NWNX_Snapshot_ClearSnapshot(int nSnapshotID = 0); |
| 93 | + |
| 94 | +/// @brief Sort a snapshot by distance to oTarget, ascending. |
| 95 | +/// @param oTarget The target. |
| 96 | +/// @param nSnapshotID An optional snapshot ID. |
| 97 | +void NWNX_Snapshot_SortSnapshotByDistance(object oTarget, int nSnapshotID = 0); |
| 98 | + |
| 99 | +/// @brief Add a filter to nSnapshotID, should be called before creating a snapshot. |
| 100 | +/// @param nSnapshotID A snapshot ID. |
| 101 | +/// @param strFilter A NWNX_Snapshot_Filter struct. |
| 102 | +void NWNX_Snapshot_AddFilter(int nSnapshotID, struct NWNX_Snapshot_Filter strFilter); |
| 103 | + |
| 104 | +/// @brief Remove all filters associated with nSnapshotID. |
| 105 | +/// @param nSnapshotID A snapshot ID. |
| 106 | +void NWNX_Snapshot_ClearFilters(int nSnapshotID); |
| 107 | + |
| 108 | +/// @} |
| 109 | + |
| 110 | +int NWNX_Snapshot_CreateAreaShapeSnapshot(int nShape, float fSize, location locTarget, int bLineOfSight = FALSE, int nObjectFilter = OBJECT_TYPE_CREATURE, vector vOrigin = [0.0f,0.0f,0.0f], int nSnapshotID = 0) |
| 111 | +{ |
| 112 | + string sFunc = "CreateAreaShapeSnapshot"; |
| 113 | + |
| 114 | + object oArea = GetAreaFromLocation(locTarget); |
| 115 | + vector vPosition = GetPositionFromLocation(locTarget); |
| 116 | + |
| 117 | + NWNX_PushArgumentInt(NWNX_Snapshot, sFunc, nSnapshotID); |
| 118 | + NWNX_PushArgumentFloat(NWNX_Snapshot, sFunc, vOrigin.z); |
| 119 | + NWNX_PushArgumentFloat(NWNX_Snapshot, sFunc, vOrigin.y); |
| 120 | + NWNX_PushArgumentFloat(NWNX_Snapshot, sFunc, vOrigin.x); |
| 121 | + NWNX_PushArgumentInt(NWNX_Snapshot, sFunc, nObjectFilter); |
| 122 | + NWNX_PushArgumentInt(NWNX_Snapshot, sFunc, bLineOfSight); |
| 123 | + NWNX_PushArgumentFloat(NWNX_Snapshot, sFunc, vPosition.z); |
| 124 | + NWNX_PushArgumentFloat(NWNX_Snapshot, sFunc, vPosition.y); |
| 125 | + NWNX_PushArgumentFloat(NWNX_Snapshot, sFunc, vPosition.x); |
| 126 | + NWNX_PushArgumentObject(NWNX_Snapshot, sFunc, oArea); |
| 127 | + NWNX_PushArgumentFloat(NWNX_Snapshot, sFunc, fSize); |
| 128 | + NWNX_PushArgumentInt(NWNX_Snapshot, sFunc, nShape); |
| 129 | + NWNX_CallFunction(NWNX_Snapshot, sFunc); |
| 130 | + |
| 131 | + return NWNX_GetReturnValueInt(NWNX_Snapshot, sFunc); |
| 132 | +} |
| 133 | + |
| 134 | +int NWNX_Snapshot_CreateAreaSnapshot(object oArea, int nObjectFilter = OBJECT_TYPE_CREATURE, int nSnapshotID = 0) |
| 135 | +{ |
| 136 | + string sFunc = "CreateAreaSnapshot"; |
| 137 | + |
| 138 | + NWNX_PushArgumentInt(NWNX_Snapshot, sFunc, nSnapshotID); |
| 139 | + NWNX_PushArgumentInt(NWNX_Snapshot, sFunc, nObjectFilter); |
| 140 | + NWNX_PushArgumentObject(NWNX_Snapshot, sFunc, oArea); |
| 141 | + NWNX_CallFunction(NWNX_Snapshot, sFunc); |
| 142 | + |
| 143 | + return NWNX_GetReturnValueInt(NWNX_Snapshot, sFunc); |
| 144 | +} |
| 145 | + |
| 146 | +int NWNX_Snapshot_CreateModuleSnapshot(int nObjectFilter = OBJECT_TYPE_CREATURE, int nSnapshotID = 0) |
| 147 | +{ |
| 148 | + string sFunc = "CreateModuleSnapshot"; |
| 149 | + |
| 150 | + NWNX_PushArgumentInt(NWNX_Snapshot, sFunc, nSnapshotID); |
| 151 | + NWNX_PushArgumentInt(NWNX_Snapshot, sFunc, nObjectFilter); |
| 152 | + NWNX_CallFunction(NWNX_Snapshot, sFunc); |
| 153 | + |
| 154 | + return NWNX_GetReturnValueInt(NWNX_Snapshot, sFunc); |
| 155 | +} |
| 156 | + |
| 157 | +object NWNX_Snapshot_GetObjectFromSnapshot(int nIndex, int nSnapshotID = 0) |
| 158 | +{ |
| 159 | + string sFunc = "GetObjectFromSnapshot"; |
| 160 | + |
| 161 | + NWNX_PushArgumentInt(NWNX_Snapshot, sFunc, nSnapshotID); |
| 162 | + NWNX_PushArgumentInt(NWNX_Snapshot, sFunc, nIndex); |
| 163 | + NWNX_CallFunction(NWNX_Snapshot, sFunc); |
| 164 | + |
| 165 | + return NWNX_GetReturnValueObject(NWNX_Snapshot, sFunc); |
| 166 | +} |
| 167 | + |
| 168 | +int NWNX_Snapshot_PruneSnapshot(int nSnapshotID = 0) |
| 169 | +{ |
| 170 | + string sFunc = "PruneSnapshot"; |
| 171 | + |
| 172 | + NWNX_PushArgumentInt(NWNX_Snapshot, sFunc, nSnapshotID); |
| 173 | + NWNX_CallFunction(NWNX_Snapshot, sFunc); |
| 174 | + |
| 175 | + return NWNX_GetReturnValueInt(NWNX_Snapshot, sFunc); |
| 176 | +} |
| 177 | + |
| 178 | +void NWNX_Snapshot_ClearSnapshot(int nSnapshotID = 0) |
| 179 | +{ |
| 180 | + string sFunc = "ClearSnapshot"; |
| 181 | + |
| 182 | + NWNX_PushArgumentInt(NWNX_Snapshot, sFunc, nSnapshotID); |
| 183 | + NWNX_CallFunction(NWNX_Snapshot, sFunc); |
| 184 | +} |
| 185 | + |
| 186 | +void NWNX_Snapshot_SortSnapshotByDistance(object oTarget, int nSnapshotID = 0) |
| 187 | +{ |
| 188 | + string sFunc = "SortSnapshotByDistance"; |
| 189 | + |
| 190 | + NWNX_PushArgumentInt(NWNX_Snapshot, sFunc, nSnapshotID); |
| 191 | + NWNX_PushArgumentObject(NWNX_Snapshot, sFunc, oTarget); |
| 192 | + NWNX_CallFunction(NWNX_Snapshot, sFunc); |
| 193 | +} |
| 194 | + |
| 195 | +void NWNX_Snapshot_AddFilter(int nSnapshotID, struct NWNX_Snapshot_Filter strFilter) |
| 196 | +{ |
| 197 | + string sFunc = "AddFilter"; |
| 198 | + |
| 199 | + NWNX_PushArgumentObject(NWNX_Snapshot, sFunc, strFilter.oParam2); |
| 200 | + NWNX_PushArgumentObject(NWNX_Snapshot, sFunc, strFilter.oParam1); |
| 201 | + NWNX_PushArgumentFloat(NWNX_Snapshot, sFunc, strFilter.fParam2); |
| 202 | + NWNX_PushArgumentFloat(NWNX_Snapshot, sFunc, strFilter.fParam1); |
| 203 | + NWNX_PushArgumentString(NWNX_Snapshot, sFunc, strFilter.sParam2); |
| 204 | + NWNX_PushArgumentString(NWNX_Snapshot, sFunc, strFilter.sParam1); |
| 205 | + NWNX_PushArgumentInt(NWNX_Snapshot, sFunc, strFilter.nParam2); |
| 206 | + NWNX_PushArgumentInt(NWNX_Snapshot, sFunc, strFilter.nParam1); |
| 207 | + NWNX_PushArgumentInt(NWNX_Snapshot, sFunc, strFilter.bInvert); |
| 208 | + NWNX_PushArgumentInt(NWNX_Snapshot, sFunc, strFilter.nComparison); |
| 209 | + NWNX_PushArgumentInt(NWNX_Snapshot, sFunc, strFilter.nSubtype); |
| 210 | + NWNX_PushArgumentInt(NWNX_Snapshot, sFunc, strFilter.nType); |
| 211 | + NWNX_PushArgumentInt(NWNX_Snapshot, sFunc, nSnapshotID); |
| 212 | + NWNX_CallFunction(NWNX_Snapshot, sFunc); |
| 213 | +} |
| 214 | + |
| 215 | +void NWNX_Snapshot_ClearFilters(int nSnapshotID) |
| 216 | +{ |
| 217 | + string sFunc = "ClearFilters"; |
| 218 | + |
| 219 | + NWNX_PushArgumentInt(NWNX_Snapshot, sFunc, nSnapshotID); |
| 220 | + NWNX_CallFunction(NWNX_Snapshot, sFunc); |
| 221 | +} |
0 commit comments