# Adding Pests & Diseases

Pests and diseases are defined in static Lua files under `data/`.&#x20;

They apply negative effects to specific plant types and progress over time unless cured. \
These definitions are used by the growing system to apply random or conditional challenges to plants.

***

## Structure: Pests

A pest definition must include the following fields:

| Field           | Description                                                             |
| --------------- | ----------------------------------------------------------------------- |
| `plant_types`   | Array of plant keys this pest can affect (e.g. `"cabbage"`, `"tomato"`) |
| `label`         | Human-readable name                                                     |
| `severity`      | Optional severity label (informational only)                            |
| `effects`       | Tiered effect values applied per severity (`low`, `medium`, `high`)     |
| `cure`          | Required item to cure the pest (with `id`, `label`, and `amount`)       |
| `increase_rate` | How fast the severity escalates (e.g. ticks until next stage)           |

#### Example: `cabbage_loopers`

```lua
cabbage_loopers = {
    plant_types = { "cabbage", "tomato", "corn" },
    label = "Cabbage Loopers",
    severity = "low",
    effects = {
        low = { quality = 2, health = 1 },
        medium = { quality = 4, health = 3 },
        high = { quality = 6, health = 5 }
    },
    cure = { id = "organic_pesticide", label = "Organic Pesticide", amount = 1 },
    increase_rate = 4
}
```

***

## Structure: Diseases

Diseases follow the exact same structure and fields as pests.

#### Example: `downy_mildew`

```lua
downy_mildew = {
    plant_types = { "cabbage", "tomato", "corn" },
    label = "Downy Mildew",
    severity = "low",
    effects = {
        low = { quality = 2, health = 1 },
        medium = { quality = 4, health = 2 },
        high = { quality = 6, health = 3 }
    },
    cure = { id = "copper_fungicide", label = "Copper Fungicide", amount = 1 },
    increase_rate = 5
}
```

***

## Effects Table

The `effects` table defines what penalties are applied to the plant per severity tier.

Each tier must include:

* `quality`: Reduction in final yield quality
* `health`: Reduction in overall plant health

These values are cumulative and applied when the condition escalates.

***

## Cure Field

The `cure` field defines which item is required to remove the pest or disease. Structure:

```lua
cure = {
    id = "item_name",
    label = "Item Label",
    amount = 1
}
```

This item must exist in your inventory system.

***

## Increase Rate

This value determines how quickly the condition escalates to a higher severity level. \
Lower values escalate faster.

```lua
increase_rate = 4 -- escalates every 4 ticks
```

***

## Registering New Pests or Diseases

To add a new entry:

1. Open `data/pests.lua` or `data/diseases.lua`.
2. Add a new key to the returned table.
3. Define the structure following the format above.
4. Ensure `plant_types` includes only valid keys from `data/plants.lua`.

***

## Example: Adding a New Disease

```lua
powdery_mildew = {
    plant_types = { "tomato" },
    label = "Powdery Mildew",
    severity = "low",
    effects = {
        low = { quality = 2, health = 1 },
        medium = { quality = 4, health = 2 },
        high = { quality = 6, health = 3 }
    },
    cure = { id = "sodium_bicarbonate", label = "Sodium Bicarbonate", amount = 1 },
    increase_rate = 5
}
```

Add this to the return table in `data/diseases.lua`.\
Pests follow the same format.
