diff --git a/src/Battlescape/BattlescapeState.cpp b/src/Battlescape/BattlescapeState.cpp
index 9945818..0affc7f 100644
--- a/src/Battlescape/BattlescapeState.cpp
+++ b/src/Battlescape/BattlescapeState.cpp
@@ -461,6 +461,8 @@ BattlescapeState::BattlescapeState() : _reserve(0), _xBeforeMouseScrolling(0), _
_btnStats->onKeyboardPress((ActionHandler)&BattlescapeState::btnReloadClick, Options::keyBattleReload);
_btnStats->onKeyboardPress((ActionHandler)&BattlescapeState::btnPersonalLightingClick, Options::keyBattlePersonalLighting);
+ _btnStats->onKeyboardPress((ActionHandler)&BattlescapeState::btnNightVisionClick, Options::keyNightVisionToggle);
+
SDLKey buttons[] = {Options::keyBattleCenterEnemy1,
Options::keyBattleCenterEnemy2,
Options::keyBattleCenterEnemy3,
@@ -1300,6 +1302,15 @@ void BattlescapeState::btnPersonalLightingClick(Action *)
}
/**
+ * Toggles map-wide night vision (purely cosmetic).
+ * @param action Pointer to an action.
+ */
+void BattlescapeState::btnNightVisionClick(Action *action)
+{
+ _map->toggleNightVision();
+}
+
+/**
* Determines whether a playable unit is selected. Normally only player side units can be selected, but in debug mode one can play with aliens too :)
* Is used to see if stats can be displayed and action buttons will work.
* @return Whether a playable unit is selected.
diff --git a/src/Battlescape/BattlescapeState.h b/src/Battlescape/BattlescapeState.h
index 15f6073..776f2d3 100644
--- a/src/Battlescape/BattlescapeState.h
+++ b/src/Battlescape/BattlescapeState.h
@@ -167,6 +167,8 @@ public:
void btnReloadClick(Action *action);
https:/// Handler for clicking the lighting button.
void btnPersonalLightingClick(Action *action);
+ https:/// Handler for toggling the "night vision" mode.
+ void btnNightVisionClick(Action *action);
https:/// Determines whether a playable unit is selected.
bool playableUnitSelected();
https:/// Updates soldier name/rank/tu/energy/health/morale.
diff --git a/src/Battlescape/Map.cpp b/src/Battlescape/Map.cpp
index ec64c89..e30408c 100644
--- a/src/Battlescape/Map.cpp
+++ b/src/Battlescape/Map.cpp
@@ -108,6 +108,11 @@ Map::Map(Game *game, int width, int height, int x, int y, int visibleMapHeight)
_scrollMouseTimer->onTimer((SurfaceHandler)&Map::scrollMouse);
_scrollKeyTimer = new Timer(SCROLL_INTERVAL);
_scrollKeyTimer->onTimer((SurfaceHandler)&Map::scrollKey);
+ _fadeTimer = new Timer(FADE_INTERVAL);
+ _fadeTimer->onTimer((SurfaceHandler)&Map::fadeShade);
+ _fadeTimer->start();
+ _fadeShade = 16;
+ _nightVisionOn = false;
_camera->setScrollTimer(_scrollMouseTimer, _scrollKeyTimer);
_txtAccuracy = new Text(24, 9, 0, 0);
@@ -124,6 +129,7 @@ Map::~Map()
{
delete _scrollMouseTimer;
delete _scrollKeyTimer;
+ delete _fadeTimer;
delete _arrow;
delete _message;
delete _camera;
@@ -174,6 +180,7 @@ void Map::think()
{
_scrollMouseTimer->think(0, this);
_scrollKeyTimer->think(0, this);
+ _fadeTimer->think(0, this);
}
/**
@@ -417,7 +424,7 @@ void Map::drawTerrain(Surface *surface)
if (tile->isDiscovered(2))
{
- tileShade = tile->getShade();
+ tileShade = reShade(tile->getShade());
}
else
{
@@ -469,7 +476,7 @@ void Map::drawTerrain(Surface *surface)
int tileNorthShade, tileTwoNorthShade, tileWestShade, tileNorthWestShade, tileSouthWestShade;
if (tileNorth->isDiscovered(2))
{
- tileNorthShade = tileNorth->getShade();
+ tileNorthShade = reShade(tileNorth->getShade());
}
else
{
@@ -508,7 +515,7 @@ void Map::drawTerrain(Surface *surface)
Tile *tileTwoNorth = _save->getTile(mapPosition - Position(0,2,0));
if (tileTwoNorth->isDiscovered(2))
{
- tileTwoNorthShade = tileTwoNorth->getShade();
+ tileTwoNorthShade = reShade(tileTwoNorth->getShade());
}
else
{
@@ -529,7 +536,7 @@ void Map::drawTerrain(Surface *surface)
Tile *tileNorthWest = _save->getTile(mapPosition - Position(1,1,0));
if (tileNorthWest->isDiscovered(2))
{
- tileNorthWestShade = tileNorthWest->getShade();
+ tileNorthWestShade = reShade(tileNorthWest->getShade());
}
else
{
@@ -563,7 +570,7 @@ void Map::drawTerrain(Surface *surface)
Tile *tileSouthWest = _save->getTile(mapPosition + Position(-1, 1, 0));
if (tileSouthWest->isDiscovered(2))
{
- tileSouthWestShade = tileSouthWest->getShade();
+ tileSouthWestShade = reShade(tileSouthWest->getShade());
}
else
{
@@ -583,7 +590,7 @@ void Map::drawTerrain(Surface *surface)
BattleUnit *westUnit = tileWest->getUnit();
if (tileWest->isDiscovered(2))
{
- tileWestShade = tileWest->getShade();
+ tileWestShade = reShade(tileWest->getShade());
}
else
{
@@ -595,7 +602,7 @@ void Map::drawTerrain(Surface *surface)
{
if ((tileWest->getMapData(O_WESTWALL)->isDoor() || tileWest->getMapData(O_WESTWALL)->isUFODoor())
&& tileWest->isDiscovered(0))
- wallShade = tileWest->getShade();
+ wallShade = reShade(tileWest->getShade());
else
wallShade = tileWestShade;
tmpSurface->blitNShade(surface, screenPosition.x - tileOffset.x, screenPosition.y - tileWest->getMapData(O_WESTWALL)->getYOffset() + tileOffset.y, wallShade, true);
@@ -605,7 +612,7 @@ void Map::drawTerrain(Surface *surface)
{
if ((tileWest->getMapData(O_NORTHWALL)->isDoor() || tileWest->getMapData(O_NORTHWALL)->isUFODoor())
&& tileWest->isDiscovered(1))
- wallShade = tileWest->getShade();
+ wallShade = reShade(tileWest->getShade());
else
wallShade = tileWestShade;
tmpSurface->blitNShade(surface, screenPosition.x - tileOffset.x, screenPosition.y - tileWest->getMapData(O_NORTHWALL)->getYOffset() + tileOffset.y, wallShade, true);
@@ -699,7 +706,7 @@ void Map::drawTerrain(Surface *surface)
{
if ((tile->getMapData(O_WESTWALL)->isDoor() || tile->getMapData(O_WESTWALL)->isUFODoor())
&& tile->isDiscovered(0))
- wallShade = tile->getShade();
+ wallShade = reShade(tile->getShade());
else
wallShade = tileShade;
tmpSurface->blitNShade(surface, screenPosition.x, screenPosition.y - tile->getMapData(O_WESTWALL)->getYOffset(), wallShade);
@@ -710,7 +717,7 @@ void Map::drawTerrain(Surface *surface)
{
if ((tile->getMapData(O_NORTHWALL)->isDoor() || tile->getMapData(O_NORTHWALL)->isUFODoor())
&& tile->isDiscovered(1))
- wallShade = tile->getShade();
+ wallShade = reShade(tile->getShade());
else
wallShade = tileShade;
if (tile->getMapData(O_WESTWALL))
@@ -897,7 +904,7 @@ void Map::drawTerrain(Surface *surface)
tunit, part,
offset.x,
offset.y,
- ttile->getShade()
+ reShade(ttile->getShade())
);
}
}
@@ -1325,6 +1332,25 @@ void Map::keyboardPress(Action *action, State *state)
}
/**
+ * Handles map vision toggle mode.
+ */
+
+void Map::toggleNightVision()
+{
+ _nightVisionOn = not _nightVisionOn;
+}
+
+/**
+ * Handles fade-in and fade-out shade modification
+ * @param original tile/item/unit shade
+ */
+
+int Map::reShade(const int shade)
+{
+ return shade > _fadeShade ? _fadeShade : shade;
+}
+
+/**
* Handles keyboard releases on the map.
* @param action Pointer to an action.
* @param state State that the action handlers belong to.
@@ -1626,6 +1652,28 @@ void Map::scrollKey()
}
/**
+ * Modify the fade shade level if fade's in progress.
+ */
+void Map::fadeShade()
+{
+ bool hold = SDL_GetKeyState(NULL)[Options::keyNightVisionHold];
+ if (_nightVisionOn xor hold )
+ {
+ if (_fadeShade > 4)
+ {
+ --_fadeShade;
+ }
+ }
+ else
+ {
+ if (_fadeShade < _save->getGlobalShade())
+ {
+ ++_fadeShade;
+ }
+ }
+}
+
+/**
* Gets a list of waypoints on the map.
* @return A list of waypoints.
*/
diff --git a/src/Battlescape/Map.h b/src/Battlescape/Map.h
index ea2bd22..34f8ab2 100644
--- a/src/Battlescape/Map.h
+++ b/src/Battlescape/Map.h
@@ -46,8 +46,12 @@ class Map : public InteractiveSurface
{
private:
static const int SCROLL_INTERVAL = 15;
+ static const int FADE_INTERVAL = 23;
static const int BULLET_SPRITES = 35;
Timer *_scrollMouseTimer, *_scrollKeyTimer;
+ Timer *_fadeTimer;
+ int _fadeShade;
+ bool _nightVisionOn;
Game *_game;
SavedBattleGame *_save;
Surface *_arrow;
@@ -121,6 +125,8 @@ public:
void scrollMouse();
https:/// Keyboard-scrolls the camera.
void scrollKey();
+ https:/// fades in/out
+ void fadeShade();
https:/// Get waypoints vector.
std::vector<Position> *getWaypoints();
https:/// Set mouse-buttons' pressed state.
@@ -147,6 +153,11 @@ public:
void setBlastFlash(bool flash);
https:/// Check if the screen is flashing this.
bool getBlastFlash();
+ https:/// Modify shade for fading
+ int reShade(const int shade);
+ https:/// toggle the night-vision mode
+ void toggleNightVision();
+
};
}
diff --git a/src/Engine/Options.cpp b/src/Engine/Options.cpp
index 4537766..5b35eb9 100644
--- a/src/Engine/Options.cpp
+++ b/src/Engine/Options.cpp
@@ -296,6 +296,9 @@ void create()
_info.push_back(OptionInfo("keyBattleActionItem5", &keyBattleActionItem5, SDLK_5, "STR_ACTION_ITEM_5", "STR_OXCE"));
_info.push_back(OptionInfo("keyToggleQuickSearch", &keyToggleQuickSearch, SDLK_q, "STR_TOGGLE_QUICK_SEARCH", "STR_OXCE"));
+ _info.push_back(OptionInfo("keyNightVisionToggle", &keyNightVisionToggle, SDLK_SCROLLOCK, "STR_TOGGLE_NIGHT_VISION", "STR_OXCE"));
+ _info.push_back(OptionInfo("keyNightVisionHold", &keyNightVisionHold, SDLK_BACKQUOTE, "STR_HOLD_NIGHT_VISION", "STR_OXCE"));
+
#ifdef __MORPHOS__
_info.push_back(OptionInfo("FPS", &FPS, 15, "STR_FPS_LIMIT", "STR_GENERAL"));
_info.push_back(OptionInfo("FPSInactive", &FPSInactive, 15, "STR_FPS_INACTIVE_LIMIT", "STR_GENERAL"));
diff --git a/src/Engine/Options.inc.h b/src/Engine/Options.inc.h
index 3fc086c..53a7780 100644
--- a/src/Engine/Options.inc.h
+++ b/src/Engine/Options.inc.h
@@ -52,6 +52,8 @@ OPT bool showAllCommendations;
OPT bool removeWoundedFromTraining;
OPT bool autoAssignPilots;
+OPT SDLKey keyNightVisionToggle, keyNightVisionHold;
+
https:// Flags and other stuff that don't need OptionInfo's.
OPT bool mute, reload, newOpenGL, newScaleFilter, newHQXFilter, newXBRZFilter;
OPT int newDisplayWidth, newDisplayHeight, newBattlescapeScale, newGeoscapeScale;