Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSONify addictions #56786

Merged
merged 7 commits into from
Apr 19, 2022
Merged

Conversation

dseguin
Copy link
Member

@dseguin dseguin commented Apr 13, 2022

Summary

None

(alternate summary: "pldata.h is dead, long live addictions.json")

Purpose of change

Describe the solution

Promote the add_type enum into an object with it's own string_id, and migrate hardcoded addiction functions to the "addiction_type" JSON object:

{
  "type": "addiction_type",
  "id": "caffeine",
  "name": "Caffeine Withdrawal",
  "type_name": "caffeine",
  "description": "Strength - 1;   Slight sluggishness;   Occasional cravings",
  "craving_morale": "morale_craving_caffeine",
  "effect_on_condition": "EOC_CAFFEINE_ADDICTION"
}
(definition of EOC_CAFFEINE_ADDICTION)
{
  "type": "effect_on_condition",
  "id": "EOC_CAFFEINE_ADDICTION",
  "condition": {
    "compare_int": [
      { "rand": 2000 },
      "<=",
      { "u_val": "addiction_intensity", "addiction": "caffeine", "mod": { "val": 2000, "step": 20 } }
    ]
  },
  "effect": [
    { "u_message": "You want some caffeine.", "type": "warning" },
    { "u_add_morale": "morale_craving_caffeine", "bonus": -5, "max_bonus": -30 },
    {
      "run_eocs": [
        {
          "id": "EOC_CAFFEINE_ADDICTION_MODSTIM",
          "condition": {
            "and": [
              { "compare_int": [ { "u_val": "stim" }, ">", { "u_val": "addiction_intensity", "addiction": "caffeine", "mod": -10 } ] },
              {
                "compare_int": [ { "rand": 10 }, "<", { "u_val": "addiction_intensity", "addiction": "caffeine" } ]
              }
            ]
          },
          "effect": { "arithmetic": [ { "u_val": "stim" }, "-=", { "const": 1 } ] }
        },
        {
          "id": "EOC_CAFFEINE_ADDICTION_SHAKES",
          "condition": {
            "and": [
              { "compare_int": [ { "u_val": "addiction_intensity", "addiction": "caffeine" }, ">=", { "const": 8 } ] },
              {
                "compare_int": [ { "rand": 392 }, "<", { "u_val": "addiction_intensity", "addiction": "caffeine" } ]
              }
            ]
          },
          "effect": [
            { "u_message": "Your hands start shaking… you need it bad!", "type": "bad" },
            { "u_add_effect": "shakes", "duration": "2 minutes" }
          ]
        }
      ]
    }
  ]
}
Field definitions
Field Description
"name" The name of the addiction's effect as it appears in the player's status
"type_name" The name of the addiction's source
"description" Description of the addiction's effects as it appears in the player's status
"craving_morale" ID of the morale_type penalty
"effect_on_condition" ID of the effect_on_condition (can also be an inline EOC) which activates on each update_body (aka every turn)
"builtin" (for legacy addiction code) Name of a hardcoded function to process the addiction's effect. For new addictions, use "effect_on_condition" instead.

Describe alternatives you've considered

Using a different mechanism for applying addiction effects, like some custom built-ins or effect stuff.

Testing

Added extensive unit tests for validating JSON vs. hardcoded addiction effects:

./tests/cata_test --rng-seed time "[addiction]"

Additional context

TODO:

  • Promote add_type to data object
  • Remove pldata.h
  • Convert existing save data
  • Add conditions and dialogue effects for processing addiction EOCs
  • Convert addiction effects to EOCs
    • Note: some harcoded addiction effects are incompatible with current EOC infrastructure. Those effects use the "builtin" field
  • Documentation
  • Unit tests

@github-actions github-actions bot added [C++] Changes (can be) made in C++. Previously named `Code` [JSON] Changes (can be) made in JSON Code: Tests Measurement, self-control, statistics, balancing. Code: Tooling Tooling that is not part of the main game but is part of the repo. json-styled JSON lint passed, label assigned by github actions astyled astyled PR, label is assigned by github actions labels Apr 13, 2022
@dseguin dseguin force-pushed the jsonify_addictions branch 2 times, most recently from 944b1f1 to 055ecbe Compare April 13, 2022 22:52
@github-actions github-actions bot removed the json-styled JSON lint passed, label assigned by github actions label Apr 13, 2022
@dseguin dseguin force-pushed the jsonify_addictions branch from 055ecbe to e752c2a Compare April 13, 2022 22:58
@github-actions github-actions bot added the json-styled JSON lint passed, label assigned by github actions label Apr 13, 2022
@dseguin dseguin force-pushed the jsonify_addictions branch 2 times, most recently from 50f27b5 to 4d859d4 Compare April 14, 2022 00:08
@github-actions github-actions bot added BasicBuildPassed This PR builds correctly, label assigned by github actions <Documentation> Design documents, internal info, guides and help. [Python] Code made in Python Translation I18n and removed BasicBuildPassed This PR builds correctly, label assigned by github actions labels Apr 14, 2022
@dseguin dseguin force-pushed the jsonify_addictions branch from 41b3e92 to c159c1a Compare April 14, 2022 07:51
@github-actions github-actions bot added Mods Issues related to mods or modding Lore Game lore, in-game communication. Also the Lore tab. BasicBuildPassed This PR builds correctly, label assigned by github actions labels Apr 14, 2022
@dseguin dseguin force-pushed the jsonify_addictions branch from a2c2c9f to e278564 Compare April 15, 2022 01:46
@dseguin dseguin marked this pull request as ready for review April 15, 2022 01:50
@dseguin dseguin requested a review from BrettDong as a code owner April 15, 2022 01:50
@dseguin dseguin force-pushed the jsonify_addictions branch from e278564 to 1326d67 Compare April 15, 2022 03:24
@dseguin dseguin force-pushed the jsonify_addictions branch from 1326d67 to 96744e4 Compare April 17, 2022 17:19
@kevingranade kevingranade merged commit b58b793 into CleverRaven:master Apr 19, 2022
@dseguin dseguin deleted the jsonify_addictions branch April 19, 2022 01:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
astyled astyled PR, label is assigned by github actions BasicBuildPassed This PR builds correctly, label assigned by github actions [C++] Changes (can be) made in C++. Previously named `Code` Code: Tests Measurement, self-control, statistics, balancing. Code: Tooling Tooling that is not part of the main game but is part of the repo. <Documentation> Design documents, internal info, guides and help. [JSON] Changes (can be) made in JSON json-styled JSON lint passed, label assigned by github actions Lore Game lore, in-game communication. Also the Lore tab. Mods Issues related to mods or modding [Python] Code made in Python Translation I18n
Projects
None yet
Development

Successfully merging this pull request may close these issues.

JSONized Addictions.cpp
2 participants