コード例 #1
0
ファイル: ammo.c プロジェクト: cxong/cdogs-sdl
// TODO: use map structure?
Ammo *StrAmmo(const char *s)
{
	return AmmoGetById(&gAmmo, StrAmmoId(s));
}
コード例 #2
0
ファイル: weapon.c プロジェクト: depoorterp/cdogs-sdl
static void LoadGunDescription(
	GunDescription *g, json_t *node, const GunDescription *defaultGun)
{
	memset(g, 0, sizeof *g);
	g->AmmoId = -1;
	if (defaultGun)
	{
		memcpy(g, defaultGun, sizeof *g);
		if (defaultGun->name)
		{
			CSTRDUP(g->name, defaultGun->name);
		}
		if (defaultGun->Description)
		{
			CSTRDUP(g->Description, defaultGun->Description);
		}
		g->MuzzleHeight /= Z_FACTOR;
	}
	char *tmp;

	if (json_find_first_label(node, "Pic"))
	{
		tmp = GetString(node, "Pic");
		if (strcmp(tmp, "blaster") == 0)
		{
			g->pic = GUNPIC_BLASTER;
		}
		else if (strcmp(tmp, "knife") == 0)
		{
			g->pic = GUNPIC_KNIFE;
		}
		else
		{
			g->pic = -1;
		}
		CFREE(tmp);
	}

	if (json_find_first_label(node, "Icon"))
	{
		tmp = GetString(node, "Icon");
		g->Icon = PicManagerGet(&gPicManager, tmp, -1);
		CFREE(tmp);
	}

	g->name = GetString(node, "Name");

	if (json_find_first_label(node, "Description"))
	{
		g->Description = GetString(node, "Description");
	}

	if (json_find_first_label(node, "Bullet"))
	{
		tmp = GetString(node, "Bullet");
		g->Bullet = StrBulletClass(tmp);
		CFREE(tmp);
	}

	if (json_find_first_label(node, "Ammo"))
	{
		tmp = GetString(node, "Ammo");
		g->AmmoId = StrAmmoId(tmp);
		CFREE(tmp);
	}

	LoadInt(&g->Cost, node, "Cost");

	LoadInt(&g->Lock, node, "Lock");

	LoadInt(&g->ReloadLead, node, "ReloadLead");

	LoadSoundFromNode(&g->Sound, node, "Sound");
	LoadSoundFromNode(&g->ReloadSound, node, "ReloadSound");
	LoadSoundFromNode(&g->SwitchSound, node, "SwitchSound");

	LoadInt(&g->SoundLockLength, node, "SoundLockLength");

	LoadDouble(&g->Recoil, node, "Recoil");

	LoadInt(&g->Spread.Count, node, "SpreadCount");
	LoadDouble(&g->Spread.Width, node, "SpreadWidth");
	LoadDouble(&g->AngleOffset, node, "AngleOffset");

	LoadInt(&g->MuzzleHeight, node, "MuzzleHeight");
	g->MuzzleHeight *= Z_FACTOR;
	if (json_find_first_label(node, "Elevation"))
	{
		LoadInt(&g->ElevationLow, node, "Elevation");
		g->ElevationHigh = g->ElevationLow;
	}
	LoadInt(&g->ElevationLow, node, "ElevationLow");
	LoadInt(&g->ElevationHigh, node, "ElevationHigh");
	g->ElevationLow = MIN(g->ElevationLow, g->ElevationHigh);
	g->ElevationHigh = MAX(g->ElevationLow, g->ElevationHigh);
	if (json_find_first_label(node, "MuzzleFlashParticle"))
	{
		tmp = GetString(node, "MuzzleFlashParticle");
		g->MuzzleFlash = StrParticleClass(&gParticleClasses, tmp);
		CFREE(tmp);
	}

	if (json_find_first_label(node, "Brass"))
	{
		tmp = GetString(node, "Brass");
		g->Brass = StrParticleClass(&gParticleClasses, tmp);
		CFREE(tmp);
	}

	LoadBool(&g->CanShoot, node, "CanShoot");

	LoadInt(&g->ShakeAmount, node, "ShakeAmount");

	g->IsRealGun = true;
}