Skip to content

Commit 8c0751c

Browse files
authored
Merge pull request #79025 from anothersimulacrum/gun-variant-fixes
Misc gun variant script fixes
2 parents 7148609 + 4c02e89 commit 8c0751c

File tree

7 files changed

+119
-77
lines changed

7 files changed

+119
-77
lines changed

data/json/items/gun/3006.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"looks_like": "modular_ar15",
55
"type": "GUN",
66
"reload_noise_volume": 10,
7-
"name": { "str": "magazine-fed lever-action hunting rifle" },
7+
"name": { "str": "BLR lever-action hunting rifle" },
88
"description": "A highly accurate lever-action hunting rifle chambered for the powerful .30-06 round. Notable for using a detachable magazine instead of a traditional tube.",
99
"variant_type": "gun",
1010
"variants": [

data/json/items/gun/38.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@
157157
"copy-from": "pistol_revolver",
158158
"looks_like": "sw_619",
159159
"type": "GUN",
160-
"name": { "str_sp": ".357 revolver" },
160+
"name": { "str_sp": "classic .357 revolver", "//": "This looks like a classic revolver, from a western" },
161161
"//": "This is the Colt Python 2020 6-inch version.",
162162
"description": "A six inch revolver chambered in .357 Magnum/.38 Special. Favorite of sheriffs and post-Cataclysm survivor group leaders.",
163163
"//s": "omg twd reference :O",
@@ -401,7 +401,7 @@
401401
"copy-from": "rifle_manual",
402402
"looks_like": "modular_ar15",
403403
"type": "GUN",
404-
"name": { "str": ".357 lever-action rifle" },
404+
"name": { "str": "long-barreled .357 lever-action rifle" },
405405
"description": "This lever-action rifle is chambered in the powerful .357 Magnum cartridge, with an 20\" barrel with a tube-fed magazine. Go get 'em cowboy!",
406406
"variant_type": "gun",
407407
"variants": [

data/json/items/gun/44.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@
319319
"copy-from": "rifle_manual",
320320
"looks_like": "modular_ar15",
321321
"type": "GUN",
322-
"name": { "str": ".44 lever-action rifle" },
322+
"name": { "str": "long-barreled .44 lever-action rifle" },
323323
"description": "This lever-action rifle is chambered in the powerful .44 Magnum cartridge, with an 20\" barrel with a tube-fed magazine. Go get 'em cowboy!",
324324
"variant_type": "gun",
325325
"variants": [

data/json/items/gun/57.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"looks_like": "glock_17",
55
"type": "GUN",
66
"reload_noise_volume": 10,
7-
"name": { "str": "5.7mm pistol" },
7+
"name": { "str": "FN 5.7mm pistol" },
88
"description": "Firing the armor-piercing 5.7x28mm round, this lightweight handgun was developed for NATO use as a sidearm capable of penetrating body armor. Its proprietary and nonprolific ammunition kept it comparatively rare among both civilian and militant use, but the gun's ability to ignore most forms of conventional ballistic armor can't be argued with. Given that its tiny bullets have next to no stopping power, its armor-penetrating capability comes at a considerable trade-off.",
99
"variant_type": "gun",
1010
"variants": [

data/json/items/magazine/57.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"id": "fn57mag",
44
"looks_like": "glock17_17",
55
"type": "MAGAZINE",
6-
"name": { "str": "5.7mm 20-round pistol magazine" },
6+
"name": { "str": "FN 5.7mm 20-round pistol magazine" },
77
"description": "A 20-round box magazine, for use with handguns chambering the proprietary 5.7x28mm cartridge.",
88
"variant_type": "gun",
99
"variants": [
Lines changed: 64 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,65 @@
1-
{
2-
"type": "palette",
3-
"id": "storage_unit_palette",
4-
"palettes": [
5-
"parametrized_walls_palette"
6-
],
7-
"terrain": {
8-
" ": "t_thconc_floor",
9-
"+": "t_door_c",
10-
".": "t_pavement",
11-
"_": "t_thconc_floor",
12-
"1": "t_window",
13-
"2": "t_sidewalk",
14-
"3": "t_tree_young",
15-
"4": "t_chaingate_l",
16-
"5": "t_wall_wood",
17-
"6": "t_chainfence",
18-
"7": "t_door_metal_locked",
19-
"8": "t_gates_mech_control",
20-
"E": "t_dirtfloor",
21-
"G": "t_dirtfloor",
22-
"I": "t_sidewalk",
23-
"R": "t_pavement_y",
24-
"U": "t_sidewalk",
25-
"V": "t_sidewalk",
26-
"W": "t_sidewalk",
27-
"c": "t_column",
28-
"p": "t_pavement_y",
29-
"r": "t_pavement",
30-
"s": "t_sidewalk",
31-
"y": "t_pavement_y"
32-
},
33-
"furniture": {
34-
"A": "f_rack",
35-
"B": "f_toilet",
36-
"C": "f_counter",
37-
"D": "f_sink",
38-
"E": "f_sink",
39-
"F": "f_chair",
40-
"G": "f_locker",
41-
"H": "f_table",
42-
"I": "f_sofa",
43-
"J": "f_chair",
44-
"K": "f_dumpster",
45-
"L": "f_locker",
46-
"M": [ "f_crate_c", "f_cardboard_box" ],
47-
"R": "f_rubble",
48-
"b": "f_bed",
49-
"d": "f_dresser",
50-
"o": "f_bookcase",
51-
"q": "f_rubble",
52-
"t": "f_table",
53-
"u": "f_rack",
54-
"v": "f_rack_coat",
55-
"w": "f_rubble",
56-
"^": "f_rubble",
57-
"{": [ "f_vending_o", "f_vending_c_off" ]
58-
},
59-
"vendingmachines": {
60-
"U": { "item_group": "vending_drink", "lootable": true },
61-
"V": { "item_group": "vending_food", "lootable": true },
62-
"W": { "item_group": "vending_drink", "lootable": true },
63-
"Á": { "item_group": "vending_food", "lootable": true }
1+
[
2+
{
3+
"type": "palette",
4+
"id": "storage_unit_palette",
5+
"palettes": [ "parametrized_walls_palette" ],
6+
"terrain": {
7+
" ": "t_thconc_floor",
8+
"+": "t_door_c",
9+
".": "t_pavement",
10+
"_": "t_thconc_floor",
11+
"1": "t_window",
12+
"2": "t_sidewalk",
13+
"3": "t_tree_young",
14+
"4": "t_chaingate_l",
15+
"5": "t_wall_wood",
16+
"6": "t_chainfence",
17+
"7": "t_door_metal_locked",
18+
"8": "t_gates_mech_control",
19+
"E": "t_dirtfloor",
20+
"G": "t_dirtfloor",
21+
"I": "t_sidewalk",
22+
"R": "t_pavement_y",
23+
"U": "t_sidewalk",
24+
"V": "t_sidewalk",
25+
"W": "t_sidewalk",
26+
"c": "t_column",
27+
"p": "t_pavement_y",
28+
"r": "t_pavement",
29+
"s": "t_sidewalk",
30+
"y": "t_pavement_y"
31+
},
32+
"furniture": {
33+
"A": "f_rack",
34+
"B": "f_toilet",
35+
"C": "f_counter",
36+
"D": "f_sink",
37+
"E": "f_sink",
38+
"F": "f_chair",
39+
"G": "f_locker",
40+
"H": "f_table",
41+
"I": "f_sofa",
42+
"J": "f_chair",
43+
"K": "f_dumpster",
44+
"L": "f_locker",
45+
"M": [ "f_crate_c", "f_cardboard_box" ],
46+
"R": "f_rubble",
47+
"b": "f_bed",
48+
"d": "f_dresser",
49+
"o": "f_bookcase",
50+
"q": "f_rubble",
51+
"t": "f_table",
52+
"u": "f_rack",
53+
"v": "f_rack_coat",
54+
"w": "f_rubble",
55+
"^": "f_rubble",
56+
"{": [ "f_vending_o", "f_vending_c_off" ]
57+
},
58+
"vendingmachines": {
59+
"U": { "item_group": "vending_drink", "lootable": true },
60+
"V": { "item_group": "vending_food", "lootable": true },
61+
"W": { "item_group": "vending_drink", "lootable": true },
62+
": { "item_group": "vending_food", "lootable": true }
63+
}
6464
}
65-
}
65+
]

tools/json_tools/gun_variant_validator.py

Lines changed: 49 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@
141141
"plasma_gun",
142142
"bbgun",
143143
}
144+
# Stripped from gun/mag names before checking for an identifier
144145
BAD_IDENTIFIERS = [
145146
"10mm",
146147
".22",
@@ -157,9 +158,25 @@
157158
"9x19mm",
158159
"-round",
159160
"magazine",
161+
"pistol",
160162
"stripper",
161163
"speedloader",
162164
]
165+
# Common tokens that will be rejected
166+
BAD_COMMON_TOKENS = {
167+
"rifle",
168+
"carbine",
169+
"pistol",
170+
"ing"
171+
}
172+
# Common tokens that are permitted to be below length reqs
173+
SHORT_COMMON_TOKENS = {
174+
"AI", # Abbreviation of gun manufacturer
175+
"AK", # Common name for a gun family
176+
"FN", # Common name for a manufacturer
177+
"G3", # Common name for a certain gun
178+
"M9", # Common name for a certain gun
179+
}
163180
TYPE_DESCRIPTORS = [
164181
"automagnum",
165182
"blunderbuss",
@@ -195,6 +212,10 @@
195212
"submachine gun",
196213
"trenchgun",
197214
]
215+
DUPE_CHECK_BLACKLIST = [
216+
# No magazines, and very similar tube-fed rifles with slightly diff barrels
217+
{"rio_bravo", "henry_golden_boy"},
218+
]
198219

199220
"""
200221
JSON parsing functions
@@ -591,11 +612,12 @@ def common_token(names):
591612
# Assume the longest common substring will be the "identifier"
592613
# leading/trailing whitespace isn't meaningful in identifiers
593614
common_token = longest_common_substring(names).strip()
594-
# It can't be a meaningful identifier if it's 1 character long
595-
if len(common_token) < 2:
615+
# It can't be a meaningful identifier if it's 1-2 characters long
616+
# Some exceptions (e.g. AK, G3)
617+
if len(common_token) < 3 and common_token not in SHORT_COMMON_TOKENS:
596618
return None
597619
# Some common identifiers that don't work
598-
if common_token in {"11", "to", "if", "ip", "rifle", "carbine"}:
620+
if common_token in BAD_COMMON_TOKENS:
599621
return None
600622
return common_token
601623

@@ -682,7 +704,24 @@ def find_bad_names(all_guns):
682704
"""
683705

684706

707+
def remove_blacklisted_dupes(guns):
708+
if len(guns) == 1:
709+
return guns
710+
guns_set = set(map(lambda gun: gun["id"], guns))
711+
for blacklist_set in DUPE_CHECK_BLACKLIST:
712+
all_match = True
713+
for gun in blacklist_set:
714+
if gun not in guns_set:
715+
print(gun, "not in", guns_set)
716+
all_match = False
717+
break
718+
if all_match:
719+
guns = list(filter(lambda g: g["id"] not in blacklist_set, guns))
720+
return guns
721+
722+
685723
def find_dupe_names(all_guns):
724+
error = False
686725
all_names = {}
687726
for gun in all_guns:
688727
name = name_of(gun) + str(sorted(gun["ammo"]))
@@ -691,12 +730,15 @@ def find_dupe_names(all_guns):
691730
else:
692731
all_names[name] = [gun]
693732
for key, value in all_names.items():
694-
if len(value) == 1:
733+
value = remove_blacklisted_dupes(value)
734+
if len(value) < 2:
695735
continue
696736
out = "ERROR: Guns have the same name and ammo (" + key + "):"
737+
error = True
697738
for gun in value:
698739
out += " (" + gun["id"] + "),"
699740
print(out)
741+
return error
700742

701743

702744
"""
@@ -759,7 +801,7 @@ def check_identifiers(all_guns):
759801
good_tokens = [[]]
760802
idx = 0
761803
len_so_far = 0
762-
for token in good_token_list:
804+
for token in sorted(good_token_list):
763805
guns_str = string_listify(good_token_list[token], " ")
764806
good_tokens[idx].append(f"{token} ({guns_str})")
765807
len_so_far += len(good_tokens[idx][-1])
@@ -781,9 +823,9 @@ def check_names(all_guns):
781823
for bad in bad_names:
782824
print("ERROR: Gun %s (%s) lacks a descriptive name" % (bad[1], bad[0]))
783825

784-
find_dupe_names(all_guns)
826+
dupes = find_dupe_names(all_guns)
785827

786-
return len(bad_names) > 0
828+
return len(bad_names) > 0 or dupes
787829

788830

789831
csv = True

0 commit comments

Comments
 (0)