Пример #1
0
int qlua_getclientinfo(lua_State *L) {
	centity_t	*luaentity;
	clientInfo_t	*ci;

	luaL_checktype(L,1,LUA_TUSERDATA);

	luaentity = lua_toentity(L,1);
	if(luaentity != NULL) {
		ci = &cgs.clientinfo[ luaentity->currentState.clientNum ];
		if(cg.snap && cg.snap->ps.commandTime != 0) {
			if(luaentity->currentState.clientNum == cg.clientNum) {
				ci->health = cg.snap->ps.stats[STAT_HEALTH];
				ci->armor = cg.snap->ps.stats[STAT_ARMOR];
				ci->curWeapon = cg.snap->ps.weapon;
#ifndef LUA_WEAPONS
				ci->ammo = cg.snap->ps.ammo[ci->curWeapon];
#else
				ci->ammo = BG_GetAmmo(cg.snap->ps.clientNum, ci->curWeapon);
#endif
			} else {
				ci->health = luaentity->currentState.health;
			}
		}
		CG_PushClientInfoTab(L,ci);
	}
	return 1;
}
//=========================================================
// BG_ParseWeaponStats
//---------------------------------------------------------
// Description:
// Parses the stats block of a weapons file.
//=========================================================
static void BG_ParseWeaponStats ( weaponData_t *weaponData, cJSON *statsNode )
{
    cJSON *node;
    const char *flags[4];
    const char *ammo;
    
    if ( statsNode == NULL )
    {
        return;
    }

    node = cJSON_GetObjectItem (statsNode, "slot");
    weaponData->weaponSlot = (unsigned char)cJSON_ToIntegerOpt (node, 0);

    node = cJSON_GetObjectItem (statsNode, "reloadtime");
    weaponData->weaponReloadTime = (unsigned short)cJSON_ToIntegerOpt (node, 0);

    node = cJSON_GetObjectItem (statsNode, "ammoIndex");
    ammo = cJSON_ToStringOpt (node, "AMMO_NONE");
	weaponData->ammoIndex = BG_GetAmmo(ammo)->ammoIndex;

	node = cJSON_GetObjectItem (statsNode, "ammoOnSpawn");
	weaponData->ammoOnSpawn = (unsigned int)cJSON_ToIntegerOpt (node, ((weaponData->ammoIndex < AMMO_ROCKETS) ? 400 : ((weaponData->ammoIndex != AMMO_ROCKETS) ? 444 : 10)));	// Gives 300 ammo for non-explosives

	node = cJSON_GetObjectItem (statsNode, "ammoOnPickup");
	weaponData->ammoOnPickup = (unsigned int)cJSON_ToIntegerOpt (node, ((weaponData->ammoIndex < AMMO_ROCKETS) ? 20 : 1));	// Gives 20 ammo for non-explosives

	node = cJSON_GetObjectItem (statsNode, "clipSize");
	weaponData->clipSize = (unsigned int)cJSON_ToIntegerOpt (node, 0);

    node = cJSON_GetObjectItem (statsNode, "flags");
    if ( node != NULL )
    {
        int numFlags = cJSON_ReadStringArray (node, 4, flags);
        int i;

        for ( i = 0; i < numFlags; i++ )
        {
            BG_ParseWeaponStatsFlags (weaponData, flags[i]);
        }
    }

    node = cJSON_GetObjectItem (statsNode, "speed");
    weaponData->speedModifier = (float)cJSON_ToNumberOpt (node, 1.0);
        
    node = cJSON_GetObjectItem (statsNode, "reloadmodifier");
    weaponData->reloadModifier = (float)cJSON_ToNumberOpt (node, 1.0);
    
    node = cJSON_GetObjectItem (statsNode, "startzoomfov");
    weaponData->startZoomFov = (float)cJSON_ToNumberOpt (node, 50.0);
    
    node = cJSON_GetObjectItem (statsNode, "endzoomfov");
    weaponData->endZoomFov = (float)cJSON_ToNumberOpt (node, weaponData->zoomType == ZOOM_TOGGLE ? weaponData->startZoomFov : 5.0);
    
    node = cJSON_GetObjectItem (statsNode, "zoomtime");
    weaponData->zoomTime = cJSON_ToIntegerOpt (node, 2000);

	node = cJSON_GetObjectItem (statsNode, "ironsightsTime");
	weaponData->ironsightsTime = cJSON_ToIntegerOpt (node, IRONSIGHTS_TIME);
}
Пример #3
0
/*
========================
BG_InitializeAmmo

Initializes the ammo subsystem.
========================
*/
void BG_InitializeAmmo ( void )
{
	char ammoFiles[AMMO_NAMEBUFFER] {0};
	const char* ammo;
	const char* ammoDir = "ext_data/ammo/";
	int failed = 0;
	int numFiles;

	numFiles = trap->FS_GetFileList(ammoDir, ".ammo", ammoFiles, sizeof(ammoFiles));
	ammo = ammoFiles;

	Com_Printf("------- Ammo -------\n");

	for (int i = 0; i < numFiles; i++) {
		if (!JKG_LoadAmmo(ammo, ammoDir)) {
			failed++;
			ammo += strlen(ammo) + 1;
			continue;
		}

		ammo += strlen(ammo) + 1;
	}

	Com_Printf("Ammo: %d successful, %d failed.\n", numAmmoLoaded, failed);
	Com_Printf("-------------------------------------\n");

	// Link up all of the substitutes
	for (int i = 0; i < numAmmoLoaded; i++) {
		ammoTable[i].pSub = BG_GetAmmo(ammoTable[i].substitute);
	}
}
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);
}