static int GLua_JSON_IsNumber( lua_State *L ) { // Check and make sure we're using a valid index if( !FJSON_ValidateNode( L, 1 ) ) { lua_pushnil(L); return 1; } cJSON *node = FJSON_RetrieveNode( L, 1 ); lua_pushboolean( L, cJSON_IsNumber( node ) ); return 1; }
static CC *prefixFromJSON(const cJSON *params, char *err) { cJSON *mml_item = cJSON_GetObjectItem(params, "maxMessageLength"); if (!cJSON_IsNumber(mml_item)) { strcpy(err, "maxMessageLength must be a number"); return NULL; } cJSON *subcond_item = cJSON_GetObjectItem(params, "subfulfillment"); CC *sub = cc_conditionFromJSON(subcond_item, err); if (!sub) { return NULL; } CC *cond = cc_new(CC_Prefix); cond->maxMessageLength = (unsigned long) mml_item->valuedouble; cond->subcondition = sub; if (!jsonGetBase64(params, "prefix", err, &cond->prefix, &cond->prefixLength)) { cc_free(cond); return NULL; } return cond; }
static void BG_ParseDamage ( weaponFireModeStats_t *fireModeStats, cJSON *damageNode, qboolean secondary ) { if ( !damageNode ) { return; } if ( !secondary && cJSON_IsNumber (damageNode) ) { fireModeStats->baseDamage = (short)cJSON_ToIntegerOpt (damageNode, 0); } else if ( cJSON_IsObject (damageNode) ) { damageSettings_t darea; cJSON *node = NULL; qhandle_t areaHandle = 0; memset (&darea, 0, sizeof (darea)); node = cJSON_GetObjectItem (damageNode, "damageradius"); if ( node ) { cJSON *child = NULL; const char *s = NULL; darea.radial = qtrue; child = cJSON_GetObjectItem (node, "start"); darea.radiusParams.startRadius = (float)cJSON_ToNumber (child); child = cJSON_GetObjectItem (node, "end"); darea.radiusParams.endRadius = (float)cJSON_ToNumber (child); child = cJSON_GetObjectItem (node, "parm"); darea.radiusParams.generic1 = cJSON_ToInteger (child); child = cJSON_GetObjectItem (node, "falloff"); s = cJSON_ToStringOpt (child, "constant"); if ( Q_stricmp (s, "constant") == 0 ) darea.radiusParams.damageFunc = DF_CONSTANT; else if ( Q_stricmp (s, "linear") == 0 ) darea.radiusParams.damageFunc = DF_LINEAR; else if ( Q_stricmp (s, "gaussian") == 0 ) darea.radiusParams.damageFunc = DF_GAUSSIAN; else { darea.radiusParams.damageFunc = DF_CONSTANT; Com_Printf ("Unknown damage falloff type used: %s. Defaulting to linear falloff.\n", s); } child = cJSON_GetObjectItem (node, "function"); s = cJSON_ToStringOpt (child, "constant"); if ( Q_stricmp (s, "linear") == 0 ) darea.radiusParams.radiusFunc = RF_LINEAR; else if ( Q_stricmp (s, "nonlinear") == 0 ) darea.radiusParams.radiusFunc = RF_NONLINEAR; else if ( Q_stricmp (s, "clamp") == 0 ) darea.radiusParams.radiusFunc = RF_CLAMP; else if ( Q_stricmp (s, "wave") == 0 ) darea.radiusParams.radiusFunc = RF_WAVE; else if ( Q_stricmp (s, "constant") == 0 ) darea.radiusParams.radiusFunc = RF_CONSTANT; else { darea.radiusParams.radiusFunc = RF_CONSTANT; Com_Printf ("Unknown radius function used: %s; Defaulting to constant radius.\n", s); } } node = cJSON_GetObjectItem (damageNode, "duration"); darea.lifetime = cJSON_ToIntegerOpt (node, 0); node = cJSON_GetObjectItem (damageNode, "delay"); darea.delay = cJSON_ToIntegerOpt (node, 0); node = cJSON_GetObjectItem (damageNode, "damage"); darea.damage = cJSON_ToIntegerOpt (node, 0); fireModeStats->baseDamage = darea.damage; node = cJSON_GetObjectItem (damageNode, "damagedelay"); darea.damageDelay = cJSON_ToIntegerOpt (node, 0); node = cJSON_GetObjectItem (damageNode, "penetration"); switch ( cJSON_ToIntegerOpt (node, 0) ) { default: case 0: darea.penetrationType = PT_NONE; break; case 1: darea.penetrationType = PT_SHIELD; break; case 2: darea.penetrationType = PT_SHIELD_ARMOR; break; case 3: darea.penetrationType = PT_SHIELD_ARMOR_BUILDING; break; } node = cJSON_GetObjectItem (damageNode, "damagetype"); if ( node ) { int i = 0; const char *types[NUM_DAMAGE_TYPES]; int numTypes = cJSON_ReadStringArray (node, NUM_DAMAGE_TYPES, types); for ( i = 0; i < numTypes; i++ ) { if ( Q_stricmp (types[i], "annihilate") == 0 ) { int dType = (int)darea.damageType; dType |= (1 << DT_ANNIHILATION); darea.damageType = dType; } else if ( Q_stricmp (types[i], "concussion") == 0 ) { int dType = (int)darea.damageType; dType |= (1 << DT_CONCUSSION); darea.damageType = dType; } else if ( Q_stricmp (types[i], "cut") == 0 ) { int dType = (int)darea.damageType; dType |= (1 << DT_CUT); darea.damageType = dType; } else if ( Q_stricmp (types[i], "disintegrate") == 0 ) { int dType = (int)darea.damageType; dType |= (1 << DT_DISINTEGRATE); darea.damageType = dType; } else if ( Q_stricmp (types[i], "electric") == 0 ) { int dType = (int)darea.damageType; dType |= (1 << DT_ELECTRIC); darea.damageType = dType; } else if ( Q_stricmp (types[i], "explosion") == 0 ) { int dType = (int)darea.damageType; dType |= (1 << DT_EXPLOSION); darea.damageType = dType; } else if ( Q_stricmp (types[i], "fire") == 0 ) { int dType = (int)darea.damageType; dType |= ( 1 << DT_FIRE ); darea.damageType = dType; } else if ( Q_stricmp (types[i], "freeze") == 0 ) { int dType = (int)darea.damageType; dType |= (1 << DT_FREEZE); darea.damageType = dType; } else if ( Q_stricmp (types[i], "implosion") == 0 ) { int dType = (int)darea.damageType; dType |= (1 << DT_IMPLOSION); darea.damageType = dType; } else if ( Q_stricmp (types[i], "stun") == 0 ) { int dType = (int)darea.damageType; dType |= (1 << DT_STUN); darea.damageType = dType; } else if ( Q_stricmp (types[i], "carbonite") == 0 ) { int dType = (int)darea.damageType; dType |= (1 << DT_CARBONITE); darea.damageType = dType; } else { Com_Printf ("Unknown damage type used: %s.\n", types[i]); } } } areaHandle = JKG_RegisterDamageSettings (&darea); if ( !secondary ) { fireModeStats->damageTypeHandle = areaHandle; } else { fireModeStats->secondaryDmgHandle = areaHandle; } } }