"int velocity": Keeps an updated velocity for the falling object. Every tick, floor and ceiling is lowered by this amount. Every tick, the velocity is increased.
"delay(90)": I put it there to get a little time before things happen.
"v =
GetSectorFloorZ(sec_3d_crate,0,0) - GetSectorFloorZ(sec_crate,0,0);"
sec_3d_crate floor z: the floor (lowest surface) of the crate
sec_crate floor z: the floor (lowest surface) of the sector containing the crate
"sec_3d_crate floor z" - "sec_crate floor z": distance from bottom of crate to the floor that will stop it. If v is 0, the crate has hit the floor. If v is less than 0, the crate has gone through the floor (the code tries to prevent that from happening).
"while (v > 0)..." as long as the crate is still above the floor
"velocity = velocity + grav_accel - FixedMul(linear_drag, velocity);" ... math. Increase velocity by a fixed amount (grav_accel). Reduce acceleration by a value that increases the faster you are falling. (When acceleration is 100% reduced, the crate falls at constant speed; terminal velocity) This is a rough mathematical approximation of stuff as it happens in the real world.
"if (v > 8 * velocity) v = (velocity + 0.5)>>16;"
"else v = (v >>16)/8;"
8: Several specials multiply height changes by 8, which means they go 8 times too fast. The grav_accel and linear_drag have been divided by 8 to correct for this.
"velocity" holds the distance to be traveled, in fixed point / map units. This distance will be multiplied by 8 in Floor_LowerInstant.
Movement towards the floor = 8 * velocity.
"v" holds the remaining distance to the floor. If movement towards the floor is more than remaining distance, the crate should instead move to the floor and stop there. (v is actual distance, but would be multiplied by 8 in Floor_LowerInstant. We must therefore divide it by 8 if we use it.)
Review that one again. We assign to v in this statement. After this statement, v holds the distance to be traveled (or actually, that distance divided by 8).
"if (v > 8 * velocity) v = (velocity + 0.5)>>16;"
--- IF remaining actual distance (v) IS GREATER THAN distance to be traveled (8 * velocity): v = (velocity + 0.5)>>16;
--- (velocity + 0.5)>>16: convert from fixed point to integer and round to nearest
-- ELSE (if remaining actual distance is less than the crate would travel at its current velocity): v = (v >>16)/8;
--- actual remaining distance, converted to int and divided by 8
-- Then there's a print for debugging purposes
-- And we lower floor and ceiling by v. v is determined by velocity or remaining distance to the ground, whichever is less.
-- Then we delay so that time gets to pass in the game.
-- Then "v = GetSectorFloorZ(sec_3d_crate,0,0) - GetSectorFloorZ(sec_crate,0,0);"
-- we calculate the distance from crate to ground again. If we are above the ground, we keep moving down, from the top of the loop.