Skip to content

Commit

Permalink
Fixes #71315. Add ereader power consumption to read_activity_actor.
Browse files Browse the repository at this point in the history
  • Loading branch information
random-cdda-modder authored and random-cdda-player committed Jan 29, 2024
1 parent dc071d3 commit e6983be
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 6 deletions.
20 changes: 19 additions & 1 deletion src/activity_actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -1814,7 +1819,9 @@ void read_activity_actor::do_turn( player_activity &act, Character &who )
_( "<npcname> 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." ),
Expand All @@ -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,
Expand Down
19 changes: 14 additions & 5 deletions tests/reading_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
}
}
}
Expand Down

0 comments on commit e6983be

Please sign in to comment.