# Modules

`modules.json` switches on things most games need. The compiler writes them out as script,
so a game can call them, and they follow the same rules. All parts are optional.

    {
      "season": {"days": 60, "score": "worth(p)", "on_reset": "start_again", "on_end": "fn"},
      "players": true,
      "rankings": [{"name": "richest", "title": "The richest", "value": "worth(p)", "count": 10}],
      "shops": [{"name": "store", "title": "The store", "money": "cash", "goods": [
        {"label": "Water", "field": "water", "buy": "3", "sell": "1", "most": "40",
         "stock": "world.water", "bought": "world.sold += n", "sold": ""}]}]
    }

| Module | What a game gets |
|---|---|
| season | A season of so many days. At its end the highest `score` (of player `p`) goes into the hall and the news, `on_end` runs, and then for each player `on_reset`, with `player` as that player; both are atomic functions. Fields `world.season`, `world.season_start`, `player.season`; table `season_hall`; `season_left()`, `show_hall()`. A shared table that must start again can compare its own season with `world.season` in its `on_row_day` |
| players | `show_players()` |
| rankings | `show_` and the name, for each |
| shops | a function with the shop's name. `buy` and `sell` are prices, `most` the most a player may have, `stock` a field there is a limited amount in. `bought` and `sold` are script run in the same step, where `n` is how many |
| bank | `{"money": "cash", "interest": 3, "most": 500}`: `visit_bank()` and `player.bank`; interest in percent a day, up to `most` |
| levels | `{"need": [60, 220], "rewards": [{"field": "max_hp", "add": 10}], "say": "..."}`: `player.level`, `player.exp`, `check_level()`, `level_need(n)`. `need` is for level 2, 3 and so on |
| fights | a list; each has a `name` and a fixed `table` of opponents (`foe_name`, `foe_hp` say which fields; usually `name` and `hp`), and gives `name()` and `name_with(f)` (1 won, 2 got away, 3 lost, 0 not begun). Script about the opponent `f`: `choose`, `hit`, `foe_hit`, `win_money`, `win_exp`. Also `money`, `lose_percent`, `run_chance`, `turns`, `item` (`field`, `label`, `heals`), and `won` and `lost`, functions taking `f`. `hang_up` is `loss` or `escape`; with `loss`, leaving in any way in the middle is losing. Fields `player.hp`, `player.max_hp` (healed each day), `player.fighting` |
| challenges | `{"strength": "p.strength", "when": "...", "daily": 1, "protect_days": 3, "take_percent": 10, "turns": 1, "money": "cash"}`: `challenge()`. Worked out in one step whether the other is playing or not; the loser pays, gets a letter, and cannot be beaten again that day |
| letters | `true`: `write_letter()` |

With several fights, the one whose `hang_up` is `loss` and that comes last says what leaving costs.

Ids from 50001 are for modules.
