Advertisement

Combining Objects

Started by March 18, 2001 10:55 AM
10 comments, last by Ketchaval 23 years, 9 months ago
What are the best ways of making games where the "objects" (ie. items that the player can pick up and manipulate) are combinable to create something with a different / altered or combined effect?
I would create objects using your own medium-level scripting language. If you embed a gem of light on a staff, for instance, just combine the scripts of the objects and any incompatabilities (like both have the same effect on a single command) can be resolved randomly. (eliminate one of them, make that action cause both effects) I could come up with some examples if you like...
Advertisement
This is a good place for bitflags, eg, one potion could have flags of ITEM_CONSUMABLE | ITEM_MAGICAL (among others), while another could have ITEM_CONSUMABLE | ITEM_FIRERESISTANT. Combine the two potions and simply or the flags together to make one super potion. You could also have certain flags cancel each other out. Check out your bitwise operators


Or if there is only a small amount of "combined" items, then make separate items for them. For example you have empty waterskin and waterskin which are separate objects. When the player fills the empty waterskin it''s object id is changed to waterskin. This example was taken from my game
Or have a Waterskin object of type OBJ_CONTAINER and a flag of OBJ_FLAG_FULL

An empty Waterskin would, obviously, be flagged OBJ_FLAG_EMPTY
quote: Original post by Anonymous Poster
Or have a Waterskin object of type OBJ_CONTAINER and a flag of OBJ_FLAG_FULL
An empty Waterskin would, obviously, be flagged OBJ_FLAG_EMPTY


I have that kind of flag (actually a variable called duration) but I''m using SVGA graphics and the empty waterskin really looks empty (remember Dungeon Master?). Objects could have precalculated ''frame'' in a mask map, but I''m using one frame for item.
Advertisement
quote: Original post by paulkp
I have that kind of flag (actually a variable called duration) but I''m using SVGA graphics and the empty waterskin really looks empty (remember Dungeon Master?). Objects could have precalculated ''frame'' in a mask map, but I''m using one frame for item.


You could still do it like that, it just depends on how you draw your graphics. Quick eg :

BlitTile(x,y,(Tile^.Flags && OBJ_FLAG_FULL ? TILE_GRAPHIC_WATERSKIN_FULL : TILE_GRAPHIC_WATERSKIN_EMPTY));

Or something ...

quote: Original post by C-Junkie
If you embed a gem of light on a staff


So in this case the objects are made to be more granular? [ie. gem of light, gem of fire, MOUNT staff , MOUNT ring] and you have certain things that they can be combined with. ie. mountable objects. [a bit like the materia in Final Fantasy 7].

This would be one way, by putting more combinable objects into the game which can be done in different combinations.

So

twig + binding materials + axe blade = axe.

(long) twig + binding materials + spear head = spear
quote: Original post by Ketchaval

twig + binding materials + axe blade = axe.

(long) twig + binding materials + spear head = spear

How about having something like (very simplified, don''t try this at home) :

  Ingredients[ITEM_SPEAR] = ITEM_BRANCH | ITEM_BINDER | ITEM_SPEARHEAD; ...if Player->Inventory->Contains(Ingredients[ITEM_SPEAR]) {  Player->Inventory->Remove(Ingredients[ITEM_SPEAR];  Player->Inventory->Add(ITEM_SPEAR);};  


This is pretty trivial, really. A simple way is to just store some sort of Combination Table somewhere. It just maps components to composite items. Whenever the player tries to combine some items, search down the list of composites and try to find a match for all the components. If you find a match for that combination, the other side of the table can give the resulting item. So you then nuke the original items and invoke the new one in their place.

Example, assuming combinations always involve making 2 items into 1:
Original Item 1    Original Item 2     Result----------------------------------------------Hilt               Blade               SwordBranch             Spearhead           Spear 

You'd probably use Object type numbers rather than names, obviously.

Maybe you could use 3 components instead of 2, which is simple enough. If you could need a lot more than that, you can use a list of component numbers, which would be easy using the STL in C++ or a collection in Visual Basic.

Edited by - Kylotan on March 20, 2001 1:43:41 PM

This topic is closed to new replies.

Advertisement