Anyway I'm having some trouble setting up the data structres that would be required to tackle this ambitious endeavour. Here's what I thought up so far:

So each item will have a number of properties... starting with ID, and then things like weaponDamage, armorRating, etc etc. Within that item would then be a "contains" array which will store pointers to other items... (I will probably have to limit the amount recursions at some point to retain sanity).
Another detail to note:
There will be 2 huge data structures:
- Master item data
This is where the "base" items are defined and stored. This list is created at compile and will not change in-game. Its purpose is to store a master database of every single item in the game.
- Created item data
This mirrors the master item database... basically, every single item placed into the map or created in-game will have a unique reference created for them. This is so that every single item can have unique data. When an item is created, it will pull its base stats from the master table, then create an entire copy of itself into this data structure. From then on, its properties can be modified in any way. I will of course have to create some form of clean up routine later down the line to delete removed items from this list to make way for newer items.
Any thoughts? Thinking of using a 3D array but if anyone has any input on how to optimize this entire system further... I'd like to hear about it.
Here's what I have so far but this is only in 2 dimensions and doesn't take into account the extra dimension needed to store contained items because I just can't wrap my head around this concept and translate it into code at the moment...
Code: Select all
//===========================================================================
//
// GLOBAL VARIABLES
//
//===========================================================================
global int 32: item[]; // master item data
global str 33: itemname[]; // master item name
global str 34: itemdesc[]; // master item description text
global int 35: createditem[]; // a list of all items created
global str 36: createditemname[]; // names of created items
global str 37: createditemdesc[]; // descriptions of created items
//===========================================================================
//
// MASTER ITEM DATA
//
//===========================================================================
#define item_max 16384 // maximum number of definable items
#define item_propsmax 16 // maximum number of properties
// item properties
#define item_prop_type 0 // the item type. weapon, armor, food, etc
#define item_prop_value 1 // the item's value for bartering
#define item_prop_weight 2 // the item's weight, in fixed point
#define item_prop_weapondamage 3 // weapon damage
#define item_prop_armorrating 4 // armor rating
#define item_prop_creationtime 5 // time stamp of item's creation
#define item_prop_condition 6 // item condition/durability
#define item_prop_conditionmax 7
#define item_prop_stolen 8 // is item stolen?
#define item_prop_weightmax 9 // if this item is a container, how much can it hold?
#define item_prop_weaponmod 10 // a flag of enabled enchantments on this weapon
#define item_prop_armormod 11 // a flag of enabled enchantments on this armor
#define item_prop_useeffect 12 // if this item is used, what will it do? for potions, food, etc
#define item_prop_13 13
#define item_prop_14 14
#define item_prop_15 15
// item types
#define item_type_none 0
#define item_type_food 1
#define item_type_weapon 2
#define item_type_container 3 // this item can hold other items!
function void SetItem(int x, int y, int val)
{
if(x >= item_max)
{
log(s:"x exceeds item_max");
return;
}
if(y >= item_propsmax)
{
log(s:"y exceeds item_propsmax");
return;
}
item[item_max * x + y] = val;
}
function int GetItem(int x, int y)
{
if(x >= item_max)
{
log(s:"x exceeds item_max");
return 0;
}
if(y >= item_propsmax)
{
log(s:"y exceeds item_propsmax");
return 0;
}
return item[item_max * x + y];
}
function void InitItems (void)
{
// 0
itemname[0] = "";
itemdesc[0] = "";
SetItem(0, item_prop_type, 0);
SetItem(0, item_prop_value, 0);
SetItem(0, item_prop_weight, 0);
SetItem(0, item_prop_weapondamage, 0);
SetItem(0, item_prop_armorrating, 0);
SetItem(0, item_prop_creationtime, 0);
SetItem(0, item_prop_condition, 0);
SetItem(0, item_prop_conditionmax, 0);
SetItem(0, item_prop_stolen, 0);
SetItem(0, item_prop_weightmax, 0);
SetItem(0, item_prop_weaponmod, 0);
SetItem(0, item_prop_armormod, 0);
SetItem(0, item_prop_useeffect, 0);
SetItem(0, item_prop_13, 0);
SetItem(0, item_prop_14, 0);
SetItem(0, item_prop_15, 0);
// 1
itemname[1] = "Roasted Chicken";
itemdesc[1] = "A juicy roasted chicken that heals for $someval points";
SetItem(1, item_prop_type, item_type_food);
SetItem(1, item_prop_value, 10);
SetItem(1, item_prop_weight, 0.5);
SetItem(1, item_prop_weapondamage, 0);
SetItem(1, item_prop_armorrating, 0);
SetItem(1, item_prop_creationtime, 0);
SetItem(1, item_prop_condition, 0);
SetItem(1, item_prop_conditionmax, 0);
SetItem(1, item_prop_stolen, 0);
SetItem(1, item_prop_weightmax, 0);
SetItem(1, item_prop_weaponmod, 0);
SetItem(1, item_prop_armormod, 0);
SetItem(1, item_prop_useeffect, 0);
SetItem(1, item_prop_13, 0);
SetItem(1, item_prop_14, 0);
SetItem(1, item_prop_15, 0);
// 2
itemname[2] = "Iron Sword";
itemdesc[2] = "A sword made of iron that deals $someval damage";
SetItem(2, item_prop_type, item_type_weapon);
SetItem(2, item_prop_value, 200);
SetItem(2, item_prop_weight, 2.5);
SetItem(2, item_prop_weapondamage, 25);
SetItem(2, item_prop_armorrating, 0);
SetItem(2, item_prop_creationtime, 0);
SetItem(2, item_prop_condition, 0);
SetItem(2, item_prop_conditionmax, 0);
SetItem(2, item_prop_stolen, 0);
SetItem(2, item_prop_weightmax, 0);
SetItem(2, item_prop_weaponmod, 0);
SetItem(2, item_prop_armormod, 0);
SetItem(2, item_prop_useeffect, 0);
SetItem(2, item_prop_13, 0);
SetItem(2, item_prop_14, 0);
SetItem(2, item_prop_15, 0);
}
//===========================================================================
//
// CREATED ITEMS
// An item created in-game will pull its base states from the master list
//
//===========================================================================
#define createditem_max 2147483647 // total number of items creatable
#define createditem_propsmax item_propsmax // same max properties as master
function void SetCreatedItem(int x, int y, int val)
{
if(x >= createditem_max)
{
log(s:"x exceeds createditem_max");
return;
}
if(y >= createditem_propsmax)
{
log(s:"y exceeds item_propsmax");
return;
}
createditem[createditem_max * x + y] = val;
}
function int GetCreatedItem(int x, int y)
{
if(x >= createditem_max)
{
log(s:"x exceeds createditem_max");
return 0;
}
if(y >= createditem_propsmax)
{
log(s:"y exceeds item_propsmax");
return 0;
}
return createditem[createditem_max * x + y];
}
