About Store Forum Documentation Contact
Donations:
345$/mo



Post Reply 
move World Object to Storage
Author Message
AndrewBGS Offline
Member

Post: #1
move World Object to Storage
I would really need this function NOT to require EXACTLY the same type of container as the Object type in order to move it; I want to move an item of type FOOD, which EXTENDS ITEM, into a container of type ITEM.
The function does not allow me to do this; I tried doing this manually, but something probably gets messed up, because I end up with wrong parameters.

Can't you alter the moveWorldObjectToStorage function to accommodate moving Objects of a subtype of the container into the container please?
07-07-2013 09:33 AM
Find all posts by this user Quote this message in a reply
Rofar Offline
Member

Post: #2
RE: move World Object to Storage
If I understand this correctly, you want to be able to have classes that extend the item class for specific item functionality. If that is the case, I have been trying to figure out how to do this as well. I haven't really put much effort into this yet but I'm not seeing how to do this easily yet.
07-07-2013 03:54 PM
Find all posts by this user Quote this message in a reply
AndrewBGS Offline
Member

Post: #3
RE: move World Object to Storage
Well, it does bring me a little comfort to see I'm not the only one with this issue.
Yes, extending item in code is proving to be a real challange. I was suggested to make my own inventory system, but after spending so much time to get used to Esenthel's one, and finally using it really good in my game, I'd like to keep it.

But... here's the issue. Can't integrate sub-classes of item. And I would like to request making this possible.
07-07-2013 04:30 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #4
RE: move World Object to Storage
You would lose all members specific to "FOOD" class when moving to "ITEM" container, assuming that you have
class FOOD : ITEM
{
}
and want to put that into
Memx<ITEM> items;
07-08-2013 08:54 AM
Find all posts by this user Quote this message in a reply
AndrewBGS Offline
Member

Post: #5
RE: move World Object to Storage
i know, that is why this topic is under "feature request".
I know this is what currently happens, but I would really need the functionality to be changed so FOOD specific members would be kept. Any chance you could do that for us?

My alternatives are using STL (which i know near to nothing about) or pile up all info about FOOD, ARMOR, WEAPON and whatever item extensions I have right in the Item class, and i'll only use 4-5 of the 15 parameters at a time. Which... I'd rather not do.
07-08-2013 10:19 AM
Find all posts by this user Quote this message in a reply
Rofar Offline
Member

Post: #6
RE: move World Object to Storage
There is another alternative Andrew. This is actually the way I am handling it currently.
-Create a class ItemData and implement Load and Save (along with data members for things that all of your items have).
-Extend this ItemData class for each of your item types.
-Add a member to your item class of ItemData*. Instantiate the desired ItemData class for the item based on Item type.
-When Item Load or Save is called, call the methods in your ItemData instantiated class.

It's not a super clean solution but I think it solves the problem adequately.
(This post was last modified: 07-08-2013 04:39 PM by Rofar.)
07-08-2013 04:38 PM
Find all posts by this user Quote this message in a reply
shadow Offline
Member

Post: #7
RE: move World Object to Storage
Why not use "Memx<FOOD> foods;" ?
07-08-2013 05:44 PM
Find all posts by this user Quote this message in a reply
AndrewBGS Offline
Member

Post: #8
RE: move World Object to Storage
And use 3 containers in the inventory? Then figure a way to display item from the 3-4 containers in the order items were picked up, not container by container? No thanks...
07-08-2013 05:52 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #9
RE: move World Object to Storage
You cannot make a container which holds class objects (not pointers) of different kinds of classes.
Using multiple containers for different classes is the way to go.
07-08-2013 08:05 PM
Find all posts by this user Quote this message in a reply
AndrewBGS Offline
Member

Post: #10
RE: move World Object to Storage
Well that's a no-go. Naturally when you have an inventory you want to see items in the order you pick them up, and if those items are stored in 4 containers it's a total pain in the ass to achieve this.

I guess I have to either drop the esenthel inventory pattern or pile up all possible item info in the Item class.... sucks. I'll see what I can do.
07-08-2013 08:35 PM
Find all posts by this user Quote this message in a reply
Rofar Offline
Member

Post: #11
RE: move World Object to Storage
No, you don't have to drop the esenthel inventory pattern and you don't have to pile up all the possible item info in the item class. I explained an alternative above.
07-08-2013 09:29 PM
Find all posts by this user Quote this message in a reply
AndrewBGS Offline
Member

Post: #12
RE: move World Object to Storage
I tried several things close to this one, it doesn't really work. If the inventroy container is of some super type, there's no way I can add in it items of some extended types. That is because the container does NOT actually have an ADD method, so everything new has to be created there. And if it's an Item container, it will call the item constructor. And won't build the sub-type object, it will always go for the item one.
I tried, a lot. Couldn't find any way around this.
If you do, and it actually works, I would be very happy if you shared it with me. But I really don't think it's possible anymore.
07-08-2013 09:34 PM
Find all posts by this user Quote this message in a reply
Rofar Offline
Member

Post: #13
RE: move World Object to Storage
Maybe you don't fully understand my solution.

Code:
class Item : Game.Item
{
   // various methods and members

   ItemData* data;
}

class ItemData
{
   Str Name;
   // and whatever else is common to all items
}

class ArmorData : ItemData
{
   int ArmorClass;
   // whatever else your armor needs
}

Then in the Item class Create method:
Code:
if (type == [armor]
  {
     data = new AmorData();
     // set members
     data->AmorClass = [probably from an object param]
  }
  else
    data = new ItemData();

  // set common members
  data->Name = [from params]

And do the same thing in the load method. So the object params would have an indication of the type of item and that is saved and loaded.

So when Created...based on params, instantiate the ItemData member as ItemData, ArmorData, WeaponData, FoodData...whatever you create.

When loaded...based on the saved type, instantiate the ItemData member as the specific data type you need.

Does this make sense? I know it works because I am doing it this way.
(This post was last modified: 07-08-2013 09:50 PM by Rofar.)
07-08-2013 09:49 PM
Find all posts by this user Quote this message in a reply
AndrewBGS Offline
Member

Post: #14
RE: move World Object to Storage
Aaaah yes, I did misunderstand you, I see your point now. I do believe this could work, yes. I'll give it a go, see how it works out. Thanks.
07-08-2013 10:02 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #15
RE: move World Object to Storage
Or add
DateTime picked_up_at;
member to all of your item classes

Memc<Game.Obj*> items;
setup pointers to all of your objects (from all of the containers)

then sort the pointers by 'picked_up_at' member, and draw according to pointers.

Possibilites are endless.
07-09-2013 05:54 PM
Find all posts by this user Quote this message in a reply
Post Reply