… | |
… | |
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) |
… | |
… | |
258 | shstr_cmp name_ (name); |
256 | shstr_cmp name_ (name); |
259 | |
257 | |
260 | if (!name_) |
258 | if (!name_) |
261 | return 0; |
259 | return 0; |
262 | |
260 | |
263 | for (treasurelist * tl = first_treasurelist; tl != 0; tl = tl->next) |
261 | for (treasurelist *tl = first_treasurelist; tl != 0; tl = tl->next) |
264 | if (name_ == tl->name) |
262 | if (name_ == tl->name) |
265 | return tl; |
263 | return tl; |
266 | |
264 | |
267 | if (first_treasurelist) |
265 | if (first_treasurelist) |
268 | LOG (llevError, "Couldn't find treasurelist %s\n", name); |
266 | LOG (llevError, "Couldn't find treasurelist %s\n", name); |
… | |
… | |
280 | * being generated. |
278 | * being generated. |
281 | * If flag is GT_INVISIBLE, only invisible objects are generated (ie, only |
279 | * If flag is GT_INVISIBLE, only invisible objects are generated (ie, only |
282 | * abilities. This is used by summon spells, thus no summoned monsters |
280 | * abilities. This is used by summon spells, thus no summoned monsters |
283 | * start with equipment, but only their abilities). |
281 | * start with equipment, but only their abilities). |
284 | */ |
282 | */ |
285 | |
|
|
286 | |
|
|
287 | static void |
283 | static void |
288 | put_treasure (object *op, object *creator, int flags) |
284 | put_treasure (object *op, object *creator, int flags) |
289 | { |
285 | { |
290 | object *tmp; |
286 | object *tmp; |
291 | |
287 | |
… | |
… | |
294 | * this is the original object, or if this is an object that should be created |
290 | * this is the original object, or if this is an object that should be created |
295 | * by another object. |
291 | * by another object. |
296 | */ |
292 | */ |
297 | if (flags & GT_ENVIRONMENT && op->type != SPELL) |
293 | if (flags & GT_ENVIRONMENT && op->type != SPELL) |
298 | { |
294 | { |
299 | op->x = creator->x; |
|
|
300 | op->y = creator->y; |
|
|
301 | SET_FLAG (op, FLAG_OBJ_ORIGINAL); |
295 | SET_FLAG (op, FLAG_OBJ_ORIGINAL); |
302 | insert_ob_in_map (op, creator->map, op, INS_NO_MERGE | INS_NO_WALK_ON); |
296 | op->insert_at (creator, creator, INS_NO_MERGE | INS_NO_WALK_ON); |
303 | } |
297 | } |
304 | else |
298 | else |
305 | { |
299 | { |
306 | op = insert_ob_in_ob (op, creator); |
300 | op = creator->insert (op); |
|
|
301 | |
307 | if ((flags & GT_APPLY) && QUERY_FLAG (creator, FLAG_MONSTER)) |
302 | if ((flags & GT_APPLY) && QUERY_FLAG (creator, FLAG_MONSTER)) |
308 | monster_check_apply (creator, op); |
303 | monster_check_apply (creator, op); |
|
|
304 | |
309 | if ((flags & GT_UPDATE_INV) && (tmp = is_player_inv (creator)) != NULL) |
305 | if ((flags & GT_UPDATE_INV) && (tmp = creator->in_player ())) |
310 | esrv_send_item (tmp, op); |
306 | esrv_send_item (tmp, op); |
311 | } |
307 | } |
312 | } |
308 | } |
313 | |
309 | |
314 | /* if there are change_xxx commands in the treasure, we include the changes |
310 | /* if there are change_xxx commands in the treasure, we include the changes |
… | |
… | |
338 | |
334 | |
339 | if ((int) t->chance >= 100 || (RANDOM () % 100 + 1) < (int) t->chance) |
335 | if ((int) t->chance >= 100 || (RANDOM () % 100 + 1) < (int) t->chance) |
340 | { |
336 | { |
341 | if (t->name) |
337 | if (t->name) |
342 | { |
338 | { |
343 | if (strcmp (t->name, "NONE") && difficulty >= t->magic) |
339 | if (difficulty >= t->magic) |
|
|
340 | { |
|
|
341 | treasurelist *tl = find_treasurelist (t->name); |
|
|
342 | if (tl) |
344 | create_treasure (find_treasurelist (t->name), op, flag, difficulty, tries); |
343 | create_treasure (tl, op, flag, difficulty, tries); |
|
|
344 | } |
345 | } |
345 | } |
346 | else |
346 | else |
347 | { |
347 | { |
348 | if (t->item->clone.invisible != 0 || !(flag & GT_INVISIBLE)) |
348 | if (t->item && (t->item->clone.invisible != 0 || !(flag & GT_INVISIBLE))) |
349 | { |
349 | { |
350 | tmp = arch_to_object (t->item); |
350 | tmp = arch_to_object (t->item); |
351 | if (t->nrof && tmp->nrof <= 1) |
351 | if (t->nrof && tmp->nrof <= 1) |
352 | tmp->nrof = RANDOM () % ((int) t->nrof) + 1; |
352 | tmp->nrof = RANDOM () % ((int) t->nrof) + 1; |
353 | fix_generated_item (tmp, op, difficulty, t->magic, flag); |
353 | fix_generated_item (tmp, op, difficulty, t->magic, flag); |
… | |
… | |
393 | return; |
393 | return; |
394 | } |
394 | } |
395 | |
395 | |
396 | if (t->name) |
396 | if (t->name) |
397 | { |
397 | { |
398 | if (!strcmp (t->name, "NONE")) |
|
|
399 | return; |
|
|
400 | |
|
|
401 | if (difficulty >= t->magic) |
398 | if (difficulty >= t->magic) |
|
|
399 | { |
|
|
400 | treasurelist *tl = find_treasurelist (t->name); |
|
|
401 | if (tl) |
402 | create_treasure (find_treasurelist (t->name), op, flag, difficulty, tries); |
402 | create_treasure (tl, op, flag, difficulty, tries); |
|
|
403 | } |
403 | else if (t->nrof) |
404 | else if (t->nrof) |
404 | create_one_treasure (tl, op, flag, difficulty, tries); |
405 | create_one_treasure (tl, op, flag, difficulty, tries); |
405 | |
406 | |
406 | return; |
407 | return; |
407 | } |
408 | } |
408 | |
409 | |
409 | if ((t->item && t->item->clone.invisible != 0) || flag != GT_INVISIBLE) |
410 | if (t->item && (t->item->clone.invisible != 0 || flag != GT_INVISIBLE)) |
410 | { |
411 | { |
411 | object *tmp = arch_to_object (t->item); |
412 | object *tmp = arch_to_object (t->item); |
412 | |
413 | |
413 | if (!tmp) |
414 | if (!tmp) |
414 | return; |
415 | return; |
… | |
… | |
428 | * list transitions, or so that excessively good treasure will not be |
429 | * list transitions, or so that excessively good treasure will not be |
429 | * 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 |
430 | * to do that. |
431 | * to do that. |
431 | */ |
432 | */ |
432 | void |
433 | void |
433 | 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) |
434 | { |
435 | { |
435 | |
436 | |
436 | if (tries++ > 100) |
437 | if (tries++ > 100) |
437 | { |
438 | { |
438 | LOG (llevDebug, "createtreasure: tries exceeded 100, returning without making treasure\n"); |
439 | LOG (llevDebug, "createtreasure: tries exceeded 100, returning without making treasure\n"); |
439 | return; |
440 | return; |
440 | } |
441 | } |
441 | if (t->total_chance) |
442 | if (tl->total_chance) |
442 | create_one_treasure (t, op, flag, difficulty, tries); |
443 | create_one_treasure (tl, op, flag, difficulty, tries); |
443 | else |
444 | else |
444 | create_all_treasures (t->items, op, flag, difficulty, tries); |
445 | create_all_treasures (tl->items, op, flag, difficulty, tries); |
445 | } |
446 | } |
446 | |
447 | |
447 | /* This is similar to the old generate treasure function. However, |
448 | /* This is similar to the old generate treasure function. However, |
448 | * 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 |
449 | * create_treasure. We create a dummy object that the treasure gets |
450 | * create_treasure. We create a dummy object that the treasure gets |
450 | * inserted into, and then return that treausre |
451 | * inserted into, and then return that treausre |
451 | */ |
452 | */ |
452 | object * |
453 | object * |
453 | generate_treasure (treasurelist * t, int difficulty) |
454 | generate_treasure (treasurelist *tl, int difficulty) |
454 | { |
455 | { |
|
|
456 | difficulty = clamp (difficulty, 1, settings.max_level); |
|
|
457 | |
455 | object *ob = get_object (), *tmp; |
458 | object *ob = object::create (), *tmp; |
456 | |
459 | |
457 | create_treasure (t, ob, 0, difficulty, 0); |
460 | create_treasure (tl, ob, 0, difficulty, 0); |
458 | |
461 | |
459 | /* 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 */ |
460 | tmp = ob->inv; |
463 | tmp = ob->inv; |
461 | if (tmp != NULL) |
464 | if (tmp != NULL) |
462 | tmp->remove (); |
465 | tmp->remove (); |
463 | |
466 | |
464 | if (ob->inv) |
467 | if (ob->inv) |
465 | LOG (llevError, "In generate treasure, created multiple objects.\n"); |
468 | LOG (llevError, "In generate treasure, created multiple objects.\n"); |
466 | |
469 | |
467 | ob->destroy (0); |
470 | ob->destroy (); |
468 | return tmp; |
471 | return tmp; |
469 | } |
472 | } |
470 | |
473 | |
471 | /* |
474 | /* |
472 | * This is a new way of calculating the chance for an item to have |
475 | * This is a new way of calculating the chance for an item to have |
… | |
… | |
999 | op->value *= 5; /* Since it's not just decoration */ |
1002 | op->value *= 5; /* Since it's not just decoration */ |
1000 | |
1003 | |
1001 | case RING: |
1004 | case RING: |
1002 | if (op->arch == NULL) |
1005 | if (op->arch == NULL) |
1003 | { |
1006 | { |
1004 | op->remove (); |
|
|
1005 | op->destroy (0); |
1007 | op->destroy (); |
1006 | op = NULL; |
1008 | op = 0; |
1007 | break; |
1009 | break; |
1008 | } |
1010 | } |
1009 | |
1011 | |
1010 | if (op->arch != ring_arch && op->arch != amulet_arch) /* It's a special artifact! */ |
1012 | if (op->arch != ring_arch && op->arch != amulet_arch) /* It's a special artifact! */ |
1011 | break; |
1013 | break; |
… | |
… | |
1169 | */ |
1171 | */ |
1170 | |
1172 | |
1171 | static artifactlist * |
1173 | static artifactlist * |
1172 | get_empty_artifactlist (void) |
1174 | get_empty_artifactlist (void) |
1173 | { |
1175 | { |
1174 | artifactlist *tl = (artifactlist *) malloc (sizeof (artifactlist)); |
1176 | artifactlist *al = (artifactlist *) malloc (sizeof (artifactlist)); |
1175 | |
1177 | |
1176 | if (tl == NULL) |
1178 | if (al == NULL) |
1177 | fatal (OUT_OF_MEMORY); |
1179 | fatal (OUT_OF_MEMORY); |
1178 | tl->next = NULL; |
1180 | al->next = NULL; |
1179 | tl->items = NULL; |
1181 | al->items = NULL; |
1180 | tl->total_chance = 0; |
1182 | al->total_chance = 0; |
1181 | return tl; |
1183 | return al; |
1182 | } |
1184 | } |
1183 | |
1185 | |
1184 | /* |
1186 | /* |
1185 | * Allocate and return the pointer to an empty artifact structure. |
1187 | * Allocate and return the pointer to an empty artifact structure. |
1186 | */ |
1188 | */ |
1187 | |
1189 | |
1188 | static artifact * |
1190 | static artifact * |
1189 | get_empty_artifact (void) |
1191 | get_empty_artifact (void) |
1190 | { |
1192 | { |
1191 | artifact *t = (artifact *) malloc (sizeof (artifact)); |
1193 | artifact *a = (artifact *) malloc (sizeof (artifact)); |
1192 | |
1194 | |
1193 | if (t == NULL) |
1195 | if (a == NULL) |
1194 | fatal (OUT_OF_MEMORY); |
1196 | fatal (OUT_OF_MEMORY); |
1195 | t->item = NULL; |
1197 | a->item = NULL; |
1196 | t->next = NULL; |
1198 | a->next = NULL; |
1197 | t->chance = 0; |
1199 | a->chance = 0; |
1198 | t->difficulty = 0; |
1200 | a->difficulty = 0; |
1199 | t->allowed = NULL; |
1201 | a->allowed = NULL; |
1200 | return t; |
1202 | return a; |
1201 | } |
1203 | } |
1202 | |
1204 | |
1203 | /* |
1205 | /* |
1204 | * 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 |
1205 | * of objects on it. |
1207 | * of objects on it. |
… | |
… | |
1255 | treasurelist *tl; |
1257 | treasurelist *tl; |
1256 | int i; |
1258 | int i; |
1257 | |
1259 | |
1258 | if (depth > 100) |
1260 | if (depth > 100) |
1259 | return; |
1261 | return; |
1260 | while (t != NULL) |
1262 | while (t) |
1261 | { |
1263 | { |
1262 | if (t->name != NULL) |
1264 | if (t->name) |
1263 | { |
1265 | { |
1264 | for (i = 0; i < depth; i++) |
1266 | for (i = 0; i < depth; i++) |
1265 | fprintf (logfile, " "); |
1267 | fprintf (logfile, " "); |
1266 | fprintf (logfile, "{ (list: %s)\n", &t->name); |
1268 | fprintf (logfile, "{ (list: %s)\n", &t->name); |
1267 | tl = find_treasurelist (t->name); |
1269 | tl = find_treasurelist (t->name); |
|
|
1270 | if (tl) |
1268 | dump_monster_treasure_rec (name, tl->items, depth + 2); |
1271 | dump_monster_treasure_rec (name, tl->items, depth + 2); |
1269 | for (i = 0; i < depth; i++) |
1272 | for (i = 0; i < depth; i++) |
1270 | fprintf (logfile, " "); |
1273 | fprintf (logfile, " "); |
1271 | fprintf (logfile, "} (end of list: %s)\n", &t->name); |
1274 | fprintf (logfile, "} (end of list: %s)\n", &t->name); |
1272 | } |
1275 | } |
1273 | else |
1276 | else |
1274 | { |
1277 | { |
1275 | for (i = 0; i < depth; i++) |
1278 | for (i = 0; i < depth; i++) |
1276 | fprintf (logfile, " "); |
1279 | fprintf (logfile, " "); |
1277 | if (t->item->clone.type == FLESH) |
1280 | if (t->item && t->item->clone.type == FLESH) |
1278 | fprintf (logfile, "%s's %s\n", name, &t->item->clone.name); |
1281 | fprintf (logfile, "%s's %s\n", name, &t->item->clone.name); |
1279 | else |
1282 | else |
1280 | fprintf (logfile, "%s\n", &t->item->clone.name); |
1283 | fprintf (logfile, "%s\n", &t->item->clone.name); |
1281 | } |
1284 | } |
|
|
1285 | |
1282 | if (t->next_yes != NULL) |
1286 | if (t->next_yes) |
1283 | { |
1287 | { |
1284 | for (i = 0; i < depth; i++) |
1288 | for (i = 0; i < depth; i++) |
1285 | fprintf (logfile, " "); |
1289 | fprintf (logfile, " "); |
1286 | fprintf (logfile, " (if yes)\n"); |
1290 | fprintf (logfile, " (if yes)\n"); |
1287 | dump_monster_treasure_rec (name, t->next_yes, depth + 1); |
1291 | dump_monster_treasure_rec (name, t->next_yes, depth + 1); |
1288 | } |
1292 | } |
|
|
1293 | |
1289 | if (t->next_no != NULL) |
1294 | if (t->next_no) |
1290 | { |
1295 | { |
1291 | for (i = 0; i < depth; i++) |
1296 | for (i = 0; i < depth; i++) |
1292 | fprintf (logfile, " "); |
1297 | fprintf (logfile, " "); |
1293 | fprintf (logfile, " (if no)\n"); |
1298 | fprintf (logfile, " (if no)\n"); |
1294 | dump_monster_treasure_rec (name, t->next_no, depth + 1); |
1299 | dump_monster_treasure_rec (name, t->next_no, depth + 1); |
1295 | } |
1300 | } |
|
|
1301 | |
1296 | t = t->next; |
1302 | t = t->next; |
1297 | } |
1303 | } |
1298 | } |
1304 | } |
1299 | |
1305 | |
1300 | /* |
1306 | /* |
… | |
… | |
1390 | art->chance = (uint16) value; |
1396 | art->chance = (uint16) value; |
1391 | else if (sscanf (cp, "difficulty %d", &value)) |
1397 | else if (sscanf (cp, "difficulty %d", &value)) |
1392 | art->difficulty = (uint8) value; |
1398 | art->difficulty = (uint8) value; |
1393 | else if (!strncmp (cp, "Object", 6)) |
1399 | else if (!strncmp (cp, "Object", 6)) |
1394 | { |
1400 | { |
1395 | art->item = get_object (); |
1401 | art->item = object::create (); |
1396 | |
1402 | |
1397 | if (!load_object (thawer, art->item, 0)) |
1403 | if (!load_object (thawer, art->item, 0)) |
1398 | LOG (llevError, "Init_Artifacts: Could not load object.\n"); |
1404 | LOG (llevError, "Init_Artifacts: Could not load object.\n"); |
1399 | |
1405 | |
1400 | art->item->name = strchr (cp, ' ') + 1; |
1406 | art->item->name = strchr (cp, ' ') + 1; |
… | |
… | |
1489 | CLEAR_FLAG (op, FLAG_ANIMATE); |
1495 | CLEAR_FLAG (op, FLAG_ANIMATE); |
1490 | /* so artifacts will join */ |
1496 | /* so artifacts will join */ |
1491 | if (!QUERY_FLAG (op, FLAG_ALIVE)) |
1497 | if (!QUERY_FLAG (op, FLAG_ALIVE)) |
1492 | op->speed = 0.0; |
1498 | op->speed = 0.0; |
1493 | |
1499 | |
1494 | update_ob_speed (op); |
1500 | op->set_speed (op->speed); |
1495 | } |
1501 | } |
1496 | |
1502 | |
1497 | if (change->nrof) |
1503 | if (change->nrof) |
1498 | op->nrof = RANDOM () % ((int) change->nrof) + 1; |
1504 | op->nrof = RANDOM () % ((int) change->nrof) + 1; |
1499 | |
1505 | |
… | |
… | |
1511 | { |
1517 | { |
1512 | object *tmp_obj; |
1518 | object *tmp_obj; |
1513 | |
1519 | |
1514 | /* Remove any spells this object currently has in it */ |
1520 | /* Remove any spells this object currently has in it */ |
1515 | while (op->inv) |
1521 | while (op->inv) |
1516 | { |
|
|
1517 | tmp_obj = op->inv; |
|
|
1518 | tmp_obj->remove (); |
|
|
1519 | tmp_obj->destroy (0); |
1522 | op->inv->destroy (); |
1520 | } |
|
|
1521 | |
1523 | |
1522 | tmp_obj = arch_to_object (change->other_arch); |
1524 | tmp_obj = arch_to_object (change->other_arch); |
1523 | insert_ob_in_ob (tmp_obj, op); |
1525 | insert_ob_in_ob (tmp_obj, op); |
1524 | } |
1526 | } |
1525 | /* No harm setting this for potions/horns */ |
1527 | /* No harm setting this for potions/horns */ |
… | |
… | |
1804 | /* special_potion() - so that old potion code is still done right. */ |
1806 | /* special_potion() - so that old potion code is still done right. */ |
1805 | |
1807 | |
1806 | int |
1808 | int |
1807 | special_potion (object *op) |
1809 | special_potion (object *op) |
1808 | { |
1810 | { |
1809 | |
|
|
1810 | int i; |
|
|
1811 | |
|
|
1812 | if (op->attacktype) |
1811 | if (op->attacktype) |
1813 | return 1; |
1812 | return 1; |
1814 | |
1813 | |
1815 | 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) |
1816 | return 1; |
1815 | return 1; |
1817 | |
1816 | |
1818 | for (i = 0; i < NROFATTACKS; i++) |
1817 | for (int i = 0; i < NROFATTACKS; i++) |
1819 | if (op->resist[i]) |
1818 | if (op->resist[i]) |
1820 | return 1; |
1819 | return 1; |
1821 | |
1820 | |
1822 | return 0; |
1821 | return 0; |
1823 | } |
1822 | } |