- lay tyre tracks only if wheels on ground

- new SurfaceType enum
This commit is contained in:
InspirationByte 2022-01-25 21:17:14 +03:00
parent 2a9fd24865
commit 973729f117
5 changed files with 47 additions and 36 deletions

View File

@ -11,9 +11,9 @@
#include "main.h"
#include "ASM/d2mapasm.h"
sdPlane default_plane = { 0, 0, 0, 0, 2048 };
sdPlane default_plane = { SURF_CONCRETE, 0, 0, 0, 2048 };
sdPlane sea_plane = { 9, 0, 16384, 0, 2048 }; // a default surface if FindSurfaceD2 fails
sdPlane sea_plane = { SURF_DEEPWATER, 0, 16384, 0, 2048 }; // a default surface if FindSurfaceD2 fails
sdPlane* GetSeaPlane()
{

View File

@ -1511,7 +1511,7 @@ void CheckCarEffects(CAR_DATA* cp, int player_id)
for (cnt = 0; cnt < 4; cnt++)
{
if (cp->hd.wheel[cnt].susCompression != 0)
wheels_on_ground = 1;
wheels_on_ground |= 1 << cnt;
}
skidsound = 0;
@ -1523,7 +1523,7 @@ void CheckCarEffects(CAR_DATA* cp, int player_id)
rear_vel = ABS(cp->hd.rear_vel);
front_vel = ABS(cp->hd.front_vel);
if (rear_vel > 15000 || cp->wheelspin)
if ((wheels_on_ground & 5) && (rear_vel > 15000 || cp->wheelspin))
{
lay_down_tracks |= 1;
@ -1536,7 +1536,7 @@ void CheckCarEffects(CAR_DATA* cp, int player_id)
skidsound = 13000;
}
if (front_vel > 15000)
if ((wheels_on_ground & 10) && front_vel > 15000)
{
lay_down_tracks |= 2;
}
@ -1667,18 +1667,21 @@ void CheckCarEffects(CAR_DATA* cp, int player_id)
// make tyre tracks
GetTyreTrackPositions(cp, player_id);
#define ADD_WHEEL_TYRE_TRACK(wheelNum, trackIdx) \
if (wheels_on_ground & (1 << wheelNum)) { \
AddTyreTrack(trackIdx, tracks_and_smoke, player_id, last_track_state[player_id][trackIdx] != -1); \
last_track_state[player_id][trackIdx] = 1; \
} else \
last_track_state[player_id][trackIdx] = -1;
if (lay_down_tracks & 1) // rear
{
#if MAX_TYRE_TRACK_WHEELS == 4
AddTyreTrack(0, tracks_and_smoke, player_id, last_track_state[player_id][0] != -1);
AddTyreTrack(2, tracks_and_smoke, player_id, last_track_state[player_id][2] != -1);
last_track_state[player_id][0] = 1;
last_track_state[player_id][2] = 1;
ADD_WHEEL_TYRE_TRACK(0, 0)
ADD_WHEEL_TYRE_TRACK(2, 2)
#else
AddTyreTrack(0, tracks_and_smoke, player_id, last_track_state[player_id][0] != -1);
AddTyreTrack(1, tracks_and_smoke, player_id, last_track_state[player_id][1] != -1);
last_track_state[player_id][0] = 1;
last_track_state[player_id][1] = 1;
ADD_WHEEL_TYRE_TRACK(0, 0)
ADD_WHEEL_TYRE_TRACK(2, 1)
#endif
}
else
@ -1695,10 +1698,8 @@ void CheckCarEffects(CAR_DATA* cp, int player_id)
#if MAX_TYRE_TRACK_WHEELS == 4
if (lay_down_tracks & 2) // front
{
AddTyreTrack(1, tracks_and_smoke, player_id, last_track_state[player_id][1] != -1);
AddTyreTrack(3, tracks_and_smoke, player_id, last_track_state[player_id][3] != -1);
last_track_state[player_id][1] = 1;
last_track_state[player_id][3] = 1;
ADD_WHEEL_TYRE_TRACK(1, 1)
ADD_WHEEL_TYRE_TRACK(3, 3)
}
else
{
@ -1707,6 +1708,8 @@ void CheckCarEffects(CAR_DATA* cp, int player_id)
}
#endif
#undef ADD_WHEEL_TYRE_TRACK
SetTyreTrackOldPositions(player_id);
}

View File

@ -137,10 +137,10 @@ void AddTyreTrack(int wheel, int tracksAndSmoke, int player_id, int continuous_t
// check surface type
if (SurfaceDataPtr != NULL)
{
if (SurfaceDataPtr->surface == 6)
if (SurfaceDataPtr->surface == SURF_WATER)
return;
if (SurfaceDataPtr->surface == 4)
if (SurfaceDataPtr->surface == SURF_GRASS)
{
tt_p->surface = 2;
player[player_id].onGrass = 1;
@ -162,10 +162,10 @@ void AddTyreTrack(int wheel, int tracksAndSmoke, int player_id, int continuous_t
SurfaceDataPtr = sdGetCell(newtp);
trackSurface = 1;
if (SurfaceDataPtr->surface == 6)
if (SurfaceDataPtr->surface == SURF_WATER)
return;
if (SurfaceDataPtr->surface == 4)
if (SurfaceDataPtr->surface == SURF_GRASS)
trackSurface = 2;
}

View File

@ -253,7 +253,7 @@ void AddWheelForcesDriver1(CAR_DATA* cp, CAR_LOCALS* cl)
friction_coef = (newCompression * (32400 - wetness) >> 15) + 500;
if (SurfacePtr != NULL)
wheel->onGrass = SurfacePtr->surface == 4;
wheel->onGrass = SurfacePtr->surface == SURF_GRASS;
else
wheel->onGrass = 0;
@ -261,10 +261,10 @@ void AddWheelForcesDriver1(CAR_DATA* cp, CAR_LOCALS* cl)
{
switch (SurfacePtr->surface)
{
case 4:
case 6:
case 9:
case 11:
case SURF_GRASS:
case SURF_WATER:
case SURF_DEEPWATER:
case SURF_SAND:
wheel->surface = 0x80;
break;
default:
@ -277,14 +277,14 @@ void AddWheelForcesDriver1(CAR_DATA* cp, CAR_LOCALS* cl)
switch (SurfacePtr->surface)
{
case 8:
case SURF_ALLEY:
wheel->surface |= 0x2;
break;
case 6:
case 9:
case SURF_WATER:
case SURF_DEEPWATER:
wheel->surface |= 0x1;
break;
case 11:
case SURF_SAND:
wheel->surface |= 0x3;
break;
}
@ -697,7 +697,7 @@ void StepOneCar(CAR_DATA* cp)
Setup_Debris((VECTOR*)&deepestPoint, &direction, 10, 0);
}
if (SurfacePtr && (SurfacePtr->surface != 9) && (SurfacePtr->surface != 6))
if (SurfacePtr && (SurfacePtr->surface != SURF_DEEPWATER) && (SurfacePtr->surface != SURF_WATER))
{
CollisionSound(GetPlayerId(cp), cp, (impulse / 6 + (impulse >> 0x1f) >> 3) - (impulse >> 0x1f), 0);
}

View File

@ -152,12 +152,20 @@ struct DRIVER2_JUNCTION
u_int flags;
};
enum SurfaceType
{
SURF_CONCRETE = 0, // concrete/paved tiles
SURF_GRASS = 4,
SURF_WATER = 6,
SURF_ALLEY = 8,
SURF_DEEPWATER = 9,
SURF_SAND = 11,
};
typedef struct _sdPlane
{
short surface;
short a;
short b;
short c;
short surface; // also one of SurfaceTypes
short a, b, c;
int d;
} sdPlane;