--- deliantra/server/common/readable.C 2007/02/05 01:24:45 1.21 +++ deliantra/server/common/readable.C 2007/05/24 03:33:28 1.24 @@ -1,5 +1,5 @@ /* - * CrossFire, A Multiplayer game for X-windows + * CrossFire, A Multiplayer game * * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team * Copyright (C) 2002 Mark Wedel & Crossfire Development Team @@ -643,79 +643,10 @@ * ****************************************************************************/ -/* init_msgfile() - if not called before, initialise the info list - * reads the messages file into the list pointed to by first_msg -*/ - -static void -init_msgfile (void) -{ - FILE *fp; - char buf[MAX_BUF], msgbuf[HUGE_BUF], fname[MAX_BUF], *cp; - int comp; - static int did_init_msgfile; - - if (did_init_msgfile) - return; - did_init_msgfile = 1; - - sprintf (fname, "%s/messages", settings.datadir); - LOG (llevDebug, "Reading messages from %s...\n", fname); - - 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\n", msgbuf); - } - tmp->name = msgbuf; - tmp->next = first_msg; - first_msg = tmp; - nrofmsg++; - continue; - } - else if (!strncmp (cp, "MSG", 3)) - { - tmp = new 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 - LOG (llevDebug, "init_info_listfile() got %d messages.\n", nrofmsg); -#endif - LOG (llevDebug, "done.\n"); -} - - /* init_book_archive() - if not called before, initialise the info list * This reads in the bookarch file into memory. bookarch is the file * created and updated across multiple runs of the program. */ - static void init_book_archive (void) { @@ -837,14 +768,12 @@ LOG (llevDebug, "init_mon_info() got %d monsters\n", nrofmon); } - /* init_readable() - initialise linked lists utilized by * message functions in tailor_readable_ob() * * This is the function called by the main routine to initialise * all the readable information. */ - void init_readable (void) { @@ -856,11 +785,9 @@ did_this = 1; LOG (llevDebug, "Initialising reading data...\n"); - init_msgfile (); init_book_archive (); init_mon_info (); LOG (llevDebug, " Done\n"); - } /***************************************************************************** @@ -870,11 +797,9 @@ * *****************************************************************************/ - /* find_title() - Search the titlelist (based on msgtype) to see if * book matches something already there. IF so, return that title. */ - static title * find_title (const object *book, int msgtype) { @@ -1370,15 +1295,15 @@ /* artifact_msg() - generate a message detailing the properties * of 1-6 artifacts drawn sequentially from the artifact list. */ - -char * +const char * artifact_msg (int level, int booksize) { artifactlist *al = NULL; artifact *art; int chance, i, type, index; int book_entries = level > 5 ? RANDOM () % 3 + RANDOM () % 3 + 2 : RANDOM () % level + 1; - char *ch, name[MAX_BUF], buf[BOOK_BUF], sbuf[MAX_BUF]; + const char *ch; + char name[MAX_BUF], buf[BOOK_BUF], sbuf[MAX_BUF]; static char retbuf[BOOK_BUF]; object *tmp = NULL; @@ -1402,7 +1327,7 @@ 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... */ @@ -1557,12 +1482,9 @@ return retbuf; } - - /* formula_msg() - generate a message detailing the properties * of a randomly selected alchemical formula. */ - void make_formula_book (object *book, int level) { @@ -1674,46 +1596,9 @@ } } - -/* msgfile_msg() - generate a message drawn randomly from a - * file in lib/. Level currently has no effect on the message - * which is returned. - */ - -char * -msgfile_msg (int level, int booksize) -{ - static char retbuf[BOOK_BUF]; - int i, msgnum; - linked_char *msg = NULL; - - /* 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; - } - - if (msg && !book_overflow (retbuf, msg->name, booksize)) - assign (retbuf, msg->name); - else - sprintf (retbuf, "\n "); - -#ifdef BOOK_MSG_DEBUG - LOG (llevDebug, "\n info_list_msg() created strng: %d\n", strlen (retbuf)); - LOG (llevDebug, " MADE THIS:\n%s\n", retbuf); -#endif - - return retbuf; -} - - /* god_info_msg() - generate a message detailing the properties * of a random god. Used by the book hack. b.t. */ - const char * god_info_msg (int level, int booksize) { @@ -1759,6 +1644,7 @@ 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; @@ -1777,13 +1663,12 @@ 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); + char tmpbuf[MAX_BUF]; - if (*cp) + if (const char *cp = describe_resistance (god, 1)) { /* 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"); @@ -1794,6 +1679,7 @@ else sprintf (buf, " "); } + if (level == 5 && RANDOM () % 2) { /* aligned race, summoning */ const char *race = god->race; /* aligned race */ @@ -1811,13 +1697,12 @@ 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); + char tmpbuf[MAX_BUF]; - if (*cp) + if (const char *cp = describe_resistance (god, 1)) { /* 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"); @@ -1829,6 +1714,7 @@ sprintf (buf, " "); } + if (level == 8 && RANDOM () % 2) { /* immunity, holy possession */ int has_effect = 0, tmpvar; @@ -1847,6 +1733,7 @@ sprintf (tmpbuf + strlen (tmpbuf), "Immunity to %s", attacktype_desc[tmpvar]); } } + if (has_effect) { strcat (buf, tmpbuf); @@ -1855,6 +1742,7 @@ else sprintf (buf, " "); } + if (level == 12 && RANDOM () % 2) { /* spell paths */ int has_effect = 0, tmpvar; @@ -1863,21 +1751,25 @@ 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); @@ -1895,8 +1787,10 @@ 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"); @@ -1925,7 +1819,6 @@ * message type - otherwise a random value is used. * */ - void tailor_readable_ob (object *book, int msg_type) { @@ -1958,27 +1851,27 @@ msg_type = msg_type > 0 ? msg_type : (RANDOM () % 6); switch (msg_type) { - case 1: /* monster attrib */ - strcpy (msgbuf, mon_info_msg (level, book_buf_size)); - break; - case 2: /* artifact attrib */ - 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; - case 4: /* describe an alchemy formula */ - 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; - case 0: /* use info list in lib/ */ - default: - strcpy (msgbuf, msgfile_msg (level, book_buf_size)); - break; + case 1: /* monster attrib */ + strcpy (msgbuf, mon_info_msg (level, book_buf_size)); + break; + case 2: /* artifact attrib */ + 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; + case 4: /* describe an alchemy formula */ + 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; + case 0: /* use info list in lib/ */ + default: + cfperl_make_book (book, level); + return; } strcat (msgbuf, "\n"); /* safety -- we get ugly map saves/crashes w/o this */