Join GitHub today
GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.
Sign upOnly charged electronic devices will show time and work as an alarm clocks #28485
Conversation
This comment has been minimized.
This comment has been minimized.
|
This pull request has been mentioned on Cataclysm: Dark Days Ahead. There might be relevant details there: https://discourse.cataclysmdda.org/t/cellphones-show-the-time-with-0-charge/19041/4 |
This comment has been minimized.
This comment has been minimized.
rangilin
commented
Mar 4, 2019
|
I could be wrong as I am not familiar with the code base, but I feel like this change can cause unintended behaviors. For example:
|
This comment has been minimized.
This comment has been minimized.
|
Yeah, it seems you are right. Will work on it. |
Night-Pryanik
changed the title
Only charged electronic devices will show time
[WIP] Only charged electronic devices will show time
Mar 4, 2019
Night-Pryanik
added some commits
Mar 4, 2019
Night-Pryanik
changed the title
[WIP] Only charged electronic devices will show time
Only charged electronic devices will show time and work as an alarm clocks
Mar 4, 2019
kevingranade
changed the base branch from
development
to
master
Mar 5, 2019
kevingranade
changed the base branch from
master
to
development
Mar 5, 2019
This comment has been minimized.
This comment has been minimized.
|
I'm not sure what's happening, but this is causing crashes:
The assertion in cata::optional<islot_tool>::get() is failing, but I'm not sure what is triggering it. |
This comment has been minimized.
This comment has been minimized.
|
Crash on game start? |
AMurkin
reviewed
Mar 5, 2019
| return has_item_with( [&flag]( const item & it ) { | ||
| return has_item_with( [&flag, &need_charges]( const item & it ) { | ||
| if( need_charges ) { | ||
| return it.has_flag( flag ) && it.type->tool->max_charges ? it.charges > 0 : it.has_flag( flag ); |
This comment has been minimized.
This comment has been minimized.
AMurkin
Mar 5, 2019
Contributor
You need to check it.is_tool() probably. And what function does it.type->tool->max_charges perform here?
This comment has been minimized.
This comment has been minimized.
Night-Pryanik
Mar 5, 2019
Author
Member
Check for max_charges is a hack to check if this item requires charges to work.
This comment has been minimized.
This comment has been minimized.
|
Added a sanity check for tools. |
kevingranade
reviewed
Mar 8, 2019
| return has_item_with( [&flag]( const item & it ) { | ||
| return has_item_with( [&flag, &need_charges]( const item & it ) { | ||
| if( it.is_tool() && need_charges ) { | ||
| return it.has_flag( flag ) && it.type->tool->max_charges ? it.charges > 0 : it.has_flag( flag ); |
This comment has been minimized.
This comment has been minimized.
kevingranade
Mar 8, 2019
Member
| return it.has_flag( flag ) && it.type->tool->max_charges ? it.charges > 0 : it.has_flag( flag ); | |
| return it.has_flag( flag ) && it.type->tool->max_charges ? it.charges > 0 : true; |
Night-Pryanik commentedMar 4, 2019
Summary
SUMMARY: Bugfixes "Fixed electronic devices with 0 charge still showing time."Purpose of change
Fix issue mentioned here.
Describe the solution
Check if an item has an appropriate flag (
WATCH) and hasmax_chargesfield (= it accepts batteries, like game watch or cellphone). If if does, check if the item has at least one charge. If either of the checks fail, bail out. Otherwise, item can show time.If an item has the flag, but doesn't accept batteries (like gold watch), it can show time.