--- deliantra/server/common/readable.C 2006/08/13 17:16:00 1.1 +++ deliantra/server/common/readable.C 2006/08/29 08:01:35 1.2 @@ -1,6 +1,6 @@ /* * static char *rcsid_readable_c = - * "$Id: readable.C,v 1.1 2006/08/13 17:16:00 elmex Exp $"; + * "$Id: readable.C,v 1.2 2006/08/29 08:01:35 root Exp $"; */ /* @@ -458,9 +458,9 @@ */ static readable_message_type readable_message_types[] = { - /*subtype 0 */ {0,0}, + /*subtype 0 */ {0,0}, /* book messages subtypes */ - /*subtype 1 */ {MSG_TYPE_BOOK, MSG_TYPE_BOOK_CLASP_1}, + /*subtype 1 */ {MSG_TYPE_BOOK, MSG_TYPE_BOOK_CLASP_1}, {MSG_TYPE_BOOK, MSG_TYPE_BOOK_CLASP_2}, {MSG_TYPE_BOOK, MSG_TYPE_BOOK_ELEGANT_1}, {MSG_TYPE_BOOK, MSG_TYPE_BOOK_ELEGANT_2}, @@ -469,7 +469,7 @@ {MSG_TYPE_BOOK, MSG_TYPE_BOOK_SPELL_EVOKER}, {MSG_TYPE_BOOK, MSG_TYPE_BOOK_SPELL_PRAYER}, {MSG_TYPE_BOOK, MSG_TYPE_BOOK_SPELL_PYRO}, - /*subtype 10 */ {MSG_TYPE_BOOK, MSG_TYPE_BOOK_SPELL_SORCERER}, + /*subtype 10 */ {MSG_TYPE_BOOK, MSG_TYPE_BOOK_SPELL_SORCERER}, {MSG_TYPE_BOOK, MSG_TYPE_BOOK_SPELL_SUMMONER}, /* card messages subtypes*/ {MSG_TYPE_CARD, MSG_TYPE_CARD_SIMPLE_1}, @@ -480,7 +480,7 @@ {MSG_TYPE_CARD, MSG_TYPE_CARD_ELEGANT_3}, {MSG_TYPE_CARD, MSG_TYPE_CARD_STRANGE_1}, {MSG_TYPE_CARD, MSG_TYPE_CARD_STRANGE_2}, - /*subtype 20 */ {MSG_TYPE_CARD, MSG_TYPE_CARD_STRANGE_3}, + /*subtype 20 */ {MSG_TYPE_CARD, MSG_TYPE_CARD_STRANGE_3}, {MSG_TYPE_CARD, MSG_TYPE_CARD_MONEY_1}, {MSG_TYPE_CARD, MSG_TYPE_CARD_MONEY_2}, {MSG_TYPE_CARD, MSG_TYPE_CARD_MONEY_3}, @@ -492,7 +492,7 @@ {MSG_TYPE_PAPER, MSG_TYPE_PAPER_LETTER_OLD_1}, {MSG_TYPE_PAPER, MSG_TYPE_PAPER_LETTER_OLD_2}, {MSG_TYPE_PAPER, MSG_TYPE_PAPER_LETTER_NEW_1}, - /*subtype 30 */ {MSG_TYPE_PAPER, MSG_TYPE_PAPER_LETTER_NEW_2}, + /*subtype 30 */ {MSG_TYPE_PAPER, MSG_TYPE_PAPER_LETTER_NEW_2}, {MSG_TYPE_PAPER, MSG_TYPE_PAPER_ENVELOPE_1}, {MSG_TYPE_PAPER, MSG_TYPE_PAPER_ENVELOPE_2}, {MSG_TYPE_PAPER, MSG_TYPE_PAPER_SCROLL_OLD_1}, @@ -504,7 +504,7 @@ /* road signs messages subtypes */ {MSG_TYPE_SIGN, MSG_TYPE_SIGN_BASIC}, {MSG_TYPE_SIGN, MSG_TYPE_SIGN_DIR_LEFT}, - /*subtype 40 */ {MSG_TYPE_SIGN, MSG_TYPE_SIGN_DIR_RIGHT}, + /*subtype 40 */ {MSG_TYPE_SIGN, MSG_TYPE_SIGN_DIR_RIGHT}, {MSG_TYPE_SIGN, MSG_TYPE_SIGN_DIR_BOTH}, /* stones and monument messages */ @@ -516,7 +516,7 @@ {MSG_TYPE_MONUMENT, MSG_TYPE_MONUMENT_STATUE_3}, {MSG_TYPE_MONUMENT, MSG_TYPE_MONUMENT_GRAVESTONE_1}, {MSG_TYPE_MONUMENT, MSG_TYPE_MONUMENT_GRAVESTONE_2}, - /*subtype 50 */ {MSG_TYPE_MONUMENT, MSG_TYPE_MONUMENT_GRAVESTONE_3}, + /*subtype 50 */ {MSG_TYPE_MONUMENT, MSG_TYPE_MONUMENT_GRAVESTONE_3}, {MSG_TYPE_MONUMENT, MSG_TYPE_MONUMENT_WALL_1}, {MSG_TYPE_MONUMENT, MSG_TYPE_MONUMENT_WALL_2}, {MSG_TYPE_MONUMENT, MSG_TYPE_MONUMENT_WALL_3} @@ -544,7 +544,7 @@ { titlelist *bl = (titlelist *) malloc (sizeof (titlelist)); if (bl == NULL) - fatal (OUT_OF_MEMORY); + fatal (OUT_OF_MEMORY); bl->number = 0; bl->first_book = NULL; bl->next = NULL; @@ -556,7 +556,7 @@ { title *t = (title *) malloc (sizeof (title)); if (t == NULL) - fatal (OUT_OF_MEMORY); + fatal (OUT_OF_MEMORY); t->name = NULL; t->archname = NULL; t->authour = NULL; @@ -576,14 +576,14 @@ int number = i; if (number < 0) - return tl; + return tl; while (tl && number) { - if (!tl->next) - tl->next = get_empty_booklist (); - tl = tl->next; - number--; + if (!tl->next) + tl->next = get_empty_booklist (); + tl = tl->next; + number--; } return tl; @@ -603,14 +603,14 @@ int number = 0; if (!buf1 || !buf2) - return 0; + return 0; sprintf (buf, "%s", buf1); sprintf (sbuf, "%s", buf2); tbuf = strtok (buf, sbuf); while (tbuf) { - number++; - tbuf = strtok (NULL, sbuf); + number++; + tbuf = strtok (NULL, sbuf); } return number; } @@ -634,15 +634,15 @@ tbuf = strtok (buf, sbuf); while (tbuf && i > 0) { - strcat (rbuf, tbuf); - i--; - if (i == 1 && maxi > 1) - strcat (rbuf, " and "); - else if (i > 0 && maxi > 1) - strcat (rbuf, ", "); - else - strcat (rbuf, "."); - tbuf = strtok (NULL, sbuf); + strcat (rbuf, tbuf); + i--; + if (i == 1 && maxi > 1) + strcat (rbuf, " and "); + else if (i > 0 && maxi > 1) + strcat (rbuf, ", "); + else + strcat (rbuf, "."); + tbuf = strtok (NULL, sbuf); } return (char *) rbuf; } @@ -652,8 +652,8 @@ { if (buf_overflow (buf1, buf2, BOOK_BUF - 2) /* 2 less so always room for trailing \n */ - || buf_overflow (buf1, buf2, booksize)) - return 1; + || buf_overflow (buf1, buf2, booksize)) + return 1; return 0; @@ -678,7 +678,7 @@ static int did_init_msgfile; if (did_init_msgfile) - return; + return; did_init_msgfile = 1; sprintf (fname, "%s/messages", settings.datadir); @@ -686,42 +686,42 @@ if ((fp = open_and_uncompress (fname, 0, &comp)) != NULL) { - linked_char *tmp = NULL; - while (fgets (buf, MAX_BUF, fp) != NULL) - { - if (*buf == '#') - continue; - if ((cp = strchr (buf, '\n')) != NULL) - *cp = '\0'; - cp = buf; - while (*cp == ' ') /* Skip blanks */ - cp++; - if (!strncmp (cp, "ENDMSG", 6)) - { - if (strlen (msgbuf) > BOOK_BUF) - { - LOG (llevDebug, "Warning: this string exceeded max book buf size:"); - LOG (llevDebug, " %s", msgbuf); - } - tmp->name = add_string (msgbuf); - tmp->next = first_msg; - first_msg = tmp; - nrofmsg++; - continue; - } - else if (!strncmp (cp, "MSG", 3)) - { - tmp = (linked_char *) malloc (sizeof (linked_char)); - strcpy (msgbuf, " "); /* reset msgbuf for new message */ - continue; - } - else if (!buf_overflow (msgbuf, cp, HUGE_BUF - 1)) - { - strcat (msgbuf, cp); - strcat (msgbuf, "\n"); - } - } - close_and_delete (fp, comp); + linked_char *tmp = NULL; + while (fgets (buf, MAX_BUF, fp) != NULL) + { + if (*buf == '#') + continue; + if ((cp = strchr (buf, '\n')) != NULL) + *cp = '\0'; + cp = buf; + while (*cp == ' ') /* Skip blanks */ + cp++; + if (!strncmp (cp, "ENDMSG", 6)) + { + if (strlen (msgbuf) > BOOK_BUF) + { + LOG (llevDebug, "Warning: this string exceeded max book buf size:"); + LOG (llevDebug, " %s", msgbuf); + } + tmp->name = add_string (msgbuf); + tmp->next = first_msg; + first_msg = tmp; + nrofmsg++; + continue; + } + else if (!strncmp (cp, "MSG", 3)) + { + tmp = (linked_char *) malloc (sizeof (linked_char)); + strcpy (msgbuf, " "); /* reset msgbuf for new message */ + continue; + } + else if (!buf_overflow (msgbuf, cp, HUGE_BUF - 1)) + { + strcat (msgbuf, cp); + strcat (msgbuf, "\n"); + } + } + close_and_delete (fp, comp); } #ifdef BOOK_MSG_DEBUG @@ -747,76 +747,76 @@ static int did_init_barch; if (did_init_barch) - return; + return; did_init_barch = 1; if (!booklist) - booklist = bl; + booklist = bl; sprintf (fname, "%s/bookarch", settings.localdir); LOG (llevDebug, " Reading bookarch from %s...\n", fname); if ((fp = open_and_uncompress (fname, 0, &comp)) != NULL) { - int value, type = 0; - size_t i; + int value, type = 0; + size_t i; - while (fgets (buf, MAX_BUF, fp) != NULL) - { - if (*buf == '#') - continue; - if ((cp = strchr (buf, '\n')) != NULL) - *cp = '\0'; - cp = buf; - while (*cp == ' ') /* Skip blanks */ - cp++; - if (!strncmp (cp, "title", 4)) - { - book = get_empty_book (); /* init new book entry */ - book->name = add_string (strchr (cp, ' ') + 1); - type = -1; - nroftitle++; - continue; - } - if (!strncmp (cp, "authour", 4)) - { - book->authour = add_string (strchr (cp, ' ') + 1); - } - if (!strncmp (cp, "arch", 4)) - { - book->archname = add_string (strchr (cp, ' ') + 1); - } - else if (sscanf (cp, "level %d", &value)) - { - book->level = (uint16) value; - } - else if (sscanf (cp, "type %d", &value)) - { - type = (uint16) value; - } - else if (sscanf (cp, "size %d", &value)) - { - book->size = (uint16) value; - } - else if (sscanf (cp, "index %d", &value)) - { - book->msg_index = (uint16) value; - } - else if (!strncmp (cp, "end", 3)) - { /* link it */ - bl = get_titlelist (type); - book->next = bl->first_book; - bl->first_book = book; - bl->number++; - } - } - LOG (llevDebug, " book archives(used/avail): "); - for (bl = booklist, i = 0; bl != NULL && i < sizeof(max_titles)/sizeof(*max_titles); bl = bl->next, i++) - { - LOG (llevDebug, "(%d/%d)", bl->number, max_titles[i]); - } - LOG (llevDebug, "\n"); - close_and_delete (fp, comp); + while (fgets (buf, MAX_BUF, fp) != NULL) + { + if (*buf == '#') + continue; + if ((cp = strchr (buf, '\n')) != NULL) + *cp = '\0'; + cp = buf; + while (*cp == ' ') /* Skip blanks */ + cp++; + if (!strncmp (cp, "title", 4)) + { + book = get_empty_book (); /* init new book entry */ + book->name = add_string (strchr (cp, ' ') + 1); + type = -1; + nroftitle++; + continue; + } + if (!strncmp (cp, "authour", 4)) + { + book->authour = add_string (strchr (cp, ' ') + 1); + } + if (!strncmp (cp, "arch", 4)) + { + book->archname = add_string (strchr (cp, ' ') + 1); + } + else if (sscanf (cp, "level %d", &value)) + { + book->level = (uint16) value; + } + else if (sscanf (cp, "type %d", &value)) + { + type = (uint16) value; + } + else if (sscanf (cp, "size %d", &value)) + { + book->size = (uint16) value; + } + else if (sscanf (cp, "index %d", &value)) + { + book->msg_index = (uint16) value; + } + else if (!strncmp (cp, "end", 3)) + { /* link it */ + bl = get_titlelist (type); + book->next = bl->first_book; + bl->first_book = book; + bl->number++; + } + } + LOG (llevDebug, " book archives(used/avail): "); + for (bl = booklist, i = 0; bl != NULL && i < sizeof(max_titles)/sizeof(*max_titles); bl = bl->next, i++) + { + LOG (llevDebug, "(%d/%d)", bl->number, max_titles[i]); + } + LOG (llevDebug, "\n"); + close_and_delete (fp, comp); } #ifdef BOOK_MSG_DEBUG @@ -836,24 +836,24 @@ static int did_init_mon_info = 0; if (did_init_mon_info) - return; + return; did_init_mon_info = 1; for (at = first_archetype; at != NULL; at = at->next) { - if (QUERY_FLAG (&at->clone, FLAG_MONSTER) && - (!QUERY_FLAG (&at->clone, FLAG_CHANGING) - || QUERY_FLAG (&at->clone, FLAG_UNAGGRESSIVE)) - ) - { - objectlink *mon = (objectlink *) malloc (sizeof (objectlink)); - mon->ob = &at->clone; - mon->id = nrofmon; - mon->next = first_mon_info; - first_mon_info = mon; - nrofmon++; - } + if (QUERY_FLAG (&at->clone, FLAG_MONSTER) && + (!QUERY_FLAG (&at->clone, FLAG_CHANGING) + || QUERY_FLAG (&at->clone, FLAG_UNAGGRESSIVE)) + ) + { + objectlink *mon = (objectlink *) malloc (sizeof (objectlink)); + mon->ob = &at->clone; + mon->id = nrofmon; + mon->next = first_mon_info; + first_mon_info = mon; + nrofmon++; + } } LOG (llevDebug, "init_mon_info() got %d monsters\n", nrofmon); } @@ -903,20 +903,20 @@ int index = strtoint (book->msg); if (msgtype < 0) - return (title *) NULL; + return (title *) NULL; if (tl) - t = tl->first_book; + t = tl->first_book; while (t) - if (t->size == length && t->msg_index == index) - break; - else - t = t->next; + if (t->size == length && t->msg_index == index) + break; + else + t = t->next; #ifdef ARCHIVE_DEBUG if (t) - LOG (llevDebug, "Found title match (list %d): %s %s (%d)\n", - msgtype, t->name, t->authour, t->msg_index); + LOG (llevDebug, "Found title match (list %d): %s %s (%d)\n", + msgtype, t->name, t->authour, t->msg_index); #endif return t; @@ -936,43 +936,43 @@ char name[MAX_BUF]; if (book->type != BOOK) - return; + return; switch (msgtype) { case 1: /*monster */ - nbr = sizeof (mon_book_name) / sizeof (char *); - strcpy (name, mon_book_name[RANDOM () % nbr]); - break; + nbr = sizeof (mon_book_name) / sizeof (char *); + strcpy (name, mon_book_name[RANDOM () % nbr]); + break; case 2: /*artifact */ - nbr = sizeof (art_book_name) / sizeof (char *); - strcpy (name, art_book_name[RANDOM () % nbr]); - break; + nbr = sizeof (art_book_name) / sizeof (char *); + strcpy (name, art_book_name[RANDOM () % nbr]); + break; case 3: /*spellpath */ - nbr = sizeof (path_book_name) / sizeof (char *); - strcpy (name, path_book_name[RANDOM () % nbr]); - break; + nbr = sizeof (path_book_name) / sizeof (char *); + strcpy (name, path_book_name[RANDOM () % nbr]); + break; case 4: /*alchemy */ - nbr = sizeof (formula_book_name) / sizeof (char *); - strcpy (name, formula_book_name[RANDOM () % nbr]); - break; + nbr = sizeof (formula_book_name) / sizeof (char *); + strcpy (name, formula_book_name[RANDOM () % nbr]); + break; case 5: /*gods */ - nbr = sizeof (gods_book_name) / sizeof (char *); - strcpy (name, gods_book_name[RANDOM () % nbr]); - break; + nbr = sizeof (gods_book_name) / sizeof (char *); + strcpy (name, gods_book_name[RANDOM () % nbr]); + break; case 6: /*msg file */ default: - if (book->weight > 2000) - { /* based on weight */ - nbr = sizeof (heavy_book_name) / sizeof (char *); - strcpy (name, heavy_book_name[RANDOM () % nbr]); - } - else if (book->weight < 2001) - { - nbr = sizeof (light_book_name) / sizeof (char *); - strcpy (name, light_book_name[RANDOM () % nbr]); - } - break; + if (book->weight > 2000) + { /* based on weight */ + nbr = sizeof (heavy_book_name) / sizeof (char *); + strcpy (name, heavy_book_name[RANDOM () % nbr]); + } + else if (book->weight < 2001) + { + nbr = sizeof (light_book_name) / sizeof (char *); + strcpy (name, light_book_name[RANDOM () % nbr]); + } + break; } free_string (book->name); book->name = add_string (name); @@ -990,33 +990,33 @@ int nbr = sizeof (book_author) / sizeof (char *); if (msgtype < 0 || strlen (op->msg) < 5) - return; + return; switch (msgtype) { case 1: /* monster */ - nbr = sizeof (mon_author) / sizeof (char *); - strcpy (name, mon_author[RANDOM () % nbr]); - break; + nbr = sizeof (mon_author) / sizeof (char *); + strcpy (name, mon_author[RANDOM () % nbr]); + break; case 2: /* artifacts */ - nbr = sizeof (art_author) / sizeof (char *); - strcpy (name, art_author[RANDOM () % nbr]); - break; + nbr = sizeof (art_author) / sizeof (char *); + strcpy (name, art_author[RANDOM () % nbr]); + break; case 3: /* spellpath */ - nbr = sizeof (path_author) / sizeof (char *); - strcpy (name, path_author[RANDOM () % nbr]); - break; + nbr = sizeof (path_author) / sizeof (char *); + strcpy (name, path_author[RANDOM () % nbr]); + break; case 4: /* alchemy */ - nbr = sizeof (formula_author) / sizeof (char *); - strcpy (name, formula_author[RANDOM () % nbr]); - break; + nbr = sizeof (formula_author) / sizeof (char *); + strcpy (name, formula_author[RANDOM () % nbr]); + break; case 5: /* gods */ - nbr = sizeof (gods_author) / sizeof (char *); - strcpy (name, gods_author[RANDOM () % nbr]); - break; + nbr = sizeof (gods_author) / sizeof (char *); + strcpy (name, gods_author[RANDOM () % nbr]); + break; case 6: /* msg file */ default: - strcpy (name, book_author[RANDOM () % nbr]); + strcpy (name, book_author[RANDOM () % nbr]); } sprintf (title, "of %s", name); @@ -1034,14 +1034,14 @@ title *test; if (!booklist) - return 1; /* No archival entries! Must be unique! */ + return 1; /* No archival entries! Must be unique! */ /* Go through the booklist. If the author and name match, not unique so * return 0. */ for (test = get_titlelist (msgtype)->first_book; test; test=test->next) { - if (!strcmp(test->name, book->name) && !strcmp(book->title, test->authour)) - return 0; + if (!strcmp(test->name, book->name) && !strcmp(book->title, test->authour)) + return 0; } return 1; } @@ -1056,8 +1056,8 @@ if (!tl) { - LOG (llevError, "add_book_to_list can't get booklist!\n"); - return; + LOG (llevError, "add_book_to_list can't get booklist!\n"); + return; } t = get_empty_book (); @@ -1077,7 +1077,7 @@ #ifdef ARCHIVE_DEBUG LOG (llevDebug, "Archiving new title: %s %s (%d)\n", book->name, - book->title, msgtype); + book->title, msgtype); #endif } @@ -1101,125 +1101,125 @@ switch (book->type) { case BOOK: - { - titlelist *tl = get_titlelist (msgtype); - title *t = NULL; - int tries = 0; - /* look to see if our msg already been archived. If so, alter - * the book to match the archival text. If we fail to match, - * then we archive the new title/name/msg combo if there is - * room on the titlelist. - */ - - if ((strlen (book->msg) > 5) && (t = find_title (book, msgtype))) - { - object *tmpbook; - - /* alter book properties */ - if ((tmpbook = get_archetype (t->archname)) != NULL) - { - if (tmpbook->msg) - free_string (book->msg); - tmpbook->msg = add_string (book->msg); - copy_object (tmpbook, book); - free_object (tmpbook); - } - - book->title = add_string (t->authour); - free_string (book->name); - book->name = add_string (t->name); - book->level = t->level; - } - /* Don't have any default title, so lets make up a new one */ - else - { - int numb, maxnames = max_titles[msgtype]; - const char *old_title; - const char *old_name; + { + titlelist *tl = get_titlelist (msgtype); + title *t = NULL; + int tries = 0; + /* look to see if our msg already been archived. If so, alter + * the book to match the archival text. If we fail to match, + * then we archive the new title/name/msg combo if there is + * room on the titlelist. + */ + + if ((strlen (book->msg) > 5) && (t = find_title (book, msgtype))) + { + object *tmpbook; + + /* alter book properties */ + if ((tmpbook = get_archetype (t->archname)) != NULL) + { + if (tmpbook->msg) + free_string (book->msg); + tmpbook->msg = add_string (book->msg); + copy_object (tmpbook, book); + free_object (tmpbook); + } + + book->title = add_string (t->authour); + free_string (book->name); + book->name = add_string (t->name); + book->level = t->level; + } + /* Don't have any default title, so lets make up a new one */ + else + { + int numb, maxnames = max_titles[msgtype]; + const char *old_title; + const char *old_name; old_title = book->title ? add_string(book->title) : NULL; old_name = add_string(book->name); - /* some pre-generated books have title already set (from - * maps), also don't bother looking for unique title if - * we already used up all the available names! */ - - if (!tl) - { - LOG (llevError, "change_book_name(): can't find title list\n"); - numb = 0; - } - else - numb = tl->number; + /* some pre-generated books have title already set (from + * maps), also don't bother looking for unique title if + * we already used up all the available names! */ + + if (!tl) + { + LOG (llevError, "change_book_name(): can't find title list\n"); + numb = 0; + } + else + numb = tl->number; - if (numb == maxnames) - { + if (numb == maxnames) + { #ifdef ARCHIVE_DEBUG - LOG (llevDebug, "titles for list %d full (%d possible).\n", - msgtype, maxnames); + LOG (llevDebug, "titles for list %d full (%d possible).\n", + msgtype, maxnames); #endif - if (old_title != NULL) - free_string(old_title); - free_string(old_name); - break; - } - /* shouldnt change map-maker books */ - else if (!book->title) - do - { - /* random book name */ - new_text_name (book, msgtype); - add_author (book, msgtype); /* random author */ - tries++; - } - while (!unique_book (book, msgtype) && tries < MAX_TITLE_CHECK); - - /* Now deal with 2 cases. - * 1)If no space for a new title exists lets just restore - * the old book properties. Remember, if the book had - * matchd an older entry on the titlelist, we shouldnt - * have called this routine in the first place! - * 2) If we got a unique title, we need to add it to - * the list. - */ + if (old_title != NULL) + free_string(old_title); + free_string(old_name); + break; + } + /* shouldnt change map-maker books */ + else if (!book->title) + do + { + /* random book name */ + new_text_name (book, msgtype); + add_author (book, msgtype); /* random author */ + tries++; + } + while (!unique_book (book, msgtype) && tries < MAX_TITLE_CHECK); + + /* Now deal with 2 cases. + * 1)If no space for a new title exists lets just restore + * the old book properties. Remember, if the book had + * matchd an older entry on the titlelist, we shouldnt + * have called this routine in the first place! + * 2) If we got a unique title, we need to add it to + * the list. + */ - if (tries == MAX_TITLE_CHECK || numb == maxnames) - { /* got to check maxnames again */ + if (tries == MAX_TITLE_CHECK || numb == maxnames) + { /* got to check maxnames again */ #ifdef ARCHIVE_DEBUG - LOG (llevDebug, "Failed to obtain unique title for %s %s (names:%d/%d)\n", - book->name, book->title, numb, maxnames); + LOG (llevDebug, "Failed to obtain unique title for %s %s (names:%d/%d)\n", + book->name, book->title, numb, maxnames); #endif - /* restore old book properties here */ - free_string (book->name); - free_string (book->title); - if (old_title!=NULL) - book->title = add_string (old_title); - - if (RANDOM () % 4) { - /* Lets give the book a description to individualize it some */ - char new_name[MAX_BUF]; - snprintf (new_name, MAX_BUF, "%s %s", book_descrpt[RANDOM () % nbr], old_name); + /* restore old book properties here */ + free_string (book->name); + free_string (book->title); + if (old_title!=NULL) + book->title = add_string (old_title); + + if (RANDOM () % 4) { + /* Lets give the book a description to individualize it some */ + char new_name[MAX_BUF]; + snprintf (new_name, MAX_BUF, "%s %s", book_descrpt[RANDOM () % nbr], old_name); - book->name = add_string (new_name); - } else { - book->name = add_string (old_name); - } - } - else if (book->title && strlen (book->msg) > 5) { /* archive if long msg texts */ - add_book_to_list (book, msgtype); - } - - if (old_title != NULL) - free_string(old_title); - free_string(old_name); - - } - break; - } + book->name = add_string (new_name); + } else { + book->name = add_string (old_name); + } + } + else if (book->title && strlen (book->msg) > 5) { /* archive if long msg texts */ + add_book_to_list (book, msgtype); + } + + if (old_title != NULL) + free_string(old_title); + free_string(old_name); + + } + break; + } default: - LOG (llevError, "change_book_name() called w/ illegal obj type.\n"); - return; + LOG (llevError, "change_book_name() called w/ illegal obj type.\n"); + return; } } @@ -1249,23 +1249,23 @@ /* safety check. Problem w/ init_mon_info list? */ if (!nrofmon || !mon) - return (object *) NULL; + return (object *) NULL; if (!level) { - /* lets get a random monster from the mon_info linked list */ - monnr = RANDOM () % nrofmon; + /* lets get a random monster from the mon_info linked list */ + monnr = RANDOM () % nrofmon; - for (mon = first_mon_info, i = 0; mon; mon = mon->next) - if (i++ == monnr) - break; - - if (!mon) - { - LOG (llevError, "get_random_mon: Didn't find a monster when we should have\n"); - return NULL; - } - return mon->ob; + for (mon = first_mon_info, i = 0; mon; mon = mon->next) + if (i++ == monnr) + break; + + if (!mon) + { + LOG (llevError, "get_random_mon: Didn't find a monster when we should have\n"); + return NULL; + } + return mon->ob; } /* Case where we are searching by level. Redone 971225 to be clearer @@ -1282,25 +1282,25 @@ /* First count number of monsters meeting level criteria */ for (mon = first_mon_info, i = 0; mon; mon = mon->next) - if (mon->ob->level >= level) - i++; + if (mon->ob->level >= level) + i++; if (i == 0) { - LOG (llevError, "get_random_mon() couldn't return monster for level %d\n", - level); - return NULL; + LOG (llevError, "get_random_mon() couldn't return monster for level %d\n", + level); + return NULL; } monnr = RANDOM () % i; for (mon = first_mon_info; mon; mon = mon->next) - if (mon->ob->level >= level && monnr-- == 0) - return mon->ob; + if (mon->ob->level >= level && monnr-- == 0) + return mon->ob; if (!mon) { - LOG (llevError, "get_random_mon(): didn't find a monster when we should have\n"); - return NULL; + LOG (llevError, "get_random_mon(): didn't find a monster when we should have\n"); + return NULL; } return NULL; /* Should be unreached, by keeps warnings down */ } @@ -1333,16 +1333,16 @@ objectlink *mon; for (mon = first_mon_info; mon; mon = mon->next) - if (mon->ob == tmp) - break; + if (mon->ob == tmp) + break; /* didn't find a match */ if (!mon) - return NULL; + return NULL; if (mon->next) - return mon->next->ob; + return mon->next->ob; else - return first_mon_info->ob; + return first_mon_info->ob; } @@ -1371,16 +1371,16 @@ */ tmp = get_random_mon (level * 3); while (tmp) { - /* monster description */ - sprintf (tmpbuf, "\n---\n%s", mon_desc (tmp)); + /* monster description */ + sprintf (tmpbuf, "\n---\n%s", mon_desc (tmp)); - if (!book_overflow (retbuf, tmpbuf, booksize)) - strcat (retbuf, tmpbuf); - else - break; + if (!book_overflow (retbuf, tmpbuf, booksize)) + strcat (retbuf, tmpbuf); + else + break; - /* Note that the value this returns is not based on level */ - tmp = get_next_mon (tmp); + /* Note that the value this returns is not based on level */ + tmp = get_next_mon (tmp); } #ifdef BOOK_MSG_DEBUG @@ -1413,7 +1413,7 @@ /* values greater than 5 create msg buffers that are too big! */ if (book_entries > 5) - book_entries = 5; + book_entries = 5; /* lets determine what kind of artifact type randomly. * Right now legal artifacts only come from those listed @@ -1422,23 +1422,23 @@ */ i=0; do { - index = RANDOM () % (sizeof (art_name_array) / sizeof (arttypename)); - type = art_name_array[index].type; - al = find_artifactlist (type); - i++; + index = RANDOM () % (sizeof (art_name_array) / sizeof (arttypename)); + type = art_name_array[index].type; + al = find_artifactlist (type); + i++; } while ((al == NULL) && (i<10)); if (i==10) /* Unable to find a message */ - return("None"); + return("None"); /* There is no reason to start on the artifact list at the begining. Lets * take our starting position randomly... */ art = al->items; for (i = RANDOM () % level + RANDOM () % 2 + 1; i > 0; i--) { - if (art == NULL) - art = al->items; /* hmm, out of stuff, loop back around */ - art = art->next; + if (art == NULL) + art = al->items; /* hmm, out of stuff, loop back around */ + art = art->next; } /* the base 'generic' name for our artifact */ @@ -1446,7 +1446,7 @@ /* Ok, lets print out the contents */ sprintf (retbuf, "Herein %s detailed %s...\n", book_entries > 1 ? "are" : "is", - book_entries > 1 ? "some artifacts" : "an artifact"); + book_entries > 1 ? "some artifacts" : "an artifact"); /* artifact msg attributes loop. Lets keep adding entries to the 'book' * as long as we have space up to the allowed max # (book_entires) @@ -1454,66 +1454,66 @@ while (book_entries > 0) { - if (art == NULL) - art = al->items; + if (art == NULL) + art = al->items; - /* separator of items */ - strcpy (buf, "--- \n"); + /* separator of items */ + strcpy (buf, "--- \n"); - /* Name */ - if (art->allowed != NULL && strcmp (art->allowed->name, "All")) - { - linked_char *temp, *next = art->allowed; - do - { - temp = next; - next = next->next; - } - while ((next != (linked_char *) NULL) && !RANDOM () % 2); - sprintf (buf, "%s A %s of %s", buf, temp->name, art->item->name); - } - else /* default name is used */ - sprintf (buf, "%s The %s of %s", buf, name, art->item->name); - - /* chance of finding */ - chance = (int) (100 * ((float) art->chance / al->total_chance)); - if (chance >= 20) - sprintf (sbuf, "an uncommon"); - else if (chance >= 10) - sprintf (sbuf, "an unusual"); - else if (chance >= 5) - sprintf (sbuf, "a rare"); - else - sprintf (sbuf, "a very rare"); - sprintf (buf, "%s is %s\n", buf, sbuf); - - /* value of artifact */ - sprintf (buf, "%s item with a value that is %d times normal.\n", - buf, art->item->value); - - /* include the message about the artifact, if exists, and book - * level is kinda high */ - if (art->item->msg && (RANDOM () % 4 + 1) < level && - !((strlen (art->item->msg) + strlen (buf)) > BOOK_BUF)) - strcat(buf, art->item->msg); - - /* properties of the artifact */ - tmp = get_object (); - add_abilities (tmp, art->item); - tmp->type = type; - SET_FLAG (tmp, FLAG_IDENTIFIED); - if ((ch = describe_item (tmp, NULL)) != NULL && strlen (ch) > 1) - sprintf (buf, "%s Properties of this artifact include: \n %s \n", - buf, ch); - free_object(tmp); - /* add the buf if it will fit */ - if (!book_overflow (retbuf, buf, booksize)) - strcat (retbuf, buf); - else - break; + /* Name */ + if (art->allowed != NULL && strcmp (art->allowed->name, "All")) + { + linked_char *temp, *next = art->allowed; + do + { + temp = next; + next = next->next; + } + while ((next != (linked_char *) NULL) && !RANDOM () % 2); + sprintf (buf, "%s A %s of %s", buf, temp->name, art->item->name); + } + else /* default name is used */ + sprintf (buf, "%s The %s of %s", buf, name, art->item->name); + + /* chance of finding */ + chance = (int) (100 * ((float) art->chance / al->total_chance)); + if (chance >= 20) + sprintf (sbuf, "an uncommon"); + else if (chance >= 10) + sprintf (sbuf, "an unusual"); + else if (chance >= 5) + sprintf (sbuf, "a rare"); + else + sprintf (sbuf, "a very rare"); + sprintf (buf, "%s is %s\n", buf, sbuf); + + /* value of artifact */ + sprintf (buf, "%s item with a value that is %d times normal.\n", + buf, art->item->value); + + /* include the message about the artifact, if exists, and book + * level is kinda high */ + if (art->item->msg && (RANDOM () % 4 + 1) < level && + !((strlen (art->item->msg) + strlen (buf)) > BOOK_BUF)) + strcat(buf, art->item->msg); + + /* properties of the artifact */ + tmp = get_object (); + add_abilities (tmp, art->item); + tmp->type = type; + SET_FLAG (tmp, FLAG_IDENTIFIED); + if ((ch = describe_item (tmp, NULL)) != NULL && strlen (ch) > 1) + sprintf (buf, "%s Properties of this artifact include: \n %s \n", + buf, ch); + free_object(tmp); + /* add the buf if it will fit */ + if (!book_overflow (retbuf, buf, booksize)) + strcat (retbuf, buf); + else + break; - art = art->next; - book_entries--; + art = art->next; + book_entries--; } #ifdef BOOK_MSG_DEBUG @@ -1544,43 +1544,43 @@ /* Preamble */ sprintf (retbuf, "Herein are detailed the names of %s\n", - prayers ? "prayers": "incantations"); + prayers ? "prayers": "incantations"); if (path == -1) - strcat (retbuf, "having no known spell path.\n"); + strcat (retbuf, "having no known spell path.\n"); else - sprintf (retbuf, "%sbelonging to the path of %s:\n", retbuf, - spellpathnames[path]); + sprintf (retbuf, "%sbelonging to the path of %s:\n", retbuf, + spellpathnames[path]); for (at=first_archetype; at != NULL; at=at->next) { - /* Determine if this is an appropriate spell. Must - * be of matching path, must be of appropriate type (prayer - * or not), and must be within the valid level range. - */ - if (at->clone.type == SPELL && at->clone.path_attuned & pnum && - ((at->clone.stats.grace && prayers) || (at->clone.stats.sp && !prayers)) && - (at->clone.level < (level * 8))) { - strcpy (tmpbuf, at->clone.name); - - if (book_overflow (retbuf, tmpbuf, booksize)) - break; - else { - if (did_first_sp) - strcat (retbuf, ",\n"); - did_first_sp = 1; - strcat (retbuf, tmpbuf); - } - } + /* Determine if this is an appropriate spell. Must + * be of matching path, must be of appropriate type (prayer + * or not), and must be within the valid level range. + */ + if (at->clone.type == SPELL && at->clone.path_attuned & pnum && + ((at->clone.stats.grace && prayers) || (at->clone.stats.sp && !prayers)) && + (at->clone.level < (level * 8))) { + strcpy (tmpbuf, at->clone.name); + + if (book_overflow (retbuf, tmpbuf, booksize)) + break; + else { + if (did_first_sp) + strcat (retbuf, ",\n"); + did_first_sp = 1; + strcat (retbuf, tmpbuf); + } + } } /* Geez, no spells were generated. */ if (!did_first_sp) { - if (RANDOM () % 4) /* usually, lets make a recursive call... */ - spellpath_msg (level, booksize); - else /* give up, cause knowing no spells exist for path is info too. */ - strcat (retbuf, "\n - no known spells exist -\n"); + if (RANDOM () % 4) /* usually, lets make a recursive call... */ + spellpath_msg (level, booksize); + else /* give up, cause knowing no spells exist for path is info too. */ + strcat (retbuf, "\n - no known spells exist -\n"); } else { - strcat (retbuf, "\n"); + strcat (retbuf, "\n"); } return retbuf; } @@ -1603,105 +1603,105 @@ fl = get_formulalist (((RANDOM () % level) / 3) + 1); if (!fl) - fl = get_formulalist (1); /* safety */ + fl = get_formulalist (1); /* safety */ if (fl->total_chance == 0) { - book->msg = add_string(" \n"); - new_text_name(book, 4); - add_author(book,4); - return; + book->msg = add_string(" \n"); + new_text_name(book, 4); + add_author(book,4); + return; } /* get a random formula, weighted by its bookchance */ chance = RANDOM () % fl->total_chance; for (formula = fl->items; formula != NULL; formula = formula->next) { - chance -= formula->chance; - if (chance <= 0) - break; + chance -= formula->chance; + if (chance <= 0) + break; } if (!formula || formula->arch_names <= 0) { - book->msg = add_string(" \n"); - new_text_name(book, 4); - add_author(book,4); - + book->msg = add_string(" \n"); + new_text_name(book, 4); + add_author(book,4); + } else { - /* looks like a formula was found. Base the amount - * of information on the booklevel and the spellevel - * of the formula. */ - - const char *op_name = formula->arch_name[RANDOM()%formula->arch_names]; - archetype *at; - - /* preamble */ - sprintf(retbuf, "Herein is described a project using %s: \n", - formula->skill?formula->skill:"an unknown skill"); - - if ((at = find_archetype (op_name)) != (archetype *) NULL) - op_name = at->clone.name; - else - LOG (llevError, "formula_msg() can't find arch %s for formula.\n", - op_name); - - /* item name */ - if (strcmp (formula->title, "NONE")) { - sprintf (retbuf, "%sThe %s of %s", retbuf, op_name, formula->title); - /* This results in things like pile of philo. sulfur. - * while philo. sulfur may look better, without this, - * you get things like 'the wise' because its missing the - * water of section. - */ - sprintf(title,"%s: %s of %s", - formula_book_name[RANDOM() % (sizeof(formula_book_name) / sizeof(char*))], - op_name, formula->title); - } - else - { - sprintf (retbuf, "%sThe %s", retbuf, op_name); - sprintf(title,"%s: %s", - formula_book_name[RANDOM() % (sizeof(formula_book_name) / sizeof(char*))], - op_name); - if (at->clone.title) - { - strcat (retbuf, " "); - strcat (retbuf, at->clone.title); - strcat(title, " "); - strcat(title, at->clone.title); - } - } - /* Lets name the book something meaningful ! */ - if (book->name) free_string(book->name); - book->name = add_string(title); - if (book->title) { - free_string(book->title); - book->title = NULL; - } - - /* ingredients to make it */ - if (formula->ingred != NULL) - { - linked_char *next; - archetype *at; - - at = find_archetype(formula->cauldron); - - sprintf(retbuf + strlen(retbuf), - " may be made at %s using the following ingredients:\n", - at?query_name(&at->clone):"an unknown place"); - - for (next = formula->ingred; next != NULL; next = next->next) - { - strcat (retbuf, next->name); - strcat (retbuf, "\n"); - } - } - else - LOG (llevError, "formula_msg() no ingredient list for object %s of %s\n", - op_name, formula->title); - if (retbuf[strlen(retbuf)-1]!= '\n') strcat(retbuf, "\n"); - if (book->msg) free_string(book->msg); - book->msg = add_string(retbuf); + /* looks like a formula was found. Base the amount + * of information on the booklevel and the spellevel + * of the formula. */ + + const char *op_name = formula->arch_name[RANDOM()%formula->arch_names]; + archetype *at; + + /* preamble */ + sprintf(retbuf, "Herein is described a project using %s: \n", + formula->skill?formula->skill:"an unknown skill"); + + if ((at = find_archetype (op_name)) != (archetype *) NULL) + op_name = at->clone.name; + else + LOG (llevError, "formula_msg() can't find arch %s for formula.\n", + op_name); + + /* item name */ + if (strcmp (formula->title, "NONE")) { + sprintf (retbuf, "%sThe %s of %s", retbuf, op_name, formula->title); + /* This results in things like pile of philo. sulfur. + * while philo. sulfur may look better, without this, + * you get things like 'the wise' because its missing the + * water of section. + */ + sprintf(title,"%s: %s of %s", + formula_book_name[RANDOM() % (sizeof(formula_book_name) / sizeof(char*))], + op_name, formula->title); + } + else + { + sprintf (retbuf, "%sThe %s", retbuf, op_name); + sprintf(title,"%s: %s", + formula_book_name[RANDOM() % (sizeof(formula_book_name) / sizeof(char*))], + op_name); + if (at->clone.title) + { + strcat (retbuf, " "); + strcat (retbuf, at->clone.title); + strcat(title, " "); + strcat(title, at->clone.title); + } + } + /* Lets name the book something meaningful ! */ + if (book->name) free_string(book->name); + book->name = add_string(title); + if (book->title) { + free_string(book->title); + book->title = NULL; + } + + /* ingredients to make it */ + if (formula->ingred != NULL) + { + linked_char *next; + archetype *at; + + at = find_archetype(formula->cauldron); + + sprintf(retbuf + strlen(retbuf), + " may be made at %s using the following ingredients:\n", + at?query_name(&at->clone):"an unknown place"); + + for (next = formula->ingred; next != NULL; next = next->next) + { + strcat (retbuf, next->name); + strcat (retbuf, "\n"); + } + } + else + LOG (llevError, "formula_msg() no ingredient list for object %s of %s\n", + op_name, formula->title); + if (retbuf[strlen(retbuf)-1]!= '\n') strcat(retbuf, "\n"); + if (book->msg) free_string(book->msg); + book->msg = add_string(retbuf); } } @@ -1721,16 +1721,16 @@ /* get a random message for the 'book' from linked list */ if (nrofmsg > 1) { - msg = first_msg; - msgnum = RANDOM () % nrofmsg; - for (i = 0; msg && i < nrofmsg && i != msgnum; i++) - msg = msg->next; + msg = first_msg; + msgnum = RANDOM () % nrofmsg; + for (i = 0; msg && i < nrofmsg && i != msgnum; i++) + msg = msg->next; } if (msg && !book_overflow (retbuf, msg->name, booksize)) - strcpy (retbuf, msg->name); + strcpy (retbuf, msg->name); else - sprintf (retbuf, "\n "); + sprintf (retbuf, "\n "); #ifdef BOOK_MSG_DEBUG LOG (llevDebug, "\n info_list_msg() created strng: %d\n", strlen (retbuf)); @@ -1756,7 +1756,7 @@ object *god = pntr_to_god_obj (get_rand_god ()); if (!god) - return (char *) NULL; /* oops, problems... */ + return (char *) NULL; /* oops, problems... */ name = god->name; /* preamble.. */ @@ -1766,11 +1766,11 @@ /* Always have as default information the god's descriptive terms. */ if (nstrtok (god->msg, ",") > 0) { - strcat (retbuf, ", known as"); - strcat (retbuf, strtoktolin (god->msg, ",")); + strcat (retbuf, ", known as"); + strcat (retbuf, strtoktolin (god->msg, ",")); } else - strcat (retbuf, "..."); + strcat (retbuf, "..."); strcat (retbuf, "\n ---\n"); introlen = strlen (retbuf); /* so we will know if no new info is added later */ @@ -1782,151 +1782,151 @@ while (level > 0) { - sprintf (buf, " "); - if (level == 2 && RANDOM () % 2) - { /* enemy god */ - const char *enemy = god->title; - if (enemy) - sprintf (buf, "The gods %s and %s are enemies.\n ---\n", - name, enemy); - } - if (level == 3 && RANDOM () % 2) - { /* enemy race, what the god's holy word effects */ - const char *enemy = god->slaying; - if (enemy && !(god->path_denied & PATH_TURNING)) - if ((i = nstrtok (enemy, ",")) > 0) - { - char tmpbuf[MAX_BUF]; - sprintf (buf, "The holy words of %s have the power to\n", name); - strcat (buf, "slay creatures belonging to the "); - if (i > 1) - sprintf (tmpbuf, "following \n races:%s", - strtoktolin (enemy, ",")); - else - sprintf (tmpbuf, "race of%s", strtoktolin (enemy, ",")); - sprintf (buf, "%s%s\n ---\n", buf, tmpbuf); - } - } - if (level == 4 && RANDOM () % 2) - { /* Priest of god gets these protect,vulnerable... */ - char tmpbuf[MAX_BUF],*cp; - - cp = describe_resistance(god, 1); - - if (*cp) { /* This god does have protections */ - sprintf (tmpbuf, "%s has a potent aura which is extended\n" - ,name); - strcat (tmpbuf, "faithful priests. The effects of this aura include:\n"); - strcat(tmpbuf, cp); - strcat (buf, tmpbuf); - strcat (buf, "\n ---\n"); - } - else - sprintf (buf, " "); - } - if (level == 5 && RANDOM () % 2) - { /* aligned race, summoning */ - const char *race = god->race; /* aligned race */ - if (race && !(god->path_denied & PATH_SUMMON)) - if ((i = nstrtok (race, ",")) > 0) - { - char tmpbuf[MAX_BUF]; - sprintf (buf, "Creatures sacred to %s include the \n", name); - if (i > 1) - sprintf (tmpbuf, "following \n races:%s", - strtoktolin (race, ",")); - else - sprintf (tmpbuf, "race of%s", strtoktolin (race, ",")); - sprintf (buf, "%s%s\n ---\n", buf, tmpbuf); - } - } - if (level == 6 && RANDOM () % 2) - { /* blessing,curse properties of the god */ - char tmpbuf[MAX_BUF],*cp; - - cp = describe_resistance(god, 1); - - if (*cp) { /* This god does have protections */ - sprintf (tmpbuf, "\nThe priests of %s are known to be able to \n" - ,name); - strcat (tmpbuf, "bestow a blessing which makes the recipient\n"); - strcat(tmpbuf, cp); - strcat (buf, tmpbuf); - strcat (buf, "\n ---\n"); - } - else - sprintf (buf, " "); - - } - if (level == 8 && RANDOM () % 2) - { /* immunity, holy possession */ - int has_effect = 0, tmpvar; - char tmpbuf[MAX_BUF]; - sprintf (tmpbuf, "\n"); - sprintf (tmpbuf, "The priests of %s are known to make cast a mighty \n" - ,name); - - strcat (tmpbuf, "prayer of possession which gives the recipient\n"); - - for (tmpvar=0; tmpvarresist[tmpvar]==100) { - has_effect = 1; - sprintf(tmpbuf + strlen(tmpbuf),"Immunity to %s", attacktype_desc[tmpvar]); - } - } - if (has_effect) { - strcat (buf, tmpbuf); - strcat (buf, "\n ---\n"); - } - else - sprintf (buf, " "); - } - if (level == 12 && RANDOM () % 2) - { /* spell paths */ - int has_effect = 0, tmpvar; - char tmpbuf[MAX_BUF]; - sprintf (tmpbuf, "\n"); - sprintf (tmpbuf, "It is rarely known fact that the priests of %s\n" - ,name); - strcat (tmpbuf, "are mystically transformed. Effects of this include:\n"); - if ((tmpvar = god->path_attuned)) - { - has_effect = 1; - DESCRIBE_PATH (tmpbuf, tmpvar, "Attuned"); - } - if ((tmpvar = god->path_repelled)) - { - has_effect = 1; - DESCRIBE_PATH (tmpbuf, tmpvar, "Repelled"); - } - if ((tmpvar = god->path_denied)) - { - has_effect = 1; - DESCRIBE_PATH (tmpbuf, tmpvar, "Denied"); - } - if (has_effect) - { - strcat (buf, tmpbuf); - strcat (buf, "\n ---\n"); - } - else - sprintf (buf, " "); - } - - /* check to be sure new buffer size dont exceed either - * the maximum buffer size, or the 'natural' size of the - * book... - */ - if (book_overflow (retbuf, buf, booksize)) - break; - else if (strlen (buf) > 1) - strcat (retbuf, buf); - level--; + sprintf (buf, " "); + if (level == 2 && RANDOM () % 2) + { /* enemy god */ + const char *enemy = god->title; + if (enemy) + sprintf (buf, "The gods %s and %s are enemies.\n ---\n", + name, enemy); + } + if (level == 3 && RANDOM () % 2) + { /* enemy race, what the god's holy word effects */ + const char *enemy = god->slaying; + if (enemy && !(god->path_denied & PATH_TURNING)) + if ((i = nstrtok (enemy, ",")) > 0) + { + char tmpbuf[MAX_BUF]; + sprintf (buf, "The holy words of %s have the power to\n", name); + strcat (buf, "slay creatures belonging to the "); + if (i > 1) + sprintf (tmpbuf, "following \n races:%s", + strtoktolin (enemy, ",")); + else + sprintf (tmpbuf, "race of%s", strtoktolin (enemy, ",")); + sprintf (buf, "%s%s\n ---\n", buf, tmpbuf); + } + } + if (level == 4 && RANDOM () % 2) + { /* Priest of god gets these protect,vulnerable... */ + char tmpbuf[MAX_BUF],*cp; + + cp = describe_resistance(god, 1); + + if (*cp) { /* This god does have protections */ + sprintf (tmpbuf, "%s has a potent aura which is extended\n" + ,name); + strcat (tmpbuf, "faithful priests. The effects of this aura include:\n"); + strcat(tmpbuf, cp); + strcat (buf, tmpbuf); + strcat (buf, "\n ---\n"); + } + else + sprintf (buf, " "); + } + if (level == 5 && RANDOM () % 2) + { /* aligned race, summoning */ + const char *race = god->race; /* aligned race */ + if (race && !(god->path_denied & PATH_SUMMON)) + if ((i = nstrtok (race, ",")) > 0) + { + char tmpbuf[MAX_BUF]; + sprintf (buf, "Creatures sacred to %s include the \n", name); + if (i > 1) + sprintf (tmpbuf, "following \n races:%s", + strtoktolin (race, ",")); + else + sprintf (tmpbuf, "race of%s", strtoktolin (race, ",")); + sprintf (buf, "%s%s\n ---\n", buf, tmpbuf); + } + } + if (level == 6 && RANDOM () % 2) + { /* blessing,curse properties of the god */ + char tmpbuf[MAX_BUF],*cp; + + cp = describe_resistance(god, 1); + + if (*cp) { /* This god does have protections */ + sprintf (tmpbuf, "\nThe priests of %s are known to be able to \n" + ,name); + strcat (tmpbuf, "bestow a blessing which makes the recipient\n"); + strcat(tmpbuf, cp); + strcat (buf, tmpbuf); + strcat (buf, "\n ---\n"); + } + else + sprintf (buf, " "); + + } + if (level == 8 && RANDOM () % 2) + { /* immunity, holy possession */ + int has_effect = 0, tmpvar; + char tmpbuf[MAX_BUF]; + sprintf (tmpbuf, "\n"); + sprintf (tmpbuf, "The priests of %s are known to make cast a mighty \n" + ,name); + + strcat (tmpbuf, "prayer of possession which gives the recipient\n"); + + for (tmpvar=0; tmpvarresist[tmpvar]==100) { + has_effect = 1; + sprintf(tmpbuf + strlen(tmpbuf),"Immunity to %s", attacktype_desc[tmpvar]); + } + } + if (has_effect) { + strcat (buf, tmpbuf); + strcat (buf, "\n ---\n"); + } + else + sprintf (buf, " "); + } + if (level == 12 && RANDOM () % 2) + { /* spell paths */ + int has_effect = 0, tmpvar; + char tmpbuf[MAX_BUF]; + sprintf (tmpbuf, "\n"); + sprintf (tmpbuf, "It is rarely known fact that the priests of %s\n" + ,name); + strcat (tmpbuf, "are mystically transformed. Effects of this include:\n"); + if ((tmpvar = god->path_attuned)) + { + has_effect = 1; + DESCRIBE_PATH (tmpbuf, tmpvar, "Attuned"); + } + if ((tmpvar = god->path_repelled)) + { + has_effect = 1; + DESCRIBE_PATH (tmpbuf, tmpvar, "Repelled"); + } + if ((tmpvar = god->path_denied)) + { + has_effect = 1; + DESCRIBE_PATH (tmpbuf, tmpvar, "Denied"); + } + if (has_effect) + { + strcat (buf, tmpbuf); + strcat (buf, "\n ---\n"); + } + else + sprintf (buf, " "); + } + + /* check to be sure new buffer size dont exceed either + * the maximum buffer size, or the 'natural' size of the + * book... + */ + if (book_overflow (retbuf, buf, booksize)) + break; + else if (strlen (buf) > 1) + strcat (retbuf, buf); + level--; } if (strlen (retbuf) == introlen) { /* we got no information beyond the preamble! */ - strcat (retbuf, " [Unfortunately the rest of the information is\n"); - strcat (retbuf, " hopelessly garbled!]\n ---\n"); + strcat (retbuf, " [Unfortunately the rest of the information is\n"); + strcat (retbuf, " hopelessly garbled!]\n ---\n"); } #ifdef BOOK_MSG_DEBUG LOG (llevDebug, "\n god_info_msg() created strng: %d\n", strlen (retbuf)); @@ -1961,10 +1961,10 @@ /* safety */ if (book->type != BOOK) - return; + return; if (level <= 0) - return; /* if no level no point in doing any more... */ + return; /* if no level no point in doing any more... */ /* Max text length this book can have. */ book_buf_size = BOOKSIZE (book); @@ -1985,36 +1985,36 @@ switch (msg_type) { case 1: /* monster attrib */ - strcpy (msgbuf, mon_info_msg (level, book_buf_size)); - break; + strcpy (msgbuf, mon_info_msg (level, book_buf_size)); + break; case 2: /* artifact attrib */ - strcpy (msgbuf, artifact_msg (level, book_buf_size)); - break; + strcpy (msgbuf, artifact_msg (level, book_buf_size)); + break; case 3: /* grouping incantations/prayers by path */ - strcpy (msgbuf, spellpath_msg (level, book_buf_size)); - break; + strcpy (msgbuf, spellpath_msg (level, book_buf_size)); + break; case 4: /* describe an alchemy formula */ - make_formula_book(book, level); - /* make_formula_book already gives title */ - return; - break; + make_formula_book(book, level); + /* make_formula_book already gives title */ + return; + break; case 5: /* bits of information about a god */ - strcpy (msgbuf, god_info_msg (level, book_buf_size)); - break; + strcpy (msgbuf, god_info_msg (level, book_buf_size)); + break; case 0: /* use info list in lib/ */ default: - strcpy (msgbuf, msgfile_msg (level, book_buf_size)); - break; + strcpy (msgbuf, msgfile_msg (level, book_buf_size)); + break; } strcat (msgbuf, "\n"); /* safety -- we get ugly map saves/crashes w/o this */ if (strlen (msgbuf) > 1) { - if (book->msg) - free_string (book->msg); - book->msg = add_string (msgbuf); - /* lets give the "book" a new name, which may be a compound word */ - change_book (book, msg_type); + if (book->msg) + free_string (book->msg); + book->msg = add_string (msgbuf); + /* lets give the "book" a new name, which may be a compound word */ + change_book (book, msg_type); } } @@ -2038,31 +2038,31 @@ for (tlist = booklist; tlist != NULL; tlist = tnext) { - tnext = tlist->next; - for (title1 = tlist->first_book; title1; title1 = titlenext) - { - titlenext = title1->next; - if (title1->name) - free_string (title1->name); - if (title1->authour) - free_string (title1->authour); - if (title1->archname) - free_string (title1->archname); - free (title1); - } - free (tlist); + tnext = tlist->next; + for (title1 = tlist->first_book; title1; title1 = titlenext) + { + titlenext = title1->next; + if (title1->name) + free_string (title1->name); + if (title1->authour) + free_string (title1->authour); + if (title1->archname) + free_string (title1->archname); + free (title1); + } + free (tlist); } for (lmsg = first_msg; lmsg; lmsg = nextmsg) { - nextmsg = lmsg->next; - if (lmsg->name) - free_string (lmsg->name); - free (lmsg); + nextmsg = lmsg->next; + if (lmsg->name) + free_string (lmsg->name); + free (lmsg); } for (monlink = first_mon_info; monlink; monlink = nextmon) { - nextmon = monlink->next; - free (monlink); + nextmon = monlink->next; + free (monlink); } } @@ -2093,34 +2093,34 @@ if ((fp = fopen (fname, "w")) == NULL) { - LOG (llevDebug, "Can't open book archive file %s\n", fname); + LOG (llevDebug, "Can't open book archive file %s\n", fname); } else { - while (bl) - { - for (book = bl->first_book; book; book = book->next) - if (book && book->authour) - { - fprintf (fp, "title %s\n", book->name); - fprintf (fp, "authour %s\n", book->authour); - fprintf (fp, "arch %s\n", book->archname); - fprintf (fp, "level %d\n", book->level); - fprintf (fp, "type %d\n", index); - fprintf (fp, "size %d\n", book->size); - fprintf (fp, "index %d\n", book->msg_index); - fprintf (fp, "end\n"); - } - bl = bl->next; - index++; - } - fclose (fp); - chmod (fname, SAVE_MODE); + while (bl) + { + for (book = bl->first_book; book; book = book->next) + if (book && book->authour) + { + fprintf (fp, "title %s\n", book->name); + fprintf (fp, "authour %s\n", book->authour); + fprintf (fp, "arch %s\n", book->archname); + fprintf (fp, "level %d\n", book->level); + fprintf (fp, "type %d\n", index); + fprintf (fp, "size %d\n", book->size); + fprintf (fp, "index %d\n", book->msg_index); + fprintf (fp, "end\n"); + } + bl = bl->next; + index++; + } + fclose (fp); + chmod (fname, SAVE_MODE); } } readable_message_type* get_readable_message_type(object* readable){ - uint8 subtype = readable->subtype; - if (subtype>last_readable_subtype) - return &(readable_message_types[0]); - return &(readable_message_types[subtype]); + uint8 subtype = readable->subtype; + if (subtype>last_readable_subtype) + return &(readable_message_types[0]); + return &(readable_message_types[subtype]); }