Exemplo n.º 1
0
/*
============================
JKG_ParseJetpackMovement

Parses the "movement" block of a jetpack.
============================
*/
static void JKG_ParseJetpackMovement(cJSON* jsonNode, jetpackData_t& jetpackData) {
	cJSON* child;

	child = cJSON_GetObjectItem(jsonNode, "thrustAllowed");
	jetpackData.move.thrustAllowed = cJSON_ToBooleanOpt(child, true);

	child = cJSON_GetObjectItem(jsonNode, "fwdThrustAllowed");
	jetpackData.move.fwdThrustAllowed = cJSON_ToBooleanOpt(child, true);

	child = cJSON_GetObjectItem(jsonNode, "loadBearingAllowed");
	jetpackData.move.loadBearingAllowed = cJSON_ToBooleanOpt(child, false);
	
	child = cJSON_GetObjectItem(jsonNode, "hoverGravity");
	jetpackData.move.hoverGravity = cJSON_ToNumberOpt(child, -1.0);

	child = cJSON_GetObjectItem(jsonNode, "forwardMove");
	jetpackData.move.forwardMove = cJSON_ToNumberOpt(child, 1.0);

	child = cJSON_GetObjectItem(jsonNode, "backMove");
	jetpackData.move.backMove = cJSON_ToNumberOpt(child, 1.0);

	child = cJSON_GetObjectItem(jsonNode, "sideMove");
	jetpackData.move.sideMove = cJSON_ToNumberOpt(child, 1.0);

	child = cJSON_GetObjectItem(jsonNode, "downMove");
	jetpackData.move.downMove = cJSON_ToNumberOpt(child, 1.0);

	child = cJSON_GetObjectItem(jsonNode, "thrustFwd");
	jetpackData.move.thrustFwd = cJSON_ToNumberOpt(child, 1.0);

	child = cJSON_GetObjectItem(jsonNode, "thrustBack");
	jetpackData.move.thrustBack = cJSON_ToNumberOpt(child, 1.0);

	child = cJSON_GetObjectItem(jsonNode, "thrustSide");
	jetpackData.move.thrustSide = cJSON_ToNumberOpt(child, 1.0);

	child = cJSON_GetObjectItem(jsonNode, "thrustUp");
	jetpackData.move.thrustUp = cJSON_ToNumberOpt(child, 1.0);

	child = cJSON_GetObjectItem(jsonNode, "fwdThrustAmt");
	jetpackData.move.fwdThrustAmt = cJSON_ToNumberOpt(child, 2.0);
}
Exemplo n.º 2
0
static int GLua_JSON_ToBooleanOpt( 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_ToBooleanOpt( node, lua_toboolean( L, 2 ) ) );

	return 1;
}
Exemplo n.º 3
0
static void JKG_ParseBuffOverrides(ammo_t* ammo, cJSON* json, const char* nodeName)
{
	cJSON* child = cJSON_GetObjectItem(json, nodeName);
	if (child == nullptr)
	{
		return;
	}

	int elemCount = cJSON_GetArraySize(child);
	if (elemCount <= 0)
	{
		return; // not actually an array
	}

	// Iterate through each buff array item
	for (int i = 0; i < elemCount; i++)
	{
		cJSON* buff = cJSON_GetArrayItem(child, i);
		complexAmmoBuffOverride buffOverride = { 0 };

		cJSON* buffChild = cJSON_GetObjectItem(buff, "buff");
		if (buffChild == nullptr)
		{	// JSON doesn't contain a "buff" field. Continue.
			continue;
		}

		buffOverride.buff = JKG_ResolveBuffName(cJSON_ToStringOpt(buffChild, ""));
		if (buffOverride.buff < 0)
		{	// A buff by this name doesn't exist, continue.
			continue;
		}

		buffChild = cJSON_GetObjectItem(buff, "remove");
		buffOverride.bRemove = cJSON_ToBooleanOpt(buffChild, qfalse);

		buffChild = cJSON_GetObjectItem(buff, "addbuff");
		buffOverride.bAddBuff = cJSON_ToBooleanOpt(buffChild, qfalse);

		buffChild = cJSON_GetObjectItem(buff, "duration");
		if (buffChild != nullptr)
		{
			cJSON* childProps;

			childProps = cJSON_GetObjectItem(buffChild, "add");
			if (childProps != nullptr)
			{
				buffOverride.bAddDuration = qtrue;
				buffOverride.addDuration = cJSON_ToInteger(childProps);
			}

			childProps = cJSON_GetObjectItem(buffChild, "multiply");
			if (childProps != nullptr)
			{
				buffOverride.bMultiplyDuration = qtrue;
				buffOverride.multiplyDuration = cJSON_ToNumber(childProps);
			}

			childProps = cJSON_GetObjectItem(buffChild, "set");
			if (childProps != nullptr)
			{
				buffOverride.bSetDuration = qtrue;
				buffOverride.setDuration = cJSON_ToInteger(childProps);
			}
		}

		buffChild = cJSON_GetObjectItem(buff, "intensity");
		if (buffChild != nullptr)
		{
			cJSON* childProps;

			childProps = cJSON_GetObjectItem(buffChild, "add");
			if (childProps != nullptr)
			{
				buffOverride.bAddIntensity = qtrue;
				buffOverride.addIntensity = cJSON_ToNumber(childProps);
			}

			childProps = cJSON_GetObjectItem(buffChild, "multiply");
			if (childProps != nullptr)
			{
				buffOverride.bMultiplyIntensity = qtrue;
				buffOverride.multiplyIntensity = cJSON_ToNumber(childProps);
			}

			childProps = cJSON_GetObjectItem(buffChild, "set");
			if (childProps != nullptr)
			{
				buffOverride.bSetIntensity = qtrue;
				buffOverride.setIntensity = cJSON_ToNumber(childProps);
			}
		}

		// Add the override to the list of buff overrides
		ammo->overrides.buffs.emplace_back(buffOverride);
	}
}
static void BG_ParseWeaponFireMode ( weaponFireModeStats_t *fireModeStats, cJSON *fireModeNode )
{
    cJSON *node;
    const char *str = NULL;
    
    if ( fireModeNode == NULL )
    {
        return;
    }
    
    node = cJSON_GetObjectItem (fireModeNode, "ammo");
    str = cJSON_ToString (node);
    if ( str && str[0] )
    {
        fireModeStats->ammo = BG_GetAmmo (str);
    }

    node = cJSON_GetObjectItem (fireModeNode, "damage");
#ifdef QAGAME
    BG_ParseDamage (fireModeStats, node, qfalse);
    
    node = cJSON_GetObjectItem (fireModeNode, "secondarydamage");
    BG_ParseDamage (fireModeStats, node, qtrue);
#else
	fireModeStats->baseDamage = cJSON_ToInteger (node);
#endif
    
    node = cJSON_GetObjectItem (fireModeNode, "grenade");
    fireModeStats->isGrenade = (qboolean)cJSON_ToBooleanOpt (node, 0);

	node = cJSON_GetObjectItem (fireModeNode, "grenadeBounces");
    fireModeStats->grenadeBounces = (qboolean)cJSON_ToBooleanOpt (node, 1);

	node = cJSON_GetObjectItem (fireModeNode, "grenadeBounceDMG");
    fireModeStats->grenadeBounceDMG = (char)cJSON_ToIntegerOpt (node, 10);
    
    node = cJSON_GetObjectItem (fireModeNode, "ballistic");
    fireModeStats->applyGravity = (char)cJSON_ToBooleanOpt (node, 0);
    
    node = cJSON_GetObjectItem (fireModeNode, "bounces");
    fireModeStats->bounceCount = (char)cJSON_ToIntegerOpt (node, 0);
    
    node = cJSON_GetObjectItem (fireModeNode, "hitscan");
    fireModeStats->hitscan = (char)cJSON_ToBooleanOpt (node, 0);
    
    node = cJSON_GetObjectItem (fireModeNode, "projectiles");
    fireModeStats->shotCount = (char)cJSON_ToIntegerOpt (node, 0);
    
    node = cJSON_GetObjectItem (fireModeNode, "collisionsize");
    fireModeStats->boxSize = (float)cJSON_ToNumberOpt (node, 0.0);
    
    node = cJSON_GetObjectItem (fireModeNode, "maxchargetime");
    fireModeStats->chargeMaximum = (short)cJSON_ToIntegerOpt (node, 0);
    
    node = cJSON_GetObjectItem (fireModeNode, "chargedamage");
    fireModeStats->chargeMultiplier = (float)cJSON_ToNumberOpt (node, 0);
    
    node = cJSON_GetObjectItem (fireModeNode, "chargedelay");
    fireModeStats->chargeTime = (short)cJSON_ToIntegerOpt (node, 0);
    
    node = cJSON_GetObjectItem (fireModeNode, "ammocost");
    fireModeStats->cost = (char)cJSON_ToIntegerOpt (node, 0);
    
    node = cJSON_GetObjectItem (fireModeNode, "firingtype");
    BG_ParseFireModeFiringType (fireModeStats, cJSON_ToStringOpt (node, "auto"));
    
    // 0 means fully automatic, otherwise one burst will fire weapon n times.
    node = cJSON_GetObjectItem (fireModeNode, "shotsperburst");
    fireModeStats->shotsPerBurst = (char)cJSON_ToIntegerOpt (node, 0);
    
    // 0 means infinite delay (semi-automatic), otherwise n milliseconds between
    // rounds in a burst.
    node = cJSON_GetObjectItem (fireModeNode, "burstshotdelay");
    fireModeStats->burstFireDelay = (short)cJSON_ToIntegerOpt (node, 0);
    
    node = cJSON_GetObjectItem (fireModeNode, "firedelay");
    fireModeStats->delay = (short)cJSON_ToIntegerOpt (node, 0);
    
    node = cJSON_GetObjectItem (fireModeNode, "range");
    fireModeStats->range = (float)cJSON_ToIntegerOpt (node, WPR_M);
    
    node = cJSON_GetObjectItem (fireModeNode, "splashrange");
    fireModeStats->rangeSplash = (float)cJSON_ToNumberOpt (node, 0.0);
    
    node = cJSON_GetObjectItem (fireModeNode, "recoil");
    fireModeStats->recoil = (float)cJSON_ToNumberOpt (node, 0.0);
    
    //node = cJSON_GetObjectItem (fireModeNode, "spread");
    //fireModeStats->spread = (float)cJSON_ToNumberOpt (node, 0.0);

	node = cJSON_GetObjectItem (fireModeNode, "accuracy");
	if( node )
	{
		cJSON *child = NULL;

		child = cJSON_GetObjectItem( node, "accuracyRating" );
		fireModeStats->weaponAccuracy.accuracyRating = (vec_t)cJSON_ToNumberOpt( child, 32.0f );

		child = cJSON_GetObjectItem( node, "crouchModifier" );
		fireModeStats->weaponAccuracy.crouchModifier = (float)cJSON_ToNumberOpt( child, 0.8f );

		child = cJSON_GetObjectItem( node, "runModifier" );
		fireModeStats->weaponAccuracy.runModifier = (float)cJSON_ToNumberOpt( child, 2.0f );

		child = cJSON_GetObjectItem( node, "sightsModifier" );
		fireModeStats->weaponAccuracy.sightsModifier = (float)cJSON_ToNumberOpt( child, 0.2f );

		child = cJSON_GetObjectItem( node, "walkModifier" );
		fireModeStats->weaponAccuracy.walkModifier = (float)cJSON_ToNumberOpt( child, 1.55f );

		child = cJSON_GetObjectItem( node, "inAirModifier" );
		fireModeStats->weaponAccuracy.inAirModifier = (float)cJSON_ToNumberOpt( child, 3.0f );

		child = cJSON_GetObjectItem( node, "accuracyRatingPerShot" );
		fireModeStats->weaponAccuracy.accuracyRatingPerShot = (int)cJSON_ToNumberOpt( child, 2 );

		child = cJSON_GetObjectItem( node, "msToDrainAccuracy" );
		fireModeStats->weaponAccuracy.msToDrainAccuracy = (int)cJSON_ToNumberOpt( child, 200 );

		child = cJSON_GetObjectItem( node, "maxAccuracyAdd" );
		fireModeStats->weaponAccuracy.maxAccuracyAdd = (int)cJSON_ToNumberOpt( child, 128 );
	}
	else
	{
		fireModeStats->weaponAccuracy.accuracyRating = 32.0f;
		fireModeStats->weaponAccuracy.crouchModifier = 0.8f;
		fireModeStats->weaponAccuracy.runModifier = 2.0f;
		fireModeStats->weaponAccuracy.sightsModifier = 0.2f;
		fireModeStats->weaponAccuracy.walkModifier = 1.55f;
		fireModeStats->weaponAccuracy.inAirModifier = 3.0f;
		fireModeStats->weaponAccuracy.accuracyRatingPerShot = 2;
		fireModeStats->weaponAccuracy.msToDrainAccuracy = 200;
		fireModeStats->weaponAccuracy.maxAccuracyAdd = 128;
	}
    
    node = cJSON_GetObjectItem (fireModeNode, "projectilespeed");
    fireModeStats->speed = (float)cJSON_ToNumberOpt (node, 0.0);
    
    node = cJSON_GetObjectItem (fireModeNode, "projectileclass");
    str = cJSON_ToStringOpt (node, "unknown_proj");
    Q_strncpyz (fireModeStats->weaponClass, str, sizeof (fireModeStats->weaponClass));
    
    node = cJSON_GetObjectItem (fireModeNode, "meansofdeath");
    str = cJSON_ToStringOpt (node, "MOD_UNKNOWN");
    fireModeStats->weaponMOD = GetIDForString (MODTable, str);
    
    node = cJSON_GetObjectItem (fireModeNode, "splashmeansofdeath");
    str = cJSON_ToStringOpt (node, "MOD_UNKNOWN");
    fireModeStats->weaponSplashMOD = GetIDForString (MODTable, str);
}