Add inventory.
All checks were successful
Build Dusk / run-tests (push) Successful in 2m12s
Build Dusk / build-linux (push) Successful in 1m49s
Build Dusk / build-psp (push) Successful in 1m52s

This commit is contained in:
2026-01-06 07:47:16 -06:00
parent 024ace1078
commit af5bf987c8
91 changed files with 1108 additions and 139 deletions

135
archive/scriptfuncentity.h Normal file
View File

@@ -0,0 +1,135 @@
/**
* Copyright (c) 2025 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "script/scriptcontext.h"
#include "rpg/entity/entity.h"
#include "assert/assert.h"
int scriptFuncEntityAdd(lua_State *L) {
assertNotNull(L, "Lua state cannot be NULL");
assertTrue(lua_isinteger(L, 1), "Expected integer entity type");
lua_Integer entityType = luaL_checkinteger(L, 1);
assertTrue(
entityType >= ENTITY_TYPE_NULL && entityType < ENTITY_TYPE_COUNT,
"Invalid entity type passed to scriptFuncEntityAdd"
);
// Pop entity
uint8_t available = entityGetAvailable();
if(available == 0xFF) {
lua_pushnil(L);
return 1;
}
entity_t *ent = &ENTITIES[available];
entityInit(ent, (entitytype_t)entityType);
// May include X, Y and/or Z
if(lua_isinteger(L, 2)) {
lua_Integer xPos = luaL_checkinteger(L, 2);
ent->position.x = (int32_t)xPos;
}
if(lua_isinteger(L, 3)) {
lua_Integer yPos = luaL_checkinteger(L, 3);
ent->position.y = (int32_t)yPos;
}
if(lua_isinteger(L, 4)) {
lua_Integer zPos = luaL_checkinteger(L, 4);
ent->position.z = (int32_t)zPos;
}
// Send entity id.
lua_pushinteger(L, ent->id);
return 1;
}
int scriptFuncEntitySetX(lua_State *L) {
assertNotNull(L, "Lua state cannot be NULL");
assertTrue(lua_isinteger(L, 1), "Expected integer entity id");
assertTrue(lua_isinteger(L, 2), "Expected integer x position");
lua_Integer entityId = luaL_checkinteger(L, 1);
lua_Integer xPos = luaL_checkinteger(L, 2);
assertTrue(
entityId >= 0 && entityId < ENTITY_COUNT,
"Invalid entity id passed to scriptFuncEntitySetX"
);
entity_t *ent = &ENTITIES[entityId];
assertTrue(
ent->type != ENTITY_TYPE_NULL,
"Cannot set position of NULL entity in scriptFuncEntitySetX"
);
ent->position.x = (int32_t)xPos;
return 0;
}
int scriptFuncEntitySetY(lua_State *L) {
assertNotNull(L, "Lua state cannot be NULL");
assertTrue(lua_isinteger(L, 1), "Expected integer entity id");
assertTrue(lua_isinteger(L, 2), "Expected integer y position");
lua_Integer entityId = luaL_checkinteger(L, 1);
lua_Integer yPos = luaL_checkinteger(L, 2);
assertTrue(
entityId >= 0 && entityId < ENTITY_COUNT,
"Invalid entity id passed to scriptFuncEntitySetY"
);
entity_t *ent = &ENTITIES[entityId];
assertTrue(
ent->type != ENTITY_TYPE_NULL,
"Cannot set position of NULL entity in scriptFuncEntitySetY"
);
ent->position.y = (int32_t)yPos;
return 0;
}
int scriptFuncEntitySetZ(lua_State *L) {
assertNotNull(L, "Lua state cannot be NULL");
assertTrue(lua_isinteger(L, 1), "Expected integer entity id");
assertTrue(lua_isinteger(L, 2), "Expected integer z position");
lua_Integer entityId = luaL_checkinteger(L, 1);
lua_Integer zPos = luaL_checkinteger(L, 2);
assertTrue(
entityId >= 0 && entityId < ENTITY_COUNT,
"Invalid entity id passed to scriptFuncEntitySetZ"
);
entity_t *ent = &ENTITIES[entityId];
assertTrue(
ent->type != ENTITY_TYPE_NULL,
"Cannot set position of NULL entity in scriptFuncEntitySetZ"
);
ent->position.z = (int32_t)zPos;
return 0;
}
void scriptFuncEntity(scriptcontext_t *context) {
assertNotNull(context, "Script context cannot be NULL");
scriptContextRegFunc(context, "entityAdd", scriptFuncEntityAdd);
scriptContextRegFunc(context, "entitySetX", scriptFuncEntitySetX);
scriptContextRegFunc(context, "entitySetY", scriptFuncEntitySetY);
scriptContextRegFunc(context, "entitySetZ", scriptFuncEntitySetZ);
}