1 | /* |
1 | /* |
2 | * CrossFire, A Multiplayer game |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 | * |
3 | * |
4 | * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team |
4 | * Copyright (©) 2005,2006,2007,2008,2009 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * Copyright (C) 2002 Mark Wedel & Crossfire Development Team |
5 | * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team |
6 | * Copyright (C) 1992 Frank Tore Johansen |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
7 | * |
7 | * |
8 | * This program is free software; you can redistribute it and/or modify |
8 | * Deliantra is free software: you can redistribute it and/or modify it under |
9 | * it under the terms of the GNU General Public License as published by |
9 | * the terms of the Affero GNU General Public License as published by the |
10 | * the Free Software Foundation; either version 2 of the License, or |
10 | * Free Software Foundation, either version 3 of the License, or (at your |
11 | * (at your option) any later version. |
11 | * option) any later version. |
12 | * |
12 | * |
13 | * This program is distributed in the hope that it will be useful, |
13 | * This program is distributed in the hope that it will be useful, |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | * GNU General Public License for more details. |
16 | * GNU General Public License for more details. |
17 | * |
17 | * |
18 | * You should have received a copy of the GNU General Public License |
18 | * You should have received a copy of the Affero GNU General Public License |
19 | * along with this program; if not, write to the Free Software |
19 | * and the GNU General Public License along with this program. If not, see |
20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
20 | * <http://www.gnu.org/licenses/>. |
21 | * |
21 | * |
22 | * The authors can be reached via e-mail at <crossfire@schmorp.de> |
22 | * The authors can be reached via e-mail to <support@deliantra.net> |
23 | */ |
23 | */ |
24 | |
|
|
25 | |
24 | |
26 | /* This file contains code relevant to the BOOKS hack -- designed |
25 | /* This file contains code relevant to the BOOKS hack -- designed |
27 | * to allow randomly occuring messages in non-magical texts. |
26 | * to allow randomly occuring messages in non-magical texts. |
28 | */ |
27 | */ |
29 | |
28 | |
… | |
… | |
31 | |
30 | |
32 | #include <global.h> |
31 | #include <global.h> |
33 | #include <book.h> |
32 | #include <book.h> |
34 | #include <living.h> |
33 | #include <living.h> |
35 | #include <spells.h> |
34 | #include <spells.h> |
36 | |
|
|
37 | |
35 | |
38 | /* Define this if you want to archive book titles by contents. |
36 | /* Define this if you want to archive book titles by contents. |
39 | * This option should enforce UNIQUE combinations of titles,authors and |
37 | * This option should enforce UNIQUE combinations of titles,authors and |
40 | * msg contents during and *between* game sessions. |
38 | * msg contents during and *between* game sessions. |
41 | * Note: a slight degeneracy exists since books are archived based on an integer |
39 | * Note: a slight degeneracy exists since books are archived based on an integer |
… | |
… | |
436 | * Be careful to keep the order. If you add readable subtype, add them |
434 | * Be careful to keep the order. If you add readable subtype, add them |
437 | * at the bottom of the list. Never delete a subtype because index is used as |
435 | * at the bottom of the list. Never delete a subtype because index is used as |
438 | * subtype paramater in arch files! |
436 | * subtype paramater in arch files! |
439 | */ |
437 | */ |
440 | static readable_message_type readable_message_types[] = { |
438 | static readable_message_type readable_message_types[] = { |
441 | /*subtype 0 */ {0, 0}, |
439 | /*subtype 0 */ {0, 0, "info"}, |
442 | /* book messages subtypes */ |
440 | /* book messages subtypes */ |
443 | /*subtype 1 */ {MSG_TYPE_BOOK, MSG_TYPE_BOOK_CLASP_1}, |
441 | /*subtype 1 */ {MSG_TYPE_BOOK, MSG_TYPE_BOOK_CLASP_1, "readable-book-clasp-1"}, |
444 | {MSG_TYPE_BOOK, MSG_TYPE_BOOK_CLASP_2}, |
442 | {MSG_TYPE_BOOK, MSG_TYPE_BOOK_CLASP_2, "readable-book-clasp-2"}, |
445 | {MSG_TYPE_BOOK, MSG_TYPE_BOOK_ELEGANT_1}, |
443 | {MSG_TYPE_BOOK, MSG_TYPE_BOOK_ELEGANT_1, "readable-book-elegant-1"}, |
446 | {MSG_TYPE_BOOK, MSG_TYPE_BOOK_ELEGANT_2}, |
444 | {MSG_TYPE_BOOK, MSG_TYPE_BOOK_ELEGANT_2, "readable-book-elegant-2"}, |
447 | {MSG_TYPE_BOOK, MSG_TYPE_BOOK_QUARTO_1}, |
445 | {MSG_TYPE_BOOK, MSG_TYPE_BOOK_QUARTO_1, "readable-book-quarto-1"}, |
448 | {MSG_TYPE_BOOK, MSG_TYPE_BOOK_QUARTO_2}, |
446 | {MSG_TYPE_BOOK, MSG_TYPE_BOOK_QUARTO_2, "readable-book-quarto-2"}, |
449 | {MSG_TYPE_BOOK, MSG_TYPE_BOOK_SPELL_EVOKER}, |
447 | {MSG_TYPE_BOOK, MSG_TYPE_BOOK_SPELL_EVOKER, "readable-book-spell-evocation"}, |
450 | {MSG_TYPE_BOOK, MSG_TYPE_BOOK_SPELL_PRAYER}, |
448 | {MSG_TYPE_BOOK, MSG_TYPE_BOOK_SPELL_PRAYER, "readable-book-spell-praying"}, |
451 | {MSG_TYPE_BOOK, MSG_TYPE_BOOK_SPELL_PYRO}, |
449 | {MSG_TYPE_BOOK, MSG_TYPE_BOOK_SPELL_PYRO, "readable-book-spell-pyromancy"}, |
452 | /*subtype 10 */ {MSG_TYPE_BOOK, MSG_TYPE_BOOK_SPELL_SORCERER}, |
450 | /*subtype 10 */ {MSG_TYPE_BOOK, MSG_TYPE_BOOK_SPELL_SORCERER, "readable-book-spell-sorcery"}, |
453 | {MSG_TYPE_BOOK, MSG_TYPE_BOOK_SPELL_SUMMONER}, |
451 | {MSG_TYPE_BOOK, MSG_TYPE_BOOK_SPELL_SUMMONER, "readable-book-spell-summoning"}, |
454 | /* card messages subtypes */ |
452 | /* card messages subtypes */ |
455 | {MSG_TYPE_CARD, MSG_TYPE_CARD_SIMPLE_1}, |
453 | {MSG_TYPE_CARD, MSG_TYPE_CARD_SIMPLE_1, "readable-card-simple-1"}, |
456 | {MSG_TYPE_CARD, MSG_TYPE_CARD_SIMPLE_2}, |
454 | {MSG_TYPE_CARD, MSG_TYPE_CARD_SIMPLE_2, "readable-card-simple-2"}, |
457 | {MSG_TYPE_CARD, MSG_TYPE_CARD_SIMPLE_3}, |
455 | {MSG_TYPE_CARD, MSG_TYPE_CARD_SIMPLE_3, "readable-card-simple-3"}, |
458 | {MSG_TYPE_CARD, MSG_TYPE_CARD_ELEGANT_1}, |
456 | {MSG_TYPE_CARD, MSG_TYPE_CARD_ELEGANT_1, "readable-card-elegant-1"}, |
459 | {MSG_TYPE_CARD, MSG_TYPE_CARD_ELEGANT_2}, |
457 | {MSG_TYPE_CARD, MSG_TYPE_CARD_ELEGANT_2, "readable-card-elegant-2"}, |
460 | {MSG_TYPE_CARD, MSG_TYPE_CARD_ELEGANT_3}, |
458 | {MSG_TYPE_CARD, MSG_TYPE_CARD_ELEGANT_3, "readable-card-elegant-3"}, |
461 | {MSG_TYPE_CARD, MSG_TYPE_CARD_STRANGE_1}, |
459 | {MSG_TYPE_CARD, MSG_TYPE_CARD_STRANGE_1, "readable-card-strange-1"}, |
462 | {MSG_TYPE_CARD, MSG_TYPE_CARD_STRANGE_2}, |
460 | {MSG_TYPE_CARD, MSG_TYPE_CARD_STRANGE_2, "readable-card-strange-2"}, |
463 | /*subtype 20 */ {MSG_TYPE_CARD, MSG_TYPE_CARD_STRANGE_3}, |
461 | /*subtype 20 */ {MSG_TYPE_CARD, MSG_TYPE_CARD_STRANGE_3, "readable-card-strange-3"}, |
464 | {MSG_TYPE_CARD, MSG_TYPE_CARD_MONEY_1}, |
462 | {MSG_TYPE_CARD, MSG_TYPE_CARD_MONEY_1, "readable-card-money-1"}, |
465 | {MSG_TYPE_CARD, MSG_TYPE_CARD_MONEY_2}, |
463 | {MSG_TYPE_CARD, MSG_TYPE_CARD_MONEY_2, "readable-card-money-2"}, |
466 | {MSG_TYPE_CARD, MSG_TYPE_CARD_MONEY_3}, |
464 | {MSG_TYPE_CARD, MSG_TYPE_CARD_MONEY_3, "readable-card-money-3"}, |
467 | |
465 | |
468 | /* Paper messages subtypes */ |
466 | /* Paper messages subtypes */ |
469 | {MSG_TYPE_PAPER, MSG_TYPE_PAPER_NOTE_1}, |
467 | {MSG_TYPE_PAPER, MSG_TYPE_PAPER_NOTE_1, "readable-paper-note-1"}, |
470 | {MSG_TYPE_PAPER, MSG_TYPE_PAPER_NOTE_2}, |
468 | {MSG_TYPE_PAPER, MSG_TYPE_PAPER_NOTE_2, "readable-paper-note-2"}, |
471 | {MSG_TYPE_PAPER, MSG_TYPE_PAPER_NOTE_3}, |
469 | {MSG_TYPE_PAPER, MSG_TYPE_PAPER_NOTE_3, "readable-paper-note-3"}, |
472 | {MSG_TYPE_PAPER, MSG_TYPE_PAPER_LETTER_OLD_1}, |
470 | {MSG_TYPE_PAPER, MSG_TYPE_PAPER_LETTER_OLD_1, "readable-paper-letter-old-1"}, |
473 | {MSG_TYPE_PAPER, MSG_TYPE_PAPER_LETTER_OLD_2}, |
471 | {MSG_TYPE_PAPER, MSG_TYPE_PAPER_LETTER_OLD_2, "readable-paper-letter-old-2"}, |
474 | {MSG_TYPE_PAPER, MSG_TYPE_PAPER_LETTER_NEW_1}, |
472 | {MSG_TYPE_PAPER, MSG_TYPE_PAPER_LETTER_NEW_1, "readable-paper-letter-new-1"}, |
475 | /*subtype 30 */ {MSG_TYPE_PAPER, MSG_TYPE_PAPER_LETTER_NEW_2}, |
473 | /*subtype 30 */ {MSG_TYPE_PAPER, MSG_TYPE_PAPER_LETTER_NEW_2, "readable-paper-letter-new-2"}, |
476 | {MSG_TYPE_PAPER, MSG_TYPE_PAPER_ENVELOPE_1}, |
474 | {MSG_TYPE_PAPER, MSG_TYPE_PAPER_ENVELOPE_1, "readable-paper-envelope-1"}, |
477 | {MSG_TYPE_PAPER, MSG_TYPE_PAPER_ENVELOPE_2}, |
475 | {MSG_TYPE_PAPER, MSG_TYPE_PAPER_ENVELOPE_2, "readable-paper-envelope-2"}, |
478 | {MSG_TYPE_PAPER, MSG_TYPE_PAPER_SCROLL_OLD_1}, |
476 | {MSG_TYPE_PAPER, MSG_TYPE_PAPER_SCROLL_OLD_1, "readable-paper-scroll-old-1"}, |
479 | {MSG_TYPE_PAPER, MSG_TYPE_PAPER_SCROLL_OLD_2}, |
477 | {MSG_TYPE_PAPER, MSG_TYPE_PAPER_SCROLL_OLD_2, "readable-paper-scroll-old-2"}, |
480 | {MSG_TYPE_PAPER, MSG_TYPE_PAPER_SCROLL_NEW_1}, |
478 | {MSG_TYPE_PAPER, MSG_TYPE_PAPER_SCROLL_NEW_1, "readable-paper-scroll-new-1"}, |
481 | {MSG_TYPE_PAPER, MSG_TYPE_PAPER_SCROLL_NEW_2}, |
479 | {MSG_TYPE_PAPER, MSG_TYPE_PAPER_SCROLL_NEW_2, "readable-paper-scroll-new-2"}, |
482 | {MSG_TYPE_PAPER, MSG_TYPE_PAPER_SCROLL_MAGIC}, |
480 | {MSG_TYPE_PAPER, MSG_TYPE_PAPER_SCROLL_MAGIC, "readable-paper-scroll-magic"}, |
483 | |
481 | |
484 | /* road signs messages subtypes */ |
482 | /* road signs messages subtypes */ |
485 | {MSG_TYPE_SIGN, MSG_TYPE_SIGN_BASIC}, |
483 | {MSG_TYPE_SIGN, MSG_TYPE_SIGN_BASIC, "readable-sign-basic"}, |
486 | {MSG_TYPE_SIGN, MSG_TYPE_SIGN_DIR_LEFT}, |
484 | {MSG_TYPE_SIGN, MSG_TYPE_SIGN_DIR_LEFT, "readable-sign-dir-left"}, |
487 | /*subtype 40 */ {MSG_TYPE_SIGN, MSG_TYPE_SIGN_DIR_RIGHT}, |
485 | /*subtype 40 */ {MSG_TYPE_SIGN, MSG_TYPE_SIGN_DIR_RIGHT, "readable-sign-dir-right"}, |
488 | {MSG_TYPE_SIGN, MSG_TYPE_SIGN_DIR_BOTH}, |
486 | {MSG_TYPE_SIGN, MSG_TYPE_SIGN_DIR_BOTH, "readable-sign-dir-both"}, |
489 | |
487 | |
490 | /* stones and monument messages */ |
488 | /* stones and monument messages */ |
491 | {MSG_TYPE_MONUMENT, MSG_TYPE_MONUMENT_STONE_1}, |
489 | {MSG_TYPE_MONUMENT, MSG_TYPE_MONUMENT_STONE_1, "readable-monument-stone-1"}, |
492 | {MSG_TYPE_MONUMENT, MSG_TYPE_MONUMENT_STONE_2}, |
490 | {MSG_TYPE_MONUMENT, MSG_TYPE_MONUMENT_STONE_2, "readable-monument-stone-2"}, |
493 | {MSG_TYPE_MONUMENT, MSG_TYPE_MONUMENT_STONE_3}, |
491 | {MSG_TYPE_MONUMENT, MSG_TYPE_MONUMENT_STONE_3, "readable-monument-stone-3"}, |
494 | {MSG_TYPE_MONUMENT, MSG_TYPE_MONUMENT_STATUE_1}, |
492 | {MSG_TYPE_MONUMENT, MSG_TYPE_MONUMENT_STATUE_1, "readable-monument-statue-1"}, |
495 | {MSG_TYPE_MONUMENT, MSG_TYPE_MONUMENT_STATUE_2}, |
493 | {MSG_TYPE_MONUMENT, MSG_TYPE_MONUMENT_STATUE_2, "readable-monument-statue-2"}, |
496 | {MSG_TYPE_MONUMENT, MSG_TYPE_MONUMENT_STATUE_3}, |
494 | {MSG_TYPE_MONUMENT, MSG_TYPE_MONUMENT_STATUE_3, "readable-monument-statue-3"}, |
497 | {MSG_TYPE_MONUMENT, MSG_TYPE_MONUMENT_GRAVESTONE_1}, |
495 | {MSG_TYPE_MONUMENT, MSG_TYPE_MONUMENT_GRAVESTONE_1, "readable-monument-gravestone-1"}, |
498 | {MSG_TYPE_MONUMENT, MSG_TYPE_MONUMENT_GRAVESTONE_2}, |
496 | {MSG_TYPE_MONUMENT, MSG_TYPE_MONUMENT_GRAVESTONE_2, "readable-monument-gravestone-2"}, |
499 | /*subtype 50 */ {MSG_TYPE_MONUMENT, MSG_TYPE_MONUMENT_GRAVESTONE_3}, |
497 | /*subtype 50 */ {MSG_TYPE_MONUMENT, MSG_TYPE_MONUMENT_GRAVESTONE_3, "readable-monument-gravestone-3"}, |
500 | {MSG_TYPE_MONUMENT, MSG_TYPE_MONUMENT_WALL_1}, |
498 | {MSG_TYPE_MONUMENT, MSG_TYPE_MONUMENT_WALL_1, "readable-monument-wall-1"}, |
501 | {MSG_TYPE_MONUMENT, MSG_TYPE_MONUMENT_WALL_2}, |
499 | {MSG_TYPE_MONUMENT, MSG_TYPE_MONUMENT_WALL_2, "readable-monument-wall-2"}, |
502 | {MSG_TYPE_MONUMENT, MSG_TYPE_MONUMENT_WALL_3} |
500 | {MSG_TYPE_MONUMENT, MSG_TYPE_MONUMENT_WALL_3, "readable-monument-wall-3"} |
503 | }; |
501 | }; |
504 | int last_readable_subtype = sizeof (readable_message_types) / sizeof (readable_message_type); |
502 | int last_readable_subtype = sizeof (readable_message_types) / sizeof (readable_message_type); |
505 | |
503 | |
506 | static int max_titles[6] = { |
504 | static int max_titles[6] = { |
507 | ((sizeof (light_book_name) / sizeof (char *)) + (sizeof (heavy_book_name) / sizeof (char *))) * (sizeof (book_author) / sizeof (char *)), |
505 | ((sizeof (light_book_name) / sizeof (char *)) + (sizeof (heavy_book_name) / sizeof (char *))) * (sizeof (book_author) / sizeof (char *)), |
… | |
… | |
571 | * (shstr.c ?), but the quantity BOOK_BUF will need to be defined. */ |
569 | * (shstr.c ?), but the quantity BOOK_BUF will need to be defined. */ |
572 | |
570 | |
573 | /* nstrtok() - simple routine to return the number of list |
571 | /* nstrtok() - simple routine to return the number of list |
574 | * items in buf1 as separated by the value of buf2 |
572 | * items in buf1 as separated by the value of buf2 |
575 | */ |
573 | */ |
576 | |
574 | static int |
577 | int |
|
|
578 | nstrtok (const char *buf1, const char *buf2) |
575 | nstrtok (const char *buf1, const char *buf2) |
579 | { |
576 | { |
580 | char *tbuf, sbuf[12], buf[MAX_BUF]; |
577 | char *tbuf, sbuf[12], buf[MAX_BUF]; |
581 | int number = 0; |
578 | int number = 0; |
582 | |
579 | |
… | |
… | |
595 | |
592 | |
596 | /* strtoktolin() - takes a string in buf1 and separates it into |
593 | /* strtoktolin() - takes a string in buf1 and separates it into |
597 | * a list of strings delimited by buf2. Then returns a comma |
594 | * a list of strings delimited by buf2. Then returns a comma |
598 | * separated string w/ decent punctuation. |
595 | * separated string w/ decent punctuation. |
599 | */ |
596 | */ |
600 | |
597 | static char * |
601 | char * |
|
|
602 | strtoktolin (const char *buf1, const char *buf2) |
598 | strtoktolin (const char *buf1, const char *buf2) |
603 | { |
599 | { |
604 | int maxi, i = nstrtok (buf1, buf2); |
600 | int maxi, i = nstrtok (buf1, buf2); |
605 | char *tbuf, buf[MAX_BUF], sbuf[12]; |
601 | char *tbuf, buf[MAX_BUF], sbuf[12]; |
606 | static char rbuf[BOOK_BUF]; |
602 | static char rbuf[BOOK_BUF]; |
… | |
… | |
623 | tbuf = strtok (NULL, sbuf); |
619 | tbuf = strtok (NULL, sbuf); |
624 | } |
620 | } |
625 | return (char *) rbuf; |
621 | return (char *) rbuf; |
626 | } |
622 | } |
627 | |
623 | |
628 | int |
624 | static int |
629 | book_overflow (const char *buf1, const char *buf2, int booksize) |
625 | book_overflow (const char *buf1, const char *buf2, int booksize) |
630 | { |
626 | { |
631 | |
|
|
632 | if (buf_overflow (buf1, buf2, BOOK_BUF - 2) /* 2 less so always room for trailing \n */ |
627 | if (buf_overflow (buf1, buf2, BOOK_BUF - 2) /* 2 less so always room for trailing \n */ |
633 | || buf_overflow (buf1, buf2, booksize)) |
628 | || buf_overflow (buf1, buf2, booksize)) |
634 | return 1; |
629 | return 1; |
|
|
630 | |
635 | return 0; |
631 | return 0; |
636 | |
|
|
637 | |
|
|
638 | } |
632 | } |
639 | |
633 | |
640 | /***************************************************************************** |
634 | /***************************************************************************** |
641 | * |
635 | * |
642 | * Start of initialisation related functions. |
636 | * Start of initialisation related functions. |
… | |
… | |
749 | if (did_init_mon_info) |
743 | if (did_init_mon_info) |
750 | return; |
744 | return; |
751 | |
745 | |
752 | did_init_mon_info = 1; |
746 | did_init_mon_info = 1; |
753 | |
747 | |
754 | |
748 | for_all_archetypes (at) |
755 | for (at = first_archetype; at != NULL; at = at->next) |
|
|
756 | { |
749 | { |
757 | if (QUERY_FLAG (&at->clone, FLAG_MONSTER) && (!QUERY_FLAG (&at->clone, FLAG_CHANGING) || QUERY_FLAG (&at->clone, FLAG_UNAGGRESSIVE))) |
750 | if (QUERY_FLAG (at, FLAG_MONSTER) && (!QUERY_FLAG (at, FLAG_CHANGING) || QUERY_FLAG (at, FLAG_UNAGGRESSIVE))) |
758 | { |
751 | { |
759 | objectlink *mon = new objectlink; |
752 | objectlink *mon = new objectlink; |
760 | |
753 | |
761 | mon->ob = &at->clone; |
754 | mon->ob = at; |
762 | mon->next = first_mon_info; |
755 | mon->next = first_mon_info; |
763 | first_mon_info = mon; |
756 | first_mon_info = mon; |
764 | nrofmon++; |
757 | nrofmon++; |
765 | } |
758 | } |
766 | } |
759 | } |
… | |
… | |
820 | else |
813 | else |
821 | t = t->next; |
814 | t = t->next; |
822 | |
815 | |
823 | #ifdef ARCHIVE_DEBUG |
816 | #ifdef ARCHIVE_DEBUG |
824 | if (t) |
817 | if (t) |
825 | LOG (llevDebug, "Found title match (list %d): %s %s (%d)\n", msgtype, t->name, t->authour, t->msg_index); |
818 | LOG (llevDebug, "Found title match (list %d): %s %s (%d)\n", msgtype, &t->name, &t->authour, t->msg_index); |
826 | #endif |
819 | #endif |
827 | |
820 | |
828 | return t; |
821 | return t; |
829 | } |
822 | } |
830 | |
823 | |
… | |
… | |
832 | * handled directly in change_book_name(). Names are based on text |
825 | * handled directly in change_book_name(). Names are based on text |
833 | * msgtype |
826 | * msgtype |
834 | * this sets book book->name based on msgtype given. What name |
827 | * this sets book book->name based on msgtype given. What name |
835 | * is given is based on various criteria |
828 | * is given is based on various criteria |
836 | */ |
829 | */ |
837 | |
|
|
838 | static void |
830 | static void |
839 | new_text_name (object *book, int msgtype) |
831 | new_text_name (object *book, int msgtype) |
840 | { |
832 | { |
841 | int nbr; |
833 | int nbr; |
842 | char name[MAX_BUF]; |
834 | char name[MAX_BUF]; |
… | |
… | |
935 | */ |
927 | */ |
936 | |
928 | |
937 | static int |
929 | static int |
938 | unique_book (const object *book, int msgtype) |
930 | unique_book (const object *book, int msgtype) |
939 | { |
931 | { |
940 | title *test; |
|
|
941 | |
|
|
942 | if (!booklist) |
932 | if (!booklist) |
943 | return 1; /* No archival entries! Must be unique! */ |
933 | return 1; /* No archival entries! Must be unique! */ |
944 | |
934 | |
945 | /* Go through the booklist. If the author and name match, not unique so |
935 | /* Go through the booklist. If the author and name match, not unique so |
946 | * return 0. |
936 | * return 0. |
947 | */ |
937 | */ |
948 | for (test = get_titlelist (msgtype)->first_book; test; test = test->next) |
938 | for (title *test = get_titlelist (msgtype)->first_book; test; test = test->next) |
949 | { |
|
|
950 | if (!strcmp (test->name, book->name) && !strcmp (book->title, test->authour)) |
939 | if (test->name == book->name && book->title == test->authour) |
951 | return 0; |
940 | return 0; |
952 | } |
941 | |
953 | return 1; |
942 | return 1; |
954 | } |
943 | } |
955 | |
944 | |
956 | /* add_book_to_list() */ |
945 | /* add_book_to_list() */ |
957 | |
946 | |
… | |
… | |
970 | t = get_empty_book (); |
959 | t = get_empty_book (); |
971 | t->name = book->name; |
960 | t->name = book->name; |
972 | t->authour = book->title; |
961 | t->authour = book->title; |
973 | t->size = strlen (book->msg); |
962 | t->size = strlen (book->msg); |
974 | t->msg_index = strtoint (book->msg); |
963 | t->msg_index = strtoint (book->msg); |
975 | t->archname = book->arch->name; |
964 | t->archname = book->arch->archname; |
976 | t->level = book->level; |
965 | t->level = book->level; |
977 | |
966 | |
978 | t->next = tl->first_book; |
967 | t->next = tl->first_book; |
979 | tl->first_book = t; |
968 | tl->first_book = t; |
980 | tl->number++; |
969 | tl->number++; |
981 | |
970 | |
982 | /* We have stuff we need to write now */ |
971 | /* We have stuff we need to write now */ |
983 | need_to_write_bookarchive = 1; |
972 | need_to_write_bookarchive = 1; |
984 | |
973 | |
985 | #ifdef ARCHIVE_DEBUG |
974 | #ifdef ARCHIVE_DEBUG |
986 | LOG (llevDebug, "Archiving new title: %s %s (%d)\n", book->name, book->title, msgtype); |
975 | LOG (llevDebug, "Archiving new title: %s %s (%d)\n", &book->name, &book->title, msgtype); |
987 | #endif |
976 | #endif |
988 | |
977 | |
989 | } |
978 | } |
990 | |
979 | |
991 | |
980 | |
… | |
… | |
997 | * levels and architypes. -b.t. |
986 | * levels and architypes. -b.t. |
998 | */ |
987 | */ |
999 | |
988 | |
1000 | #define MAX_TITLE_CHECK 20 |
989 | #define MAX_TITLE_CHECK 20 |
1001 | |
990 | |
1002 | void |
991 | static void |
1003 | change_book (object *book, int msgtype) |
992 | change_book (object *book, int msgtype) |
1004 | { |
993 | { |
1005 | int nbr = sizeof (book_descrpt) / sizeof (char *); |
994 | int nbr = sizeof (book_descrpt) / sizeof (char *); |
1006 | |
995 | |
1007 | switch (book->type) |
996 | switch (book->type) |
1008 | { |
997 | { |
1009 | case BOOK: |
998 | case BOOK: |
1010 | { |
999 | { |
1011 | titlelist *tl = get_titlelist (msgtype); |
1000 | titlelist *tl = get_titlelist (msgtype); |
1012 | title *t = NULL; |
1001 | title *t = NULL; |
1013 | int tries = 0; |
1002 | int tries = 0; |
1014 | |
1003 | |
1015 | /* look to see if our msg already been archived. If so, alter |
1004 | /* look to see if our msg already been archived. If so, alter |
1016 | * the book to match the archival text. If we fail to match, |
1005 | * the book to match the archival text. If we fail to match, |
1017 | * then we archive the new title/name/msg combo if there is |
1006 | * then we archive the new title/name/msg combo if there is |
1018 | * room on the titlelist. |
1007 | * room on the titlelist. |
1019 | */ |
1008 | */ |
1020 | |
1009 | |
1021 | if ((strlen (book->msg) > 5) && (t = find_title (book, msgtype))) |
1010 | if ((strlen (book->msg) > 5) && (t = find_title (book, msgtype))) |
1022 | { |
1011 | { |
1023 | object *tmpbook; |
|
|
1024 | |
|
|
1025 | /* alter book properties */ |
1012 | /* alter book properties */ |
1026 | if ((tmpbook = get_archetype (t->archname)) != NULL) |
1013 | if (object *tmpbook = get_archetype (t->archname)) |
|
|
1014 | { |
|
|
1015 | tmpbook->msg = book->msg; |
|
|
1016 | tmpbook->copy_to (book); |
|
|
1017 | tmpbook->destroy (); |
|
|
1018 | } |
|
|
1019 | |
|
|
1020 | book->title = t->authour; |
|
|
1021 | book->name = t->name; |
|
|
1022 | book->level = t->level; |
|
|
1023 | } |
|
|
1024 | /* Don't have any default title, so lets make up a new one */ |
|
|
1025 | else |
|
|
1026 | { |
|
|
1027 | int numb, maxnames = max_titles[msgtype]; |
|
|
1028 | const char *old_title; |
|
|
1029 | const char *old_name; |
|
|
1030 | |
|
|
1031 | old_title = book->title; |
|
|
1032 | old_name = book->name; |
|
|
1033 | |
|
|
1034 | /* some pre-generated books have title already set (from |
|
|
1035 | * maps), also don't bother looking for unique title if |
|
|
1036 | * we already used up all the available names! */ |
|
|
1037 | |
|
|
1038 | if (!tl) |
|
|
1039 | { |
|
|
1040 | LOG (llevError, "change_book_name(): can't find title list\n"); |
|
|
1041 | numb = 0; |
|
|
1042 | } |
|
|
1043 | else |
|
|
1044 | numb = tl->number; |
|
|
1045 | |
|
|
1046 | if (numb == maxnames) |
|
|
1047 | { |
|
|
1048 | #ifdef ARCHIVE_DEBUG |
|
|
1049 | LOG (llevDebug, "titles for list %d full (%d possible).\n", msgtype, maxnames); |
|
|
1050 | #endif |
|
|
1051 | } |
|
|
1052 | /* shouldnt change map-maker books */ |
|
|
1053 | else if (!book->title) |
|
|
1054 | do |
1027 | { |
1055 | { |
1028 | tmpbook->msg = book->msg; |
1056 | /* random book name */ |
1029 | tmpbook->copy_to (book); |
1057 | new_text_name (book, msgtype); |
1030 | tmpbook->destroy (); |
1058 | add_author (book, msgtype); /* random author */ |
|
|
1059 | tries++; |
1031 | } |
1060 | } |
|
|
1061 | while (!unique_book (book, msgtype) && tries < MAX_TITLE_CHECK); |
1032 | |
1062 | |
1033 | book->title = t->authour; |
1063 | /* Now deal with 2 cases. |
1034 | book->name = t->name; |
1064 | * 1)If no space for a new title exists lets just restore |
1035 | book->level = t->level; |
1065 | * the old book properties. Remember, if the book had |
|
|
1066 | * matchd an older entry on the titlelist, we shouldnt |
|
|
1067 | * have called this routine in the first place! |
|
|
1068 | * 2) If we got a unique title, we need to add it to |
|
|
1069 | * the list. |
1036 | } |
1070 | */ |
1037 | /* Don't have any default title, so lets make up a new one */ |
|
|
1038 | else |
|
|
1039 | { |
|
|
1040 | int numb, maxnames = max_titles[msgtype]; |
|
|
1041 | const char *old_title; |
|
|
1042 | const char *old_name; |
|
|
1043 | |
1071 | |
1044 | old_title = book->title; |
1072 | if (tries == MAX_TITLE_CHECK || numb == maxnames) |
1045 | old_name = book->name; |
1073 | { /* got to check maxnames again */ |
1046 | |
|
|
1047 | /* some pre-generated books have title already set (from |
|
|
1048 | * maps), also don't bother looking for unique title if |
|
|
1049 | * we already used up all the available names! */ |
|
|
1050 | |
|
|
1051 | if (!tl) |
|
|
1052 | { |
|
|
1053 | LOG (llevError, "change_book_name(): can't find title list\n"); |
|
|
1054 | numb = 0; |
|
|
1055 | } |
|
|
1056 | else |
|
|
1057 | numb = tl->number; |
|
|
1058 | |
|
|
1059 | if (numb == maxnames) |
|
|
1060 | { |
|
|
1061 | #ifdef ARCHIVE_DEBUG |
1074 | #ifdef ARCHIVE_DEBUG |
1062 | LOG (llevDebug, "titles for list %d full (%d possible).\n", msgtype, maxnames); |
1075 | LOG (llevDebug, "Failed to obtain unique title for %s %s (names:%d/%d)\n", &book->name, &book->title, numb, maxnames); |
1063 | #endif |
1076 | #endif |
1064 | break; |
1077 | /* restore old book properties here */ |
1065 | } |
1078 | book->title = old_title; |
1066 | /* shouldnt change map-maker books */ |
1079 | |
1067 | else if (!book->title) |
1080 | if (rndm (4)) |
1068 | do |
|
|
1069 | { |
1081 | { |
1070 | /* random book name */ |
1082 | /* Lets give the book a description to individualize it some */ |
1071 | new_text_name (book, msgtype); |
1083 | char new_name[MAX_BUF]; |
1072 | add_author (book, msgtype); /* random author */ |
1084 | |
1073 | tries++; |
1085 | snprintf (new_name, MAX_BUF, "%s %s", book_descrpt[rndm (nbr)], old_name); |
|
|
1086 | |
|
|
1087 | book->name = new_name; |
1074 | } |
1088 | } |
1075 | while (!unique_book (book, msgtype) && tries < MAX_TITLE_CHECK); |
|
|
1076 | |
|
|
1077 | /* Now deal with 2 cases. |
|
|
1078 | * 1)If no space for a new title exists lets just restore |
|
|
1079 | * the old book properties. Remember, if the book had |
|
|
1080 | * matchd an older entry on the titlelist, we shouldnt |
|
|
1081 | * have called this routine in the first place! |
|
|
1082 | * 2) If we got a unique title, we need to add it to |
|
|
1083 | * the list. |
|
|
1084 | */ |
|
|
1085 | |
|
|
1086 | if (tries == MAX_TITLE_CHECK || numb == maxnames) |
|
|
1087 | { /* got to check maxnames again */ |
|
|
1088 | #ifdef ARCHIVE_DEBUG |
|
|
1089 | LOG (llevDebug, "Failed to obtain unique title for %s %s (names:%d/%d)\n", book->name, book->title, numb, maxnames); |
|
|
1090 | #endif |
|
|
1091 | /* restore old book properties here */ |
|
|
1092 | book->title = old_title; |
|
|
1093 | |
|
|
1094 | if (RANDOM () % 4) |
|
|
1095 | { |
|
|
1096 | /* Lets give the book a description to individualize it some */ |
|
|
1097 | char new_name[MAX_BUF]; |
|
|
1098 | |
|
|
1099 | snprintf (new_name, MAX_BUF, "%s %s", book_descrpt[rndm (nbr)], old_name); |
|
|
1100 | |
|
|
1101 | book->name = new_name; |
|
|
1102 | } |
|
|
1103 | else |
1089 | else |
1104 | { |
1090 | { |
1105 | book->name = old_name; |
1091 | book->name = old_name; |
1106 | } |
1092 | } |
1107 | } |
1093 | } |
1108 | else if (book->title && strlen (book->msg) > 5) |
1094 | else if (book->title && strlen (book->msg) > 5) |
1109 | { /* archive if long msg texts */ |
1095 | { /* archive if long msg texts */ |
1110 | add_book_to_list (book, msgtype); |
1096 | add_book_to_list (book, msgtype); |
1111 | } |
1097 | } |
1112 | } |
1098 | } |
1113 | break; |
1099 | break; |
1114 | } |
1100 | } |
1115 | |
1101 | |
1116 | default: |
1102 | default: |
1117 | LOG (llevError, "change_book_name() called w/ illegal obj type.\n"); |
1103 | LOG (llevError, "change_book_name() called w/ illegal obj type.\n"); |
1118 | return; |
1104 | return; |
1119 | } |
1105 | } |
1120 | } |
1106 | } |
1121 | |
1107 | |
1122 | /***************************************************************************** |
1108 | /***************************************************************************** |
1123 | * |
1109 | * |
… | |
… | |
1134 | * list of all monsters in the current game. If level is non-zero, |
1120 | * list of all monsters in the current game. If level is non-zero, |
1135 | * then only monsters greater than that level will be returned. |
1121 | * then only monsters greater than that level will be returned. |
1136 | * Changed 971225 to be greater than equal to level passed. Also |
1122 | * Changed 971225 to be greater than equal to level passed. Also |
1137 | * made choosing by level more random. |
1123 | * made choosing by level more random. |
1138 | */ |
1124 | */ |
1139 | |
|
|
1140 | object * |
1125 | object * |
1141 | get_random_mon (int level) |
1126 | get_random_mon (int level) |
1142 | { |
1127 | { |
1143 | objectlink *mon = first_mon_info; |
1128 | objectlink *mon = first_mon_info; |
1144 | int i = 0, monnr; |
1129 | int i = 0, monnr; |
… | |
… | |
1148 | return (object *) NULL; |
1133 | return (object *) NULL; |
1149 | |
1134 | |
1150 | if (!level) |
1135 | if (!level) |
1151 | { |
1136 | { |
1152 | /* lets get a random monster from the mon_info linked list */ |
1137 | /* lets get a random monster from the mon_info linked list */ |
1153 | monnr = RANDOM () % nrofmon; |
1138 | monnr = rndm (nrofmon); |
1154 | |
1139 | |
1155 | for (mon = first_mon_info, i = 0; mon; mon = mon->next) |
1140 | for (mon = first_mon_info, i = 0; mon; mon = mon->next) |
1156 | if (i++ == monnr) |
1141 | if (i++ == monnr) |
1157 | break; |
1142 | break; |
1158 | |
1143 | |
… | |
… | |
1185 | { |
1170 | { |
1186 | LOG (llevError, "get_random_mon() couldn't return monster for level %d\n", level); |
1171 | LOG (llevError, "get_random_mon() couldn't return monster for level %d\n", level); |
1187 | return NULL; |
1172 | return NULL; |
1188 | } |
1173 | } |
1189 | |
1174 | |
1190 | monnr = RANDOM () % i; |
1175 | monnr = rndm (i); |
1191 | for (mon = first_mon_info; mon; mon = mon->next) |
1176 | for (mon = first_mon_info; mon; mon = mon->next) |
1192 | if (mon->ob->level >= level && monnr-- == 0) |
1177 | if (mon->ob->level >= level && monnr-- == 0) |
1193 | return mon->ob; |
1178 | return mon->ob; |
1194 | |
1179 | |
1195 | if (!mon) |
1180 | if (!mon) |
… | |
… | |
1202 | |
1187 | |
1203 | /* |
1188 | /* |
1204 | * Returns a description of the monster. This really needs to be |
1189 | * Returns a description of the monster. This really needs to be |
1205 | * redone, as describe_item really gives a pretty internal description. |
1190 | * redone, as describe_item really gives a pretty internal description. |
1206 | */ |
1191 | */ |
1207 | |
1192 | static const char * |
1208 | char * |
|
|
1209 | mon_desc (const object *mon) |
1193 | mon_desc (const object *mon) |
1210 | { |
1194 | { |
1211 | static char retbuf[HUGE_BUF]; |
1195 | static dynbuf_text buf; buf.clear (); |
1212 | |
1196 | |
1213 | sprintf (retbuf, " *** %s ***\n", &mon->name); |
1197 | buf.printf ("B<< %s >>\r", &mon->name); |
1214 | strcat (retbuf, describe_item (mon, NULL)); |
1198 | buf << describe_item (mon, 0); |
1215 | |
1199 | |
1216 | return retbuf; |
1200 | return buf; |
1217 | } |
1201 | } |
1218 | |
1202 | |
1219 | |
1203 | |
1220 | /* This function returns the next monsters after 'tmp'. If no match is |
1204 | /* This function returns the next monsters after 'tmp'. If no match is |
1221 | * found, it returns NULL (changed 0.94.3 to do this, since the |
1205 | * found, it returns NULL (changed 0.94.3 to do this, since the |
1222 | * calling function (mon_info_msg) seems to expect that. |
1206 | * calling function (mon_info_msg) seems to expect that. |
1223 | */ |
1207 | */ |
1224 | |
1208 | static object * |
1225 | object * |
|
|
1226 | get_next_mon (object *tmp) |
1209 | get_next_mon (object *tmp) |
1227 | { |
1210 | { |
1228 | objectlink *mon; |
1211 | objectlink *mon; |
1229 | |
1212 | |
1230 | for (mon = first_mon_info; mon; mon = mon->next) |
1213 | for (mon = first_mon_info; mon; mon = mon->next) |
… | |
… | |
1239 | else |
1222 | else |
1240 | return first_mon_info->ob; |
1223 | return first_mon_info->ob; |
1241 | |
1224 | |
1242 | } |
1225 | } |
1243 | |
1226 | |
1244 | |
|
|
1245 | |
|
|
1246 | /* mon_info_msg() - generate a message detailing the properties |
1227 | /* mon_info_msg() - generate a message detailing the properties |
1247 | * of a randomly selected monster. |
1228 | * of a randomly selected monster. |
1248 | */ |
1229 | */ |
1249 | |
1230 | static const char * |
1250 | char * |
|
|
1251 | mon_info_msg (int level, int booksize) |
1231 | mon_info_msg (int level, int booksize) |
1252 | { |
1232 | { |
1253 | static char retbuf[BOOK_BUF]; |
1233 | static dynbuf_text buf; buf.clear (); |
1254 | char tmpbuf[HUGE_BUF]; |
|
|
1255 | object *tmp; |
|
|
1256 | |
1234 | |
1257 | /*preamble */ |
1235 | /*preamble */ |
1258 | strcpy (retbuf, "This beastiary contains:"); |
1236 | buf << "This beastiary contains:\n"; |
1259 | |
1237 | |
1260 | /* lets print info on as many monsters as will fit in our |
1238 | /* lets print info on as many monsters as will fit in our |
1261 | * document. |
1239 | * document. |
1262 | * 8-96 Had to change this a bit, otherwise there would |
1240 | * 8-96 Had to change this a bit, otherwise there would |
1263 | * have been an impossibly large number of combinations |
1241 | * have been an impossibly large number of combinations |
1264 | * of text! (and flood out the available number of titles |
1242 | * of text! (and flood out the available number of titles |
1265 | * in the archive in a snap!) -b.t. |
1243 | * in the archive in a snap!) -b.t. |
1266 | */ |
1244 | */ |
1267 | tmp = get_random_mon (level * 3); |
1245 | object *tmp = get_random_mon (level * 3); |
1268 | while (tmp) |
1246 | while (tmp && buf.size () < BOOK_BUF) |
1269 | { |
1247 | { |
1270 | /* monster description */ |
1248 | /* monster description */ |
1271 | sprintf (tmpbuf, "\n---\n%s", mon_desc (tmp)); |
1249 | buf.printf ("\n%s\n", mon_desc (tmp)); |
1272 | |
|
|
1273 | if (!book_overflow (retbuf, tmpbuf, booksize)) |
|
|
1274 | strcat (retbuf, tmpbuf); |
|
|
1275 | else |
|
|
1276 | break; |
|
|
1277 | |
1250 | |
1278 | /* Note that the value this returns is not based on level */ |
1251 | /* Note that the value this returns is not based on level */ |
1279 | tmp = get_next_mon (tmp); |
1252 | tmp = get_next_mon (tmp); |
1280 | } |
1253 | } |
1281 | |
1254 | |
1282 | #ifdef BOOK_MSG_DEBUG |
|
|
1283 | LOG (llevDebug, "\n mon_info_msg() created strng: %d\n", strlen (retbuf)); |
|
|
1284 | fprintf (logfile, " MADE THIS:\n%s\n", retbuf); |
|
|
1285 | #endif |
|
|
1286 | |
|
|
1287 | return retbuf; |
1255 | return buf; |
1288 | } |
1256 | } |
1289 | |
1257 | |
1290 | |
1258 | |
1291 | /***************************************************************************** |
1259 | /***************************************************************************** |
1292 | * Artifact msg generation code. |
1260 | * Artifact msg generation code. |
1293 | ****************************************************************************/ |
1261 | ****************************************************************************/ |
1294 | |
1262 | |
1295 | /* artifact_msg() - generate a message detailing the properties |
1263 | /* artifact_msg() - generate a message detailing the properties |
1296 | * of 1-6 artifacts drawn sequentially from the artifact list. |
1264 | * of 1-6 artifacts drawn sequentially from the artifact list. |
1297 | */ |
1265 | */ |
1298 | const char * |
1266 | static const char * |
1299 | artifact_msg (int level, int booksize) |
1267 | artifact_msg (int level, int booksize) |
1300 | { |
1268 | { |
1301 | artifactlist *al = NULL; |
1269 | artifactlist *al = NULL; |
1302 | artifact *art; |
1270 | artifact *art; |
1303 | int chance, i, type, index; |
1271 | int chance, i, type, index; |
1304 | int book_entries = level > 5 ? RANDOM () % 3 + RANDOM () % 3 + 2 : RANDOM () % level + 1; |
1272 | int book_entries = level > 5 ? rndm (3) + rndm (3) + 2 : rndm (level) + 1; |
1305 | const char *ch; |
1273 | const char *ch; |
1306 | char name[MAX_BUF], buf[BOOK_BUF], sbuf[MAX_BUF]; |
1274 | char name[MAX_BUF]; |
1307 | static char retbuf[BOOK_BUF]; |
|
|
1308 | object *tmp = NULL; |
1275 | object *tmp = NULL; |
|
|
1276 | |
|
|
1277 | static dynbuf_text buf; buf.clear (); |
1309 | |
1278 | |
1310 | /* values greater than 5 create msg buffers that are too big! */ |
1279 | /* values greater than 5 create msg buffers that are too big! */ |
1311 | if (book_entries > 5) |
1280 | if (book_entries > 5) |
1312 | book_entries = 5; |
1281 | book_entries = 5; |
1313 | |
1282 | |
… | |
… | |
1317 | * for that type exists! |
1286 | * for that type exists! |
1318 | */ |
1287 | */ |
1319 | i = 0; |
1288 | i = 0; |
1320 | do |
1289 | do |
1321 | { |
1290 | { |
1322 | index = RANDOM () % (sizeof (art_name_array) / sizeof (arttypename)); |
1291 | index = rndm (sizeof (art_name_array) / sizeof (arttypename)); |
1323 | type = art_name_array[index].type; |
1292 | type = art_name_array[index].type; |
1324 | al = find_artifactlist (type); |
1293 | al = find_artifactlist (type); |
1325 | i++; |
1294 | i++; |
1326 | } |
1295 | } |
1327 | while ((al == NULL) && (i < 10)); |
1296 | while ((al == NULL) && (i < 10)); |
… | |
… | |
1330 | return "None"; |
1299 | return "None"; |
1331 | |
1300 | |
1332 | /* There is no reason to start on the artifact list at the begining. Lets |
1301 | /* There is no reason to start on the artifact list at the begining. Lets |
1333 | * take our starting position randomly... */ |
1302 | * take our starting position randomly... */ |
1334 | art = al->items; |
1303 | art = al->items; |
1335 | for (i = RANDOM () % level + RANDOM () % 2 + 1; i > 0; i--) |
1304 | for (i = rndm (level) + rndm (2) + 1; i > 0; i--) |
1336 | { |
1305 | { |
1337 | if (art == NULL) |
1306 | if (!art) |
1338 | art = al->items; /* hmm, out of stuff, loop back around */ |
1307 | art = al->items; /* hmm, out of stuff, loop back around */ |
|
|
1308 | |
1339 | art = art->next; |
1309 | art = art->next; |
1340 | } |
1310 | } |
1341 | |
1311 | |
1342 | /* the base 'generic' name for our artifact */ |
1312 | /* the base 'generic' name for our artifact */ |
1343 | assign (name, art_name_array[index].name); |
1313 | assign (name, art_name_array[index].name); |
1344 | |
1314 | |
1345 | /* Ok, lets print out the contents */ |
1315 | /* Ok, lets print out the contents */ |
1346 | 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"); |
1347 | |
1319 | |
1348 | /* artifact msg attributes loop. Lets keep adding entries to the 'book' |
1320 | /* artifact msg attributes loop. Lets keep adding entries to the 'book' |
1349 | * 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) |
1350 | */ |
1322 | */ |
1351 | while (book_entries > 0) |
1323 | while (book_entries > 0 && buf.size () < BOOK_BUF) |
1352 | { |
1324 | { |
1353 | |
1325 | |
1354 | if (art == NULL) |
1326 | if (!art) |
1355 | art = al->items; |
1327 | art = al->items; |
1356 | |
1328 | |
1357 | /* separator of items */ |
1329 | buf << '\n'; |
1358 | strcpy (buf, "--- \n"); |
|
|
1359 | |
1330 | |
1360 | /* Name */ |
1331 | /* Name */ |
1361 | if (art->allowed != NULL && strcmp (art->allowed->name, "All")) |
1332 | if (art->allowed && art->allowed->name != shstr_All) |
1362 | { |
1333 | { |
1363 | linked_char *temp, *next = art->allowed; |
1334 | linked_char *temp, *next = art->allowed; |
1364 | |
1335 | |
1365 | do |
1336 | do |
1366 | { |
1337 | { |
1367 | temp = next; |
1338 | temp = next; |
1368 | next = next->next; |
1339 | next = next->next; |
1369 | } |
1340 | } |
1370 | while (next && !RANDOM () % 2); |
1341 | while (next && rndm (2)); |
|
|
1342 | |
1371 | 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); |
1372 | } |
1344 | } |
1373 | else /* default name is used */ |
1345 | else /* default name is used */ |
1374 | 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 "; |
1375 | |
1349 | |
1376 | /* chance of finding */ |
1350 | /* chance of finding */ |
1377 | chance = (int) (100 * ((float) art->chance / al->total_chance)); |
1351 | chance = (int) (100 * ((float) art->chance / al->total_chance)); |
1378 | if (chance >= 20) |
1352 | if (chance >= 20) |
1379 | sprintf (sbuf, "an uncommon"); |
1353 | buf << "an uncommon"; |
1380 | else if (chance >= 10) |
1354 | else if (chance >= 10) |
1381 | sprintf (sbuf, "an unusual"); |
1355 | buf << "an unusual"; |
1382 | else if (chance >= 5) |
1356 | else if (chance >= 5) |
1383 | sprintf (sbuf, "a rare"); |
1357 | buf << "a rare"; |
1384 | else |
1358 | else |
1385 | sprintf (sbuf, "a very rare"); |
1359 | buf << "a very rare"; |
1386 | sprintf (buf, "%s is %s\n", buf, sbuf); |
|
|
1387 | |
1360 | |
1388 | /* value of artifact */ |
1361 | /* value of artifact */ |
1389 | 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"; |
1390 | |
1363 | |
1391 | /* include the message about the artifact, if exists, and book |
1364 | /* include the message about the artifact, if exists, and book |
1392 | * level is kinda high */ |
1365 | * level is kinda high */ |
1393 | if (art->item->msg && (RANDOM () % 4 + 1) < level && !((strlen (art->item->msg) + strlen (buf)) > BOOK_BUF)) |
1366 | if (art->item->msg |
|
|
1367 | && rndm (4) + 1 < level) |
1394 | strcat (buf, art->item->msg); |
1368 | buf << art->item->msg; |
1395 | |
1369 | |
1396 | /* properties of the artifact */ |
1370 | /* properties of the artifact */ |
1397 | tmp = object::create (); |
1371 | tmp = object::create (); |
1398 | add_abilities (tmp, art->item); |
1372 | add_abilities (tmp, art->item); |
1399 | tmp->type = type; |
1373 | tmp->type = type; |
1400 | SET_FLAG (tmp, FLAG_IDENTIFIED); |
1374 | SET_FLAG (tmp, FLAG_IDENTIFIED); |
1401 | if ((ch = describe_item (tmp, NULL)) != NULL && strlen (ch) > 1) |
1375 | if ((ch = describe_item (tmp, 0)) && strlen (ch) > 1) |
1402 | sprintf (buf, "%s Properties of this artifact include: \n %s \n", buf, ch); |
1376 | buf << "\rProperties of this artifact include:\r" << ch << "\n"; |
|
|
1377 | |
1403 | tmp->destroy (); |
1378 | tmp->destroy (); |
1404 | /* add the buf if it will fit */ |
|
|
1405 | if (!book_overflow (retbuf, buf, booksize)) |
|
|
1406 | strcat (retbuf, buf); |
|
|
1407 | else |
|
|
1408 | break; |
|
|
1409 | |
1379 | |
1410 | art = art->next; |
1380 | art = art->next; |
1411 | book_entries--; |
1381 | book_entries--; |
1412 | } |
1382 | } |
1413 | |
1383 | |
1414 | #ifdef BOOK_MSG_DEBUG |
|
|
1415 | LOG (llevDebug, "artifact_msg() created strng: %d\n", strlen (retbuf)); |
|
|
1416 | fprintf (logfile, " MADE THIS:\n%s", retbuf); |
|
|
1417 | #endif |
|
|
1418 | return retbuf; |
1384 | return buf; |
1419 | } |
1385 | } |
1420 | |
1386 | |
1421 | /***************************************************************************** |
1387 | /***************************************************************************** |
1422 | * Spellpath message generation |
1388 | * Spellpath message generation |
1423 | *****************************************************************************/ |
1389 | *****************************************************************************/ |
1424 | |
1390 | |
1425 | /* spellpath_msg() - generate a message detailing the member |
1391 | /* spellpath_msg() - generate a message detailing the member |
1426 | * incantations/prayers (and some of their properties) belonging to |
1392 | * incantations/prayers (and some of their properties) belonging to |
1427 | * a given spellpath. |
1393 | * a given spellpath. |
1428 | */ |
1394 | */ |
1429 | |
1395 | static char * |
1430 | char * |
|
|
1431 | spellpath_msg (int level, int booksize) |
1396 | spellpath_msg (int level, int booksize) |
1432 | { |
1397 | { |
|
|
1398 | static dynbuf_text buf; buf.clear (); |
|
|
1399 | |
1433 | static char retbuf[BOOK_BUF]; |
1400 | static char retbuf[BOOK_BUF]; |
1434 | char tmpbuf[BOOK_BUF]; |
1401 | char tmpbuf[BOOK_BUF]; |
1435 | int path = RANDOM () % NRSPELLPATHS, prayers = RANDOM () % 2; |
1402 | int path = rndm (NRSPELLPATHS), prayers = rndm (2); |
1436 | int did_first_sp = 0; |
|
|
1437 | uint32 pnum = (path == -1) ? PATH_NULL : spellpathdef[path]; |
1403 | uint32 pnum = (path == -1) ? PATH_NULL : spellpathdef[path]; |
1438 | archetype *at; |
1404 | archetype *at; |
1439 | |
1405 | |
1440 | /* Preamble */ |
1406 | /* Preamble */ |
1441 | 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"); |
1442 | |
1409 | |
1443 | if (path == -1) |
1410 | if (path == -1) |
1444 | strcat (retbuf, "having no known spell path.\n"); |
1411 | buf << " having no known spell path.\n"; |
1445 | else |
1412 | else |
1446 | sprintf (retbuf, "%sbelonging to the path of %s:\n", retbuf, spellpathnames[path]); |
1413 | buf << " belonging to the path of B<< " << spellpathnames[path] << " >>:\n\n"; |
1447 | |
1414 | |
1448 | for (at = first_archetype; at != NULL; at = at->next) |
1415 | int seen = 0; |
1449 | { |
1416 | |
|
|
1417 | for_all_archetypes (at) |
1450 | /* Determine if this is an appropriate spell. Must |
1418 | /* Determine if this is an appropriate spell. Must |
1451 | * be of matching path, must be of appropriate type (prayer |
1419 | * be of matching path, must be of appropriate type (prayer |
1452 | * or not), and must be within the valid level range. |
1420 | * or not), and must be within the valid level range. |
1453 | */ |
1421 | */ |
1454 | if (at->clone.type == SPELL && at->clone.path_attuned & pnum && |
1422 | if (at->type == SPELL && at->path_attuned & pnum && |
1455 | ((at->clone.stats.grace && prayers) || (at->clone.stats.sp && !prayers)) && (at->clone.level < (level * 8))) |
1423 | ((at->stats.grace && prayers) || (at->stats.sp && !prayers)) && (at->level < (level * 8))) |
1456 | { |
1424 | { |
1457 | assign (tmpbuf, at->clone.name); |
1425 | seen = 1; |
1458 | |
1426 | buf << at->object::name << '\r'; |
1459 | if (book_overflow (retbuf, tmpbuf, booksize)) |
|
|
1460 | break; |
|
|
1461 | else |
|
|
1462 | { |
|
|
1463 | if (did_first_sp) |
|
|
1464 | strcat (retbuf, ",\n"); |
|
|
1465 | did_first_sp = 1; |
|
|
1466 | strcat (retbuf, tmpbuf); |
|
|
1467 | } |
|
|
1468 | } |
1427 | } |
1469 | } |
1428 | |
1470 | /* Geez, no spells were generated. */ |
1429 | /* Geez, no spells were generated. */ |
1471 | if (!did_first_sp) |
1430 | if (!seen) |
1472 | { |
|
|
1473 | if (RANDOM () % 4) /* usually, lets make a recursive call... */ |
1431 | if (rndm (4)) /* usually, lets make a recursive call... */ |
1474 | spellpath_msg (level, booksize); |
1432 | return spellpath_msg (level, booksize); |
1475 | 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. */ |
1476 | strcat (retbuf, "\n - no known spells exist -\n"); |
1434 | buf << "- no known spells exist.\n"; |
1477 | } |
1435 | |
1478 | else |
|
|
1479 | { |
|
|
1480 | strcat (retbuf, "\n"); |
|
|
1481 | } |
|
|
1482 | return retbuf; |
1436 | return buf; |
1483 | } |
1437 | } |
1484 | |
1438 | |
1485 | /* formula_msg() - generate a message detailing the properties |
1439 | /* formula_msg() - generate a message detailing the properties |
1486 | * of a randomly selected alchemical formula. |
1440 | * of a randomly selected alchemical formula. |
1487 | */ |
1441 | */ |
1488 | void |
1442 | static void |
1489 | make_formula_book (object *book, int level) |
1443 | make_formula_book (object *book, int level) |
1490 | { |
1444 | { |
1491 | char retbuf[BOOK_BUF], title[MAX_BUF]; |
1445 | char retbuf[BOOK_BUF], title[MAX_BUF]; |
1492 | recipelist *fl; |
1446 | recipelist *fl; |
1493 | recipe *formula = NULL; |
1447 | recipe *formula = NULL; |
1494 | int chance; |
1448 | int chance; |
1495 | |
1449 | |
1496 | /* the higher the book level, the more complex (ie number of |
1450 | /* the higher the book level, the more complex (ie number of |
1497 | * ingredients) the formula can be. |
1451 | * ingredients) the formula can be. |
1498 | */ |
1452 | */ |
1499 | fl = get_formulalist (((RANDOM () % level) / 3) + 1); |
1453 | fl = get_formulalist (rndm (level) / 3 + 1); |
1500 | |
1454 | |
1501 | if (!fl) |
1455 | if (!fl) |
1502 | fl = get_formulalist (1); /* safety */ |
1456 | fl = get_formulalist (1); /* safety */ |
1503 | |
1457 | |
1504 | if (fl->total_chance == 0) |
1458 | if (fl->total_chance == 0) |
… | |
… | |
1508 | add_author (book, 4); |
1462 | add_author (book, 4); |
1509 | return; |
1463 | return; |
1510 | } |
1464 | } |
1511 | |
1465 | |
1512 | /* get a random formula, weighted by its bookchance */ |
1466 | /* get a random formula, weighted by its bookchance */ |
1513 | chance = RANDOM () % fl->total_chance; |
1467 | chance = rndm (fl->total_chance); |
1514 | for (formula = fl->items; formula != NULL; formula = formula->next) |
1468 | for (formula = fl->items; formula; formula = formula->next) |
1515 | { |
1469 | { |
1516 | chance -= formula->chance; |
1470 | chance -= formula->chance; |
1517 | if (chance <= 0) |
1471 | if (chance <= 0) |
1518 | break; |
1472 | break; |
1519 | } |
1473 | } |
… | |
… | |
1529 | { |
1483 | { |
1530 | /* looks like a formula was found. Base the amount |
1484 | /* looks like a formula was found. Base the amount |
1531 | * of information on the booklevel and the spellevel |
1485 | * of information on the booklevel and the spellevel |
1532 | * of the formula. */ |
1486 | * of the formula. */ |
1533 | |
1487 | |
1534 | const char *op_name = formula->arch_name[RANDOM () % formula->arch_names]; |
1488 | const char *op_name = formula->arch_name [rndm (formula->arch_names)]; |
1535 | archetype *at; |
1489 | archetype *at; |
1536 | |
1490 | |
1537 | /* preamble */ |
1491 | /* preamble */ |
1538 | sprintf (retbuf, "Herein is described a project using %s: \n", formula->skill ? &formula->skill : "an unknown skill"); |
1492 | sprintf (retbuf, "Herein is described a project using %s: \n", formula->skill ? &formula->skill : "an unknown skill"); |
1539 | |
1493 | |
1540 | if ((at = archetype::find (op_name)) != (archetype *) NULL) |
1494 | if ((at = archetype::find (op_name)) != (archetype *) NULL) |
1541 | op_name = at->clone.name; |
1495 | op_name = at->object::name; |
1542 | else |
1496 | else |
1543 | LOG (llevError, "formula_msg() can't find arch %s for formula.\n", op_name); |
1497 | LOG (llevError, "formula_msg() can't find arch %s for formula.\n", op_name); |
1544 | |
1498 | |
1545 | /* item name */ |
1499 | /* item name */ |
1546 | if (strcmp (formula->title, "NONE")) |
1500 | if (formula->title != shstr_NONE) |
1547 | { |
1501 | { |
1548 | sprintf (retbuf, "%sThe %s of %s", retbuf, op_name, &formula->title); |
1502 | sprintf (retbuf, "%sThe %s of %s", retbuf, op_name, &formula->title); |
1549 | /* This results in things like pile of philo. sulfur. |
1503 | /* This results in things like pile of philo. sulfur. |
1550 | * while philo. sulfur may look better, without this, |
1504 | * while philo. sulfur may look better, without this, |
1551 | * you get things like 'the wise' because its missing the |
1505 | * you get things like 'the wise' because its missing the |
1552 | * water of section. |
1506 | * water of section. |
1553 | */ |
1507 | */ |
1554 | sprintf (title, "%s: %s of %s", |
1508 | sprintf (title, "%s: %s of %s", |
1555 | formula_book_name[RANDOM () % (sizeof (formula_book_name) / sizeof (char *))], op_name, &formula->title); |
1509 | formula_book_name [rndm (sizeof (formula_book_name) / sizeof (char *))], op_name, &formula->title); |
1556 | } |
1510 | } |
1557 | else |
1511 | else |
1558 | { |
1512 | { |
1559 | sprintf (retbuf, "%sThe %s", retbuf, op_name); |
1513 | sprintf (retbuf, "%sThe %s", retbuf, op_name); |
1560 | sprintf (title, "%s: %s", formula_book_name[RANDOM () % (sizeof (formula_book_name) / sizeof (char *))], op_name); |
1514 | sprintf (title, "%s: %s", formula_book_name [rndm (sizeof (formula_book_name) / sizeof (char *))], op_name); |
1561 | if (at->clone.title) |
1515 | if (at->title) |
1562 | { |
1516 | { |
1563 | strcat (retbuf, " "); |
1517 | strcat (retbuf, " "); |
1564 | strcat (retbuf, at->clone.title); |
1518 | strcat (retbuf, at->title); |
1565 | strcat (title, " "); |
1519 | strcat (title, " "); |
1566 | strcat (title, at->clone.title); |
1520 | strcat (title, at->title); |
1567 | } |
1521 | } |
1568 | } |
1522 | } |
|
|
1523 | |
1569 | /* Lets name the book something meaningful ! */ |
1524 | /* Lets name the book something meaningful ! */ |
1570 | book->name = title; |
1525 | book->name = title; |
1571 | book->title = NULL; |
1526 | book->title = NULL; |
1572 | |
1527 | |
1573 | /* ingredients to make it */ |
1528 | /* ingredients to make it */ |
… | |
… | |
1577 | archetype *at; |
1532 | archetype *at; |
1578 | |
1533 | |
1579 | at = archetype::find (formula->cauldron); |
1534 | at = archetype::find (formula->cauldron); |
1580 | |
1535 | |
1581 | sprintf (retbuf + strlen (retbuf), |
1536 | sprintf (retbuf + strlen (retbuf), |
1582 | " may be made at %s using the following ingredients:\n", at ? query_name (&at->clone) : "an unknown place"); |
1537 | " may be made at %s using the following ingredients:\n", at ? query_name (at) : "an unknown place"); |
1583 | |
1538 | |
1584 | for (next = formula->ingred; next != NULL; next = next->next) |
1539 | for (next = formula->ingred; next != NULL; next = next->next) |
1585 | { |
1540 | { |
1586 | strcat (retbuf, next->name); |
1541 | strcat (retbuf, next->name); |
1587 | strcat (retbuf, "\n"); |
1542 | strcat (retbuf, "\n"); |
… | |
… | |
1594 | |
1549 | |
1595 | book->msg = retbuf; |
1550 | book->msg = retbuf; |
1596 | } |
1551 | } |
1597 | } |
1552 | } |
1598 | |
1553 | |
|
|
1554 | #define DESCRIBE_PATH(retbuf, variable, name) \ |
|
|
1555 | if(variable) { \ |
|
|
1556 | int i,j=0; \ |
|
|
1557 | strcat(retbuf,"(" name ": "); \ |
|
|
1558 | for(i=0; i<NRSPELLPATHS; i++) \ |
|
|
1559 | if(variable & (1<<i)) { \ |
|
|
1560 | if (j) \ |
|
|
1561 | strcat(retbuf,", "); \ |
|
|
1562 | else \ |
|
|
1563 | j = 1; \ |
|
|
1564 | strcat(retbuf, spellpathnames[i]); \ |
|
|
1565 | } \ |
|
|
1566 | strcat(retbuf,")"); \ |
|
|
1567 | } |
|
|
1568 | |
1599 | /* god_info_msg() - generate a message detailing the properties |
1569 | /* god_info_msg() - generate a message detailing the properties |
1600 | * of a random god. Used by the book hack. b.t. |
1570 | * of a random god. Used by the book hack. b.t. |
1601 | */ |
1571 | */ |
1602 | const char * |
1572 | static const char * |
1603 | god_info_msg (int level, int booksize) |
1573 | god_info_msg (int level, int booksize) |
1604 | { |
1574 | { |
1605 | static char retbuf[BOOK_BUF]; |
1575 | static char retbuf[BOOK_BUF]; |
1606 | const char *name = NULL; |
1576 | const char *name = NULL; |
1607 | char buf[BOOK_BUF]; |
1577 | char buf[BOOK_BUF]; |
… | |
… | |
1631 | |
1601 | |
1632 | /* Information about the god is random, and based on the level of the |
1602 | /* Information about the god is random, and based on the level of the |
1633 | * 'book'. Probably there is a more intellegent way to implement |
1603 | * 'book'. Probably there is a more intellegent way to implement |
1634 | * this ... |
1604 | * this ... |
1635 | */ |
1605 | */ |
1636 | |
|
|
1637 | while (level > 0) |
1606 | while (level > 0) |
1638 | { |
1607 | { |
1639 | sprintf (buf, " "); |
1608 | sprintf (buf, " "); |
1640 | if (level == 2 && RANDOM () % 2) |
1609 | if (level == 2 && rndm (2)) |
1641 | { /* enemy god */ |
1610 | { /* enemy god */ |
1642 | const char *enemy = god->title; |
1611 | const char *enemy = god->title; |
1643 | |
1612 | |
1644 | if (enemy) |
1613 | if (enemy) |
1645 | sprintf (buf, "The gods %s and %s are enemies.\n ---\n", name, enemy); |
1614 | sprintf (buf, "The gods %s and %s are enemies.\n ---\n", name, enemy); |
1646 | } |
1615 | } |
1647 | |
1616 | |
1648 | if (level == 3 && RANDOM () % 2) |
1617 | if (level == 3 && rndm (2)) |
1649 | { /* enemy race, what the god's holy word effects */ |
1618 | { /* enemy race, what the god's holy word effects */ |
1650 | const char *enemy = god->slaying; |
1619 | const char *enemy = god->slaying; |
1651 | |
1620 | |
1652 | if (enemy && !(god->path_denied & PATH_TURNING)) |
1621 | if (enemy && !(god->path_denied & PATH_TURNING)) |
1653 | if ((i = nstrtok (enemy, ",")) > 0) |
1622 | if ((i = nstrtok (enemy, ",")) > 0) |
… | |
… | |
1662 | sprintf (tmpbuf, "race of%s", strtoktolin (enemy, ",")); |
1631 | sprintf (tmpbuf, "race of%s", strtoktolin (enemy, ",")); |
1663 | sprintf (buf, "%s%s\n ---\n", buf, tmpbuf); |
1632 | sprintf (buf, "%s%s\n ---\n", buf, tmpbuf); |
1664 | } |
1633 | } |
1665 | } |
1634 | } |
1666 | |
1635 | |
1667 | if (level == 4 && RANDOM () % 2) |
1636 | if (level == 4 && rndm (2)) |
1668 | { /* Priest of god gets these protect,vulnerable... */ |
1637 | { /* Priest of god gets these protect,vulnerable... */ |
1669 | char tmpbuf[MAX_BUF]; |
1638 | char tmpbuf[MAX_BUF]; |
1670 | |
1639 | |
1671 | if (const char *cp = describe_resistance (god, 1)) |
1640 | if (const char *cp = describe_resistance (god, 1)) |
1672 | { /* This god does have protections */ |
1641 | { /* This god does have protections */ |
… | |
… | |
1678 | } |
1647 | } |
1679 | else |
1648 | else |
1680 | sprintf (buf, " "); |
1649 | sprintf (buf, " "); |
1681 | } |
1650 | } |
1682 | |
1651 | |
1683 | if (level == 5 && RANDOM () % 2) |
1652 | if (level == 5 && rndm (2)) |
1684 | { /* aligned race, summoning */ |
1653 | { /* aligned race, summoning */ |
1685 | const char *race = god->race; /* aligned race */ |
1654 | const char *race = god->race; /* aligned race */ |
1686 | |
1655 | |
1687 | if (race && !(god->path_denied & PATH_SUMMON)) |
1656 | if (race && !(god->path_denied & PATH_SUMMON)) |
1688 | if ((i = nstrtok (race, ",")) > 0) |
1657 | if ((i = nstrtok (race, ",")) > 0) |
… | |
… | |
1696 | sprintf (tmpbuf, "race of%s", strtoktolin (race, ",")); |
1665 | sprintf (tmpbuf, "race of%s", strtoktolin (race, ",")); |
1697 | sprintf (buf, "%s%s\n ---\n", buf, tmpbuf); |
1666 | sprintf (buf, "%s%s\n ---\n", buf, tmpbuf); |
1698 | } |
1667 | } |
1699 | } |
1668 | } |
1700 | |
1669 | |
1701 | if (level == 6 && RANDOM () % 2) |
1670 | if (level == 6 && rndm (2)) |
1702 | { /* blessing,curse properties of the god */ |
1671 | { /* blessing,curse properties of the god */ |
1703 | char tmpbuf[MAX_BUF]; |
1672 | char tmpbuf[MAX_BUF]; |
1704 | |
1673 | |
1705 | if (const char *cp = describe_resistance (god, 1)) |
1674 | if (const char *cp = describe_resistance (god, 1)) |
1706 | { /* This god does have protections */ |
1675 | { /* This god does have protections */ |
… | |
… | |
1713 | else |
1682 | else |
1714 | sprintf (buf, " "); |
1683 | sprintf (buf, " "); |
1715 | |
1684 | |
1716 | } |
1685 | } |
1717 | |
1686 | |
1718 | if (level == 8 && RANDOM () % 2) |
1687 | if (level == 8 && rndm (2)) |
1719 | { /* immunity, holy possession */ |
1688 | { /* immunity, holy possession */ |
1720 | int has_effect = 0, tmpvar; |
1689 | int has_effect = 0, tmpvar; |
1721 | char tmpbuf[MAX_BUF]; |
1690 | char tmpbuf[MAX_BUF]; |
1722 | |
1691 | |
1723 | sprintf (tmpbuf, "\n"); |
1692 | sprintf (tmpbuf, "\n"); |
… | |
… | |
1741 | } |
1710 | } |
1742 | else |
1711 | else |
1743 | sprintf (buf, " "); |
1712 | sprintf (buf, " "); |
1744 | } |
1713 | } |
1745 | |
1714 | |
1746 | if (level == 12 && RANDOM () % 2) |
1715 | if (level == 12 && rndm (2)) |
1747 | { /* spell paths */ |
1716 | { /* spell paths */ |
1748 | int has_effect = 0, tmpvar; |
1717 | int has_effect = 0, tmpvar; |
1749 | char tmpbuf[MAX_BUF]; |
1718 | char tmpbuf[MAX_BUF]; |
1750 | |
1719 | |
1751 | sprintf (tmpbuf, "\n"); |
1720 | sprintf (tmpbuf, "\n"); |
… | |
… | |
1795 | { /* we got no information beyond the preamble! */ |
1764 | { /* we got no information beyond the preamble! */ |
1796 | strcat (retbuf, " [Unfortunately the rest of the information is\n"); |
1765 | strcat (retbuf, " [Unfortunately the rest of the information is\n"); |
1797 | strcat (retbuf, " hopelessly garbled!]\n ---\n"); |
1766 | strcat (retbuf, " hopelessly garbled!]\n ---\n"); |
1798 | } |
1767 | } |
1799 | #ifdef BOOK_MSG_DEBUG |
1768 | #ifdef BOOK_MSG_DEBUG |
1800 | LOG (llevDebug, "\n god_info_msg() created strng: %d\n", strlen (retbuf)); |
1769 | LOG (llevDebug, "\n god_info_msg() created string: %d\n", strlen (retbuf)); |
1801 | fprintf (logfile, " MADE THIS:\n%s", retbuf); |
1770 | LOG (llevDebug, " MADE THIS:\n%s", retbuf); |
1802 | #endif |
1771 | #endif |
1803 | return retbuf; |
1772 | return retbuf; |
1804 | } |
1773 | } |
1805 | |
1774 | |
1806 | /* tailor_readable_ob()- The main routine. This chooses a random |
1775 | /* tailor_readable_ob()- The main routine. This chooses a random |
… | |
… | |
1821 | */ |
1790 | */ |
1822 | void |
1791 | void |
1823 | tailor_readable_ob (object *book, int msg_type) |
1792 | tailor_readable_ob (object *book, int msg_type) |
1824 | { |
1793 | { |
1825 | char msgbuf[BOOK_BUF]; |
1794 | char msgbuf[BOOK_BUF]; |
1826 | int level = book->level ? (RANDOM () % book->level) + 1 : 1; |
1795 | int level = book->level ? rndm (book->level) + 1 : 1; |
1827 | int book_buf_size; |
1796 | int book_buf_size; |
1828 | |
1797 | |
1829 | /* safety */ |
1798 | /* safety */ |
1830 | if (book->type != BOOK) |
1799 | if (book->type != BOOK) |
1831 | return; |
1800 | return; |
… | |
… | |
1845 | * 2) make sure there is an entry in max_titles[] array. |
1814 | * 2) make sure there is an entry in max_titles[] array. |
1846 | * 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() |
1847 | * and add_authour(). |
1816 | * and add_authour(). |
1848 | * 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 |
1849 | */ |
1818 | */ |
1850 | |
|
|
1851 | msg_type = msg_type > 0 ? msg_type : (RANDOM () % 6); |
1819 | msg_type = msg_type > 0 ? msg_type : rndm (8); |
1852 | switch (msg_type) |
1820 | switch (msg_type*0+2)//D |
1853 | { |
1821 | { |
1854 | case 1: /* monster attrib */ |
1822 | case 1: /* monster attrib */ |
1855 | strcpy (msgbuf, mon_info_msg (level, book_buf_size)); |
1823 | strcpy (msgbuf, mon_info_msg (level, book_buf_size)); |
1856 | break; |
1824 | break; |
1857 | case 2: /* artifact attrib */ |
1825 | case 2: /* artifact attrib */ |
… | |
… | |
1880 | { |
1848 | { |
1881 | book->msg = msgbuf; |
1849 | book->msg = msgbuf; |
1882 | /* lets give the "book" a new name, which may be a compound word */ |
1850 | /* lets give the "book" a new name, which may be a compound word */ |
1883 | change_book (book, msg_type); |
1851 | change_book (book, msg_type); |
1884 | } |
1852 | } |
1885 | |
|
|
1886 | } |
1853 | } |
1887 | |
1854 | |
1888 | |
1855 | |
1889 | /***************************************************************************** |
1856 | /***************************************************************************** |
1890 | * |
1857 | * |
… | |
… | |
1985 | get_readable_message_type (object *readable) |
1952 | get_readable_message_type (object *readable) |
1986 | { |
1953 | { |
1987 | uint8 subtype = readable->subtype; |
1954 | uint8 subtype = readable->subtype; |
1988 | |
1955 | |
1989 | if (subtype > last_readable_subtype) |
1956 | if (subtype > last_readable_subtype) |
1990 | return &(readable_message_types[0]); |
1957 | return &readable_message_types[0]; |
|
|
1958 | |
1991 | return &(readable_message_types[subtype]); |
1959 | return &readable_message_types[subtype]; |
1992 | } |
1960 | } |