… | |
… | |
1269 | artifactlist *al = NULL; |
1269 | artifactlist *al = NULL; |
1270 | artifact *art; |
1270 | artifact *art; |
1271 | int chance, i, type, index; |
1271 | int chance, i, type, index; |
1272 | int book_entries = level > 5 ? rndm (3) + rndm (3) + 2 : rndm (level) + 1; |
1272 | int book_entries = level > 5 ? rndm (3) + rndm (3) + 2 : rndm (level) + 1; |
1273 | const char *ch; |
1273 | const char *ch; |
1274 | char name[MAX_BUF], buf[BOOK_BUF], sbuf[MAX_BUF]; |
1274 | char name[MAX_BUF]; |
1275 | static char retbuf[BOOK_BUF]; |
|
|
1276 | object *tmp = NULL; |
1275 | object *tmp = NULL; |
|
|
1276 | |
|
|
1277 | static dynbuf_text buf; buf.clear (); |
1277 | |
1278 | |
1278 | /* values greater than 5 create msg buffers that are too big! */ |
1279 | /* values greater than 5 create msg buffers that are too big! */ |
1279 | if (book_entries > 5) |
1280 | if (book_entries > 5) |
1280 | book_entries = 5; |
1281 | book_entries = 5; |
1281 | |
1282 | |
… | |
… | |
1310 | |
1311 | |
1311 | /* the base 'generic' name for our artifact */ |
1312 | /* the base 'generic' name for our artifact */ |
1312 | assign (name, art_name_array[index].name); |
1313 | assign (name, art_name_array[index].name); |
1313 | |
1314 | |
1314 | /* Ok, lets print out the contents */ |
1315 | /* Ok, lets print out the contents */ |
1315 | sprintf (retbuf, "Herein %s detailed %s...\n", book_entries > 1 ? "are" : "is", book_entries > 1 ? "some artifacts" : "an artifact"); |
1316 | buf.printf ("Herein %s detailed %s...\n", |
|
|
1317 | book_entries > 1 ? "are" : "is", |
|
|
1318 | book_entries > 1 ? "some artifacts" : "an artifact"); |
1316 | |
1319 | |
1317 | /* artifact msg attributes loop. Lets keep adding entries to the 'book' |
1320 | /* artifact msg attributes loop. Lets keep adding entries to the 'book' |
1318 | * as long as we have space up to the allowed max # (book_entires) |
1321 | * as long as we have space up to the allowed max # (book_entires) |
1319 | */ |
1322 | */ |
1320 | while (book_entries > 0) |
1323 | while (book_entries > 0 && buf.size () < BOOK_BUF) |
1321 | { |
1324 | { |
1322 | |
1325 | |
1323 | if (art == NULL) |
1326 | if (!art) |
1324 | art = al->items; |
1327 | art = al->items; |
1325 | |
1328 | |
1326 | /* separator of items */ |
1329 | buf << '\n'; |
1327 | strcpy (buf, "--- \n"); |
|
|
1328 | |
1330 | |
1329 | /* Name */ |
1331 | /* Name */ |
1330 | if (art->allowed && art->allowed->name != shstr_All) |
1332 | if (art->allowed && art->allowed->name != shstr_All) |
1331 | { |
1333 | { |
1332 | linked_char *temp, *next = art->allowed; |
1334 | linked_char *temp, *next = art->allowed; |
… | |
… | |
1335 | { |
1337 | { |
1336 | temp = next; |
1338 | temp = next; |
1337 | next = next->next; |
1339 | next = next->next; |
1338 | } |
1340 | } |
1339 | while (next && rndm (2)); |
1341 | while (next && rndm (2)); |
|
|
1342 | |
1340 | sprintf (buf, "%s A %s of %s", buf, &temp->name, &art->item->name); |
1343 | buf.printf ("A B<< %s of %s >>", &temp->name, &art->item->name); |
1341 | } |
1344 | } |
1342 | else /* default name is used */ |
1345 | else /* default name is used */ |
1343 | sprintf (buf, "%s The %s of %s", buf, name, &art->item->name); |
1346 | buf.printf ("The B<< %s of %s >>", name, &art->item->name); |
|
|
1347 | |
|
|
1348 | buf << " is "; |
1344 | |
1349 | |
1345 | /* chance of finding */ |
1350 | /* chance of finding */ |
1346 | chance = (int) (100 * ((float) art->chance / al->total_chance)); |
1351 | chance = (int) (100 * ((float) art->chance / al->total_chance)); |
1347 | if (chance >= 20) |
1352 | if (chance >= 20) |
1348 | sprintf (sbuf, "an uncommon"); |
1353 | buf << "an uncommon"; |
1349 | else if (chance >= 10) |
1354 | else if (chance >= 10) |
1350 | sprintf (sbuf, "an unusual"); |
1355 | buf << "an unusual"; |
1351 | else if (chance >= 5) |
1356 | else if (chance >= 5) |
1352 | sprintf (sbuf, "a rare"); |
1357 | buf << "a rare"; |
1353 | else |
1358 | else |
1354 | sprintf (sbuf, "a very rare"); |
1359 | buf << "a very rare"; |
1355 | sprintf (buf, "%s is %s\n", buf, sbuf); |
|
|
1356 | |
1360 | |
1357 | /* value of artifact */ |
1361 | /* value of artifact */ |
1358 | sprintf (buf, "%s item with a value that is %d times normal.\n", buf, art->item->value); |
1362 | buf << " item with a value that is " << art->item->value << " times normal.\n"; |
1359 | |
1363 | |
1360 | /* include the message about the artifact, if exists, and book |
1364 | /* include the message about the artifact, if exists, and book |
1361 | * level is kinda high */ |
1365 | * level is kinda high */ |
1362 | if (art->item->msg |
1366 | if (art->item->msg |
1363 | && rndm (4) + 1 < level |
1367 | && rndm (4) + 1 < level) |
1364 | && !(strlen (art->item->msg) + strlen (buf) > BOOK_BUF)) |
|
|
1365 | strcat (buf, art->item->msg); |
1368 | buf << art->item->msg; |
1366 | |
1369 | |
1367 | /* properties of the artifact */ |
1370 | /* properties of the artifact */ |
1368 | tmp = object::create (); |
1371 | tmp = object::create (); |
1369 | add_abilities (tmp, art->item); |
1372 | add_abilities (tmp, art->item); |
1370 | tmp->type = type; |
1373 | tmp->type = type; |
1371 | SET_FLAG (tmp, FLAG_IDENTIFIED); |
1374 | SET_FLAG (tmp, FLAG_IDENTIFIED); |
1372 | if ((ch = describe_item (tmp, NULL)) != NULL && strlen (ch) > 1) |
1375 | if ((ch = describe_item (tmp, 0)) && strlen (ch) > 1) |
1373 | sprintf (buf, "%s Properties of this artifact include: \n %s \n", buf, ch); |
1376 | buf << "\rProperties of this artifact include:\r" << ch << "\n"; |
|
|
1377 | |
1374 | tmp->destroy (); |
1378 | tmp->destroy (); |
1375 | /* add the buf if it will fit */ |
|
|
1376 | if (!book_overflow (retbuf, buf, booksize)) |
|
|
1377 | strcat (retbuf, buf); |
|
|
1378 | else |
|
|
1379 | break; |
|
|
1380 | |
1379 | |
1381 | art = art->next; |
1380 | art = art->next; |
1382 | book_entries--; |
1381 | book_entries--; |
1383 | } |
1382 | } |
1384 | |
1383 | |
1385 | #ifdef BOOK_MSG_DEBUG |
|
|
1386 | LOG (llevDebug, "artifact_msg() created string: %d\n", strlen (retbuf)); |
|
|
1387 | LOG (llevDebug, " MADE THIS:\n%s", retbuf); |
|
|
1388 | #endif |
|
|
1389 | return retbuf; |
1384 | return buf; |
1390 | } |
1385 | } |
1391 | |
1386 | |
1392 | /***************************************************************************** |
1387 | /***************************************************************************** |
1393 | * Spellpath message generation |
1388 | * Spellpath message generation |
1394 | *****************************************************************************/ |
1389 | *****************************************************************************/ |
… | |
… | |
1398 | * a given spellpath. |
1393 | * a given spellpath. |
1399 | */ |
1394 | */ |
1400 | static char * |
1395 | static char * |
1401 | spellpath_msg (int level, int booksize) |
1396 | spellpath_msg (int level, int booksize) |
1402 | { |
1397 | { |
|
|
1398 | static dynbuf_text buf; buf.clear (); |
|
|
1399 | |
1403 | static char retbuf[BOOK_BUF]; |
1400 | static char retbuf[BOOK_BUF]; |
1404 | char tmpbuf[BOOK_BUF]; |
1401 | char tmpbuf[BOOK_BUF]; |
1405 | int path = rndm (NRSPELLPATHS), prayers = rndm (2); |
1402 | int path = rndm (NRSPELLPATHS), prayers = rndm (2); |
1406 | int did_first_sp = 0; |
|
|
1407 | uint32 pnum = (path == -1) ? PATH_NULL : spellpathdef[path]; |
1403 | uint32 pnum = (path == -1) ? PATH_NULL : spellpathdef[path]; |
1408 | archetype *at; |
1404 | archetype *at; |
1409 | |
1405 | |
1410 | /* Preamble */ |
1406 | /* Preamble */ |
1411 | sprintf (retbuf, "Herein are detailed the names of %s\n", prayers ? "prayers" : "incantations"); |
1407 | buf << "Herein are detailed the names of " |
|
|
1408 | << (prayers ? "prayers" : "incantations"); |
1412 | |
1409 | |
1413 | if (path == -1) |
1410 | if (path == -1) |
1414 | strcat (retbuf, "having no known spell path.\n"); |
1411 | buf << " having no known spell path.\n"; |
1415 | else |
1412 | else |
1416 | sprintf (retbuf, "%sbelonging to the path of %s:\n", retbuf, spellpathnames[path]); |
1413 | buf << " belonging to the path of B<< " << spellpathnames[path] << " >>:\n\n"; |
|
|
1414 | |
|
|
1415 | int seen = 0; |
1417 | |
1416 | |
1418 | for_all_archetypes (at) |
1417 | for_all_archetypes (at) |
1419 | { |
|
|
1420 | /* Determine if this is an appropriate spell. Must |
1418 | /* Determine if this is an appropriate spell. Must |
1421 | * be of matching path, must be of appropriate type (prayer |
1419 | * be of matching path, must be of appropriate type (prayer |
1422 | * or not), and must be within the valid level range. |
1420 | * or not), and must be within the valid level range. |
1423 | */ |
1421 | */ |
1424 | if (at->type == SPELL && at->path_attuned & pnum && |
1422 | if (at->type == SPELL && at->path_attuned & pnum && |
1425 | ((at->stats.grace && prayers) || (at->stats.sp && !prayers)) && (at->level < (level * 8))) |
1423 | ((at->stats.grace && prayers) || (at->stats.sp && !prayers)) && (at->level < (level * 8))) |
1426 | { |
1424 | { |
1427 | assign (tmpbuf, at->object::name); |
1425 | seen = 1; |
1428 | |
1426 | buf << at->object::name << '\r'; |
1429 | if (book_overflow (retbuf, tmpbuf, booksize)) |
|
|
1430 | break; |
|
|
1431 | else |
|
|
1432 | { |
|
|
1433 | if (did_first_sp) |
|
|
1434 | strcat (retbuf, ",\n"); |
|
|
1435 | did_first_sp = 1; |
|
|
1436 | strcat (retbuf, tmpbuf); |
|
|
1437 | } |
|
|
1438 | } |
1427 | } |
1439 | } |
1428 | |
1440 | /* Geez, no spells were generated. */ |
1429 | /* Geez, no spells were generated. */ |
1441 | if (!did_first_sp) |
1430 | if (!seen) |
1442 | { |
|
|
1443 | if (rndm (4)) /* usually, lets make a recursive call... */ |
1431 | if (rndm (4)) /* usually, lets make a recursive call... */ |
1444 | spellpath_msg (level, booksize); |
1432 | return spellpath_msg (level, booksize); |
1445 | else /* give up, cause knowing no spells exist for path is info too. */ |
1433 | else /* give up, cause knowing no spells exist for path is info too. */ |
1446 | strcat (retbuf, "\n - no known spells exist -\n"); |
1434 | buf << "- no known spells exist.\n"; |
1447 | } |
|
|
1448 | else |
|
|
1449 | { |
|
|
1450 | strcat (retbuf, "\n"); |
|
|
1451 | } |
|
|
1452 | |
1435 | |
1453 | #ifdef BOOK_MSG_DEBUG |
|
|
1454 | LOG (llevDebug, "spellpath_msg() created string: %d\n", strlen (retbuf)); |
|
|
1455 | LOG (llevDebug, " MADE THIS:\n%s", retbuf); |
|
|
1456 | #endif |
|
|
1457 | return retbuf; |
1436 | return buf; |
1458 | } |
1437 | } |
1459 | |
1438 | |
1460 | /* formula_msg() - generate a message detailing the properties |
1439 | /* formula_msg() - generate a message detailing the properties |
1461 | * of a randomly selected alchemical formula. |
1440 | * of a randomly selected alchemical formula. |
1462 | */ |
1441 | */ |
… | |
… | |
1836 | * 3) make sure there are entries for your case in new_text_title() |
1815 | * 3) make sure there are entries for your case in new_text_title() |
1837 | * and add_authour(). |
1816 | * and add_authour(). |
1838 | * 4) you may want separate authour/book name arrays in read.h |
1817 | * 4) you may want separate authour/book name arrays in read.h |
1839 | */ |
1818 | */ |
1840 | msg_type = msg_type > 0 ? msg_type : rndm (8); |
1819 | msg_type = msg_type > 0 ? msg_type : rndm (8); |
1841 | switch (msg_type) |
1820 | switch (msg_type*0+2)//D |
1842 | { |
1821 | { |
1843 | case 1: /* monster attrib */ |
1822 | case 1: /* monster attrib */ |
1844 | strcpy (msgbuf, mon_info_msg (level, book_buf_size)); |
1823 | strcpy (msgbuf, mon_info_msg (level, book_buf_size)); |
1845 | break; |
1824 | break; |
1846 | case 2: /* artifact attrib */ |
1825 | case 2: /* artifact attrib */ |