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

[CR]Falling vehicles #13436

Merged
merged 12 commits into from Sep 8, 2015
Merged

[CR]Falling vehicles #13436

merged 12 commits into from Sep 8, 2015

Conversation

Coolthulhu
Copy link
Contributor

Most likely the hardest part of #6823

Vehicles are marked as "falling" when they drive over a ledge, terrain/furniture under them stops supporting their weight or vehicle moves from under them.

A falling vehicle is "active" in the same way one with of_turn > 0 is.
It will check all tiles underneath it. If all of them are open air and no tiles under those offer support, it will accelerate down and fall.

Falling vehicle will collide with things on its way. I disabled floor breaking for now; current collision calculations are too unbalanced at high mass*velocity, which would cause heavy vehicles to sink in solid rock like a red hot nickel ball in butter. Vehicle-vehicle collisions work OK, though.

Also fixed two minor bugs: colliding with a monster while driving in reverse would not fling it, but drive over it. Driving over a monster at low enough speed would damage it, but also have vehicle phase into it.

Includes some more or less minor changes to code:

  • Extracted "traction" code. Currently only checks for something for the wheel to sit on and move cost of the tile, but will help with turning it into something more proper.
  • Extracted "buoyancy" code. Would help with amphibious vehicles and realistic boats (ones that sink when their weight capacity is exceeded)
  • Simplified vehicle::collision's argument list. Most of those were return values that can be extracted in the processing of the most important one anyway.
  • Implemented vehicle::wheelcache, which existed for a while but wasn't used. Implemented a vehicle::floating - similar thing but for floating parts.
  • Split map::update_vehicle_cache into add_vehicle_to_cache and update_vehicle_cache. update_ takes a z-level argument. This argument is necessary to properly update vehicles moving from one z-level to another (otherwise the entire vehicle cache would have to be rebuilt).

@Coolthulhu Coolthulhu changed the title [WiP][CR]Falling vehicles [CR]Falling vehicles Aug 29, 2015
@Coolthulhu
Copy link
Contributor Author

Should be ready, I think. Not perfect, but I didn't see it breaking any existing functionality or acting too weird.

Most issues are with the way damage is spread: a falling vehicle will lose HP from random or arbitrary parts, losing seatbelts, clocks, roofs and seats before frames.
The other issue is with collision damage for vehicle vs. everything else. Accelerating to relativistic speed allows digging self into steel walls with relatively little harm to the vehicle itself. But that's an issue bigger than just falling vehicles or vehicle collisions.

@chaosvolt
Copy link
Contributor

This colud be useful. Now if only I could drag shopping carts up/down stairs... owo

if( moored > num - 1 ) {
// destroy vehicle (sank to nowhere)
destroy_vehicle( &veh );
// The returned pointer is always a dangling one!
Copy link
Contributor

Choose a reason for hiding this comment

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

Whoa, stop right there, what's that? You're returning an invalid non-null pointer on purpose? The caller has no way to distinguish it from a valid non-null pointer. And I see the returned pointer being used:

        const vehicle *veh = vehproceed();
        if( veh == nullptr ) {
            break;
        } else {
            on_vehicle_moved( veh->smz ); // Hello undefined behavior.
        }

@Coolthulhu
Copy link
Contributor Author

Changed vehproceed to return a bool and invoke on_vehicle_moved when it actually moves (or is destroyed due to sinking). This has a nice side effect of making it compatible with current lua implementation, so you can invoke vehproceed and watch vehicles move step-by-step.
The returned value is false if the value returned would be nullptr before, true otherwise.
This fixes the dangling pointer issue.

Fixed the "falling with no velocity" bug and possibly a separate bug with same cause (I didn't expect initialized tileray to have non-zero dx and dy even before first advance, so I assumed they'll be zeros).

Reworked collision sounds a bit. A vehicle will now produce a crashing sound on its own, not just by bashing terrain in front of it.
Prevented falling vehicle from bashing floors (just the floors/dirt/etc.) altogether. This bashing was mostly for sound, but produced 4k sounds per collision, which is obviously not OK.

@BevapDin BevapDin self-assigned this Sep 8, 2015
BevapDin added a commit that referenced this pull request Sep 8, 2015
@BevapDin BevapDin merged commit 2d80646 into CleverRaven:master Sep 8, 2015
@BevapDin
Copy link
Contributor

BevapDin commented Sep 8, 2015

When you drive a car across a ledge and all wheels end up in midair, but one (non-wheel) part of the vehicle is still over floor the game says "Your %s can't move on this terrain." and the vehicle stops immediately, but without any effects from the sudden deceleration. This is probably fine for now, as a proper behavior would require inclined vehicles with some of its parts on the lower level and some of them on the upper level.

Another slight inconsistency (but fine for now): vehicles (and furniture) support other vehicles on top of them, but they don't support creatures on top of them. For example: when pushing a welding cart across a ledge on top of another vehicles, it stays on the upper level (and can be pulled back). But if my character moves on the same spot in the air, it falls down into the (sometimes impassable) vehicle part below.

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.

None yet

4 participants