Skip to content

Commit 3819302

Browse files
fix: migrate legacy swords to proc recipes
Assisted-by: openai/gpt-5.4 on opencode Co-authored-by: chatgpt-codex-connector[bot] <199175422+chatgpt-codex-connector[bot]@users.noreply.github.com>
1 parent ba10d18 commit 3819302

File tree

5 files changed

+66
-12
lines changed

5 files changed

+66
-12
lines changed

data/json/obsoletion/migration.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -729,6 +729,11 @@
729729
"type": "MIGRATION",
730730
"replace": "multi_cooker"
731731
},
732+
{
733+
"id": [ "sword_metal", "sword_wood", "sword_nail", "sword_crude", "sword_bone" ],
734+
"type": "MIGRATION",
735+
"replace": "proc_sword_generic"
736+
},
732737
{
733738
"id": [
734739
"blt",

data/json/obsoletion/recipes.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2321,5 +2321,30 @@
23212321
"type": "recipe",
23222322
"result": "fish_sandwich",
23232323
"obsolete": true
2324+
},
2325+
{
2326+
"type": "recipe",
2327+
"result": "sword_wood",
2328+
"obsolete": true
2329+
},
2330+
{
2331+
"type": "recipe",
2332+
"result": "sword_nail",
2333+
"obsolete": true
2334+
},
2335+
{
2336+
"type": "recipe",
2337+
"result": "sword_crude",
2338+
"obsolete": true
2339+
},
2340+
{
2341+
"type": "recipe",
2342+
"result": "sword_metal",
2343+
"obsolete": true
2344+
},
2345+
{
2346+
"type": "recipe",
2347+
"result": "sword_bone",
2348+
"obsolete": true
23242349
}
23252350
]

data/json/recipes/weapon/proc_sword.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"skill_used": "fabrication",
88
"difficulty": 2,
99
"time": 1500,
10+
"reversible": true,
1011
"proc": true,
1112
"proc_id": "sword",
1213
"builder_name": { "str": "Sword" },

src/proc_item.cpp

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -161,17 +161,18 @@ auto make_legacy_sandwich_part( const legacy_sandwich_part_spec &spec ) -> proc:
161161
return part;
162162
}
163163

164-
auto default_weapon_blob( const item &it ) -> proc::fast_blob
164+
auto default_weapon_blob( const itype_id &source_id ) -> proc::fast_blob
165165
{
166+
const auto source = item( source_id, calendar::turn );
166167
auto blob = proc::fast_blob{};
167-
blob.mass_g = units::to_gram( it.weight() );
168-
blob.volume_ml = units::to_milliliter( it.volume() );
169-
blob.name = it.type_name();
170-
blob.melee.bash = it.damage_melee( DT_BASH );
171-
blob.melee.cut = it.damage_melee( DT_CUT );
172-
blob.melee.stab = it.damage_melee( DT_STAB );
173-
blob.melee.to_hit = it.type->m_to_hit;
174-
blob.melee.dur = std::max( it.max_damage(), 0 );
168+
blob.mass_g = units::to_gram( source.weight() );
169+
blob.volume_ml = units::to_milliliter( source.volume() );
170+
blob.name = source.type_name();
171+
blob.melee.bash = source.damage_melee( DT_BASH );
172+
blob.melee.cut = source.damage_melee( DT_CUT );
173+
blob.melee.stab = source.damage_melee( DT_STAB );
174+
blob.melee.to_hit = source.type->m_to_hit;
175+
blob.melee.dur = std::max( source.max_damage(), 0 );
175176
return blob;
176177
}
177178

@@ -903,7 +904,7 @@ auto legacy_sandwich_payload( const item &it,
903904
return out;
904905
}
905906

906-
auto legacy_weapon_payload( const item &it,
907+
auto legacy_weapon_payload( const item &,
907908
const itype_id &legacy_id ) -> std::optional<payload>
908909
{
909910
const auto specs = legacy_weapon_specs( legacy_id );
@@ -924,7 +925,7 @@ auto legacy_weapon_payload( const item &it,
924925
out.id = schema_id( "sword" );
925926
out.mode = hist::compact;
926927
out.fp = "sword:legacy:" + legacy_id.str();
927-
out.blob = default_weapon_blob( it );
928+
out.blob = default_weapon_blob( legacy_id );
928929
out.parts = make_compact_parts( facts, slots );
929930
return out;
930931
}

tests/proc_payload_test.cpp

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,11 +357,14 @@ TEST_CASE( "legacy_swords_gain_proc_payload_on_save_load", "[proc][payload][migr
357357
CHECK( payload->id == proc::schema_id( "sword" ) );
358358
CHECK( payload->mode == proc::hist::compact );
359359
CHECK( payload->fp == "sword:legacy:" + test_case.id.str() );
360-
CHECK( restored->typeId() == test_case.id );
360+
CHECK( item_controller->migrate_id( test_case.id ) == itype_id( "proc_sword_generic" ) );
361+
CHECK( restored->typeId() == itype_id( "proc_sword_generic" ) );
361362
CHECK( restored->type_name() == legacy.type_name() );
362363
CHECK( payload->blob.name == legacy.type_name() );
363364
CHECK( payload->blob.mass_g == units::to_gram( legacy.weight() ) );
364365
CHECK( payload->blob.volume_ml == units::to_milliliter( legacy.volume() ) );
366+
CHECK( units::to_gram( restored->weight() ) == units::to_gram( legacy.weight() ) );
367+
CHECK( restored->volume() == legacy.volume() );
365368
CHECK( payload->blob.melee.bash == legacy.damage_melee( DT_BASH ) );
366369
CHECK( payload->blob.melee.cut == legacy.damage_melee( DT_CUT ) );
367370
CHECK( payload->blob.melee.stab == legacy.damage_melee( DT_STAB ) );
@@ -380,6 +383,25 @@ TEST_CASE( "legacy_swords_gain_proc_payload_on_save_load", "[proc][payload][migr
380383
} );
381384
}
382385

386+
TEST_CASE( "legacy_sword_ids_migrate_to_proc_uncraft_recipe", "[proc][payload][migration]" )
387+
{
388+
CHECK( recipe_dictionary::get_uncraft( itype_id( "proc_sword_generic" ) ) );
389+
390+
const auto cases = std::vector<itype_id> {
391+
itype_id( "sword_metal" ),
392+
itype_id( "sword_wood" ),
393+
itype_id( "sword_nail" ),
394+
itype_id( "sword_crude" ),
395+
itype_id( "sword_bone" )
396+
};
397+
398+
std::ranges::for_each( cases, [&]( const itype_id & test_case ) {
399+
INFO( test_case.str() );
400+
CHECK( item_controller->migrate_id( test_case ) == itype_id( "proc_sword_generic" ) );
401+
CHECK( recipe_dictionary::get_uncraft( item_controller->migrate_id( test_case ) ) );
402+
} );
403+
}
404+
383405
TEST_CASE( "legacy_sandwich_ids_migrate_to_proc_uncraft_recipe", "[proc][payload][migration]" )
384406
{
385407
CHECK( recipe_dictionary::get_uncraft( itype_id( "sandwich_generic" ) ) );

0 commit comments

Comments
 (0)