… | |
… | |
156 | * so that the treasure name can be printed out |
156 | * so that the treasure name can be printed out |
157 | */ |
157 | */ |
158 | static void |
158 | static void |
159 | check_treasurelist (const treasure *t, const treasurelist * tl) |
159 | check_treasurelist (const treasure *t, const treasurelist * tl) |
160 | { |
160 | { |
161 | if (t->item == NULL && t->name == NULL) |
|
|
162 | LOG (llevError, "Treasurelist %s has element with no name or archetype\n", &tl->name); |
|
|
163 | if (t->chance >= 100 && t->next_yes && (t->next || t->next_no)) |
161 | if (t->chance >= 100 && t->next_yes && (t->next || t->next_no)) |
164 | LOG (llevError, "Treasurelist %s has element that has 100%% generation, next_yes field as well as next or next_no\n", &tl->name); |
162 | LOG (llevError, "Treasurelist %s has element that has 100%% generation, next_yes field as well as next or next_no\n", &tl->name); |
165 | /* find_treasurelist will print out its own error message */ |
163 | /* find_treasurelist will print out its own error message */ |
166 | if (t->name && *t->name) |
164 | if (t->name && *t->name) |
167 | (void) find_treasurelist (t->name); |
165 | find_treasurelist (t->name); |
168 | if (t->next) |
166 | if (t->next) |
169 | check_treasurelist (t->next, tl); |
167 | check_treasurelist (t->next, tl); |
170 | if (t->next_yes) |
168 | if (t->next_yes) |
171 | check_treasurelist (t->next_yes, tl); |
169 | check_treasurelist (t->next_yes, tl); |
172 | if (t->next_no) |
170 | if (t->next_no) |
… | |
… | |
336 | |
334 | |
337 | if ((int) t->chance >= 100 || (RANDOM () % 100 + 1) < (int) t->chance) |
335 | if ((int) t->chance >= 100 || (RANDOM () % 100 + 1) < (int) t->chance) |
338 | { |
336 | { |
339 | if (t->name) |
337 | if (t->name) |
340 | { |
338 | { |
341 | if (strcmp (t->name, "NONE") && difficulty >= t->magic) |
339 | if (difficulty >= t->magic) |
342 | { |
340 | { |
343 | treasurelist *tl = find_treasurelist (t->name); |
341 | treasurelist *tl = find_treasurelist (t->name); |
344 | if (tl) |
342 | if (tl) |
345 | create_treasure (tl, op, flag, difficulty, tries); |
343 | create_treasure (tl, op, flag, difficulty, tries); |
346 | } |
344 | } |
347 | } |
345 | } |
348 | else |
346 | else |
349 | { |
347 | { |
350 | if (t->item->clone.invisible != 0 || !(flag & GT_INVISIBLE)) |
348 | if (t->item && (t->item->clone.invisible != 0 || !(flag & GT_INVISIBLE))) |
351 | { |
349 | { |
352 | tmp = arch_to_object (t->item); |
350 | tmp = arch_to_object (t->item); |
353 | if (t->nrof && tmp->nrof <= 1) |
351 | if (t->nrof && tmp->nrof <= 1) |
354 | tmp->nrof = RANDOM () % ((int) t->nrof) + 1; |
352 | tmp->nrof = RANDOM () % ((int) t->nrof) + 1; |
355 | fix_generated_item (tmp, op, difficulty, t->magic, flag); |
353 | fix_generated_item (tmp, op, difficulty, t->magic, flag); |
… | |
… | |
395 | return; |
393 | return; |
396 | } |
394 | } |
397 | |
395 | |
398 | if (t->name) |
396 | if (t->name) |
399 | { |
397 | { |
400 | if (!strcmp (t->name, "NONE")) |
|
|
401 | return; |
|
|
402 | |
|
|
403 | if (difficulty >= t->magic) |
398 | if (difficulty >= t->magic) |
404 | { |
399 | { |
405 | treasurelist *tl = find_treasurelist (t->name); |
400 | treasurelist *tl = find_treasurelist (t->name); |
406 | if (tl) |
401 | if (tl) |
407 | create_treasure (tl, op, flag, difficulty, tries); |
402 | create_treasure (tl, op, flag, difficulty, tries); |
… | |
… | |
410 | create_one_treasure (tl, op, flag, difficulty, tries); |
405 | create_one_treasure (tl, op, flag, difficulty, tries); |
411 | |
406 | |
412 | return; |
407 | return; |
413 | } |
408 | } |
414 | |
409 | |
415 | if ((t->item && t->item->clone.invisible != 0) || flag != GT_INVISIBLE) |
410 | if (t->item && (t->item->clone.invisible != 0 || flag != GT_INVISIBLE)) |
416 | { |
411 | { |
417 | object *tmp = arch_to_object (t->item); |
412 | object *tmp = arch_to_object (t->item); |
418 | |
413 | |
419 | if (!tmp) |
414 | if (!tmp) |
420 | return; |
415 | return; |
… | |
… | |
434 | * list transitions, or so that excessively good treasure will not be |
429 | * list transitions, or so that excessively good treasure will not be |
435 | * created on weak maps, because it will exceed the number of allowed tries |
430 | * created on weak maps, because it will exceed the number of allowed tries |
436 | * to do that. |
431 | * to do that. |
437 | */ |
432 | */ |
438 | void |
433 | void |
439 | create_treasure (treasurelist * t, object *op, int flag, int difficulty, int tries) |
434 | create_treasure (treasurelist *tl, object *op, int flag, int difficulty, int tries) |
440 | { |
435 | { |
441 | |
436 | |
442 | if (tries++ > 100) |
437 | if (tries++ > 100) |
443 | { |
438 | { |
444 | LOG (llevDebug, "createtreasure: tries exceeded 100, returning without making treasure\n"); |
439 | LOG (llevDebug, "createtreasure: tries exceeded 100, returning without making treasure\n"); |
445 | return; |
440 | return; |
446 | } |
441 | } |
447 | if (t->total_chance) |
442 | if (tl->total_chance) |
448 | create_one_treasure (t, op, flag, difficulty, tries); |
443 | create_one_treasure (tl, op, flag, difficulty, tries); |
449 | else |
444 | else |
450 | create_all_treasures (t->items, op, flag, difficulty, tries); |
445 | create_all_treasures (tl->items, op, flag, difficulty, tries); |
451 | } |
446 | } |
452 | |
447 | |
453 | /* This is similar to the old generate treasure function. However, |
448 | /* This is similar to the old generate treasure function. However, |
454 | * it instead takes a treasurelist. It is really just a wrapper around |
449 | * it instead takes a treasurelist. It is really just a wrapper around |
455 | * create_treasure. We create a dummy object that the treasure gets |
450 | * create_treasure. We create a dummy object that the treasure gets |
456 | * inserted into, and then return that treausre |
451 | * inserted into, and then return that treausre |
457 | */ |
452 | */ |
458 | object * |
453 | object * |
459 | generate_treasure (treasurelist *t, int difficulty) |
454 | generate_treasure (treasurelist *tl, int difficulty) |
460 | { |
455 | { |
461 | difficulty = clamp (difficulty, 1, settings.max_level); |
456 | difficulty = clamp (difficulty, 1, settings.max_level); |
462 | |
457 | |
463 | object *ob = object::create (), *tmp; |
458 | object *ob = object::create (), *tmp; |
464 | |
459 | |
465 | create_treasure (t, ob, 0, difficulty, 0); |
460 | create_treasure (tl, ob, 0, difficulty, 0); |
466 | |
461 | |
467 | /* Don't want to free the object we are about to return */ |
462 | /* Don't want to free the object we are about to return */ |
468 | tmp = ob->inv; |
463 | tmp = ob->inv; |
469 | if (tmp != NULL) |
464 | if (tmp != NULL) |
470 | tmp->remove (); |
465 | tmp->remove (); |
… | |
… | |
1176 | */ |
1171 | */ |
1177 | |
1172 | |
1178 | static artifactlist * |
1173 | static artifactlist * |
1179 | get_empty_artifactlist (void) |
1174 | get_empty_artifactlist (void) |
1180 | { |
1175 | { |
1181 | artifactlist *tl = (artifactlist *) malloc (sizeof (artifactlist)); |
1176 | artifactlist *al = (artifactlist *) malloc (sizeof (artifactlist)); |
1182 | |
1177 | |
1183 | if (tl == NULL) |
1178 | if (al == NULL) |
1184 | fatal (OUT_OF_MEMORY); |
1179 | fatal (OUT_OF_MEMORY); |
1185 | tl->next = NULL; |
1180 | al->next = NULL; |
1186 | tl->items = NULL; |
1181 | al->items = NULL; |
1187 | tl->total_chance = 0; |
1182 | al->total_chance = 0; |
1188 | return tl; |
1183 | return al; |
1189 | } |
1184 | } |
1190 | |
1185 | |
1191 | /* |
1186 | /* |
1192 | * Allocate and return the pointer to an empty artifact structure. |
1187 | * Allocate and return the pointer to an empty artifact structure. |
1193 | */ |
1188 | */ |
1194 | |
1189 | |
1195 | static artifact * |
1190 | static artifact * |
1196 | get_empty_artifact (void) |
1191 | get_empty_artifact (void) |
1197 | { |
1192 | { |
1198 | artifact *t = (artifact *) malloc (sizeof (artifact)); |
1193 | artifact *a = (artifact *) malloc (sizeof (artifact)); |
1199 | |
1194 | |
1200 | if (t == NULL) |
1195 | if (a == NULL) |
1201 | fatal (OUT_OF_MEMORY); |
1196 | fatal (OUT_OF_MEMORY); |
1202 | t->item = NULL; |
1197 | a->item = NULL; |
1203 | t->next = NULL; |
1198 | a->next = NULL; |
1204 | t->chance = 0; |
1199 | a->chance = 0; |
1205 | t->difficulty = 0; |
1200 | a->difficulty = 0; |
1206 | t->allowed = NULL; |
1201 | a->allowed = NULL; |
1207 | return t; |
1202 | return a; |
1208 | } |
1203 | } |
1209 | |
1204 | |
1210 | /* |
1205 | /* |
1211 | * Searches the artifact lists and returns one that has the same type |
1206 | * Searches the artifact lists and returns one that has the same type |
1212 | * of objects on it. |
1207 | * of objects on it. |
… | |
… | |
1262 | treasurelist *tl; |
1257 | treasurelist *tl; |
1263 | int i; |
1258 | int i; |
1264 | |
1259 | |
1265 | if (depth > 100) |
1260 | if (depth > 100) |
1266 | return; |
1261 | return; |
1267 | while (t != NULL) |
1262 | while (t) |
1268 | { |
1263 | { |
1269 | if (t->name != NULL) |
1264 | if (t->name) |
1270 | { |
1265 | { |
1271 | for (i = 0; i < depth; i++) |
1266 | for (i = 0; i < depth; i++) |
1272 | fprintf (logfile, " "); |
1267 | fprintf (logfile, " "); |
1273 | fprintf (logfile, "{ (list: %s)\n", &t->name); |
1268 | fprintf (logfile, "{ (list: %s)\n", &t->name); |
1274 | tl = find_treasurelist (t->name); |
1269 | tl = find_treasurelist (t->name); |
… | |
… | |
1280 | } |
1275 | } |
1281 | else |
1276 | else |
1282 | { |
1277 | { |
1283 | for (i = 0; i < depth; i++) |
1278 | for (i = 0; i < depth; i++) |
1284 | fprintf (logfile, " "); |
1279 | fprintf (logfile, " "); |
1285 | if (t->item->clone.type == FLESH) |
1280 | if (t->item && t->item->clone.type == FLESH) |
1286 | fprintf (logfile, "%s's %s\n", name, &t->item->clone.name); |
1281 | fprintf (logfile, "%s's %s\n", name, &t->item->clone.name); |
1287 | else |
1282 | else |
1288 | fprintf (logfile, "%s\n", &t->item->clone.name); |
1283 | fprintf (logfile, "%s\n", &t->item->clone.name); |
1289 | } |
1284 | } |
|
|
1285 | |
1290 | if (t->next_yes != NULL) |
1286 | if (t->next_yes) |
1291 | { |
1287 | { |
1292 | for (i = 0; i < depth; i++) |
1288 | for (i = 0; i < depth; i++) |
1293 | fprintf (logfile, " "); |
1289 | fprintf (logfile, " "); |
1294 | fprintf (logfile, " (if yes)\n"); |
1290 | fprintf (logfile, " (if yes)\n"); |
1295 | dump_monster_treasure_rec (name, t->next_yes, depth + 1); |
1291 | dump_monster_treasure_rec (name, t->next_yes, depth + 1); |
1296 | } |
1292 | } |
|
|
1293 | |
1297 | if (t->next_no != NULL) |
1294 | if (t->next_no) |
1298 | { |
1295 | { |
1299 | for (i = 0; i < depth; i++) |
1296 | for (i = 0; i < depth; i++) |
1300 | fprintf (logfile, " "); |
1297 | fprintf (logfile, " "); |
1301 | fprintf (logfile, " (if no)\n"); |
1298 | fprintf (logfile, " (if no)\n"); |
1302 | dump_monster_treasure_rec (name, t->next_no, depth + 1); |
1299 | dump_monster_treasure_rec (name, t->next_no, depth + 1); |
1303 | } |
1300 | } |
|
|
1301 | |
1304 | t = t->next; |
1302 | t = t->next; |
1305 | } |
1303 | } |
1306 | } |
1304 | } |
1307 | |
1305 | |
1308 | /* |
1306 | /* |
… | |
… | |
1808 | /* special_potion() - so that old potion code is still done right. */ |
1806 | /* special_potion() - so that old potion code is still done right. */ |
1809 | |
1807 | |
1810 | int |
1808 | int |
1811 | special_potion (object *op) |
1809 | special_potion (object *op) |
1812 | { |
1810 | { |
1813 | |
|
|
1814 | int i; |
|
|
1815 | |
|
|
1816 | if (op->attacktype) |
1811 | if (op->attacktype) |
1817 | return 1; |
1812 | return 1; |
1818 | |
1813 | |
1819 | if (op->stats.Str || op->stats.Dex || op->stats.Con || op->stats.Pow || op->stats.Wis || op->stats.Int || op->stats.Cha) |
1814 | if (op->stats.Str || op->stats.Dex || op->stats.Con || op->stats.Pow || op->stats.Wis || op->stats.Int || op->stats.Cha) |
1820 | return 1; |
1815 | return 1; |
1821 | |
1816 | |
1822 | for (i = 0; i < NROFATTACKS; i++) |
1817 | for (int i = 0; i < NROFATTACKS; i++) |
1823 | if (op->resist[i]) |
1818 | if (op->resist[i]) |
1824 | return 1; |
1819 | return 1; |
1825 | |
1820 | |
1826 | return 0; |
1821 | return 0; |
1827 | } |
1822 | } |