console/cmd: move /tp to libtrx

This commit is contained in:
Marcin Kurczewski 2024-09-23 00:17:22 +02:00
parent da5c040ded
commit 6bbabcb343
No known key found for this signature in database
GPG Key ID: CC65E6FD28CAE42A
11 changed files with 23 additions and 275 deletions

View File

@ -616,7 +616,7 @@ typedef struct __unaligned {
uint8_t buffer[6272];
} SAVEGAME_INFO;
typedef struct __unaligned {
typedef struct __unaligned { // decompiled
uint16_t idx;
int16_t box;
uint8_t pit_room;
@ -883,7 +883,7 @@ typedef struct { // decompiled
int16_t link_frame_num;
} ANIM_RANGE;
typedef struct __unaligned {
typedef struct __unaligned { // decompiled
int16_t room;
int16_t x;
int16_t y;
@ -891,12 +891,12 @@ typedef struct __unaligned {
XYZ_16 vertex[4];
} DOOR_INFO;
typedef struct __unaligned {
typedef struct __unaligned { // decompiled
int16_t count;
DOOR_INFO door[];
} DOOR_INFOS;
typedef struct __unaligned {
typedef struct __unaligned { // decompiled
int32_t x;
int32_t y;
int32_t z;
@ -906,7 +906,7 @@ typedef struct __unaligned {
int32_t falloff2;
} LIGHT_INFO;
typedef struct __unaligned {
typedef struct __unaligned { // decompiled
int32_t x;
int32_t y;
int32_t z;
@ -929,7 +929,7 @@ typedef struct __unaligned {
int16_t block;
} DOORPOS_DATA;
typedef struct __unaligned {
typedef struct __unaligned { // decompiled
int16_t *data;
DOOR_INFOS *doors;
SECTOR_INFO *sector;
@ -1645,7 +1645,7 @@ typedef enum { // decompiled
IF_KILLED = 0x8000,
} ITEM_FLAG;
typedef enum {
typedef enum { // decompiled
IS_INACTIVE = 0,
IS_ACTIVE = 1,
IS_DEACTIVATED = 2,

View File

@ -96,7 +96,6 @@ dll_sources = [
'src/game/console/cmd/play_demo.c',
'src/game/console/cmd/play_level.c',
'src/game/console/cmd/save_game.c',
'src/game/console/cmd/teleport.c',
'src/game/console/common.c',
'src/game/console/setup.c',
'src/game/creature.c',

View File

@ -1,168 +0,0 @@
#include "game/console/cmd/teleport.h"
#include "game/game_string.h"
#include "game/gameflow/gameflow_new.h"
#include "game/items.h"
#include "game/lara/cheat.h"
#include "game/objects/names.h"
#include "game/objects/vars.h"
#include "game/random.h"
#include "global/const.h"
#include "global/vars.h"
#include <libtrx/game/objects/common.h>
#include <libtrx/strings.h>
#include <math.h>
#include <stdio.h>
static bool M_CanTargetObject(GAME_OBJECT_ID object_id);
static bool M_IsFloatRound(float num);
static COMMAND_RESULT M_Entrypoint(const COMMAND_CONTEXT *ctx);
static bool M_CanTargetObject(const GAME_OBJECT_ID object_id)
{
return !Object_IsObjectType(object_id, g_NullObjects)
&& !Object_IsObjectType(object_id, g_AnimObjects)
&& !Object_IsObjectType(object_id, g_InvObjects);
}
static inline bool M_IsFloatRound(const float num)
{
return (fabsf(num) - roundf(num)) < 0.0001f;
}
static COMMAND_RESULT M_Entrypoint(const COMMAND_CONTEXT *const ctx)
{
if (g_GameInfo.current_level.type == GFL_TITLE
|| g_GameInfo.current_level.type == GFL_DEMO
|| g_GameInfo.current_level.type == GFL_CUTSCENE) {
return CR_UNAVAILABLE;
}
if (!g_Objects[O_LARA].loaded || !g_LaraItem->hit_points) {
return CR_UNAVAILABLE;
}
// X Y Z
{
float x, y, z;
if (sscanf(ctx->args, "%f %f %f", &x, &y, &z) == 3) {
if (M_IsFloatRound(x)) {
x += 0.5f;
}
if (M_IsFloatRound(z)) {
z += 0.5f;
}
if (Lara_Cheat_Teleport(x * WALL_L, y * WALL_L, z * WALL_L)) {
Console_Log(GS(OSD_POS_SET_POS), x, y, z);
return CR_SUCCESS;
}
Console_Log(GS(OSD_POS_SET_POS_FAIL), x, y, z);
return CR_FAILURE;
}
}
// Room number
{
int16_t room_num = NO_ROOM_NEG;
if (sscanf(ctx->args, "%hd", &room_num) == 1) {
if (room_num < 0 || room_num >= g_RoomCount) {
Console_Log(GS(OSD_INVALID_ROOM), room_num, g_RoomCount - 1);
return CR_FAILURE;
}
const ROOM_INFO *const room = &g_Rooms[room_num];
const int32_t x1 = room->pos.x + WALL_L;
const int32_t x2 =
(room->x_size << WALL_SHIFT) + room->pos.x - WALL_L;
const int32_t y1 = room->min_floor;
const int32_t y2 = room->max_ceiling;
const int32_t z1 = room->pos.z + WALL_L;
const int32_t z2 =
(room->z_size << WALL_SHIFT) + room->pos.z - WALL_L;
for (int32_t i = 0; i < 100; i++) {
int32_t x = x1 + Random_GetControl() * (x2 - x1) / 0x7FFF;
int32_t y = y1;
int32_t z = z1 + Random_GetControl() * (z2 - z1) / 0x7FFF;
if (Lara_Cheat_Teleport(x, y, z)) {
Console_Log(GS(OSD_POS_SET_ROOM), room_num);
return CR_SUCCESS;
}
}
Console_Log(GS(OSD_POS_SET_ROOM_FAIL), room_num);
return CR_FAILURE;
}
}
// Nearest item of this name
if (!String_Equivalent(ctx->args, "")) {
int32_t match_count = 0;
GAME_OBJECT_ID *matching_objs =
Object_IdsFromName(ctx->args, &match_count, M_CanTargetObject);
const ITEM_INFO *best_item = NULL;
int32_t best_distance = INT32_MAX;
for (int16_t item_num = 0; item_num < Item_GetTotalCount();
item_num++) {
const ITEM_INFO *const item = &g_Items[item_num];
if (Object_IsObjectType(item->object_id, g_PickupObjects)
&& (item->status == IS_INVISIBLE
|| item->status == IS_DEACTIVATED
|| item->room_num == NO_ROOM)) {
continue;
}
if (item->flags & IF_KILLED) {
continue;
}
bool is_matched = false;
for (int32_t i = 0; i < match_count; i++) {
if (matching_objs[i] == item->object_id) {
is_matched = true;
break;
}
}
if (!is_matched) {
continue;
}
const int32_t distance = Item_GetDistance(item, &g_LaraItem->pos);
if (distance < best_distance) {
best_distance = distance;
best_item = item;
}
}
if (best_item != NULL) {
if (Lara_Cheat_Teleport(
best_item->pos.x, best_item->pos.y - STEP_L,
best_item->pos.z)) {
Console_Log(
GS(OSD_POS_SET_ITEM), Object_GetName(best_item->object_id));
} else {
Console_Log(
GS(OSD_POS_SET_ITEM_FAIL),
Object_GetName(best_item->object_id));
}
return CR_SUCCESS;
} else {
Console_Log(GS(OSD_POS_SET_ITEM_FAIL), ctx->args);
return CR_FAILURE;
}
}
return CR_BAD_INVOCATION;
}
CONSOLE_COMMAND g_Console_Cmd_Teleport = {
.prefix = "tp",
.proc = M_Entrypoint,
};

View File

@ -1,5 +0,0 @@
#pragma once
#include <libtrx/game/console/common.h>
extern CONSOLE_COMMAND g_Console_Cmd_Teleport;

View File

@ -5,7 +5,6 @@
#include "game/console/cmd/play_demo.h"
#include "game/console/cmd/play_level.h"
#include "game/console/cmd/save_game.h"
#include "game/console/cmd/teleport.h"
#include <libtrx/game/console/cmd/config.h>
#include <libtrx/game/console/cmd/die.h>
@ -19,6 +18,7 @@
#include <libtrx/game/console/cmd/pos.h>
#include <libtrx/game/console/cmd/set_health.h>
#include <libtrx/game/console/cmd/sfx.h>
#include <libtrx/game/console/cmd/teleport.h>
#include <stddef.h>

View File

@ -1,11 +1,5 @@
GS_DEFINE(OSD_FLY_MODE_ON, "Fly mode enabled")
GS_DEFINE(OSD_FLY_MODE_OFF, "Fly mode disabled")
GS_DEFINE(OSD_POS_SET_POS, "Teleported to position: %.3f %.3f %.3f")
GS_DEFINE(OSD_POS_SET_POS_FAIL, "Failed to teleport to position: %.3f %.3f %.3f")
GS_DEFINE(OSD_POS_SET_ROOM, "Teleported to room: %d")
GS_DEFINE(OSD_POS_SET_ROOM_FAIL, "Failed to teleport to room: %d")
GS_DEFINE(OSD_POS_SET_ITEM, "Teleported to object: %s")
GS_DEFINE(OSD_POS_SET_ITEM_FAIL, "Failed to teleport to object: %s")
GS_DEFINE(OSD_GIVE_ITEM_ALL_KEYS, "Surprise! Every key item Lara needs is now in her backpack.")
GS_DEFINE(OSD_GIVE_ITEM_ALL_GUNS, "Lock'n'load - Lara's armed to the teeth!")
GS_DEFINE(OSD_GIVE_ITEM_CHEAT, "Lara's backpack just got way heavier!")
@ -15,12 +9,8 @@ GS_DEFINE(OSD_FLIPMAP_FAIL_ALREADY_ON, "Flipmap is already ON")
GS_DEFINE(OSD_FLIPMAP_FAIL_ALREADY_OFF, "Flipmap is already OFF")
GS_DEFINE(OSD_COMPLETE_LEVEL, "Level complete!")
GS_DEFINE(OSD_PLAY_LEVEL, "Loading %s")
GS_DEFINE(OSD_INVALID_ROOM, "Invalid room: %d. Valid rooms are 0-%d")
GS_DEFINE(OSD_INVALID_LEVEL, "Invalid level")
GS_DEFINE(OSD_INVALID_SAVE_SLOT, "Invalid save slot %d")
GS_DEFINE(OSD_UNKNOWN_COMMAND, "Unknown command: %s")
GS_DEFINE(OSD_COMMAND_BAD_INVOCATION, "Invalid invocation: %s")
GS_DEFINE(OSD_COMMAND_UNAVAILABLE, "This command is not currently available")
GS_DEFINE(OSD_DOOR_OPEN, "Open Sesame!")
GS_DEFINE(OSD_DOOR_CLOSE, "Close Sesame!")
GS_DEFINE(OSD_DOOR_OPEN_FAIL, "No doors in Lara's proximity")
@ -28,5 +18,3 @@ GS_DEFINE(OSD_LOAD_GAME, "Loaded game from save slot %d")
GS_DEFINE(OSD_LOAD_GAME_FAIL_UNAVAILABLE_SLOT, "Save slot %d is not available")
GS_DEFINE(OSD_SAVE_GAME, "Saved game to save slot %d")
GS_DEFINE(OSD_SAVE_GAME_FAIL, "Cannot save the game in the current state")
GS_DEFINE(OSD_CURRENT_HEALTH_GET, "Current Lara's health: %d")
GS_DEFINE(OSD_CURRENT_HEALTH_SET, "Lara's health set to %d")

View File

@ -956,3 +956,13 @@ void __cdecl Room_TriggerMusicTrack(
}
}
}
int32_t Room_GetTotalCount(void)
{
return g_RoomCount;
}
ROOM_INFO *Room_Get(const int32_t room_num)
{
return &g_Rooms[room_num];
}

View File

@ -2,6 +2,8 @@
#include "global/types.h"
#include <libtrx/game/rooms/types.h>
#include <stdint.h>
int16_t Room_GetIndexFromPos(int32_t x, int32_t y, int32_t z);

View File

@ -11,6 +11,7 @@
#include <libtrx/game/lot.h>
#include <libtrx/game/math.h>
#include <libtrx/game/objects/common.h>
#include <libtrx/game/rooms/types.h>
#include <ddraw.h>
#include <ddrawi.h>
@ -524,15 +525,6 @@ typedef struct __unaligned {
uint8_t buffer[6272];
} SAVEGAME_INFO;
typedef struct __unaligned {
uint16_t idx;
int16_t box;
uint8_t pit_room;
int8_t floor;
uint8_t sky_room;
int8_t ceiling;
} SECTOR_INFO;
typedef struct __unaligned {
int16_t lock_angles[4];
int16_t left_angles[4];
@ -719,39 +711,6 @@ typedef struct __unaligned {
int32_t mesh_num;
} BITE_INFO;
typedef struct __unaligned {
int16_t room;
int16_t x;
int16_t y;
int16_t z;
XYZ_16 vertex[4];
} DOOR_INFO;
typedef struct __unaligned {
int16_t count;
DOOR_INFO door[];
} DOOR_INFOS;
typedef struct __unaligned {
int32_t x;
int32_t y;
int32_t z;
int16_t intensity1;
int16_t intensity2;
int32_t falloff1;
int32_t falloff2;
} LIGHT_INFO;
typedef struct __unaligned {
int32_t x;
int32_t y;
int32_t z;
int16_t y_rot;
int16_t shade1;
int16_t shade2;
int16_t static_num;
} MESH_INFO;
typedef enum {
RF_UNDERWATER = 0x01,
RF_OUTSIDE = 0x08,
@ -765,37 +724,6 @@ typedef struct __unaligned {
int16_t block;
} DOORPOS_DATA;
typedef struct __unaligned {
int16_t *data;
DOOR_INFOS *doors;
SECTOR_INFO *sector;
LIGHT_INFO *light;
MESH_INFO *mesh;
XYZ_32 pos;
int32_t min_floor;
int32_t max_ceiling;
int16_t z_size;
int16_t x_size;
int16_t ambient1;
int16_t ambient2;
int16_t light_mode;
int16_t num_lights;
int16_t num_meshes;
int16_t bound_left;
int16_t bound_right;
int16_t bound_top;
int16_t bound_bottom;
uint16_t bound_active;
int16_t test_left;
int16_t test_right;
int16_t test_top;
int16_t test_bottom;
int16_t item_num;
int16_t fx_num;
int16_t flipped_room;
uint16_t flags;
} ROOM_INFO;
typedef enum {
CAM_CHASE = 0,
CAM_FIXED = 1,
@ -1341,13 +1269,6 @@ typedef struct __unaligned {
int16_t roll;
} CINE_FRAME;
typedef enum {
IS_INACTIVE = 0,
IS_ACTIVE = 1,
IS_DEACTIVATED = 2,
IS_INVISIBLE = 3,
} ITEM_STATUS;
typedef struct __unaligned {
uint16_t key[14]; // INPUT_ROLE_NUMBER_OF
} CONTROL_LAYOUT;

@ -1 +1 @@
Subproject commit 28fd44933585a8ceae19bf999159e84260d0e0d1
Subproject commit 433c815b497d84c0922584b31a41e75e0d0ad9f2

View File

@ -120,6 +120,7 @@ def make_types_h(types: list[str]) -> None:
"#include <libtrx/game/lot.h>",
"#include <libtrx/game/math.h>",
"#include <libtrx/game/objects/common.h>",
"#include <libtrx/game/rooms/types.h>",
"",
"#include <ddraw.h>",
"#include <ddrawi.h>",