[DGD] Complex Inventory

Lord Lerkista lordlerkista at gmx.net
Mon Nov 7 05:43:02 CET 2005


I want to change the way query_inventory() works, i want to group 
similar items, at the moment
i use another function to get the object list and then using mappings to 
make the list, for example

items["small sword"]++; items["small sword"] returns the number of items 
named "small sword",
but i want to do it all directly with query_inventory(), returning a 
mapping with all the inventory
data in a better way

I've thinking in something like this:

inventory = ([ "Items_Eqp": ([ "small sword": ([ Object: 1 ]),
                                            "small shield": ([ Object: 1 ])
                                            "small ring": ([ Object1:1, 
Object2:1 ])
                                         ]),
                     "Items_Nrm": ([ "simple key": ([ Object1: 1, 
Object2:1, Object3:1  ])
                                         ])
            ]);

That way i can add objects like this:

if(ob->query_equipped())
{
  inventory["Items_Eqp"][ob->query_short()][ob]=1;
}
else
{
  inventory["Items_Nrm"][ob->query_short()][ob]=1;
}

to handle two separate inventories, like in MMORPGs one with the items 
equipped and one
with the all other stuff

and doing a query like:

number = map_sizeof(inventory["Items_Nrm"][ob->query_short()];
items = map_sizeof(inventory["Items_Nrm"];

number will give me the number of ob same-type objects
items will give me the number of the different objects i have, maybe a 
inventory based on slots
like many MMORPGs

But in this example i use 3 nested mappings, and that may uses many 
resources, well i don't know
exactly because i haven't tested this, is just theory

Any better method to do that in a 2.4.5 derived lib??












More information about the DGD mailing list