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.57 by root, Sun Apr 11 00:34:05 2010 UTC

1/* 1/*
2 * This file is part of Deliantra, the Roguelike Realtime MMORPG. 2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 * 3 *
4 * Copyright (©) 2005,2006,2007,2008,2009 Marc Alexander Lehmann / Robin Redeker / the Deliantra team 4 * Copyright (©) 2005,2006,2007,2008,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team 5 * Copyright (©) 2002 Mark Wedel & Crossfire Development Team
6 * Copyright (©) 1992,2007 Frank Tore Johansen 6 * Copyright (©) 1992 Frank Tore Johansen
7 * 7 *
8 * Deliantra is free software: you can redistribute it and/or modify it under 8 * Deliantra is free software: you can redistribute it and/or modify it under
9 * the terms of the Affero GNU General Public License as published by the 9 * the terms of the Affero GNU General Public License as published by the
10 * Free Software Foundation, either version 3 of the License, or (at your 10 * Free Software Foundation, either version 3 of the License, or (at your
11 * option) any later version. 11 * option) any later version.
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
119 * the messages file
120 */
121static linked_char *first_msg = NULL;
122
123/* 113/*
124 * Spellpath information 114 * Spellpath information
125 */ 115 */
126
127static uint32 spellpathdef[NRSPELLPATHS] = { 116static uint32 spellpathdef[NRSPELLPATHS] = {
128 PATH_PROT, 117 PATH_PROT,
129 PATH_FIRE, 118 PATH_FIRE,
130 PATH_FROST, 119 PATH_FROST,
131 PATH_ELEC, 120 PATH_ELEC,
497 /*subtype 50 */ {MSG_TYPE_MONUMENT, MSG_TYPE_MONUMENT_GRAVESTONE_3, "readable-monument-gravestone-3"}, 486 /*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"}, 487 {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"}, 488 {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"} 489 {MSG_TYPE_MONUMENT, MSG_TYPE_MONUMENT_WALL_3, "readable-monument-wall-3"}
501}; 490};
502int last_readable_subtype = sizeof (readable_message_types) / sizeof (readable_message_type); 491static int last_readable_subtype = sizeof (readable_message_types) / sizeof (readable_message_type);
503 492
504static int max_titles[6] = { 493static int max_titles[6] = {
505 ((sizeof (light_book_name) / sizeof (char *)) + (sizeof (heavy_book_name) / sizeof (char *))) * (sizeof (book_author) / sizeof (char *)), 494 ((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 *)), 495 (sizeof (mon_book_name) / sizeof (char *)) * (sizeof (mon_author) / sizeof (char *)),
507 (sizeof (art_book_name) / sizeof (char *)) * (sizeof (art_author) / sizeof (char *)), 496 (sizeof (art_book_name) / sizeof (char *)) * (sizeof (art_author) / sizeof (char *)),
515 * Start of misc. readable functions used by others functions in this file 504 * Start of misc. readable functions used by others functions in this file
516 * 505 *
517 *****************************************************************************/ 506 *****************************************************************************/
518 507
519static titlelist * 508static titlelist *
520get_empty_booklist (void) 509get_empty_booklist ()
521{ 510{
522 titlelist *bl = new titlelist; 511 titlelist *bl = new titlelist;
523 512
524 bl->number = 0; 513 bl->number = 0;
525 bl->first_book = NULL; 514 bl->first_book = NULL;
526 bl->next = NULL; 515 bl->next = NULL;
527 return bl; 516 return bl;
528} 517}
529 518
530static title * 519static title *
531get_empty_book (void) 520get_empty_book ()
532{ 521{
533 title *t = new title; 522 title *t = new title;
534 523
535 t->name = NULL; 524 t->name = NULL;
536 t->archname = NULL; 525 t->archname = NULL;
619 tbuf = strtok (NULL, sbuf); 608 tbuf = strtok (NULL, sbuf);
620 } 609 }
621 return (char *) rbuf; 610 return (char *) rbuf;
622} 611}
623 612
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}
633
634/***************************************************************************** 613/*****************************************************************************
635 * 614 *
636 * Start of initialisation related functions. 615 * Start of initialisation related functions.
637 * 616 *
638 ****************************************************************************/ 617 ****************************************************************************/
640/* init_book_archive() - if not called before, initialise the info list 619/* init_book_archive() - if not called before, initialise the info list
641 * This reads in the bookarch file into memory. bookarch is the file 620 * This reads in the bookarch file into memory. bookarch is the file
642 * created and updated across multiple runs of the program. 621 * created and updated across multiple runs of the program.
643 */ 622 */
644static void 623static void
645init_book_archive (void) 624init_book_archive ()
646{ 625{
647 FILE *fp; 626 FILE *fp;
648 int comp, nroftitle = 0; 627 int comp, nroftitle = 0;
649 char buf[MAX_BUF], fname[MAX_BUF], *cp; 628 char buf[MAX_BUF], fname[MAX_BUF], *cp;
650 title *book = NULL; 629 title *book = NULL;
731} 710}
732 711
733/* init_mon_info() - creates the linked list of pointers to 712/* init_mon_info() - creates the linked list of pointers to
734 * monster archetype objects if not called previously 713 * monster archetype objects if not called previously
735 */ 714 */
736
737static void 715static void
738init_mon_info (void) 716init_mon_info ()
739{ 717{
740 archetype *at; 718 archetype *at;
741 static int did_init_mon_info = 0; 719 static int did_init_mon_info = 0;
742 720
743 if (did_init_mon_info) 721 if (did_init_mon_info)
744 return; 722 return;
745 723
746 did_init_mon_info = 1; 724 did_init_mon_info = 1;
747 725
748 for_all_archetypes (at) 726 for_all_archetypes (at)
749 { 727 if (at->flag [FLAG_MONSTER]
750 if (QUERY_FLAG (at, FLAG_MONSTER) && (!QUERY_FLAG (at, FLAG_CHANGING) || QUERY_FLAG (at, FLAG_UNAGGRESSIVE))) 728 && at->is_head ()
729 && (!at->flag [FLAG_CHANGING] || at->flag [FLAG_UNAGGRESSIVE]))
751 { 730 {
752 objectlink *mon = new objectlink; 731 objectlink *mon = new objectlink;
753 732
754 mon->ob = at; 733 mon->ob = at;
755 mon->next = first_mon_info; 734 mon->next = first_mon_info;
756 first_mon_info = mon; 735 first_mon_info = mon;
757 nrofmon++; 736 nrofmon++;
758 } 737 }
759 }
760 738
761 LOG (llevDebug, "init_mon_info() got %d monsters\n", nrofmon); 739 LOG (llevDebug, "init_mon_info() got %d monsters\n", nrofmon);
762} 740}
763 741
764/* init_readable() - initialise linked lists utilized by 742/* init_readable() - initialise linked lists utilized by
766 * 744 *
767 * This is the function called by the main routine to initialise 745 * This is the function called by the main routine to initialise
768 * all the readable information. 746 * all the readable information.
769 */ 747 */
770void 748void
771init_readable (void) 749init_readable ()
772{ 750{
773 static int did_this; 751 static int did_this;
774 752
775 if (did_this) 753 if (did_this)
776 return; 754 return;
1215 break; 1193 break;
1216 1194
1217 /* didn't find a match */ 1195 /* didn't find a match */
1218 if (!mon) 1196 if (!mon)
1219 return NULL; 1197 return NULL;
1198
1220 if (mon->next) 1199 if (mon->next)
1221 return mon->next->ob; 1200 return mon->next->ob;
1222 else 1201 else
1223 return first_mon_info->ob; 1202 return first_mon_info->ob;
1224 1203
1226 1205
1227/* mon_info_msg() - generate a message detailing the properties 1206/* mon_info_msg() - generate a message detailing the properties
1228 * of a randomly selected monster. 1207 * of a randomly selected monster.
1229 */ 1208 */
1230static const char * 1209static const char *
1231mon_info_msg (int level, int booksize) 1210mon_info_msg (int level)
1232{ 1211{
1233 static dynbuf_text buf; buf.clear (); 1212 static dynbuf_text buf; buf.clear ();
1234 1213
1235 /*preamble */ 1214 /*preamble */
1236 buf << "This beastiary contains:\n"; 1215 buf << "This beastiary contains:\n";
1262 1241
1263/* artifact_msg() - generate a message detailing the properties 1242/* artifact_msg() - generate a message detailing the properties
1264 * of 1-6 artifacts drawn sequentially from the artifact list. 1243 * of 1-6 artifacts drawn sequentially from the artifact list.
1265 */ 1244 */
1266static const char * 1245static const char *
1267artifact_msg (int level, int booksize) 1246artifact_msg (int level)
1268{ 1247{
1269 artifactlist *al = NULL; 1248 artifactlist *al = NULL;
1270 artifact *art; 1249 artifact *art;
1271 int chance, i, type, index; 1250 int chance, i, type, index;
1272 int book_entries = level > 5 ? rndm (3) + rndm (3) + 2 : rndm (level) + 1; 1251 int book_entries = level > 5 ? rndm (3) + rndm (3) + 2 : rndm (level) + 1;
1369 1348
1370 /* properties of the artifact */ 1349 /* properties of the artifact */
1371 tmp = object::create (); 1350 tmp = object::create ();
1372 add_abilities (tmp, art->item); 1351 add_abilities (tmp, art->item);
1373 tmp->type = type; 1352 tmp->type = type;
1374 SET_FLAG (tmp, FLAG_IDENTIFIED); 1353 tmp->set_flag (FLAG_IDENTIFIED);
1375 if ((ch = describe_item (tmp, 0)) && strlen (ch) > 1) 1354 if ((ch = describe_item (tmp, 0)) && strlen (ch) > 1)
1376 buf << "\rProperties of this artifact include:\r" << ch << "\n"; 1355 buf << "\rProperties of this artifact include:\r" << ch << "\n";
1377 1356
1378 tmp->destroy (); 1357 tmp->destroy ();
1379 1358
1391/* spellpath_msg() - generate a message detailing the member 1370/* spellpath_msg() - generate a message detailing the member
1392 * incantations/prayers (and some of their properties) belonging to 1371 * incantations/prayers (and some of their properties) belonging to
1393 * a given spellpath. 1372 * a given spellpath.
1394 */ 1373 */
1395static char * 1374static char *
1396spellpath_msg (int level, int booksize) 1375spellpath_msg (int level)
1397{ 1376{
1398 static dynbuf_text buf; buf.clear (); 1377 static dynbuf_text buf; buf.clear ();
1399 1378
1400 static char retbuf[BOOK_BUF]; 1379 static char retbuf[BOOK_BUF];
1401 char tmpbuf[BOOK_BUF]; 1380 char tmpbuf[BOOK_BUF];
1427 } 1406 }
1428 1407
1429 /* Geez, no spells were generated. */ 1408 /* Geez, no spells were generated. */
1430 if (!seen) 1409 if (!seen)
1431 if (rndm (4)) /* usually, lets make a recursive call... */ 1410 if (rndm (4)) /* usually, lets make a recursive call... */
1432 return spellpath_msg (level, booksize); 1411 return spellpath_msg (level);
1433 else /* give up, cause knowing no spells exist for path is info too. */ 1412 else /* give up, cause knowing no spells exist for path is info too. */
1434 buf << "- no known spells exist.\n"; 1413 buf << "- no known spells exist.\n";
1435 1414
1436 return buf; 1415 return buf;
1437} 1416}
1440 * of a randomly selected alchemical formula. 1419 * of a randomly selected alchemical formula.
1441 */ 1420 */
1442static void 1421static void
1443make_formula_book (object *book, int level) 1422make_formula_book (object *book, int level)
1444{ 1423{
1445 char retbuf[BOOK_BUF], title[MAX_BUF]; 1424 char title[MAX_BUF];
1446 recipelist *fl; 1425 recipelist *fl;
1447 recipe *formula = NULL; 1426 recipe *formula = NULL;
1448 int chance; 1427 int chance;
1428
1429 static dynbuf_text buf; buf.clear ();
1449 1430
1450 /* the higher the book level, the more complex (ie number of 1431 /* the higher the book level, the more complex (ie number of
1451 * ingredients) the formula can be. 1432 * ingredients) the formula can be.
1452 */ 1433 */
1453 fl = get_formulalist (rndm (level) / 3 + 1); 1434 fl = get_formulalist (rndm (level) / 3 + 1);
1466 /* get a random formula, weighted by its bookchance */ 1447 /* get a random formula, weighted by its bookchance */
1467 chance = rndm (fl->total_chance); 1448 chance = rndm (fl->total_chance);
1468 for (formula = fl->items; formula; formula = formula->next) 1449 for (formula = fl->items; formula; formula = formula->next)
1469 { 1450 {
1470 chance -= formula->chance; 1451 chance -= formula->chance;
1452
1471 if (chance <= 0) 1453 if (chance <= 0)
1472 break; 1454 break;
1473 } 1455 }
1474 1456
1475 if (!formula || formula->arch_names <= 0) 1457 if (!formula || formula->arch_names <= 0)
1476 { 1458 {
1477 book->msg = "<indecipherable text>\n"; 1459 book->msg = "<indecipherable text>\n";
1478 new_text_name (book, 4); 1460 new_text_name (book, 4);
1479 add_author (book, 4); 1461 add_author (book, 4);
1480 1462 return;
1481 } 1463 }
1464
1465 /* looks like a formula was found. Base the amount
1466 * of information on the booklevel and the spellevel
1467 * of the formula. */
1468
1469 const char *op_name = formula->arch_name [rndm (formula->arch_names)];
1470 archetype *at;
1471
1472 /* preamble */
1473 buf << "Herein is described a project using B<< "
1474 << (formula->skill ? &formula->skill : "an unknown skill")
1475 << " >>:\n\n";
1476
1477 if ((at = archetype::find (op_name)))
1478 op_name = at->object::name;
1482 else 1479 else
1480 LOG (llevError, "formula_msg() can't find arch %s for formula.\n", op_name);
1481
1482 /* item name */
1483 if (formula->title != shstr_NONE)
1484 {
1485 buf.printf ("The B<< %s of %s >>", op_name, &formula->title);
1486 /* This results in things like pile of philo. sulfur.
1487 * while philo. sulfur may look better, without this,
1488 * you get things like 'the wise' because its missing the
1489 * water of section.
1490 */
1491 sprintf (title, "%s: %s of %s",
1492 formula_book_name [rndm (sizeof (formula_book_name) / sizeof (char *))], op_name, &formula->title);
1483 { 1493 }
1484 /* looks like a formula was found. Base the amount 1494 else
1485 * of information on the booklevel and the spellevel 1495 {
1486 * of the formula. */ 1496 buf << "The B<< " << op_name;
1487 1497
1488 const char *op_name = formula->arch_name [rndm (formula->arch_names)]; 1498 sprintf (title, "%s: %s", formula_book_name [rndm (sizeof (formula_book_name) / sizeof (char *))], op_name);
1499 if (at->title)
1500 {
1501 buf << " " << at->title;
1502 strcat (title, " ");
1503 strcat (title, at->title);
1504 }
1505
1506 buf << " >>";
1507 }
1508
1509 /* Lets name the book something meaningful ! */
1510 book->name = title;
1511 book->title = NULL;
1512
1513 /* ingredients to make it */
1514 if (formula->ingred)
1515 {
1516 linked_char *next;
1489 archetype *at; 1517 archetype *at;
1490 1518
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); 1519 at = archetype::find (formula->cauldron);
1535 1520
1536 sprintf (retbuf + strlen (retbuf), 1521 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"); 1522 at ? query_name (at) : "an appropriate place");
1538 1523
1539 for (next = formula->ingred; next != NULL; next = next->next) 1524 for (next = formula->ingred; next; next = next->next)
1540 { 1525 buf << next->name << '\r';
1541 strcat (retbuf, next->name); 1526 }
1542 strcat (retbuf, "\n");
1543 }
1544 }
1545 else 1527 else
1546 LOG (llevError, "formula_msg() no ingredient list for object %s of %s\n", op_name, &formula->title); 1528 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 1529
1550 book->msg = retbuf; 1530 book->msg = buf;
1551 }
1552} 1531}
1553 1532
1554#define DESCRIBE_PATH(retbuf, variable, name) \ 1533#define DESCRIBE_PATH(retbuf, variable, name) \
1555 if(variable) { \ 1534 if(variable) { \
1556 int i,j=0; \ 1535 int i,j=0; \
1568 1547
1569/* god_info_msg() - generate a message detailing the properties 1548/* god_info_msg() - generate a message detailing the properties
1570 * of a random god. Used by the book hack. b.t. 1549 * of a random god. Used by the book hack. b.t.
1571 */ 1550 */
1572static const char * 1551static const char *
1573god_info_msg (int level, int booksize) 1552god_info_msg (int level)
1574{ 1553{
1575 static char retbuf[BOOK_BUF];
1576 const char *name = NULL; 1554 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 ()); 1555 object *god = pntr_to_god_obj (get_rand_god ());
1581 1556
1557 static dynbuf_text buf; buf.clear ();
1558
1582 if (!god) 1559 if (!god)
1583 return (char *) NULL; /* oops, problems... */ 1560 return 0; /* oops, problems... */
1561
1584 name = god->name; 1562 name = god->name;
1585 1563
1586 /* preamble.. */ 1564 /* preamble.. */
1587 sprintf (retbuf, "This document contains knowledge concerning\n"); 1565 buf << "This document contains knowledge concerning the diety B<< "
1588 sprintf (retbuf, "%sthe diety %s", retbuf, name); 1566 << name << " >>";
1589 1567
1590 /* Always have as default information the god's descriptive terms. */ 1568 /* Always have as default information the god's descriptive terms. */
1591 if (nstrtok (god->msg, ",") > 0) 1569 if (nstrtok (god->msg, ",") > 0)
1592 { 1570 buf << ", known as" << strtoktolin (god->msg, ",");
1593 strcat (retbuf, ", known as");
1594 strcat (retbuf, strtoktolin (god->msg, ","));
1595 }
1596 else 1571 else
1597 strcat (retbuf, "..."); 1572 buf << "...";
1598 1573
1599 strcat (retbuf, "\n ---\n"); 1574 buf << "\n\n";
1575
1600 introlen = strlen (retbuf); /* so we will know if no new info is added later */ 1576 int introlen = buf.size (); /* so we will know if no new info is added later */
1601 1577
1602 /* Information about the god is random, and based on the level of the 1578 /* Information about the god is random, and based on the level of the
1603 * 'book'. Probably there is a more intellegent way to implement 1579 * 'book'. Probably there is a more intellegent way to implement
1604 * this ... 1580 * this ...
1605 */ 1581 */
1606 while (level > 0) 1582 while (level > 0 && buf.size () < BOOK_BUF)
1607 { 1583 {
1608 sprintf (buf, " ");
1609 if (level == 2 && rndm (2)) 1584 if (level == 2 && rndm (2))
1610 { /* enemy god */ 1585 { /* enemy god */
1611 const char *enemy = god->title; 1586 const char *enemy = god->title;
1612 1587
1613 if (enemy) 1588 if (enemy)
1614 sprintf (buf, "The gods %s and %s are enemies.\n ---\n", name, enemy); 1589 buf.printf ("The gods %s and %s are enemies.\r", name, enemy);
1615 } 1590 }
1616 1591
1617 if (level == 3 && rndm (2)) 1592 if (level == 3 && rndm (2))
1618 { /* enemy race, what the god's holy word effects */ 1593 { /* enemy race, what the god's holy word effects */
1619 const char *enemy = god->slaying; 1594 const char *enemy = god->slaying;
1595 int i;
1620 1596
1621 if (enemy && !(god->path_denied & PATH_TURNING)) 1597 if (enemy && !(god->path_denied & PATH_TURNING))
1622 if ((i = nstrtok (enemy, ",")) > 0) 1598 if ((i = nstrtok (enemy, ",")) > 0)
1623 { 1599 {
1624 char tmpbuf[MAX_BUF]; 1600 char tmpbuf[MAX_BUF];
1625 1601
1626 sprintf (buf, "The holy words of %s have the power to\n", name); 1602 buf << "The holy words of " << name
1627 strcat (buf, "slay creatures belonging to the "); 1603 << " have the power to slay creatures belonging to the ";
1604
1628 if (i > 1) 1605 if (i > 1)
1629 sprintf (tmpbuf, "following \n races:%s", strtoktolin (enemy, ",")); 1606 buf << "following races:" << strtoktolin (enemy, ",");
1630 else 1607 else
1631 sprintf (tmpbuf, "race of%s", strtoktolin (enemy, ",")); 1608 buf << "race of" << strtoktolin (enemy, ",");
1632 sprintf (buf, "%s%s\n ---\n", buf, tmpbuf); 1609
1610 buf << '\r';
1633 } 1611 }
1634 } 1612 }
1635 1613
1636 if (level == 4 && rndm (2)) 1614 if (level == 4 && rndm (2))
1637 { /* Priest of god gets these protect,vulnerable... */ 1615 { /* Priest of god gets these protect,vulnerable... */
1638 char tmpbuf[MAX_BUF];
1639
1640 if (const char *cp = describe_resistance (god, 1)) 1616 if (const char *cp = describe_resistance (god, 1))
1641 { /* This god does have protections */ 1617 { /* This god does have protections */
1642 sprintf (tmpbuf, "%s has a potent aura which is extended\n", name); 1618 buf << name
1619 << " has a potent aura which is extended to"
1643 strcat (tmpbuf, "faithful priests. The effects of this aura include:\n"); 1620 " faithful priests. The effects of this aura include: "
1644 strcat (tmpbuf, cp); 1621 << cp
1645 strcat (buf, tmpbuf); 1622 << ".\r";
1646 strcat (buf, "\n ---\n");
1647 } 1623 }
1648 else
1649 sprintf (buf, " ");
1650 } 1624 }
1651 1625
1652 if (level == 5 && rndm (2)) 1626 if (level == 5 && rndm (2))
1653 { /* aligned race, summoning */ 1627 { /* aligned race, summoning */
1654 const char *race = god->race; /* aligned race */ 1628 const char *race = god->race; /* aligned race */
1629 int i;
1655 1630
1656 if (race && !(god->path_denied & PATH_SUMMON)) 1631 if (race && !(god->path_denied & PATH_SUMMON))
1657 if ((i = nstrtok (race, ",")) > 0) 1632 if ((i = nstrtok (race, ",")) > 0)
1658 { 1633 {
1659 char tmpbuf[MAX_BUF]; 1634 buf << "Creatures sacred to " << name << " include the ";
1660
1661 sprintf (buf, "Creatures sacred to %s include the \n", name);
1662 if (i > 1) 1635 if (i > 1)
1663 sprintf (tmpbuf, "following \n races:%s", strtoktolin (race, ",")); 1636 buf << "following races:" << strtoktolin (race, ",");
1664 else 1637 else
1665 sprintf (tmpbuf, "race of%s", strtoktolin (race, ",")); 1638 buf << "race of" << strtoktolin (race, ",");
1666 sprintf (buf, "%s%s\n ---\n", buf, tmpbuf); 1639
1640 buf << '\r';
1667 } 1641 }
1668 } 1642 }
1669 1643
1670 if (level == 6 && rndm (2)) 1644 if (level == 6 && rndm (2))
1671 { /* blessing,curse properties of the god */ 1645 { /* blessing,curse properties of the god */
1672 char tmpbuf[MAX_BUF];
1673
1674 if (const char *cp = describe_resistance (god, 1)) 1646 if (const char *cp = describe_resistance (god, 1))
1675 { /* This god does have protections */ 1647 { /* This god does have protections */
1676 sprintf (tmpbuf, "\nThe priests of %s are known to be able to \n", name); 1648 buf << "The priests of " << name
1649 << " are known to be able to "
1677 strcat (tmpbuf, "bestow a blessing which makes the recipient\n"); 1650 "bestow a blessing which makes the recipient "
1678 strcat (tmpbuf, cp); 1651 << cp
1679 strcat (buf, tmpbuf); 1652 << '\r';
1680 strcat (buf, "\n ---\n");
1681 } 1653 }
1682 else
1683 sprintf (buf, " ");
1684
1685 } 1654 }
1686 1655
1687 if (level == 8 && rndm (2)) 1656 if (level == 8 && rndm (2))
1688 { /* immunity, holy possession */ 1657 { /* immunity, holy possession */
1689 int has_effect = 0, tmpvar; 1658 buf << "The priests of " << name
1690 char tmpbuf[MAX_BUF]; 1659 << " are known to make cast a mighty"
1660 " prayer of possession";
1661
1662 int first = 1;
1691 1663
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++) 1664 for (int i = 0; i < NROFATTACKS; i++)
1665 if (god->resist[i] == 100)
1698 { 1666 {
1699 if (god->resist[tmpvar] == 100) 1667 if (first)
1700 { 1668 {
1669 buf << " which gives the recipient";
1701 has_effect = 1; 1670 first = 0;
1702 sprintf (tmpbuf + strlen (tmpbuf), "Immunity to %s", attacktype_desc[tmpvar]);
1703 } 1671 }
1672 else
1673 buf << ", ";
1674
1675 buf << " immunity to " << attacktype_desc[i];
1704 } 1676 }
1705 1677
1706 if (has_effect) 1678 buf << ".\r";
1707 {
1708 strcat (buf, tmpbuf);
1709 strcat (buf, "\n ---\n");
1710 }
1711 else
1712 sprintf (buf, " ");
1713 } 1679 }
1714 1680
1715 if (level == 12 && rndm (2)) 1681 if (level == 12 && rndm (2))
1716 { /* spell paths */ 1682 { /* spell paths */
1683 //TODO:
1717 int has_effect = 0, tmpvar; 1684 int has_effect = 0, tmpvar;
1718 char tmpbuf[MAX_BUF]; 1685 char tmpbuf[MAX_BUF];
1719 1686
1720 sprintf (tmpbuf, "\n"); 1687 sprintf (tmpbuf, "\n");
1721 sprintf (tmpbuf, "It is rarely known fact that the priests of %s\n", name); 1688 sprintf (tmpbuf, "It is rarely known fact that the priests of %s\n", name);
1738 has_effect = 1; 1705 has_effect = 1;
1739 DESCRIBE_PATH (tmpbuf, tmpvar, "Denied"); 1706 DESCRIBE_PATH (tmpbuf, tmpvar, "Denied");
1740 } 1707 }
1741 1708
1742 if (has_effect) 1709 if (has_effect)
1743 { 1710 buf << tmpbuf << '\r';
1744 strcat (buf, tmpbuf);
1745 strcat (buf, "\n ---\n");
1746 }
1747 else 1711 else
1748 sprintf (buf, " "); 1712 buf << '\r';
1749 } 1713 }
1750 1714
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--; 1715 level--;
1761 } 1716 }
1762 1717
1763 if (strlen (retbuf) == introlen) 1718 if (buf.size () == introlen)
1764 { /* we got no information beyond the preamble! */ 1719 /* we got no information beyond the preamble! */
1765 strcat (retbuf, " [Unfortunately the rest of the information is\n"); 1720 buf << "[Unfortunately the rest of the information is hopelessly garbled!]";
1766 strcat (retbuf, " hopelessly garbled!]\n ---\n"); 1721
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; 1722 return buf;
1773} 1723}
1774 1724
1775/* tailor_readable_ob()- The main routine. This chooses a random 1725/* tailor_readable_ob()- The main routine. This chooses a random
1776 * message to put in given readable object (type==BOOK) which will 1726 * 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- 1727 * be referred hereafter as a 'book'. We use the book level to de-
1789 * 1739 *
1790 */ 1740 */
1791void 1741void
1792tailor_readable_ob (object *book, int msg_type) 1742tailor_readable_ob (object *book, int msg_type)
1793{ 1743{
1794 char msgbuf[BOOK_BUF];
1795 int level = book->level ? rndm (book->level) + 1 : 1; 1744 int level = book->level ? rndm (book->level) + 1 : 1;
1796 int book_buf_size;
1797 1745
1798 /* safety */ 1746 /* safety */
1799 if (book->type != BOOK) 1747 if (book->type != BOOK)
1800 return; 1748 return;
1801 1749
1802 if (level <= 0) 1750 if (level <= 0)
1803 return; /* if no level no point in doing any more... */ 1751 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 1752
1808 /* &&& The message switch &&& */ 1753 /* &&& The message switch &&& */
1809 /* Below all of the possible types of messages in the "book"s. 1754 /* Below all of the possible types of messages in the "book"s.
1810 */ 1755 */
1811 /* 1756 /*
1814 * 2) make sure there is an entry in max_titles[] array. 1759 * 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() 1760 * 3) make sure there are entries for your case in new_text_title()
1816 * and add_authour(). 1761 * and add_authour().
1817 * 4) you may want separate authour/book name arrays in read.h 1762 * 4) you may want separate authour/book name arrays in read.h
1818 */ 1763 */
1764 const char *new_msg = "";
1819 msg_type = msg_type > 0 ? msg_type : rndm (8); 1765 msg_type = msg_type > 0 ? msg_type : rndm (8);
1820 switch (msg_type*0+2)//D 1766 switch (msg_type)
1821 { 1767 {
1822 case 1: /* monster attrib */ 1768 case 1: /* monster attrib */
1823 strcpy (msgbuf, mon_info_msg (level, book_buf_size)); 1769 new_msg = mon_info_msg (level);
1824 break; 1770 break;
1825 case 2: /* artifact attrib */ 1771 case 2: /* artifact attrib */
1826 strcpy (msgbuf, artifact_msg (level, book_buf_size)); 1772 new_msg = artifact_msg (level);
1827 break; 1773 break;
1828 case 3: /* grouping incantations/prayers by path */ 1774 case 3: /* grouping incantations/prayers by path */
1829 strcpy (msgbuf, spellpath_msg (level, book_buf_size)); 1775 new_msg = spellpath_msg (level);
1830 break; 1776 break;
1831 case 4: /* describe an alchemy formula */ 1777 case 4: /* describe an alchemy formula */
1832 make_formula_book (book, level); 1778 make_formula_book (book, level);
1833 /* make_formula_book already gives title */ 1779 /* make_formula_book already gives title */
1834 return; 1780 return;
1835 break;
1836 case 5: /* bits of information about a god */ 1781 case 5: /* bits of information about a god */
1837 strcpy (msgbuf, god_info_msg (level, book_buf_size)); 1782 new_msg = god_info_msg (level);
1838 break; 1783 break;
1839 case 0: /* use info list in lib/ */ 1784 case 0: /* use info list in lib/ */
1840 default: 1785 default:
1841 cfperl_make_book (book, level); 1786 cfperl_make_book (book, level);
1787 /* already gives title */
1842 return; 1788 return;
1843 } 1789 }
1844 1790
1845 strcat (msgbuf, "\n"); /* safety -- we get ugly map saves/crashes w/o this */
1846
1847 if (strlen (msgbuf) > 1) 1791 if (strlen (new_msg) > 1)
1848 { 1792 {
1849 book->msg = msgbuf; 1793 book->msg = new_msg;
1850 /* lets give the "book" a new name, which may be a compound word */ 1794 /* lets give the "book" a new name, which may be a compound word */
1851 change_book (book, msg_type); 1795 change_book (book, msg_type);
1852 } 1796 }
1853} 1797}
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 1798
1899/***************************************************************************** 1799/*****************************************************************************
1900 * 1800 *
1901 * Writeback routine for updating the bookarchive. 1801 * Writeback routine for updating the bookarchive.
1902 * 1802 *
1903 ****************************************************************************/ 1803 ****************************************************************************/
1904
1905/* write_book_archive() - write out the updated book archive */ 1804/* write_book_archive() - write out the updated book archive */
1906
1907void 1805void
1908write_book_archive (void) 1806write_book_archive ()
1909{ 1807{
1910 FILE *fp; 1808 FILE *fp;
1911 int index = 0; 1809 int index = 0;
1912 char fname[MAX_BUF]; 1810 char fname[MAX_BUF];
1913 title *book = NULL; 1811 title *book = NULL;
1914 titlelist *bl = get_titlelist (0); 1812 titlelist *bl = get_titlelist (0);
1915 1813
1916 /* If nothing changed, don't write anything */ 1814 /* If nothing changed, don't write anything */
1917 if (!need_to_write_bookarchive) 1815 if (!need_to_write_bookarchive)
1918 return; 1816 return;
1817
1919 need_to_write_bookarchive = 0; 1818 need_to_write_bookarchive = 0;
1920 1819
1921 sprintf (fname, "%s/bookarch", settings.localdir); 1820 sprintf (fname, "%s/bookarch", settings.localdir);
1922 LOG (llevDebug, "Updating book archive: %s...\n", fname); 1821 LOG (llevDebug, "Updating book archive: %s...\n", fname);
1923 1822
1924 if ((fp = fopen (fname, "w")) == NULL) 1823 if ((fp = fopen (fname, "w")) == NULL)
1925 {
1926 LOG (llevDebug, "Can't open book archive file %s\n", fname); 1824 LOG (llevDebug, "Can't open book archive file %s\n", fname);
1927 }
1928 else 1825 else
1929 { 1826 {
1930 while (bl) 1827 while (bl)
1931 { 1828 {
1932 for (book = bl->first_book; book; book = book->next) 1829 for (book = bl->first_book; book; book = book->next)
1939 fprintf (fp, "type %d\n", index); 1836 fprintf (fp, "type %d\n", index);
1940 fprintf (fp, "size %d\n", book->size); 1837 fprintf (fp, "size %d\n", book->size);
1941 fprintf (fp, "index %d\n", book->msg_index); 1838 fprintf (fp, "index %d\n", book->msg_index);
1942 fprintf (fp, "end\n"); 1839 fprintf (fp, "end\n");
1943 } 1840 }
1841
1944 bl = bl->next; 1842 bl = bl->next;
1945 index++; 1843 index++;
1946 } 1844 }
1845
1947 fclose (fp); 1846 fclose (fp);
1948 chmod (fname, SAVE_MODE); 1847 chmod (fname, SAVE_MODE);
1949 } 1848 }
1950} 1849}
1850
1951readable_message_type * 1851readable_message_type *
1952get_readable_message_type (object *readable) 1852get_readable_message_type (object *readable)
1953{ 1853{
1954 uint8 subtype = readable->subtype; 1854 uint8 subtype = readable->subtype;
1955 1855

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines