Skip to content
Permalink
Browse files

Merge pull request #1223 from Yankes/constantsLoadingRefactor

Constants loading refactor
  • Loading branch information...
SupSuper committed Jun 22, 2019
2 parents c13d540 + ac53ede commit 1ed95032c072b4b22e7315fd815043dcd59d70c5
Showing with 100 additions and 76 deletions.
  1. +25 −25 bin/standard/xcom2/vars.rul
  2. +74 −51 src/Mod/Mod.cpp
  3. +1 −0 src/Mod/Mod.h
@@ -18,31 +18,31 @@ alienFuel: [STR_ZRBITE, 50]
fontName: Font.dat

constants: #done
- doorSound: 47
- slidingDoorSound: 46
- slidingDoorClose: -1
- smallExplosion: 30
- largeExplosion: 29
- itemDrop: 44
- itemThrow: 42
- itemReload: 45
- walkOffset: 0
- flyingSound: 66
- buttonPress: 0
- windowPopup: [1, 1, 1]
- ufoFire: 5
- ufoHit: 4
- ufoExplode: 3
- ufoCrash: 2
- interceptorHit: 2
- interceptorExplode: 2
- explosionOffset: 8
- smokeOffset: 56
- underwaterSmokeOffset: 8
- basescapeCursor: 42
- graphsCursor: 144
- goodDebriefingMusic: GMDEBGOO
- badDebriefingMusic: GMDEBPOR
doorSound: 47
slidingDoorSound: 46
slidingDoorClose: -1
smallExplosion: 30
largeExplosion: 29
itemDrop: 44
itemThrow: 42
itemReload: 45
walkOffset: 0
flyingSound: 66
buttonPress: 0
windowPopup: [1, 1, 1]
ufoFire: 5
ufoHit: 4
ufoExplode: 3
ufoCrash: 2
interceptorHit: 2
interceptorExplode: 2
explosionOffset: 8
smokeOffset: 56
underwaterSmokeOffset: 8
basescapeCursor: 42
graphsCursor: 144
goodDebriefingMusic: GMDEBGOO
badDebriefingMusic: GMDEBPOR

soundDefs: #done: double check explosions.
- type: GEO.CAT
@@ -1041,6 +1041,59 @@ void Mod::loadResourceConfigFile(const std::string &filename)
}
}

/**
* Loads "constants" node.
*/
void Mod::loadConstants(const YAML::Node &node)
{
loadSoundOffset("constants", DOOR_OPEN, node["doorSound"], "BATTLE.CAT");
loadSoundOffset("constants", SLIDING_DOOR_OPEN, node["slidingDoorSound"], "BATTLE.CAT");
loadSoundOffset("constants", SLIDING_DOOR_CLOSE, node["slidingDoorClose"], "BATTLE.CAT");
loadSoundOffset("constants", SMALL_EXPLOSION, node["smallExplosion"], "BATTLE.CAT");
loadSoundOffset("constants", LARGE_EXPLOSION, node["largeExplosion"], "BATTLE.CAT");

loadSpriteOffset("constants", EXPLOSION_OFFSET, node["explosionOffset"], "X1.PCK");
loadSpriteOffset("constants", SMOKE_OFFSET, node["smokeOffset"], "SMOKE.PCK");
loadSpriteOffset("constants", UNDERWATER_SMOKE_OFFSET, node["underwaterSmokeOffset"], "SMOKE.PCK");

loadSoundOffset("constants", ITEM_DROP, node["itemDrop"], "BATTLE.CAT");
loadSoundOffset("constants", ITEM_THROW, node["itemThrow"], "BATTLE.CAT");
loadSoundOffset("constants", ITEM_RELOAD, node["itemReload"], "BATTLE.CAT");
loadSoundOffset("constants", WALK_OFFSET, node["walkOffset"], "BATTLE.CAT");
loadSoundOffset("constants", FLYING_SOUND, node["flyingSound"], "BATTLE.CAT");

loadSoundOffset("constants", BUTTON_PRESS, node["buttonPress"], "GEO.CAT");
if (node["windowPopup"])
{
int k = 0;
for (YAML::const_iterator j = node["windowPopup"].begin(); j != node["windowPopup"].end() && k < 3; ++j, ++k)
{
loadSoundOffset("constants", WINDOW_POPUP[k], (*j), "GEO.CAT");
}
}
loadSoundOffset("constants", UFO_FIRE, node["ufoFire"], "GEO.CAT");
loadSoundOffset("constants", UFO_HIT, node["ufoHit"], "GEO.CAT");
loadSoundOffset("constants", UFO_CRASH, node["ufoCrash"], "GEO.CAT");
loadSoundOffset("constants", UFO_EXPLODE, node["ufoExplode"], "GEO.CAT");
loadSoundOffset("constants", INTERCEPTOR_HIT, node["interceptorHit"], "GEO.CAT");
loadSoundOffset("constants", INTERCEPTOR_EXPLODE, node["interceptorExplode"], "GEO.CAT");
GEOSCAPE_CURSOR = node["geoscapeCursor"].as<int>(GEOSCAPE_CURSOR);
BASESCAPE_CURSOR = node["basescapeCursor"].as<int>(BASESCAPE_CURSOR);
BATTLESCAPE_CURSOR = node["battlescapeCursor"].as<int>(BATTLESCAPE_CURSOR);
UFOPAEDIA_CURSOR = node["ufopaediaCursor"].as<int>(UFOPAEDIA_CURSOR);
GRAPHS_CURSOR = node["graphsCursor"].as<int>(GRAPHS_CURSOR);
DAMAGE_RANGE = node["damageRange"].as<int>(DAMAGE_RANGE);
EXPLOSIVE_DAMAGE_RANGE = node["explosiveDamageRange"].as<int>(EXPLOSIVE_DAMAGE_RANGE);
size_t num = 0;
for (YAML::const_iterator j = node["fireDamageRange"].begin(); j != node["fireDamageRange"].end() && num < 2; ++j)
{
FIRE_DAMAGE_RANGE[num] = (*j).as<int>(FIRE_DAMAGE_RANGE[num]);
++num;
}
DEBRIEF_MUSIC_GOOD = node["goodDebriefingMusic"].as<std::string>(DEBRIEF_MUSIC_GOOD);
DEBRIEF_MUSIC_BAD = node["badDebriefingMusic"].as<std::string>(DEBRIEF_MUSIC_BAD);
}

/**
* Loads a ruleset's contents from a YAML file.
* Rules that match pre-existing rules overwrite them.
@@ -1389,51 +1442,20 @@ void Mod::loadFile(const std::string &filename)
{
_converter->load(doc["converter"]);
}
for (YAML::const_iterator i = doc["constants"].begin(); i != doc["constants"].end(); ++i)
{
DOOR_OPEN = (*i)["doorSound"].as<int>(DOOR_OPEN);
SLIDING_DOOR_OPEN = (*i)["slidingDoorSound"].as<int>(SLIDING_DOOR_OPEN);
SLIDING_DOOR_CLOSE = (*i)["slidingDoorClose"].as<int>(SLIDING_DOOR_CLOSE);
SMALL_EXPLOSION = (*i)["smallExplosion"].as<int>(SMALL_EXPLOSION);
LARGE_EXPLOSION = (*i)["largeExplosion"].as<int>(LARGE_EXPLOSION);
EXPLOSION_OFFSET = (*i)["explosionOffset"].as<int>(EXPLOSION_OFFSET);
SMOKE_OFFSET = (*i)["smokeOffset"].as<int>(SMOKE_OFFSET);
UNDERWATER_SMOKE_OFFSET = (*i)["underwaterSmokeOffset"].as<int>(UNDERWATER_SMOKE_OFFSET);
ITEM_DROP = (*i)["itemDrop"].as<int>(ITEM_DROP);
ITEM_THROW = (*i)["itemThrow"].as<int>(ITEM_THROW);
ITEM_RELOAD = (*i)["itemReload"].as<int>(ITEM_RELOAD);
WALK_OFFSET = (*i)["walkOffset"].as<int>(WALK_OFFSET);
FLYING_SOUND = (*i)["flyingSound"].as<int>(FLYING_SOUND);
BUTTON_PRESS = (*i)["buttonPress"].as<int>(BUTTON_PRESS);
if ((*i)["windowPopup"])
{
int k = 0;
for (YAML::const_iterator j = (*i)["windowPopup"].begin(); j != (*i)["windowPopup"].end() && k < 3; ++j, ++k)
if (const YAML::Node& constants = doc["constants"])
{
//backward compatiblity version
if (constants.IsSequence())
{
for (YAML::const_iterator i = constants.begin(); i != constants.end(); ++i)
{
WINDOW_POPUP[k] = (*j).as<int>(WINDOW_POPUP[k]);
loadConstants((*i));
}
}
UFO_FIRE = (*i)["ufoFire"].as<int>(UFO_FIRE);
UFO_HIT = (*i)["ufoHit"].as<int>(UFO_HIT);
UFO_CRASH = (*i)["ufoCrash"].as<int>(UFO_CRASH);
UFO_EXPLODE = (*i)["ufoExplode"].as<int>(UFO_EXPLODE);
INTERCEPTOR_HIT = (*i)["interceptorHit"].as<int>(INTERCEPTOR_HIT);
INTERCEPTOR_EXPLODE = (*i)["interceptorExplode"].as<int>(INTERCEPTOR_EXPLODE);
GEOSCAPE_CURSOR = (*i)["geoscapeCursor"].as<int>(GEOSCAPE_CURSOR);
BASESCAPE_CURSOR = (*i)["basescapeCursor"].as<int>(BASESCAPE_CURSOR);
BATTLESCAPE_CURSOR = (*i)["battlescapeCursor"].as<int>(BATTLESCAPE_CURSOR);
UFOPAEDIA_CURSOR = (*i)["ufopaediaCursor"].as<int>(UFOPAEDIA_CURSOR);
GRAPHS_CURSOR = (*i)["graphsCursor"].as<int>(GRAPHS_CURSOR);
DAMAGE_RANGE = (*i)["damageRange"].as<int>(DAMAGE_RANGE);
EXPLOSIVE_DAMAGE_RANGE = (*i)["explosiveDamageRange"].as<int>(EXPLOSIVE_DAMAGE_RANGE);
size_t num = 0;
for (YAML::const_iterator j = (*i)["fireDamageRange"].begin(); j != (*i)["fireDamageRange"].end() && num < 2; ++j)
else
{
FIRE_DAMAGE_RANGE[num] = (*j).as<int>(FIRE_DAMAGE_RANGE[num]);
++num;
loadConstants(constants);
}
DEBRIEF_MUSIC_GOOD = (*i)["goodDebriefingMusic"].as<std::string>(DEBRIEF_MUSIC_GOOD);
DEBRIEF_MUSIC_BAD = (*i)["badDebriefingMusic"].as<std::string>(DEBRIEF_MUSIC_BAD);
}
for (YAML::const_iterator i = doc["mapScripts"].begin(); i != doc["mapScripts"].end(); ++i)
{
@@ -2696,6 +2718,10 @@ void Mod::loadVanillaResources()
{
// Create Geoscape surface
_sets["GlobeMarkers"] = new SurfaceSet(3, 3);
// Create Sound sets
_sounds["GEO.CAT"] = new SoundSet();
_sounds["BATTLE.CAT"] = new SoundSet();
_sounds["BATTLE2.CAT"] = new SoundSet();

// Load palettes
const char *pal[] = { "PAL_GEOSCAPE", "PAL_BASESCAPE", "PAL_GRAPHS", "PAL_UFOPAEDIA", "PAL_BATTLEPEDIA" };
@@ -2844,7 +2870,7 @@ void Mod::loadVanillaResources()
std::set<std::string>::iterator file = soundFiles.find(fname);
if (file != soundFiles.end())
{
sound = new SoundSet();
sound = _sounds[catsId[i]];
sound->loadCat(FileMap::getFilePath("SOUND/" + cats[j][i]), wav);
Options::currentSound = (wav) ? SOUND_14 : SOUND_10;
}
@@ -2853,10 +2879,6 @@ void Mod::loadVanillaResources()
{
throw Exception(catsWin[i] + " not found");
}
else
{
_sounds[catsId[i]] = sound;
}
}
}
else
@@ -2911,7 +2933,6 @@ void Mod::loadVanillaResources()
"SMOKE.PCK",
"HIT.PCK",
"BASEBITS.PCK",
"X1.PCK",
"INTICON.PCK",
};

@@ -2933,6 +2954,11 @@ void Mod::loadVanillaResources()
SurfaceSet* s = _sets["GlobeMarkers"];
s->setMaxSharedFrames(9);
}
//HACK: because of value "hitAnimation" from item that is used as offet in "X1.PCK", this set need have same number of shared frames as "SMOKE.PCK".
{
SurfaceSet* s = _sets["X1.PCK"];
s->setMaxSharedFrames((int)_sets["SMOKE.PCK"]->getMaxSharedFrames());
}
}
{
std::string soundNames[] =
@@ -2946,13 +2972,10 @@ void Mod::loadVanillaResources()
SoundSet* s = _sounds[soundNames[i]];
s->setMaxSharedSounds((int)s->getTotalSounds());
}
//case for underwater surface
//HACK: case for underwater surface, it should share same offsets as "BATTLE.CAT"
{
SoundSet* s = _sounds["BATTLE2.CAT"];
if (s)
{
s->setMaxSharedSounds((int)s->getTotalSounds());
}
s->setMaxSharedSounds((int)_sounds["BATTLE.CAT"]->getTotalSounds());
}
}
}
@@ -171,6 +171,7 @@ class Mod

/// Loads a ruleset from a YAML file that have basic resources configuration.
void loadResourceConfigFile(const std::string &filename);
void loadConstants(const YAML::Node &node);
/// Loads a ruleset from a YAML file.
void loadFile(const std::string &filename);
/// Loads a ruleset element.

0 comments on commit 1ed9503

Please sign in to comment.
You can’t perform that action at this time.