Epidemiology

Disease transmission, epidemic spread, quarantine mechanics, immunity tracking, and population-level infection modelling.

What this uses

src/sim/disease.ts src/sim/hazard.ts src/sim/nutrition.ts src/sim/world.ts src/sim/seeds.ts docs/validation-disease-mortality-rate.md

Disease modelling is entity-level: each entity carries an activeDiseases array and an immunity record. Spread is computed pair-by-pair using proximity and transmission route. A full population simulation is driven by the host iterating over entity pairs each tick.

Disease profiles

🤧 common fever
🩸 wound fever
☠ pneumonic plague
💧 dysentery
🦟 marsh fever
💀 wasting sickness
transmission route
airborne
base transmission rate
q(0.35)
incubation period2 days
symptomatic duration7 days
mortality rate
q(0.05)
immunity duration30 days
airborne range5 m

Infection phase track — entity view

static preview

Entity lifecycle for the selected disease. Width proportional to duration.

S
incubating
symptomatic
immune
S susceptible I incubating S symptomatic R immune D dead

Population spread — SIR model preview

static preview

Illustrative day-by-day infection spread in a population of 100 entities. Based on common_fever parameters with ~50% close-contact pairs per day.

Day 0
I: 1%
Day 3
I: 14%
Day 7
I: 35%
Day 14
I: 30%
Day 21
I: 10%
Day 30
I: 2%

Create / import custom disease profiles

Define a custom disease profile and save it to localStorage, download it as a TypeScript snippet, or import one from JSON. To add it to the codebase, export the snippet and open a pull request.

To add a custom disease to the codebase: download the .ts snippet, add it to src/sim/disease.ts, write a test in test/sim/disease.test.ts, then open a pull request ↗ with the title feat: add [NAME] disease profile.

Try this

  1. Expose an entity: exposeToDisease(entity, 'common_fever'). Returns true if exposure succeeded (not immune, not already infected).
  2. Step disease each tick: stepDiseaseForEntity(entity, delta_s, worldSeed, tick). Returns events (onset, death, recovery).
  3. Model spread: call spreadDisease(entityMap, pairs, worldSeed, tick) per tick with an array of entity-pair objects.
  4. Quarantine: simply don't include quarantined entities in the pairs array — they won't spread.
  5. See MARSH_FEVER for vector-borne disease (triggered by MUSTARD_GAS-style hazard zone with diseaseExposureId).