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

Fix cow milking from cows from old saves with old milk not raw milk. #37965

Merged
merged 10 commits into from Mar 2, 2020
5 changes: 2 additions & 3 deletions src/monexamine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -668,10 +668,9 @@ void monexamine::tie_or_untie( monster &z )

void monexamine::milk_source( monster &source_mon )
{
const auto milked_item = source_mon.ammo.find( "milk_raw" );
auto milked_item = source_mon.ammo.find( "milk_raw" );
if( milked_item == source_mon.ammo.end() ) {
debugmsg( "%s is milkable but has no milk in its starting ammo!",
source_mon.get_name() );
add_msg( m_info, _( "The %s has no milk." ), source_mon.get_name() );
return;
}
if( milked_item->second > 0 ) {
Expand Down
38 changes: 31 additions & 7 deletions src/monster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -362,15 +362,37 @@ void monster::try_reproduce()

void monster::refill_udders()
{
if( !has_flag( MF_MILKABLE ) ) {
return;
auto milked_item = type->starting_ammo.find( "milk_raw " );
if( milked_item == type->starting_ammo.end() ) {
milked_item = type->starting_ammo.find( "milk" );
if( milked_item == type->starting_ammo.end() ) {
// this may be a sheep from a very old save.
// sheep didnt use to be milkable, but now they have that flag,
// but the old save would keep their old blank starting ammo.
// cant modify the type, and cant get what their starting ammo should be.
This conversation was marked as resolved.
Show resolved Hide resolved
// so just let the sheep remain milkless
return;
}
}
const auto milked_item = type->starting_ammo.find( "milk_raw" );
auto current_milk = ammo.find( "milk_raw" );
if( milked_item == type->starting_ammo.end() || current_milk == ammo.end() ) {
debugmsg( "%s is milkable but has no milk in its starting ammo!", get_name() );
return;
if( current_milk == ammo.end() ) {
current_milk = ammo.find( "milk" );
if( current_milk == ammo.end() ) {
debugmsg( "%s has neither milk nor raw milk in its udders", get_name() );
return;
} else {
// take this opportunity to update udders to raw_milk
std::swap( ammo["milk_raw"], current_milk->second );
// Erase old key-value from map
ammo.erase( current_milk );
current_milk = ammo.find( "milk_raw" );
if( current_milk == ammo.end() ) {
//how?
This conversation was marked as resolved.
Show resolved Hide resolved
return;
}
}
}
// if we got here, we got milk.
if( current_milk->second == milked_item->second ) {
// already full up
return;
Expand Down Expand Up @@ -2816,7 +2838,9 @@ void monster::on_load()
try_upgrade( false );
try_reproduce();
try_biosignature();
refill_udders();
if( has_flag( MF_MILKABLE ) ) {
refill_udders();
}

const time_duration dt = calendar::turn - last_updated;
last_updated = calendar::turn;
Expand Down