Skip to content

Commit ad84005

Browse files
committed
Simplify. Just tell people the values don't match (and default a value of 0 if the vitamin isn't present)
1 parent 0d7b15f commit ad84005

File tree

1 file changed

+10
-26
lines changed

1 file changed

+10
-26
lines changed

src/item_factory.cpp

Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -896,39 +896,23 @@ void Item_factory::finalize_post( itype &obj )
896896
if( consume_drug ) {
897897
const consume_drug_iuse *consume_drug_use = dynamic_cast<const consume_drug_iuse *>
898898
( consume_drug->get_actor_ptr() );
899-
// This map is actually empty (i.e no entries) if undefined
900-
const bool has_drug_vitamins = !consume_drug_use->vitamins.empty();
901-
// This map (nutrients) is ALWAYS filled with all vitamin types, but the entries are zero'd, so we cannot check empty()!
902-
const bool has_food_vitamins = obj.comestible->default_nutrition_read_only().has_any_vitamin();
903-
if( has_food_vitamins && !has_drug_vitamins ) {
904-
debugmsg( "Error on item %s: You need to put food vitamins into the consume_drug use_action, for stupid technical reasons.",
905-
obj.id.c_str() );
906-
}
907-
if( has_drug_vitamins && !has_food_vitamins ) {
908-
debugmsg( "Error on item %s: You also need to put the consume_drug vitamins into food vitamins, for stupider technical reasons.",
909-
obj.id.c_str() );
910-
}
911899

912-
// Now to be extra sure, we also compare the vitamins to make sure they're equal...
900+
// We compare the vitamins to make sure they're equal...
913901
const auto &LHS_vitmap = consume_drug_use->vitamins;
914902
const auto &RHS_vitmap = obj.comestible->default_nutrition_read_only().vitamins();
915903
for( const std::pair<const vitamin_id, vitamin> &vit_pair : vitamin::all() ) {
916904
const vitamin_id &vit = vit_pair.first;
905+
// Bounds check. Stupid juggling because LHS is a range, we want the midpoint.
906+
const auto LHS_range = LHS_vitmap.find( vit );
917907
const bool LHS_has_vit = LHS_vitmap.find( vit ) != LHS_vitmap.end();
918908
const bool RHS_has_vit = RHS_vitmap.find( vit ) != RHS_vitmap.end();
919-
if( LHS_has_vit != RHS_has_vit ) {
920-
debugmsg( "Error in item definition %s. Food vitamins and consume_drug vitamins do not match.",
921-
obj.id.c_str() );
922-
break; // stop evaluating this itype, it's already known to be broken.
923-
}
924-
// Bounds check. Stupid juggling because LHS is a range, we want the midpoint. If LHS doesn't have the vitamin we can skip the rest, because we just checked that
925-
// both LHS and RHS should have the vitamin.
926-
const auto LHS_range = LHS_vitmap.find( vit );
927-
if( LHS_range == LHS_vitmap.end() ) {
928-
continue;
929-
}
930-
const int LHS_vit_amt = ( LHS_range->second.first + LHS_range->second.second ) / 2;
931-
const int RHS_vit_amt = RHS_has_vit ? RHS_vitmap.find( vit )->second : 0;
909+
910+
const int LHS_vit_amt = LHS_has_vit ?
911+
( LHS_range->second.first + LHS_range->second.second ) / 2 :
912+
0;
913+
const int RHS_vit_amt = RHS_has_vit ?
914+
RHS_vitmap.find( vit )->second :
915+
0;
932916
if( LHS_vit_amt != RHS_vit_amt ) {
933917
debugmsg( "Error in item definition %s. Food vitamins and consume_drug vitamins have different vitamin amounts for %s.",
934918
obj.id.c_str(), vit.c_str() );

0 commit comments

Comments
 (0)