Skip to content

Commit

Permalink
feat(port): JSONize ammo consumption per shot, allow gunmods to modif…
Browse files Browse the repository at this point in the history
…y ammo use, add a flamethrower gunmod to demonstrate ammo use modifier (#6012)

* Part one

Co-Authored-By: Mom-Bun <[email protected]>

* Part two

Co-Authored-By: John Candlebury <[email protected]>

* My turn

* style(autofix.ci): automated formatting

* Update json_info.md

---------

Co-authored-by: Mom-Bun <[email protected]>
Co-authored-by: John Candlebury <[email protected]>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
  • Loading branch information
4 people authored Jan 30, 2025
1 parent cc542bd commit e38857b
Show file tree
Hide file tree
Showing 9 changed files with 77 additions and 8 deletions.
6 changes: 4 additions & 2 deletions data/json/items/classes/gun.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
"ammo": "flammable",
"ammo_effects": [ "FLARE" ],
"reload": 400,
"flags": [ "FIRE_100", "NEVER_JAMS", "FIRESTARTER", "PYROMANIAC_WEAPON" ],
"ammo_to_fire": 100,
"flags": [ "NEVER_JAMS", "FIRESTARTER", "PYROMANIAC_WEAPON" ],
"use_action": { "type": "firestarter", "moves": 200 },
"faults": [ ]
},
Expand Down Expand Up @@ -495,7 +496,8 @@
"bashing": 9,
"skill": "launcher",
"ammo": "chemical_spray",
"flags": [ "FIRE_50", "NEVER_JAMS", "NON_FOULING" ],
"ammo_to_fire": 50,
"flags": [ "NEVER_JAMS", "NON_FOULING" ],
"valid_mod_locations": [
[ "accessories", 4 ],
[ "grip", 1 ],
Expand Down
17 changes: 13 additions & 4 deletions data/json/items/gun/flammable.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
[ "rail", 1 ],
[ "stock", 1 ],
[ "sights", 1 ],
[ "underbarrel", 1 ]
[ "underbarrel", 1 ],
[ "muzzle", 1 ]
],
"magazines": [ [ "flammable", [ "pressurized_tank" ] ] ]
},
Expand All @@ -42,9 +43,17 @@
"durability": 9,
"loudness": 3,
"modes": [ [ "DEFAULT", "semi", 1 ], [ "AUTO", "auto", 4 ] ],
"valid_mod_locations": [ [ "accessories", 4 ], [ "rail", 1 ], [ "grip", 1 ], [ "sling", 1 ], [ "stock", 1 ], [ "underbarrel", 1 ] ],
"extend": { "flags": [ "FIRE_20", "MODE_BURST", "NON_FOULING" ] },
"delete": { "flags": [ "FIRE_100" ] },
"valid_mod_locations": [
[ "accessories", 4 ],
[ "rail", 1 ],
[ "grip", 1 ],
[ "sling", 1 ],
[ "stock", 1 ],
[ "underbarrel", 1 ],
[ "muzzle", 1 ]
],
"ammo_to_fire": 20,
"extend": { "flags": [ "MODE_BURST", "NON_FOULING" ] },
"magazines": [ [ "flammable", [ "rm4502", "rm4504" ] ] ]
}
]
20 changes: 20 additions & 0 deletions data/json/items/gunmod/muzzle.json
Original file line number Diff line number Diff line change
Expand Up @@ -246,5 +246,25 @@
"install_time": "0 m",
"handling_modifier": 3,
"loudness_modifier": -50
},
{
"id": "mod_flamethrower_nozzle",
"type": "GUNMOD",
"name": { "str": "high-pressure combustion nozzle" },
"description": "An attachment resembling a rocket nozzle along with parts from a pump assembly. Installing this on a flamethrower will increase its maximum range and damage, but increase fuel consumption.",
"looks_like": "pump_complex",
"weight": "700 g",
"volume": "250 ml",
"price": "100 USD",
"price_postapoc": "5 USD",
"material": [ "steel" ],
"symbol": ":",
"color": "light_gray",
"location": "muzzle",
"mod_target_category": [ [ "FLAMETHROWERS" ] ],
"install_time": "5 m",
"damage_modifier": [ { "damage_type": "heat", "amount": 5 } ],
"range_modifier": 5,
"ammo_to_fire_multiplier": 1.25
}
]
14 changes: 14 additions & 0 deletions data/json/recipes/weapon/mods.json
Original file line number Diff line number Diff line change
Expand Up @@ -963,5 +963,19 @@
[ [ "steel_lump", 1 ] ],
[ [ "RAM", 1 ] ]
]
},
{
"type": "recipe",
"result": "mod_flamethrower_nozzle",
"category": "CC_WEAPON",
"subcategory": "CSC_WEAPON_MODS",
"skill_used": "mechanics",
"difficulty": 5,
"skills_required": [ [ "fabrication", 4 ] ],
"time": "45 m",
"book_learn": [ [ "textbook_gaswarfare", 5 ], [ "book_icef", 5 ], [ "textbook_anarch", 6 ], [ "manual_launcher", 4 ] ],
"using": [ [ "welding_standard", 10 ], [ "steel_tiny", 1 ] ],
"qualities": [ { "id": "HAMMER", "level": 2 }, { "id": "SAW_M", "level": 1 }, { "id": "SCREW", "level": 1 } ],
"components": [ [ [ "pipe", 1 ] ], [ [ "sheet_metal_small", 2 ] ], [ [ "pump_complex", 1 ] ] ]
}
]
4 changes: 3 additions & 1 deletion doc/src/content/docs/en/mod/json/reference/json_flags.md
Original file line number Diff line number Diff line change
Expand Up @@ -778,8 +778,10 @@ List of known flags, used in both `terrain.json` and `furniture.json`.
- `CROSSBOW` Counts as a crossbow for the purpose of gunmod compatibility. Default behavior is to
match the skill used by that weapon.
- `DISABLE_SIGHTS` Prevents use of the base weapon sights
- `FIRE_100` Uses 100 shots per firing.
- `FIRE_20` Uses 20 shots per firing.
- `FIRE_50` Uses 50 shots per firing.
- `FIRE_100` Uses 100 shots per firing. See also the `ammo_to_fire` property to specify any amount
of ammo usage per shot desired. These flags will override `ammo_to_fire` if present.
- `HEAVY_WEAPON_SUPPORT` Wearing this will let you hip-fire heavy weapons without needing terrain
support, like Large or Huge mutants can.
- `FIRE_TWOHAND` Gun can only be fired if player has two free hands.
Expand Down
4 changes: 4 additions & 0 deletions doc/src/content/docs/en/mod/json/reference/json_info.md
Original file line number Diff line number Diff line change
Expand Up @@ -1911,6 +1911,8 @@ Guns can be defined like this:
"burst": 5, // Number of shots fired in burst mode
"clip_size": 100, // Maximum amount of ammo that can be loaded
"ups_charges": 0, // Additionally to the normal ammo (if any), a gun can require some charges from an UPS. This also works on mods. Attaching a mod with ups_charges will add/increase ups drain on the weapon.
"ammo_to_fire" 1, // Amount of ammo used per shot, separate from any UPS cost that may be given to the weapon.
// The legacy item flags `FIRE_20`, `FIRE_50`, and `FIRE_100` are still permitted and will override `ammo_to_fire` if present.
"reload": 450, // Amount of time to reload, 100 = 1 second = 1 "turn". Default 100.
"built_in_mods": ["m203"], // An array of mods that will be integrated in the weapon using the IRREMOVABLE tag.
"default_mods": ["m203"] // An array of mods that will be added to a weapon on spawn.
Expand Down Expand Up @@ -1990,6 +1992,8 @@ Gun mods can be defined like this:
"recoil_modifier": -100, // Optional field increasing or decreasing base gun recoil
"ups_charges_modifier": 200, // Optional field increasing or decreasing base gun UPS consumption (per shot) by adding given value
"ups_charges_multiplier": 2.5, // Optional field increasing or decreasing base gun UPS consumption (per shot) by multiplying by given value
"ammo_to_fire_modifier": 200, // Optional field increasing or decreasing amount of main ammo consumed per shot by adding given value
"ammo_to_fire_multiplier": 2.5, // Optional field increasing or decreasing main ammo consumed per shot by multiplying by given value
"reload_modifier": -10, // Optional field increasing or decreasing base gun reload time in percent
"min_str_required_mod": 14, // Optional field increasing or decreasing minimum strength required to use gun
```
Expand Down
8 changes: 7 additions & 1 deletion src/item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7906,7 +7906,13 @@ int item::ammo_required() const
} else if( has_flag( flag_FIRE_20 ) ) {
return 20;
} else {
return 1;
int modifier = 0;
float multiplier = 1.0f;
for( const item *mod : gunmods() ) {
modifier += mod->type->gunmod->ammo_to_fire_modifier;
multiplier *= mod->type->gunmod->ammo_to_fire_multiplier;
}
return ( type->gun->ammo_to_fire * multiplier ) + modifier;
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/item_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1885,6 +1885,7 @@ void Item_factory::load( islot_gun &slot, const JsonObject &jo, const std::strin
assign( jo, "blackpowder_tolerance", slot.blackpowder_tolerance, strict, 0 );
assign( jo, "min_cycle_recoil", slot.min_cycle_recoil, strict, 0 );
assign( jo, "ammo_effects", slot.ammo_effects, strict );
assign( jo, "ammo_to_fire", slot.ammo_to_fire, strict, 1 );

if( jo.has_array( "valid_mod_locations" ) ) {
slot.valid_mod_locations.clear();
Expand Down Expand Up @@ -2391,6 +2392,8 @@ void Item_factory::load( islot_gunmod &slot, const JsonObject &jo, const std::st
assign( jo, "ammo_effects", slot.ammo_effects, strict );
assign( jo, "ups_charges_multiplier", slot.ups_charges_multiplier );
assign( jo, "ups_charges_modifier", slot.ups_charges_modifier );
assign( jo, "ammo_to_fire_multiplier", slot.ammo_to_fire_multiplier );
assign( jo, "ammo_to_fire_modifier", slot.ammo_to_fire_modifier );
assign( jo, "weight_multiplier", slot.weight_multiplier );
if( jo.has_int( "install_time" ) ) {
slot.install_time = jo.get_int( "install_time" );
Expand Down
9 changes: 9 additions & 0 deletions src/itype.h
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,9 @@ struct islot_gun : common_ranged_data {
* @note useful for adding recoil effect to guns which otherwise consume no ammo
*/
int recoil = 0;

/** How much ammo is consumed per shot. */
int ammo_to_fire = 1;
};

struct islot_gunmod : common_ranged_data {
Expand Down Expand Up @@ -596,6 +599,12 @@ struct islot_gunmod : common_ranged_data {
/** Increases base gun UPS consumption by this value per shot */
int ups_charges_modifier = 0;

/** Increases base gun ammo to fire by this many times per shot */
float ammo_to_fire_multiplier = 1.0f;

/** Increases base gun ammo to fire by this value per shot */
int ammo_to_fire_modifier = 0;

/** Increases gun weight by this many times */
float weight_multiplier = 1.0f;

Expand Down

0 comments on commit e38857b

Please sign in to comment.