Join GitHub today
GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.
Sign up[WIP] [CR] Item Bags #10927
Conversation
DavidKeaton
added some commits
Jan 18, 2015
DavidKeaton
reviewed
Jan 19, 2015
| bmenu.addentry((i + 1), true, -1, bag.contents[i].tname()); | ||
| } | ||
| bmenu.query(); | ||
| int index = clamp_value(0, (bmenu.ret - 1), bag.contents.size()); |
This comment has been minimized.
This comment has been minimized.
DavidKeaton
Jan 19, 2015
Author
Contributor
I know that this is the cause of removing an item even if you don't select it [via escape to quit], but I put this here to prevent OOB errors with vector for the time being.
DavidKeaton
reviewed
Jan 19, 2015
| @@ -1511,6 +1582,12 @@ nc_color item::color(player *u) const | |||
| ammotype amtype = ammo_type(); | |||
| if (u->has_ammo(amtype).size() > 0) | |||
| ret = c_green; | |||
| } else if(is_item_container()) { // something we can store items in | |||
| if(!has_been_opened || is_container_empty()) { | |||
| ret = c_ltgray; // unknown contents or we know it's empty | |||
This comment has been minimized.
This comment has been minimized.
DavidKeaton
Jan 19, 2015
Author
Contributor
I want to perhaps make unopened bags a color and just make 'known' bags regular.
DavidKeaton
reviewed
Jan 19, 2015
| int storage_occupied; | ||
| public: | ||
| // amount of storage available in bag | ||
| inline int storage_left() const |
This comment has been minimized.
This comment has been minimized.
DavidKeaton
Jan 19, 2015
Author
Contributor
Prob just migrate this logic into get_remaining_capacity.
BevapDin
reviewed
Jan 19, 2015
| { | ||
| item it; | ||
| if(is_container_empty()) { | ||
| it.type->id = "null"; |
This comment has been minimized.
This comment has been minimized.
BevapDin
Jan 19, 2015
Contributor
You do not want to change the id of an existing item type, ever. This member is only written when new items types are created during loading of the world data.
Just return the default created item and later check the returned item with item::is_null().
BevapDin
reviewed
Jan 19, 2015
| if(!is_between(1, bmenu.ret, i, true)) { return; } | ||
| bag.has_been_opened = true; | ||
| //[davek] TODO: explain volume_factor | ||
| u.store(&bag, ur_junk[bmenu.ret-1], "null", bag.storage_used()); |
This comment has been minimized.
This comment has been minimized.
BevapDin
Jan 19, 2015
Contributor
How about using game::inv() or game::inv_for_filter instead of this whole block.
BevapDin
reviewed
Jan 19, 2015
| bool did_coloring = (c == c_ltgray) ? false : true; | ||
| if(did_coloring) { temp1 << "<color_" << string_from_color(c) << ">"; } | ||
| temp1 << item::nname(elem.type->id); | ||
| if(did_coloring) { temp1 << "</color>"; } |
This comment has been minimized.
This comment has been minimized.
BevapDin
Jan 19, 2015
Contributor
Why don't you print color tags for ltgray? This seems unnecessarily and potentially wrong (you don't know which default color is used to display the text).
BevapDin
reviewed
Jan 19, 2015
| @@ -493,6 +510,23 @@ class item : public JsonSerializer, public JsonDeserializer | |||
| mtype* corpse; | |||
| std::vector<item> contents; | |||
|
|
|||
| protected: | |||
| // amount of storage used by bag | |||
| int storage_occupied; | |||
This comment has been minimized.
This comment has been minimized.
BevapDin
Jan 19, 2015
Contributor
This looks like a simple cache of the total contained volume. It can be recalculated when needed for the few items that require it instead of storing it for every item in existence.
BevapDin
reviewed
Jan 19, 2015
| // determines if the item will fit in the space left | ||
| inline bool has_space_for(item it) | ||
| { | ||
| return (it.volume() < storage_left()); |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
Some style issue: I know the temptation is big, but function definitions inside the class definitions are automatically inline, so there is no need to add the inline keyword there, it's redundant. An index in a vector is of type Some item functions could be const ( And |
This comment has been minimized.
This comment has been minimized.
|
Duly noted! I appreciate the clarification on a few things (namely, didn't know const prevents shadow copy and all that, nor about inline not needing to be declared). I can slip these in as I got some more code to do to this anywho. Thanks Bevap! |
This comment has been minimized.
This comment has been minimized.
What exactly are you referring to with "shadow copy"? |
This comment has been minimized.
This comment has been minimized.
|
I am referring to the fact it makes a copy of the item as its argument, or is this notion I have not right? |
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
|
const doesn't prevent that, using a reference does. It's pass by reference vs pass by value. By reference you pass it THE object, by value you just pass the value contained in the object. |
kevingranade
reviewed
Jan 20, 2015
| bool item::is_item_container() const | ||
| { | ||
| // only check for armour atm | ||
| return type->armor && (type->armor->storage > 0) && has_flag("HOLDS_ITEMS"); |
This comment has been minimized.
This comment has been minimized.
kevingranade
Jan 20, 2015
Member
Might be good temporally, but eventually if it has storage it will be a container.
kevingranade
reviewed
Jan 20, 2015
| return (get_storage() - storage_left()); | ||
| } | ||
| // whether the mysteries of a bag have been explored. | ||
| bool has_been_opened; |
This comment has been minimized.
This comment has been minimized.
kevingranade
Jan 20, 2015
Member
A bool is insufficient for this, we need to know if a particular player has opened the bag. Since there's no stable way for a player to refer to a bag, this should probably be a set of player identifiers.
kevingranade
reviewed
Jan 20, 2015
| @@ -914,6 +921,7 @@ class player : public Character, public JsonSerializer, public JsonDeserializer | |||
| * the weapon or worn items, If the item is a pointer to an item inside a | |||
| * container, it wont work. | |||
| */ | |||
| // [davek] TODO: Extend this with item `pathname` extension to search nested containers. | |||
This comment has been minimized.
This comment has been minimized.
kevingranade
Jan 20, 2015
Member
There are two options here, either issue every item a unique index or use a set of tiered indices.
I haven't thought out the implications of both yet.
This comment has been minimized.
This comment has been minimized.
|
re: the two options As far as what the pathname will look like? I have a rough draft if you want to see it. |
This comment has been minimized.
This comment has been minimized.
|
re: learning about C++ Thanks for the info! :-) |
This comment has been minimized.
This comment has been minimized.
|
Okay so the basic implement was the easy part, been having to rewrite chunks at a time (this ain't dead yet). |
This comment has been minimized.
This comment has been minimized.
|
I'm looking forward to seeing how this one turns out. |
This comment has been minimized.
This comment has been minimized.
|
I hope at least a majority of container management will be in background instead of explicit. I want to play a scavenger roguelike, not inventory management game. As in, inventory is still looking mostly the same as now, except if you take a worn container with background-assigned items off and you have no space for the entire container on you, you're presented with the option to 'w'ield the container, and if you refuse, to drop the items on the floor (if container itself can still fit) or drop it altogether (if it can't). So you don't have to waste time putting things into backpacks, bags, pouches and pockets manually or switching their container if you take one of them off. However there still should be option to exempt a container from background assignment, resulting in it being manually-managed (or even auto-stocked for things like wielding items! Put a knife in a sheath, wield it, take it off, it goes back in that sheath instead of any other container). |
This comment has been minimized.
This comment has been minimized.
|
I don't think that's quite the direction I'm going mate. |
This comment has been minimized.
This comment has been minimized.
|
Hopefully a miscommunication, that's roughly what we discussed what was |
This comment has been minimized.
This comment has been minimized.
|
Wait so now I'm confused? |
This comment has been minimized.
This comment has been minimized.
|
If you mean the auto sort items yes, but i think he meant the system staying close to similar. |
This comment has been minimized.
This comment has been minimized.
|
Yeah, even with automatic containerization, it won't be that similar -- for On Tue, Jan 27, 2015 at 7:21 PM, Davek notifications@github.com wrote:
|
This comment has been minimized.
This comment has been minimized.
|
My aim is to make it as transparent as possible, but items will be in containers. Not the same volume system as before. |
This comment has been minimized.
This comment has been minimized.
|
Yes, but there should be an interface that works more or less like the |
This comment has been minimized.
This comment has been minimized.
Yep, that's exactly what I mean! Having a non-basic inventory mode that shows nested containers with some data, like example below and working like a 2D layering interface, would be very nice in addition to the basic one. But by no means required!
Aaaalso, speaking of ideas. This PR can pave the way for advanced decay mechanics, for example, honey rotting if it's placed in a container that doesn't seal (IRL honey starts to decay when it absorbs enough water to drop sugar content below antibacterial threshold, and so needs to be stored in airtight containers) or tin cans that have been opened not preserving their contents. |
This comment has been minimized.
This comment has been minimized.
|
Ah okay! Gotcha! Yeah man, it won't be having to open a container to get the item. That was a big misconstrued notion I picked up. Sorry aboot that. |
This comment has been minimized.
This comment has been minimized.
|
Any news on this front? |
This comment has been minimized.
This comment has been minimized.
|
Late reply, didn't ever show up as a notification. Still in the works, check out #11182 |
DavidKeaton commentedJan 19, 2015
See #10926
This is still WIP, even though it's basic. I still need some minor kinks sorted out before this can be merge-able, and I would massively prefer to be able to merge in changes over time in successive PRs, so that way all the additions aren't in a massive commit and a total bitch to merge.
Things that need fixed
backpackcan do this.uimenu_cb.