Page 1 of 1

Contamination hack

PostPosted: Sunday, 14th September 2014, 23:11
by skjarl
I'm trying to hack the contamination lamp (I think that's the word the devs use for these status effects in the HUD) to give me a numeric value for contamination level rather than the mostly useless color-coded word "contam". I've been all over output.cc and several other source files. I'm sure it's obvious, but I seem to be missing it. Can anyone tell me precisely where the I should be looking to modify this?

Re: Contamination hack

PostPosted: Sunday, 14th September 2014, 23:37
by Patashu
status.cc

  Code:
static void _describe_glow(status_info* inf)
{
    const int cont = get_contamination_level();
    if (cont > 0)
    {
        inf->light_colour = DARKGREY;
        if (cont > 1)
            inf->light_colour = _bad_ench_colour(cont, 3, 4);
        if (cont > 1
#if TAG_MAJOR_VERSION == 34
                || you.species != SP_DJINNI
#endif
                )
            inf->light_text = "Contam";
    }

    if (cont > 0)
    {
        inf->short_text =
                 (cont == 1) ? "very slightly " :
                 (cont == 2) ? "slightly " :
                 (cont == 3) ? "" :
                 (cont == 4) ? "moderately " :
                 (cont == 5) ? "heavily "
                             : "really heavily ";
        inf->short_text += "contaminated";
        inf->long_text = describe_contamination(cont);
    }
}


player.cc
  Code:
int get_contamination_level()
{
    const int glow = you.magic_contamination;

    if (glow > 60000)
        return glow / 20000 + 3;
    if (glow > 40000)
        return 5;
    if (glow > 25000)
        return 4;
    if (glow > 15000)
        return 3;
    if (glow > 5000)
        return 2;
    if (glow > 0)
        return 1;

    return 0;
}


status.cc

  Code:
bool fill_status_info(int status, status_info* inf)
{
...
    case STATUS_CONTAMINATION:
        _describe_glow(inf);
        break;
...
}


So what you want to do is something like this one-line change:

  Code:
static void _describe_glow(status_info* inf)
{
    const int cont = get_contamination_level();
    if (cont > 0)
    {
        inf->light_colour = DARKGREY;
        if (cont > 1)
            inf->light_colour = _bad_ench_colour(cont, 3, 4);
        if (cont > 1
#if TAG_MAJOR_VERSION == 34
                || you.species != SP_DJINNI
#endif
                )
            inf->light_text = make_stringf("Contam %d", (int)you.magic_contamination);
    }

    if (cont > 0)
    {
        inf->short_text =
                 (cont == 1) ? "very slightly " :
                 (cont == 2) ? "slightly " :
                 (cont == 3) ? "" :
                 (cont == 4) ? "moderately " :
                 (cont == 5) ? "heavily "
                             : "really heavily ";
        inf->short_text += "contaminated";
        inf->long_text = describe_contamination(cont);
    }
}

Re: Contamination hack

PostPosted: Monday, 15th September 2014, 00:39
by skjarl
That gave me precisely what I wanted and it's awesome. Thank you, Patashu. I'm not sure how I missed that in player.cc. I think I had my case sensitivity turned on when I was searching.

Re: Contamination hack

PostPosted: Monday, 15th September 2014, 00:52
by Patashu
skjarl wrote:That gave me precisely what I wanted and it's awesome. Thank you, Patashu. I'm not sure how I missed that in player.cc. I think I had my case sensitivity turned on when I was searching.

I hate when I do that! :)

Re: Contamination hack

PostPosted: Monday, 15th September 2014, 05:58
by Bloax
The worst thing you could ever do is search with case sensitivity in the crawl codebase, so remember that.

Re: Contamination hack

PostPosted: Monday, 15th September 2014, 15:30
by skjarl
Yes, I know. I've been coding in one way or another for 27 years. I was looking for something very specific earlier and forgot to turn it off.