Skip to content

Reduce likelihood of machines interfering with each other #786

@brturn

Description

@brturn

Based on a report from brogue forum

In seed #20220710, a sacrifice creature in a statue is surrounded by a chasm (confirmed in 1.14.1), making the puzzle almost impossible to solve.

Pender on Discord theorized the cause, and a potential fix.

Pender's suggestion is to fail a room machine if the floor of the machine touches any TM_IS_WIRED tiles. I wrote some test code to find out if this works.

This is the loop where the room machine floor is checked:

for (int k=0; k<1000 && qualifyingTileCount < totalFreq; k++) {
for(int i=0; i<DCOLS && qualifyingTileCount < totalFreq; i++) {
for(int j=0; j<DROWS && qualifyingTileCount < totalFreq; j++) {
if (distanceMap[p->sCols[i]][p->sRows[j]] == k) {
p->interior[p->sCols[i]][p->sRows[j]] = true;
qualifyingTileCount++;
if (pmap[p->sCols[i]][p->sRows[j]].flags & (HAS_ITEM | HAS_MONSTER | IS_IN_MACHINE)) {
// Abort if we've entered another machine or engulfed another machine's item or monster.
tryAgain = true;
qualifyingTileCount = totalFreq; // This is a hack to drop out of these three for-loops.
}
}
}
}
}

Placing this test code after the IF statement in the inner loop causes the room machine to abort:

        if (pmap[ ... ].flags & ( .... )) {
           ....
        }

        // Check all surrounding tiles to see if they are in another machine (terribly inefficient, just for testing)
        unsigned long mechFlags = 0;
        for (int nx = -1; nx < 2; nx++) {
            for (int ny = -1; ny < 2; ny++) {
                if (!isPosInMap((pos){i+nx,j+ny})) continue;
                // Gather mech flags for all layers of tile
                pcell *pc = &pmap[p->sCols[i+nx]][p->sRows[j+ny]];
                for (int layer = 0; layer < NUMBER_TERRAIN_LAYERS; layer++) {
                    mechFlags |= tileCatalog[pc->layers[layer]].mechFlags;
                }
            }
        }

        if ((mechFlags & (TM_IS_WIRED | TM_IS_CIRCUIT_BREAKER)) != 0) {
            // Abort if we've entered another machine or engulfed another machine's item or monster.
            tryAgain = true;
            qualifyingTileCount = totalFreq; // This is a hack to drop out of these three for-loops.
        }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions