UltimaHacks icon indicating copy to clipboard operation
UltimaHacks copied to clipboard

[Feature Request] Allow more than 10 item combinations (UW1, perhaps UW2)

Open KarlClinckspoor opened this issue 2 years ago • 13 comments

I've been doing tests of CMB.DAT, which controls what happens when you combine (drag and drop one item on top of another). My plan was to add several more combinations and allow for more flexibility and varied playstyles. I've been able to add combinations, but it seems the game ignores everything past entry 10, much to my dismay. I thought what controlled the end of CMB.DAT, and the total number of combinations, was the final entry of six bytes of 0, per uw-formats.txt, but my tests indicate the limit is hardcoded in the engine. I've tested this with GOG's exe and your mouselook patch and both work the same. I didn't test UW2 yet because my project so far has focused on UW1, but I imagine this limitation might exist in it too.

I would be very grateful if you could look into this and add the ability of more combinations to your hacks.

If you want to test, I've created three CMB.DAT files. CMB.DATs.zip All items are found right in the beginning of the game, and the hand axe is just down the corridor into a side room with some skulls and a bowl.

  • CMB.DAT_AppleSword has two new combinations. "Apple*+Lit torch = debris" and "HandAxe*+Dagger*=Black Sword". Asterisks indicate items that are destroyed after the combination. Due to the aforementioned limitation, axe+dagger doesn't work.
  • CMB.DAT_SwordApple has the same combinations but in the inverse order. Axe+dagger work, but not apple+lit torch.
  • CMB.DAT_AllNew has only three combinations. The two ones above, plus "apple+fish=fireball". The three work, but no other traditional combination (e.g. corn+lit torch = popcorn)

Thank you for your time,

KarlClinckspoor avatar Sep 05 '22 16:09 KarlClinckspoor

wow. your project definitely seems like a cool idea and this is something i will look into.. not sure when i'll get the time to, though : /

do you have a rough idea of how many total combinations you'd need?

also, is the system of specifying combinations powerful and flexible enough, or have you run into any other limits on what it allows you to do?

JohnGlassmyer avatar Sep 05 '22 16:09 JohnGlassmyer

wow. your project definitely seems like a cool idea and this is something i will look into.. not sure when i'll get the time to, though : /

Thank you so much! No worries about time.

do you have a rough idea of how many total combinations you'd need?

Well IDK... I have about 40 new combinations mapped out at this moment. I was thinking of an upper limit of 255 combinations, I guess that'll be quite future-proof. Famous last words though.

also, is the system of specifying combinations powerful and flexible enough, or have you run into any other limits on what it allows you to do?

These are the limitations I've encountered so far:

  • At least one item has to be destroyed. If one or both aren't flagged, no combination happens. I think that's fair, otherwise you would create an item out of nothing, potentially infinitely.
  • Matches are solely dependent on itemID. This means the condition/quantity and other characteristics can't be specified. Weapons are always created in "excellent" condition, which I guess is the default state. I guess the same applies to general items and food quality, but I haven't tested yet. You can't combine a cudgel and a gold crown and create several golden nuggets, only 1. Also, I haven't tested but I'm quite sure that item enchantments would be lost, as the item created is "new", so you can't replicate that old exploit of debris having the same enchantment as a scroll, but with infinite reuse.
  • One limitation, which is outside the scope of item combinations, is that you can't place certain items in your inventory, like some pieces of debris, or a fireball. I think the implications of modifying this would be far reaching (player able to pick up npcs, benches, shrines?), so I think this should be left intact.

There's bits left in each value (it's a short for each item, 3 shorts per combination). 1 bit for "destroy" flag, 9 bits for item ID, 6 bits that are unused. This isn't enough to fully specify an item (static). However, if it's not too hard, these 6 bits could be used to specify the quantity and/or the quality. With this, I would be able to create more advanced and specific recipes. For example, I could create a jury-rigging repair system, where you can combine two pieces of similar armor, for example, and repair one, destroying the other in the process. This could open a whole can of worms though, as both these object properties don't always mean exactly "quantity" and "quality", but that would be left to the recipe creator, not the player. Also, adding this would potentially increase the total number of combinations I would like to add.

Anyway, I'm fine with the system as it is. And any modifications to it would be just a bonus, but a hugely cool bonus.

Thanks again, and I look forward to seeing your work.

KarlClinckspoor avatar Sep 05 '22 17:09 KarlClinckspoor

perhaps setting one of the 6 unused bits would indicate that the following entry contained additional info about this entry, eg about how to set quantity, quality, etc, and was not itself a combination. perhaps that following entry would then have to start with some number of zeros.

i would guess off the top of my head that quantity and quality are stored in the same bits or bytes of game data, with any item having either quality or quantity but not both, but i'm not sure.

do you have an idea as to whether or when you would compare the mechanics in UW2? perhaps there are additional complications in the sequel that should be taken into consideration first..

JohnGlassmyer avatar Sep 05 '22 17:09 JohnGlassmyer

also, what do you think of the idea of skill thresholds? perhaps one number to specify a skill and a second number to specify the minimum level of that skill the player must have in order to perform the combination. if the player doesn't have enough points in the skill, the combination fails with a message like "you are not skilled enough in Repair to use Leather Armor on Leather Armor" or whatever.

JohnGlassmyer avatar Sep 05 '22 19:09 JohnGlassmyer

do you have an idea as to whether or when you would compare the mechanics in UW2? perhaps there are additional complications in the sequel that should be taken into consideration first..

I've tested UW2 and this is what I found out:

  • The format is exactly the same as UW1. short+short=short.
  • There is a hard limit of 10 items too. In this case, the file doesn't have six consecutive 0s to denote it ended. Instead, its size is fixed. Empty entries are 0xFFFF. I replaced all empty slots with new combinations and all worked until the tenth. For posterity, here's the combinations present in UW2 (didn't know about the wafer one).

0: (216:0xD8)a_pole*+(300:0x12C)some_thread&pieces_of_thread*=(299:0x12B)a_fishing_pole 1: (300:0x12C)some_thread&pieces_of_thread*+(210:0xD2)a_lump_of_wax&lumps_of_wax*=(146:0x92)a_candle 2: (149:0x95)a_lit_torch+(180:0xB4)an_ear_of_corn&ears_of_corn*=(183:0xB7)some_popcorn&bunches_of_popcorn 3: (149:0x95)a_lit_torch+(186:0xBA)a_honeycomb*=(210:0xD2)a_lump_of_wax&lumps_of_wax 4: (191:0xBF)a_nutritious_wafer*+(188:0xBC)a_bottle_of_water&bottles_of_water*=(187:0xBB)a_bottle_of_ale&bottles_of_ale

  • Weapons and armor were created in the "servicable" state. I revisited UW1 and found out the same occurs, with the exception of the black sword, which I used to test. Same goes for armor. Sorry about that.

This means the handling of both games would need to be slightly different.

perhaps setting one of the 6 unused bits would indicate that the following entry contained additional info about this entry, eg about how to set quantity, quality, etc, and was not itself a combination. perhaps that following entry would then have to start with some number of zeros.

That's a good idea! This is getting exciting. Each bit could represent a flag. One meaning "specify quantity", another "specify quality", another meaning "skill threshold", another meaning "verbatim". And each flag would add a certain number of bytes after the initial identifier with the extra info. For example, 2 bytes for skill (1 specifies which, another the minimum, but I think we can shrink this to 1 byte if necessary), 1 byte for quantity, 1 byte for quality, 8 bytes for "verbatim". By verbatim I mean "generate an item with exactly this buffer" which could be useful to make specific potions, scrolls and magic weapons/armor. I think it's going to be too much to specify "verbatim" in the input ingredients. To preserve compatibility with the games, the first 10 entries could be always "normal" and the rest be with this new format.

Perhaps something like this:

D0QA_SV0I IIII_IIII

I is reserved for itemID, and the flags V is "verbatim", S is "skill", A is amount/quantity, Q is "quality". 0 is "unused".

Of course, it'll be up to you to decide the best way to implement, or not, all of this.

i would guess off the top of my head that quantity and quality are stored in the same bits or bytes of game data, with any item having either quality or quantity but not both, but i'm not sure.

I think quantity and quality can coexist, for example, I remember torches stacking when unburnt, but don't when used a bit. I'm going to copy over the relevant section in uw-formats.txt (wall of text incoming). It'll explain far better than me. The following is valid for static items (e.g. not npcs/enemies) although you can create mobile items by item combination. I even created the unused "an adventurer" npc. It was hostile but had no AI.

Each object entry has a "general object info" block consisting of 4 Int16 words. The 256 "mobile objects" are followed by 19 bytes "mobile object extra info", resulting in entries of 27 bytes length. The remaining 768 entries only have 8 bytes each. The "mobile object extra info" is described in chapter 4.2.3.

The "general object info" block looks as following:

   bits  size  field      description

    0000 objid / flags
         0- 8   9   "item_id"   Object ID (see below)
         9-12   4   "flags"     Flags
           12   1   "enchant"   Enchantment flag (enchantable objects only)
           13   1   "doordir"   Direction flag (doors)
           14   1   "invis"     Invisible flag (don't draw this object)
           15   1   "is_quant"  Quantity flag (link field is quantity/special)
         OR
         9-15       texture number

Note: some objects don't have flags and use the whole lower byte as a texture number (gravestone, picture, lever, switch, shelf, bridge, ..)

    0002 position
         0- 6   7   "zpos"      Object Z position (0-127)
         7- 9   3   "heading"   Heading (*45 deg)
        10-12   3   "ypos"      Object Y position (0-7)
        13-15   3   "xpos"      Object X position (0-7)

    0004 quality / chain
         0- 5   6   "quality"   Quality
         6-15   10  "next"      Index of next object in chain

    0006 link / special
         0- 5   6   "owner"     Owner / special
         6-15   10  (*)         Quantity / special link / special property

All field names listed are used later to refer to these fields in the object's information words.

Object IDs can be split up for classification purposes. Read more in chapter 6 about it.

Objects in a tile are stored as a linked list, where the "Index of next object in chain" points to the next object in list, or contains 0 for the end of the linked list. The first object in the list is determined by the tile's object index value (see above, at "Tile map").

(*) The "Quantity" field in word 0006 can have several meanings. If the "is_quant" field is 0 (unset), it contains the index of an associated object. The exact meaning varies, but is generally a "has-a" type relationship (contents, trap to set off, spell). The field name "sp_link" is used in this document if that type of field is meant.

If the "is_quant" flag is set, the field is a quantity or a special property. If the value is < 512 or 0x0200 it gives the number of stacked items present. Identical objects may be stacked up to 256 objects at a time. The field name "quantity" is used for this.

If the value is > 512, the value minus 512 is a special property; the object type defines the further meaning of this value (see chapter 6.1 for all special objects in Ultima Underworld). The field name "property" is used for this type of value.

KarlClinckspoor avatar Sep 05 '22 23:09 KarlClinckspoor

well, if and then i get around to this, i'll first add support for more than 10 combinations, and then i guess we can see what would be useful in terms of more sophisticated combinations.

could allow a second extension entry, also starting with 00 00, extending the main entry by a further 4 bytes or so, if needed.

being able to create NPCs with this, together with thresholding on skill level, could open up a new form of Conjuration or Necromancy magic.. but maybe that's a little far-fetched.

JohnGlassmyer avatar Sep 06 '22 00:09 JohnGlassmyer

a few thoughts.

  • occurred to me that there is also the script ("usecode" in Ultima VII, i don't remember what it's called in Underworld) that runs when you Use an item. some things might make more sense to implement by adding Use functionality to the game's scripting, rather than adding them as item combinations. i haven't yet put much thought into where this line might tend to fall.

  • might make sense to add one or more new "Crafting" skills, various levels of which item combinations would require, to allow the player to unlock more combinations to play with and use as they proceed through the game. i haven't looked to see how difficult it might be to add a new skill.

  • visually highlighting items in inventory with which the dragged item might be combined could be useful.

JohnGlassmyer avatar Sep 08 '22 23:09 JohnGlassmyer

might make sense to add one or more new "Crafting" skills, various levels of which item combinations would require, to allow the player to unlock more combinations to play with and use as they proceed through the game. i haven't looked to see how difficult it might be to add a new skill.

What I think this might require:

  • Adapt the character generation tables to include these skills. If I ever get to this in my Randomizer, I might have this covered.
  • Modify the UI (char gen and char attribute) to show them.
  • Add mantras (UW1) and trainers (UW2) to develop those skills

One might combine Repair with a character tree skill to represent some things. For example, Missile to craft ranged weapons/ammo, Lore for potions, Casting for enchantments.

occurred to me that there is also the script ("usecode" in Ultima VII, i don't remember what it's called in Underworld) that runs when you Use an item. some things might make more sense to implement by adding Use functionality to the game's scripting, rather than adding them as item combinations. i haven't yet put much thought into where this line might tend to fall.

visually highlighting items in inventory with which the dragged item might be combined could be useful.

Both are cool ideas. I was surprised that oil flask + wood, or oil flask + lantern are "Use" actions rather than combinations, so this idea is already in the game. Downsides of Combine are that you might inadvertently combining two items while simply reorganizing your inventory, you can't combine with stuff on the Overworld and, at the moment, it's very simplistic. On the other hand, the downsides of "Use" are that some items are immediately activated (scrolls, weapons) when Using, combinations probably won't be "commutative", and new "Uses" will probably be hardcoded. This diminishes the possibility of more mods. But I think you can "Use" with stuff on the overworld (e.g. key on doors), which opens up more possibilities.

KarlClinckspoor avatar Sep 09 '22 00:09 KarlClinckspoor

Missile to craft ranged weapons/ammo

Missile was pretty useless in the original game, wasn't it? i know i've seen advice online strongly recommending against putting points into it.

maybe being able to quickly switch (with a keypress) between missile and melee weapon would help. for that matter, numeric hotkeys to quickly switch weapons, maybe even a hotbar on screen. so many ideas..

can you think of any ways to make Missile more useful?

JohnGlassmyer avatar Sep 09 '22 00:09 JohnGlassmyer

Indeed, Missile has always been looked down and it is partly my wish to make it more relevant. Several of the recipes I thought of had to do with creating missiles or missile weapons. Why I think Missile is bad at the moment:

  • It's rare, compared to other weapons. There's like 3 of each (sling, bow, crossbow) in the entire game (UW1). You're probably going to need to use some other weapon before finding a decent ranged weapon. There's only 1 enchanted crossbow in UW1, level 8, and 1 jeweled bow, also in level 8. That's way too late. There's several better jeweled and enchanted weapons before that. There's a battle axe in Lvl2, jeweled swords and maces on lvl 4. The first crossbow is found in lvl3.
  • I don't know how ranged weapon if the weapon enchantment affects the missile damage, so that enchanted crossbow of unsurpassed damage might just be equivalent to a normal one. In the UW2 cluebook, missile damage is a property of the projectile, isn't even affected by draw time, and the average damage itself is very poor, with bolts being comparable to mid-tier weapons.
  • Bolts and arrows are very difficult to find on the ground because they're 3D objects. IIRC, arrows blend pretty well with dirt floors and bolts on stone floors. Makes it hard to find them when exploring and makes it annoying to collect them after a fight. Also, makes me nervous about reaching the 730ish static object limit.
  • You're likely to fight enemies in locations that would result in losing your ammo. Lurkers and fire elementals for example. So a pure ranged character might simply have to ignore them.
  • It's dark, so you're likely firing into the darkness more often than not.

Here's how I would perhaps address these limitations:

  • Modify lev.ark to include more ranged weapons, and add some enchantments to them. Perhaps change the starting bag to match the player's class. Add more ammo throughout. Those are all ideas I'm considering in the Randomizer. I was dreaming about adding new items and though about lead shot (+damage), poison tipped arrows, bolts that ignore armor, but that's a bit far fetched.
  • Assure enchantments actually work as expected, and buff ranged weapon damage (I think that can be done my modifying the common object properties).
  • Modify the color of bolts and arrows to make them stick out more. It would be cool if an autopickup feature was available for missiles. I know it already exists because of that pacman easter egg in UW1.
  • Don't know how to fix the issue with enemies in water/lava.
  • The darkness aspect could perhaps be addressed by increasing the light potency, which I know there's a mod that does just that. But it's so inherent to UW that I would leave that alone.

Having a hotkey to switch between weapons would be interesting. Perhaps the object slot on top of the weapon slot could be used as a secondary hand slot, and a key press would switch the items between the two. Would definitely make it less cumbersome to shoot a few arrows and switch to a melee weapon when it comes near.

KarlClinckspoor avatar Sep 09 '22 11:09 KarlClinckspoor

you know, in (Zelda) Breath of the Wild there's a mechanic where if you draw your bow while in mid-air (after jumping off of something), time slows down, giving you more time to aim at things while falling. maybe i could implement a similar mechanic in Underworld. without requiring being in mid-air. maybe make it optional. maybe increasing skill in Missile would increase the length of time you could slow while drawing the weapon..

JohnGlassmyer avatar Sep 09 '22 15:09 JohnGlassmyer

could have a magic quiver that creates each arrow out of Mana, rather than consuming physical ones.

ed: or a bow enchantment that returns projectiles (some of the time?)

JohnGlassmyer avatar Sep 09 '22 17:09 JohnGlassmyer

Breath of the Wild also has Bomb Arrows, which explode on impact and might be fun to use against masses of enemies. perhaps i could add a knockback effect to throw enemies from the point of the explosion. (perhaps i could also add an Explosion spell to both Underworld games that does likewise.)

also particular types of arrows - Ice, Fire, Shock, Ancient - which might be useful against different elemental enemies.

these could all have unique crafting recipes.

JohnGlassmyer avatar Sep 15 '22 17:09 JohnGlassmyer