• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

TFS 1.X+ Storing item attributes system

Itutorial

Legendary OT User
Joined
Dec 23, 2014
Messages
2,336
Solutions
68
Reaction score
1,018
I am looking at the item attributes system. It seems we have to store values based on bit shift operations which obviously limits the amount of attributes that can be defined. Can someone who knows explain why this is and how the system works?
 
TFS item attributes system

C++:
enum itemAttrTypes : uint32_t {
    ITEM_ATTRIBUTE_NONE,

    ITEM_ATTRIBUTE_ACTIONID = 1 << 0,
    ITEM_ATTRIBUTE_UNIQUEID = 1 << 1,
    ITEM_ATTRIBUTE_DESCRIPTION = 1 << 2,
    ITEM_ATTRIBUTE_TEXT = 1 << 3,
    ITEM_ATTRIBUTE_DATE = 1 << 4,
    ITEM_ATTRIBUTE_WRITER = 1 << 5,
    ITEM_ATTRIBUTE_NAME = 1 << 6,
    ITEM_ATTRIBUTE_ARTICLE = 1 << 7,
    ITEM_ATTRIBUTE_PLURALNAME = 1 << 8,
    ITEM_ATTRIBUTE_WEIGHT = 1 << 9,
    ITEM_ATTRIBUTE_ATTACK = 1 << 10,

    ITEM_ATTRIBUTE_ARMOR = 1 << 11,
    ITEM_ATTRIBUTE_DEFENSE = 1 << 12,
    ITEM_ATTRIBUTE_EXTRADEFENSE = 1 << 13,
    ITEM_ATTRIBUTE_HITCHANCE = 1 << 14,
    ITEM_ATTRIBUTE_SHOOTRANGE = 1 << 15,
    ITEM_ATTRIBUTE_OWNER = 1 << 16,
    ITEM_ATTRIBUTE_DURATION = 1 << 17,
    ITEM_ATTRIBUTE_DECAYSTATE = 1 << 18,
    ITEM_ATTRIBUTE_CORPSEOWNER = 1 << 19,
    ITEM_ATTRIBUTE_CHARGES = 1 << 20,
    ITEM_ATTRIBUTE_FLUIDTYPE = 1 << 21,
    ITEM_ATTRIBUTE_DOORID = 1 << 22,
    ITEM_ATTRIBUTE_DECAYTO = 1 << 23,
    ITEM_ATTRIBUTE_WRAPID = 1 << 24,
    ITEM_ATTRIBUTE_STOREITEM = 1 << 25,
    ITEM_ATTRIBUTE_ATTACK_SPEED = 1 << 26,

    ITEM_ATTRIBUTE_CUSTOM = 1U << 27
};
 
I'd say its just to easily check with 1 value 32 attributes of an item. It's not about checking the value of something. Its about checking wether an item has it at all. If it does then this enum doesnt really matter anymore and values are checked other way.
C++:
        bool hasAttribute(itemAttrTypes type) const {
            return (type & attributeBits) != 0;
        }

Condition system is written in the same manner.
If I didn't have enough bits for new conditions that I added, I'd just have another value (+32 conditions/item attributes etc. whatever).
 
The only reason for these to be flags is, because their type is checked with bitwise operators (it's fast). I got rid of that for a hashmap (probably slower) though, so no longer a limit.
 
The only reason for these to be flags is, because their type is checked with bitwise operators (it's fast). I got rid of that for a hashmap (probably slower) though, so no longer a limit.
That is what I was thinking about doing but I didn't know if it would create problems with RME or whatever
 
Back
Top