Change InventoryAdd/Remove/GetCount/SetCount and GameScriptInventoryObject to use ItemEnumPair.

This commit is contained in:
hispidence 2021-08-09 00:01:40 +01:00
parent 5458e7a67e
commit d3742cb87e
3 changed files with 14 additions and 25 deletions

View file

@ -13,7 +13,6 @@
#include "effect2.h" #include "effect2.h"
#include "pickup.h" #include "pickup.h"
#include "newinv2.h" #include "newinv2.h"
#include "InventorySlots.h"
#include "ObjectIDs.h" #include "ObjectIDs.h"
#ifndef _DEBUG #ifndef _DEBUG
@ -109,25 +108,25 @@ static void Earthquake(int strength)
} }
// Inventory // Inventory
static void InventoryAdd(GAME_OBJECT_ID slot, sol::optional<int> count) static void InventoryAdd(ItemEnumPair slot, sol::optional<int> count)
{ {
PickedUpObject(slot, count.value_or(0)); PickedUpObject(slot.m_pair.first, count.value_or(0));
} }
static void InventoryRemove(GAME_OBJECT_ID slot, sol::optional<int> count) static void InventoryRemove(ItemEnumPair slot, sol::optional<int> count)
{ {
RemoveObjectFromInventory(static_cast<GAME_OBJECT_ID>(inventry_objects_list[slot].object_number), count.value_or(0)); RemoveObjectFromInventory(slot.m_pair.first, count.value_or(0));
} }
static int InventoryGetCount(GAME_OBJECT_ID slot) static int InventoryGetCount(ItemEnumPair slot)
{ {
return GetInventoryCount(slot); return GetInventoryCount(slot.m_pair.first);
} }
static void InventorySetCount(GAME_OBJECT_ID slot, int count) static void InventorySetCount(ItemEnumPair slot, int count)
{ {
// add the amount we'd need to add to get to count // add the amount we'd need to add to get to count
int currAmt = GetInventoryCount(slot); int currAmt = GetInventoryCount(slot.m_pair.first);
InventoryAdd(slot, count - currAmt); InventoryAdd(slot, count - currAmt);
} }

View file

@ -1,24 +1,13 @@
#include "framework.h" #include "framework.h"
#include "GameScriptInventoryObject.h" #include "GameScriptInventoryObject.h"
GameScriptInventoryObject::GameScriptInventoryObject(std::string name, short slot, float yOffset, float scale, float xRot, float yRot, float zRot, short rotationFlags, int meshBits, __int64 operation) GameScriptInventoryObject::GameScriptInventoryObject(std::string const& name, ItemEnumPair slot, float yOffset, float scale, float xRot, float yRot, float zRot, short rotationFlags, int meshBits, __int64 operation) : name{ name }, slot{ slot.m_pair.second }, yOffset{ yOffset }, scale{ scale }, xRot{ xRot }, yRot{ yRot }, zRot{ zRot }, rotationFlags{ rotationFlags }, meshBits{ meshBits }, operation{ operation }
{ {}
this->name = name;
this->slot = slot;
this->yOffset = yOffset;
this->scale = scale;
this->xRot = xRot;
this->yRot = yRot;
this->zRot = zRot;
this->rotationFlags = rotationFlags;
this->meshBits = meshBits;
this->operation = operation;
}
void GameScriptInventoryObject::Register(sol::state * lua) void GameScriptInventoryObject::Register(sol::state * lua)
{ {
lua->new_usertype<GameScriptInventoryObject>("InventoryObject", lua->new_usertype<GameScriptInventoryObject>("InventoryObject",
sol::constructors<GameScriptInventoryObject(std::string, short, float, float, float, float, float, short, int, __int64)>(), sol::constructors<GameScriptInventoryObject(std::string const &, ItemEnumPair, float, float, float, float, float, short, int, __int64)>(),
"name", &GameScriptInventoryObject::name, "name", &GameScriptInventoryObject::name,
"yOffset", &GameScriptInventoryObject::yOffset, "yOffset", &GameScriptInventoryObject::yOffset,
"scale", &GameScriptInventoryObject::scale, "scale", &GameScriptInventoryObject::scale,

View file

@ -1,5 +1,6 @@
#pragma once #pragma once
#include <string> #include <string>
#include "ItemEnumPair.h"
namespace sol { namespace sol {
class state; class state;
@ -8,7 +9,7 @@ namespace sol {
struct GameScriptInventoryObject struct GameScriptInventoryObject
{ {
std::string name; std::string name;
short slot; inv_objects slot;
float yOffset; float yOffset;
float scale; float scale;
float xRot; float xRot;
@ -18,7 +19,7 @@ struct GameScriptInventoryObject
int meshBits; int meshBits;
__int64 operation; __int64 operation;
GameScriptInventoryObject(std::string name, short slot, float yOffset, float scale, float xRot, float yRot, float zRot, short rotationFlags, int meshBits, __int64 operation); GameScriptInventoryObject(std::string const & name, ItemEnumPair slot, float yOffset, float scale, float xRot, float yRot, float zRot, short rotationFlags, int meshBits, __int64 operation);
static void Register(sol::state* lua); static void Register(sol::state* lua);
}; };