Map colors and the ledgers that keep them honest
A game map is a drawing and a database pretending to be one file. The interesting part is what happens when the two fall out of step.
Painting a map is satisfying in a way that editing a table rarely is. You choose a color, fill a region, and the world gains a coastline. The database does not see any of that. It sees a list of rows, each with a number and a color, and it trusts that every painted color has a row waiting for it.
Crusader Kings II works this way. A single bitmap holds the provinces, each one a flat color. A companion file assigns numbers to those colors. White and black are special cases, used for the edge of the world and for mountain barriers. Everything else needs an entry, or the game will object at startup.
Two sources of truth
The bitmap answers the question of where. The ledger answers the question of what. A color that appears in the painting but not in the ledger is an orphan. A color in the ledger that no longer appears in the painting is a ghost. Orphans are dangerous because the game has no name for them. Ghosts are mostly harmless, but they clutter the record and make future edits harder to reason about.
A good sync pass treats both files as sets and compares them directly. It does not rewrite the whole ledger from scratch, because province numbers are referenced elsewhere: events, history files, localisation, save games. Renumbering a province can quietly break all of those references. Stable numbers matter more than tidy rows.
Make the pass idempotent
The simplest useful rule is that running the tool twice should produce the same result as running it once. To get there, separate three operations:
- Deactivate rows whose colors have disappeared from the painting.
- Reactivate rows whose colors have returned, keeping their original numbers.
- Append new rows only for colors that have never had a number.
Deactivation is better than deletion. A commented row is a memory of an earlier design, and it lets the next pass restore the old number instead of issuing a new one.
A map edit is a change to shared vocabulary. Treat the numbers as names, not as counters.
Small checks before the launch
Before loading a modified map, verify that every painted color has exactly one active row, that every active row has a painted color, and that no two rows share a number. Those three checks catch most of the failures that would otherwise appear as a crash with no useful message.
The rest is patience. Paint a little, run the pass, inspect the diff, and keep a copy of the ledger from before the experiment. The map will forgive a bad color choice. It will not forgive a lost number.