diff --git a/src/activity_actor.cpp b/src/activity_actor.cpp index da5ffc80362a7..d00f10f330272 100644 --- a/src/activity_actor.cpp +++ b/src/activity_actor.cpp @@ -1776,6 +1776,11 @@ void read_activity_actor::start( player_activity &act, Character &who ) add_msg_debug( debugmode::DF_ACT_READ, "reading time = %s", to_string_writable( time_duration::from_moves( moves_total ) ) ); + // starting the activity should cost a charge to boot up the ebook app + if( using_ereader ) { + ereader->ammo_consume( ereader->ammo_required(), who.pos(), &who ); + } + act.moves_total = moves_total; act.moves_left = moves_total; } @@ -1814,7 +1819,9 @@ void read_activity_actor::do_turn( player_activity &act, Character &who ) _( " no longer has the e-book!" ) ); who.cancel_activity(); return; - } else if( using_ereader && !ereader->ammo_sufficient( &who ) ) { + } + + if( using_ereader && !ereader->ammo_sufficient( &who ) ) { add_msg_if_player_sees( who, _( "%1$s %2$s ran out of batteries." ), @@ -1823,6 +1830,17 @@ void read_activity_actor::do_turn( player_activity &act, Character &who ) who.cancel_activity(); return; } + + if( using_ereader && calendar::once_every( 5_minutes ) ) { + /** Expected battery life while reading with common ereaders: + integrated_ar - implant = potentially infinite + ar_glasses_advanced - max 300 charges from disposable light battery = 25 hours of reading + eink_tablet_pc - max 300 charges from disposable light battery = 25 hours of reading + laptop - max 1200 charges from disposable medium battery = 100 hours of reading + smart_phone - 120 UPS charges = 10 hours of reading + */ + ereader->ammo_consume( ereader->ammo_required(), who.pos(), &who ); + } } void read_activity_actor::read_book( Character &learner, diff --git a/tests/reading_test.cpp b/tests/reading_test.cpp index 728ec0632d80b..dddb1c1f6981d 100644 --- a/tests/reading_test.cpp +++ b/tests/reading_test.cpp @@ -503,18 +503,27 @@ TEST_CASE( "reading_a_book_with_an_ebook_reader", "[reading][book][ereader]" ) read_activity_actor actor( dummy.time_to_read( *booklc, dummy ), booklc, ereader, true ); dummy.activity = player_activity( actor ); + REQUIRE( ereader->ammo_remaining() == 100 ); + dummy.activity.start_or_resume( dummy, false ); REQUIRE( dummy.activity.id() == ACT_READ ); + + CHECK( ereader->ammo_remaining() == 99 ); + dummy.activity.do_turn( dummy ); CHECK( dummy.activity.id() == ACT_READ ); - AND_THEN( "ereader runs out of battery" ) { - ereader->ammo_consume( 100, dummy.pos(), &dummy ); - dummy.activity.do_turn( dummy ); + AND_THEN( "ereader has spent a charge while reading" ) { + CHECK( ereader->ammo_remaining() == 98 ); + + AND_THEN( "ereader runs out of battery" ) { + ereader->ammo_consume( ereader->ammo_remaining(), dummy.pos(), &dummy ); + dummy.activity.do_turn( dummy ); - THEN( "reading stops" ) { - CHECK( dummy.activity.id() != ACT_READ ); + THEN( "reading stops" ) { + CHECK( dummy.activity.id() != ACT_READ ); + } } } }