LambdaRogue .:. roguelike RPG


25.09.2009, 10:17, written by Mario Donick

The Item Package Problem

In a comment, Grimwerk wrote:

I found it weird that I could not drop my aspirin unless it was a full pack. Luckily, I was able to sell it.

My answer:

This is indeed weird, but I have not yet found another solution forthis problem. If I would allow you to drop a, say half-empty, "packageof"-item, you would be able to pick up a FULL package afterwards,because the number of units in the package is not stored in the dungeonstructure (only the existence of an item with the name "package of...." is stored). This could be solved by changing the item- anddungeon-structure, but this is a very low priority for me.

Now I want to go more in detail. The background of this silly problem is that items in LambdaRogue are no actual objects. Instead, there exist hundreds of "templates", containing the item properties (name, type, effect etc.) All occurences of items are only references to a certain template, and all item handling just works with these references.

Say, Aspirin is template no. 14 (here, this is just an arbitrary number, to demonstrate the problem). Among others, that template has a property "amount", which may be 25 (I don't remember the actual number currently).

Now, say you see an Aspirin on a dungeon tile. Then what you see is not an actual object that could be manipulated as own data/methods structure. It is just a reference: TheDungeon[12,24].intItem = 14 So, when you pick up that item, you don't change the position (state, owner, ...) of an actual object -- you just remove the reference to the template from the dungeon tile (TheDungeon[12,24].intItem = 0) and add a reference to the same template in your inventory list (Inventory[3].intType = 14), or, in case of Aspirin, add 25 references of the same type in the same inventory slot (Inventory[3].intNumber += 25).

If you consume an item, you decrease the amount of references. If you equip an item, you add an reference to the related equipment slot. Dropping an item simply decreases references, usually by 1.

But as a full package of Aspirin may add 25 references to inventory, depicting 25 pills of Aspirin, dropping a package of Aspirin should neither drop just 1 pill, nor the full 25 package, but drop the actual amount. But as one dungeon tile can only store the reference, and only 1, this is not possible.

Now there are several ways to deal with my design failure: wink

  1. Only allow to drop "Package of Aspirin" if at least 25 units of Aspirin (= 25 references) are in the related inventory slot. This is the current "solution".
  2. Don't use packages, but single units: "Aspirin", "Long Arrow" etc. The problem here is that it would take lots of time to buy or find a decent amount of Aspirin.
  3. The same as 2., but allow traders to sell more than one item unit at a time: Thus, sell it as "Package of Aspirin", but once in inventory, process it as 'unit of' "Aspirin".

Any opinions? (Changing the item system is no option for the 1.x branch of LambdaRogue; this will be part of the 2.x re-write).

Earlier / Later / Permanent Link

 

Comments

Krice schrieb am 25.09.2009, 12:52

How about creating an actual item object and then inventory and map both contain item objects. The handling should not be that different, other than item stacks which needs add/remove routines. The item object itself could be really simple, containing amount of items in stack and item type to point at item template, better known as data.

 

Mario Donick schrieb am 25.09.2009, 12:59

Theoretically you're right and this is what I do in the 2.x branch, but 1.x is not object oriented and will never be.

 

Krice schrieb am 25.09.2009, 14:45

That's quite.. strict, don't you think? Using a class as type to replace simple int is not that object oriented anyway.

 

mingos schrieb am 25.09.2009, 23:02
single item

1. Make aspirin a single pill instead of a box of 25
2. Lower the price of aspirin
3. Let shopkeepers sell you any amount of aspirin, each at a unitary price of 1/25 of a full packet.
4. Eliminate aspirin lying around the dungeon. Monsters that might have dropped it don't use aspirin anyway biggrin.

That's the quickest and simplest workaround. In the long run, I think you really should use objects. you already have a template (I guess it's a struct of values). Just apply those values to an Item class and instead of an integer, make the map point to an object in the memory. Operate on it via a pointer only. It might require a small refactor, but I don't believe it's not doable.

Byt the way, items can be structs, they really don't have to be instances of a CLASS, so the design won't necessarily be object oriented biggrin.

 

Dave schrieb am 28.09.2009, 00:43
Items

What I do in Kharne is store a bunch of TItems (my item class) in a TObjectList. Inventory is then just an array of ints linked to the ItemIndex of the object in TObjectList.

 

 

Write a comment

Your name:


Headline:


Spam protection: Enter the result of »eleven minus six« as word:


Text of your comment:


Click »Send« to save your comment.

powered by d.elog blogging software v0.6 / 17.04.2009
© Mario Donick 2005–2009.
d.elog contains Xinha, a free WYSIWYG textarea editor.