Author Topic: How do I figure out if a box is full (or, alternatively, an item's size)?  (Read 436 times)

Legacy_The__Dude

  • Newbie
  • *
  • Posts: 10
  • Karma: +0/-0


               What I'm trying to do is make a wand that will bundle everything I have of a certain type of thing into a box that I have in my possession but I need to know when to stop. I can't seem to figure out if a new item copied into its inventory would actually fit. Clearly the game figures this out when I try to drag and drop something and there isn't room, but I can't find a function I could use to make that same check. Anyone know if I'm missing something obious?

In the meantime, I've come up with a way to work around not knowing when the container is full if that proves to be unsolvable. First, I'll assume an empty box (it's on me to empty it before I begin unless there's an easy way to do *that*...). Next, figure out the size of the item I'm trying to bundle into the box and stop when I've reached the limit of how many items of that size could fit into an empty box.

Of course that leads to me not being able to figure out the size of the items easily. I can't seem to find item properties to get x and y sizes. At the moment all I seem to be able to do with this workaround is to figure out the size by going through all the
known base item types and my knowlege of their sizes. Figure out
which one the item I'm bundling is and limit myself to transferring that many of the item I selected. So if I've got seven items that are base item type of BASE_ITEM_MISCMEDIUM then I know I've got a 2x2 item and I can only fit six of them so I leave one of them out of the box. If someone knows an easier way to do this I'd love to hear about it!
               
               

               
            

Legacy_FunkySwerve

  • Hero Member
  • *****
  • Posts: 2325
  • Karma: +0/-0
How do I figure out if a box is full (or, alternatively, an item's size)?
« Reply #1 on: December 19, 2010, 10:42:04 pm »


               Given the limited functions that we have, the algorithm to do this for any given container and any possible set of items would be extraordinarily complicated. You'd have to store each base item's dimensions, then 'fill' the container one bit at a time. The trick would not be so much knowing if you could fit another item, as in knowing if they could fit if placed a different way.



To do it as I think you mean, however, it would be manageable given a few simplifying factors:

1) the wand would only work if the bag were empty

2) the 'certain type of thing' you want to bundle is either all the same base item type, or, at a minimum, of another type of identical size



From there it's relatively easy to calculate how many would fit of a given type - you could even make a function to return limit by type.



As for the sizes of the items, they're stored in baseitems.2da, in columns labeled InvSlotWidth and InvSlotHeight. You can view 2das using NWN Explorer.



Funky
               
               

               
            

Legacy_The__Dude

  • Newbie
  • *
  • Posts: 10
  • Karma: +0/-0
How do I figure out if a box is full (or, alternatively, an item's size)?
« Reply #2 on: December 19, 2010, 10:51:03 pm »


               You are correct about the mind boggling permutations necessary to figure out if I'm trying to do a "put all my inventory into my boxes" type thing. I am, however, simplifying things exactly as you say; box is assumed empty and function only works on a single item type (the item to bundle is selected by the wand so that object's resref and base item type are used).



Thanks for the tip about the baseitems.2da file! I was just going by memory through the base item constants listed in the lexicon.
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
How do I figure out if a box is full (or, alternatively, an item's size)?
« Reply #3 on: December 20, 2010, 02:19:40 am »


               To get the X.y values you can use.  



int nWidth = StringToInt(Get2daString( "baseitems","InvSlotWidth",GetBaseItemType(oItem)));

int nHieght = StringToInt(Get2daString( "baseitems","InvSlotHeight",GetBaseItemType(oItem)));



Where oItem is the item you want the information for.
               
               

               
            

Legacy_The__Dude

  • Newbie
  • *
  • Posts: 10
  • Karma: +0/-0
How do I figure out if a box is full (or, alternatively, an item's size)?
« Reply #4 on: December 20, 2010, 03:06:48 am »


               Oh fantastic! And just when I was finished with my awful switch statement from beyond... And hey, that solves my trying to get the max stack size issue too! Thanks!