… | |
… | |
569 | char *tbuf, sbuf[12], buf[MAX_BUF]; |
569 | char *tbuf, sbuf[12], buf[MAX_BUF]; |
570 | int number = 0; |
570 | int number = 0; |
571 | |
571 | |
572 | if (!buf1 || !buf2) |
572 | if (!buf1 || !buf2) |
573 | return 0; |
573 | return 0; |
574 | sprintf (buf, "%s", buf1); |
574 | |
575 | sprintf (sbuf, "%s", buf2); |
575 | strcpy (buf, buf1); |
|
|
576 | strcpy (sbuf, buf2); |
|
|
577 | |
576 | tbuf = strtok (buf, sbuf); |
578 | tbuf = strtok (buf, sbuf); |
577 | while (tbuf) |
579 | while (tbuf) |
578 | { |
580 | { |
579 | number++; |
581 | number++; |
580 | tbuf = strtok (NULL, sbuf); |
582 | tbuf = strtok (NULL, sbuf); |
… | |
… | |
599 | strcpy (rbuf, " "); |
601 | strcpy (rbuf, " "); |
600 | tbuf = strtok (buf, sbuf); |
602 | tbuf = strtok (buf, sbuf); |
601 | while (tbuf && i > 0) |
603 | while (tbuf && i > 0) |
602 | { |
604 | { |
603 | strcat (rbuf, tbuf); |
605 | strcat (rbuf, tbuf); |
|
|
606 | |
604 | i--; |
607 | i--; |
605 | if (i == 1 && maxi > 1) |
608 | if (i == 1 && maxi > 1) |
606 | strcat (rbuf, " and "); |
609 | strcat (rbuf, " and "); |
607 | else if (i > 0 && maxi > 1) |
610 | else if (i > 0 && maxi > 1) |
608 | strcat (rbuf, ", "); |
611 | strcat (rbuf, ", "); |
609 | else |
612 | else |
610 | strcat (rbuf, "."); |
613 | strcat (rbuf, "."); |
|
|
614 | |
611 | tbuf = strtok (NULL, sbuf); |
615 | tbuf = strtok (NULL, sbuf); |
612 | } |
616 | } |
|
|
617 | |
613 | return (char *) rbuf; |
618 | return rbuf; |
614 | } |
619 | } |
615 | |
620 | |
616 | /***************************************************************************** |
621 | /***************************************************************************** |
617 | * |
622 | * |
618 | * Start of initialisation related functions. |
623 | * Start of initialisation related functions. |
… | |
… | |
625 | */ |
630 | */ |
626 | static void |
631 | static void |
627 | init_book_archive () |
632 | init_book_archive () |
628 | { |
633 | { |
629 | int nroftitle = 0; |
634 | int nroftitle = 0; |
630 | char fname[MAX_BUF]; |
|
|
631 | titlelist *bl = get_empty_booklist (); |
635 | titlelist *bl = get_empty_booklist (); |
632 | |
636 | |
633 | sprintf (fname, "%s/bookarch", settings.localdir); |
637 | object_thawer thawer (settings.localdir, "bookarch"); |
634 | LOG (llevDebug, " Reading bookarch from %s...\n", fname); |
|
|
635 | |
|
|
636 | object_thawer thawer (fname); |
|
|
637 | |
638 | |
638 | if (!thawer) |
639 | if (!thawer) |
639 | { |
640 | { |
640 | LOG (llevDebug, "could not read bookarch file\n"); |
641 | LOG (llevDebug, "could not read bookarch file\n"); |
641 | return; |
642 | return; |
… | |
… | |
688 | int i; |
689 | int i; |
689 | for (bl = booklist, i = 0; bl && i < sizeof (max_titles) / sizeof (*max_titles); bl = bl->next, i++) |
690 | for (bl = booklist, i = 0; bl && i < sizeof (max_titles) / sizeof (*max_titles); bl = bl->next, i++) |
690 | LOG (llevDebug, " (%d/%d)\n", bl->number, max_titles[i]); |
691 | LOG (llevDebug, " (%d/%d)\n", bl->number, max_titles[i]); |
691 | |
692 | |
692 | LOG (llevDebug, "init_book_archive() got %d titles.\n", nroftitle); |
693 | LOG (llevDebug, "init_book_archive() got %d titles.\n", nroftitle); |
693 | LOG (llevDebug, " done.\n"); |
|
|
694 | } |
694 | } |
695 | |
695 | |
696 | /* init_mon_info() - creates the linked list of pointers to |
696 | /* init_mon_info() - creates the linked list of pointers to |
697 | * monster archetype objects if not called previously |
697 | * monster archetype objects if not called previously |
698 | */ |
698 | */ |
… | |
… | |
790 | * is given is based on various criteria |
790 | * is given is based on various criteria |
791 | */ |
791 | */ |
792 | static void |
792 | static void |
793 | new_text_name (object *book, int msgtype) |
793 | new_text_name (object *book, int msgtype) |
794 | { |
794 | { |
795 | int nbr; |
795 | const char *name; |
796 | char name[MAX_BUF]; |
|
|
797 | |
796 | |
798 | if (book->type != BOOK) |
797 | if (book->type != BOOK) |
799 | return; |
798 | return; |
800 | |
799 | |
801 | switch (msgtype) |
800 | switch (msgtype) |
802 | { |
801 | { |
803 | case 1: /*monster */ |
802 | case 1: /*monster */ |
804 | nbr = sizeof (mon_book_name) / sizeof (char *); |
803 | name = mon_book_name[rndm (array_length (mon_book_name))]; |
805 | assign (name, mon_book_name[rndm (nbr)]); |
|
|
806 | break; |
804 | break; |
807 | case 2: /*artifact */ |
805 | case 2: /*artifact */ |
808 | nbr = sizeof (art_book_name) / sizeof (char *); |
806 | name = art_book_name[rndm (array_length (art_book_name))]; |
809 | assign (name, art_book_name[rndm (nbr)]); |
|
|
810 | break; |
807 | break; |
811 | case 3: /*spellpath */ |
808 | case 3: /*spellpath */ |
812 | nbr = sizeof (path_book_name) / sizeof (char *); |
809 | name = path_book_name[rndm (array_length (path_book_name))]; |
813 | assign (name, path_book_name[rndm (nbr)]); |
|
|
814 | break; |
810 | break; |
815 | case 4: /*alchemy */ |
811 | case 4: /*alchemy */ |
816 | nbr = sizeof (formula_book_name) / sizeof (char *); |
812 | name = formula_book_name[rndm (array_length (formula_book_name))]; |
817 | assign (name, formula_book_name[rndm (nbr)]); |
|
|
818 | break; |
813 | break; |
819 | case 5: /*gods */ |
814 | case 5: /*gods */ |
820 | nbr = sizeof (gods_book_name) / sizeof (char *); |
815 | name = gods_book_name[rndm (array_length (gods_book_name))]; |
821 | assign (name, gods_book_name[rndm (nbr)]); |
|
|
822 | break; |
816 | break; |
823 | case 6: /*msg file */ |
817 | case 6: /*msg file */ |
824 | default: |
818 | default: |
825 | if (book->weight > 2000) |
819 | if (book->weight > 2000) |
826 | { /* based on weight */ |
820 | { /* based on weight */ |
827 | nbr = sizeof (heavy_book_name) / sizeof (char *); |
821 | name = heavy_book_name[rndm (array_length (heavy_book_name))]; |
828 | assign (name, heavy_book_name[rndm (nbr)]); |
|
|
829 | } |
822 | } |
830 | else if (book->weight < 2001) |
823 | else if (book->weight < 2001) |
831 | { |
824 | { |
832 | nbr = sizeof (light_book_name) / sizeof (char *); |
825 | name = light_book_name[rndm (array_length (light_book_name))]; |
833 | assign (name, light_book_name[rndm (nbr)]); |
|
|
834 | } |
826 | } |
835 | break; |
827 | break; |
836 | } |
828 | } |
837 | |
829 | |
838 | book->name = name; |
830 | book->name = name; |
… | |
… | |
844 | */ |
836 | */ |
845 | |
837 | |
846 | static void |
838 | static void |
847 | add_author (object *op, int msgtype) |
839 | add_author (object *op, int msgtype) |
848 | { |
840 | { |
849 | char title[MAX_BUF], name[MAX_BUF]; |
841 | const char *name; |
850 | int nbr = sizeof (book_author) / sizeof (char *); |
|
|
851 | |
842 | |
852 | if (msgtype < 0 || strlen (op->msg) < 5) |
843 | if (msgtype < 0 || strlen (op->msg) < 5) |
853 | return; |
844 | return; |
854 | |
845 | |
855 | switch (msgtype) |
846 | switch (msgtype) |
856 | { |
847 | { |
857 | case 1: /* monster */ |
848 | case 1: /* monster */ |
858 | nbr = sizeof (mon_author) / sizeof (char *); |
849 | name = mon_author[rndm (array_length (mon_author))]; |
859 | assign (name, mon_author[rndm (nbr)]); |
|
|
860 | break; |
850 | break; |
861 | case 2: /* artifacts */ |
851 | case 2: /* artifacts */ |
862 | nbr = sizeof (art_author) / sizeof (char *); |
852 | name = art_author[rndm (array_length (art_author))]; |
863 | assign (name, art_author[rndm (nbr)]); |
|
|
864 | break; |
853 | break; |
865 | case 3: /* spellpath */ |
854 | case 3: /* spellpath */ |
866 | nbr = sizeof (path_author) / sizeof (char *); |
855 | name = path_author[rndm (array_length (path_author))]; |
867 | assign (name, path_author[rndm (nbr)]); |
|
|
868 | break; |
856 | break; |
869 | case 4: /* alchemy */ |
857 | case 4: /* alchemy */ |
870 | nbr = sizeof (formula_author) / sizeof (char *); |
858 | name = formula_author[rndm (array_length (formula_author))]; |
871 | assign (name, formula_author[rndm (nbr)]); |
|
|
872 | break; |
859 | break; |
873 | case 5: /* gods */ |
860 | case 5: /* gods */ |
874 | nbr = sizeof (gods_author) / sizeof (char *); |
861 | name = gods_author[rndm (array_length (gods_author))]; |
875 | assign (name, gods_author[rndm (nbr)]); |
|
|
876 | break; |
862 | break; |
877 | case 6: /* msg file */ |
863 | case 6: /* msg file */ |
878 | default: |
864 | default: |
879 | assign (name, book_author[rndm (nbr)]); |
865 | name = book_author[rndm (array_length (book_author))]; |
880 | } |
866 | } |
881 | |
867 | |
882 | sprintf (title, "of %s", name); |
868 | op->title = format ("of %s", name); |
883 | op->title = title; |
|
|
884 | } |
869 | } |
885 | |
870 | |
886 | /* unique_book() - check to see if the book title/msg is unique. We |
871 | /* unique_book() - check to see if the book title/msg is unique. We |
887 | * go through the entire list of possibilities each time. If we find |
872 | * go through the entire list of possibilities each time. If we find |
888 | * a match, then unique_book returns true (because inst unique). |
873 | * a match, then unique_book returns true (because inst unique). |
… | |
… | |
1038 | #endif |
1023 | #endif |
1039 | /* restore old book properties here */ |
1024 | /* restore old book properties here */ |
1040 | book->title = old_title; |
1025 | book->title = old_title; |
1041 | |
1026 | |
1042 | if (rndm (4)) |
1027 | if (rndm (4)) |
1043 | { |
|
|
1044 | /* Lets give the book a description to individualize it some */ |
1028 | /* Lets give the book a description to individualize it some */ |
1045 | char new_name[MAX_BUF]; |
|
|
1046 | |
|
|
1047 | snprintf (new_name, MAX_BUF, "%s %s", book_descrpt[rndm (nbr)], old_name); |
1029 | book->name = format ("%s %s", book_descrpt[rndm (nbr)], old_name); |
1048 | |
|
|
1049 | book->name = new_name; |
|
|
1050 | } |
|
|
1051 | else |
1030 | else |
1052 | { |
|
|
1053 | book->name = old_name; |
1031 | book->name = old_name; |
1054 | } |
|
|
1055 | } |
1032 | } |
1056 | else if (book->title && strlen (book->msg) > 5) |
1033 | else if (book->title && strlen (book->msg) > 5) |
1057 | { /* archive if long msg texts */ |
1034 | { /* archive if long msg texts */ |
1058 | add_book_to_list (book, msgtype); |
1035 | add_book_to_list (book, msgtype); |
1059 | } |
1036 | } |
… | |
… | |
1249 | * for that type exists! |
1226 | * for that type exists! |
1250 | */ |
1227 | */ |
1251 | i = 0; |
1228 | i = 0; |
1252 | do |
1229 | do |
1253 | { |
1230 | { |
1254 | index = rndm (sizeof (art_name_array) / sizeof (arttypename)); |
1231 | index = rndm (array_length (art_name_array)); |
1255 | type = art_name_array[index].type; |
1232 | type = art_name_array[index].type; |
1256 | al = find_artifactlist (type); |
1233 | al = find_artifactlist (type); |
1257 | i++; |
1234 | i++; |
1258 | } |
1235 | } |
1259 | while ((al == NULL) && (i < 10)); |
1236 | while ((al == NULL) && (i < 10)); |
… | |
… | |
1579 | int i; |
1556 | int i; |
1580 | |
1557 | |
1581 | if (enemy && !(god->path_denied & PATH_TURNING)) |
1558 | if (enemy && !(god->path_denied & PATH_TURNING)) |
1582 | if ((i = nstrtok (enemy, ",")) > 0) |
1559 | if ((i = nstrtok (enemy, ",")) > 0) |
1583 | { |
1560 | { |
1584 | char tmpbuf[MAX_BUF]; |
|
|
1585 | |
|
|
1586 | buf << "The holy words of " << name |
1561 | buf << "The holy words of " << name |
1587 | << " have the power to slay creatures belonging to the "; |
1562 | << " have the power to slay creatures belonging to the "; |
1588 | |
1563 | |
1589 | if (i > 1) |
1564 | if (i > 1) |
1590 | buf << "following races:" << strtoktolin (enemy, ","); |
1565 | buf << "following races:" << strtoktolin (enemy, ","); |
… | |
… | |
1666 | { /* spell paths */ |
1641 | { /* spell paths */ |
1667 | //TODO: |
1642 | //TODO: |
1668 | int has_effect = 0, tmpvar; |
1643 | int has_effect = 0, tmpvar; |
1669 | char tmpbuf[MAX_BUF]; |
1644 | char tmpbuf[MAX_BUF]; |
1670 | |
1645 | |
1671 | sprintf (tmpbuf, "\n"); |
|
|
1672 | sprintf (tmpbuf, "It is rarely known fact that the priests of %s\n", name); |
1646 | sprintf (tmpbuf, "It is rarely known fact that the priests of %s\n", name); |
1673 | strcat (tmpbuf, "are mystically transformed. Effects of this include:\n"); |
1647 | strcat (tmpbuf, "are mystically transformed. Effects of this include:\n"); |
1674 | |
1648 | |
1675 | if ((tmpvar = god->path_attuned)) |
1649 | if ((tmpvar = god->path_attuned)) |
1676 | { |
1650 | { |