bool BG_InitWeaponStats(void) { void *GP2, *topGroup, *topSubs; GP2 = trap_GP_ParseFile("ext_data/sof2.wpn", true, false); if (!GP2) { return false; } topGroup = trap_GP_GetBaseParseGroup(GP2); topSubs = trap_GPG_GetSubGroups(topGroup); while(topSubs) { char name[256]; trap_GPG_GetName(topSubs, name); if (strcmp(name, "weapon") == 0) { trap_GPG_FindPairValue(topSubs, "name", "", name); for(int i=0;i<WP_NUM_WEAPONS;i++) { if (strcmp(bg_weaponNames[i], name) == 0) { BG_ParseWeaponStats((weapon_t)i, topSubs); break; } } } topSubs = trap_GPG_GetNext(topSubs); } trap_GP_Delete(&GP2); return true; }
static qboolean BG_ParseWeaponFile ( const char *weaponFilePath ) { cJSON *json = NULL; cJSON *jsonNode = NULL; char error[MAX_STRING_CHARS]; const char *str = NULL; int weapon; int i; char weaponFileData[MAX_WEAPON_FILE_LENGTH]; fileHandle_t f; int fileLen = strap_FS_FOpenFile (weaponFilePath, &f, FS_READ); weaponData_t weaponData; fmLoadCounter = 0; if ( !f || fileLen == -1 ) { Com_Printf (S_COLOR_RED "%s: failed to read the weapon file. File is unreadable or is empty.\n", weaponFilePath); return qfalse; } if ( (fileLen + 1) >= MAX_WEAPON_FILE_LENGTH ) { trap_FS_FCloseFile (f); Com_Printf (S_COLOR_RED "%s: file too big (%d bytes, maximum is %d).\n", weaponFilePath, fileLen, MAX_WEAPON_FILE_LENGTH - 1); return qfalse; } strap_FS_Read (&weaponFileData, fileLen, f); weaponFileData[fileLen] = '\0'; strap_FS_FCloseFile (f); json = cJSON_ParsePooled (weaponFileData, error, sizeof (error)); if ( json == NULL ) { Com_Printf (S_COLOR_RED "%s: %s\n", weaponFilePath, error); return qfalse; } BG_InitializeWeaponData (&weaponData); ReadString (json, "classname", weaponData.classname, sizeof (weaponData.classname)); jsonNode = cJSON_GetObjectItem (json, "type"); str = cJSON_ToString (jsonNode); weapon = GetIDForString (WPTable, str); weaponData.weaponBaseIndex = weapon; jsonNode = cJSON_GetObjectItem (json, "variation"); weapon = cJSON_ToNumber (jsonNode); weaponData.weaponModIndex = weapon; jsonNode = cJSON_GetObjectItem (json, "stats"); BG_ParseWeaponStats (&weaponData, jsonNode); weaponData.numFiringModes = 0; for(i = 0; i < MAX_FIREMODES; i++) { jsonNode = cJSON_GetObjectItem (json, va("firemode%i", i)); if(jsonNode != NULL) { BG_ParseWeaponFireMode (&weaponData.firemodes[i], jsonNode); weaponData.numFiringModes++; } } // Old stuff for when we had primary/alt attacks --eez /*jsonNode = cJSON_GetObjectItem (json, "primaryattack"); BG_ParseWeaponFireMode (&weaponData.firemodes[0], jsonNode); jsonNode = cJSON_GetObjectItem (json, "secondaryattack"); if ( jsonNode != NULL ) { weaponData.hasSecondary = 1; BG_ParseWeaponFireMode (&weaponData.firemodes[1], jsonNode); }*/ jsonNode = cJSON_GetObjectItem (json, "playeranims"); BG_ParseWeaponPlayerAnimations (&weaponData, jsonNode); jsonNode = cJSON_GetObjectItem (json, "name"); str = cJSON_ToString (jsonNode); Q_strncpyz (weaponData.displayName, str, sizeof (weaponData.displayName)); #ifdef CGAME // TODO: Maybe we can turn this into a loop somehow? It's just turning into a stupidly long list. jsonNode = cJSON_GetObjectItem (json, "weaponanims"); // TODO jsonNode = cJSON_GetObjectItem (json, "description"); str = cJSON_ToString (jsonNode); Q_strncpyz (weaponData.visuals.description, str, sizeof (weaponData.visuals.description)); jsonNode = cJSON_GetObjectItem (json, "visual"); BG_ParseVisuals (&weaponData, jsonNode); #endif /*if ( weaponData.zoomType != ZOOM_NONE ) { // If we have zoom mode, then copy over the data from the primary to the secondary // so it's as if we haven't changed fire modes at all! Ingenious! (And also temporary) weaponData.firemodes[1] = weaponData.firemodes[0]; }*/ BG_AddWeaponData (&weaponData); cJSON_Delete (json); return qtrue; }