How to add new CBMs


So I checked Guide to adding new content to CDDA for first time modders , JSON_INFO and JSON_FLAGS and bionics.cpp. But I didn’t find what I was looking for.

I’d like to add LED Tattoo as a cosmetic CBM that could also serve as a nightlight. But I don’t understand how to add the nightlight effect. CBM effect seems to be hardcoded in bionics.cpp so I tried to find how cranial flashlight works since I thought It would be similar to nightlight. But Its only flag is BIONIC_TOGGLED which doesn’t specify what it does and in bionics.cpp under player::activate_bionic there’s no entry for bio_flashlight.

Can anyone help me to understand how this works ?


The reason I didn’t provide much detail on CBMs is that CBMs effects are hardcoded, which means you need to know C++ programming to do much with them.

But let’s look at your question. First, let’s find out what the C++ code does with bio_flashlight:

$ git grep -n bio_flashlight src
src/player.cpp:194:static const bionic_id bio_flashlight( "bio_flashlight" );
src/player.cpp:2645:    if( lumination < 60 && has_active_bionic( bio_flashlight ) ) {

The first instance is clearly just a static definition and can be ignored.

The second one is more interesting:

float player::active_light() const
    float lumination = 0;

    int maxlum = 0;
    has_item_with( [&maxlum]( const item & it ) {
        const int lumit = it.getlight_emit();
        if( maxlum < lumit ) {
            maxlum = lumit;
        return false; // continue search, otherwise has_item_with would cancel the search
    } );

    lumination = static_cast<float>( maxlum );

    if( lumination < 60 && has_active_bionic( bio_flashlight ) ) {
        lumination = 60;
    } else if( lumination < 25 && has_artifact_with( AEP_GLOW ) ) {
        lumination = 25;
    } else if( lumination < 5 && has_effect( effect_glowing ) ) {
        lumination = 5;
    return lumination;

So that’s how a bionic flashlight works. You can either add a check for the bionic_led_tattoo here and give it some small level of lumination, or have the activated bionic_led_tattoo give the effect_glowing effect.

Hope that helps. Learn to use command line git, because git grep is your friend for actual code development.


Thanks a lot !
Indeed git grep is pretty useful !