I'm not sure what you've already gathered, but I can tell you this:
When rendering pallets, the game needs the map's lighting settings.
The values in the map are multiplied by the values in the palet files. Ambient is the number of brightness added per higher level (tiles that have higher z-index).
Here's some code that calculates the used palets from the lighting section.
Code:
struct Lighting {
double level;
double ambient;
double red;
double green;
double blue;
Lighting();
Lighting(const INI_Section& ini);
void Read(const INI_Section& ini);
};
void Palet::Initialize(shared_ptr<File> f, const Lighting& l, bool greyscale) {
// Level is the ammount of "more white" that is gained by highening tiles
// Ambient is the overall ammount of light/darkness
// Red, green and blue define alterations in respective colors
// Initialize palet from file
vector<unsigned char> data;
f->read(data, 768);
// load greyscales if needed
if (greyscale)
memcpy(&data[16*3], greyscales, 16 * 3);
double ambient = l.ambient;
// Add colors for 15 heights, each time adding level to ambient
for (int j = 0; j < 15; j++) {
// Three bytes per color, 256 colors
for (int i = 0; i < 768; i += 3) {
// shift 2 bits, only first 6 are used
// don't go over 255, that'd look weird :D
unsigned char r = std::min(
255, static_cast<int>(ambient * l.red * (data[i+0]<<2)));
unsigned char g = std::min(
255, static_cast<int>(ambient * l.green * (data[i+1]<<2)));
unsigned char b = std::min(
255, static_cast<int>(ambient * l.blue * (data[i+2]<<2)));
// Stored as int, although only first 24 bits are going to be used
// Alignment required anyway
colors.push_back(b + 256 * g + 65536 * r);
}
ambient += l.level;
}
}
// returns pointer to a modified palet, can be used to draw SHP/TMP
// images with some adjusted form of light
int* Palet::Get_Colors(int Height) {
return &colors[0] + 256 * Height;
}
Lighting L(myMap.Get_INI_Section("Lighting"));
Palet p_iso;
p_iso.Initialize(vfs.open("isosno.pal"), L);