five-on-it / packages/sim/src/boat
packages/sim/src/boat
Boats (GAME_DESIGN §6.1): a class with a BoatDef floats instead of rolling. It is the same vehicle entity as a car (its body, its empty wheel controller, its seats, its health, its fire), and the vehicle system hands it here each tick instead of to its wheels (vehicle.ts):
- Buoyancy. Six points on the hull's bottom, two at the bow, two amidships, two at the stern, are each a spring and a damper on how deep they lie under the surface of the water at them (
water.ts), stiff enough that the six hold the boat's weight at its draught (BoatDef.draught): about one bounce a second, under-damped, so a boat rocks when it is shoved and settles within a couple of seconds; pitch and roll come of it. The water's surface is flat in the simulation: the client draws the swell (a client's world does not run on the server's tick, so a wave in the physics would set the prediction of a driven boat against the server's at every snapshot). - Drag. In the hull's frame, by how much of the hull is in the water: light along it, a share of the speed and of its square; strong across it, the keel's, so a boat goes where it points; the yaw is damped the same way.
- Thrust from the propeller at the stern, only while it is under water (a beached boat cannot drive itself off), with the cars' taper to the top speed and the boost; a rowed boat's comes in strokes. Backing the throttle off past zero is the brake: the propeller reverses.
- Rudder. The yaw follows the steering by the speed through the water and the propeller's wash over the rudder, so a boat turns from rest under power and none without it; it leans into a turn (BoatDef
.lean), and a planing hull lifts its bow and sheds drag above its planing speed. - Beached. A hull out of the water rests on the ground and slides on it as any body does.
- Moored. A boat nobody drives holds where it came to rest (
VehicleState.parked, the cars' parking brake: anchored atparkX,parkZ), so it never drifts off its spawner's bay; a shove harder than its mooring moves it, and it is moored again where it stops. - Flooding. A wrecked boat floods,
VehicleState.floodgoing from 0 to 1 over BOAT.floodSeconds, its buoyancy failing with it, and sinks; once it is flooded the water's sinking (sinking.ts) takes it to the bottom and puts its people out to swim.
Deterministic: a pure function of the body's state, the level's water and the flood, all hashed; the rowing's stroke runs on its own phase (the boost meter, which a rowed boat has no use for), carried by the snapshots.