예제 #1
0
static void LoadClassicRooms(Mission *m, json_t *roomsNode)
{
	LoadInt(&m->u.Classic.Rooms.Count, roomsNode, "Count");
	LoadInt(&m->u.Classic.Rooms.Min, roomsNode, "Min");
	LoadInt(&m->u.Classic.Rooms.Max, roomsNode, "Max");
	LoadBool(&m->u.Classic.Rooms.Edge, roomsNode, "Edge");
	LoadBool(&m->u.Classic.Rooms.Overlap, roomsNode, "Overlap");
	LoadInt(&m->u.Classic.Rooms.Walls, roomsNode, "Walls");
	LoadInt(&m->u.Classic.Rooms.WallLength, roomsNode, "WallLength");
	LoadInt(&m->u.Classic.Rooms.WallPad, roomsNode, "WallPad");
}
예제 #2
0
static void LoadSoundConfigNode(SoundConfig *config, json_t *node)
{
	if (node == NULL)
	{
		return;
	}
	node = node->child;
	LoadInt(&config->SoundVolume, node, "SoundVolume");
	LoadInt(&config->MusicVolume, node, "MusicVolume");
	LoadBool(&config->Footsteps, node, "Footsteps");
	LoadBool(&config->Hits, node, "Hits");
	LoadBool(&config->Reloads, node, "Reloads");
}
예제 #3
0
void CProject::Serialize(CArchive& ar)
{
	if (ar.IsStoring()) {
		ar << ARCHIVE_SIG;
		ar << m_Version;
		StoreHistory(ar);
		ar << m_HistPos;
		ar << m_ThumbSize;
		StoreBool(ar, m_CycleColors);
		ar << m_ColorCycleRate;
	} else {
		UINT	sig;
		ar >> sig;
		ar >> m_Version;
		if (sig != ARCHIVE_SIG || m_Version > ARCHIVE_VERSION)
			AfxThrowArchiveException(CArchiveException::badIndex, ar.m_strFileName);
		LoadHistory(ar);
		ar >> m_HistPos;
		ar >> m_ThumbSize;
		LoadBool(ar, m_CycleColors);
		ar >> m_ColorCycleRate;
	}
	m_RecInfo.Serialize(ar);
	m_Snapshot.Serialize(ar);
}
예제 #4
0
static void LoadGameConfigNode(GameConfig *config, json_t *node)
{
	if (node == NULL)
	{
		return;
	}
	node = node->child;
	LoadBool(&config->FriendlyFire, node, "FriendlyFire");
	config->RandomSeed = atoi(json_find_first_label(node, "RandomSeed")->child->text);
	JSON_UTILS_LOAD_ENUM(config->Difficulty, node, "Difficulty", StrDifficulty);
	LoadBool(&config->SlowMotion, node, "SlowMotion");
	LoadInt(&config->EnemyDensity, node, "EnemyDensity");
	LoadInt(&config->NonPlayerHP, node, "NonPlayerHP");
	LoadInt(&config->PlayerHP, node, "PlayerHP");
	LoadBool(&config->Fog, node, "Fog");
	LoadInt(&config->SightRange, node, "SightRange");
	LoadBool(&config->Shadows, node, "Shadows");
	LoadBool(&config->MoveWhenShooting, node, "MoveWhenShooting");
	JSON_UTILS_LOAD_ENUM(
		config->SwitchMoveStyle, node, "SwitchMoveStyle", StrSwitchMoveStyle);
	LoadBool(&config->ShotsPushback, node, "ShotsPushback");
	JSON_UTILS_LOAD_ENUM(
		config->AllyCollision, node, "AllyCollision", StrAllyCollision);
	LoadBool(&config->HealthPickups, node, "HealthPickups");
}
예제 #5
0
void wxArchive::SkipData(wxUint8 hdr)
{
	switch(hdr)
	{
	case wxARCHIVE_HDR_BOOL:
		LoadBool();
		break;

	case wxARCHIVE_HDR_INT8:
		LoadChar();
		break;

	case wxARCHIVE_HDR_INT16:
		LoadUint16();
		break;

	case wxARCHIVE_HDR_INT32:
		LoadUint32();
		break;

	case wxARCHIVE_HDR_INT64:
		LoadUint64();
		break;

	case wxARCHIVE_HDR_DOUBLE:
		LoadDouble();
		break;

	case wxARCHIVE_HDR_STRING:
		LoadString();
		break;

	case wxARCHIVE_HDR_ARRSTRING:
		LoadArrayString();
		break;

	case wxARCHIVE_HDR_RECORD:
		{
			wxCharBuffer buf;
			Load(buf);
		}
		break;

	case wxARCHIVE_HDR_INT:
		LoadInt();
		break;

	case wxARCHIVE_HDR_ENTER:
		break;

	case wxARCHIVE_HDR_LEAVE:
		break;
	default:
		LogError(wxARCHIVE_ERR_ILL, wxARCHIVE_ERR_STR_ILL_UNKNOWN_HDR_s1, GetHeaderName(hdr));
		break;
	}
}
예제 #6
0
파일: Lib.c 프로젝트: overzeroe/Vyquon
/* Load the core library */
void LoadCoreLibrary(){
    CreateTypes();

    CreateSymbols();

    LoadMath();
    LoadBool();
    LoadList();
    LoadIO();
}
예제 #7
0
static void LoadClassicDoors(Mission *m, json_t *node, char *name)
{
	json_t *child = json_find_first_label(node, name);
	if (!child || !child->child)
	{
		return;
	}
	child = child->child;
	LoadBool(&m->u.Classic.Doors.Enabled, child, "Enabled");
	LoadInt(&m->u.Classic.Doors.Min, child, "Min");
	LoadInt(&m->u.Classic.Doors.Max, child, "Max");
}
예제 #8
0
void MesenMovie::ApplySettings()
{
	NesModel region = FromString(LoadString(_settings, MovieKeys::Region), NesModelNames, NesModel::NTSC);
	ConsoleType consoleType = FromString(LoadString(_settings, MovieKeys::ConsoleType), ConsoleTypeNames, ConsoleType::Nes);
	ControllerType controller1 = FromString(LoadString(_settings, MovieKeys::Controller1), ControllerTypeNames, ControllerType::None);
	ControllerType controller2 = FromString(LoadString(_settings, MovieKeys::Controller2), ControllerTypeNames, ControllerType::None);
	ControllerType controller3 = FromString(LoadString(_settings, MovieKeys::Controller3), ControllerTypeNames, ControllerType::None);
	ControllerType controller4 = FromString(LoadString(_settings, MovieKeys::Controller4), ControllerTypeNames, ControllerType::None);
	ExpansionPortDevice expansionDevice = FromString<ExpansionPortDevice>(LoadString(_settings, MovieKeys::ExpansionDevice), ExpansionPortDeviceNames, ExpansionPortDevice::None);

	EmulationSettings::SetNesModel(region);
	EmulationSettings::SetConsoleType(consoleType);
	EmulationSettings::SetControllerType(0, controller1);
	EmulationSettings::SetControllerType(1, controller2);
	EmulationSettings::SetControllerType(2, controller3);
	EmulationSettings::SetControllerType(3, controller4);
	EmulationSettings::SetExpansionDevice(expansionDevice);

	uint32_t ramPowerOnState = LoadInt(_settings, MovieKeys::RamPowerOnState);
	if(ramPowerOnState == 0xFF) {
		EmulationSettings::SetRamPowerOnState(RamPowerOnState::AllOnes);
	} else {
		EmulationSettings::SetRamPowerOnState(RamPowerOnState::AllZeros);
	}

	EmulationSettings::SetInputPollScanline(LoadInt(_settings, MovieKeys::InputPollScanline, 240));

	EmulationSettings::SetZapperDetectionRadius(LoadInt(_settings, MovieKeys::ZapperDetectionRadius));
	
	uint32_t cpuClockRate = LoadInt(_settings, MovieKeys::CpuClockRate);
	if(cpuClockRate != 100) {
		bool adjustApu = LoadBool(_settings, MovieKeys::OverclockAdjustApu);
		EmulationSettings::SetOverclockRate(cpuClockRate, adjustApu);
	} else {
		EmulationSettings::SetOverclockRate(100, true);
	}

	EmulationSettings::SetPpuNmiConfig(
		LoadInt(_settings, MovieKeys::ExtraScanlinesBeforeNmi),
		LoadInt(_settings, MovieKeys::ExtraScanlinesAfterNmi)
	);

	EmulationSettings::SetFlagState(EmulationFlags::DisablePpu2004Reads, LoadBool(_settings, MovieKeys::DisablePpu2004Reads));
	EmulationSettings::SetFlagState(EmulationFlags::DisablePaletteRead, LoadBool(_settings, MovieKeys::DisablePaletteRead));
	EmulationSettings::SetFlagState(EmulationFlags::DisableOamAddrBug, LoadBool(_settings, MovieKeys::DisableOamAddrBug));
	EmulationSettings::SetFlagState(EmulationFlags::UseNes101Hvc101Behavior, LoadBool(_settings, MovieKeys::UseNes101Hvc101Behavior));
	EmulationSettings::SetFlagState(EmulationFlags::EnableOamDecay, LoadBool(_settings, MovieKeys::EnableOamDecay));
	EmulationSettings::SetFlagState(EmulationFlags::DisablePpuReset, LoadBool(_settings, MovieKeys::DisablePpuReset));

	//VS System flags
	EmulationSettings::SetPpuModel(FromString(LoadString(_settings, MovieKeys::PpuModel), PpuModelNames, PpuModel::Ppu2C02));
	EmulationSettings::SetDipSwitches(HexUtilities::FromHex(LoadString(_settings, MovieKeys::DipSwitches)));

	LoadCheats();
}
예제 #9
0
static void LoadInterfaceConfigNode(
	InterfaceConfig *config, json_t *node, int version)
{
	if (node == NULL)
	{
		return;
	}
	node = node->child;
	LoadBool(&config->ShowFPS, node, "ShowFPS");
	LoadBool(&config->ShowTime, node, "ShowTime");
	if (version < 4)
	{
		bool splitscreenAlways;
		LoadBool(&splitscreenAlways, node, "SplitscreenAlways");
		config->Splitscreen =
			splitscreenAlways ? SPLITSCREEN_ALWAYS : SPLITSCREEN_NORMAL;
	}
	else
	{
		config->Splitscreen = StrSplitscreenStyle(
			json_find_first_label(node, "Splitscreen")->child->text);
	}
	LoadBool(&config->ShowHUDMap, node, "ShowHUDMap");
}
예제 #10
0
static void LoadGraphicsConfigNode(GraphicsConfig *config, json_t *node)
{
	if (node == NULL)
	{
		return;
	}
	node = node->child;
	LoadInt(&config->Brightness, node, "Brightness");
	LoadInt(&config->Res.x, node, "ResolutionWidth");
	LoadInt(&config->Res.y, node, "ResolutionHeight");
	LoadBool(&config->Fullscreen, node, "Fullscreen");
	LoadInt(&config->ScaleFactor, node, "ScaleFactor");
	LoadInt(&config->ShakeMultiplier, node, "ShakeMultiplier");
	JSON_UTILS_LOAD_ENUM(config->ScaleMode, node, "ScaleMode", StrScaleMode);
}
예제 #11
0
bool wxArchive::ReadBool(bool& value)
{
    // load boolean value
    if(LoadChunkHeader(wxARCHIVE_HDR_BOOL))
    {
        bool tmpvalue = LoadBool();

		if(IsOk())
		{
            value = tmpvalue;
			return true;
		}
    }

    return false;
}
예제 #12
0
static void LoadQuickPlayConfigNode(QuickPlayConfig *config, json_t *node)
{
	if (node == NULL)
	{
		return;
	}
	node = node->child;
	config->MapSize = StrQuickPlayQuantity(json_find_first_label(node, "MapSize")->child->text);
	config->WallCount = StrQuickPlayQuantity(json_find_first_label(node, "WallCount")->child->text);
	config->WallLength = StrQuickPlayQuantity(json_find_first_label(node, "WallLength")->child->text);
	config->RoomCount = StrQuickPlayQuantity(json_find_first_label(node, "RoomCount")->child->text);
	config->SquareCount = StrQuickPlayQuantity(json_find_first_label(node, "SquareCount")->child->text);
	config->EnemyCount = StrQuickPlayQuantity(json_find_first_label(node, "EnemyCount")->child->text);
	config->EnemySpeed = StrQuickPlayQuantity(json_find_first_label(node, "EnemySpeed")->child->text);
	config->EnemyHealth = StrQuickPlayQuantity(json_find_first_label(node, "EnemyHealth")->child->text);
	LoadBool(&config->EnemiesWithExplosives, node, "EnemiesWithExplosives");
	config->ItemCount = StrQuickPlayQuantity(json_find_first_label(node, "ItemCount")->child->text);
}
예제 #13
0
void ConfigLoadJSON(Config *config, const char *filename)
{
	FILE *f = fopen(filename, "r");
	json_t *root = NULL;
	int version;

	if (f == NULL)
	{
		printf("Error loading config '%s'\n", filename);
		goto bail;
	}

	if (json_stream_parse(f, &root) != JSON_OK)
	{
		printf("Error parsing config '%s'\n", filename);
		goto bail;
	}
	LoadInt(&version, root, "Version");
	ConfigLoadVisit(config, root);

	// Old config version stuff
	if (version < 5)
	{
		json_t *node = JSONFindNode(root, "Game");
		if (node != NULL)
		{
			bool moveWhenShooting = false;
			LoadBool(&moveWhenShooting, node, "MoveWhenShooting");
			Config *c = ConfigGet(config, "Game.FireMoveStyle");
			c->u.Enum.Value = moveWhenShooting ? FIREMOVE_NORMAL : FIREMOVE_STOP;
		}
	}
	if (version < 6)
	{
		json_t *node = JSONFindNode(root, "Input/Keys");
		if (node != NULL)
		{
			for (int i = 0; i < 2 && node != NULL; i++)
			{
				char buf[256];
				sprintf(buf, "Input.PlayerKeys%d", i);
				Config *c = ConfigGet(config, buf);
				ConfigLoadVisit(c, node->child);
				node = node->next;
			}
		}
	}
	if (version < 4)
	{
		json_t *node = JSONFindNode(root, "Interface");
		if (node != NULL)
		{
			bool splitscreenAlways;
			LoadBool(&splitscreenAlways, node, "SplitscreenAlways");
			Config *c = ConfigGet(config, "Interface.Splitscreen");
			c->u.Enum.Value =
				splitscreenAlways ? SPLITSCREEN_ALWAYS : SPLITSCREEN_NORMAL;
		}
	}

bail:
	json_free_value(&root);
	if (f != NULL)
	{
		fclose(f);
	}
}
예제 #14
0
static void ConfigLoadVisit(Config *c, json_t *node)
{
	if (node == NULL)
	{
		fprintf(stderr, "Error loading config: node %s not found\n",
			c->Name);
		return;
	}
	switch (c->Type)
	{
	case CONFIG_TYPE_STRING:
		CASSERT(false, "not implemented");
		break;
	case CONFIG_TYPE_INT:
		LoadInt(&c->u.Int.Value, node, c->Name);
		if (c->u.Int.Min > 0)
			c->u.Int.Value = MAX(c->u.Int.Value, c->u.Int.Min);
		if (c->u.Int.Max > 0)
			c->u.Int.Value = MIN(c->u.Int.Value, c->u.Int.Max);
		break;
	case CONFIG_TYPE_FLOAT:
		LoadDouble(&c->u.Float.Value, node, c->Name);
		if (c->u.Float.Min > 0)
			c->u.Float.Value = MAX(c->u.Float.Value, c->u.Float.Min);
		if (c->u.Float.Max > 0)
			c->u.Float.Value = MIN(c->u.Float.Value, c->u.Float.Max);
		break;
	case CONFIG_TYPE_BOOL:
		LoadBool(&c->u.Bool.Value, node, c->Name);
		break;
	case CONFIG_TYPE_ENUM:
		JSON_UTILS_LOAD_ENUM(
			c->u.Enum.Value, node, c->Name, c->u.Enum.StrToEnum);
		if (c->u.Enum.Min > 0)
			c->u.Enum.Value = MAX(c->u.Enum.Value, c->u.Enum.Min);
		if (c->u.Enum.Max > 0)
			c->u.Enum.Value = MIN(c->u.Enum.Value, c->u.Enum.Max);
		break;
	case CONFIG_TYPE_GROUP:
		{
			// If the config has no name, then it is the root element
			// Load children directly to the node
			// Otherwise, find the named child
			if (c->Name != NULL)
			{
				node = json_find_first_label(node, c->Name);
				if (node == NULL)
				{
					fprintf(stderr, "Error loading config: node %s not found\n",
						c->Name);
					return;
				}
				node = node->child;
			}
			CA_FOREACH(Config, child, c->u.Group)
				ConfigLoadVisit(child, node);
			CA_FOREACH_END()
		}
		break;
	default:
		CASSERT(false, "Unknown config type");
		break;
	}
}
예제 #15
0
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;
}
예제 #16
0
static bool TryLoadMapObject(MapObject *m, json_t *node, const int version)
{
	memset(m, 0, sizeof *m);

	m->Name = GetString(node, "Name");

	// Pic
	json_t *normalNode = json_find_first_label(node, "Pic");
	if (normalNode != NULL && normalNode->child != NULL)
	{
		if (version < 2)
		{
			CPicLoadNormal(&m->Pic, normalNode->child);
		}
		else
		{
			CPicLoadJSON(&m->Pic, normalNode->child);
		}
		// Pic required for map object
		if (!CPicIsLoaded(&m->Pic))
		{
			LOG(LM_MAIN, LL_ERROR, "pic not found for map object(%s)", m->Name);
			goto bail;
		}
	}
	if (CPicIsLoaded(&m->Pic))
	{
		// Default offset: centered X, align bottom of tile and sprite
		const Vec2i size = CPicGetSize(&m->Pic);
		m->Offset = Vec2iNew(-size.x / 2, TILE_HEIGHT / 2 - size.y);
		LoadVec2i(&m->Offset, node, "Offset");
	}

	// Wreck
	if (version < 3)
	{
		// Assume old wreck pic is wreck
		json_t *wreckNode = json_find_first_label(node, "WreckPic");
		if (wreckNode != NULL && wreckNode->child != NULL)
		{
			if (version < 2)
			{
				LoadStr(&m->Wreck, node, "WreckPic");
			}
			else
			{
				LoadStr(&m->Wreck, wreckNode, "Pic");
			}
		}
	}
	else
	{
		LoadStr(&m->Wreck, node, "Wreck");
	}

	// Default tile size
	m->Size = TILE_SIZE;
	LoadVec2i(&m->Size, node, "Size");
	LoadVec2i(&m->PosOffset, node, "PosOffset");
	LoadInt(&m->Health, node, "Health");
	LoadBulletGuns(&m->DestroyGuns, node, "DestroyGuns");

	// Flags
	json_t *flagsNode = json_find_first_label(node, "Flags");
	if (flagsNode != NULL && flagsNode->child != NULL)
	{
		for (json_t *flagNode = flagsNode->child->child;
			flagNode;
			flagNode = flagNode->next)
		{
			m->Flags |= 1 << StrPlacementFlag(flagNode->text);
		}
	}

	LoadBool(&m->DrawLast, node, "DrawLast");

	// Special types
	JSON_UTILS_LOAD_ENUM(m->Type, node, "Type", StrMapObjectType);
	switch (m->Type)
	{
	case MAP_OBJECT_TYPE_NORMAL:
		// Do nothing
		break;
	case MAP_OBJECT_TYPE_PICKUP_SPAWNER:
		{
			char *tmp = GetString(node, "Pickup");
			m->u.PickupClass = StrPickupClass(tmp);
			CFREE(tmp);
		}
		break;
	default:
		CASSERT(false, "unknown error");
		break;
	}

	// DestroySpawn - pickups to spawn on destruction
	json_t *destroySpawnNode = json_find_first_label(node, "DestroySpawn");
	if (destroySpawnNode != NULL && destroySpawnNode->child != NULL)
	{
		CArrayInit(&m->DestroySpawn, sizeof(MapObjectDestroySpawn));
		for (json_t *dsNode = destroySpawnNode->child->child;
			dsNode;
			dsNode = dsNode->next)
		{
			MapObjectDestroySpawn mods;
			memset(&mods, 0, sizeof mods);
			JSON_UTILS_LOAD_ENUM(mods.Type, dsNode, "Type", StrPickupType);
			LoadDouble(&mods.SpawnChance, dsNode, "SpawnChance");
			CArrayPushBack(&m->DestroySpawn, &mods);
		}
	}

	return true;

bail:
	return false;
}
예제 #17
0
bool CSettings::LoadBool ( SettingID Type )
{
	bool Value = false;
	LoadBool(Type,Value);
	return Value;
}
예제 #18
0
static void LoadBullet(
	BulletClass *b, json_t *node, const BulletClass *defaultBullet)
{
	memset(b, 0, sizeof *b);
	if (defaultBullet != NULL)
	{
		memcpy(b, defaultBullet, sizeof *b);
		if (defaultBullet->HitSound.Object != NULL)
		{
			CSTRDUP(b->HitSound.Object, defaultBullet->HitSound.Object);
		}
		if (defaultBullet->HitSound.Flesh != NULL)
		{
			CSTRDUP(b->HitSound.Flesh, defaultBullet->HitSound.Flesh);
		}
		if (defaultBullet->HitSound.Wall != NULL)
		{
			CSTRDUP(b->HitSound.Wall, defaultBullet->HitSound.Wall);
		}
		// TODO: enable default bullet guns?
		memset(&b->Falling.DropGuns, 0, sizeof b->Falling.DropGuns);
		memset(&b->OutOfRangeGuns, 0, sizeof b->OutOfRangeGuns);
		memset(&b->HitGuns, 0, sizeof b->HitGuns);
		memset(&b->ProximityGuns, 0, sizeof b->ProximityGuns);
	}
	char *tmp;

	LoadStr(&b->Name, node, "Name");
	if (json_find_first_label(node, "Pic"))
	{
		json_t *pic = json_find_first_label(node, "Pic")->child;
		tmp = GetString(pic, "Type");
		b->CPic.Type = StrPicType(tmp);
		CFREE(tmp);
		bool picLoaded = false;
		switch (b->CPic.Type)
		{
		case PICTYPE_NORMAL:
			tmp = GetString(pic, "Pic");
			b->CPic.u.Pic = PicManagerGetPic(&gPicManager, tmp);
			CFREE(tmp);
			picLoaded = b->CPic.u.Pic != NULL;
			break;
		case PICTYPE_DIRECTIONAL:
			tmp = GetString(pic, "Sprites");
			b->CPic.u.Sprites =
				&PicManagerGetSprites(&gPicManager, tmp)->pics;
			CFREE(tmp);
			picLoaded = b->CPic.u.Sprites != NULL;
			break;
		case PICTYPE_ANIMATED:	// fallthrough
		case PICTYPE_ANIMATED_RANDOM:
			tmp = GetString(pic, "Sprites");
			b->CPic.u.Animated.Sprites =
				&PicManagerGetSprites(&gPicManager, tmp)->pics;
			CFREE(tmp);
			LoadInt(&b->CPic.u.Animated.Count, pic, "Count");
			LoadInt(&b->CPic.u.Animated.TicksPerFrame, pic, "TicksPerFrame");
			// Set safe default ticks per frame 1;
			// if 0 then this leads to infinite loop when animating
			b->CPic.u.Animated.TicksPerFrame = MAX(
				b->CPic.u.Animated.TicksPerFrame, 1);
			picLoaded = b->CPic.u.Animated.Sprites != NULL;
			break;
		default:
			CASSERT(false, "unknown pic type");
			break;
		}
		b->CPic.UseMask = true;
		b->CPic.u1.Mask = colorWhite;
		if (json_find_first_label(pic, "Mask"))
		{
			tmp = GetString(pic, "Mask");
			b->CPic.u1.Mask = StrColor(tmp);
			CFREE(tmp);
		}
		else if (json_find_first_label(pic, "Tint"))
		{
			b->CPic.UseMask = false;
			json_t *tint = json_find_first_label(pic, "Tint")->child->child;
			b->CPic.u1.Tint.h = atof(tint->text);
			tint = tint->next;
			b->CPic.u1.Tint.s = atof(tint->text);
			tint = tint->next;
			b->CPic.u1.Tint.v = atof(tint->text);
		}
		if ((json_find_first_label(pic, "OldPic") &&
			ConfigGetBool(&gConfig, "Graphics.OriginalPics")) ||
			!picLoaded)
		{
			int oldPic = PIC_UZIBULLET;
			LoadInt(&oldPic, pic, "OldPic");
			b->CPic.Type = PICTYPE_NORMAL;
			b->CPic.u.Pic = PicManagerGetFromOld(&gPicManager, oldPic);
		}
	}
	LoadVec2i(&b->ShadowSize, node, "ShadowSize");
	LoadInt(&b->Delay, node, "Delay");
	if (json_find_first_label(node, "Speed"))
	{
		LoadInt(&b->SpeedLow, node, "Speed");
		b->SpeedHigh = b->SpeedLow;
	}
	if (json_find_first_label(node, "SpeedLow"))
	{
		LoadInt(&b->SpeedLow, node, "SpeedLow");
	}
	if (json_find_first_label(node, "SpeedHigh"))
	{
		LoadInt(&b->SpeedHigh, node, "SpeedHigh");
	}
	b->SpeedLow = MIN(b->SpeedLow, b->SpeedHigh);
	b->SpeedHigh = MAX(b->SpeedLow, b->SpeedHigh);
	LoadBool(&b->SpeedScale, node, "SpeedScale");
	LoadInt(&b->Friction, node, "Friction");
	if (json_find_first_label(node, "Range"))
	{
		LoadInt(&b->RangeLow, node, "Range");
		b->RangeHigh = b->RangeLow;
	}
	if (json_find_first_label(node, "RangeLow"))
	{
		LoadInt(&b->RangeLow, node, "RangeLow");
	}
	if (json_find_first_label(node, "RangeHigh"))
	{
		LoadInt(&b->RangeHigh, node, "RangeHigh");
	}
	b->RangeLow = MIN(b->RangeLow, b->RangeHigh);
	b->RangeHigh = MAX(b->RangeLow, b->RangeHigh);
	LoadInt(&b->Power, node, "Power");
	LoadVec2i(&b->Size, node, "Size");
	if (json_find_first_label(node, "Special"))
	{
		tmp = GetString(node, "Special");
		b->Special = StrSpecialDamage(tmp);
		CFREE(tmp);
	}
	LoadBool(&b->HurtAlways, node, "HurtAlways");
	LoadBool(&b->Persists, node, "Persists");
	if (json_find_first_label(node, "Spark"))
	{
		tmp = GetString(node, "Spark");
		b->Spark = StrParticleClass(&gParticleClasses, tmp);
		CFREE(tmp);
	}
	if (json_find_first_label(node, "HitSounds"))
	{
		json_t *hitSounds = json_find_first_label(node, "HitSounds")->child;
		CFREE(b->HitSound.Object);
		b->HitSound.Object = NULL;
		LoadStr(&b->HitSound.Object, hitSounds, "Object");
		CFREE(b->HitSound.Flesh);
		b->HitSound.Flesh = NULL;
		LoadStr(&b->HitSound.Flesh, hitSounds, "Flesh");
		CFREE(b->HitSound.Wall);
		b->HitSound.Wall = NULL;
		LoadStr(&b->HitSound.Wall, hitSounds, "Wall");
	}
	LoadBool(&b->WallBounces, node, "WallBounces");
	LoadBool(&b->HitsObjects, node, "HitsObjects");
	if (json_find_first_label(node, "Falling"))
	{
		json_t *falling = json_find_first_label(node, "Falling")->child;
		LoadInt(&b->Falling.GravityFactor, falling, "GravityFactor");
		LoadBool(&b->Falling.FallsDown, falling, "FallsDown");
		LoadBool(&b->Falling.DestroyOnDrop, falling, "DestroyOnDrop");
		LoadBool(&b->Falling.Bounces, falling, "Bounces");
	}
	LoadInt(&b->SeekFactor, node, "SeekFactor");
	LoadBool(&b->Erratic, node, "Erratic");

	b->node = node;
}
예제 #19
0
static void LoadBullet(
	BulletClass *b, json_t *node, const BulletClass *defaultBullet)
{
	memset(b, 0, sizeof *b);
	if (defaultBullet != NULL)
	{
		memcpy(b, defaultBullet, sizeof *b);
		if (defaultBullet->Name != NULL)
		{
			CSTRDUP(b->Name, defaultBullet->Name);
		}
		if (defaultBullet->HitSound.Object != NULL)
		{
			CSTRDUP(b->HitSound.Object, defaultBullet->HitSound.Object);
		}
		if (defaultBullet->HitSound.Flesh != NULL)
		{
			CSTRDUP(b->HitSound.Flesh, defaultBullet->HitSound.Flesh);
		}
		if (defaultBullet->HitSound.Wall != NULL)
		{
			CSTRDUP(b->HitSound.Wall, defaultBullet->HitSound.Wall);
		}
		// TODO: enable default bullet guns?
		memset(&b->Falling.DropGuns, 0, sizeof b->Falling.DropGuns);
		memset(&b->OutOfRangeGuns, 0, sizeof b->OutOfRangeGuns);
		memset(&b->HitGuns, 0, sizeof b->HitGuns);
		memset(&b->ProximityGuns, 0, sizeof b->ProximityGuns);
	}

	char *tmp;

	tmp = NULL;
	LoadStr(&tmp, node, "Name");
	if (tmp != NULL)
	{
		CFREE(b->Name);
		b->Name = tmp;
	}
	if (json_find_first_label(node, "Pic"))
	{
		CPicLoadJSON(&b->CPic, json_find_first_label(node, "Pic")->child);
	}
	LoadVec2i(&b->ShadowSize, node, "ShadowSize");
	LoadInt(&b->Delay, node, "Delay");
	if (json_find_first_label(node, "Speed"))
	{
		LoadInt(&b->SpeedLow, node, "Speed");
		b->SpeedHigh = b->SpeedLow;
	}
	LoadInt(&b->SpeedLow, node, "SpeedLow");
	LoadInt(&b->SpeedHigh, node, "SpeedHigh");
	b->SpeedLow = MIN(b->SpeedLow, b->SpeedHigh);
	b->SpeedHigh = MAX(b->SpeedLow, b->SpeedHigh);
	LoadBool(&b->SpeedScale, node, "SpeedScale");
	LoadInt(&b->Friction, node, "Friction");
	if (json_find_first_label(node, "Range"))
	{
		LoadInt(&b->RangeLow, node, "Range");
		b->RangeHigh = b->RangeLow;
	}
	LoadInt(&b->RangeLow, node, "RangeLow");
	LoadInt(&b->RangeHigh, node, "RangeHigh");
	b->RangeLow = MIN(b->RangeLow, b->RangeHigh);
	b->RangeHigh = MAX(b->RangeLow, b->RangeHigh);
	LoadInt(&b->Power, node, "Power");
	LoadVec2i(&b->Size, node, "Size");
	tmp = NULL;
	LoadStr(&tmp, node, "Special");
	if (tmp != NULL)
	{
		b->Special = StrSpecialDamage(tmp);
		CFREE(tmp);
	}
	LoadBool(&b->HurtAlways, node, "HurtAlways");
	LoadBool(&b->Persists, node, "Persists");
	tmp = NULL;
	LoadStr(&tmp, node, "Spark");
	if (tmp != NULL)
	{
		b->Spark = StrParticleClass(&gParticleClasses, tmp);
		CFREE(tmp);
	}
	if (json_find_first_label(node, "HitSounds"))
	{
		json_t *hitSounds = json_find_first_label(node, "HitSounds")->child;
		CFREE(b->HitSound.Object);
		b->HitSound.Object = NULL;
		LoadStr(&b->HitSound.Object, hitSounds, "Object");
		CFREE(b->HitSound.Flesh);
		b->HitSound.Flesh = NULL;
		LoadStr(&b->HitSound.Flesh, hitSounds, "Flesh");
		CFREE(b->HitSound.Wall);
		b->HitSound.Wall = NULL;
		LoadStr(&b->HitSound.Wall, hitSounds, "Wall");
	}
	LoadBool(&b->WallBounces, node, "WallBounces");
	LoadBool(&b->HitsObjects, node, "HitsObjects");
	if (json_find_first_label(node, "Falling"))
	{
		json_t *falling = json_find_first_label(node, "Falling")->child;
		LoadInt(&b->Falling.GravityFactor, falling, "GravityFactor");
		LoadBool(&b->Falling.FallsDown, falling, "FallsDown");
		LoadBool(&b->Falling.DestroyOnDrop, falling, "DestroyOnDrop");
		LoadBool(&b->Falling.Bounces, falling, "Bounces");
	}
	LoadInt(&b->SeekFactor, node, "SeekFactor");
	LoadBool(&b->Erratic, node, "Erratic");

	b->node = node;

	LOG(LM_MAP, LL_DEBUG,
		"loaded bullet name(%s) shadowSize(%d, %d) delay(%d) speed(%d-%d)...",
		b->Name != NULL ? b->Name : "", b->ShadowSize.x, b->ShadowSize.y,
		b->Delay, b->SpeedLow, b->SpeedHigh);
	LOG(LM_MAP, LL_DEBUG,
		"...speedScale(%s) friction(%d) range(%d-%d) power(%d)...",
		b->SpeedScale ? "true" : "false", b->Friction,
		b->RangeLow, b->RangeHigh, b->Power);
	LOG(LM_MAP, LL_DEBUG,
		"...size(%d, %d) hurtAlways(%s) persists(%s) spark(%s)...",
		b->Size.x, b->Size.y, b->HurtAlways ? "true" : "false",
		b->Persists ? "true" : "false",
		b->Spark != NULL ? b->Spark->Name : "");
	LOG(LM_MAP, LL_DEBUG,
		"...hitSounds(object(%s), flesh(%s), wall(%s)) wallBounces(%s)...",
		b->HitSound.Object != NULL ? b->HitSound.Object : "",
		b->HitSound.Flesh != NULL ? b->HitSound.Flesh : "",
		b->HitSound.Wall != NULL ? b->HitSound.Wall : "",
		b->WallBounces ? "true" : "false");
	LOG(LM_MAP, LL_DEBUG,
		"...hitsObjects(%s) gravity(%d) fallsDown(%s) destroyOnDrop(%s)...",
		b->HitsObjects ? "true" : "false", b->Falling.GravityFactor,
		b->Falling.FallsDown ? "true" : "false",
		b->Falling.DestroyOnDrop ? "true" : "false");
	LOG(LM_MAP, LL_DEBUG,
		"...dropGuns(%d) seekFactor(%d) erratic(%s)...",
		(int)b->Falling.DropGuns.size, b->SeekFactor,
		b->Erratic ? "true" : "false");
	LOG(LM_MAP, LL_DEBUG,
		"...outOfRangeGuns(%d) hitGuns(%d) proximityGuns(%d)",
		(int)b->OutOfRangeGuns.size,
		(int)b->HitGuns.size,
		(int)b->ProximityGuns.size);
}