-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Add a flag that allows mods to create rotorlike aircraft #77663
Add a flag that allows mods to create rotorlike aircraft #77663
Conversation
something went clearly wrong with your astyle |
That's what I noticed. It appears that my current astyle isn't the right one, so I'll see if I can modify the astyle included included in my instance of visual studio and if I can't, then I'll have to revert and manually fix that push. Edit: found it. My version of astyle was too old. Now it's fixed |
I was under the impression that you'd be implementing some distinct form of flight, not just bypassing the checks added for helicopters. I'm not interested in maintaining hacks in game to implement these bypasses. |
I am implementing a distinct type of flying vehicles intended for mainlined mods. Non-rotor aicraft is anything that can fly but isn't using rotors to do so. Jury-rigged mad science aircraft? Yes. Sci-fi regular science aircraft? Yes. Any other thing that can fly? Yes. This is distinct enough from helicopters to require separate code but similar enough to not need to fully duplicate the code where adding to the check can do the same. Aircraft and rotorcraft share the same main function and goal: lifting a valid vehicle from the ground so there's some overlap unlike, say, the systems for ground vehicles and for water vehicles. By the way, I have been informed that the function of at least one of the helicopter checks is to forbid anything that isn't a flyworthy helicopter from flying and to forbid anything without a rotor from being considered a flying vehicle so any such checks need to be bypassed for non-rotor aircraft to be possible at all. Flat-out removing said checks isn't an option either, as according to @RenechCDDA all vehicles are flyable by default. They just can't attempt to fly if they don't have rotors, meaning that I need to add something that can be used to allow a vehicle to fly while keeping the code that keeps regular vehicles from flying. |
What is the distinct type of flying vehicle then, because it looks like you're just doing "make it work like a helicopter but bypass the rotor checks"? |
My goal is to add the required infrastructure to simulate any new vehicle type without every single new type needing their own code for that through a polyvalent flag. Aircraft is intended to allow anything to be made flyable in a way that can be adapted to any modded vehicle that would use it. Rotorcraft is rotorcraft, but aircraft can be anything the modder wishes to make and allows it to be done in a 100% Json way. In my case, I have plan involving XE's inventors and making aircraft. The need for aircraft has come up for Magiclysm and Aftershock too, as I read on the discord. The alternative is fully duplicating the entire flight code at least three times (jury-rigged sci-fi/regular sci-fi/magic) which ins't sustainable long-term. The aircraft system handle anything that can be described as "this single-tile part allows flight, losing that part loses the ability to fly this vehicle" without needing to mostly copy-paste the same code over and over. The main overlap with how helicopters work is that both allow a vehicle to fly if the conditions are met. |
The existing system is Not Fit For Purpose for representing arbitrary aircraft, that's why it has all these limitations. I'm not merging a PR that goes, "you can be anything you want as long as it flies kind of like a jank helicopter and now we're pretending that's ok". |
This is what I'm aiming for: to allow the things that allow abstraction and are little more than "it flies because it does", the kind of vehicle that would never, ever be part of non-modded CDDA but has its place in mainlined mods while requiring little more than being able to quit the ground. These are the vehicles this PR intend to allow. It's not a system for balloons, nor for fixed-wing aircrafts nor gyrocopters. It's a system for mod-makers wanting to add their own handwaved flying vehicle even if they're not based on anything that exists. If I'm allowed to continue work on this PR, I'll add a very clear note about how this flag is meant to never be used for anything not within a mod along with bunch of renaiming so it's clearly mod-only. I feel that it would address the valid point you're raising about the content of this PR being seen as nothing but a shortcut to add planes. dirigibles, etc to the main game without the proper systems of each. |
I guess what kevingranade is thinking of, is that most aircraft doesn't move the same way a ground vehicle or helicopter does, so you can't simply abstract things, you need to actually implement the per-aircraft-type behaviour.
And this is insufficient information - even if it's magic / handwavium, it still needs to be known how the vehicles moves (effect) even if cause of the movement is magic (especially if it's magic, because then it easily might behave differently from real-life things). E .g., can the aircraft be moved in all directions (UFOs?) or does it need to rotate first to point in the right direction, does it spin (some UFOs), are there extrusions that can be damaged by nearby trees (cata rotors), are there height limitations (hovercraft?), how does energy consumption scale with velocity, acceleration, air resistance, distance to ground, is acceleration instantaneous, does it perform many small teleports or does it have well-defined speeds? If some of the engines are broken or turned off, does it only reduce thrust (cars) or does it reduce in what directions rotation and thrust can be applied (some spacecraft designs, also bad for airplanes I think)? In any case, the C++ code needs to know these factors. Perhaps it could delegate it to JSON code, ...
... but that delegation hasn't actually been implemented by this PR. |
The PR is in the middle of being rewritten to better reflect its intent: allowing vehicles that have no real-world equivalent and only these, the vehicles that cannot be based on IRL flying vehicles, to be added to mods. The description is still the old one as I'm trying to get the compiled game to open again first before modyfing the PR in case the new description needs to be adjusted (said description already needs a heavy rewrite). What I had in mind when implementing the abstracted_aircraft vehicle class are the myriad of vehicles that are incredibly similar in function to rotorless helicopters: sci-fi ships, magic brooms, UFOs, magic carpets, steampunk jetpack chairs, etc, which all work with the following mechanics:
This is why they're all grouped up in the same system: despite the lack of real-world examples, there's a huge pile of fiction examples and they all behave the same way flightwise. The Json plans have also changed to limit scope creep. It turned out that allowing any non-rotor vehicle at all was a much bigger task than planned, so Jsonizing it will have to wait. The current goal is to get the system to work at all, as it currently doesn't. |
I would make |
Spell checker encountered unrecognized words in the in-game text added in this pull request. See below for details. Click to expand
This alert is automatically generated. You can simply disregard if this is inaccurate, or (optionally) you can also add the new words to Hints for adding a new word to the dictionary
|
I feel like this hasn't been asked, so I will ask: Why do you need an aircraft that behaves exactly like a helicopter but is not (internally) called a helicopter and copies 99% of the helicopter code? Why can't you just implement as a helicopter, without any new C++? |
So instead of adding OR checks, I make the rotorlike_aircraft class include the rotorcraft class for most purposes and add checks looking for rotors in the code lines where having rotors or not matter? I can see if I manage to do that. I have in mind placing a check to see if one of the two flags is present (for most behaviors), a check to determinate when regular rotors are used (so helicopters keep their function) and code to prevent both flags from being applied to the same vehicle (with an error if both are defined on the same part) |
Yes, that's it. Although, keep in mind I'm not familiar with cata's vehicle code.
It is actually asked: #77663 (comment) (and initially (emphasis on initially) without a proper answer). It's the 1% that's important:
This sounds like it doesn't have rotors, so the rotor collision checks don't make sense in this case (I haven't checked if they were removed for non-helicopters though). Also, from the very first comment:
These properties aren't like helicopters either. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm going to be blunt with you at this point: This seems to be above your current capabilities.
You clearly do not understand the code you are modifying, nor the concepts they represent (e.g. rotorcraft lift). I'm not saying that to denigrate you, or say that's not allowed. This is a very complicated part of the codebase and anything we add here only makes that worse.
You have to understand that your responsibility in adding code is not just to do the thing you want. It's also got to be maintainable. You have to make sensible assumptions, and others need to be able to follow your code... even if they're pretty ignorant of the what the code is actually doing/supposed to do.
So far, you have not left that impression on me. Even if you are able to address all the concerns I have raised, I'm not the only person you need to convince. I'm not even the most critical one!
Simply, I do not see any likely futures where you can get this PR into a shape that it would be merged.
My recommendation to you would be to shelve this project, and consider revisiting it when you have a better understanding of C++ and the codebase.
bool is_wiring = parts[split_part0].info().base_item == itype_wall_wiring; | ||
bool is_appliance = parts[ split_part0 ].info().has_flag( flag_APPLIANCE ); | ||
bool is_wiring = parts[ split_part0 ].info().base_item == itype_wall_wiring; | ||
bool is_rotorlike_aircraft = parts[ split_part0 ].info().has_flag( flag_ROTORLIKE_AIRCRAFT ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Appliances can use front() because they are always one single vehicle part. Therefore front() is always the one and only vehicle part in the parts array.
This is not true in your case.
@@ -1572,6 +1577,10 @@ int vehicle::install_part( const point_rel_ms &dp, vehicle_part &&vp ) | |||
debugmsg( "installing %s would make invalid vehicle: %s", vpi.id.str(), valid_mount.str() ); | |||
return -1; | |||
} | |||
if( vpi.has_flag( flag_ROTORLIKE_AIRCRAFT ) ) { | |||
// Installing a part that grants flyworthiness allows the vehicle to fly. | |||
set_flyable( true ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should just be overridden in vehicle::is_flyable()
// so ground speed is used here. | ||
int vehicle::max_rotorlike_velocity( const bool fueled ) const | ||
{ | ||
const double max_air_mps = std::sqrt( max_ground_velocity( fueled ) / coeff_air_drag() ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we checking our possible ground velocity? This is only called when we are is_flying
.
// so ground speed is used here. | ||
int vehicle::safe_rotorlike_velocity( const bool fueled ) const | ||
{ | ||
const double max_air_mps = std::sqrt( safe_ground_velocity( fueled ) / coeff_air_drag() ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto, why check the ground?
bool vehicle::is_rotorlike_aircraft() const | ||
{ | ||
// checks if the aircraft is a helicopter or works like one | ||
return ( ( !rotorlike_aircraft.empty() && has_driver() ) || ( !rotors.empty() && has_driver() && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clang error that would need to be resolved.
int vehicle::max_velocity( const bool fueled ) const | ||
{ | ||
if( is_flying && is_rotorcraft() ) { | ||
return max_rotor_velocity( fueled ); | ||
} else if( is_flying && !is_rotorcraft() ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
!is_rotorcraft()
doesn't make much sense here, it should be is_rotorlike_aircraft()
.
@@ -564,7 +565,9 @@ void vehicle::thrust( int thd, int z ) | |||
// helicopters improve efficiency the closer they get to 50-70 knots | |||
// then it drops off as they go over that. | |||
// see https://i.stack.imgur.com/0zIO7.jpg | |||
if( is_rotorcraft() && is_flying_in_air() ) { | |||
// rotorlike aircraft are intended to be mechanically similar to helicopters | |||
// so they get the same efficiency factor |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.......why?
Again, this is a rotor physics issue. If you aren't using rotors, you should not be dealing with their physics.
Just to further clarify: As the rotor goes faster the relative speed of the airflow over its lifting surface goes down, which makes it produce less lift. Hence the "pushing power" at 200mph is not equivalent to the very same "pushing power" at 500mph.
You do not have a rotor. This should not apply to you.
Summary
Features "Add a flag that allows mods to create rotorlike aircraft"
Purpose of change
I am planning to add a new vehicle part craftable by XE's inventors that would make a vehicle including said part flyable.
When designing how it would fly, it turned out that my intent for the behavior of that flight was incredibly similar to how helicopters fly.
Describe the solution
Add the ROTORLIKE_AIRCRAFT flag.
Installing a part with this flag allows the vehicle to fly in a similar way to helicopters.
By default, vehicles with this flag don't require any proficiency to fly but requirements can be defined in the vehicle parts.
They also can be repaired and modified with the only caveat of the removal of the fly-granting part removing the ability to fly until reinstalled.
Describe alternatives you've considered
Making this class a catch-all for all non-existing vehicles has been attempted. It was a horrendous idea.
Making a vehicle class that is obviously about a single vehicle part and nothing else was considered.
Testing
The game starts without throwing errors.
Regular helicopters still work as intended.
Vehicles with a part having this flag can fly.
Vehicles without rotors or this flag cannot attempt to lift.
Removed the part: Couldn't fly anymore.
Reinstalled the part: Could fly again.
Tried to fly the vehicle with a part having a defined proficiency without having said proficiency: couldn't fly it unless I had the proficiency.
Destroyed the part midflight: the aircraft crashed to the ground.
Destroyed one part midflight but not the other: the aircraft crashed to the ground even in case of a vehicle split.
Used autodrive: works without issue. It needed some more code for autodrive to handle a vehicle with both wheel and flight but it now uses the autodrive air speed as intended and only slows down when turning or completing its path.
Used autodrive while in a helicopter: worked without issue.
Used autodrive while in a car: worked without issue.
Additional context