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

MVP of grid furniture examine action #1613

Conversation

AngelicosPhosphoros
Copy link
Contributor

@AngelicosPhosphoros AngelicosPhosphoros commented Jun 11, 2022

Summary

SUMMARY: Features "Allow use grid powered welders and soldering irons by [e]xamining"

Purpose of change

#1612
Grid powered furniture should be usable by examining it or it would be worse than vehicle powered ones.

Describe the solution

  • Added new examine action use_furn_fake_item which allows players to activate crafting pseudo items from furniture.
  • Added use_furn_fake_item for grid welder and grid soldering iron.
  • Copied usages from soldering iron and welder to their fake counterparts.
  • Rewritten and generalized vehicle welding usage hack to use furniture too.
  • Little changes in tests.
  • Added TODOs for further improvements.

Describe alternatives you've considered

  • Creating separated iexamine actions for each furniture type.
  • Creating some hidden persistent fake items to avoid rewriting repair hack.

Testing

  • One time usages tested by placing soldering iron, spawning nurse, getting bleeding and cauterizing.
  • Repair activity changes tested using:
    • Repair items using spawned welding cart
    • Try to repair items using spawned welding cart without charges
    • Repair items using grid soldering iron and grid welder
    • Try to repair items using grid soldering iron without power in grid
    • Repair items using soldering iron and tailor kit in inventory
    • Repair items using soldering iron and tailor kit standing in nearby tile
  • Watched variable changes during all manual testing using debugger.

Additional context

See #1612

@AngelicosPhosphoros
Copy link
Contributor Author

изображение

@AngelicosPhosphoros AngelicosPhosphoros changed the title [CR] MVP of grid furniture examine action [CR] [WIP] MVP of grid furniture examine action Jun 11, 2022
@AngelicosPhosphoros AngelicosPhosphoros force-pushed the make_grid_powered_appliances_usable branch from d1136d2 to 6de118d Compare June 11, 2022 11:19
//
// This relies on fact that repairing with real tools
// never use `player_activity::coords`
// and use `player::activity::values` with only one item.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check out activity_actor_definitions.h for something better than the old, ugly coords/values vector hackery.

Copy link
Contributor Author

@AngelicosPhosphoros AngelicosPhosphoros Jun 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is the plan.
I would do that in further work on that issue.
#1612

I just want to split work into chunks to make it easier.

}
}

static void return_unused_charges( hack_type_t hack_type, item &tool, const tripoint &position ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discharge/recharge "cycle" can change the way energy is distributed.
Would be better to note how much energy was in the grid at start, then consume the difference later.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reimplemented original algorithm. Probably, your version is better and more consistent with one time usages on examine action.

Would do it little later in that PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@AngelicosPhosphoros AngelicosPhosphoros force-pushed the make_grid_powered_appliances_usable branch 2 times, most recently from 4c8fd40 to f6ac3b9 Compare June 11, 2022 20:04
@AngelicosPhosphoros AngelicosPhosphoros changed the title [CR] [WIP] MVP of grid furniture examine action MVP of grid furniture examine action Jun 11, 2022
@AngelicosPhosphoros
Copy link
Contributor Author

@Coolthulhu This PR is finished and works stable when I playing.
I think, we can merge it, than I would open another PR with further improvements.

const vehicle &veh,
int interact_part_idx )
{
if( activity.id() != ACT_REPAIR_ITEM ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it happen? Is it expected to happen?
Needs a comment documenting when is this desirable or a debugmsg describing that an undesirable and unexpected event happened.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't happen but allowed.

I moved this code from vehicle.cpp to make hack code more encapsulated in one place so it would be easier to remove later.

raii_fake_tool( const raii_fake_tool & ) = delete;
raii_fake_tool( raii_fake_tool && ) = delete;
raii_fake_tool( const player_activity &activity ): hack_type( get_hack_type( activity ) ) {
if( !hack_type ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expected or unexpected? Needs documentation or debugmsg.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was needed to make RAII easier. Removed now.

item &get_fake_tool() {
return fake_tool;
}
~raii_fake_tool() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RAII sounds unusual and fragile here. Resource consumption should be made explicit, even if it makes it more verbose.
RAII can print debugmsgs on skipped discharge or discharge being called twice.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, old code used RAII here, I just didn't want to change it much.

Removed RAII.

Implementation parts:

* Added new examine action `use_furn_fake_item` which allows players to activate crafting pseudo items from furniture.
* Added `use_furn_fake_item` for grid welder and grid soldering iron.
* Copied usages from soldering iron and welder to their fake counterparts.
* Rewritten and generalized vehicle welding usage hack to use furniture too.
* Little changes in tests.
* Added TODOs for further improvements.

Testings:
* One time usages tested by placing soldering iron, spawning nurse, getting bleeding and cauterizing.
* Repair activity changes tested using:
    - Repair items using spawned welding cart
    - Try to repair items using spawned welding cart without charges
    - Repair items using grid soldering iron and grid welder
    - Try to repair items using grid soldering iron without power in grid
    - Repair items using soldering iron and tailor kit in inventory
    - Repair items using soldering iron and tailor kit standing in nearby tile
* Watched variable changes during all manual testing using debugger.

Additional context:
See cataclysmbnteam#1612
@AngelicosPhosphoros AngelicosPhosphoros force-pushed the make_grid_powered_appliances_usable branch from f6ac3b9 to 8ffaa86 Compare June 15, 2022 16:11
@AngelicosPhosphoros
Copy link
Contributor Author

@Coolthulhu Removed usage of RAII and added comments where requested.

@Coolthulhu Coolthulhu self-assigned this Jun 19, 2022
@Coolthulhu
Copy link
Member

Alright, looks good on paper and I didn't manage to get it to break in manual testing.
It will probably bug out in some edge cases like all big changes inevitably do, so stay tuned for player feedback.
One thing that is hard to predict and painful to reproduce is how will it behave with old saves that saved mid-activity.

@Coolthulhu Coolthulhu merged commit 3f8acfd into cataclysmbnteam:upload Jun 21, 2022
@AngelicosPhosphoros
Copy link
Contributor Author

Alright, looks good on paper and I didn't manage to get it to break in manual testing.
It will probably bug out in some edge cases like all big changes inevitably do, so stay tuned for player feedback.
One thing that is hard to predict and painful to reproduce is how will it behave with old saves that saved mid-activity.

Well, I played with this patch 10 days and didn't got any issues yet.

Now I would begin Full stage of refactoring.

@AngelicosPhosphoros AngelicosPhosphoros deleted the make_grid_powered_appliances_usable branch June 22, 2022 11:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants