Skip to content

Commit

Permalink
objects: rename object_id variables
Browse files Browse the repository at this point in the history
This standardizes the use of GAME_OBJECT_ID to obj_id.
  • Loading branch information
lahm86 committed Feb 3, 2025
1 parent 49a673a commit 9d3119f
Show file tree
Hide file tree
Showing 54 changed files with 280 additions and 287 deletions.
15 changes: 7 additions & 8 deletions src/libtrx/game/console/cmd/give_item.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,14 @@
#include <stdio.h>
#include <string.h>

static bool M_CanTargetObjectPickup(GAME_OBJECT_ID object_id);
static bool M_CanTargetObjectPickup(GAME_OBJECT_ID obj_id);
static COMMAND_RESULT M_Entrypoint(const COMMAND_CONTEXT *ctx);

static bool M_CanTargetObjectPickup(const GAME_OBJECT_ID object_id)
static bool M_CanTargetObjectPickup(const GAME_OBJECT_ID obj_id)
{
return Object_IsType(object_id, g_InvObjects)
&& Object_Get(object_id)->loaded
return Object_IsType(obj_id, g_InvObjects) && Object_Get(obj_id)->loaded
&& Object_IsType(
Object_GetCognateInverse(object_id, g_ItemToInvObjectMap),
Object_GetCognateInverse(obj_id, g_ItemToInvObjectMap),
g_PickupObjects);
}

Expand Down Expand Up @@ -62,12 +61,12 @@ static COMMAND_RESULT M_Entrypoint(const COMMAND_CONTEXT *const ctx)
GAME_OBJECT_ID *matching_objs =
Object_IdsFromName(args, &match_count, M_CanTargetObjectPickup);
for (int32_t i = 0; i < match_count; i++) {
const GAME_OBJECT_ID object_id = matching_objs[i];
const char *obj_name = Object_GetName(object_id);
const GAME_OBJECT_ID obj_id = matching_objs[i];
const char *obj_name = Object_GetName(obj_id);
if (obj_name == nullptr) {
obj_name = args;
}
Inv_AddItemNTimes(object_id, num);
Inv_AddItemNTimes(obj_id, num);
Console_Log(GS(OSD_GIVE_ITEM), obj_name);
found = true;
}
Expand Down
10 changes: 5 additions & 5 deletions src/libtrx/game/console/cmd/kill.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@
#include "memory.h"
#include "strings.h"

static bool M_CanTargetObjectCreature(GAME_OBJECT_ID object_id);
static bool M_CanTargetObjectCreature(GAME_OBJECT_ID obj_id);
static bool M_KillSingleEnemyInRange(int32_t max_dist);
static int32_t M_KillAllEnemiesInRange(int32_t max_dist);
static COMMAND_RESULT M_KillAllEnemies(void);
static COMMAND_RESULT M_KillNearestEnemies(void);
static COMMAND_RESULT M_KillEnemyType(const char *enemy_name);
static COMMAND_RESULT M_Entrypoint(const COMMAND_CONTEXT *ctx);

static bool M_CanTargetObjectCreature(const GAME_OBJECT_ID object_id)
static bool M_CanTargetObjectCreature(const GAME_OBJECT_ID obj_id)
{
return (Object_IsType(object_id, g_EnemyObjects)
|| Object_IsType(object_id, g_AllyObjects))
&& Object_Get(object_id)->loaded;
return (Object_IsType(obj_id, g_EnemyObjects)
|| Object_IsType(obj_id, g_AllyObjects))
&& Object_Get(obj_id)->loaded;
}

static bool M_KillSingleEnemyInRange(const int32_t max_dist)
Expand Down
18 changes: 9 additions & 9 deletions src/libtrx/game/console/cmd/teleport.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

static int16_t m_LastTeleportedItemNum = NO_ITEM;

static bool M_CanTargetObject(GAME_OBJECT_ID object_id);
static bool M_CanTargetObject(GAME_OBJECT_ID obj_id);
static bool M_CanTargetItem(
const ITEM *item, const GAME_OBJECT_ID *matching_objs, int32_t match_count);
static const ITEM *M_GetItemToTeleporTo(const char *user_input);
Expand All @@ -31,26 +31,26 @@ static COMMAND_RESULT M_TeleportToObject(const char *user_input);

static COMMAND_RESULT M_Entrypoint(const COMMAND_CONTEXT *ctx);

static bool M_ObjectCanBePickedUp(const GAME_OBJECT_ID object_id)
static bool M_ObjectCanBePickedUp(const GAME_OBJECT_ID obj_id)
{
if (!Object_IsType(object_id, g_PickupObjects)) {
if (!Object_IsType(obj_id, g_PickupObjects)) {
return true;
}
for (int32_t item_num = 0; item_num < Item_GetTotalCount(); item_num++) {
const ITEM *const item = Item_Get(item_num);
if (item->object_id == object_id && item->status != IS_INVISIBLE) {
if (item->object_id == obj_id && item->status != IS_INVISIBLE) {
return true;
}
}
return false;
}

static bool M_CanTargetObject(const GAME_OBJECT_ID object_id)
static bool M_CanTargetObject(const GAME_OBJECT_ID obj_id)
{
return !Object_IsType(object_id, g_NullObjects)
&& !Object_IsType(object_id, g_AnimObjects)
&& !Object_IsType(object_id, g_InvObjects)
&& Object_Get(object_id)->loaded && M_ObjectCanBePickedUp(object_id);
return !Object_IsType(obj_id, g_NullObjects)
&& !Object_IsType(obj_id, g_AnimObjects)
&& !Object_IsType(obj_id, g_InvObjects) && Object_Get(obj_id)->loaded
&& M_ObjectCanBePickedUp(obj_id);
}

static bool M_CanTargetItem(
Expand Down
6 changes: 3 additions & 3 deletions src/libtrx/game/game_flow/reader.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,15 +126,15 @@ static DECLARE_SEQUENCE_EVENT_HANDLER_FUNC(M_HandleTotalStatsEvent)

static DECLARE_SEQUENCE_EVENT_HANDLER_FUNC(M_HandleAddItemEvent)
{
const GAME_OBJECT_ID object_id =
const GAME_OBJECT_ID obj_id =
M_GetObjectFromJSONValue(JSON_ObjectGetValue(event_obj, "object_id"));
if (object_id == NO_OBJECT) {
if (obj_id == NO_OBJECT) {
Shell_ExitSystem("Invalid item");
return -1;
}
if (event != nullptr) {
GF_ADD_ITEM_DATA *const event_data = extra_data;
event_data->object_id = object_id;
event_data->object_id = obj_id;
event_data->quantity = JSON_ObjectGetInt(event_obj, "quantity", 1);
#if TR_VERSION == 2
event_data->inv_type =
Expand Down
4 changes: 2 additions & 2 deletions src/libtrx/game/game_flow/sequencer_misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ GF_COMMAND GF_ShowInventory(const INVENTORY_MODE mode)
GF_COMMAND GF_ShowInventoryKeys(const GAME_OBJECT_ID receptacle_type_id)
{
if (g_Config.gameplay.enable_auto_item_selection) {
const GAME_OBJECT_ID object_id = Object_GetCognateInverse(
const GAME_OBJECT_ID obj_id = Object_GetCognateInverse(
receptacle_type_id, g_KeyItemToReceptacleMap);
InvRing_SetRequestedObjectID(object_id);
InvRing_SetRequestedObjectID(obj_id);
}
return GF_ShowInventory(INV_KEYS_MODE);
}
Expand Down
8 changes: 4 additions & 4 deletions src/libtrx/game/game_string_table/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,17 @@ static void M_Apply(const GS_TABLE *const table)
{
const GS_OBJECT_ENTRY *cur = table->objects;
while (cur != nullptr && cur->key != nullptr) {
const GAME_OBJECT_ID object_id = Object_IdFromKey(cur->key);
if (object_id == NO_OBJECT) {
const GAME_OBJECT_ID obj_id = Object_IdFromKey(cur->key);
if (obj_id == NO_OBJECT) {
LOG_ERROR("Invalid object id: %s", cur->key);
} else {
if (cur->name == nullptr) {
LOG_ERROR("Invalid object name: %s", cur->key);
} else {
Object_SetName(object_id, cur->name);
Object_SetName(obj_id, cur->name);
}
if (cur->description != nullptr) {
Object_SetDescription(object_id, cur->description);
Object_SetDescription(obj_id, cur->description);
}
}
cur++;
Expand Down
24 changes: 12 additions & 12 deletions src/libtrx/game/inventory.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@
#include "game/inventory_ring/vars.h"
#include "game/objects/vars.h"

bool Inv_AddItemNTimes(const GAME_OBJECT_ID object_id, const int32_t qty)
bool Inv_AddItemNTimes(const GAME_OBJECT_ID obj_id, const int32_t qty)
{
bool result = false;
for (int32_t i = 0; i < qty; i++) {
result |= Inv_AddItem(object_id);
result |= Inv_AddItem(obj_id);
}
return result;
}

GAME_OBJECT_ID Inv_GetItemOption(const GAME_OBJECT_ID object_id)
GAME_OBJECT_ID Inv_GetItemOption(const GAME_OBJECT_ID obj_id)
{
if (Object_IsType(object_id, g_InvObjects)) {
return object_id;
if (Object_IsType(obj_id, g_InvObjects)) {
return obj_id;
}
return Object_GetCognate(object_id, g_ItemToInvObjectMap);
return Object_GetCognate(obj_id, g_ItemToInvObjectMap);
}

void Inv_InsertItem(INVENTORY_ITEM *const inv_item)
Expand All @@ -41,13 +41,13 @@ void Inv_InsertItem(INVENTORY_ITEM *const inv_item)
source->count++;
}

bool Inv_RemoveItem(const GAME_OBJECT_ID object_id)
bool Inv_RemoveItem(const GAME_OBJECT_ID obj_id)
{
const GAME_OBJECT_ID inv_object_id = Inv_GetItemOption(object_id);
const GAME_OBJECT_ID inv_obj_id = Inv_GetItemOption(obj_id);
for (RING_TYPE ring_type = 0; ring_type < RT_NUMBER_OF; ring_type++) {
INV_RING_SOURCE *const source = &g_InvRing_Source[ring_type];
for (int32_t i = 0; i < source->count; i++) {
if (source->items[i]->object_id == inv_object_id) {
if (source->items[i]->object_id == inv_obj_id) {
source->qtys[i]--;
if (source->qtys[i] == 0) {
source->count--;
Expand All @@ -63,13 +63,13 @@ bool Inv_RemoveItem(const GAME_OBJECT_ID object_id)
return false;
}

int32_t Inv_RequestItem(const GAME_OBJECT_ID object_id)
int32_t Inv_RequestItem(const GAME_OBJECT_ID obj_id)
{
const GAME_OBJECT_ID inv_object_id = Inv_GetItemOption(object_id);
const GAME_OBJECT_ID inv_obj_id = Inv_GetItemOption(obj_id);
for (RING_TYPE ring_type = 0; ring_type < RT_NUMBER_OF; ring_type++) {
INV_RING_SOURCE *const source = &g_InvRing_Source[ring_type];
for (int32_t i = 0; i < source->count; i++) {
if (source->items[i]->object_id == inv_object_id) {
if (source->items[i]->object_id == inv_obj_id) {
return source->qtys[i];
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/libtrx/game/inventory_ring/priv.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ static void M_HandleRequestedObject(INV_RING *const ring)
m_RequestedObjectID = NO_OBJECT;
}

void InvRing_SetRequestedObjectID(const GAME_OBJECT_ID object_id)
void InvRing_SetRequestedObjectID(const GAME_OBJECT_ID obj_id)
{
m_RequestedObjectID = object_id;
m_RequestedObjectID = obj_id;
}

void InvRing_InitRing(
Expand Down
8 changes: 4 additions & 4 deletions src/libtrx/game/items.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ void Item_TakeDamage(
}
}

ITEM *Item_Find(const GAME_OBJECT_ID object_id)
ITEM *Item_Find(const GAME_OBJECT_ID obj_id)
{
for (int32_t item_num = 0; item_num < Item_GetTotalCount(); item_num++) {
ITEM *const item = Item_Get(item_num);
if (item->object_id == object_id) {
if (item->object_id == obj_id) {
return item;
}
}
Expand All @@ -57,9 +57,9 @@ void Item_SwitchToAnim(

void Item_SwitchToObjAnim(
ITEM *const item, const int16_t anim_idx, const int16_t frame,
const GAME_OBJECT_ID object_id)
const GAME_OBJECT_ID obj_id)
{
const OBJECT *const obj = Object_Get(object_id);
const OBJECT *const obj = Object_Get(obj_id);
item->anim_num = obj->anim_idx + anim_idx;

const ANIM *const anim = Item_GetAnim(item);
Expand Down
4 changes: 2 additions & 2 deletions src/libtrx/game/lara/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ void Lara_Animate(ITEM *const item)
item->pos.z += (item->speed * Math_Cos(lara->move_angle)) >> W2V_SHIFT;
}

void Lara_SwapSingleMesh(const LARA_MESH mesh, const GAME_OBJECT_ID object_id)
void Lara_SwapSingleMesh(const LARA_MESH mesh, const GAME_OBJECT_ID obj_id)
{
const OBJECT *const obj = Object_Get(object_id);
const OBJECT *const obj = Object_Get(obj_id);
Lara_SetMesh(mesh, Object_GetMesh(obj->mesh_idx + mesh));
}

Expand Down
8 changes: 4 additions & 4 deletions src/libtrx/game/level/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -449,13 +449,13 @@ void Level_ReadObjects(VFILE *const file)
const int32_t num_objects = VFile_ReadS32(file);
LOG_INFO("objects: %d", num_objects);
for (int32_t i = 0; i < num_objects; i++) {
const GAME_OBJECT_ID object_id = VFile_ReadS32(file);
if (object_id < 0 || object_id >= O_NUMBER_OF) {
const GAME_OBJECT_ID obj_id = VFile_ReadS32(file);
if (obj_id < 0 || obj_id >= O_NUMBER_OF) {
Shell_ExitSystemFmt(
"Invalid object ID: %d (max=%d)", object_id, O_NUMBER_OF);
"Invalid object ID: %d (max=%d)", obj_id, O_NUMBER_OF);
}

OBJECT *const obj = Object_Get(object_id);
OBJECT *const obj = Object_Get(obj_id);
obj->mesh_count = VFile_ReadS16(file);
obj->mesh_idx = VFile_ReadS16(file);
obj->bone_idx = VFile_ReadS32(file) / ANIM_BONE_SIZE;
Expand Down
9 changes: 4 additions & 5 deletions src/libtrx/game/objects/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ static STATIC_OBJECT_2D m_StaticObjects2D[MAX_STATIC_OBJECTS] = {};
static OBJECT_MESH **m_MeshPointers = nullptr;
static int32_t m_MeshCount = 0;

OBJECT *Object_Get(const GAME_OBJECT_ID object_id)
OBJECT *Object_Get(const GAME_OBJECT_ID obj_id)
{
return &m_Objects[object_id];
return &m_Objects[obj_id];
}

STATIC_OBJECT_3D *Object_Get3DStatic(const int32_t static_id)
Expand All @@ -25,11 +25,10 @@ STATIC_OBJECT_2D *Object_Get2DStatic(const int32_t static_id)
return &m_StaticObjects2D[static_id];
}

bool Object_IsType(
const GAME_OBJECT_ID object_id, const GAME_OBJECT_ID *test_arr)
bool Object_IsType(const GAME_OBJECT_ID obj_id, const GAME_OBJECT_ID *test_arr)
{
for (int32_t i = 0; test_arr[i] != NO_OBJECT; i++) {
if (test_arr[i] == object_id) {
if (test_arr[i] == obj_id) {
return true;
}
}
Expand Down
32 changes: 16 additions & 16 deletions src/libtrx/game/objects/names.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,39 +33,39 @@ static void M_ClearNames(void);

static void M_ClearNames(void)
{
for (GAME_OBJECT_ID object_id = 0; object_id < O_NUMBER_OF; object_id++) {
M_NAME_ENTRY *const entry = &m_NamesTable[object_id];
for (GAME_OBJECT_ID obj_id = 0; obj_id < O_NUMBER_OF; obj_id++) {
M_NAME_ENTRY *const entry = &m_NamesTable[obj_id];
Memory_FreePointer(&entry->name);
Memory_FreePointer(&entry->description);
}
}

void Object_SetName(const GAME_OBJECT_ID object_id, const char *const name)
void Object_SetName(const GAME_OBJECT_ID obj_id, const char *const name)
{
M_NAME_ENTRY *const entry = &m_NamesTable[object_id];
M_NAME_ENTRY *const entry = &m_NamesTable[obj_id];
Memory_FreePointer(&entry->name);
ASSERT(name != nullptr);
entry->name = Memory_DupStr(name);
}

void Object_SetDescription(
const GAME_OBJECT_ID object_id, const char *const description)
const GAME_OBJECT_ID obj_id, const char *const description)
{
M_NAME_ENTRY *const entry = &m_NamesTable[object_id];
M_NAME_ENTRY *const entry = &m_NamesTable[obj_id];
Memory_FreePointer(&entry->description);
ASSERT(description != nullptr);
entry->description = Memory_DupStr(description);
}

const char *Object_GetName(const GAME_OBJECT_ID object_id)
const char *Object_GetName(const GAME_OBJECT_ID obj_id)
{
M_NAME_ENTRY *const entry = &m_NamesTable[object_id];
M_NAME_ENTRY *const entry = &m_NamesTable[obj_id];
return entry != nullptr ? entry->name : nullptr;
}

const char *Object_GetDescription(GAME_OBJECT_ID object_id)
const char *Object_GetDescription(GAME_OBJECT_ID obj_id)
{
M_NAME_ENTRY *const entry = &m_NamesTable[object_id];
M_NAME_ENTRY *const entry = &m_NamesTable[obj_id];
return entry != nullptr ? entry->description : nullptr;
}

Expand Down Expand Up @@ -95,26 +95,26 @@ GAME_OBJECT_ID *Object_IdsFromName(
{
VECTOR *source = Vector_Create(sizeof(STRING_FUZZY_SOURCE));

for (GAME_OBJECT_ID object_id = 0; object_id < O_NUMBER_OF; object_id++) {
if (filter != nullptr && !filter(object_id)) {
for (GAME_OBJECT_ID obj_id = 0; obj_id < O_NUMBER_OF; obj_id++) {
if (filter != nullptr && !filter(obj_id)) {
continue;
}

{
STRING_FUZZY_SOURCE source_item = {
.key = Object_GetName(object_id),
.value = (void *)(intptr_t)object_id,
.key = Object_GetName(obj_id),
.value = (void *)(intptr_t)obj_id,
.weight = 2,
};
if (source_item.key != nullptr) {
Vector_Add(source, &source_item);
}
}

if (Object_IsType(object_id, g_PickupObjects)) {
if (Object_IsType(obj_id, g_PickupObjects)) {
STRING_FUZZY_SOURCE source_item = {
.key = "pickup",
.value = (void *)(intptr_t)object_id,
.value = (void *)(intptr_t)obj_id,
.weight = 1,
};
Vector_Add(source, &source_item);
Expand Down
Loading

0 comments on commit 9d3119f

Please sign in to comment.