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

Allow loading multiple ammo/charge containers and consuming multiple ammos per use #32227

Closed
ymber opened this issue Jul 7, 2019 · 3 comments

Comments

@ymber
Copy link
Member

commented Jul 7, 2019

Is your feature request related to a problem? Please describe.
Some things should load and use multiple types of ammunition or power. Pneumatic guns should require ammo and compressed gas, railguns should require ammo and power etc. There are also use cases for items taking more than one of the same magazine as it would obsolete the gunmod hack items like the KSG use.

Describe the solution you'd like
Items should define a loadables object specifying the types of items it can load.

"loadables": {
  "integral_magazines": [
    {
      "type": [ "38special", "357mag" ],
      "capacity": 7,
      "reliability": 5
    },
    {
      "type": [ "38special", "357mag" ],
      "capacity": 7,
      "reliability": 5
    }
  ],
  "integral_batteries": [
    {
      "max_energy": "30 kJ"
    }
  ],
  "magazine_wells": [
    { 
      "contain_volume": "250 ml",
      "mag_map": [ 
        [ "ball", [ "ball_box" ] ],
        [ "other_ball", [ "other_ball_box" ] ]
      ]
    },
    {
      "contain_volume": "500 ml",
      "mag_map": [ 
        [ "compressed_gas", [ "canister", "canister_large" ] ]
      ]
    }
  ],
  "battery_wells": [
    {
      "contain_volume": "250 ml",
      "batteries": [ "battery_aa" ]
    }
  ]
}

Here an item defines 6 loadables.

  • 2 identical integral magazines. integral_magazines is essentially an array of objects that define islot_magazine objects.
  • An integral battery with a 30 kilojoule capacity. Objects in integral_batteries define islot_battery objects.
  • A magazine well with 250 ml containing volume (essentially the current magazine_well volume). Compatible magazines for ball and other_ball ammotypes will go in this magazine well. The ammotype/itype_id map there is essentially the same as the current magazines field.
  • Another mag well for compressed gas canisters.
  • A battery compartment for AA batteries. The batteries array in objects in battery_wells is an array of compatible itype_ids.

The contents of this item will always have 2 magazine items for the integral magazines, 1 battery for the integral battery, and may have any or none of the compatible magazines and batteries. These integral magazines and batteries should be treated similarly to our current integrated gunmods where they are separate items in something's contents but from the player's point of view it's all one item.

Items requiring energy or ammunition to use should also define a per_use object.

"per_use": {
  "ammunition": [
    [ "ball", 1 ],
    [ "compressed_gas", 20 ]
  ],
  "energy": "500 J"
}

Using this item would require 1 ball ammo item, 20 compressed_gas ammo items, and 500 joules from a battery loaded in the item.

The big implementation point is that to support loading things that don't fit the established item containing ammo items model (eg batteries) we should template the reloading and ammo consumption code. This should mean that if someones does something similar to my current batteries work that requires a new quantity type it will require some template specializations at most to integrate it with the ammo and reloading code.

Additional context
#30874 (comment)
If we're redoing everything about reloading anyway we might want to move to [ "ammotype", (int)capacity ] capacity definitions while were here.

This should probably come before the rest of #32067 because the code in #32193 is getting kinda awful.

@ymber

This comment has been minimized.

Copy link
Member Author

commented Jul 11, 2019

Revised data

"loadables": {
  "integrals": [
    {
      "id": "test_tool_mag1",
      "type": "MAGAZINE",
      "ammo_type": [ "38special", "357mag" ],
      "capacity": 7,
      "reliability": 5
    },
    {
      "id": "test_tool_mag2",
      "type": "MAGAZINE",
      "ammo_type": [ "38special", "357mag" ],
      "capacity": 7,
      "reliability": 5
    },
    {
      "id": "test_tool_battery1",
      "type":"BATTERY",
      "max_capacity":"30 kJ"
    }
  ],
  "item_wells": [
    { 
      "contain_volume": "250 ml",
      "items": [ "ball_box", "other_ball_box" ]
    },
    {
      "contain_volume": "500 ml",
      "items": [ "canister", "canister_large" ]
    },
    {
      "contain_volume": "250 ml",
      "items": [ "battery_aa" ]
    }
  ]
}
  • Integral loadables are now all in one array. They were all parsed into itype objects and put in the same vector anyway so this just simplifies the JSON.
  • Integral loadables must define items with type and id as well as appropriate islot data. The code was not set up to handle anonymous items.
  • Item wells are now all the same. Mappings between ammotypes and itype_ids are now gone in favor of an item well specifying all of its compatible itype_ids in an array.
  • Item wells are now all defined in one array.
"per_use": {
  "ammunition": [
    [ 1, [ "ball", "other_ball" ] ],
    [ 20, [ "compressed_gas" ] ]
  ],
  "energy": "500 J",
  "items": [
    [ 1, "CONSUME", [ "charcoal", "hydrogen" ] ],
    [ 1, "NOCONSUME", [ "filter_thing" ] ]
  ]
}
  • Specifying multiple ammotypes is now allowed for ammunition.
  • Elements of items can specify CONSUME or NOCONSUME. NOCONSUME items are required to be loaded for the item to be used but are not consumed when the item is used.

Implementation notes

  • It will be possible and perhaps desirable to replace some uses of the charges system with integral mag loadables with NORELOAD and nonzero count.
  • Bandoliers should be defined with loadables. This could be an item well for each round or an integral magazine.
  • Only MAGAZINE or CONTAINER type items should be directly reloadable. Everything else should define integral magazines or item_wells.
  • Only MAGAZINE type items should be treated as magazines when loaded in an item well. In future we should consider allowing CONTAINER items to be used as well so we can handle liquid and gas ammo better. With CONTAINERs a precise volume to consume could be specified in per_use.
  • Speedloaders and clips will have to be reimplemented as items that can be used to reload a magazine rather than magazines themselves.

As I have explored implementation options for this I have come to think that a common interface for handling item contents and pseudo contents is not viable without overhauling an enormous amount of code. Implementing the item well system and moving integral magazines and batteries to being actual items will still give us a significantly more consistent and versatile system with cleaner code.

@stale

This comment has been minimized.

Copy link

commented Aug 16, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. Please do not 'bump' or comment on this issue unless you are actively working on it. Stale issues, and stale issues that are closed are still considered.

@stale stale bot added the stale label Aug 16, 2019
@stale

This comment has been minimized.

Copy link

commented Sep 15, 2019

This issue has been automatically closed due to lack of activity. This does not mean that we do not value the issue. Feel free to request that it be re-opened if you are going to actively work on it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.