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

[RDY] Vehicle mounted washing machine #21650

Merged

Conversation

Projects
None yet
8 participants
@Night-Pryanik
Copy link
Member

commented Aug 17, 2017

  • Washing machine for now spawns only in deluxe RV. Changed it for one of the seats.
  • It can hold items up to total volume of 40 liters.
  • Player needs 24 charges (6 liters) of water (decided not to use clean water for washing purposes) and 5 charges of detergent. The machine is connected to the vehicle water tanks, so water is auto-drained on activation. Detergent is auto-consumed from the player's inventory.
  • Washing program has a fixed duration of 1,5 hours.
  • Player should wash only filthy items.
  • Player can manually stop the activated machine before it's completed its program. In that case filthy items won't be cleaned, water and detergent will be simply lost.
  • Player puts items in the machine and activates it. This means that he closes the lid of the machine, so he can't get his items back until washing machine is stopped - either automatically or manual.
  • Game will inform player about remaining duration of the washing process every 15 minutes.
  • There is issue I found - one can still put items in the activated (=closed) machine. That can be abstracted though - imagine it is the machine with upper (not side) lid that can be opened at will, even during the washing process, and player just adds some more items to the machine.
  • All numbers and values are a subject for discussion.

Night-Pryanik added some commits Aug 17, 2017

Added option to interact with the washing machine in the vehicle
To activate the machine, player needs to have 24 charges of water and 5 charges of detergent
Water is auto-drained from the vehicle tanks, detergent is auto-consumed from the player's inventory
Process the washing machine.
The washing program will take 90 minutes to complete.
Game will inform the player about remaining duration of the washing process every 15 minutes.
@ZhilkinSerg

This comment has been minimized.

Copy link
Contributor

commented Aug 17, 2017

Gorgon says that something is not good with astyle:

21:09:02 astyle regressions found.
21:09:02 Formatted  src/pickup.cpp
21:09:02 Makefile:950: recipe for target 'astyle-check' failed
21:09:02 make: *** [astyle-check] Error 1
@AMurkin

This comment has been minimized.

Copy link
Contributor

commented Aug 17, 2017

Also it ironically states 21:09:00 +./mainline-build.zsh:87> make clean

@ZhilkinSerg
Copy link
Contributor

left a comment

sorry

src/map.cpp Outdated
cur_veh->parts[part].enabled = false;
counter = 0;
} else if( calendar::once_every( MINUTES( 15 ) ) ) {
add_msg( _("It should take %d minutes to finish washing."), time_left / MINUTES( 1 ) + 1 );

This comment has been minimized.

Copy link
@ZhilkinSerg

ZhilkinSerg Aug 17, 2017

Contributor

Whitespaces are probably required in _ function?

This comment has been minimized.

Copy link
@Night-Pryanik

Night-Pryanik Aug 17, 2017

Author Member

Fixed.

@Coolthulhu

This comment has been minimized.

Copy link
Contributor

commented Aug 17, 2017

Statics are unacceptable here.
Consider the case where two vehicles have washing machines:

  • Turn on first machine
  • Turn on second machine
  • First machine increments static counter
  • Second machine increments same exact static counter
  • Increments repeat for washing_time / 2
  • First washing machine finishes washing in washing_time / 2
  • Second machine finishes washing in washing_time * 3 / 2

This only gets worse as more machines are in the bubble.

The easiest way to fix it would be to have washing machine note in its item (vehicle_part::base) when washing started and use this number.

@Night-Pryanik

This comment has been minimized.

Copy link
Member Author

commented Aug 17, 2017

The easiest way to fix it would be to have washing machine note in its item (vehicle_part::base) when washing started and use this number.

Umm, need some help on this.

@@ -83,6 +83,9 @@ interact_results interact_with_vehicle( vehicle *veh, const tripoint &pos,
const bool can_be_folded = veh->is_foldable();
const bool is_convertible = ( veh->tags.count( "convertible" ) > 0 );
const bool remotely_controlled = g->remoteveh() == veh;
const bool has_washmachine = ( veh->part_with_feature( veh_root_part, "WASHING_MACHINE" ) >= 0 );
bool working = false;

This comment has been minimized.

Copy link
@Coolthulhu

Coolthulhu Aug 17, 2017

Contributor

washing_machine_on or something like that. Ambiguous variable names make code harder to read.

This comment has been minimized.

Copy link
@Night-Pryanik

Night-Pryanik Aug 18, 2017

Author Member

Well, I'm not against renaming, but the name has_washmachine was taken by an analogy of has_kitchen, has_weldrig and so on just above.

This comment has been minimized.

Copy link
@AMurkin

AMurkin Aug 18, 2017

Contributor

I think it's about working flag

This comment has been minimized.

Copy link
@Night-Pryanik

Night-Pryanik Aug 18, 2017

Author Member

Oh, sorry, mislooked.

@@ -83,6 +83,9 @@ interact_results interact_with_vehicle( vehicle *veh, const tripoint &pos,
const bool can_be_folded = veh->is_foldable();
const bool is_convertible = ( veh->tags.count( "convertible" ) > 0 );
const bool remotely_controlled = g->remoteveh() == veh;
const bool has_washmachine = ( veh->part_with_feature( veh_root_part, "WASHING_MACHINE" ) >= 0 );
bool working = false;
bool detergent_is_enough = false;

This comment has been minimized.

Copy link
@Coolthulhu

Coolthulhu Aug 17, 2017

Contributor

Move this variable into the case.
You can have variable declarations inside a case if you wrap the block in braces, like this:

switch( x ) {
    case y: {
        bool is_happening = true;
        if( is_happening ) add_msg( m_good, "It's happening!" );
    }
}

This comment has been minimized.

Copy link
@Night-Pryanik

Night-Pryanik Aug 18, 2017

Author Member

Move this variable into the case.

You mean move bool detergent_is_enough = false into the USE_WASHMACHINE case?

This comment has been minimized.

Copy link
@Coolthulhu

Coolthulhu Aug 18, 2017

Contributor

Yes.
Nothing else uses it.

This comment has been minimized.

Copy link
@Night-Pryanik

Night-Pryanik Aug 18, 2017

Author Member

Moving bool detergent_is_enough = false into the USE_WASHMACHINE case generates crosses initialization of 'bool detergent_is_enough' error.

This comment has been minimized.

Copy link
@Coolthulhu

Coolthulhu Aug 18, 2017

Contributor

As I said: you need an extra pair of braces inside the case.
Look at my example above.

This comment has been minimized.

Copy link
@Night-Pryanik

Night-Pryanik Aug 18, 2017

Author Member

Ok, thanks. Fixed in 3af7934.

veh->tags.erase( "manual_stop" );
add_msg( m_neutral, _( "You close the lid of the washing machine, and turn it on. The washing machine is being filled with soapy water." ) );
}
}

This comment has been minimized.

Copy link
@Coolthulhu

Coolthulhu Aug 17, 2017

Contributor

Would be better if you moved the whole block to interact_with_vehicle in pickup.cpp.
Washing machine should not require you to go to vehicle controls to activate it, but rather should be interacted with directly.

This comment has been minimized.

Copy link
@Night-Pryanik

Night-Pryanik Aug 18, 2017

Author Member

But it is already in interact_with_vehicle in pickup.cpp. And it indeed working by interacting with it directly, not through controls.

This comment has been minimized.

Copy link
@Coolthulhu

Coolthulhu Aug 18, 2017

Contributor

Oh, my bad then

@Coolthulhu

This comment has been minimized.

Copy link
Contributor

commented Aug 17, 2017

Umm, need some help on this.

This isn't exactly easy. Vehicle parts aren't easy to work with.

I think I have an easier idea, though:

  • In interact_with_vehicle in pickup.cpp, check if there is a washing machine
  • Check if the washing machine is enabled
  • If washing machine is not enabled, it means it isn't working (duh). Proceed with all the checks for water and detergent. If everything is OK, demand that the player removes all non-filthy items (if any). If there are none, ask the player if they want to enable it. If player wants to enable it, close and enable the machine, and set birthday of all items (or just the first item) inside machine to current turn
  • If the machine is enabled, it is working. Player can open it, but the items inside will still be dirty AND the machine will become disabled.
  • In vehicle::idle, check if the first item in any enabled machine is already washed. Like this: first_item.bday + washing_time > current_turn. If it is, disable the machine and clean all the items in machine.

That way it would work similarly to furniture charcoal kiln.

Night-Pryanik added some commits Aug 18, 2017

Corrected remove of the FILTHY flag for more than one item.
Also, moved variables into for cycle.
@Night-Pryanik

This comment has been minimized.

Copy link
Member Author

commented Aug 18, 2017

I was able to get rid of the static counters.
Activating the machine set the bday of the filthy item to the current turn. Then in process_vehicle_items the game checks for the time_left == washing_time - calendar::turn.get_turn() + bday. If there is no time left, stop the process, and clean the filthy clothes.

@Coolthulhu

This comment has been minimized.

Copy link
Contributor

commented Aug 18, 2017

There are still some issues:

  • You can wash - and thus apply bday change - to all items, including those that rely on bday to do calculations (food, corpses). You could wash a stack of squirrel corpses to freshen them.
  • "Washing machine has finished" x20, because you apply finishing per item. Either check only the first item or check them all, then clean them up in a separate loop, then print one message.
  • Which machine has finished washing? When batteries die, they say which vehicle lost battery power.

EDIT: Also check gorgon/travis complaints.

@Night-Pryanik

This comment has been minimized.

Copy link
Member Author

commented Aug 18, 2017

You can wash - and thus apply bday change - to all items, including those that rely on bday to do calculations (food, corpses). You could wash a stack of squirrel corpses to freshen them.

Fixed in abaca20.

"Washing machine has finished" x20, because you apply finishing per item. Either check only the first item or check them all, then clean them up in a separate loop, then print one message.

Fixed in da82944.

Which machine has finished washing? When batteries die, they say which vehicle lost battery power.

Fixed in 1b09a2d.

@Night-Pryanik

This comment has been minimized.

Copy link
Member Author

commented Aug 18, 2017

I just can't to figure out what are the problems with astyle in pickup.cpp.

Night-Pryanik added some commits Aug 18, 2017

@Coolthulhu

This comment has been minimized.

Copy link
Contributor

commented Aug 18, 2017

It would be easiest if you just downloaded the astyle binary version 2.05.1 and ran it (from command line), like this:

astyle.exe --options=path\to\Cataclysm-DDA\.astylerc -n path\to\Cataclysm-DDA\src\pickup.cpp

Astyle sometimes has really stupid requirements that you won't figure out yourself. For example, it may require very strict line breaks that look ugly, or weird alignment.

src/map.cpp Outdated
@@ -4672,6 +4672,28 @@ static void process_vehicle_items( vehicle *cur_veh, int part )
apply_in_fridge(n);
}
}

const bool washmachine_here = cur_veh->part_flag( part, VPFLAG_WASHING_MACHINE ) && cur_veh->has_part( "WASHING_MACHINE", true );
bool washing_machine_finished = false;

This comment has been minimized.

Copy link
@Coolthulhu

Coolthulhu Aug 18, 2017

Contributor

You don't use it outside the if, so it should be inside the if.

This comment has been minimized.

Copy link
@Night-Pryanik

Night-Pryanik Aug 18, 2017

Author Member

You mean outside of if( time_left <= 0 ) or if( finished )?

src/map.cpp Outdated
@@ -4672,6 +4672,28 @@ static void process_vehicle_items( vehicle *cur_veh, int part )
apply_in_fridge(n);
}
}

const bool washmachine_here = cur_veh->part_flag( part, VPFLAG_WASHING_MACHINE ) && cur_veh->has_part( "WASHING_MACHINE", true );

This comment has been minimized.

Copy link
@Coolthulhu

Coolthulhu Aug 18, 2017

Contributor

This check is not correct.
Consider more than one washing machine: in this case this check is true if any of the washing machines is turned on.

The check should be:

if( cur_veh->part_flag( part, VPFLAG_WASHING_MACHINE ) && cur_veh->is_part_on( part ) ) {

This comment has been minimized.

Copy link
@Night-Pryanik

Night-Pryanik Aug 19, 2017

Author Member

Fixed in fb0146f.

Night-Pryanik added some commits Aug 19, 2017

Reset bday for filthy items only if all checks are good.
Also, get and save veh->part_with_feature( veh_root_part, "WASHING_MACHINE" ) only once, then use it when needed.
bool detergent_is_enough = g->u.crafting_inventory().has_charges( "detergent", 5 );
static const std::string filthy( "FILTHY" );
bool filthy_items = std::any_of( veh->get_items( washing_machine_part ).begin(),
veh->get_items( washing_machine_part ).end(),

This comment has been minimized.

Copy link
@codemime

codemime Aug 19, 2017

Member

Though the function doesn't look expensive, it would be safer to stash the result of veh->get_items( washing_machine_part ) in a temp variable: const auto items = veh->get_items( washing_machine_part ).

This comment has been minimized.

Copy link
@Night-Pryanik

Night-Pryanik Aug 19, 2017

Author Member

Implemented in 6114c40, but had to made it without const, as items are changed below, where we set the bday.

Night-Pryanik added some commits Aug 19, 2017

Removed redundant check.
Also, corrected description.
} else {
veh->parts[washing_machine_part].enabled = true;
for( auto &n : items ) {
if( filthy_items ) {

This comment has been minimized.

Copy link
@AMurkin

AMurkin Aug 19, 2017

Contributor

This condition is redundant.

This comment has been minimized.

Copy link
@Night-Pryanik

Night-Pryanik Aug 19, 2017

Author Member

Fixed in 1163892.

add_msg( m_bad, _( "You need 5 charges of detergent for the washing machine." ) );
} else if( !filthy_items ) {
add_msg( m_bad,
_( "There are only non-filthy items in the washing machine. There is no need to wash them." ) );

This comment has been minimized.

Copy link
@AMurkin

AMurkin Aug 19, 2017

Contributor

Now that message is incorrect.

This comment has been minimized.

Copy link
@Night-Pryanik

Night-Pryanik Aug 19, 2017

Author Member

Fixed in 1163892.

@Night-Pryanik Night-Pryanik changed the title Vehicle mounted washing machine [RDY] Vehicle mounted washing machine Oct 18, 2017

@cainiaowu

This comment has been minimized.

Copy link
Contributor

commented Nov 1, 2017

Jenkins, rebuild.

Changes due to the implementation of time_duration
Changed duration of washing process to 2 hours, as I don't know how to better describe 90 minutes (or 1,5 hours) in new terms.
src/map.cpp Outdated
@@ -4677,15 +4677,15 @@ static void process_vehicle_items( vehicle *cur_veh, int part )
bool washing_machine_finished = false;
if( washmachine_here ) {
for( auto &n : cur_veh->get_items( part ) ) {
const int washing_time = MINUTES( 90 );
const int time_left = washing_time - n.age();
const time_duration washing_time = 2_hours;

This comment has been minimized.

Copy link
@codemime

codemime Dec 22, 2017

Member

2_hours isn't equivalent to MINUTES( 90 ). Is that intentional?

This comment has been minimized.

Copy link
@Night-Pryanik

Night-Pryanik Dec 22, 2017

Author Member

I don't know how to convert 90 minutes into a new form.

This comment has been minimized.

Copy link
@ZhilkinSerg

ZhilkinSerg Dec 22, 2017

Contributor

don't know how to translate 90 minutes in to new for.

90_minutes and most probably 1.5_hours will also work

This comment has been minimized.

Copy link
@AMurkin

AMurkin Dec 22, 2017

Contributor

90_minutes is ok. _hours take int so 1.5_hours is not ok.

@Night-Pryanik

This comment has been minimized.

Copy link
Member Author

commented Jan 8, 2018

I'm sorry for possibly being annoying, but is there something critical that blocks this from merging?

@ZhilkinSerg

This comment has been minimized.

Copy link
Contributor

commented Jan 8, 2018

I'm sorry for possibly being annoying, but is there something critical that blocks this from merging?

Possibly lack of time for contributors with merge rights.

Night-Pryanik added some commits Jan 24, 2018

@@ -83,9 +83,13 @@ interact_results interact_with_vehicle( vehicle *veh, const tripoint &pos,
const bool can_be_folded = veh->is_foldable();
const bool is_convertible = ( veh->tags.count( "convertible" ) > 0 );
const bool remotely_controlled = g->remoteveh() == veh;
const int washing_machine_part = veh->part_with_feature( veh_root_part, "WASHING_MACHINE" );
const bool has_washmachine = washing_machine_part >= 0;
bool washing_machine_on = veh->parts[washing_machine_part].enabled;

This comment has been minimized.

Copy link
@kevingranade

kevingranade Jan 25, 2018

Member

Segfault on this line, you cannot dereference an array with the -1 returned by veh->part_with_feature( veh_root_part, "WASHING_MACHINE" ); if there is no washing machine in the vehicle.
This would work:

bool washing_machine_on = ( washing_machine_part == -1 ) ? false :  veh->parts[washing_machine_part].enabled;

This comment has been minimized.

Copy link
@kevingranade

kevingranade Jan 25, 2018

Member

I fixed this during the merge, looks like it works flawlessly otherwise 👍

This comment has been minimized.

Copy link
@Night-Pryanik

Night-Pryanik Jan 25, 2018

Author Member

Thanks!
Though I'd like to know at which moment does it segfault?

@kevingranade kevingranade merged commit 8cc9d3f into CleverRaven:master Jan 25, 2018

3 checks passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
coverage/coveralls Coverage increased (+0.8%) to 22.783%
Details
gorgon-ghprb Build finished.
Details

@Night-Pryanik Night-Pryanik deleted the Night-Pryanik:vehicle-mounted-washing-machine branch Jan 25, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.