| 114 | |
| 115 | |
| 116 | AString Desolve(short a_ItemType, short a_ItemDamage) |
| 117 | { |
| 118 | // First try an exact match, both ItemType and ItemDamage ("birchplanks=5:2"): |
| 119 | for (ItemMap::iterator itr = m_Map.begin(), end = m_Map.end(); itr != end; ++itr) |
| 120 | { |
| 121 | if ((itr->second.first == a_ItemType) && (itr->second.second == a_ItemDamage)) |
| 122 | { |
| 123 | return itr->first; |
| 124 | } |
| 125 | } // for itr - m_Map[] |
| 126 | |
| 127 | // There is no exact match, try matching ItemType only ("planks=5"): |
| 128 | if (a_ItemDamage == 0) |
| 129 | { |
| 130 | for (ItemMap::iterator itr = m_Map.begin(), end = m_Map.end(); itr != end; ++itr) |
| 131 | { |
| 132 | if ((itr->second.first == a_ItemType) && (itr->second.second == -1)) |
| 133 | { |
| 134 | return itr->first; |
| 135 | } |
| 136 | } // for itr - m_Map[] |
| 137 | } |
| 138 | |
| 139 | // No match at all, synthesize a string ("5:1"): |
| 140 | AString res; |
| 141 | if (a_ItemDamage == -1) |
| 142 | { |
| 143 | Printf(res, "%d", a_ItemType); |
| 144 | } |
| 145 | else |
| 146 | { |
| 147 | Printf(res, "%d:%d", a_ItemType, a_ItemDamage); |
| 148 | } |
| 149 | return res; |
| 150 | } |
| 151 | |
| 152 | |
| 153 | protected: |
no test coverage detected