fallout2-ce/src/light.cc

144 lines
2.7 KiB
C++
Raw Normal View History

2022-05-19 01:51:26 -07:00
#include "light.h"
2023-01-03 12:00:38 -08:00
#include <algorithm>
2022-09-15 02:38:23 -07:00
2022-06-18 07:44:17 -07:00
#include "map_defs.h"
#include "object.h"
2022-05-19 01:51:26 -07:00
#include "perk.h"
#include "tile.h"
2022-09-23 05:43:44 -07:00
namespace fallout {
2022-06-18 07:44:17 -07:00
// 20% of max light per "Night Vision" rank
#define LIGHT_LEVEL_NIGHT_VISION_BONUS (65536 / 5)
2022-05-19 01:51:26 -07:00
// 0x51923C
2023-01-03 12:56:52 -08:00
static int gAmbientIntensity = LIGHT_INTENSITY_MAX;
2022-05-19 01:51:26 -07:00
// light intensity per elevation per tile
// 0x59E994
2023-01-03 12:56:52 -08:00
static int gTileIntensity[ELEVATION_COUNT][HEX_GRID_SIZE];
2022-05-19 01:51:26 -07:00
// 0x47A8F0
int lightInit()
{
2023-01-03 12:56:52 -08:00
lightResetTileIntensity();
2022-05-19 01:51:26 -07:00
return 0;
}
2023-01-03 12:56:52 -08:00
// 0x47A8F0
void lightReset()
2022-05-19 01:51:26 -07:00
{
2023-01-03 12:56:52 -08:00
lightResetTileIntensity();
2022-05-19 01:51:26 -07:00
}
2023-01-03 12:56:52 -08:00
// 0x47A8F0
void lightExit()
2022-05-19 01:51:26 -07:00
{
2023-01-03 12:56:52 -08:00
lightResetTileIntensity();
}
2022-05-19 01:51:26 -07:00
2023-01-03 12:56:52 -08:00
// 0x47A8F8
int lightGetAmbientIntensity()
{
return gAmbientIntensity;
}
2022-05-19 01:51:26 -07:00
2023-01-03 12:56:52 -08:00
// 0x47A908
void lightSetAmbientIntensity(int intensity, bool shouldUpdateScreen)
{
int adjustedIntensity = intensity + perkGetRank(gDude, PERK_NIGHT_VISION) * LIGHT_LEVEL_NIGHT_VISION_BONUS;
int normalizedIntensity = std::clamp(adjustedIntensity, LIGHT_INTENSITY_MIN, LIGHT_INTENSITY_MAX);
2022-05-19 01:51:26 -07:00
2023-01-03 12:56:52 -08:00
int oldAmbientIntensity = gAmbientIntensity;
gAmbientIntensity = normalizedIntensity;
2022-05-19 01:51:26 -07:00
if (shouldUpdateScreen) {
2023-01-03 12:56:52 -08:00
if (oldAmbientIntensity != normalizedIntensity) {
2022-05-19 01:51:26 -07:00
tileWindowRefresh();
}
}
}
2023-01-03 12:00:38 -08:00
// 0x47A980
2023-01-03 12:56:52 -08:00
int lightGetTileIntensity(int elevation, int tile)
2022-05-19 01:51:26 -07:00
{
if (!elevationIsValid(elevation)) {
return 0;
}
if (!hexGridTileIsValid(tile)) {
return 0;
}
2023-01-03 12:56:52 -08:00
return std::min(gTileIntensity[elevation][tile], LIGHT_INTENSITY_MAX);
2022-05-19 01:51:26 -07:00
}
// 0x47A9C4
2023-01-03 12:56:52 -08:00
int lightGetTrueTileIntensity(int elevation, int tile)
2022-05-19 01:51:26 -07:00
{
if (!elevationIsValid(elevation)) {
return 0;
}
if (!hexGridTileIsValid(tile)) {
return 0;
}
2023-01-03 12:56:52 -08:00
return gTileIntensity[elevation][tile];
2022-05-19 01:51:26 -07:00
}
// 0x47A9EC
2023-01-03 12:56:52 -08:00
void lightSetTileIntensity(int elevation, int tile, int intensity)
2022-05-19 01:51:26 -07:00
{
if (!elevationIsValid(elevation)) {
return;
}
if (!hexGridTileIsValid(tile)) {
return;
}
2023-01-03 12:56:52 -08:00
gTileIntensity[elevation][tile] = intensity;
2022-05-19 01:51:26 -07:00
}
// 0x47AA10
2023-01-03 12:56:52 -08:00
void lightIncreaseTileIntensity(int elevation, int tile, int intensity)
2022-05-19 01:51:26 -07:00
{
if (!elevationIsValid(elevation)) {
return;
}
if (!hexGridTileIsValid(tile)) {
return;
}
2023-01-03 12:56:52 -08:00
gTileIntensity[elevation][tile] += intensity;
2022-05-19 01:51:26 -07:00
}
// 0x47AA48
2023-01-03 12:56:52 -08:00
void lightDecreaseTileIntensity(int elevation, int tile, int intensity)
2022-05-19 01:51:26 -07:00
{
if (!elevationIsValid(elevation)) {
return;
}
if (!hexGridTileIsValid(tile)) {
return;
}
2023-01-03 12:56:52 -08:00
gTileIntensity[elevation][tile] -= intensity;
2022-05-19 01:51:26 -07:00
}
// 0x47AA84
2023-01-03 12:56:52 -08:00
void lightResetTileIntensity()
2022-05-19 01:51:26 -07:00
{
for (int elevation = 0; elevation < ELEVATION_COUNT; elevation++) {
for (int tile = 0; tile < HEX_GRID_SIZE; tile++) {
2023-01-03 12:56:52 -08:00
gTileIntensity[elevation][tile] = 655;
2022-05-19 01:51:26 -07:00
}
}
}
2022-09-23 05:43:44 -07:00
} // namespace fallout