Tuesday, March 1, 2011
Crimmor: Hidden Weaponry
Hidden weapons: If you played Assassin's Creed you'll know what I mean. The player has instant access to a weapon that the npc's do not see, like the Assassin's Creed pc had the daggers that popped out.
In the first picture you can see the hidden weapon system in action. Our intrepid thief has picked up a hidden weapon, equipped and been caught pickpocketing. The weapon is visible to the player, but the npc simply does not "see" the weapon. Our player only takes the standard reputation penalty of -20, as if he was unarmed.
Then he picks up a spear, equips it, and tries again. Caught this time, the npc can "see" the weapon, and so thinks they are getting mugged. As a result, the player takes the -20 rep penalty for pickpocketing, and an extra -20 for using a weapon! What about dual wielding? The system catches that too. It doesn't identify two visible weapons as more threatening than one (I don't think it should), but if you have a hidden weapon in your main hand, and a visible one in the left, the npc sees the weapon in the left hand. So no tricking the system.
In addition to the custom hidden weaponry, some weapon types are always considered to be hidden, as they are designed to be hidden on the body for surprise use anyway, or unanticipated weapons. So darts and shuriken are "hidden", and unarmed and torches also qualify since they are unexpected.
The same weapon detection code is going to run when you talk to npc's. They will not be friendly if you're pointing a weapon they can see at them, in fact you will lose a few points of reputation with them, Crimmor is civilized!
The system relies on detecting substrings of weapon tags and item types, and comparing the substring with the predefined prefix for the tags for all hidden weaponry then comparing the weapon type for the weapon types that are "hideable by definition" like shuriken. So for me, the code detects if the tag begins "sh_hidden_", the remainder of the tag does not matter.
I had to get this code down and set, as substring detection forms the basis not only of weapon detection, but several other system things I'm putting in place such as clothing with hidden pockets.