ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/common/readable.C
(Generate patch)

Comparing deliantra/server/common/readable.C (file contents):
Revision 1.45 by root, Thu Oct 15 22:50:41 2009 UTC vs.
Revision 1.52 by root, Fri Nov 6 13:31:47 2009 UTC

108/* these are needed for creation of a linked list of 108/* these are needed for creation of a linked list of
109 * pointers to all (hostile) monster objects */ 109 * pointers to all (hostile) monster objects */
110 110
111static int nrofmon = 0, need_to_write_bookarchive = 0; 111static int nrofmon = 0, need_to_write_bookarchive = 0;
112 112
113
114/* this is needed to keep track of status of initialisation
115 * of the message file */
116static int nrofmsg = 0;
117
118/* first_msg is the started of the linked list of messages as read from 113/* first_msg is the started of the linked list of messages as read from
119 * the messages file 114 * the messages file
120 */ 115 */
121static linked_char *first_msg = NULL; 116static linked_char *first_msg = NULL;
122 117
123/* 118/*
124 * Spellpath information 119 * Spellpath information
125 */ 120 */
126
127static uint32 spellpathdef[NRSPELLPATHS] = { 121static uint32 spellpathdef[NRSPELLPATHS] = {
128 PATH_PROT, 122 PATH_PROT,
129 PATH_FIRE, 123 PATH_FIRE,
130 PATH_FROST, 124 PATH_FROST,
131 PATH_ELEC, 125 PATH_ELEC,
497 /*subtype 50 */ {MSG_TYPE_MONUMENT, MSG_TYPE_MONUMENT_GRAVESTONE_3, "readable-monument-gravestone-3"}, 491 /*subtype 50 */ {MSG_TYPE_MONUMENT, MSG_TYPE_MONUMENT_GRAVESTONE_3, "readable-monument-gravestone-3"},
498 {MSG_TYPE_MONUMENT, MSG_TYPE_MONUMENT_WALL_1, "readable-monument-wall-1"}, 492 {MSG_TYPE_MONUMENT, MSG_TYPE_MONUMENT_WALL_1, "readable-monument-wall-1"},
499 {MSG_TYPE_MONUMENT, MSG_TYPE_MONUMENT_WALL_2, "readable-monument-wall-2"}, 493 {MSG_TYPE_MONUMENT, MSG_TYPE_MONUMENT_WALL_2, "readable-monument-wall-2"},
500 {MSG_TYPE_MONUMENT, MSG_TYPE_MONUMENT_WALL_3, "readable-monument-wall-3"} 494 {MSG_TYPE_MONUMENT, MSG_TYPE_MONUMENT_WALL_3, "readable-monument-wall-3"}
501}; 495};
502int last_readable_subtype = sizeof (readable_message_types) / sizeof (readable_message_type); 496static int last_readable_subtype = sizeof (readable_message_types) / sizeof (readable_message_type);
503 497
504static int max_titles[6] = { 498static int max_titles[6] = {
505 ((sizeof (light_book_name) / sizeof (char *)) + (sizeof (heavy_book_name) / sizeof (char *))) * (sizeof (book_author) / sizeof (char *)), 499 ((sizeof (light_book_name) / sizeof (char *)) + (sizeof (heavy_book_name) / sizeof (char *))) * (sizeof (book_author) / sizeof (char *)),
506 (sizeof (mon_book_name) / sizeof (char *)) * (sizeof (mon_author) / sizeof (char *)), 500 (sizeof (mon_book_name) / sizeof (char *)) * (sizeof (mon_author) / sizeof (char *)),
507 (sizeof (art_book_name) / sizeof (char *)) * (sizeof (art_author) / sizeof (char *)), 501 (sizeof (art_book_name) / sizeof (char *)) * (sizeof (art_author) / sizeof (char *)),
617 else 611 else
618 strcat (rbuf, "."); 612 strcat (rbuf, ".");
619 tbuf = strtok (NULL, sbuf); 613 tbuf = strtok (NULL, sbuf);
620 } 614 }
621 return (char *) rbuf; 615 return (char *) rbuf;
622}
623
624static int
625book_overflow (const char *buf1, const char *buf2, int booksize)
626{
627 if (buf_overflow (buf1, buf2, BOOK_BUF - 2) /* 2 less so always room for trailing \n */
628 || buf_overflow (buf1, buf2, booksize))
629 return 1;
630
631 return 0;
632} 616}
633 617
634/***************************************************************************** 618/*****************************************************************************
635 * 619 *
636 * Start of initialisation related functions. 620 * Start of initialisation related functions.
731} 715}
732 716
733/* init_mon_info() - creates the linked list of pointers to 717/* init_mon_info() - creates the linked list of pointers to
734 * monster archetype objects if not called previously 718 * monster archetype objects if not called previously
735 */ 719 */
736
737static void 720static void
738init_mon_info (void) 721init_mon_info ()
739{ 722{
740 archetype *at; 723 archetype *at;
741 static int did_init_mon_info = 0; 724 static int did_init_mon_info = 0;
742 725
743 if (did_init_mon_info) 726 if (did_init_mon_info)
744 return; 727 return;
745 728
746 did_init_mon_info = 1; 729 did_init_mon_info = 1;
747 730
748 for_all_archetypes (at) 731 for_all_archetypes (at)
749 { 732 if (at->flag [FLAG_MONSTER]
750 if (QUERY_FLAG (at, FLAG_MONSTER) && (!QUERY_FLAG (at, FLAG_CHANGING) || QUERY_FLAG (at, FLAG_UNAGGRESSIVE))) 733 && at->is_head ()
734 && (!at->flag [FLAG_CHANGING] || at->flag [FLAG_UNAGGRESSIVE]))
751 { 735 {
752 objectlink *mon = new objectlink; 736 objectlink *mon = new objectlink;
753 737
754 mon->ob = at; 738 mon->ob = at;
755 mon->next = first_mon_info; 739 mon->next = first_mon_info;
756 first_mon_info = mon; 740 first_mon_info = mon;
757 nrofmon++; 741 nrofmon++;
758 } 742 }
759 }
760 743
761 LOG (llevDebug, "init_mon_info() got %d monsters\n", nrofmon); 744 LOG (llevDebug, "init_mon_info() got %d monsters\n", nrofmon);
762} 745}
763 746
764/* init_readable() - initialise linked lists utilized by 747/* init_readable() - initialise linked lists utilized by
1215 break; 1198 break;
1216 1199
1217 /* didn't find a match */ 1200 /* didn't find a match */
1218 if (!mon) 1201 if (!mon)
1219 return NULL; 1202 return NULL;
1203
1220 if (mon->next) 1204 if (mon->next)
1221 return mon->next->ob; 1205 return mon->next->ob;
1222 else 1206 else
1223 return first_mon_info->ob; 1207 return first_mon_info->ob;
1224 1208
1226 1210
1227/* mon_info_msg() - generate a message detailing the properties 1211/* mon_info_msg() - generate a message detailing the properties
1228 * of a randomly selected monster. 1212 * of a randomly selected monster.
1229 */ 1213 */
1230static const char * 1214static const char *
1231mon_info_msg (int level, int booksize) 1215mon_info_msg (int level)
1232{ 1216{
1233 static dynbuf_text buf; buf.clear (); 1217 static dynbuf_text buf; buf.clear ();
1234 1218
1235 /*preamble */ 1219 /*preamble */
1236 buf << "This beastiary contains:\n"; 1220 buf << "This beastiary contains:\n";
1262 1246
1263/* artifact_msg() - generate a message detailing the properties 1247/* artifact_msg() - generate a message detailing the properties
1264 * of 1-6 artifacts drawn sequentially from the artifact list. 1248 * of 1-6 artifacts drawn sequentially from the artifact list.
1265 */ 1249 */
1266static const char * 1250static const char *
1267artifact_msg (int level, int booksize) 1251artifact_msg (int level)
1268{ 1252{
1269 artifactlist *al = NULL; 1253 artifactlist *al = NULL;
1270 artifact *art; 1254 artifact *art;
1271 int chance, i, type, index; 1255 int chance, i, type, index;
1272 int book_entries = level > 5 ? rndm (3) + rndm (3) + 2 : rndm (level) + 1; 1256 int book_entries = level > 5 ? rndm (3) + rndm (3) + 2 : rndm (level) + 1;
1391/* spellpath_msg() - generate a message detailing the member 1375/* spellpath_msg() - generate a message detailing the member
1392 * incantations/prayers (and some of their properties) belonging to 1376 * incantations/prayers (and some of their properties) belonging to
1393 * a given spellpath. 1377 * a given spellpath.
1394 */ 1378 */
1395static char * 1379static char *
1396spellpath_msg (int level, int booksize) 1380spellpath_msg (int level)
1397{ 1381{
1398 static dynbuf_text buf; buf.clear (); 1382 static dynbuf_text buf; buf.clear ();
1399 1383
1400 static char retbuf[BOOK_BUF]; 1384 static char retbuf[BOOK_BUF];
1401 char tmpbuf[BOOK_BUF]; 1385 char tmpbuf[BOOK_BUF];
1427 } 1411 }
1428 1412
1429 /* Geez, no spells were generated. */ 1413 /* Geez, no spells were generated. */
1430 if (!seen) 1414 if (!seen)
1431 if (rndm (4)) /* usually, lets make a recursive call... */ 1415 if (rndm (4)) /* usually, lets make a recursive call... */
1432 return spellpath_msg (level, booksize); 1416 return spellpath_msg (level);
1433 else /* give up, cause knowing no spells exist for path is info too. */ 1417 else /* give up, cause knowing no spells exist for path is info too. */
1434 buf << "- no known spells exist.\n"; 1418 buf << "- no known spells exist.\n";
1435 1419
1436 return buf; 1420 return buf;
1437} 1421}
1440 * of a randomly selected alchemical formula. 1424 * of a randomly selected alchemical formula.
1441 */ 1425 */
1442static void 1426static void
1443make_formula_book (object *book, int level) 1427make_formula_book (object *book, int level)
1444{ 1428{
1445 char retbuf[BOOK_BUF], title[MAX_BUF]; 1429 char title[MAX_BUF];
1446 recipelist *fl; 1430 recipelist *fl;
1447 recipe *formula = NULL; 1431 recipe *formula = NULL;
1448 int chance; 1432 int chance;
1433
1434 static dynbuf_text buf; buf.clear ();
1449 1435
1450 /* the higher the book level, the more complex (ie number of 1436 /* the higher the book level, the more complex (ie number of
1451 * ingredients) the formula can be. 1437 * ingredients) the formula can be.
1452 */ 1438 */
1453 fl = get_formulalist (rndm (level) / 3 + 1); 1439 fl = get_formulalist (rndm (level) / 3 + 1);
1466 /* get a random formula, weighted by its bookchance */ 1452 /* get a random formula, weighted by its bookchance */
1467 chance = rndm (fl->total_chance); 1453 chance = rndm (fl->total_chance);
1468 for (formula = fl->items; formula; formula = formula->next) 1454 for (formula = fl->items; formula; formula = formula->next)
1469 { 1455 {
1470 chance -= formula->chance; 1456 chance -= formula->chance;
1457
1471 if (chance <= 0) 1458 if (chance <= 0)
1472 break; 1459 break;
1473 } 1460 }
1474 1461
1475 if (!formula || formula->arch_names <= 0) 1462 if (!formula || formula->arch_names <= 0)
1476 { 1463 {
1477 book->msg = "<indecipherable text>\n"; 1464 book->msg = "<indecipherable text>\n";
1478 new_text_name (book, 4); 1465 new_text_name (book, 4);
1479 add_author (book, 4); 1466 add_author (book, 4);
1480 1467 return;
1481 } 1468 }
1469
1470 /* looks like a formula was found. Base the amount
1471 * of information on the booklevel and the spellevel
1472 * of the formula. */
1473
1474 const char *op_name = formula->arch_name [rndm (formula->arch_names)];
1475 archetype *at;
1476
1477 /* preamble */
1478 buf << "Herein is described a project using B<< "
1479 << (formula->skill ? &formula->skill : "an unknown skill")
1480 << " >>:\n\n";
1481
1482 if ((at = archetype::find (op_name)))
1483 op_name = at->object::name;
1482 else 1484 else
1485 LOG (llevError, "formula_msg() can't find arch %s for formula.\n", op_name);
1486
1487 /* item name */
1488 if (formula->title != shstr_NONE)
1489 {
1490 buf.printf ("The B<< %s of %s >>", op_name, &formula->title);
1491 /* This results in things like pile of philo. sulfur.
1492 * while philo. sulfur may look better, without this,
1493 * you get things like 'the wise' because its missing the
1494 * water of section.
1495 */
1496 sprintf (title, "%s: %s of %s",
1497 formula_book_name [rndm (sizeof (formula_book_name) / sizeof (char *))], op_name, &formula->title);
1483 { 1498 }
1484 /* looks like a formula was found. Base the amount 1499 else
1485 * of information on the booklevel and the spellevel 1500 {
1486 * of the formula. */ 1501 buf << "The B<< " << op_name;
1487 1502
1488 const char *op_name = formula->arch_name [rndm (formula->arch_names)]; 1503 sprintf (title, "%s: %s", formula_book_name [rndm (sizeof (formula_book_name) / sizeof (char *))], op_name);
1504 if (at->title)
1505 {
1506 buf << " " << at->title;
1507 strcat (title, " ");
1508 strcat (title, at->title);
1509 }
1510
1511 buf << " >>";
1512 }
1513
1514 /* Lets name the book something meaningful ! */
1515 book->name = title;
1516 book->title = NULL;
1517
1518 /* ingredients to make it */
1519 if (formula->ingred)
1520 {
1521 linked_char *next;
1489 archetype *at; 1522 archetype *at;
1490 1523
1491 /* preamble */
1492 sprintf (retbuf, "Herein is described a project using %s: \n", formula->skill ? &formula->skill : "an unknown skill");
1493
1494 if ((at = archetype::find (op_name)) != (archetype *) NULL)
1495 op_name = at->object::name;
1496 else
1497 LOG (llevError, "formula_msg() can't find arch %s for formula.\n", op_name);
1498
1499 /* item name */
1500 if (formula->title != shstr_NONE)
1501 {
1502 sprintf (retbuf, "%sThe %s of %s", retbuf, op_name, &formula->title);
1503 /* This results in things like pile of philo. sulfur.
1504 * while philo. sulfur may look better, without this,
1505 * you get things like 'the wise' because its missing the
1506 * water of section.
1507 */
1508 sprintf (title, "%s: %s of %s",
1509 formula_book_name [rndm (sizeof (formula_book_name) / sizeof (char *))], op_name, &formula->title);
1510 }
1511 else
1512 {
1513 sprintf (retbuf, "%sThe %s", retbuf, op_name);
1514 sprintf (title, "%s: %s", formula_book_name [rndm (sizeof (formula_book_name) / sizeof (char *))], op_name);
1515 if (at->title)
1516 {
1517 strcat (retbuf, " ");
1518 strcat (retbuf, at->title);
1519 strcat (title, " ");
1520 strcat (title, at->title);
1521 }
1522 }
1523
1524 /* Lets name the book something meaningful ! */
1525 book->name = title;
1526 book->title = NULL;
1527
1528 /* ingredients to make it */
1529 if (formula->ingred != NULL)
1530 {
1531 linked_char *next;
1532 archetype *at;
1533
1534 at = archetype::find (formula->cauldron); 1524 at = archetype::find (formula->cauldron);
1535 1525
1536 sprintf (retbuf + strlen (retbuf), 1526 buf.printf (" may be made at %s using the following ingredients:\n\n",
1537 " may be made at %s using the following ingredients:\n", at ? query_name (at) : "an unknown place"); 1527 at ? query_name (at) : "an appropriate place");
1538 1528
1539 for (next = formula->ingred; next != NULL; next = next->next) 1529 for (next = formula->ingred; next; next = next->next)
1540 { 1530 buf << next->name << '\r';
1541 strcat (retbuf, next->name); 1531 }
1542 strcat (retbuf, "\n");
1543 }
1544 }
1545 else 1532 else
1546 LOG (llevError, "formula_msg() no ingredient list for object %s of %s\n", op_name, &formula->title); 1533 LOG (llevError, "formula_msg() no ingredient list for object %s of %s\n", op_name, &formula->title);
1547 if (retbuf[strlen (retbuf) - 1] != '\n')
1548 strcat (retbuf, "\n");
1549 1534
1550 book->msg = retbuf; 1535 book->msg = buf;
1551 }
1552} 1536}
1553 1537
1554#define DESCRIBE_PATH(retbuf, variable, name) \ 1538#define DESCRIBE_PATH(retbuf, variable, name) \
1555 if(variable) { \ 1539 if(variable) { \
1556 int i,j=0; \ 1540 int i,j=0; \
1568 1552
1569/* god_info_msg() - generate a message detailing the properties 1553/* god_info_msg() - generate a message detailing the properties
1570 * of a random god. Used by the book hack. b.t. 1554 * of a random god. Used by the book hack. b.t.
1571 */ 1555 */
1572static const char * 1556static const char *
1573god_info_msg (int level, int booksize) 1557god_info_msg (int level)
1574{ 1558{
1575 static char retbuf[BOOK_BUF];
1576 const char *name = NULL; 1559 const char *name = NULL;
1577 char buf[BOOK_BUF];
1578 int i;
1579 size_t introlen;
1580 object *god = pntr_to_god_obj (get_rand_god ()); 1560 object *god = pntr_to_god_obj (get_rand_god ());
1581 1561
1562 static dynbuf_text buf; buf.clear ();
1563
1582 if (!god) 1564 if (!god)
1583 return (char *) NULL; /* oops, problems... */ 1565 return 0; /* oops, problems... */
1566
1584 name = god->name; 1567 name = god->name;
1585 1568
1586 /* preamble.. */ 1569 /* preamble.. */
1587 sprintf (retbuf, "This document contains knowledge concerning\n"); 1570 buf << "This document contains knowledge concerning the diety B<< "
1588 sprintf (retbuf, "%sthe diety %s", retbuf, name); 1571 << name << " >>";
1589 1572
1590 /* Always have as default information the god's descriptive terms. */ 1573 /* Always have as default information the god's descriptive terms. */
1591 if (nstrtok (god->msg, ",") > 0) 1574 if (nstrtok (god->msg, ",") > 0)
1592 { 1575 buf << ", known as" << strtoktolin (god->msg, ",");
1593 strcat (retbuf, ", known as");
1594 strcat (retbuf, strtoktolin (god->msg, ","));
1595 }
1596 else 1576 else
1597 strcat (retbuf, "..."); 1577 buf << "...";
1598 1578
1599 strcat (retbuf, "\n ---\n"); 1579 buf << "\n\n";
1580
1600 introlen = strlen (retbuf); /* so we will know if no new info is added later */ 1581 int introlen = buf.size (); /* so we will know if no new info is added later */
1601 1582
1602 /* Information about the god is random, and based on the level of the 1583 /* Information about the god is random, and based on the level of the
1603 * 'book'. Probably there is a more intellegent way to implement 1584 * 'book'. Probably there is a more intellegent way to implement
1604 * this ... 1585 * this ...
1605 */ 1586 */
1606 while (level > 0) 1587 while (level > 0 && buf.size () < BOOK_BUF)
1607 { 1588 {
1608 sprintf (buf, " ");
1609 if (level == 2 && rndm (2)) 1589 if (level == 2 && rndm (2))
1610 { /* enemy god */ 1590 { /* enemy god */
1611 const char *enemy = god->title; 1591 const char *enemy = god->title;
1612 1592
1613 if (enemy) 1593 if (enemy)
1614 sprintf (buf, "The gods %s and %s are enemies.\n ---\n", name, enemy); 1594 buf.printf ("The gods %s and %s are enemies.\r", name, enemy);
1615 } 1595 }
1616 1596
1617 if (level == 3 && rndm (2)) 1597 if (level == 3 && rndm (2))
1618 { /* enemy race, what the god's holy word effects */ 1598 { /* enemy race, what the god's holy word effects */
1619 const char *enemy = god->slaying; 1599 const char *enemy = god->slaying;
1600 int i;
1620 1601
1621 if (enemy && !(god->path_denied & PATH_TURNING)) 1602 if (enemy && !(god->path_denied & PATH_TURNING))
1622 if ((i = nstrtok (enemy, ",")) > 0) 1603 if ((i = nstrtok (enemy, ",")) > 0)
1623 { 1604 {
1624 char tmpbuf[MAX_BUF]; 1605 char tmpbuf[MAX_BUF];
1625 1606
1626 sprintf (buf, "The holy words of %s have the power to\n", name); 1607 buf << "The holy words of " << name
1627 strcat (buf, "slay creatures belonging to the "); 1608 << " have the power to slay creatures belonging to the ";
1609
1628 if (i > 1) 1610 if (i > 1)
1629 sprintf (tmpbuf, "following \n races:%s", strtoktolin (enemy, ",")); 1611 buf << "following races:" << strtoktolin (enemy, ",");
1630 else 1612 else
1631 sprintf (tmpbuf, "race of%s", strtoktolin (enemy, ",")); 1613 buf << "race of" << strtoktolin (enemy, ",");
1632 sprintf (buf, "%s%s\n ---\n", buf, tmpbuf); 1614
1615 buf << '\r';
1633 } 1616 }
1634 } 1617 }
1635 1618
1636 if (level == 4 && rndm (2)) 1619 if (level == 4 && rndm (2))
1637 { /* Priest of god gets these protect,vulnerable... */ 1620 { /* Priest of god gets these protect,vulnerable... */
1638 char tmpbuf[MAX_BUF];
1639
1640 if (const char *cp = describe_resistance (god, 1)) 1621 if (const char *cp = describe_resistance (god, 1))
1641 { /* This god does have protections */ 1622 { /* This god does have protections */
1642 sprintf (tmpbuf, "%s has a potent aura which is extended\n", name); 1623 buf << name
1624 << " has a potent aura which is extended to"
1643 strcat (tmpbuf, "faithful priests. The effects of this aura include:\n"); 1625 " faithful priests. The effects of this aura include: "
1644 strcat (tmpbuf, cp); 1626 << cp
1645 strcat (buf, tmpbuf); 1627 << ".\r";
1646 strcat (buf, "\n ---\n");
1647 } 1628 }
1648 else
1649 sprintf (buf, " ");
1650 } 1629 }
1651 1630
1652 if (level == 5 && rndm (2)) 1631 if (level == 5 && rndm (2))
1653 { /* aligned race, summoning */ 1632 { /* aligned race, summoning */
1654 const char *race = god->race; /* aligned race */ 1633 const char *race = god->race; /* aligned race */
1634 int i;
1655 1635
1656 if (race && !(god->path_denied & PATH_SUMMON)) 1636 if (race && !(god->path_denied & PATH_SUMMON))
1657 if ((i = nstrtok (race, ",")) > 0) 1637 if ((i = nstrtok (race, ",")) > 0)
1658 { 1638 {
1659 char tmpbuf[MAX_BUF]; 1639 buf << "Creatures sacred to " << name << " include the ";
1660
1661 sprintf (buf, "Creatures sacred to %s include the \n", name);
1662 if (i > 1) 1640 if (i > 1)
1663 sprintf (tmpbuf, "following \n races:%s", strtoktolin (race, ",")); 1641 buf << "following races:" << strtoktolin (race, ",");
1664 else 1642 else
1665 sprintf (tmpbuf, "race of%s", strtoktolin (race, ",")); 1643 buf << "race of" << strtoktolin (race, ",");
1666 sprintf (buf, "%s%s\n ---\n", buf, tmpbuf); 1644
1645 buf << '\r';
1667 } 1646 }
1668 } 1647 }
1669 1648
1670 if (level == 6 && rndm (2)) 1649 if (level == 6 && rndm (2))
1671 { /* blessing,curse properties of the god */ 1650 { /* blessing,curse properties of the god */
1672 char tmpbuf[MAX_BUF];
1673
1674 if (const char *cp = describe_resistance (god, 1)) 1651 if (const char *cp = describe_resistance (god, 1))
1675 { /* This god does have protections */ 1652 { /* This god does have protections */
1676 sprintf (tmpbuf, "\nThe priests of %s are known to be able to \n", name); 1653 buf << "The priests of " << name
1654 << " are known to be able to "
1677 strcat (tmpbuf, "bestow a blessing which makes the recipient\n"); 1655 "bestow a blessing which makes the recipient "
1678 strcat (tmpbuf, cp); 1656 << cp
1679 strcat (buf, tmpbuf); 1657 << '\r';
1680 strcat (buf, "\n ---\n");
1681 } 1658 }
1682 else
1683 sprintf (buf, " ");
1684
1685 } 1659 }
1686 1660
1687 if (level == 8 && rndm (2)) 1661 if (level == 8 && rndm (2))
1688 { /* immunity, holy possession */ 1662 { /* immunity, holy possession */
1689 int has_effect = 0, tmpvar; 1663 buf << "The priests of " << name
1690 char tmpbuf[MAX_BUF]; 1664 << " are known to make cast a mighty"
1665 " prayer of possession";
1666
1667 int first = 1;
1691 1668
1692 sprintf (tmpbuf, "\n");
1693 sprintf (tmpbuf, "The priests of %s are known to make cast a mighty \n", name);
1694
1695 strcat (tmpbuf, "prayer of possession which gives the recipient\n");
1696
1697 for (tmpvar = 0; tmpvar < NROFATTACKS; tmpvar++) 1669 for (int i = 0; i < NROFATTACKS; i++)
1670 if (god->resist[i] == 100)
1698 { 1671 {
1699 if (god->resist[tmpvar] == 100) 1672 if (first)
1700 { 1673 {
1674 buf << " which gives the recipient";
1701 has_effect = 1; 1675 first = 0;
1702 sprintf (tmpbuf + strlen (tmpbuf), "Immunity to %s", attacktype_desc[tmpvar]);
1703 } 1676 }
1677 else
1678 buf << ", ";
1679
1680 buf << " immunity to " << attacktype_desc[i];
1704 } 1681 }
1705 1682
1706 if (has_effect) 1683 buf << ".\r";
1707 {
1708 strcat (buf, tmpbuf);
1709 strcat (buf, "\n ---\n");
1710 }
1711 else
1712 sprintf (buf, " ");
1713 } 1684 }
1714 1685
1715 if (level == 12 && rndm (2)) 1686 if (level == 12 && rndm (2))
1716 { /* spell paths */ 1687 { /* spell paths */
1688 //TODO:
1717 int has_effect = 0, tmpvar; 1689 int has_effect = 0, tmpvar;
1718 char tmpbuf[MAX_BUF]; 1690 char tmpbuf[MAX_BUF];
1719 1691
1720 sprintf (tmpbuf, "\n"); 1692 sprintf (tmpbuf, "\n");
1721 sprintf (tmpbuf, "It is rarely known fact that the priests of %s\n", name); 1693 sprintf (tmpbuf, "It is rarely known fact that the priests of %s\n", name);
1738 has_effect = 1; 1710 has_effect = 1;
1739 DESCRIBE_PATH (tmpbuf, tmpvar, "Denied"); 1711 DESCRIBE_PATH (tmpbuf, tmpvar, "Denied");
1740 } 1712 }
1741 1713
1742 if (has_effect) 1714 if (has_effect)
1743 { 1715 buf << tmpbuf << '\r';
1744 strcat (buf, tmpbuf);
1745 strcat (buf, "\n ---\n");
1746 }
1747 else 1716 else
1748 sprintf (buf, " "); 1717 buf << '\r';
1749 } 1718 }
1750 1719
1751 /* check to be sure new buffer size dont exceed either
1752 * the maximum buffer size, or the 'natural' size of the
1753 * book...
1754 */
1755 if (book_overflow (retbuf, buf, booksize))
1756 break;
1757 else if (strlen (buf) > 1)
1758 strcat (retbuf, buf);
1759
1760 level--; 1720 level--;
1761 } 1721 }
1762 1722
1763 if (strlen (retbuf) == introlen) 1723 if (buf.size () == introlen)
1764 { /* we got no information beyond the preamble! */ 1724 /* we got no information beyond the preamble! */
1765 strcat (retbuf, " [Unfortunately the rest of the information is\n"); 1725 buf << "[Unfortunately the rest of the information is hopelessly garbled!]";
1766 strcat (retbuf, " hopelessly garbled!]\n ---\n"); 1726
1767 }
1768#ifdef BOOK_MSG_DEBUG
1769 LOG (llevDebug, "\n god_info_msg() created string: %d\n", strlen (retbuf));
1770 LOG (llevDebug, " MADE THIS:\n%s", retbuf);
1771#endif
1772 return retbuf; 1727 return buf;
1773} 1728}
1774 1729
1775/* tailor_readable_ob()- The main routine. This chooses a random 1730/* tailor_readable_ob()- The main routine. This chooses a random
1776 * message to put in given readable object (type==BOOK) which will 1731 * message to put in given readable object (type==BOOK) which will
1777 * be referred hereafter as a 'book'. We use the book level to de- 1732 * be referred hereafter as a 'book'. We use the book level to de-
1789 * 1744 *
1790 */ 1745 */
1791void 1746void
1792tailor_readable_ob (object *book, int msg_type) 1747tailor_readable_ob (object *book, int msg_type)
1793{ 1748{
1794 char msgbuf[BOOK_BUF];
1795 int level = book->level ? rndm (book->level) + 1 : 1; 1749 int level = book->level ? rndm (book->level) + 1 : 1;
1796 int book_buf_size;
1797 1750
1798 /* safety */ 1751 /* safety */
1799 if (book->type != BOOK) 1752 if (book->type != BOOK)
1800 return; 1753 return;
1801 1754
1802 if (level <= 0) 1755 if (level <= 0)
1803 return; /* if no level no point in doing any more... */ 1756 return; /* if no level no point in doing any more... */
1804
1805 /* Max text length this book can have. */
1806 book_buf_size = BOOKSIZE (book);
1807 1757
1808 /* &&& The message switch &&& */ 1758 /* &&& The message switch &&& */
1809 /* Below all of the possible types of messages in the "book"s. 1759 /* Below all of the possible types of messages in the "book"s.
1810 */ 1760 */
1811 /* 1761 /*
1814 * 2) make sure there is an entry in max_titles[] array. 1764 * 2) make sure there is an entry in max_titles[] array.
1815 * 3) make sure there are entries for your case in new_text_title() 1765 * 3) make sure there are entries for your case in new_text_title()
1816 * and add_authour(). 1766 * and add_authour().
1817 * 4) you may want separate authour/book name arrays in read.h 1767 * 4) you may want separate authour/book name arrays in read.h
1818 */ 1768 */
1769 const char *new_msg = "";
1819 msg_type = msg_type > 0 ? msg_type : rndm (8); 1770 msg_type = msg_type > 0 ? msg_type : rndm (8);
1820 switch (msg_type*0+2)//D 1771 switch (msg_type)
1821 { 1772 {
1822 case 1: /* monster attrib */ 1773 case 1: /* monster attrib */
1823 strcpy (msgbuf, mon_info_msg (level, book_buf_size)); 1774 new_msg = mon_info_msg (level);
1824 break; 1775 break;
1825 case 2: /* artifact attrib */ 1776 case 2: /* artifact attrib */
1826 strcpy (msgbuf, artifact_msg (level, book_buf_size)); 1777 new_msg = artifact_msg (level);
1827 break; 1778 break;
1828 case 3: /* grouping incantations/prayers by path */ 1779 case 3: /* grouping incantations/prayers by path */
1829 strcpy (msgbuf, spellpath_msg (level, book_buf_size)); 1780 new_msg = spellpath_msg (level);
1830 break; 1781 break;
1831 case 4: /* describe an alchemy formula */ 1782 case 4: /* describe an alchemy formula */
1832 make_formula_book (book, level); 1783 make_formula_book (book, level);
1833 /* make_formula_book already gives title */ 1784 /* make_formula_book already gives title */
1834 return; 1785 return;
1835 break;
1836 case 5: /* bits of information about a god */ 1786 case 5: /* bits of information about a god */
1837 strcpy (msgbuf, god_info_msg (level, book_buf_size)); 1787 new_msg = god_info_msg (level);
1838 break; 1788 break;
1839 case 0: /* use info list in lib/ */ 1789 case 0: /* use info list in lib/ */
1840 default: 1790 default:
1841 cfperl_make_book (book, level); 1791 cfperl_make_book (book, level);
1792 /* already gives title */
1842 return; 1793 return;
1843 } 1794 }
1844 1795
1845 strcat (msgbuf, "\n"); /* safety -- we get ugly map saves/crashes w/o this */
1846
1847 if (strlen (msgbuf) > 1) 1796 if (strlen (new_msg) > 1)
1848 { 1797 {
1849 book->msg = msgbuf; 1798 book->msg = new_msg;
1850 /* lets give the "book" a new name, which may be a compound word */ 1799 /* lets give the "book" a new name, which may be a compound word */
1851 change_book (book, msg_type); 1800 change_book (book, msg_type);
1852 } 1801 }
1853} 1802}
1854
1855
1856/*****************************************************************************
1857 *
1858 * Cleanup routine for readble stuff.
1859 *
1860 *****************************************************************************/
1861
1862void
1863free_all_readable (void)
1864{
1865 titlelist *tlist, *tnext;
1866 title *title1, *titlenext;
1867 linked_char *lmsg, *nextmsg;
1868 objectlink *monlink, *nextmon;
1869
1870 LOG (llevDebug, "freeing all book information\n");
1871
1872 for (tlist = booklist; tlist != NULL; tlist = tnext)
1873 {
1874 tnext = tlist->next;
1875
1876 for (title1 = tlist->first_book; title1; title1 = titlenext)
1877 {
1878 titlenext = title1->next;
1879 delete title1;
1880 }
1881
1882 delete tlist;
1883 }
1884
1885 for (lmsg = first_msg; lmsg; lmsg = nextmsg)
1886 {
1887 nextmsg = lmsg->next;
1888 delete lmsg;
1889 }
1890
1891 for (monlink = first_mon_info; monlink; monlink = nextmon)
1892 {
1893 nextmon = monlink->next;
1894 delete monlink;
1895 }
1896}
1897
1898 1803
1899/***************************************************************************** 1804/*****************************************************************************
1900 * 1805 *
1901 * Writeback routine for updating the bookarchive. 1806 * Writeback routine for updating the bookarchive.
1902 * 1807 *
1903 ****************************************************************************/ 1808 ****************************************************************************/
1904
1905/* write_book_archive() - write out the updated book archive */ 1809/* write_book_archive() - write out the updated book archive */
1906
1907void 1810void
1908write_book_archive (void) 1811write_book_archive (void)
1909{ 1812{
1910 FILE *fp; 1813 FILE *fp;
1911 int index = 0; 1814 int index = 0;
1914 titlelist *bl = get_titlelist (0); 1817 titlelist *bl = get_titlelist (0);
1915 1818
1916 /* If nothing changed, don't write anything */ 1819 /* If nothing changed, don't write anything */
1917 if (!need_to_write_bookarchive) 1820 if (!need_to_write_bookarchive)
1918 return; 1821 return;
1822
1919 need_to_write_bookarchive = 0; 1823 need_to_write_bookarchive = 0;
1920 1824
1921 sprintf (fname, "%s/bookarch", settings.localdir); 1825 sprintf (fname, "%s/bookarch", settings.localdir);
1922 LOG (llevDebug, "Updating book archive: %s...\n", fname); 1826 LOG (llevDebug, "Updating book archive: %s...\n", fname);
1923 1827
1924 if ((fp = fopen (fname, "w")) == NULL) 1828 if ((fp = fopen (fname, "w")) == NULL)
1925 {
1926 LOG (llevDebug, "Can't open book archive file %s\n", fname); 1829 LOG (llevDebug, "Can't open book archive file %s\n", fname);
1927 }
1928 else 1830 else
1929 { 1831 {
1930 while (bl) 1832 while (bl)
1931 { 1833 {
1932 for (book = bl->first_book; book; book = book->next) 1834 for (book = bl->first_book; book; book = book->next)
1939 fprintf (fp, "type %d\n", index); 1841 fprintf (fp, "type %d\n", index);
1940 fprintf (fp, "size %d\n", book->size); 1842 fprintf (fp, "size %d\n", book->size);
1941 fprintf (fp, "index %d\n", book->msg_index); 1843 fprintf (fp, "index %d\n", book->msg_index);
1942 fprintf (fp, "end\n"); 1844 fprintf (fp, "end\n");
1943 } 1845 }
1846
1944 bl = bl->next; 1847 bl = bl->next;
1945 index++; 1848 index++;
1946 } 1849 }
1850
1947 fclose (fp); 1851 fclose (fp);
1948 chmod (fname, SAVE_MODE); 1852 chmod (fname, SAVE_MODE);
1949 } 1853 }
1950} 1854}
1855
1951readable_message_type * 1856readable_message_type *
1952get_readable_message_type (object *readable) 1857get_readable_message_type (object *readable)
1953{ 1858{
1954 uint8 subtype = readable->subtype; 1859 uint8 subtype = readable->subtype;
1955 1860

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines