SpaceCadetPinball/SpaceCadetPinball/loader.cpp

508 lines
12 KiB
C++
Raw Normal View History

2020-10-25 15:17:26 +01:00
#include "pch.h"
#include "loader.h"
#include "GroupData.h"
Implement stereo sound. (#138) * Implement stereo sound. Original Space Cadet has mono sound. To achieve stereo, the following steps were accomplished: - Add a game option to turn on/off stereo sound. Default is on. - TPinballComponent objects were extended with a method called get_coordinates() that returns a single 2D point, approximating the on-screen position of the object, re-mapped between 0 and 1 vertically and horizontally, {0, 0} being at the top-left. - For static objects like bumpers and lights, the coordinate refers to the geometric center of the corresponding graphic sprite, and is precalculated at initialization. - For ball objects, the coordinate refers to the geometric center of the ball, calculated during play when requested. - Extend all calls to sound-playing methods so that they include a TPinballComponent* argument that refers to the sound source, e.g. where the sound comes from. For instance, when a flipper is activated, its method call to emit a sound now includes a reference to the flipper object; when a ball goes under a SkillShotGate, its method call to emit a sound now includes a reference to the corresponding light; and so on. For some cases, like light rollovers, the sound source is taken from the ball that triggered the light rollover. For other cases, like holes, flags and targets, the sound source is taken from the object itself. For some special cases like ramp activation, sound source is taken from the nearest light position that makes sense. For all game-progress sounds, like mission completion sounds or ball drain sounds, the sound source is undefined (set to nullptr), and the Sound::PlaySound() method takes care of positioning them at a default location, where speakers on a pinball machine normally are. - Make the Sound::PlaySound() method accept a new argument, a TPinballComponent reference, as described above. If the stereo option is turned on, the Sound::PlaySound() method calls the get_coordinates() method of the TPinballComponent reference to get the sound position. This project uses SDL_mixer and there is a function called Mix_SetPosition() that allows placing a sound in the stereo field, by giving it a distance and an angle. We arbitrarily place the player's ears at the bottom of the table; we set the ears' height to half a table's length. Intensity of the stereo effect is directly related to this value; the farther the player's ears from the table, the narrowest the stereo picture gets, and vice-versa. From there we have all we need to calculate distance and angle; we do just that and position all the sounds. * Copy-paste typo fix.
2022-05-30 09:35:29 +02:00
#include "TPinballComponent.h"
#include "pb.h"
2020-12-25 14:46:06 +01:00
#include "Sound.h"
2020-11-08 16:37:59 +01:00
#include "zdrv.h"
2020-10-25 15:17:26 +01:00
errorMsg loader::loader_errors[] =
2021-01-28 16:01:26 +01:00
{
2020-10-25 15:17:26 +01:00
errorMsg{0, "Bad Handle"},
errorMsg{1, "No Type Field"},
errorMsg{2, "No Attributes Field"},
2020-10-25 15:17:26 +01:00
errorMsg{3, "Wrong Type: MATERIAL Expected"},
errorMsg{4, "Wrong Type: KICKER Expected"},
errorMsg{5, "Wrong Type: AN_OBJECT Expected"},
errorMsg{6, "Wrong Type: A_STATE Expected"},
errorMsg{7, "STATES (re)defined in a state"},
errorMsg{9, "Unrecognized Attribute"},
errorMsg{0x0A, "Unrecognized float Attribute"},
errorMsg{0x0B, "No float Attributes Field"},
2020-10-25 15:17:26 +01:00
errorMsg{0x0D, "float Attribute not found"},
errorMsg{0x0C, "state_index out of range"},
errorMsg{0x0F, "loader_material() reports failure"},
errorMsg{0x0E, "loader_kicker() reports failure"},
errorMsg{0x10, "loader_state_id() reports failure"},
errorMsg{0x8, "# walls doesn't match data size"},
errorMsg{0x11, "loader_query_visual_states()"},
errorMsg{0x12, "loader_query_visual()"},
errorMsg{0x15, "loader_material()"},
errorMsg{0x14, "loader_kicker()"},
errorMsg{0x16, "loader_query_attribute()"},
errorMsg{0x17, "loader_query_iattribute()"},
errorMsg{0x13, "loader_query_name()"},
errorMsg{0x18, "loader_state_id()"},
errorMsg{0x19, "loader_get_sound_id()"},
errorMsg{0x1A, "sound reference is not A_SOUND record"},
errorMsg{-1, "Unknown"},
};
int loader::sound_count = 1;
int loader::loader_sound_count;
DatFile* loader::loader_table;
DatFile* loader::sound_record_table;
2020-10-25 15:17:26 +01:00
soundListStruct loader::sound_list[65];
int loader::error(int errorCode, int captionCode)
{
auto curCode = loader_errors;
2020-10-25 15:17:26 +01:00
const char *errorText = nullptr, *errorCaption = nullptr;
auto index = 0;
while (curCode->Code >= 0)
{
if (errorCode == curCode->Code)
errorText = curCode->Message;
if (captionCode == curCode->Code)
errorCaption = curCode->Message;
curCode++;
index++;
}
2020-10-25 15:17:26 +01:00
if (!errorText)
errorText = loader_errors[index].Message;
pb::ShowMessageBox(SDL_MESSAGEBOX_ERROR, errorCaption, errorText);
2020-10-25 15:17:26 +01:00
return -1;
}
2021-01-28 16:01:26 +01:00
void loader::default_vsi(visualStruct* visual)
2020-10-25 15:17:26 +01:00
{
2021-01-28 16:01:26 +01:00
visual->CollisionGroup = 0;
2021-01-23 11:33:30 +01:00
visual->Kicker.Threshold = 8.9999999e10f;
visual->Kicker.HardHitSoundId = 0;
visual->Smoothness = 0.94999999f;
visual->Elasticity = 0.60000002f;
2020-12-20 12:13:12 +01:00
visual->FloatArrCount = 0;
2021-01-23 11:33:30 +01:00
visual->SoftHitSoundId = 0;
visual->Bitmap = { nullptr, nullptr };
2020-10-30 13:26:00 +01:00
visual->SoundIndex3 = 0;
visual->SoundIndex4 = 0;
2020-10-25 15:17:26 +01:00
}
void loader::loadfrom(DatFile* datFile)
2020-10-25 15:17:26 +01:00
{
loader_table = datFile;
sound_record_table = loader_table;
2021-01-28 16:01:26 +01:00
for (auto groupIndex = 0; groupIndex < static_cast<int>(datFile->Groups.size()); ++groupIndex)
2020-10-25 15:17:26 +01:00
{
auto value = reinterpret_cast<int16_t*>(datFile->field(groupIndex, FieldTypes::ShortValue));
2021-01-28 16:01:26 +01:00
if (value && *value == 202)
2020-10-25 15:17:26 +01:00
{
2021-01-28 16:01:26 +01:00
if (sound_count < 65)
2020-10-25 15:17:26 +01:00
{
sound_list[sound_count] = {nullptr, groupIndex, 0, 0};
2021-01-28 16:01:26 +01:00
sound_count++;
2020-10-25 15:17:26 +01:00
}
}
}
2021-01-28 16:01:26 +01:00
loader_sound_count = sound_count;
2020-10-25 15:17:26 +01:00
}
void loader::unload()
{
for (int index = 1; index < sound_count; ++index)
{
2021-01-28 16:01:26 +01:00
Sound::FreeSound(sound_list[index].WavePtr);
sound_list[index] = {};
}
2021-01-28 16:01:26 +01:00
2020-10-25 15:17:26 +01:00
sound_count = 1;
}
int loader::get_sound_id(int groupIndex)
{
int16_t soundIndex = 1;
2020-10-25 15:17:26 +01:00
if (sound_count <= 1)
{
error(25, 26);
2021-01-28 16:01:26 +01:00
return -1;
2020-10-25 15:17:26 +01:00
}
2021-01-28 16:01:26 +01:00
while (sound_list[soundIndex].GroupIndex != groupIndex)
2020-10-25 15:17:26 +01:00
{
2021-01-28 16:01:26 +01:00
++soundIndex;
if (soundIndex >= sound_count)
2020-10-25 15:17:26 +01:00
{
2021-01-28 16:01:26 +01:00
error(25, 26);
return -1;
2020-10-25 15:17:26 +01:00
}
2021-01-28 16:01:26 +01:00
}
if (!sound_list[soundIndex].Loaded && !sound_list[soundIndex].WavePtr)
{
WaveHeader wavHeader{};
2021-01-28 16:01:26 +01:00
int soundGroupId = sound_list[soundIndex].GroupIndex;
sound_list[soundIndex].Duration = 0.0;
if (soundGroupId > 0 && !pb::quickFlag)
2020-10-25 15:17:26 +01:00
{
auto value = reinterpret_cast<int16_t*>(loader_table->field(soundGroupId,
FieldTypes::ShortValue));
2021-01-28 16:01:26 +01:00
if (value && *value == 202)
2020-10-25 15:17:26 +01:00
{
// File name is in lower case, while game data is usually in upper case.
std::string fileName = loader_table->field(soundGroupId, FieldTypes::String);
if (pb::FullTiltMode)
{
// FT sounds are in SOUND subfolder
fileName.insert(0, 1, PathSeparator);
fileName.insert(0, "sound");
}
std::string filePath;
float duration = -1;
for (int i = 0; i < 2; i++)
{
if (i == 1)
std::transform(fileName.begin(), fileName.end(), fileName.begin(),
[](unsigned char c) { return std::toupper(c); });
filePath = pb::make_path_name(fileName);
auto file = fopenu(filePath.c_str(), "rb");
if (file)
{
fread(&wavHeader, 1, sizeof wavHeader, file);
fclose(file);
auto sampleCount = wavHeader.data_size / (wavHeader.channels * (wavHeader.bits_per_sample /
8.0));
duration = static_cast<float>(sampleCount / wavHeader.sample_rate);
break;
}
}
sound_list[soundIndex].Duration = duration;
sound_list[soundIndex].WavePtr = Sound::LoadWaveFile(filePath);
2020-10-25 15:17:26 +01:00
}
}
}
2021-01-28 16:01:26 +01:00
++sound_list[soundIndex].Loaded;
return soundIndex;
2020-10-25 15:17:26 +01:00
}
int loader::query_handle(LPCSTR lpString)
{
return loader_table->record_labeled(lpString);
2020-10-25 15:17:26 +01:00
}
short loader::query_visual_states(int groupIndex)
{
short result;
if (groupIndex < 0)
return error(0, 17);
auto shortArr = reinterpret_cast<int16_t*>(loader_table->field(groupIndex, FieldTypes::ShortArray));
2020-10-25 15:17:26 +01:00
if (shortArr && *shortArr == 100)
result = shortArr[1];
else
result = 1;
return result;
}
char* loader::query_name(int groupIndex)
{
2021-01-28 16:01:26 +01:00
if (groupIndex < 0)
{
error(0, 19);
return nullptr;
}
return loader_table->field(groupIndex, FieldTypes::GroupName);
2020-10-25 15:17:26 +01:00
}
int16_t* loader::query_iattribute(int groupIndex, int firstValue, int* arraySize)
2020-10-25 15:17:26 +01:00
{
2021-01-28 16:01:26 +01:00
if (groupIndex < 0)
2020-10-25 15:17:26 +01:00
{
2021-01-28 16:01:26 +01:00
error(0, 22);
return nullptr;
2020-10-25 15:17:26 +01:00
}
2021-01-28 16:01:26 +01:00
for (auto skipIndex = 0;; ++skipIndex)
2020-10-25 15:17:26 +01:00
{
auto shortArr = reinterpret_cast<int16_t*>(loader_table->field_nth(groupIndex,
FieldTypes::ShortArray, skipIndex));
2021-01-28 16:01:26 +01:00
if (!shortArr)
break;
if (*shortArr == firstValue)
{
*arraySize = loader_table->field_size(groupIndex, FieldTypes::ShortArray) / 2 - 1;
2021-01-28 16:01:26 +01:00
return shortArr + 1;
}
2020-10-25 15:17:26 +01:00
}
2021-01-28 16:01:26 +01:00
error(2, 23);
*arraySize = 0;
return nullptr;
2020-10-25 15:17:26 +01:00
}
float* loader::query_float_attribute(int groupIndex, int groupIndexOffset, int firstValue)
{
2021-01-28 16:01:26 +01:00
if (groupIndex < 0)
2020-10-25 15:17:26 +01:00
{
2021-01-28 16:01:26 +01:00
error(0, 22);
return nullptr;
2020-10-25 15:17:26 +01:00
}
2021-01-28 16:01:26 +01:00
int stateId = state_id(groupIndex, groupIndexOffset);
if (stateId < 0)
2020-10-25 15:17:26 +01:00
{
2021-01-28 16:01:26 +01:00
error(16, 22);
return nullptr;
2020-10-25 15:17:26 +01:00
}
2021-01-28 16:01:26 +01:00
for (auto skipIndex = 0;; ++skipIndex)
{
auto floatArr = reinterpret_cast<float*>(loader_table->field_nth(stateId, FieldTypes::FloatArray,
skipIndex));
2021-01-28 16:01:26 +01:00
if (!floatArr)
break;
if (static_cast<int16_t>(floor(*floatArr)) == firstValue)
2021-01-28 16:01:26 +01:00
return floatArr + 1;
}
error(13, 22);
return nullptr;
2020-10-25 15:17:26 +01:00
}
float loader::query_float_attribute(int groupIndex, int groupIndexOffset, int firstValue, float defVal)
{
if (groupIndex < 0)
{
error(0, 22);
return NAN;
}
int stateId = state_id(groupIndex, groupIndexOffset);
if (stateId < 0)
{
error(16, 22);
return NAN;
}
for (auto skipIndex = 0;; ++skipIndex)
{
auto floatArr = reinterpret_cast<float*>(loader_table->field_nth(stateId,
FieldTypes::FloatArray, skipIndex));
if (!floatArr)
break;
if (static_cast<int16_t>(floor(*floatArr)) == firstValue)
return floatArr[1];
}
if (!isnan(defVal))
return defVal;
error(13, 22);
return NAN;
}
2020-10-30 13:26:00 +01:00
int loader::material(int groupIndex, visualStruct* visual)
{
if (groupIndex < 0)
return error(0, 21);
auto shortArr = reinterpret_cast<int16_t*>(loader_table->field(groupIndex, FieldTypes::ShortValue));
2020-10-30 13:26:00 +01:00
if (!shortArr)
return error(1, 21);
if (*shortArr != 300)
return error(3, 21);
auto floatArr = reinterpret_cast<float*>(loader_table->field(groupIndex, FieldTypes::FloatArray));
2020-10-30 13:26:00 +01:00
if (!floatArr)
return error(11, 21);
2021-01-28 16:01:26 +01:00
int floatArrLength = loader_table->field_size(groupIndex, FieldTypes::FloatArray) / 4;
2021-01-28 16:01:26 +01:00
for (auto index = 0; index < floatArrLength; index += 2)
2020-10-30 13:26:00 +01:00
{
2021-01-28 16:01:26 +01:00
switch (static_cast<int>(floor(floatArr[index])))
2020-10-30 13:26:00 +01:00
{
2021-01-28 16:01:26 +01:00
case 301:
visual->Smoothness = floatArr[index + 1];
break;
case 302:
visual->Elasticity = floatArr[index + 1];
break;
case 304:
visual->SoftHitSoundId = get_sound_id(static_cast<int>(floor(floatArr[index + 1])));
break;
default:
return error(9, 21);
2020-10-30 13:26:00 +01:00
}
}
return 0;
}
Implement stereo sound. (#138) * Implement stereo sound. Original Space Cadet has mono sound. To achieve stereo, the following steps were accomplished: - Add a game option to turn on/off stereo sound. Default is on. - TPinballComponent objects were extended with a method called get_coordinates() that returns a single 2D point, approximating the on-screen position of the object, re-mapped between 0 and 1 vertically and horizontally, {0, 0} being at the top-left. - For static objects like bumpers and lights, the coordinate refers to the geometric center of the corresponding graphic sprite, and is precalculated at initialization. - For ball objects, the coordinate refers to the geometric center of the ball, calculated during play when requested. - Extend all calls to sound-playing methods so that they include a TPinballComponent* argument that refers to the sound source, e.g. where the sound comes from. For instance, when a flipper is activated, its method call to emit a sound now includes a reference to the flipper object; when a ball goes under a SkillShotGate, its method call to emit a sound now includes a reference to the corresponding light; and so on. For some cases, like light rollovers, the sound source is taken from the ball that triggered the light rollover. For other cases, like holes, flags and targets, the sound source is taken from the object itself. For some special cases like ramp activation, sound source is taken from the nearest light position that makes sense. For all game-progress sounds, like mission completion sounds or ball drain sounds, the sound source is undefined (set to nullptr), and the Sound::PlaySound() method takes care of positioning them at a default location, where speakers on a pinball machine normally are. - Make the Sound::PlaySound() method accept a new argument, a TPinballComponent reference, as described above. If the stereo option is turned on, the Sound::PlaySound() method calls the get_coordinates() method of the TPinballComponent reference to get the sound position. This project uses SDL_mixer and there is a function called Mix_SetPosition() that allows placing a sound in the stereo field, by giving it a distance and an angle. We arbitrarily place the player's ears at the bottom of the table; we set the ears' height to half a table's length. Intensity of the stereo effect is directly related to this value; the farther the player's ears from the table, the narrowest the stereo picture gets, and vice-versa. From there we have all we need to calculate distance and angle; we do just that and position all the sounds. * Copy-paste typo fix.
2022-05-30 09:35:29 +02:00
float loader::play_sound(int soundIndex, TPinballComponent *soundSource, const char *info)
2020-10-25 15:17:26 +01:00
{
if (soundIndex <= 0)
return 0.0;
Implement stereo sound. (#138) * Implement stereo sound. Original Space Cadet has mono sound. To achieve stereo, the following steps were accomplished: - Add a game option to turn on/off stereo sound. Default is on. - TPinballComponent objects were extended with a method called get_coordinates() that returns a single 2D point, approximating the on-screen position of the object, re-mapped between 0 and 1 vertically and horizontally, {0, 0} being at the top-left. - For static objects like bumpers and lights, the coordinate refers to the geometric center of the corresponding graphic sprite, and is precalculated at initialization. - For ball objects, the coordinate refers to the geometric center of the ball, calculated during play when requested. - Extend all calls to sound-playing methods so that they include a TPinballComponent* argument that refers to the sound source, e.g. where the sound comes from. For instance, when a flipper is activated, its method call to emit a sound now includes a reference to the flipper object; when a ball goes under a SkillShotGate, its method call to emit a sound now includes a reference to the corresponding light; and so on. For some cases, like light rollovers, the sound source is taken from the ball that triggered the light rollover. For other cases, like holes, flags and targets, the sound source is taken from the object itself. For some special cases like ramp activation, sound source is taken from the nearest light position that makes sense. For all game-progress sounds, like mission completion sounds or ball drain sounds, the sound source is undefined (set to nullptr), and the Sound::PlaySound() method takes care of positioning them at a default location, where speakers on a pinball machine normally are. - Make the Sound::PlaySound() method accept a new argument, a TPinballComponent reference, as described above. If the stereo option is turned on, the Sound::PlaySound() method calls the get_coordinates() method of the TPinballComponent reference to get the sound position. This project uses SDL_mixer and there is a function called Mix_SetPosition() that allows placing a sound in the stereo field, by giving it a distance and an angle. We arbitrarily place the player's ears at the bottom of the table; we set the ears' height to half a table's length. Intensity of the stereo effect is directly related to this value; the farther the player's ears from the table, the narrowest the stereo picture gets, and vice-versa. From there we have all we need to calculate distance and angle; we do just that and position all the sounds. * Copy-paste typo fix.
2022-05-30 09:35:29 +02:00
Sound::PlaySound(sound_list[soundIndex].WavePtr, pb::time_ticks, soundSource, info);
2020-12-25 14:46:06 +01:00
return sound_list[soundIndex].Duration;
2020-10-25 15:17:26 +01:00
}
int loader::state_id(int groupIndex, int groupIndexOffset)
{
2021-01-28 16:01:26 +01:00
auto visualState = query_visual_states(groupIndex);
2020-10-25 15:17:26 +01:00
if (visualState <= 0)
return error(12, 24);
auto shortArr = reinterpret_cast<int16_t*>(loader_table->field(groupIndex, FieldTypes::ShortValue));
2020-10-25 15:17:26 +01:00
if (!shortArr)
return error(1, 24);
if (*shortArr != 200)
return error(5, 24);
if (groupIndexOffset > visualState)
return error(12, 24);
if (!groupIndexOffset)
2021-01-28 16:01:26 +01:00
return groupIndex;
2020-10-25 15:17:26 +01:00
2021-01-28 16:01:26 +01:00
groupIndex += groupIndexOffset;
shortArr = reinterpret_cast<int16_t*>(loader_table->field(groupIndex, FieldTypes::ShortValue));
2020-10-25 15:17:26 +01:00
if (!shortArr)
return error(1, 24);
if (*shortArr != 201)
2021-01-28 16:01:26 +01:00
return error(6, 24);
return groupIndex;
2020-10-25 15:17:26 +01:00
}
2020-10-30 13:26:00 +01:00
int loader::kicker(int groupIndex, visualKickerStruct* kicker)
{
if (groupIndex < 0)
return error(0, 20);
auto shortArr = reinterpret_cast<int16_t*>(loader_table->field(groupIndex, FieldTypes::ShortValue));
2020-10-30 13:26:00 +01:00
if (!shortArr)
return error(1, 20);
if (*shortArr != 400)
return error(4, 20);
auto floatArr = reinterpret_cast<float*>(loader_table->field(groupIndex, FieldTypes::FloatArray));
2020-10-30 13:26:00 +01:00
if (!floatArr)
return error(11, 20);
int floatArrLength = loader_table->field_size(groupIndex, FieldTypes::FloatArray) / 4;
2020-10-30 13:26:00 +01:00
if (floatArrLength <= 0)
return 0;
2021-01-28 16:01:26 +01:00
for (auto index = 0; index < floatArrLength;)
2020-10-30 13:26:00 +01:00
{
int floorVal = static_cast<int>(floor(*floatArr++));
switch (floorVal)
{
case 401:
2021-01-23 11:33:30 +01:00
kicker->Threshold = *floatArr;
2020-10-30 13:26:00 +01:00
break;
case 402:
2021-01-23 11:33:30 +01:00
kicker->Boost = *floatArr;
2020-10-30 13:26:00 +01:00
break;
case 403:
2021-01-23 11:33:30 +01:00
kicker->ThrowBallMult = *floatArr;
2020-10-30 13:26:00 +01:00
break;
case 404:
2022-05-20 10:51:00 +02:00
kicker->ThrowBallDirection = *reinterpret_cast<vector3*>(floatArr);
2021-01-23 11:33:30 +01:00
floatArr += 3;
2020-10-30 13:26:00 +01:00
index += 4;
break;
case 405:
2021-01-23 11:33:30 +01:00
kicker->ThrowBallAngleMult = *floatArr;
2020-10-30 13:26:00 +01:00
break;
case 406:
2021-01-23 11:33:30 +01:00
kicker->HardHitSoundId = get_sound_id(static_cast<int>(floor(*floatArr)));
2020-10-30 13:26:00 +01:00
break;
default:
return error(10, 20);
}
if (floorVal != 404)
{
floatArr++;
index += 2;
}
}
return 0;
}
2021-01-28 16:01:26 +01:00
int loader::query_visual(int groupIndex, int groupIndexOffset, visualStruct* visual)
2020-10-30 13:26:00 +01:00
{
default_vsi(visual);
if (groupIndex < 0)
return error(0, 18);
2021-01-28 16:01:26 +01:00
auto stateId = state_id(groupIndex, groupIndexOffset);
if (stateId < 0)
2020-10-30 13:26:00 +01:00
return error(16, 18);
2021-01-28 16:01:26 +01:00
auto bmp = loader_table->GetBitmap(stateId);
auto zMap = loader_table->GetZMap(stateId);
visual->Bitmap = { bmp, zMap };
2021-01-28 16:01:26 +01:00
auto shortArr = reinterpret_cast<int16_t*>(loader_table->field(stateId, FieldTypes::ShortArray));
2020-10-30 13:26:00 +01:00
if (shortArr)
{
unsigned int shortArrSize = loader_table->field_size(stateId, FieldTypes::ShortArray);
2021-01-28 16:01:26 +01:00
for (auto index = 0u; index < shortArrSize / 2;)
2020-10-30 13:26:00 +01:00
{
switch (shortArr[0])
2021-01-28 16:01:26 +01:00
{
case 100:
if (groupIndexOffset)
return error(7, 18);
break;
case 300:
if (material(shortArr[1], visual))
return error(15, 18);
break;
case 304:
visual->SoftHitSoundId = get_sound_id(shortArr[1]);
break;
case 400:
if (kicker(shortArr[1], &visual->Kicker))
return error(14, 18);
break;
case 406:
visual->Kicker.HardHitSoundId = get_sound_id(shortArr[1]);
break;
case 602:
visual->CollisionGroup |= 1 << shortArr[1];
break;
case 1100:
visual->SoundIndex4 = get_sound_id(shortArr[1]);
break;
case 1101:
visual->SoundIndex3 = get_sound_id(shortArr[1]);
break;
case 1500:
shortArr += 7;
index += 7;
break;
default:
2021-01-28 16:01:26 +01:00
return error(9, 18);
2020-10-30 13:26:00 +01:00
}
shortArr += 2;
index += 2;
2020-10-30 13:26:00 +01:00
}
}
2021-01-28 16:01:26 +01:00
if (!visual->CollisionGroup)
visual->CollisionGroup = 1;
auto floatArr = reinterpret_cast<float*>(loader_table->field(stateId, FieldTypes::FloatArray));
2020-10-30 13:26:00 +01:00
if (!floatArr)
return 0;
if (*floatArr != 600.0f)
2020-10-30 13:26:00 +01:00
return 0;
2021-01-28 16:01:26 +01:00
visual->FloatArrCount = loader_table->field_size(stateId, FieldTypes::FloatArray) / 4 / 2 - 2;
auto floatVal = static_cast<int>(floor(floatArr[1]) - 1.0f);
2021-01-28 16:01:26 +01:00
switch (floatVal)
2020-10-30 13:26:00 +01:00
{
2021-01-28 16:01:26 +01:00
case 0:
visual->FloatArrCount = 1;
break;
case 1:
visual->FloatArrCount = 2;
break;
default:
if (floatVal != visual->FloatArrCount)
2020-10-30 13:26:00 +01:00
return error(8, 18);
2021-01-28 16:01:26 +01:00
break;
2020-10-30 13:26:00 +01:00
}
2021-01-28 16:01:26 +01:00
visual->FloatArr = floatArr + 2;
2020-10-30 13:26:00 +01:00
return 0;
2021-01-28 16:01:26 +01:00
}