| | 334 | /** |
|---|
| | 335 | * Copy artifact data to a normal object, and set various slightly hacky |
|---|
| | 336 | * globals. |
|---|
| | 337 | */ |
|---|
| | 338 | static void copy_artifact_data(object_type *o_ptr, artifact_type *a_ptr) |
|---|
| | 339 | { |
|---|
| | 340 | /* Hack -- Mark the artifact as "created" */ |
|---|
| | 341 | a_ptr->cur_num = 1; |
|---|
| | 342 | |
|---|
| | 343 | /* Extract the other fields */ |
|---|
| | 344 | o_ptr->pval = a_ptr->pval; |
|---|
| | 345 | o_ptr->ac = a_ptr->ac; |
|---|
| | 346 | o_ptr->dd = a_ptr->dd; |
|---|
| | 347 | o_ptr->ds = a_ptr->ds; |
|---|
| | 348 | o_ptr->to_a = a_ptr->to_a; |
|---|
| | 349 | o_ptr->to_h = a_ptr->to_h; |
|---|
| | 350 | o_ptr->to_d = a_ptr->to_d; |
|---|
| | 351 | o_ptr->weight = a_ptr->weight; |
|---|
| | 352 | |
|---|
| | 353 | /* Hack -- extract the "cursed" flag */ |
|---|
| | 354 | if (a_ptr->flags3 & TR3_LIGHT_CURSE) |
|---|
| | 355 | o_ptr->flags3 |= TR3_LIGHT_CURSE; |
|---|
| | 356 | |
|---|
| | 357 | /* Mega-Hack -- increase the rating */ |
|---|
| | 358 | rating += 10; |
|---|
| | 359 | |
|---|
| | 360 | /* Mega-Hack -- increase the rating again */ |
|---|
| | 361 | if (a_ptr->cost > 50000L) rating += 10; |
|---|
| | 362 | |
|---|
| | 363 | /* Set the good item flag */ |
|---|
| | 364 | good_item_flag = TRUE; |
|---|
| | 365 | |
|---|
| | 366 | /* Cheat -- peek at the item */ |
|---|
| | 367 | if (cheat_peek) object_mention(o_ptr); |
|---|
| | 368 | } |
|---|
| | 369 | |
|---|
| | 370 | |
|---|
| 989 | | /* |
|---|
| 990 | | * Complete the "creation" of an object by applying "magic" to the item |
|---|
| 991 | | * |
|---|
| 992 | | * This includes not only rolling for random bonuses, but also putting the |
|---|
| 993 | | * finishing touches on ego-items and artifacts, giving charges to wands and |
|---|
| 994 | | * staffs, giving fuel to lites, and placing traps on chests. |
|---|
| 995 | | * |
|---|
| 996 | | * In particular, note that "Instant Artifacts", if "created" by an external |
|---|
| 997 | | * routine, must pass through this function to complete the actual creation. |
|---|
| 998 | | * |
|---|
| 999 | | * The base "chance" of the item being "good" increases with the "level" |
|---|
| 1000 | | * parameter, which is usually derived from the dungeon level, being equal |
|---|
| 1001 | | * to the level plus 10, up to a maximum of 75. If "good" is true, then |
|---|
| 1002 | | * the object is guaranteed to be "good". If an object is "good", then |
|---|
| 1003 | | * the chance that the object will be "great" (ego-item or artifact), also |
|---|
| 1004 | | * increases with the "level", being equal to half the level, plus 5, up to |
|---|
| 1005 | | * a maximum of 20. If "great" is true, then the object is guaranteed to be |
|---|
| 1006 | | * "great". At dungeon level 65 and below, 15/100 objects are "great". |
|---|
| 1007 | | * |
|---|
| 1008 | | * If the object is not "good", there is a chance it will be "cursed", and |
|---|
| 1009 | | * if it is "cursed", there is a chance it will be "broken". These chances |
|---|
| 1010 | | * are related to the "good" / "great" chances above. |
|---|
| 1011 | | * |
|---|
| 1012 | | * Otherwise "normal" rings and amulets will be "good" half the time and |
|---|
| 1013 | | * "cursed" half the time, unless the ring/amulet is always good or cursed. |
|---|
| 1014 | | * |
|---|
| 1015 | | * If "okay" is true, and the object is going to be "great", then there is |
|---|
| 1016 | | * a chance that an artifact will be created. This is true even if both the |
|---|
| 1017 | | * "good" and "great" arguments are false. Objects which are forced "great" |
|---|
| 1018 | | * get three extra "attempts" to become an artifact. |
|---|
| 1019 | | */ |
|---|
| 1020 | | void apply_magic(object_type *o_ptr, int lev, bool okay, bool good, bool great) |
|---|
| 1021 | | { |
|---|
| 1022 | | int i, rolls, f1, f2, power; |
|---|
| 1023 | | |
|---|
| 1024 | | |
|---|
| 1025 | | /* Maximum "level" for various things */ |
|---|
| | 1030 | /** |
|---|
| | 1031 | * Complete object creation by applying magic to it. |
|---|
| | 1032 | * |
|---|
| | 1033 | * Magic includes rolling for random bonuses, applying flags to ego-items, |
|---|
| | 1034 | * charging charged items, fuelling lights, and trapping chests. |
|---|
| | 1035 | * |
|---|
| | 1036 | * The `good` argument forces the item to be at least `good`, and the `great` |
|---|
| | 1037 | * argument does likewise. Setting `allow_artifacts` to TRUE allows artifacts |
|---|
| | 1038 | * to be created here. |
|---|
| | 1039 | * |
|---|
| | 1040 | * If `good` or `great` are not set, then the `lev` argument controls the |
|---|
| | 1041 | * quality of item. See the function itself for the specifics of the |
|---|
| | 1042 | * calculations involved. |
|---|
| | 1043 | */ |
|---|
| | 1044 | void apply_magic(object_type *o_ptr, int lev, bool allow_artifacts, bool good, bool great) |
|---|
| | 1045 | { |
|---|
| | 1046 | int power = 0; |
|---|
| | 1047 | |
|---|
| | 1048 | /* Chance of being `good` and `great` */ |
|---|
| | 1049 | int good_chance = MIN(2*lev + 10, 100); |
|---|
| | 1050 | int great_chance = MIN(good_chance / 3, 20); |
|---|
| | 1051 | |
|---|
| | 1052 | |
|---|
| | 1053 | /* Limit depth */ |
|---|
| 1062 | | if (rand_int(100) < f2) power = -2; |
|---|
| 1063 | | } |
|---|
| 1064 | | |
|---|
| 1065 | | /* Assume no rolls */ |
|---|
| 1066 | | rolls = 0; |
|---|
| 1067 | | |
|---|
| 1068 | | /* Get one roll if excellent */ |
|---|
| 1069 | | if (power >= 2) rolls = 1; |
|---|
| 1070 | | |
|---|
| 1071 | | /* Get four rolls if forced great */ |
|---|
| 1072 | | if (great) rolls = 4; |
|---|
| 1073 | | |
|---|
| 1074 | | /* Get no rolls if not allowed */ |
|---|
| 1075 | | if (!okay || o_ptr->name1) rolls = 0; |
|---|
| 1076 | | |
|---|
| 1077 | | /* Roll for artifacts if allowed */ |
|---|
| 1078 | | for (i = 0; i < rolls; i++) |
|---|
| 1079 | | { |
|---|
| 1080 | | /* Roll for an artifact */ |
|---|
| 1081 | | if (make_artifact(o_ptr)) break; |
|---|
| 1082 | | } |
|---|
| 1083 | | |
|---|
| 1084 | | |
|---|
| 1085 | | /* Hack -- analyze artifacts */ |
|---|
| 1086 | | if (o_ptr->name1) |
|---|
| 1087 | | { |
|---|
| 1088 | | artifact_type *a_ptr = &a_info[o_ptr->name1]; |
|---|
| 1089 | | |
|---|
| 1090 | | /* Hack -- Mark the artifact as "created" */ |
|---|
| 1091 | | a_ptr->cur_num = 1; |
|---|
| 1092 | | |
|---|
| 1093 | | /* Extract the other fields */ |
|---|
| 1094 | | o_ptr->pval = a_ptr->pval; |
|---|
| 1095 | | o_ptr->ac = a_ptr->ac; |
|---|
| 1096 | | o_ptr->dd = a_ptr->dd; |
|---|
| 1097 | | o_ptr->ds = a_ptr->ds; |
|---|
| 1098 | | o_ptr->to_a = a_ptr->to_a; |
|---|
| 1099 | | o_ptr->to_h = a_ptr->to_h; |
|---|
| 1100 | | o_ptr->to_d = a_ptr->to_d; |
|---|
| 1101 | | o_ptr->weight = a_ptr->weight; |
|---|
| 1102 | | |
|---|
| 1103 | | /* Hack -- extract the "cursed" flag */ |
|---|
| 1104 | | if (a_ptr->flags3 & TR3_LIGHT_CURSE) |
|---|
| 1105 | | o_ptr->flags3 |= TR3_LIGHT_CURSE; |
|---|
| 1106 | | |
|---|
| 1107 | | /* Mega-Hack -- increase the rating */ |
|---|
| 1108 | | rating += 10; |
|---|
| 1109 | | |
|---|
| 1110 | | /* Mega-Hack -- increase the rating again */ |
|---|
| 1111 | | if (a_ptr->cost > 50000L) rating += 10; |
|---|
| 1112 | | |
|---|
| 1113 | | /* Set the good item flag */ |
|---|
| 1114 | | good_item_flag = TRUE; |
|---|
| 1115 | | |
|---|
| 1116 | | /* Cheat -- peek at the item */ |
|---|
| 1117 | | if (cheat_peek) object_mention(o_ptr); |
|---|
| 1118 | | |
|---|
| 1119 | | /* Done */ |
|---|
| 1120 | | return; |
|---|
| | 1073 | if (rand_int(100) < great_chance) power = -2; |
|---|
| | 1074 | } |
|---|
| | 1075 | |
|---|
| | 1076 | |
|---|
| | 1077 | /* Roll for artifact creation */ |
|---|
| | 1078 | if (allow_artifacts && !o_ptr->name1) |
|---|
| | 1079 | { |
|---|
| | 1080 | int i; |
|---|
| | 1081 | int rolls = 0; |
|---|
| | 1082 | |
|---|
| | 1083 | /* Get one roll if excellent */ |
|---|
| | 1084 | if (power >= 2) rolls = 1; |
|---|
| | 1085 | |
|---|
| | 1086 | /* Get four rolls if forced great */ |
|---|
| | 1087 | if (great) rolls = 4; |
|---|
| | 1088 | |
|---|
| | 1089 | /* Roll for artifacts if allowed */ |
|---|
| | 1090 | for (i = 0; i < rolls; i++) |
|---|
| | 1091 | { |
|---|
| | 1092 | if (make_artifact(o_ptr)) |
|---|
| | 1093 | return; |
|---|
| | 1094 | } |
|---|
| 1424 | | if (great) |
|---|
| 1425 | | tries = 5; |
|---|
| 1426 | | else if (good) |
|---|
| 1427 | | tries = 3; |
|---|
| 1428 | | |
|---|
| 1429 | | for (i = 0; i < tries; i++) |
|---|
| 1430 | | { |
|---|
| 1431 | | /* Pick a random object */ |
|---|
| 1432 | | k_idx = get_obj_num(base); |
|---|
| 1433 | | |
|---|
| 1434 | | /* Keep if it's good, or try again */ |
|---|
| 1435 | | if (kind_is_good(k_idx)) break; |
|---|
| 1436 | | } |
|---|
| 1437 | | |
|---|
| 1438 | | #if 0 |
|---|
| 1439 | | /* Good objects */ |
|---|
| 1440 | | if (good) |
|---|
| 1441 | | { |
|---|
| 1442 | | /* Clear restriction */ |
|---|
| 1443 | | get_obj_num_hook = NULL; |
|---|
| 1444 | | |
|---|
| 1445 | | /* Prepare allocation table */ |
|---|
| 1446 | | get_obj_num_prep(); |
|---|
| 1447 | | } |
|---|
| 1448 | | #endif |
|---|
| 1449 | | |
|---|
| 1450 | | /* Handle failure */ |
|---|
| 1451 | | if (!k_idx) return (FALSE); |
|---|
| 1452 | | |
|---|
| 1453 | | /* Prepare the object */ |
|---|
| 1454 | | object_prep(j_ptr, k_idx); |
|---|
| 1455 | | } |
|---|
| | 1393 | /* Keep if it's good, or try again */ |
|---|
| | 1394 | if (kind_is_good(k_idx)) break; |
|---|
| | 1395 | } |
|---|
| | 1396 | |
|---|
| | 1397 | if (!k_idx) return FALSE; |
|---|
| | 1398 | |
|---|
| | 1399 | /* Prepare the object */ |
|---|
| | 1400 | object_prep(j_ptr, k_idx); |
|---|