Why do I need to redefine mtype (or zom)?

bit of a crosspost

[quote=“pisskop”]Is this the proper thread to cry tears into?

I have a chunk of c++ here. The former

    // Generate bodies / zombies
    rn = rng(15, 20);
    for (int i = 0; i < rn; i++) {
        int zx = rng(0, SEEX * 2 - 1), zy = rng(0, SEEY * 2 - 1);
        if (passable(zx, zy)) {
            if (furn(zx, zy) == f_bed || one_in(3)) {
                add_item( zx, zy, item::make_corpse() );
            } else {
                mtype_id zom = mon_zombie;
                if (one_in(6)) {
                    zom = mon_zombie_spitter;
                } else if (!one_in(3)) {
                    zom = mon_boomer;
                }
                add_spawn(zom, 1, zx, zy);
            }
        } else {
            //This is a wall: try again
            i--;
        }
    }

Works

this:

    // Generate bodies / zombies
    rn = rng(50, 70);
    for (int i = 0; i < rn; i++) {
        int zx = rng(0, SEEX * 2 - 1), zy = rng(0, SEEY * 2 - 1);
        if (passable(zx, zy)) {
            if (furn(zx, zy) == f_bed || one_in(3)) {
                add_item( zx, zy, item::make_corpse() );
            } else {
                mtype_id zom = mon_zombie;
            } if (one_in(50)) {
                    zom = mon_zombie_child_scorched;
                } else if (one_in(25)) {
                    zom = mon_zombie_gasbag;
                } else if (one_in(20)) {
                    zom = mon_zombie_snotgobbler;
                } else if (one_in(10)) {
                    zom = mon_zombie_spitter;
                } else if (one_in(10)) {
                    zom = mon_zombie_child;
                } else if (one_in(6)) {
                    zom = mon_zombie_acidic;
                } else if (one_in(3)) {
                    zom = mon_boomer;
                }
                add_spawn(zom, 1, zx, zy);
            }
        } else {
            //This is a wall: try again
            i--;
        }
    }

Throws errors about zom not being defined. I dont know. If I add a mtype_id before zom they read (and then the line add_spawn(zom, 1, zx, zy); fails to read ‘zom’), but I shouldnt have to? zom is simply shorthand for a specific group of monsters. I am sure Ive otherwise defined the specific critters.

all Im doing is extending the concept of spawning a specified set of critters based upon a dice-roll, correct?[/quote]

in case you wanna know where I got this

I’ve not actually done any cata work, but there seems to be a logic error in your code.

In the base code, you got:

if(condition for corpse){stuff}
else{defines zom, then rolls to see if its a special}

Whereas your code has:

if(condition for corpse){stuff}
else{defines zom}
if{then we change what might be in zom}

Its throwing up because its possible to have zom not be defined by never entering the else part of the statement, so the code wouldn’t work half the time. Either move the if statements into the else statement, or define zom beforehand.

Do not add zombies directly to hardcoded mapgen, this is outdated and horrible to maintain. Not to mention that it ignores zombie spawn density.

Wrap them in a group and add a group spawn, like this:

Where x1, y1 are both 0, and x2 and y2 are both 23. This should be invoked outside the loop that places corpses. No need to check for walls.

And the error you committed (just for info, you shouldn’t fix it using your old method) is that you closed the brace after defining “zom”.

} else { mtype_id zom = mon_zombie; } if (one_in(50)) {
If you removed the ‘}’ before “if”, it would probably work.