Skip to content

Commit

Permalink
Display fridge buff in item::info (#2267)
Browse files Browse the repository at this point in the history
* Refactor item info function

* Display fridge buff in item::info (not used yet)

* Fix up existing info, where desirable

* Post rebase fix

* Remove debug printf, add static in test

* Ensure no integer overflow in time_duration

* Prevent another possible overflow
  • Loading branch information
Coolthulhu authored Jan 28, 2023
1 parent b9a5865 commit 04775f5
Show file tree
Hide file tree
Showing 28 changed files with 487 additions and 288 deletions.
7 changes: 3 additions & 4 deletions src/advanced_inv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1338,11 +1338,10 @@ void advanced_inventory::action_examine( advanced_inv_listitem *sitem,
recalc = true;
} else {
item &it = *sitem->items.front();
std::vector<iteminfo> vThisItem;
std::vector<iteminfo> vDummy;
it.info( true, vThisItem );
std::vector<iteminfo> dummy;
std::vector<iteminfo> item_info = it.info();

item_info_data data( it.tname(), it.type_name(), vThisItem, vDummy );
item_info_data data( it.tname(), it.type_name(), item_info, dummy );
data.handle_scrolling = true;

ret = draw_item_info( [&]() -> catacurses::window {
Expand Down
3 changes: 1 addition & 2 deletions src/crafting_gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,7 @@ const recipe *select_crafting_recipe( int &batch_size )
item_info_scroll = 0;
item_info_scroll_popup = 0;
}
std::vector<iteminfo> info;
item_info_cache.dummy.info( true, info, count );
std::vector<iteminfo> info = item_info_cache.dummy.info( count );
item_info_data data( item_info_cache.dummy.tname( count ),
item_info_cache.dummy.type_name( count ),
info, {}, scroll_pos );
Expand Down
2 changes: 1 addition & 1 deletion src/enums.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ struct enum_traits<holiday> {
static constexpr holiday last = holiday::num_holiday;
};

enum temperature_flag : int {
enum class temperature_flag : int {
TEMP_NORMAL = 0,
TEMP_HEATER,
TEMP_FRIDGE,
Expand Down
7 changes: 5 additions & 2 deletions src/examine_item_menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@
#include "avatar.h"
#include "crafting.h"
#include "game_inventory.h"
#include "map.h"
#include "input.h"
#include "item.h"
#include "item_functions.h"
#include "itype.h"
#include "messages.h"
#include "output.h"
#include "recipe_dictionary.h"
#include "rot.h"
#include "ui_manager.h"
#include "ui.h"

Expand Down Expand Up @@ -55,9 +57,10 @@ bool run(

int info_area_scroll_pos = 0;
constexpr int info_area_scroll_step = 3;
std::vector<iteminfo> item_info_vals;
temperature_flag temperature = rot::temperature_flag_for_location( get_map(), item_location( you,
&itm ) );
std::vector<iteminfo> item_info_vals = itm.info( temperature );
std::vector<iteminfo> dummy_compare;
itm.info( true, item_info_vals );
item_info_data data( itm.tname(), itm.type_name(), item_info_vals, dummy_compare,
info_area_scroll_pos );

Expand Down
25 changes: 15 additions & 10 deletions src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@
#include "recipe.h"
#include "recipe_dictionary.h"
#include "ret_val.h"
#include "rot.h"
#include "rng.h"
#include "safemode_ui.h"
#include "scenario.h"
Expand Down Expand Up @@ -7423,11 +7424,13 @@ game::vmenu_ret game::list_items( const std::vector<map_item_stack> &item_list )
werase( w_item_info );

if( iItemNum > 0 && activeItem ) {
std::vector<iteminfo> vThisItem;
std::vector<iteminfo> vDummy;
activeItem->example->info( true, vThisItem );
item_location loc( map_cursor( u.pos() + activeItem->example_item_pos ),
const_cast<item *>( activeItem->example ) );
temperature_flag temperature = rot::temperature_flag_for_location( m, loc );
std::vector<iteminfo> this_item = activeItem->example->info( temperature );
std::vector<iteminfo> item_info_dummy;

item_info_data dummy( "", "", vThisItem, vDummy, iScrollPos );
item_info_data dummy( "", "", this_item, item_info_dummy, iScrollPos );
dummy.without_getch = true;
dummy.without_border = true;

Expand Down Expand Up @@ -7487,12 +7490,14 @@ game::vmenu_ret game::list_items( const std::vector<map_item_stack> &item_list )
uistate.list_item_filter_active = false;
addcategory = !sort_radius;
} else if( action == "EXAMINE" && !filtered_items.empty() && activeItem ) {
std::vector<iteminfo> vThisItem;
std::vector<iteminfo> vDummy;
activeItem->example->info( true, vThisItem );

item_info_data info_data( activeItem->example->tname(), activeItem->example->type_name(), vThisItem,
vDummy );
std::vector<iteminfo> dummy;
const item *example_item = activeItem->example;
// TODO: const_item_location
item_location loc = item_location( u, const_cast<item *>( example_item ) );
temperature_flag temperature = rot::temperature_flag_for_location( m, loc );
std::vector<iteminfo> this_item = example_item->info( temperature );

item_info_data info_data( example_item->tname(), example_item->type_name(), this_item, dummy );
info_data.handle_scrolling = true;

draw_item_info( [&]() -> catacurses::window {
Expand Down
16 changes: 10 additions & 6 deletions src/game_constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,22 +79,26 @@ static constexpr int PLUTONIUM_CHARGES = 500;
namespace temperatures
{
// temperature at which something starts is considered HOT.
constexpr int hot = 100; // ~ 38 Celsius
constexpr units::temperature hot = 100_f; // ~ 38 Celsius

// the "normal" temperature midpoint between cold and hot.
constexpr int normal = 70; // ~ 21 Celsius
constexpr units::temperature normal = 70_f; // ~ 21 Celsius

// Temperature inside an active fridge in Fahrenheit.
constexpr int fridge = 37; // ~ 2.7 Celsius
constexpr units::temperature fridge = 37_f; // ~ 2.7 Celsius

// Temperature at which things are considered "cold".
constexpr int cold = 40; // ~4.4 C
constexpr units::temperature cold = 40_f; // ~4.4 C

// Temperature inside an active freezer in Fahrenheit.
constexpr int freezer = 23; // -5 Celsius
constexpr units::temperature freezer = 23_f; // -5 Celsius

// Temperature in which water freezes in Fahrenheit.
constexpr int freezing = 32; // 0 Celsius
constexpr units::temperature freezing = 32_f; // 0 Celsius

// Arbitrary constant for root cellar temperature
// Should be equal to AVERAGE_ANNUAL_TEMPERATURE, but is declared before it...
constexpr units::temperature root_cellar = 43_f;
} // namespace temperatures

// Weight per level of LIFT/JACK tool quality.
Expand Down
52 changes: 22 additions & 30 deletions src/game_inventory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1602,45 +1602,37 @@ void game_menus::inv::compare( const item &l, const item &r )
ctxt.register_action( "PAGE_UP" );
ctxt.register_action( "PAGE_DOWN" );

std::vector<iteminfo> vItemLastCh;
std::vector<iteminfo> vItemCh;
std::string sItemLastCh;
std::string sItemCh;
std::string sItemLastTn;
std::string sItemTn;
std::vector<iteminfo> lhs_info = l.info();
std::vector<iteminfo> rhs_info = r.info();
std::string lhs_tname = l.tname();
std::string rhs_tname = r.tname();
std::string lhs_type_name = l.type_name();
std::string rhs_type_name = r.type_name();

l.info( true, vItemLastCh );
sItemLastCh = l.tname();
sItemLastTn = l.type_name();
int lhs_scroll_pos = 0;
int rhs_scroll_pos = 0;

r.info( true, vItemCh );
sItemCh = r.tname();
sItemTn = r.type_name();
item_info_data lhs_item_info( lhs_tname, lhs_type_name, lhs_info, rhs_info, rhs_scroll_pos );
lhs_item_info.without_getch = true;

int iScrollPos = 0;
int iScrollPosLast = 0;
item_info_data rhs_item_info( rhs_tname, rhs_type_name, rhs_info, lhs_info, lhs_scroll_pos );
rhs_item_info.without_getch = true;

item_info_data last_item_info( sItemLastCh, sItemLastTn, vItemLastCh, vItemCh, iScrollPosLast );
last_item_info.without_getch = true;

item_info_data cur_item_info( sItemCh, sItemTn, vItemCh, vItemLastCh, iScrollPos );
cur_item_info.without_getch = true;

catacurses::window w_last_item_info;
catacurses::window w_cur_item_info;
catacurses::window w_lhs_item_info;
catacurses::window w_rhs_item_info;
ui_adaptor ui;
ui.on_screen_resize( [&]( ui_adaptor & ui ) {
const int half_width = TERMX / 2;
const int height = TERMY;
w_last_item_info = catacurses::newwin( height, half_width, point_zero );
w_cur_item_info = catacurses::newwin( height, half_width, point( half_width, 0 ) );
w_lhs_item_info = catacurses::newwin( height, half_width, point_zero );
w_rhs_item_info = catacurses::newwin( height, half_width, point( half_width, 0 ) );
ui.position( point_zero, point( half_width * 2, height ) );
} );
ui.mark_resize();

ui.on_redraw( [&]( const ui_adaptor & ) {
draw_item_info( w_last_item_info, last_item_info );
draw_item_info( w_cur_item_info, cur_item_info );
draw_item_info( w_lhs_item_info, lhs_item_info );
draw_item_info( w_rhs_item_info, rhs_item_info );
} );

do {
Expand All @@ -1649,11 +1641,11 @@ void game_menus::inv::compare( const item &l, const item &r )
action = ctxt.handle_input();

if( action == "UP" || action == "PAGE_UP" ) {
iScrollPos--;
iScrollPosLast--;
lhs_scroll_pos--;
rhs_scroll_pos--;
} else if( action == "DOWN" || action == "PAGE_DOWN" ) {
iScrollPos++;
iScrollPosLast++;
lhs_scroll_pos++;
rhs_scroll_pos++;
}

} while( action != "QUIT" );
Expand Down
3 changes: 2 additions & 1 deletion src/gamemode_defense.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "input.h"
#include "item.h"
#include "item_group.h"
#include "iteminfo_query.h"
#include "map.h"
#include "messages.h"
#include "mongroup.h"
Expand Down Expand Up @@ -1247,7 +1248,7 @@ void draw_caravan_items( const catacurses::window &w, std::vector<itype_id> *ite
// THEN print it--if item_selected is valid
if( item_selected < static_cast<int>( items->size() ) ) {
item tmp( ( *items )[item_selected], calendar::start_of_cataclysm );
fold_and_print( w, point( 1, 12 ), 38, c_white, tmp.info() );
fold_and_print( w, point( 1, 12 ), 38, c_white, tmp.info_string( iteminfo_query::no_text ) );
}
// Next, clear the item list on the right
for( int i = 1; i <= FULL_SCREEN_HEIGHT - 2; i++ ) {
Expand Down
6 changes: 3 additions & 3 deletions src/iexamine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -786,7 +786,7 @@ void iexamine::vending( player &p, const tripoint &examp )
werase( w_item_info );
// | {line}|
// 12 3
fold_and_print( w_item_info, point( 2, 1 ), w_info_w - 3, c_light_gray, cur_item->info( true ) );
fold_and_print( w_item_info, point( 2, 1 ), w_info_w - 3, c_light_gray, cur_item->info_string() );
wborder( w_item_info, LINE_XOXO, LINE_XOXO, LINE_OXOX, LINE_OXOX,
LINE_OXXO, LINE_OOXX, LINE_XXOO, LINE_XOOX );

Expand Down Expand Up @@ -5486,7 +5486,7 @@ void iexamine::mill_finalize( player &, const tripoint &examp, const time_point

for( item &it : items ) {
if( it.type->milling_data ) {
it.calc_rot_while_processing( milling_time );
it.mod_last_rot_check( milling_time );
const islot_milling &mdata = *it.type->milling_data;
item result( mdata.into_, start_time + milling_time, it.count() * mdata.conversion_rate_ );
result.components.push_back( it );
Expand Down Expand Up @@ -5533,7 +5533,7 @@ static void smoker_finalize( player &, const tripoint &examp, const time_point &
if( it.get_comestible()->smoking_result.is_empty() ) {
it.unset_flag( flag_PROCESSING );
} else {
it.calc_rot_while_processing( 6_hours );
it.mod_last_rot_check( 6_hours );

item result( it.get_comestible()->smoking_result, start_time + 6_hours, it.charges );

Expand Down
Loading

0 comments on commit 04775f5

Please sign in to comment.