About Store Forum Documentation Contact



Post Reply 
Inventory Memx Container
Author Message
AndrewBGS Offline
Member

Post: #1
Inventory Memx Container
So after a ton of failed experiments, I came to the conclusion the best way of having my custom inventory is t make use of that Memx <Item> container.

Although I did ask this in another thread i couldn't get a straight answer, so I'm trying again:
WHERE are items added in that container?
Can I alter the way they're added there?

I badly need to separate items in there, so I would need to change the way items are added in there. Can someone please tell me straight where in code are items added to that container and (if possible) what method should i edit or overwrite to have it behave my way?
I really wish this would be explained better in comments so I wouldn't have to bother innocent people with stupid questions.
(This post was last modified: 04-23-2013 09:27 AM by AndrewBGS.)
04-23-2013 09:20 AM
Find all posts by this user Quote this message in a reply
cmontiel Offline
Member

Post: #2
RE: Inventory Memx Container
WHERE are items added in that container?

With method New(), at last position. With method NewAt(Int i), item is inserted at i-th valid index.

There is no Mem Extended.cpp (except for "Esenthel Engine Source Code" licence pfft) only header, so you cannot see the code.

Can I alter the way they're added there?

You can't, the important variables are private.

Would be better if you explain what you trying to do. What items do you need to separate?

IRC: irc.freenode.net
Channel: #Esenthel
(This post was last modified: 04-23-2013 02:07 PM by cmontiel.)
04-23-2013 02:06 PM
Find all posts by this user Quote this message in a reply
AndrewBGS Offline
Member

Post: #3
RE: Inventory Memx Container
So I'm trying to separate the gear equipped by the character from the gear in the backpack.
I'm having two ideas of doing this, both involve handling memx better:

- create another container for the gear (then delete items from backpack container and add them to equipped container, and viceversa) - not sure what I did wrong when trying this approach, but i couldn't seem to create new items from the items in memx container to store them in the new container
- alocate a fixed amount of slots of memx container for equipment, (ex first 20) and the rest represent the items in my bag (that would mean when an item is added, it's added after index 19).
04-23-2013 02:41 PM
Find all posts by this user Quote this message in a reply
cmontiel Offline
Member

Post: #4
RE: Inventory Memx Container
- alocate a fixed amount of slots of memx container for equipment, (ex first 20) and the rest represent the items in my bag (that would mean when an item is added, it's added after index 19).

Bad idea, will be harder to maintain and add items.

- create another container for the gear (then delete items from backpack container and add them to equipped container, and viceversa) - not sure what I did wrong when trying this approach, but i couldn't seem to create new items from the items in memx container to store them in the new container

There is no need for 2 containers. What about something like this:

Code:
struct Item
{

Int id;
Str name;
..
...

Bool equipped;
};

Memc<Item> items;

Item &it = items.New();
it.id = ...
it.name = ...
it.equipped = true;

equipped boolean will mark equipped items.

Instead of Memx, is better Memc for this case.

IRC: irc.freenode.net
Channel: #Esenthel
04-23-2013 03:04 PM
Find all posts by this user Quote this message in a reply
AndrewBGS Offline
Member

Post: #5
RE: Inventory Memx Container
This is pretty much the tutorials solution. which is good, and I understood all right.
But I DO NEED 2 containers.

I want to be able to display only some of the items in the bag, and in some order. Now of all items are in the same container, just that some are tagged to be equipped, this would complicate things damn much; what items not to display, item indexes in container with item indexes for display wouldn't sync, and a lot of tiny problems would appear.
So I just want two containers. If you don't know how I can achieve that it's fine, I'll manage somehow, but one container rises damn too many little issues for what I want.
04-23-2013 03:25 PM
Find all posts by this user Quote this message in a reply
cmontiel Offline
Member

Post: #6
RE: Inventory Memx Container
what items not to display?

Code:
FREPA(items)
{
           if(items[i].equipped)
           {
                     //draw item
           }
}

I still don't see the need for 2 containers. But you can achieve it this way:

Code:
Memc<Item> cont1;
Memc<Item> cont2;

// Add new item
Item &item = cont1.New();
item.id = ...
item.name = ....
...

// Remove the item and add him in cont2.

FREPA(cont1)
{
         if(cont1[i].id == someid)
        {
                 Item &item = cont2.New();
                 item.id = cont1[i].id;
                 item.name = cont1[i].name;
                 ......
                 cont1.remove(i,true);
                 break;
        }
}

IRC: irc.freenode.net
Channel: #Esenthel
(This post was last modified: 04-23-2013 03:37 PM by cmontiel.)
04-23-2013 03:35 PM
Find all posts by this user Quote this message in a reply
AndrewBGS Offline
Member

Post: #7
RE: Inventory Memx Container
Ok, well this is more helpful smile
A bit more complicated than I had hoped, but I guess I'll be able to work directly with item objects. I'll see what I can make of it.

(the problem is I'm having some UI that only displays a fix number of items, let's say 20. If some of those are hidden I still want 20 items displayed. And for the next "pannel", the 20 items displayed would have to start from index + hidden items on first pannel, and so on. So things would get complicated easily. Having 2 containers would be a lot easier).
04-23-2013 03:40 PM
Find all posts by this user Quote this message in a reply
TBJokers Offline
Member

Post: #8
RE: Inventory Memx Container
@Andreim44, us working on turfbattles decided to make our own Inventory code. We have set values for how many rows and columns. A bigger piece of equipment may take up 5x3 whilst there are some that only take up 2x2 and 1x1. For this the code becomes alot more complex, since you are supposed to sort your items to get more, also you can chose to sort using our algorithm.

at the creation of our inventory & inventory slots we initialize it's graphical view. A slot is never anything but data until we link it with a screen rectangle. We create our grids Memb by doing this

Code:
for(int row = 0; row < MAX_INV_ROW; ++row)
    for(int col = 0; col < MAX_INV_COL; ++col){
    *window+=InvGrid.New().create(Rect_RU(pos.x+Width(scale.x,col),pos.y-Height(scale.y,row),scale.x,scale.y));
    }

Those loops creates 13x9 elements for us. And at the same time we link them to a graphical rectangle (GuiImage).

right now we have 117 elements inside our Memb. When adding a new item & to make sure it fits the slot you have chosen you can simply do something like this

Code:
    --slot; //Keep it membable, I.e start at 0
    InventorySlots *invg = &InvGrid[slot];
    for(int row = 0; row < (-1 + item.ItemSize.y); ++row)
    for(int col = 0; col < (-1 + item.ItemSize.x); ++col){
        if(!InvGrid[slot + (row * 9) + col].valid()){
            return false;
        }
    }
    /*Reach this and you have selected a slot with all free x*Y*/
    invg->tbitems =& item;
    invg->PartUsed=  item.ItemSize;
    invg->rectangle=Rect_RU(invg->screenPos().x+invg->screenRect().w() * invg->tbitems->ItemSize.x,invg->screenPos().y,invg->screenRect().w() * (invg->tbitems->ItemSize.x), invg->screenRect().h() * (invg->tbitems->ItemSize.y ));

Now, i selected the first row and the second column, with an item of 5x3, then this easy bool above will check if it fits in both directions x and y.
if it does then you are ok to add. When it comes to equipped items, you can keep a set array, since my guess your slots are always going to be available. And then just keep definitions (MyArrayEquip[0] == Head)

Code:
struct Equipment_slots
{
        Item * myitem;
        Rect visiblilitycloak;
}MyArray[6];/*MyArray[0] = Head, MyArray[1] = feet, MyArray[2] = body*/

to know if it is valid or not you keep the pointer to you item. This way it can be NULL and it can also point to somewhere.
I hope i answered some questions for you, and i'd be glad to give you some more examples.
(This post was last modified: 04-23-2013 04:13 PM by TBJokers.)
04-23-2013 04:08 PM
Visit this user's website Find all posts by this user Quote this message in a reply
AndrewBGS Offline
Member

Post: #9
RE: Inventory Memx Container
That does remind me of some idea I once had, and couldn't understand why it won't work:
For the equipped gear, i wanted to have a fixed array of 20 Item elements:

Item gear[20];

Then in the gui update function, just get the item from the memx container at index i and place it in the temp (0 index) slot of the gear array. Now, the way I tried to achieve this is this:

Item item=*inv.items[i]; //where inv.items is declared: Memx <Item> items.
This doesn't work however, and I wish i knew why. No matter how much i played around with * and & operators, I can't make that attribution work.
I get the same error if I try: item=inv.items.Elm(i);

Any idea how I should go around this? I want to get the item object from the memx container. The object itself, not just a reference. Could you tell me what I'm doing wrong? I'm stuck with this inventory issues for quite a while now, it's getting frustrating.

Turns out this is actually my biggest problem: whatever solution I try, it comes down to getting an item from the memx item container.

So how can achieve this? Getting a reference to the item works fine, but I can't seem to get the item itself :| I feel stupid.
(This post was last modified: 04-23-2013 04:34 PM by AndrewBGS.)
04-23-2013 04:16 PM
Find all posts by this user Quote this message in a reply
Rubeus Offline
Member

Post: #10
RE: Inventory Memx Container
To get an item from the Memx container, it should be a matter of using Items[i]. If you want an item from the Items Memx in the 0th place of the gear array, did you try gear[0] = Items[i] ? Personally, to limit the size, I would just do a check on Items.elms() whenever adding something to the inventory.
if( Items.elms( ) <= INV_SIZE ) // Add item
04-23-2013 05:39 PM
Find all posts by this user Quote this message in a reply
AndrewBGS Offline
Member

Post: #11
RE: Inventory Memx Container
Well, this leads to the same error I keep getting:

error c2783: 'void EE::Game::Obj::operator = (const EE::Game::Obj &)' : could not deduce template argument for 'UNUSED'

this error points me to the last closed bracket row of the updateGui function. And I'm totally lost with it. Does anyone know what it means? Google wasn't of much help.
04-23-2013 06:38 PM
Find all posts by this user Quote this message in a reply
rstralberg Offline
Member

Post: #12
RE: Inventory Memx Container
Item& item = inv.item[i];

My Blog is at http://mrstralberg.blogspot.se.
Chat account Skype (rstralberg)
04-23-2013 07:09 PM
Visit this user's website Find all posts by this user Quote this message in a reply
AndrewBGS Offline
Member

Post: #13
RE: Inventory Memx Container
Well, that was something I didn't try.
But it didn't seem to work.
What I'm trying to do is:

//when click an item in the backpack
- get that item (object!)
- copy that item somewhere else
- delete the item from the inventory container

Pointer operations, like what you suggest, all fail when I delete the object in the container. I keep his address, but when I delete the actual object the copied address just points to something I destroyed.

I have to duplicate the actual object somehow. And as simple as it sounds I can't seem to find a way to do it.

Right, I found my answer in another thread. Apparently it's because of Memx NO_COPY_CONSTRUCTOR thingie. I hope the engine will change that real soon, no idea why it wouldn't let a copy constructor in there.

At least it's half a release that i'm not as stupid as i thought.
(This post was last modified: 04-23-2013 08:56 PM by AndrewBGS.)
04-23-2013 08:22 PM
Find all posts by this user Quote this message in a reply
AndrewBGS Offline
Member

Post: #14
RE: Inventory Memx Container
Back to my original question:

How do I alter the way items are added to the Memx container?
I'm trying to implement STACKS, so when an item that is already in the memx is added, i don't want a new instance of that item in there, I just want a corresponding index counter to be incremented.
Can you tell me how and where to do that?
04-24-2013 07:18 AM
Find all posts by this user Quote this message in a reply
Rubeus Offline
Member

Post: #15
RE: Inventory Memx Container
It sounds to me like you would be better off just remaking the inventory system from scratch.
04-24-2013 02:19 PM
Find all posts by this user Quote this message in a reply
Post Reply