Install Steam
login
|
language
简体中文 (Simplified Chinese)
繁體中文 (Traditional Chinese)
日本語 (Japanese)
한국어 (Korean)
ไทย (Thai)
Български (Bulgarian)
Čeština (Czech)
Dansk (Danish)
Deutsch (German)
Español - España (Spanish - Spain)
Español - Latinoamérica (Spanish - Latin America)
Ελληνικά (Greek)
Français (French)
Italiano (Italian)
Bahasa Indonesia (Indonesian)
Magyar (Hungarian)
Nederlands (Dutch)
Norsk (Norwegian)
Polski (Polish)
Português (Portuguese - Portugal)
Português - Brasil (Portuguese - Brazil)
Română (Romanian)
Русский (Russian)
Suomi (Finnish)
Svenska (Swedish)
Türkçe (Turkish)
Tiếng Việt (Vietnamese)
Українська (Ukrainian)
Report a translation problem
int iType=GetBaseItemType(oItem);
string sSlot=Get2DAString("baseitems", "EquipableSlots", iType);
sSlot will be a hex-string representation of a bit field that contains the various item slots the item can be equipped in. For more information see: http://nwn.wikia.com/wiki/Baseitems.2da
This will address the problem of custom content, but 2da lookups are horribly inefficient (going from running conditionals to searching through an ASCII file), and I don't see any functions for converting a hex-string to a integer so you can use bitwise operations. Although it shouldn't be too hard to write your own.
The switch should be faster, even if it is horrible to look at, don't forget you can use fall through to write it a bit quicker eg.
...
case BASE_ITEM_LARGESHIELD:
case BASE_ITEM_SMALLSHIELD:
case BASE_ITEM_TOWERSHIELD:
iSlot=INVENTORY_SLOT_LEFTHAND;
break;
...
Even though it's an old compiler it should convert the switch to a hash table.
I always avoid using Get2daString because disk reads are comparitively slow.
Looks like I'm stuck with a long switch, then.
To my understanding (whihch may not be up to date or accurate) values are not hashed, they are direct binary comparisons.
There was a big a debate years ago on the Bioware forums about whether switches were any better than if/else if statements (other than readability), someone actually did a test and it turned out that switches do execute faster, so it appears that there is some hashing or extra optimization is involved.
Anyway it's not like it matters on a modern opimizing compiler. It will handle either implementation the same and use the most efficient implementation. Actually switch has fallen out of vogue and is considered bad coding practice from a "readable code" perspective. I suppose it's because most languages have an if/else statement but don't have a switch statement.