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 upToggle engines #9755
Conversation
malhawee
added some commits
Oct 31, 2014
This comment has been minimized.
This comment has been minimized.
|
Much less buggy than that hybrid PR I had going before. |
This comment has been minimized.
This comment has been minimized.
|
What radiators? Didn't think we had any. Alternators maybe? |
This comment has been minimized.
This comment has been minimized.
|
Whoops, you're right, alternators |
malhawee
added some commits
Oct 31, 2014
malhawee
force-pushed the
malhawee:ToggleEngines
branch
to
523dc97
Oct 31, 2014
This comment has been minimized.
This comment has been minimized.
|
Alternators work now! Calling it feature complete. |
malhawee
changed the title
Toggle engines (WIP)
Toggle engines
Oct 31, 2014
This comment has been minimized.
This comment has been minimized.
|
I'm hesitant to grab this right now given that we're assembling a stable release, but once that's done, I'm confident that it will be VERY popular. Update: I mentioned it on the IRC. May get in after all. |
KA101
reviewed
Oct 31, 2014
| } | ||
|
|
||
| void vehicle::toggle_specific_engine(int p,bool on){ | ||
| parts[engines[p]].enabled = on; |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
malhawee
Oct 31, 2014
Author
Contributor
Yep, that function gets the user to select an engine index in the engines vector. Its called from control_engines, which handles disabling the engines. It calls toggle_specific engine to turn the engine on/off.
This comment has been minimized.
This comment has been minimized.
KA101
Oct 31, 2014
Contributor
Well, that's the thing--I'm not seeing an "off" here. Someplace else I should be looking?
This comment has been minimized.
This comment has been minimized.
|
Heh, I figured people would want it in the next release, I certainly do. |
This comment has been minimized.
This comment has been minimized.
|
Oh yes, this feature was sorely missing. True hybrid cars FTW. |
malhawee
reviewed
Oct 31, 2014
| if (e_toggle >= 0 && e_toggle < (int)engines.size() && | ||
| (active_count > 1 || !is_engine_on(e_toggle))){ | ||
| active_count += (!is_engine_on(e_toggle))?1:-1; | ||
| toggle_specific_engine(e_toggle, !is_engine_on(e_toggle)); |
This comment has been minimized.
This comment has been minimized.
malhawee
Oct 31, 2014
Author
Contributor
This line (441) toggles engines on or off. It first fetches the state of the engine, and inverts it.
This comment has been minimized.
This comment has been minimized.
kevingranade
reviewed
Nov 1, 2014
| parts[engines[p]].enabled = on; | ||
| } | ||
|
|
||
| bool vehicle::is_engine_on(int p){ |
This comment has been minimized.
This comment has been minimized.
kevingranade
Nov 1, 2014
Member
How about pulling the damage and fuel checks into this too? That would clean up a lot of code I think.
kevingranade
reviewed
Nov 1, 2014
| return parts[engines[p]].enabled; | ||
| } | ||
|
|
||
| bool vehicle::is_part_on(int p){ |
This comment has been minimized.
This comment has been minimized.
kevingranade
Nov 1, 2014
Member
Especially if you do the above, you probably want one method that expects a part index that does the real work, and another method that expects the engine index and just passes the part index to the other one.
kevingranade
reviewed
Nov 1, 2014
| } | ||
|
|
||
| bool vehicle::is_active_engine_at(int x,int y){ | ||
| for( size_t p = 0; p < engines.size(); ++p ) { |
This comment has been minimized.
This comment has been minimized.
kevingranade
Nov 1, 2014
Member
Probably redefine this one in terms of calling the is_part_on() method too, nice to have it only check things in one place.
kevingranade
reviewed
Nov 1, 2014
| @@ -474,6 +549,7 @@ void vehicle::use_controls() | |||
| has_reactor = true; | |||
| } | |||
| else if (part_flag(p, "ENGINE")) { | |||
| has_mult_engine = has_engine; | |||
This comment has been minimized.
This comment has been minimized.
kevingranade
reviewed
Nov 1, 2014
| switch(options_choice[select]) { | ||
| //brackets prevent initialisation errors |
This comment has been minimized.
This comment has been minimized.
kevingranade
reviewed
Nov 1, 2014
| @@ -10,6 +10,7 @@ | |||
| #include <map> | |||
| #include <string> | |||
| #include <iosfwd> | |||
| #include "ui.h" | |||
This comment has been minimized.
This comment has been minimized.
kevingranade
Nov 1, 2014
Member
Why add this here? If it's only referenced in vehicle.cpp, #include it there.
malhawee
added some commits
Nov 2, 2014
This comment has been minimized.
This comment has been minimized.
|
Looks like I've made all the code cleaner than it was before. My testing seems to show that its still working as expected. |
BevapDin
reviewed
Nov 2, 2014
| active_count += (!is_engine_on(e_toggle))?1:-1; | ||
| toggle_specific_engine(e_toggle, !is_engine_on(e_toggle)); | ||
|
|
||
| add_msg("Switched %s %s",part_info(engines[e_toggle]).name.c_str(), |
This comment has been minimized.
This comment has been minimized.
BevapDin
reviewed
Nov 2, 2014
| // control an engine | ||
| if (has_mult_engine) { | ||
| options_choice.push_back(cont_engines); | ||
| options_message.push_back(uimenu_entry("Control individual engines", 'y')); |
malhawee commentedOct 31, 2014
Adds ability to toggle individual engines in vehicle control menu, when more than one engine present. Choice brings up submenu listing all engines. Velocities, noise and fuel usage update accordingly.
If velocity after toggling is higher than the new safe velocity, the cruise control speed is lowered.
TODO: make radiators only work if the engine they are attached to is enabled