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

Add gun variants, allowing to specify multiple guns with the same stat block #46814

Merged
merged 7 commits into from
Mar 25, 2021

Conversation

anothersimulacrum
Copy link
Member

Summary

SUMMARY: Infrastructure "Add gun variants"

Purpose of change

To say we have a lot of guns is an understatement. In particular, we have a lot of very similar guns with fully defined, yet very similar, statblocks. Because the only information that distinguishes these variants is not important, we can ditch these full statblocks, and switch them these variants to be simply cosmetic. Additionally, add a simple toggle to distinguish between generic names and brand names, because the huge variety of guns in our game can be a little overwhelming - think of it as a generic guns-lite.

Describe the solution

Add a vector of potential gun variants to islot_gun. These variants consist of an std::string id, a name and description, an ascii art id, and an integer weight.
If the generic gun names option is turned off, the description, art, and name of the gun will be replaced with those specified in the variant.

I couldn't quite figure out what I needed to do to satisfy the archive stuff, so I added more permissive overloads that do what I want.

Plumb specifying variants through all our item spawning.
All guns will randomly start out with a variant (if they can have one), selected based on the weight of the various variants.

The criteria I am using for not collapsing guns into a variant are:

  • different ammo type
  • different magazines/ammo capacity
  • different fire modes

I have done so for the NATO assault rifles as an example in this PR.
I don't know where to start with the weighting for the variants, so everything without a variant will be an m4a1, which I figure will be the most common.

See commits for more detail.

Describe alternatives you've considered

Making variants more generic. This may happen in the future, but I'd like to stay limited in scope at the moment.
Making different decisions in naming/description/which guns I collapsed into variants.

Testing

Before applying, spawn every .223 gun, and save the world.
After applying, see that when the generic gun names option is turned on, all NATO assault rifles stack and have a generic name. When turned off, they have variant names, and do not stack.
Go to military bases, spawn in helicopters, check out the soldiers map extra, etc to examine other spawning options and see that variants are spawned.
Use the debug menu (search for the generic name) to see that when spawned without an explicit variant, they assume one based on the weight of their variants.

@anothersimulacrum anothersimulacrum added 0.F Feature Freeze [C++] Changes (can be) made in C++. Previously named `Code` [JSON] Changes (can be) made in JSON <Enhancement / Feature> New features, or enhancements on existing labels Jan 17, 2021
@anothersimulacrum anothersimulacrum force-pushed the tenkatsu branch 5 times, most recently from 173a5df to 3cb672f Compare January 17, 2021 05:37
[ "sig552", -1 ],
[ "surv_carbine_223", -1 ]
],
[ [ "nato_assault_rifle", -1 ], [ "ar15", -1 ], [ "m249", -1 ], [ "m16a4", -1 ], [ "surv_carbine_223", -1 ] ],
Copy link
Contributor

@Night-Pryanik Night-Pryanik Jan 17, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

m16a4 should be converted to nato_assault_rifle too, no?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does not have auto, it has burst. I converted the m16a3 to it because it has the same fire modes, but the m16a4 does not.
While it's not very different now, hopefully in the future it will matter.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could some of the other differences be accounted for as gunmods (e.g., a folding stock)? (Admittedly, they're likely not to be quite the same statistically - not coming built-in from the manufacturer.)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It appears gunmods can change firing modes, so that is a route that we could go down.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've elected to just copy-from all non-differentiating information from the nato_assault_rifle, see the latest commit.

@SirPendrak
Copy link
Contributor

Whats the difference between this change, and just using more copy-from for theese guns?

@anothersimulacrum
Copy link
Member Author

I can add a 'generic gun names' option, and it explicitly indicates that minor differences in stat blocks do not matter (because they cannot be specified).

@anothersimulacrum anothersimulacrum force-pushed the tenkatsu branch 2 times, most recently from a93b14c to ce4fe96 Compare February 2, 2021 06:23
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.
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.
Allow specifying variatns in item groups, mapgen
(Item_group::add_item_entry), and in vehicles.
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.
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.
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.
"name": { "str": "Vector SMG 30-round magazine" },
"description": "A 30-round polymer and steel box magazine for use with the KRISS Vector.",
"name": { "str": "Glock SMG 30-round magazine" },
"description": "A 30-round polymer and steel box magazine for use with the Glock submachine gun.",
Copy link

@ghost ghost Feb 8, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Glock doesn't make submachine guns(18C is a machine pistol), KRISS is a different company whose Vector can use their magazines.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Vector is an SMG taking Glock magazines (and it's own special one). I think it's more clear to call it a Glock SMG and call it's magazine a Glock SMG magazine, than to be accurate.

That is, unless there is some sort of change that could come in the future that will change it from accepting only it's own magazines (that go into no other guns), and Glock magazines, or Glock decides to release an SMG of its own that does not accept Vector magazines.

@John-Candlebury
Copy link
Member

Do you think it would be possible or desirable to make variants specify integral/included gun mods?

For example: To my uderstanding H&k416 is basically an m4 with an improved piston that makes it more reliable. And this could be simulated by having the spawned gun always come with a reliability gun mod.

@ZhilkinSerg ZhilkinSerg changed the base branch from master to 0.F-dev March 25, 2021 07:23
ZhilkinSerg pushed a commit that referenced this pull request Mar 31, 2021
…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.
ZhilkinSerg pushed a commit that referenced this pull request Mar 31, 2021
…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.
ZhilkinSerg pushed a commit that referenced this pull request Mar 31, 2021
…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.
BrettDong pushed a commit that referenced this pull request Apr 5, 2021
…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.
ZhilkinSerg pushed a commit that referenced this pull request Apr 7, 2021
…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.
ZhilkinSerg pushed a commit that referenced this pull request Apr 9, 2021
…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.
ZhilkinSerg pushed a commit that referenced this pull request Apr 20, 2021
…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.
ZhilkinSerg pushed a commit that referenced this pull request Apr 20, 2021
…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.
ZhilkinSerg pushed a commit that referenced this pull request Apr 20, 2021
…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.
ZhilkinSerg pushed a commit that referenced this pull request May 28, 2021
…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.
ZhilkinSerg pushed a commit that referenced this pull request May 28, 2021
…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.
ZhilkinSerg pushed a commit that referenced this pull request May 31, 2021
…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.
@Maddremor
Copy link
Contributor

Maddremor commented Jun 1, 2021

Coming to this pretty late, but is there any way of referencing a specific variant by ID, be it in crafting or migration?
Are variants strictly limited to being copy-from that can only change name and description, or is there/will there be more parameters?
Can variants be removed or changed with copy-from if used in a mod?

@anothersimulacrum
Copy link
Member Author

Coming to this pretty late, but is there any way of referencing a specific variant by ID, be it in crafting or migration?

In migration, yes, crafting, no.

Are variants strictly limited to being copy-from that can only change name and description, or is there/will there be more parameters?

They can also change ascii art, but nothing else at this time. I don't have intent to add more parameters, but that doesn't mean they can't be added.

Can variants be removed or changed with copy-from if used in a mod?

Probably not.

ZhilkinSerg pushed a commit that referenced this pull request Jun 14, 2021
…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.
ZhilkinSerg pushed a commit that referenced this pull request Jun 14, 2021
…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.
ZhilkinSerg pushed a commit that referenced this pull request Jun 14, 2021
…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.
ZhilkinSerg pushed a commit that referenced this pull request Jun 21, 2021
…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.
ZhilkinSerg pushed a commit that referenced this pull request Jul 3, 2021
…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.
anothersimulacrum added a commit to anothersimulacrum/Cataclysm-DDA that referenced this pull request Jul 3, 2021
…t block (CleverRaven#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.
KorGgenT pushed a commit to KorGgenT/Cataclysm-DDA that referenced this pull request Jul 4, 2021
…t block (CleverRaven#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.
Maleclypse pushed a commit to Maleclypse/Cataclysm-DDA that referenced this pull request Jul 4, 2021
…t block (CleverRaven#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.
chaosvolt added a commit to chaosvolt/nocts_cata_mod that referenced this pull request Jul 4, 2021
* Updated gun spawns in a mapgen variant to use gun variants in the DDA, since CleverRaven/Cataclysm-DDA#46814 changed item IDs.
* Updated recipe for survivor's auxiliary .45 pistol in the DDA version, since now the M45 and Mk. 23 are variants instead of distinct guns.
* Removed obsolete references to the `burst` property from both versions. They've been obsolete a while but only 0.F experimental DDA is reporting them as an error.
Maleclypse added a commit to Maleclypse/Cataclysm-DDA that referenced this pull request Jul 4, 2021
This was referenced Jul 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[C++] Changes (can be) made in C++. Previously named `Code` <Enhancement / Feature> New features, or enhancements on existing [JSON] Changes (can be) made in JSON
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants