示例#1
0
void BulletAndWeaponInitialize(
	BulletClasses *b, GunClasses *g, const char *bpath, const char *gpath)
{
	BulletInitialize(b);

	FILE *bf = NULL;
	FILE *gf = NULL;
	json_t *broot = NULL;
	json_t *groot = NULL;
	enum json_error e;

	// 2-pass bullet loading will free root for us
	bool freeBRoot = true;
	bf = fopen(bpath, "r");
	if (bf == NULL)
	{
		printf("Error: cannot load bullets file %s\n", bpath);
		goto bail;
	}
	e = json_stream_parse(bf, &broot);
	if (e != JSON_OK)
	{
		printf("Error parsing bullets file %s [error %d]\n", bpath, (int)e);
		goto bail;
	}
	BulletLoadJSON(b, &b->Classes, broot);

	WeaponInitialize(g);
	gf = fopen(gpath, "r");
	if (gf == NULL)
	{
		printf("Error: cannot load guns file %s\n", gpath);
		goto bail;
	}
	e = json_stream_parse(gf, &groot);
	if (e != JSON_OK)
	{
		printf("Error parsing guns file %s [error %d]\n", gpath, (int)e);
		goto bail;
	}
	WeaponLoadJSON(g, &g->Guns, groot);

	BulletLoadWeapons(b);
	freeBRoot = false;

bail:
	if (bf)
	{
		fclose(bf);
	}
	if (gf)
	{
		fclose(gf);
	}
	if (freeBRoot)
	{
		json_free_value(&broot);
	}
	json_free_value(&groot);
}
示例#2
0
int MapNewLoadArchive(const char *filename, CampaignSetting *c)
{
	LOG(LM_MAP, LL_DEBUG, "Loading archive map %s", filename);
	int err = 0;
	json_t *root = ReadArchiveJSON(filename, "campaign.json");
	if (root == NULL)
	{
		err = -1;
		goto bail;
	}
	int version;
	LoadInt(&version, root, "Version");
	if (version > MAP_VERSION || version <= 2)
	{
		err = -1;
		goto bail;
	}
	MapNewLoadCampaignJSON(root, c);
	json_free_value(&root);


	// Unload previous custom data
	SoundClear(&gSoundDevice.customSounds);
	PicManagerClearCustom(&gPicManager);
	ParticleClassesClear(&gParticleClasses.CustomClasses);
	AmmoClassesClear(&gAmmo.CustomAmmo);
	CharacterClassesClear(&gCharacterClasses.CustomClasses);
	BulletClassesClear(&gBulletClasses.CustomClasses);
	WeaponClassesClear(&gGunDescriptions.CustomGuns);
	PickupClassesClear(&gPickupClasses.CustomClasses);
	MapObjectsClear(&gMapObjects.CustomClasses);

	// Load any custom data
	LoadArchiveSounds(&gSoundDevice, filename, "sounds");

	LoadArchivePics(&gPicManager, filename, "graphics");

	root = ReadArchiveJSON(filename, "particles.json");
	if (root != NULL)
	{
		ParticleClassesLoadJSON(&gParticleClasses.CustomClasses, root);
	}

	root = ReadArchiveJSON(filename, "character_classes.json");
	if (root != NULL)
	{
		CharacterClassesLoadJSON(
			&gCharacterClasses.CustomClasses, root);
	}

	root = ReadArchiveJSON(filename, "bullets.json");
	if (root != NULL)
	{
		BulletLoadJSON(
			&gBulletClasses, &gBulletClasses.CustomClasses, root);
	}

	root = ReadArchiveJSON(filename, "ammo.json");
	if (root != NULL)
	{
		AmmoLoadJSON(&gAmmo.CustomAmmo, root);
		json_free_value(&root);
	}

	root = ReadArchiveJSON(filename, "guns.json");
	if (root != NULL)
	{
		WeaponLoadJSON(
			&gGunDescriptions, &gGunDescriptions.CustomGuns, root);
		json_free_value(&root);
	}

	BulletLoadWeapons(&gBulletClasses);

	root = ReadArchiveJSON(filename, "pickups.json");
	if (root != NULL)
	{
		PickupClassesLoadJSON(&gPickupClasses.CustomClasses, root);
	}
	PickupClassesLoadAmmo(&gPickupClasses.CustomClasses, &gAmmo.CustomAmmo);
	PickupClassesLoadGuns(
		&gPickupClasses.CustomClasses, &gGunDescriptions.CustomGuns);

	root = ReadArchiveJSON(filename, "map_objects.json");
	if (root != NULL)
	{
		MapObjectsLoadJSON(&gMapObjects.CustomClasses, root);
	}
	MapObjectsLoadAmmoAndGunSpawners(&gMapObjects, &gAmmo, &gGunDescriptions);


	root = ReadArchiveJSON(filename, "missions.json");
	if (root == NULL)
	{
		err = -1;
		goto bail;
	}
	LoadMissions(
		&c->Missions, json_find_first_label(root, "Missions")->child, version);
	json_free_value(&root);

	// Note: some campaigns don't have characters (e.g. dogfights)
	root = ReadArchiveJSON(filename, "characters.json");
	if (root != NULL)
	{
		LoadCharacters(
			&c->characters, json_find_first_label(root, "Characters")->child,
			version);
	}

bail:
	json_free_value(&root);
	return err;
}