aliens

Author Topic: Any way to make your gals emit light on night missions?  (Read 38316 times)

Offline Stoddard

  • Colonel
  • ****
  • Posts: 485
  • in a fey mood
    • View Profile
    • Linux builds & stuff
Re: Any way to make your gals emit light on night missions?
« Reply #45 on: September 02, 2016, 11:46:15 am »
Ok, here goes:

Toggle bound to scroll-lock
Hold bound to backtick (under escape)

Hold inverts if toggle was toggled.

Both seem to be unused.

Keybindings added to options menu, all variables and methods renamed ten times.


Spoiler:
Code: [Select]
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;

Offline Yankes

  • Commander
  • *****
  • Posts: 3322
    • View Profile
Re: Any way to make your gals emit light on night missions?
« Reply #46 on: September 02, 2016, 12:38:13 pm »
Why so complicated?

https://vid.me/0YHL

Press alt a little longer and it all lights up. Release and it fades back.

Took all of two hours thinking of, coding, debugging, fighting with a screencapture program, uploading ...


This is my a) case, or at least how I image it could be implemented. Keep gameplay shade alone but alter display one.
 

Offline Stoddard

  • Colonel
  • ****
  • Posts: 485
  • in a fey mood
    • View Profile
    • Linux builds & stuff
Re: Any way to make your gals emit light on night missions?
« Reply #47 on: September 02, 2016, 01:23:05 pm »
This is my a) case, or at least how I image it could be implemented. Keep gameplay shade alone but alter display one.

Yes, now I see it's exactly that. When I started reading the topic though, all the formulas and stuff...


Now for the final installment:


Palette hack - classic green NV

https://vid.me/DHtc

This was ridiculously easy to do. But a) it's slow  and b) gals/units aren't shaded.  Maybe it's fine this way, maybe not. In any case, I looked at the unit draw code and called it a day.

Patch:

https://gist.github.com/StoddardOXC/3bb5c59841b7f2fd7e44dfbf1fc7ac04


« Last Edit: September 02, 2016, 01:24:46 pm by Stoddard »

Offline Dioxine

  • Commander
  • *****
  • Posts: 5455
  • punk not dead
    • View Profile
    • Nocturnal Productions
Re: Any way to make your gals emit light on night missions?
« Reply #48 on: September 02, 2016, 01:44:14 pm »

This was ridiculously easy to do. But a) it's slow  and b) gals/units aren't shaded.  Maybe it's fine this way, maybe not. In any case, I looked at the unit draw code and called it a day.


Great! Actually it's great the units stay as they are, much easier to tell them apart. If Meridian adds this, I'd like a ruleset option to choose which palette should be used (so instead of green NV, people can make orange or whatever).

Offline Yankes

  • Commander
  • *****
  • Posts: 3322
    • View Profile
Re: Any way to make your gals emit light on night missions?
« Reply #49 on: September 02, 2016, 02:12:27 pm »
This was ridiculously easy to do. But a) it's slow  and b) gals/units aren't shaded.  Maybe it's fine this way, maybe not. In any case, I looked at the unit draw code and called it a day.
a) slow? It should be barely difference between normal drawing and recolored drawing. Most of it code is same.
b) It will be hard, primary because unit can have user defined recoloring. Only way I see this could be fixed is add second pass after user recoloring.


Offline Stoddard

  • Colonel
  • ****
  • Posts: 485
  • in a fey mood
    • View Profile
    • Linux builds & stuff
Re: Any way to make your gals emit light on night missions?
« Reply #50 on: September 02, 2016, 02:19:54 pm »
a) slow? It should be barely difference between normal drawing and recolored drawing. Most of it code is same.
That was my impression, though a glance at the code says it should not differ at all. Maybe it was eclipse eating all the cpu  :-\

b) It will be hard, primary because unit can have user defined recoloring. Only way I see this could be fixed is add second pass after user recoloring.

Thought as much. Maybe later I'll take a look how that would look like. There isn't too many pixels in the units after all.

Offline Dioxine

  • Commander
  • *****
  • Posts: 5455
  • punk not dead
    • View Profile
    • Nocturnal Productions
Re: Any way to make your gals emit light on night missions?
« Reply #51 on: September 02, 2016, 02:46:40 pm »
Do as you will, but leave the version w/o unit recolors as well, since it's easier to read for the player.

Offline rezaf

  • Captain
  • ***
  • Posts: 70
    • View Profile
Re: Any way to make your gals emit light on night missions?
« Reply #52 on: September 02, 2016, 05:02:26 pm »
This is AMAZING work Stoddard.  8)

Now, how do I get it into my version of the game? Do I have to compile it myself?

Offline Arthanor

  • Commander
  • *****
  • Posts: 2488
  • XCom Armoury Quartermaster
    • View Profile
Re: Any way to make your gals emit light on night missions?
« Reply #53 on: September 02, 2016, 06:29:04 pm »
That looks amazing! Exactly what I was hoping for. Really cool work! Starting a new compilation with the NV now :)

Thanks Stoddard

Offline HelmetHair

  • Colonel
  • ****
  • Posts: 360
  • He who laughs last thinks fastest.
    • View Profile
Re: Any way to make your gals emit light on night missions?
« Reply #54 on: September 02, 2016, 06:42:14 pm »
WOW!

can we have different colors as well?

like shades of red, orange, green?

In any event.... NICE FUCKING WORK!

Online Meridian

  • Global Moderator
  • Commander
  • *****
  • Posts: 9047
    • View Profile
Re: Any way to make your gals emit light on night missions?
« Reply #55 on: September 02, 2016, 06:50:50 pm »
can we have different colors as well?
like shades of red, orange, green?

Great! Actually it's great the units stay as they are, much easier to tell them apart. If Meridian adds this, I'd like a ruleset option to choose which palette should be used (so instead of green NV, people can make orange or whatever).

Yes, I am adding this (with a few tweaks) today.

How did you mean to change the color? Globally? Or should it depend on something? I like the green btw.

Offline HelmetHair

  • Colonel
  • ****
  • Posts: 360
  • He who laughs last thinks fastest.
    • View Profile
Re: Any way to make your gals emit light on night missions?
« Reply #56 on: September 02, 2016, 07:21:33 pm »
Meridian,

If you were talking to me... I meant it in actually a few ways... I wasn't clear. I got excited :P

1. Could the player change the color of the night vision effect. Some folks are colorblind. (not me, I like green)

2. Could a particular NV effect color be applied to different units at a time. I'm not sure if I'm being clear but whatever.
So like if you had a gal with no NVGs on and so where to have a reddish colored effect to reflect that she's using her natural night sight vs a green superior nightvision of a gal wearing NVGs. So visual clues?

Huge and mushy run on sentence... 

3. could different types of NV gear have defined larger night sight ranges and as such have different colored effects.

4, Monster vision.... YEAH!

Anyway, have a great day!

Online Meridian

  • Global Moderator
  • Commander
  • *****
  • Posts: 9047
    • View Profile
Re: Any way to make your gals emit light on night missions?
« Reply #57 on: September 02, 2016, 08:15:11 pm »
Meridian,
If you were talking to me... I meant it in actually a few ways... I wasn't clear. I got excited :P
1. Could the player change the color of the night vision effect. Some folks are colorblind. (not me, I like green)
2. Could a particular NV effect color be applied to different units at a time. I'm not sure if I'm being clear but whatever.
So like if you had a gal with no NVGs on and so where to have a reddish colored effect to reflect that she's using her natural night sight vs a green superior nightvision of a gal wearing NVGs. So visual clues?
Huge and mushy run on sentence... 
3. could different types of NV gear have defined larger night sight ranges and as such have different colored effects.
4, Monster vision.... YEAH!
Anyway, have a great day!

1. No, that is a little bit too much... I don't know much about color blindness, but I think the difference here was between seeing nothing and seeing something, color shouldn't matter much.

2. Currently this is a global effect (from Commander's view if you wish).... but making it depend on the selected unit is possible and maybe would be a nice touch... I'll try it later!

3. There is no support for NV gear yet... but Surrealistik and Solarius have asked for it a few times... I have it on my todolist with low prio. They could have different color effects, yeah, that would make sense.

4. What? :)

Offline Dioxine

  • Commander
  • *****
  • Posts: 5455
  • punk not dead
    • View Profile
    • Nocturnal Productions
Re: Any way to make your gals emit light on night missions?
« Reply #58 on: September 02, 2016, 09:35:10 pm »
Like I said, I'd make the color modifiable by ruleset. Also available by default, not some special vision gear. However, this can be used later for other effects, like simulating underwater (constant blue glow) or said extra modes of vision (I see no use for this - it's better to have all spotted enemies on the basic vision type - but maybe I' wrong).

Online Meridian

  • Global Moderator
  • Commander
  • *****
  • Posts: 9047
    • View Profile
Re: Any way to make your gals emit light on night missions?
« Reply #59 on: September 02, 2016, 11:26:07 pm »
Like I said, I'd make the color modifiable by ruleset.

I was asking if it should be global, per terrain, per mission, per deployment, etc.
I made a global one anyway:

Code: [Select]
interfaces:
  - type: battlescape
    elements:
      - id: nightVision
        color: 5 # green