Mercurial > mm7
comparison Items.cpp @ 2286:288e0b29a493
some cleanups in ItemsTable::GenerateItem
author | Grumpy7 |
---|---|
date | Sat, 15 Mar 2014 19:53:14 +0100 |
parents | 4fd03103be62 |
children | 4e3236a4ea63 |
comparison
equal
deleted
inserted
replaced
2285:4fd03103be62 | 2286:288e0b29a493 |
---|---|
976 } | 976 } |
977 | 977 |
978 | 978 |
979 //----- (00456620) -------------------------------------------------------- | 979 //----- (00456620) -------------------------------------------------------- |
980 void ItemsTable::GenerateItem(int treasure_level, unsigned int uTreasureType, ItemGen *out_item) | 980 void ItemsTable::GenerateItem(int treasure_level, unsigned int uTreasureType, ItemGen *out_item) |
981 { | 981 { |
982 | 982 int treasureLevelMinus1; // ebx@3 |
983 ItemsTable *v5; // edi@1 | |
984 int v6; // ebx@3 | |
985 //int *v7; // ecx@33 | |
986 //int v8; // eax@34 | |
987 //int v9; // eax@39 | |
988 int current_chance; // ebx@43 | 983 int current_chance; // ebx@43 |
989 int tmp_chance; // ecx@47 | 984 int tmp_chance; // ecx@47 |
990 int v17; // ebx@57 | 985 int v17; // ebx@57 |
991 int v18; // edx@62 | 986 int v18; // edx@62 |
992 unsigned int special_chance; // edx@86 | 987 unsigned int special_chance; // edx@86 |
998 int v45; // eax@120 | 993 int v45; // eax@120 |
999 int v46; // edx@120 | 994 int v46; // edx@120 |
1000 int j; // eax@121 | 995 int j; // eax@121 |
1001 int val_list[800]; // [sp+Ch] [bp-C88h]@33 | 996 int val_list[800]; // [sp+Ch] [bp-C88h]@33 |
1002 int total_chance; // [sp+C8Ch] [bp-8h]@33 | 997 int total_chance; // [sp+C8Ch] [bp-8h]@33 |
1003 int v54; // [sp+C9Ch] [bp+8h]@3 | |
1004 //int v55; // [sp+CA0h] [bp+Ch]@34 | |
1005 signed int v56; // [sp+CA0h] [bp+Ch]@55 | 998 signed int v56; // [sp+CA0h] [bp+Ch]@55 |
1006 int v57; // [sp+CA0h] [bp+Ch]@62 | 999 int v57; // [sp+CA0h] [bp+Ch]@62 |
1007 | 1000 |
1008 v5 = this; | |
1009 if (!out_item) | 1001 if (!out_item) |
1010 out_item = (ItemGen *)malloc(sizeof(ItemGen)); | 1002 out_item = (ItemGen *)malloc(sizeof(ItemGen)); |
1011 memset(out_item, 0, sizeof(*out_item)); | 1003 memset(out_item, 0, sizeof(*out_item)); |
1012 | 1004 |
1013 | 1005 |
1014 v6 = treasure_level - 1; | 1006 treasureLevelMinus1 = treasure_level - 1; |
1015 v54 = treasure_level - 1; | |
1016 if ( uTreasureType ) //generate known treasure type | 1007 if ( uTreasureType ) //generate known treasure type |
1017 { | 1008 { |
1018 ITEM_EQUIP_TYPE requested_equip; | 1009 ITEM_EQUIP_TYPE requested_equip; |
1019 PLAYER_SKILL_TYPE requested_skill = PLAYER_SKILL_INVALID; | 1010 PLAYER_SKILL_TYPE requested_skill = PLAYER_SKILL_INVALID; |
1020 switch (uTreasureType) | 1011 switch (uTreasureType) |
1021 { | 1012 { |
1022 case 20: requested_equip = EQUIP_SINGLE_HANDED; break; | 1013 case 20: requested_equip = EQUIP_SINGLE_HANDED; break; |
1080 } | 1071 } |
1081 } | 1072 } |
1082 | 1073 |
1083 current_chance = 0; | 1074 current_chance = 0; |
1084 if ( total_chance ) | 1075 if ( total_chance ) |
1085 current_chance = rand() % total_chance; | 1076 { |
1086 | 1077 current_chance = rand() % total_chance + 1; |
1087 out_item->uItemID = val_list[0]; | 1078 tmp_chance = 0; |
1088 if (!out_item->uItemID) | 1079 j=0; |
1089 out_item->uItemID = 1; | 1080 while(tmp_chance < current_chance) |
1090 | 1081 { |
1091 if ( pItems[out_item->uItemID].uChanceByTreasureLvl[treasure_level - 1] < current_chance ) | 1082 out_item->uItemID = val_list[j]; |
1092 { | 1083 tmp_chance += pItems[val_list[j]].uChanceByTreasureLvl[treasure_level - 1]; |
1093 j=0; | 1084 ++j; |
1094 tmp_chance=pItems[out_item->uItemID].uChanceByTreasureLvl[treasure_level - 1]; | 1085 } |
1095 do | |
1096 { | |
1097 ++j; | |
1098 out_item->uItemID = val_list[j]; | |
1099 tmp_chance += pItems[val_list[j]].uChanceByTreasureLvl[treasure_level - 1]; | |
1100 } | |
1101 while ( tmp_chance < current_chance ); | |
1102 } | |
1103 | |
1104 if (out_item->GetItemEquipType() == EQUIP_POTION && out_item->uItemID != ITEM_POTION_BOTTLE ) | |
1105 {// if it potion set potion spec | |
1106 out_item->uEnchantmentType = 0; | |
1107 for (int i=0; i<2; ++i) | |
1108 out_item->uEnchantmentType += rand() % 4 + 1; | |
1109 out_item->uEnchantmentType = out_item->uEnchantmentType * treasure_level; | |
1110 } | |
1111 } | 1086 } |
1087 else | |
1088 { | |
1089 out_item->uItemID = 1; | |
1090 } | |
1091 } | |
1112 else | 1092 else |
1093 { | |
1094 //artifact | |
1095 if ( treasureLevelMinus1 == 5 ) | |
1113 { | 1096 { |
1114 //artifact | 1097 v56 = 0; |
1115 v56 = 0; | 1098 for(int i=0; i<29; ++i) |
1116 for(int i=0; i<29; ++i) | |
1117 v56 += pParty->pIsArtifactFound[i]; | 1099 v56 += pParty->pIsArtifactFound[i]; |
1118 | 1100 v17 = rand() % 29; |
1119 v17 = rand() % 29; | 1101 if ((rand() % 100 < 5) && !pParty->pIsArtifactFound[v17] && v56 < 13) |
1120 | 1102 { |
1121 if ( v6 == 5 && (rand() % 100 < 5) && !pParty->pIsArtifactFound[v17] && v56 < 13 ) | |
1122 { | |
1123 pParty->pIsArtifactFound[v17] = 1; | 1103 pParty->pIsArtifactFound[v17] = 1; |
1124 out_item->uAttributes = 0; | 1104 out_item->uAttributes = 0; |
1125 out_item->uItemID = v17 + 500; | 1105 out_item->uItemID = v17 + 500; |
1126 SetSpecialBonus(out_item); | 1106 SetSpecialBonus(out_item); |
1127 return; | 1107 return; |
1128 } | 1108 } |
1129 | 1109 } |
1110 | |
1130 v57 = 0; | 1111 v57 = 0; |
1131 v18 = rand() % v5->uChanceByTreasureLvlSumm[treasure_level - 1]; | 1112 v18 = rand() % this->uChanceByTreasureLvlSumm[treasure_level - 1] + 1; |
1132 out_item->uItemID = 0; | 1113 while (v57 < v18) |
1133 if ( v18 > 0 ) | 1114 { |
1134 { | 1115 ++out_item->uItemID; |
1135 do | 1116 v57 += pItems[out_item->uItemID].uChanceByTreasureLvl[treasureLevelMinus1]; |
1136 { | |
1137 v57 += pItems[out_item->uItemID + 1].uChanceByTreasureLvl[v6]; | |
1138 ++out_item->uItemID; | |
1139 } | |
1140 while ( v57 < v18 ); | |
1141 } | |
1142 | |
1143 if ( !v18 ) | |
1144 out_item->uItemID = 1; | |
1145 if ( !out_item->uItemID ) | |
1146 out_item->uItemID = 1; | |
1147 if (out_item->GetItemEquipType() == EQUIP_POTION && out_item->uItemID != ITEM_POTION_BOTTLE ) | |
1148 {// if it potion set potion spec | |
1149 out_item->uEnchantmentType = 0; | |
1150 for (int i=0; i<2; ++i) | |
1151 out_item->uEnchantmentType += rand() % 4 + 1; | |
1152 out_item->uEnchantmentType = out_item->uEnchantmentType * treasure_level; | |
1153 } | |
1154 out_item->uEnchantmentType = out_item->uEnchantmentType * treasure_level; | |
1155 } | 1117 } |
1118 } | |
1119 if (out_item->GetItemEquipType() == EQUIP_POTION && out_item->uItemID != ITEM_POTION_BOTTLE ) | |
1120 {// if it potion set potion spec | |
1121 out_item->uEnchantmentType = 0; | |
1122 for (int i=0; i<2; ++i) | |
1123 out_item->uEnchantmentType += rand() % 4 + 1; | |
1124 out_item->uEnchantmentType = out_item->uEnchantmentType * treasure_level; | |
1125 } | |
1156 | 1126 |
1157 if ( out_item->uItemID == ITEM_SPELLBOOK_LIGHT_DIVINE_INTERVENTION | 1127 if ( out_item->uItemID == ITEM_SPELLBOOK_LIGHT_DIVINE_INTERVENTION |
1158 && !(unsigned __int16)_449B57_test_bit(pParty->_quest_bits, 239) ) | 1128 && !(unsigned __int16)_449B57_test_bit(pParty->_quest_bits, 239) ) |
1159 out_item->uItemID = ITEM_SPELLBOOK_LIGHT_SUN_BURST; | 1129 out_item->uItemID = ITEM_SPELLBOOK_LIGHT_SUN_BURST; |
1160 if ( pItemsTable->pItems[out_item->uItemID + 1].uItemID_Rep_St ) | 1130 if ( pItemsTable->pItems[out_item->uItemID].uItemID_Rep_St ) |
1161 out_item->uAttributes = 0; | 1131 out_item->uAttributes = 0; |
1162 else | 1132 else |
1163 out_item->uAttributes = 1; | 1133 out_item->uAttributes = 1; |
1164 | 1134 |
1165 if ( out_item->GetItemEquipType() != EQUIP_POTION ) | 1135 if ( out_item->GetItemEquipType() != EQUIP_POTION ) |
1171 switch (out_item->GetItemEquipType()) | 1141 switch (out_item->GetItemEquipType()) |
1172 { | 1142 { |
1173 case EQUIP_SINGLE_HANDED: | 1143 case EQUIP_SINGLE_HANDED: |
1174 case EQUIP_TWO_HANDED : | 1144 case EQUIP_TWO_HANDED : |
1175 case EQUIP_BOW : | 1145 case EQUIP_BOW : |
1176 if ( !uBonusChanceWpSpecial[v6] ) | 1146 if ( !uBonusChanceWpSpecial[treasureLevelMinus1] ) |
1177 return; | 1147 return; |
1178 if ((uint)(rand() % 100)>=uBonusChanceWpSpecial[v6]) | 1148 if ((uint)(rand() % 100)>=uBonusChanceWpSpecial[treasureLevelMinus1]) |
1179 return; | 1149 return; |
1180 break; | 1150 break; |
1181 case EQUIP_ARMOUR : | 1151 case EQUIP_ARMOUR : |
1182 case EQUIP_SHIELD : | 1152 case EQUIP_SHIELD : |
1183 case EQUIP_HELMET : | 1153 case EQUIP_HELMET : |
1185 case EQUIP_CLOAK : | 1155 case EQUIP_CLOAK : |
1186 case EQUIP_GAUNTLETS : | 1156 case EQUIP_GAUNTLETS : |
1187 case EQUIP_BOOTS : | 1157 case EQUIP_BOOTS : |
1188 case EQUIP_RING : | 1158 case EQUIP_RING : |
1189 | 1159 |
1190 if ( !uBonusChanceStandart[v6] ) | 1160 if ( !uBonusChanceStandart[treasureLevelMinus1] ) |
1191 return; | 1161 return; |
1192 special_chance = rand() % 100; | 1162 special_chance = rand() % 100; |
1193 if ( special_chance < uBonusChanceStandart[v6]) | 1163 if ( special_chance < uBonusChanceStandart[treasureLevelMinus1]) |
1194 { | 1164 { |
1195 v26 = rand() %pEnchantmentsSumm[out_item->GetItemEquipType()-3]; | 1165 v26 = rand() %pEnchantmentsSumm[out_item->GetItemEquipType()-3] + 1; |
1196 out_item->uEnchantmentType = 0; | 1166 v27 = 0; |
1197 v27=pEnchantments[out_item->uEnchantmentType].to_item[out_item->GetItemEquipType()-3]; | 1167 while(v27 < v26) |
1198 if (v26>v27 ) | 1168 { |
1199 { | |
1200 do | |
1201 { | |
1202 ++out_item->uEnchantmentType; | 1169 ++out_item->uEnchantmentType; |
1203 v27+=pEnchantments[out_item->uEnchantmentType].to_item[out_item->GetItemEquipType()-3]; | 1170 v27+=pEnchantments[out_item->uEnchantmentType].to_item[out_item->GetItemEquipType()-3]; |
1204 } while (v26>v27); | 1171 } |
1205 } | 1172 |
1206 ++out_item->uEnchantmentType; | 1173 v33 = rand() % (bonus_ranges[treasureLevelMinus1].maxR - bonus_ranges[treasureLevelMinus1].minR + 1); |
1207 | 1174 out_item->m_enchantmentStrength = v33 + bonus_ranges[treasureLevelMinus1].minR; |
1208 v33 = rand() % (bonus_ranges[v6].maxR - bonus_ranges[v6].minR + 1); | |
1209 out_item->m_enchantmentStrength = v33 + bonus_ranges[v6].minR; | |
1210 v32 = out_item->uEnchantmentType - 1; | 1175 v32 = out_item->uEnchantmentType - 1; |
1211 if ( v32 == 21 || v32 == 22 || v32 == 23 ) //Armsmaster skill, Dodge skill, Unarmed skill | 1176 if ( v32 == 21 || v32 == 22 || v32 == 23 ) //Armsmaster skill, Dodge skill, Unarmed skill |
1212 out_item->m_enchantmentStrength = out_item->m_enchantmentStrength/2; | 1177 out_item->m_enchantmentStrength = out_item->m_enchantmentStrength/2; |
1213 if ( out_item->m_enchantmentStrength <= 0 ) | 1178 if ( out_item->m_enchantmentStrength <= 0 ) |
1214 out_item->m_enchantmentStrength = 1; | 1179 out_item->m_enchantmentStrength = 1; |
1215 return; | 1180 return; |
1216 | 1181 |
1217 } | 1182 } |
1218 if ( !uBonusChanceSpecial[v6]) | 1183 else if ( special_chance >= uBonusChanceStandart[treasureLevelMinus1] + uBonusChanceSpecial[treasureLevelMinus1] ) |
1219 return; | 1184 return; |
1220 v34 = uBonusChanceStandart[v6] + uBonusChanceSpecial[v6]; | |
1221 if ( special_chance>v34 ) | |
1222 return; | |
1223 break; | 1185 break; |
1224 case EQUIP_WAND: | 1186 case EQUIP_WAND: |
1225 out_item->uNumCharges = rand() % 6 + out_item->GetDamageMod() + 1; | 1187 out_item->uNumCharges = rand() % 6 + out_item->GetDamageMod() + 1; |
1226 out_item->uMaxCharges = out_item->uNumCharges; | 1188 out_item->uMaxCharges = out_item->uNumCharges; |
1189 return; | |
1227 default: | 1190 default: |
1228 return; | 1191 return; |
1229 } | 1192 } |
1230 | 1193 |
1231 j=0; | 1194 j=0; |
1232 int spc_sum=0; | 1195 int spc_sum=0; |
1233 int spc; | 1196 int spc; |
1234 memset(&val_list, 0, 3200); | 1197 memset(&val_list, 0, 3200); |
1235 for (unsigned int i=0; i<pSpecialEnchantments_count;++i) | 1198 for (unsigned int i=0; i<pSpecialEnchantments_count;++i) |
1199 { | |
1200 int tr_lv= pSpecialEnchantments[i].iTreasureLevel; | |
1201 if ((treasure_level - 1 == 2) && ( tr_lv == 1 || tr_lv == 0 ) || | |
1202 (treasure_level - 1 == 3) && (tr_lv == 2 || tr_lv == 1 || tr_lv == 0) || | |
1203 (treasure_level - 1 == 4) && (tr_lv == 3 || tr_lv == 2 || tr_lv == 1) || | |
1204 (treasure_level - 1 == 5) && (tr_lv == 3) | |
1205 ) | |
1206 { | |
1207 spc=pSpecialEnchantments[i].to_item_apply[out_item->GetItemEquipType()]; | |
1208 spc_sum+=spc; | |
1209 if(spc) | |
1236 { | 1210 { |
1237 int tr_lv= pSpecialEnchantments[i].iTreasureLevel; | 1211 val_list[j++]=i; |
1238 switch ( treasure_level - 1 ) | |
1239 { | |
1240 case 2: | |
1241 if ((tr_lv==1)||(tr_lv==0)) | |
1242 { | |
1243 spc=pSpecialEnchantments[i].to_item_apply[out_item->GetItemEquipType()]; | |
1244 spc_sum+=spc; | |
1245 if(spc) | |
1246 { | |
1247 val_list[j++]=i; | |
1248 } | |
1249 } | |
1250 break; | |
1251 case 3: | |
1252 if ((tr_lv==2)||(tr_lv==1)||(tr_lv==0)) | |
1253 { | |
1254 spc=pSpecialEnchantments[i].to_item_apply[out_item->GetItemEquipType()]; | |
1255 spc_sum+=spc; | |
1256 if(spc) | |
1257 { | |
1258 val_list[j++]=i; | |
1259 } | |
1260 } | |
1261 break; | |
1262 case 4: | |
1263 if ((tr_lv==3)||(tr_lv==2)||(tr_lv==1)) | |
1264 { | |
1265 spc=pSpecialEnchantments[i].to_item_apply[out_item->GetItemEquipType()]; | |
1266 spc_sum+=spc; | |
1267 if(spc) | |
1268 { | |
1269 val_list[j++]=i; | |
1270 } | |
1271 } | |
1272 break; | |
1273 case 5: | |
1274 if (tr_lv==3) | |
1275 { | |
1276 spc=pSpecialEnchantments[i].to_item_apply[out_item->GetItemEquipType()]; | |
1277 spc_sum+=spc; | |
1278 if(spc) | |
1279 { | |
1280 val_list[j++]=i; | |
1281 } | |
1282 } | |
1283 break; | |
1284 } | |
1285 } | 1212 } |
1213 } | |
1214 } | |
1286 | 1215 |
1287 v46 = rand()%spc_sum+1; | 1216 v46 = rand()%spc_sum+1; |
1288 j=0; | 1217 j=0; |
1289 out_item->uSpecEnchantmentType =val_list[j]; | 1218 v45 = 0; |
1290 v45=pSpecialEnchantments[val_list[j]].to_item_apply[out_item->GetItemEquipType()]; | 1219 while (v45<v46) |
1291 if (v45<v46) | 1220 { |
1292 { | 1221 ++j; |
1293 do | 1222 out_item->uSpecEnchantmentType=val_list[j]; |
1294 { | 1223 v45+=pSpecialEnchantments[val_list[j]].to_item_apply[out_item->GetItemEquipType()]; |
1295 ++j; | 1224 } |
1296 out_item->uSpecEnchantmentType=val_list[j]; | |
1297 v45+=pSpecialEnchantments[val_list[j]].to_item_apply[out_item->GetItemEquipType()]; | |
1298 } while (v45<v46); | |
1299 } | |
1300 ++out_item->uSpecEnchantmentType; | |
1301 } | 1225 } |
1302 | 1226 |
1303 //----- (004505CC) -------------------------------------------------------- | 1227 //----- (004505CC) -------------------------------------------------------- |
1304 bool ItemGen::GenerateArtifact() | 1228 bool ItemGen::GenerateArtifact() |
1305 { | 1229 { |