Skip to content

Commit

Permalink
Add gun variants, allowing to specify multiple guns with the same sta…
Browse files Browse the repository at this point in the history
…t block (#46814)

* Add gun variant support

This allows genericizing our massive variety of very similar guns into
one statblock, without removing the flavor.
If a gun or magazine is specified to spawn without a variant, it will
pick from the variants available to it, based on their assigned weight.

Gun variants can specify an alternate name, description and ascii art
for a gun, and variants can be toggled through an option.

Add support for migrations to express variants.

Add explicit extraction for magazines to handle variants.

ASCII art for a variant will fall back to that of the base gun
automatically if not specified or invalid.

Maybe the naming could better express these are for both guns and
magazines, but I think it is fine as is.

item::gun_variant makes the assumption you check it has a variant first,
so make sure to do that.

Move the ammo at the end of gun names option to be next to the gun
variant option.

item::is_magazine doesn't tell us if type->magazine is safe to use, so
!!type->magazine must be used instead of that before accessing
type->magazine.

* Add hacks to Archive::io to load/save gun variants

I couldn't figure out how to specify the lambdas correctly, so I give
up, this works.

Problem is as follows:
In item, I have
```
const gun_variant_data *_gun_variant;
...
struct gun_variant_data
{
    std::string id;
    // other info that doesn't matter
}
```
I want to save this as `_gun_variant->id;`, and on load, load the string
that was saved and call `item::set_gun_variant(loaded_string);`.
This, and many variations of it don't work.
```
// In item:: scope
const auto load = [this](const std::string &variant) {
                      set_gun_variant( variant );
                  };
const auto save = [](const gun_variant_data *gv) {
                      return gv->id;
                  };
```

Someone who know what's they're doing here may want to fix my laziness.

* Add spawning support for gun variants

Allow specifying variatns in item groups, mapgen
(Item_group::add_item_entry), and in vehicles.

* Add documentation for gun variants

* Genericize NATO assault rifles

Information lost:
acr - 250ml barrel volume, folding stock
m38dmr - 125 dispersion

Move everything using an old rifle into the new generic rifles.

The m38dmr is debatable, but I figure it's fine to be generic.

Only m4a1s will spawn from unspecified variants at the moment, someone
else can figure out what the proper chances should be.

* Genericize other 5.56 assault rifles

These ones are unique enough to not be simple variants of the NATO
assault rifle, but they also don't need a full enumeration of stats.

Move the brand-specific information to be a variant, genericize name and
descriptions, and make all non-unique stats identical to those of the
NATO assault rifle.

I'm not sure of a good name for the sig generic version, but I want it
to be distinct from the AUTO only or BURST only NATO rifles.

* Genericize .45 ACP firearms

There may be some consideration needed on collapsing the stat blocks for
the pistols/smgs into a single one with copy-from, but this is simply
the highest level genericization changes.
  • Loading branch information
anothersimulacrum authored and ZhilkinSerg committed May 31, 2021
1 parent 693feb2 commit 9b6e68c
Show file tree
Hide file tree
Showing 50 changed files with 781 additions and 538 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,9 @@
{ "item": "savage_111f", "prob": 10 },
{ "item": "ak47", "prob": 16 },
{ "item": "ak74", "prob": 4 },
{ "item": "m4a1", "prob": 7 },
{ "item": "nato_assault_rifle", "variant": "m4a1", "prob": 7 },
{ "item": "m16a4", "prob": 6 },
{ "item": "h&k416a5", "prob": 3 },
{ "item": "nato_assault_rifle", "variant": "h&k416a5", "prob": 3 },
{ "item": "m1014", "prob": 1 },
{ "item": "steyr_aug", "prob": 6 },
{ "item": "v29", "prob": 1 },
Expand Down
14 changes: 14 additions & 0 deletions data/json/itemgroups/Weapons_Mods_Ammo/gunmod.json
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,13 @@
[ "offset_sights", 6 ]
]
},
{
"type": "item_group",
"id": "m38dmr_mods",
"//": "Default mods for the m38dmr variant of the NATO assault rifle",
"subtype": "collection",
"entries": [ { "item": "suppressor" }, { "item": "rifle_scope" }, { "item": "bipod" } ]
},
{
"type": "item_group",
"id": "sights_shotgun_readied",
Expand All @@ -137,6 +144,13 @@
"//": "For shotguns that haven't been 'made ready', e.g sitting in a store or garage.",
"entries": [ { "group": "sights_shotgun", "prob": 20 }, { "group": "EMPTY_GROUP", "prob": 80 } ]
},
{
"type": "item_group",
"id": "mk23_mods",
"//": "Default mods for the mk23 variant of the USP .45 pistol",
"subtype": "collection",
"entries": [ { "item": "suppressor" }, { "item": "laser_sight" } ]
},
{
"type": "item_group",
"id": "sights_launcher",
Expand Down
27 changes: 17 additions & 10 deletions data/json/itemgroups/Weapons_Mods_Ammo/guns.json
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,16 @@
"items": [
{ "item": "m17", "prob": 100, "charges-min": 0, "charges-max": 17 },
{ "item": "glock_18c", "prob": 70, "charges-min": 0, "charges-max": 17 },
{ "item": "mk23", "prob": 10, "charges-min": 0, "charges-max": 12 },
{
"item": "usp_45",
"variant": "mk23",
"contents-group": "mk23_mods",
"prob": 10,
"charges-min": 0,
"charges-max": 12
},
{ "item": "usp_45", "prob": 15, "charges-min": 0, "charges-max": 12 },
{ "item": "m1911_MEU", "prob": 5, "charges-min": 0, "charges-max": 7 },
{ "item": "m1911", "variant": "m1911_MEU", "prob": 5, "charges-min": 0, "charges-max": 7 },
{ "item": "glock_19", "prob": 20, "charges-min": 0, "charges-max": 15 },
{ "item": "needlepistol", "prob": 45, "charges-min": 0, "charges-max": 50 },
{ "item": "rm103a_pistol", "prob": 35, "charges-min": 0, "charges-max": 10 }
Expand Down Expand Up @@ -350,7 +357,7 @@
"id": "guns_rifle_rare",
"//": "Less common rifles including those only used by police/paramilitary forces.",
"items": [
{ "item": "acr", "prob": 25, "charges-min": 0, "charges-max": 30 },
{ "item": "nato_assault_rifle", "variant": "acr", "prob": 25, "charges-min": 0, "charges-max": 30 },
{ "item": "colt_lightning", "prob": 15, "charges-min": 0, "charges-max": 10 },
{ "item": "fn_fal", "prob": 40, "charges-min": 0, "charges-max": 20 },
{ "item": "fs2000", "prob": 6, "charges-min": 0, "charges-max": 30 },
Expand All @@ -360,7 +367,7 @@
{ "item": "henry_big_boy", "prob": 10, "charges-min": 0, "charges-max": 10 },
{ "item": "m14ebr", "prob": 15, "charges-min": 0, "charges-max": 20 },
{ "item": "M24", "prob": 15, "charges-min": 0, "charges-max": 5 },
{ "item": "m4a1", "prob": 45, "charges-min": 0, "charges-max": 30 },
{ "item": "nato_assault_rifle", "variant": "m4a1", "prob": 45, "charges-min": 0, "charges-max": 30 },
{ "item": "m1903", "prob": 15, "charges-min": 0, "charges-max": 5 },
{ "item": "m1918", "prob": 30, "charges-min": 0, "charges-max": 20 },
{ "item": "mosin44_ebr", "prob": 10, "charges-min": 0, "charges-max": 5 },
Expand All @@ -379,7 +386,7 @@
"id": "guns_rifle_rare_display",
"//": "Less common rifles found exclusively in gun stores.",
"items": [
{ "item": "acr", "prob": 25, "charges-min": 0, "charges-max": 0 },
{ "item": "nato_assault_rifle", "variant": "acr", "prob": 25, "charges-min": 0, "charges-max": 0 },
{ "item": "colt_lightning", "prob": 15, "charges-min": 0, "charges-max": 0 },
{ "item": "fn_fal", "prob": 40, "charges-min": 0, "charges-max": 0 },
{ "item": "m249_semi", "prob": 5, "charges-min": 0, "charges-max": 0 },
Expand All @@ -388,7 +395,7 @@
{ "item": "henry_big_boy", "prob": 10, "charges-min": 0, "charges-max": 0 },
{ "item": "m14ebr", "prob": 15, "charges-min": 0, "charges-max": 0 },
{ "item": "M24", "prob": 15, "charges-min": 0, "charges-max": 0 },
{ "item": "m4a1", "prob": 45, "charges-min": 0, "charges-max": 0 },
{ "item": "nato_assault_rifle", "variant": "m4a1", "prob": 45, "charges-min": 0, "charges-max": 0 },
{ "item": "m1903", "prob": 15, "charges-min": 0, "charges-max": 0 },
{ "item": "m1918", "prob": 30, "charges-min": 0, "charges-max": 0 },
{ "item": "mosin44_ebr", "prob": 10, "charges-min": 0, "charges-max": 0 },
Expand All @@ -407,23 +414,23 @@
"id": "guns_rifle_milspec",
"//": "Military specification rifles only ever found at military sites.",
"items": [
{ "item": "h&k416a5", "prob": 50, "charges-min": 0, "charges-max": 30 },
{ "item": "nato_assault_rifle", "variant": "h&k416a5", "prob": 50, "charges-min": 0, "charges-max": 30 },
{ "item": "m107a1", "prob": 30, "charges-min": 0, "charges-max": 10 },
{ "item": "m134", "prob": 10, "charges-min": 0, "charges-max": 100 },
{ "item": "m14ebr", "prob": 10, "charges-min": 0, "charges-max": 20 },
{ "item": "tac50", "prob": 5, "charges-min": 0, "charges-max": 5 },
{ "item": "m2010", "prob": 20, "charges-min": 0, "charges-max": 5 },
{ "item": "m240", "prob": 15, "charges-min": 0, "charges-max": 100 },
{ "item": "m249", "prob": 25, "charges-min": 0, "charges-max": 10 },
{ "item": "m27iar", "prob": 50, "charges-min": 0, "charges-max": 30 },
{ "item": "nato_assault_rifle", "variant": "m27iar", "prob": 50, "charges-min": 0, "charges-max": 30 },
{ "item": "m60", "prob": 15, "charges-min": 0, "charges-max": 100 },
{ "item": "rm11b_sniper_rifle", "prob": 15, "charges-min": 0, "charges-max": 10 },
{ "item": "rm298", "prob": 10, "charges-min": 0, "charges-max": 100 },
{ "item": "rm51_assault_rifle", "prob": 25, "charges-min": 0, "charges-max": 50 },
{ "item": "rm614_lmg", "prob": 10, "charges-min": 0, "charges-max": 100 },
{ "item": "rm88_battle_rifle", "prob": 25, "charges-min": 0, "charges-max": 50 },
{ "item": "sig552", "prob": 100, "charges-min": 0, "charges-max": 30 },
{ "item": "scar_l", "prob": 50, "charges-min": 0, "charges-max": 30 },
{ "item": "nato_assault_rifle", "variant": "scar_l", "prob": 50, "charges-min": 0, "charges-max": 30 },
{ "item": "scar_h", "prob": 50, "charges-min": 0, "charges-max": 20 },
{ "item": "m110a1", "prob": 50, "charges-min": 0, "charges-max": 20 },
{ "item": "acr_300blk", "prob": 15, "charges-min": 0, "charges-max": 30 }
Expand Down Expand Up @@ -785,7 +792,7 @@
{ "item": "hk_mp5k", "prob": 10, "charges-min": 0, "charges-max": 30 },
{ "item": "hk_mp5sd", "prob": 5, "charges-min": 0, "charges-max": 30 },
{ "item": "m1014", "prob": 10, "charges-min": 0, "charges-max": 8 },
{ "item": "m4a1", "prob": 35, "charges-min": 0, "charges-max": 30 },
{ "item": "nato_assault_rifle", "variant": "m4a1", "prob": 35, "charges-min": 0, "charges-max": 30 },
{ "item": "as50", "prob": 5, "charges-min": 0, "charges-max": 10 },
{ "item": "hk417_13", "prob": 30, "charges-min": 0, "charges-max": 20 }
]
Expand Down
2 changes: 1 addition & 1 deletion data/json/itemgroups/defense_mode.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
{ "item": "remington_870" },
{ "item": "browning_blr" },
{ "item": "ak47" },
{ "item": "m4a1" },
{ "item": "nato_assault_rifle", "variant": "m4a1" },
{ "item": "savage_111f" },
{ "item": "hk_g3" },
{ "item": "hk_g80" },
Expand Down
32 changes: 19 additions & 13 deletions data/json/itemgroups/military.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,15 @@
"id": "military_standard_assault_rifles",
"subtype": "distribution",
"entries": [
{ "item": "m4a1", "prob": 88, "charges": [ 0, 30 ] },
{ "item": "m27iar", "prob": 10, "charges": [ 0, 30 ] },
{ "item": "m38dmr", "prob": 1, "charges": [ 0, 30 ] },
{ "item": "nato_assault_rifle", "variant": "m4a1", "prob": 88, "charges": [ 0, 30 ] },
{ "item": "nato_assault_rifle", "variant": "m27iar", "prob": 10, "charges": [ 0, 30 ] },
{
"item": "nato_assault_rifle",
"variant": "m38dmr",
"contents-group": "m38dmr_mods",
"prob": 1,
"charges": [ 0, 30 ]
},
{ "item": "m16a4", "prob": 2, "charges": [ 0, 30 ] }
]
},
Expand Down Expand Up @@ -38,7 +44,7 @@
{ "item": "m17", "prob": 65, "charges": [ 0, 17 ] },
{ "item": "m18", "prob": 30, "charges": [ 0, 17 ] },
{ "item": "glock_19", "prob": 3, "charges": [ 0, 15 ] },
{ "item": "m1911_MEU", "prob": 2, "charges": [ 0, 7 ] }
{ "item": "m1911", "variant": "m1911_MEU", "prob": 2, "charges": [ 0, 7 ] }
]
},
{
Expand Down Expand Up @@ -174,23 +180,23 @@
{ "item": "20x66_flechette", "prob": 3 },
{ "item": "m9", "prob": 6 },
{ "item": "usp_45", "prob": 6 },
{ "item": "m4a1", "prob": 7 },
{ "item": "m4_cqbr", "prob": 1 },
{ "item": "nato_assault_rifle", "variant": "m4a1", "prob": 7 },
{ "item": "nato_assault_rifle", "variant": "m4_cqbr", "prob": 1 },
{ "item": "m231pfw", "prob": 1 },
{ "item": "m16a4", "prob": 5 },
{ "item": "m16a3", "prob": 1 },
{ "item": "nato_assault_rifle", "variant": "m16a3", "prob": 1 },
{ "item": "colt_ro635", "prob": 1 },
{ "item": "p226_9mm", "prob": 1 },
{ "item": "sp2022", "prob": 1 },
{ "item": "h&k416a5", "prob": 7 },
{ "item": "nato_assault_rifle", "variant": "h&k416a5", "prob": 7 },
{ "item": "m1014", "prob": 2 },
{ "item": "scar_l", "prob": 6 },
{ "item": "nato_assault_rifle", "variant": "scar_l", "prob": 6 },
{ "item": "scar_h", "prob": 5 },
{ "item": "sig_mcx_rattler_sbr", "prob": 1 },
{ "item": "m249", "prob": 1 },
{ "item": "m240", "prob": 1 },
{ "item": "m27iar", "prob": 1 },
{ "item": "m38dmr", "prob": 1 },
{ "item": "nato_assault_rifle", "variant": "m27iar", "prob": 1 },
{ "item": "nato_assault_rifle", "variant": "m38dmr", "contents-group": "m38dmr_mods", "prob": 1 },
{ "item": "plasma_gun", "prob": 1 },
{ "item": "m320", "prob": 5 },
{ "item": "m320_mod", "prob": 10 },
Expand Down Expand Up @@ -376,8 +382,8 @@
{ "item": "rm451_flamethrower", "prob": 10, "charges": [ 0, 2000 ] },
{ "item": "m249", "prob": 30, "charges": [ 0, 30 ] },
{ "item": "m240", "prob": 20, "charges": [ 0, 200 ] },
{ "item": "m27iar", "prob": 30, "charges": [ 0, 30 ] },
{ "item": "m38dmr", "prob": 3, "charges": [ 0, 30 ] },
{ "item": "nato_assault_rifle", "variant": "m27iar", "prob": 30, "charges": [ 0, 30 ] },
{ "item": "nato_assault_rifle", "variant": "m38dmr", "contents-group": "m38dmr_mods", "charges": [ 0, 30 ] },
{ "item": "m2browning", "prob": 15, "charges": [ 0, 100 ] },
{ "item": "mark19", "prob": 15, "charges": [ 0, 50 ] },
{ "item": "556", "prob": 30, "charges": [ 1, 30 ] },
Expand Down
Loading

0 comments on commit 9b6e68c

Please sign in to comment.