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

Move /fly, /abortion and many type definitions to libtrx #1534

Merged
merged 7 commits into from
Sep 22, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
## [Unreleased](https://github.com/LostArtefacts/TR1X/compare/stable...develop) - ××××-××-××
- fixed double "Fly mode enabled" message when using `/fly` console command (regression from 4.0)

## [4.4](https://github.com/LostArtefacts/TR1X/compare/4.3-102-g458cd96...4.4) - 2024-09-20
- added `/exit` command (#1462)
Expand Down
20 changes: 9 additions & 11 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,10 @@ sources = [
'src/game/collide.c',
'src/game/console/cmd/braid.c',
'src/game/console/cmd/cheats.c',
'src/game/console/cmd/die.c',
'src/game/console/cmd/end_level.c',
'src/game/console/cmd/exit_game.c',
'src/game/console/cmd/exit_to_title.c',
'src/game/console/cmd/flipmap.c',
'src/game/console/cmd/fly.c',
'src/game/console/cmd/fps.c',
'src/game/console/cmd/load_game.c',
'src/game/console/cmd/play_demo.c',
Expand Down Expand Up @@ -160,16 +158,15 @@ sources = [
'src/game/inventory/inventory_ring.c',
'src/game/inventory/inventory_vars.c',
'src/game/items.c',
'src/game/lara/lara.c',
'src/game/lara/lara_cheat.c',
'src/game/lara/lara_col.c',
'src/game/lara/lara_control.c',
'src/game/lara/lara_draw.c',
'src/game/lara/lara_hair.c',
'src/game/lara/lara_look.c',
'src/game/lara/lara_misc.c',
'src/game/lara/lara_state.c',
'src/game/lara/cheat.c',
'src/game/lara/col.c',
'src/game/lara/common.c',
'src/game/lara/control.c',
'src/game/lara/draw.c',
'src/game/lara/hair.c',
'src/game/lara/look.c',
'src/game/lara/misc.c',
'src/game/lara/state.c',
'src/game/level.c',
'src/game/los.c',
'src/game/lot.c',
Expand Down Expand Up @@ -255,6 +252,7 @@ sources = [
'src/game/objects/traps/teeth_trap.c',
'src/game/objects/traps/thors_hammer_handle.c',
'src/game/objects/traps/thors_hammer_head.c',
'src/game/objects/vars.c',
'src/game/option/option.c',
'src/game/option/option_compass.c',
'src/game/option/option_control.c',
Expand Down
102 changes: 51 additions & 51 deletions src/game/box.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,25 @@

#include <libtrx/utils.h>

bool Box_SearchLOT(LOT_INFO *LOT, int32_t expansion)
bool Box_SearchLOT(LOT_INFO *lot, int32_t expansion)
{
int16_t *zone;
if (LOT->fly) {
if (lot->fly) {
zone = g_FlyZone[g_FlipStatus];
} else if (LOT->step == STEP_L) {
} else if (lot->step == STEP_L) {
zone = g_GroundZone[g_FlipStatus];
} else {
zone = g_GroundZone2[g_FlipStatus];
}

int16_t search_zone = zone[LOT->head];
int16_t search_zone = zone[lot->head];
for (int i = 0; i < expansion; i++) {
if (LOT->head == NO_BOX) {
if (lot->head == NO_BOX) {
return false;
}

BOX_NODE *node = &LOT->node[LOT->head];
BOX_INFO *box = &g_Boxes[LOT->head];
BOX_NODE *node = &lot->node[lot->head];
BOX_INFO *box = &g_Boxes[lot->head];

int done = 0;
int index = box->overlap_index & OVERLAP_INDEX;
Expand All @@ -41,11 +41,11 @@ bool Box_SearchLOT(LOT_INFO *LOT, int32_t expansion)
}

int change = g_Boxes[box_num].height - box->height;
if (change > LOT->step || change < LOT->drop) {
if (change > lot->step || change < lot->drop) {
continue;
}

BOX_NODE *expand = &LOT->node[box_num];
BOX_NODE *expand = &lot->node[box_num];
if ((node->search_num & SEARCH_NUMBER)
< (expand->search_num & SEARCH_NUMBER)) {
continue;
Expand All @@ -64,66 +64,66 @@ bool Box_SearchLOT(LOT_INFO *LOT, int32_t expansion)
continue;
}

if (g_Boxes[box_num].overlap_index & LOT->block_mask) {
if (g_Boxes[box_num].overlap_index & lot->block_mask) {
expand->search_num = node->search_num | BLOCKED_SEARCH;
} else {
expand->search_num = node->search_num;
expand->exit_box = LOT->head;
expand->exit_box = lot->head;
}
}

if (expand->next_expansion == NO_BOX && box_num != LOT->tail) {
LOT->node[LOT->tail].next_expansion = box_num;
LOT->tail = box_num;
if (expand->next_expansion == NO_BOX && box_num != lot->tail) {
lot->node[lot->tail].next_expansion = box_num;
lot->tail = box_num;
}
} while (!done);

LOT->head = node->next_expansion;
lot->head = node->next_expansion;
node->next_expansion = NO_BOX;
}

return true;
}

bool Box_UpdateLOT(LOT_INFO *LOT, int32_t expansion)
bool Box_UpdateLOT(LOT_INFO *lot, int32_t expansion)
{
if (LOT->required_box != NO_BOX && LOT->required_box != LOT->target_box) {
LOT->target_box = LOT->required_box;
if (lot->required_box != NO_BOX && lot->required_box != lot->target_box) {
lot->target_box = lot->required_box;

BOX_NODE *expand = &LOT->node[LOT->target_box];
if (expand->next_expansion == NO_BOX && LOT->tail != LOT->target_box) {
expand->next_expansion = LOT->head;
BOX_NODE *expand = &lot->node[lot->target_box];
if (expand->next_expansion == NO_BOX && lot->tail != lot->target_box) {
expand->next_expansion = lot->head;

if (LOT->head == NO_BOX) {
LOT->tail = LOT->target_box;
if (lot->head == NO_BOX) {
lot->tail = lot->target_box;
}

LOT->head = LOT->target_box;
lot->head = lot->target_box;
}

expand->search_num = ++LOT->search_num;
expand->search_num = ++lot->search_num;
expand->exit_box = NO_BOX;
}

return Box_SearchLOT(LOT, expansion);
return Box_SearchLOT(lot, expansion);
}

void Box_TargetBox(LOT_INFO *LOT, int16_t box_num)
void Box_TargetBox(LOT_INFO *lot, int16_t box_num)
{
box_num &= BOX_NUMBER;

BOX_INFO *box = &g_Boxes[box_num];

LOT->target.z = box->left + WALL_L / 2
lot->target.z = box->left + WALL_L / 2
+ (Random_GetControl() * (box->right - box->left - WALL_L) >> 15);
LOT->target.x = box->top + WALL_L / 2
lot->target.x = box->top + WALL_L / 2
+ (Random_GetControl() * (box->bottom - box->top - WALL_L) >> 15);
LOT->required_box = box_num;
lot->required_box = box_num;

if (LOT->fly) {
LOT->target.y = box->height - STEP_L * 3 / 2;
if (lot->fly) {
lot->target.y = box->height - STEP_L * 3 / 2;
} else {
LOT->target.y = box->height;
lot->target.y = box->height;
}
}

Expand Down Expand Up @@ -180,9 +180,9 @@ bool Box_ValidBox(ITEM_INFO *item, int16_t zone_num, int16_t box_num)
CREATURE_INFO *creature = item->data;

int16_t *zone;
if (creature->LOT.fly) {
if (creature->lot.fly) {
zone = g_FlyZone[g_FlipStatus];
} else if (creature->LOT.step == STEP_L) {
} else if (creature->lot.step == STEP_L) {
zone = g_GroundZone[g_FlipStatus];
} else {
zone = g_GroundZone2[g_FlipStatus];
Expand All @@ -193,7 +193,7 @@ bool Box_ValidBox(ITEM_INFO *item, int16_t zone_num, int16_t box_num)
}

BOX_INFO *box = &g_Boxes[box_num];
if (box->overlap_index & creature->LOT.block_mask) {
if (box->overlap_index & creature->lot.block_mask) {
return false;
}

Expand All @@ -205,14 +205,14 @@ bool Box_ValidBox(ITEM_INFO *item, int16_t zone_num, int16_t box_num)
return true;
}

TARGET_TYPE Box_CalculateTarget(XYZ_32 *target, ITEM_INFO *item, LOT_INFO *LOT)
TARGET_TYPE Box_CalculateTarget(XYZ_32 *target, ITEM_INFO *item, LOT_INFO *lot)
{
int32_t left = 0;
int32_t right = 0;
int32_t top = 0;
int32_t bottom = 0;

Box_UpdateLOT(LOT, MAX_EXPANSION);
Box_UpdateLOT(lot, MAX_EXPANSION);

target->x = item->pos.x;
target->y = item->pos.y;
Expand All @@ -228,7 +228,7 @@ TARGET_TYPE Box_CalculateTarget(XYZ_32 *target, ITEM_INFO *item, LOT_INFO *LOT)
do {
box = &g_Boxes[box_num];

if (LOT->fly) {
if (lot->fly) {
if (target->y > box->height - WALL_L) {
target->y = box->height - WALL_L;
}
Expand Down Expand Up @@ -358,9 +358,9 @@ TARGET_TYPE Box_CalculateTarget(XYZ_32 *target, ITEM_INFO *item, LOT_INFO *LOT)
}
}

if (box_num == LOT->target_box) {
if (box_num == lot->target_box) {
if (prime_free & (CLIP_LEFT | CLIP_RIGHT)) {
target->z = LOT->target.z;
target->z = lot->target.z;
} else if (!(prime_free & SECONDARY_CLIP)) {
if (target->z < box->left + BIFF) {
target->z = box->left + BIFF;
Expand All @@ -370,7 +370,7 @@ TARGET_TYPE Box_CalculateTarget(XYZ_32 *target, ITEM_INFO *item, LOT_INFO *LOT)
}

if (prime_free & (CLIP_TOP | CLIP_BOTTOM)) {
target->x = LOT->target.x;
target->x = lot->target.x;
} else if (!(prime_free & SECONDARY_CLIP)) {
if (target->x < box->top + BIFF) {
target->x = box->top + BIFF;
Expand All @@ -379,13 +379,13 @@ TARGET_TYPE Box_CalculateTarget(XYZ_32 *target, ITEM_INFO *item, LOT_INFO *LOT)
}
}

target->y = LOT->target.y;
target->y = lot->target.y;
return TARGET_PRIMARY;
}

box_num = LOT->node[box_num].exit_box;
box_num = lot->node[box_num].exit_box;
if (box_num != NO_BOX
&& (g_Boxes[box_num].overlap_index & LOT->block_mask)) {
&& (g_Boxes[box_num].overlap_index & lot->block_mask)) {
break;
}
} while (box_num != NO_BOX);
Expand All @@ -412,7 +412,7 @@ TARGET_TYPE Box_CalculateTarget(XYZ_32 *target, ITEM_INFO *item, LOT_INFO *LOT)
}
}

if (!LOT->fly) {
if (!lot->fly) {
target->y = box->height;
} else {
target->y = box->height - STEP_L * 3 / 2;
Expand All @@ -423,27 +423,27 @@ TARGET_TYPE Box_CalculateTarget(XYZ_32 *target, ITEM_INFO *item, LOT_INFO *LOT)

bool Box_BadFloor(
int32_t x, int32_t y, int32_t z, int16_t box_height, int16_t next_height,
int16_t room_num, LOT_INFO *LOT)
int16_t room_num, LOT_INFO *lot)
{
const SECTOR_INFO *const sector = Room_GetSector(x, y, z, &room_num);
if (sector->box == NO_BOX) {
return true;
}

if (g_Boxes[sector->box].overlap_index & LOT->block_mask) {
if (g_Boxes[sector->box].overlap_index & lot->block_mask) {
return true;
}

const int32_t height = g_Boxes[sector->box].height;
if (box_height - height > LOT->step || box_height - height < LOT->drop) {
if (box_height - height > lot->step || box_height - height < lot->drop) {
return true;
}

if (box_height - height < -LOT->step && height > next_height) {
if (box_height - height < -lot->step && height > next_height) {
return true;
}

if (LOT->fly && y > height + LOT->fly) {
if (lot->fly && y > height + lot->fly) {
return true;
}

Expand Down
10 changes: 5 additions & 5 deletions src/game/box.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
#include <stdbool.h>
#include <stdint.h>

bool Box_SearchLOT(LOT_INFO *LOT, int32_t expansion);
bool Box_UpdateLOT(LOT_INFO *LOT, int32_t expansion);
void Box_TargetBox(LOT_INFO *LOT, int16_t box_num);
bool Box_SearchLOT(LOT_INFO *lot, int32_t expansion);
bool Box_UpdateLOT(LOT_INFO *lot, int32_t expansion);
void Box_TargetBox(LOT_INFO *lot, int16_t box_num);
bool Box_StalkBox(ITEM_INFO *item, int16_t box_num);
bool Box_EscapeBox(ITEM_INFO *item, int16_t box_num);
bool Box_ValidBox(ITEM_INFO *item, int16_t zone_num, int16_t box_num);
TARGET_TYPE Box_CalculateTarget(XYZ_32 *target, ITEM_INFO *item, LOT_INFO *LOT);
TARGET_TYPE Box_CalculateTarget(XYZ_32 *target, ITEM_INFO *item, LOT_INFO *lot);
bool Box_BadFloor(
int32_t x, int32_t y, int32_t z, int16_t box_height, int16_t next_height,
int16_t room_num, LOT_INFO *LOT);
int16_t room_num, LOT_INFO *lot);
5 changes: 3 additions & 2 deletions src/game/carrier.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "game/gameflow.h"
#include "game/inventory.h"
#include "game/items.h"
#include "game/objects/common.h"
#include "game/objects/vars.h"
#include "game/room.h"
#include "global/const.h"
#include "global/types.h"
Expand Down Expand Up @@ -151,7 +151,8 @@ void Carrier_TestItemDrops(int16_t item_num)
ITEM_INFO *carrier = &g_Items[item_num];
CARRIED_ITEM *item = carrier->carried_item;
if (carrier->hit_points > 0 || !item
|| (carrier->object_id == O_PIERRE && !(carrier->flags & IF_ONESHOT))) {
|| (carrier->object_id == O_PIERRE
&& !(carrier->flags & IF_ONE_SHOT))) {
return;
}

Expand Down
Loading