char* GetObjectParamString(int iObject, const char* pszParam, const char* pszDefault) { char* pszString = GetObjectParams(iObject); char* pszRet = GetParamString(pszString, pszParam, pszDefault); g_pMalloc->Free(pszString); return pszRet; }
bool GetObjectParamBool(int iObject, const char* pszParam, bool bDefault) { char* params = GetObjectParams(iObject); if (!params) return bDefault; bool bRet = GetParamBool(params, pszParam, bDefault); g_pMalloc->Free(params); return bRet; }
float GetObjectParamFloat(int iObject, const char* pszParam, float fDefault) { char* params = GetObjectParams(iObject); if (!params) return fDefault; float fRet = GetParamFloat(params, pszParam, fDefault); g_pMalloc->Free(params); return fRet; }
int GetObjectParamObject(int iObject, const char* pszParam, int iDefault) { char* params = GetObjectParams(iObject); if (!params) return iDefault; int iRet = GetParamObject(params, pszParam, iDefault); g_pMalloc->Free(params); return iRet; }
void TWBaseScript::init(int time) { char* design_note = GetObjectParams(ObjId()); if(design_note) { debug = get_scriptparam_bool(design_note, "Debug"); if(debug_enabled()) { debug_printf(DL_DEBUG, "Attached %s version %s", Name(), SCRIPT_VERSTRING); debug_printf(DL_DEBUG, "Script debugging enabled"); } g_pMalloc -> Free(design_note); } // Set up randomisation uint seed = std::chrono::system_clock::now().time_since_epoch().count(); randomiser.seed(seed); }
void TWCloudDrift::init(int time) { TWBaseScript::init(time); // Fetch the initial position if needed if(!start_position.Valid()) { fetch_initial_location(); if(debug_enabled()) { const mxs_vector *location = start_position; debug_printf(DL_WARNING, "Initial location: %f, %f, %f", location -> x, location -> y, location -> z); } } // Fetch the contents of the object's design note char *design_note = GetObjectParams(ObjId()); if(!design_note) { debug_printf(DL_WARNING, "No Editor -> Design Note. Doing nothing."); } else { // Nothing can be done if there's no drift setting if(get_scriptparam_floatvec(design_note, "Range", driftrange)) { // Drifts must be positive. Divide by two so the range is relative to the start pos. driftrange.x = fabs(driftrange.x) / 2.0; driftrange.y = fabs(driftrange.y) / 2.0; driftrange.z = fabs(driftrange.z) / 2.0; // And there needs to be actual drift if(driftrange) { const mxs_vector *location = start_position; get_scriptparam_floatvec(design_note, "MaxRate", maxrates, 0.5, 0.5, 0.5); get_scriptparam_floatvec(design_note, "MinRate", minrates, 0.05, 0.05, 0.05); std::string dummy; refresh = get_scriptparam_time(design_note, "Refresh", 1000, dummy); char *facmode = get_scriptparam_string(design_note, "Mode"); if(facmode) { if(!::_stricmp(facmode, "LINEAR")) { factormode = LINEAR; } else if(!::_stricmp(facmode, "LOG")) { factormode = LOGARITHMIC; } g_pMalloc -> Free(facmode); } // Dump the settings for reference if(debug_enabled()) { debug_printf(DL_DEBUG, "Initialised on object. Settings:"); debug_printf(DL_DEBUG, "Initial location: (%.3f, %.3f, %.3f)", location -> x, location -> y, location -> z); debug_printf(DL_DEBUG, "Drift amount: (%.3f, %.3f, %.3f)" , driftrange.x * 2.0, driftrange.y * 2.0, driftrange.z * 2.0); debug_printf(DL_DEBUG, "Minimum rate: (%.3f, %.3f, %.3f)" , minrates.x , minrates.y , minrates.z); debug_printf(DL_DEBUG, "Maximum rate: (%.3f, %.3f, %.3f)" , maxrates.x , maxrates.y , maxrates.z); debug_printf(DL_DEBUG, "Update mode: %d", factormode); debug_printf(DL_DEBUG, "Update rate: %d", refresh); } // Check the velocities and start the refresh timer. check_velocities(time); // All drift values are zero, there's no point in doing anything } else { debug_printf(DL_WARNING, "All Drift values are zero. Doing nothing."); } // Can't do anything if there is no drift information } else { debug_printf(DL_WARNING, "No Drift specified. Doing nothing."); } g_pMalloc -> Free(design_note); } }