# Anyone familiar with color code?

**URL:** <https://discourse.cataclysmdda.org/t/anyone-familiar-with-color-code/15532>\
**Category:** The Toolbox\
**Created:** [May 20, 2018, 3:29pm UTC](https://discourse.cataclysmdda.org/t/anyone-familiar-with-color-code/15532 "2018-05-20T15:29:31Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![John\_Candlebury](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/john_candlebury/32/6437_2.png) [@John\_Candlebury](https://discourse.cataclysmdda.org/u/John_Candlebury)\
**Post date:** [May 20, 2018, 3:29pm UTC](https://discourse.cataclysmdda.org/t/anyone-familiar-with-color-code/15532/1 "2018-05-20T15:29:31Z")

</div>

Ive been looking for the cause of issue [#23759](https://github.com/CleverRaven/Cataclysm-DDA/issues/23759) because it bothers me to the point of unplayability.

So the issue seems related to the hilite function in colors.cpp:

```
nc_color hilite( nc_color c )
{
    const nc_color color = all_colors.get_highlight( c, HL_BLUE );
    return ( ( int )color > 0 ) ? color : h_white;
}

```

It seems that the last line always evaluates false and returns h\_white, so whatever happens to the color variable doesnt actually matter.

However changing the line to

```
return color;

```

Doesn’t actually work, since supposed highlighted tiles will just turn black.

My best bet is that its because the variable color is probably gibberish instead of what it should actually be, and that the error lies in the get\_highlight function. However by this point I get lost

```
nc_color color_manager::get_highlight( const nc_color color, const hl_enum bg ) const
{
    const color_id id = color_to_id( color );
    const color_struct &st = color_array[id];
    const auto &hl = st.highlight;
    return hl[bg];
}

```

Would someone mind giving me a brief explanation of how this function works?

---

<div class="post-metadata">

**Author:** ![syler1983](https://avatars.discourse-cdn.com/v4/letter/s/9e8a1a/32.png) [@syler1983](https://discourse.cataclysmdda.org/u/syler1983)\
**Post date:** [May 22, 2018, 2:12pm UTC](https://discourse.cataclysmdda.org/t/anyone-familiar-with-color-code/15532/2 "2018-05-22T14:12:13Z")

</div>

> Would someone mind giving me a brief explanation of how this function works?

_nc\_color hilite( nc\_color c )_ returns the highlighted (blue background) color by finding it in color\_array (get\_highlight). The thing is that the color and the highlighted color - are two different colors.  
Here is a search in the color\_array:

> const color\_id id = color\_to\_id( color );  
> const color\_struct &st = color\_array[id];

And here is a search for requested highlighted color:

> const auto &hl = st.highlight;  
> return hl[bg];

_highlight_ is an array of all highlighted colors values for current color (like blue highlighted in red, blue highlighted in white, etc.). These array build in corresponse with an _hl\_enum_.

The only reason _( int )color \> 0_ evaluates false (as far as i can tell) is here:

> const auto &hl = st.highlight;  
> return hl[bg];

Requested color doesn’t have initialized elements in _highlight_ array.  
If you’ll look into _void color\_manager::finalize()_ you’ll see, that there ARE colors with no highlight array initialization:

> ```
> const size_t underscore_num = std::count( root.begin(), root.end(), '_' ) -
> ( root.find( "light_" ) != std::string::npos ) -
> ( root.find( "dark_" ) != std::string::npos );
> // do not try to highlight color pairs, highlighted, background, and invalid colors
> if( my_name.substr( 0, 2 ) == "c_" && root != "unset" && underscore_num < 1 ) {
> for( size_t j = 0; j < NUM_HL; j++ ) {
> entry.highlight[j] = highlight_from_names( my_name, hilights[j] );
> }
> }
> }
> 
> ```

These colors are basically already backgrounded colors.  
That means that when the last line in _hilite_ evaluates false argument _nc\_color c_ is already highlighted (or has a background).

---

<div class="post-metadata">

**Author:** ![syler1983](https://avatars.discourse-cdn.com/v4/letter/s/9e8a1a/32.png) [@syler1983](https://discourse.cataclysmdda.org/u/syler1983)\
**Post date:** [May 22, 2018, 4:47pm UTC](https://discourse.cataclysmdda.org/t/anyone-familiar-with-color-code/15532/4 "2018-05-22T16:47:53Z")

</div>

From Github issue:

> All furniture that contains items, monsters that are stunned or are friendly, and anything else that gets a blue highlight dynamically applied will lose its symbol color and turn white on a blue background.

I have some contrary examples:  
Furniture that contains items and has very dark lighting, piles of items on very dark tiles and house floor tiles in e’x’amine mode will not lose their symbol color. All objects/monsters with black or dark\_gray colors will not lose their color (stunned zombie necromancers, etc.).

So the problem is not in _hilite_ and _get\_highlight_ functions.

May be it’s worthwhile to debug _color\_array[i].highlight[HL\_BLUE]_ and check, do all basic (with black background: def\_c\_green, def\_c\_blue, etc.) colors have _highlight[HL\_BLUE]_ initialized.

---

<div class="post-metadata">

**Author:** ![John\_Candlebury](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/john_candlebury/32/6437_2.png) [@John\_Candlebury](https://discourse.cataclysmdda.org/u/John_Candlebury)\
**Post date:** [May 24, 2018, 12:34am UTC](https://discourse.cataclysmdda.org/t/anyone-familiar-with-color-code/15532/5 "2018-05-24T00:34:08Z")

</div>

Thank you Syler!  
Actually I think your counter example demonstrates that its a lot of things that are borked, for example, brown colored furniture wont highlight at all when examined!

I’ll check the color array as you say, seems like the problem lies there
