Skip to content

Commit

Permalink
Merge pull request #65 from Trxyebeep/wip
Browse files Browse the repository at this point in the history
Wip
  • Loading branch information
Trxyebeep authored Apr 12, 2023
2 parents fc2d897 + f629745 commit 11cc64b
Show file tree
Hide file tree
Showing 6 changed files with 192 additions and 33 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

- Fix the random fires on screen bug.
- Fix Ahmet/Scale save crashes in Temple of Horus.
- Fix Lara snapping when moving off a ledge while wading.
- Fix floordata issues with triangular geometry, no collision tiles, and more generic situations.

### tomb4 bug fixes

Expand All @@ -19,6 +21,7 @@

### new tomb4 features

- Improve how the hair interacts with water.

## [2.1.0](https://github.com/Trxyebeep/TOMB4/tree/V2.1.0) (Mar. 3 2023)

Expand Down
181 changes: 172 additions & 9 deletions TOMB4/game/control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1263,20 +1263,20 @@ FLOOR_INFO* GetFloor(long x, long y, long z, short* room_number)

} while (door != 255);

if (y < floor->floor << 8)
if (y < GetMaximumFloor(floor, x, z))
{
if (y < floor->ceiling << 8 && floor->sky_room != 255)
if (y < GetMinimumCeiling(floor, x, z) && floor->sky_room != 255)
{
do
{
if (CheckNoColCeilingTriangle(floor, x, z) == 1 || CheckNoColCeilingTriangle(floor, x, z) == -1 && y >= r->maxceiling)
if (CheckNoColCeilingTriangle(floor, x, z) == 1)
break;

*room_number = floor->sky_room;
r = &room[floor->sky_room];
floor = &r->floor[((z - r->z) >> 10) + r->x_size * ((x - r->x) >> 10)];

if (y >= floor->ceiling << 8)
if (y >= GetMinimumCeiling(floor, x, z))
break;

} while (floor->sky_room != 255);
Expand All @@ -1286,14 +1286,14 @@ FLOOR_INFO* GetFloor(long x, long y, long z, short* room_number)
{
while (1)
{
if (CheckNoColFloorTriangle(floor, x, z) == 1 || CheckNoColFloorTriangle(floor, x, z) == -1 && y < r->minfloor)
if (CheckNoColFloorTriangle(floor, x, z) == 1)
break;

*room_number = floor->pit_room;
r = &room[floor->pit_room];
floor = &r->floor[((z - r->z) >> 10) + r->x_size * ((x - r->x) >> 10)];

if (y < floor->floor << 8)
if (y < GetMaximumFloor(floor, x, z))
break;

if (floor->pit_room == 255)
Expand Down Expand Up @@ -1362,12 +1362,12 @@ long GetWaterHeight(long x, long y, long z, short room_number)
r = &room[floor->sky_room];

if (!(r->flags & ROOM_UNDERWATER))
return r->minfloor;
break;

floor = &r->floor[((z - r->z) >> 10) + r->x_size * ((x - r->x) >> 10)];
}

return r->maxceiling;
return GetMinimumCeiling(floor, x, z);
}
else
{
Expand All @@ -1379,7 +1379,7 @@ long GetWaterHeight(long x, long y, long z, short room_number)
r = &room[floor->pit_room];

if (r->flags & ROOM_UNDERWATER)
return r->maxceiling;
return GetMaximumFloor(floor, x, z);

floor = &r->floor[((z - r->z) >> 10) + r->x_size * ((x - r->x) >> 10)];
}
Expand Down Expand Up @@ -3166,3 +3166,166 @@ long DoRayBox(GAME_VECTOR* start, GAME_VECTOR* target, short* bounds, PHD_3DPOS*

return 0;
}

long GetMaximumFloor(FLOOR_INFO* floor, long x, long z)
{
long height, h1, h2;
short* data, type, dx, dz, t0, t1, t2, t3, hadj;

height = floor->floor << 8;

if (height != NO_HEIGHT && floor->index)
{
data = &floor_data[floor->index];
type = *data++;
h1 = 0;
h2 = 0;

if ((type & 0x1F) != TILT_TYPE)
{
if ((type & 0x1F) == SPLIT1 || (type & 0x1F) == SPLIT2 || (type & 0x1F) == NOCOLF1T || (type & 0x1F) == NOCOLF1B || (type & 0x1F) == NOCOLF2T || (type & 0x1F) == NOCOLF2B)
{
dx = x & 0x3FF;
dz = z & 0x3FF;
t0 = *data & 0xF;
t1 = *data >> 4 & 0xF;
t2 = *data >> 8 & 0xF;
t3 = *data >> 12 & 0xF;

if ((type & 0x1F) == SPLIT1 || (type & 0x1F) == NOCOLF1T || (type & 0x1F) == NOCOLF1B)
{
if (dx <= 1024 - dz)
{
hadj = type >> 10 & 0x1F;
h1 = t2 - t1;
h2 = t0 - t1;
}
else
{
hadj = type >> 5 & 0x1F;
h1 = t3 - t0;
h2 = t3 - t2;
}
}
else
{
if (dx <= dz)
{
hadj = type >> 10 & 0x1F;
h1 = t2 - t1;
h2 = t3 - t2;
}
else
{
hadj = type >> 5 & 0x1F;
h1 = t3 - t0;
h2 = t0 - t1;
}
}

if (hadj & 0x10)
hadj |= 0xFFF0;

height += hadj << 8;
}
}
else
{
h1 = *data >> 8;
h2 = *(char*)data;
}

height += 256 * (abs(h1) + abs(h2));
}

return height;
}

long GetMinimumCeiling(FLOOR_INFO* floor, long x, long z)
{
long height, h1, h2;
short* data, type, dx, dz, t0, t1, t2, t3, hadj, ended;

height = floor->ceiling << 8;

if (height != NO_HEIGHT && floor->index)
{
data = &floor_data[floor->index];
type = *data++;
ended = 0;

if ((type & 0x1F) == TILT_TYPE || (type & 0x1F) == SPLIT1 || (type & 0x1F) == SPLIT2 || (type & 0x1F) == NOCOLF1T || (type & 0x1F) == NOCOLF1B || (type & 0x1F) == NOCOLF2T || (type & 0x1F) == NOCOLF2B)
{
data++;

if (type & 0x8000)
ended = 1;

type = *data++;
}

if (!ended)
{
h1 = 0;
h2 = 0;

if ((type & 0x1F) != ROOF_TYPE)
{
if ((type & 0x1F) == SPLIT3 || (type & 0x1F) == SPLIT4 || (type & 0x1F) == NOCOLC1T || (type & 0x1F) == NOCOLC1B || (type & 0x1F) == NOCOLC2T || (type & 0x1F) == NOCOLC2B)
{
dx = x & 0x3FF;
dz = z & 0x3FF;
t0 = -(*data & 0xF);
t1 = -(*data >> 4 & 0xF);
t2 = -(*data >> 8 & 0xF);
t3 = -(*data >> 12 & 0xF);

if ((type & 0x1F) == SPLIT3 || (type & 0x1F) == NOCOLC1T || (type & 0x1F) == NOCOLC1B)
{
if (dx <= 1024 - dz)
{
hadj = type >> 10 & 0x1F;
h1 = t2 - t1;
h2 = t3 - t2;
}
else
{
hadj = type >> 5 & 0x1F;
h1 = t3 - t0;
h2 = t0 - t1;
}
}
else
{
if (dx <= dz)
{
hadj = type >> 10 & 0x1F;
h1 = t2 - t1;
h2 = t0 - t1;
}
else
{
hadj = type >> 5 & 0x1F;
h1 = t3 - t0;
h2 = t3 - t2;
}
}

if (hadj & 0x10)
hadj |= 0xFFF0;

height += hadj << 8;
}
}
else
{
h1 = *data >> 8;
h2 = *(char*)data;
}

height -= 256 * (abs(h1) + abs(h2));
}
}

return height;
}
2 changes: 2 additions & 0 deletions TOMB4/game/control.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ long GetTargetOnLOS(GAME_VECTOR* src, GAME_VECTOR* dest, long DrawTarget, long f
void AnimateItem(ITEM_INFO* item);
long RayBoxIntersect(PHD_VECTOR* min, PHD_VECTOR* max, PHD_VECTOR* mid, PHD_VECTOR* dir, PHD_VECTOR* Coord);
long DoRayBox(GAME_VECTOR* start, GAME_VECTOR* target, short* bounds, PHD_3DPOS* ItemPos, PHD_VECTOR* Coord, short item_number);
long GetMaximumFloor(FLOOR_INFO* floor, long x, long z);
long GetMinimumCeiling(FLOOR_INFO* floor, long x, long z);

extern ITEM_INFO* items;
extern ANIM_STRUCT* anims;
Expand Down
27 changes: 7 additions & 20 deletions TOMB4/game/hair.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -389,35 +389,22 @@ void HairControl(long in_cutscene, long pigtail, short* cutscenething)
hair->pos.z_pos += SmokeWindZ;
}

switch (lara.water_status)
if (water == NO_HEIGHT || hair->pos.y_pos < water)
{
case LW_ABOVE_WATER:
case LW_WADE: //here instead of the other case to fix stiff hair during wade
hair->pos.y_pos += 10;

if (water != NO_HEIGHT && hair->pos.y_pos > water)
hair->pos.y_pos = water;
else if (hair->pos.y_pos > height)
{
hair->pos.x_pos = pos.x;

if (hair->pos.y_pos - height <= 256) //snap to floor if it goes below, no more than 1 click to avoid hairection when going through corners
hair->pos.y_pos = height;

hair->pos.z_pos = pos.z;
}

break;
}

case LW_UNDERWATER:
case LW_SURFACE:
if (hair->pos.y_pos > height)
{
hair->pos.x_pos = pos.x;

if (hair->pos.y_pos < water)
hair->pos.y_pos = water;
else if (hair->pos.y_pos > height)
if (hair->pos.y_pos - height <= 256) //snap to floor if it goes below, no more than 1 click to avoid hairection when going through corners
hair->pos.y_pos = height;

break;
hair->pos.z_pos = pos.z;
}

for (int j = 0; j < 6; j++) //6 instead of 5 for new sphere
Expand Down
8 changes: 6 additions & 2 deletions TOMB4/game/lara.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2126,7 +2126,9 @@ void lara_col_back(ITEM_INFO* item, COLL_INFO* coll)
if (TestLaraSlide(item, coll))
return;

if (coll->mid_floor != NO_HEIGHT)
if (lara.water_status == LW_WADE && coll->mid_floor >= 50)
item->pos.y_pos += 50;
else if (coll->mid_floor != NO_HEIGHT)
item->pos.y_pos += coll->mid_floor;
}

Expand Down Expand Up @@ -2220,7 +2222,9 @@ void lara_col_stepright(ITEM_INFO* item, COLL_INFO* coll)
if (TestLaraSlide(item, coll))
return;

if (coll->mid_floor != NO_HEIGHT)
if (lara.water_status == LW_WADE && coll->mid_floor >= 50)
item->pos.y_pos += 50;
else if (coll->mid_floor != NO_HEIGHT)
item->pos.y_pos += coll->mid_floor;
}

Expand Down
4 changes: 2 additions & 2 deletions TOMB4/game/laraswim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ long GetWaterDepth(long x, long y, long z, short room_number)

if (!(r->flags & ROOM_UNDERWATER))
{
h = floor->ceiling << 8;
h = GetMinimumCeiling(floor, x, z);
floor = GetFloor(x, y, z, &room_number);
return GetHeight(floor, x, y, z) - h;
}
Expand All @@ -368,7 +368,7 @@ long GetWaterDepth(long x, long y, long z, short room_number)

if (r->flags & ROOM_UNDERWATER)
{
h = floor->floor << 8;
h = GetMaximumFloor(floor, x, z);
floor = GetFloor(x, y, z, &room_number);
return GetHeight(floor, x, y, z) - h;
}
Expand Down

0 comments on commit 11cc64b

Please sign in to comment.