2022-05-19 01:51:26 -07:00
|
|
|
#include "light.h"
|
|
|
|
|
2022-09-15 02:38:23 -07:00
|
|
|
#include <math.h>
|
|
|
|
|
2022-06-18 07:44:17 -07:00
|
|
|
#include "map_defs.h"
|
2022-07-29 06:04:05 -07:00
|
|
|
#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
|
2022-06-18 07:44:17 -07:00
|
|
|
static int gLightLevel = LIGHT_LEVEL_MAX;
|
2022-05-19 01:51:26 -07:00
|
|
|
|
|
|
|
// light intensity per elevation per tile
|
|
|
|
// 0x59E994
|
2022-06-18 07:44:17 -07:00
|
|
|
static int gLightIntensity[ELEVATION_COUNT][HEX_GRID_SIZE];
|
2022-05-19 01:51:26 -07:00
|
|
|
|
|
|
|
// 0x47A8F0
|
|
|
|
int lightInit()
|
|
|
|
{
|
|
|
|
lightResetIntensity();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 0x47A8F8
|
|
|
|
int lightGetLightLevel()
|
|
|
|
{
|
|
|
|
return gLightLevel;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 0x47A908
|
|
|
|
void lightSetLightLevel(int lightLevel, bool shouldUpdateScreen)
|
|
|
|
{
|
|
|
|
int normalizedLightLevel = lightLevel + perkGetRank(gDude, PERK_NIGHT_VISION) * LIGHT_LEVEL_NIGHT_VISION_BONUS;
|
|
|
|
|
|
|
|
if (normalizedLightLevel < LIGHT_LEVEL_MIN) {
|
|
|
|
normalizedLightLevel = LIGHT_LEVEL_MIN;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (normalizedLightLevel > LIGHT_LEVEL_MAX) {
|
|
|
|
normalizedLightLevel = LIGHT_LEVEL_MAX;
|
|
|
|
}
|
|
|
|
|
|
|
|
int oldLightLevel = gLightLevel;
|
|
|
|
gLightLevel = normalizedLightLevel;
|
|
|
|
|
|
|
|
if (shouldUpdateScreen) {
|
|
|
|
if (oldLightLevel != normalizedLightLevel) {
|
|
|
|
tileWindowRefresh();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: Looks strange - it tries to clamp intensity as light level?
|
|
|
|
int _light_get_tile(int elevation, int tile)
|
|
|
|
{
|
|
|
|
if (!elevationIsValid(elevation)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!hexGridTileIsValid(tile)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int result = gLightIntensity[elevation][tile];
|
|
|
|
|
|
|
|
if (result >= 0x10000) {
|
|
|
|
result = 0x10000;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 0x47A9C4
|
|
|
|
int lightGetIntensity(int elevation, int tile)
|
|
|
|
{
|
|
|
|
if (!elevationIsValid(elevation)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!hexGridTileIsValid(tile)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return gLightIntensity[elevation][tile];
|
|
|
|
}
|
|
|
|
|
|
|
|
// 0x47A9EC
|
|
|
|
void lightSetIntensity(int elevation, int tile, int lightIntensity)
|
|
|
|
{
|
|
|
|
if (!elevationIsValid(elevation)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!hexGridTileIsValid(tile)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
gLightIntensity[elevation][tile] = lightIntensity;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 0x47AA10
|
|
|
|
void lightIncreaseIntensity(int elevation, int tile, int lightIntensity)
|
|
|
|
{
|
|
|
|
if (!elevationIsValid(elevation)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!hexGridTileIsValid(tile)) {
|
|
|
|
return;
|
|
|
|
}
|
2022-07-29 06:04:05 -07:00
|
|
|
|
2022-05-19 01:51:26 -07:00
|
|
|
gLightIntensity[elevation][tile] += lightIntensity;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 0x47AA48
|
|
|
|
void lightDecreaseIntensity(int elevation, int tile, int lightIntensity)
|
|
|
|
{
|
|
|
|
if (!elevationIsValid(elevation)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!hexGridTileIsValid(tile)) {
|
|
|
|
return;
|
|
|
|
}
|
2022-07-29 06:04:05 -07:00
|
|
|
|
2022-05-19 01:51:26 -07:00
|
|
|
gLightIntensity[elevation][tile] -= lightIntensity;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 0x47AA84
|
|
|
|
void lightResetIntensity()
|
|
|
|
{
|
|
|
|
for (int elevation = 0; elevation < ELEVATION_COUNT; elevation++) {
|
|
|
|
for (int tile = 0; tile < HEX_GRID_SIZE; tile++) {
|
|
|
|
gLightIntensity[elevation][tile] = 655;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-09-23 05:43:44 -07:00
|
|
|
|
|
|
|
} // namespace fallout
|