Crossfire Mailing List Archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
CF: Literacy patch part 3
- To: crossfire (at) ifi.uio.no
- Subject: CF: Literacy patch part 3
- From: Brian Thomas <>
- Date: Sun, 31 Mar 1996 04:45:43 -0500
- Sender:
Alrighty, I spent a little quality time with my code this
evening and fixed (I hope) the root cause of the crashes.
It would appear that endmsg is indeed the problem, but for
me, it only is a problem when the map that has the problem
document is saved. I found that this caused either a wonky
looking map, or a crash. Either way, bad. So I fixed readable.c
so that no more book messages should end w/o "/n
To summerize my code changes: 1) server/init.c 2) common/item.c
and 3) common/readable.c. Thats 3 patches, and I haven't
installed any I didnt make. The patch for readable.c trails
this message. Ok kiddos, try to break the code now :) . As
before, let me know if books are still giving you problems.
Im off to debug the blindness code now....
-b.t.
*** ../../tarfiles/crossfire-0.92.3/common/readable.c Thu Mar 7 03:38:10 1996
--- ../common/readable.c Sun Mar 31 04:02:07 1996
***************
*** 94,103 ****
--- 94,104 ----
default:
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);
}
}
***************
*** 242,264 ****
* of a randomly selected alchemical formula.
*/
char * formula_msg (int level, int booksize) {
static char retbuf[BOOK_BUF];
! recipelist *fl=get_formulalist();
recipe *formula=NULL;
int chance;
/* 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;
}
/* preamble */
! strcpy(retbuf,"Herein is described an alchemical experiment: \n");
/* looks like a formula was found. Base the amount
* of information on the booklevel and the spellevel
* of the formula. */
if(formula) {
--- 243,276 ----
* of a randomly selected alchemical formula.
*/
char * formula_msg (int level, int booksize) {
static char retbuf[BOOK_BUF];
! recipelist *fl;
recipe *formula=NULL;
int chance;
+ /* the higher the book level, the more complex (ie number of
+ * ingredients) the formula can be. */
+ fl = get_formulalist(((RANDOM()%level)/3)+1);
+
+ if(!fl) fl=get_formulalist(1); /* safety */
+
+ if(fl->total_chance==0) {
+ strcpy(retbuf,"\n <undecipherable message> \n");
+ return retbuf;
+ }
+
/* 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;
}
/* preamble */
! strcpy(retbuf,"Herein is described an alchemical proceedure: \n");
/* looks like a formula was found. Base the amount
* of information on the booklevel and the spellevel
* of the formula. */
if(formula) {
***************
*** 315,326 ****
strcpy(retbuf,"This beastuary contains:");
/* lets print info on as many monsters as will fit in our
* document.
*/
! while((tmp=get_random_mon(level*3))) {
/* monster description */
sprintf(tmpbuf,"\n---\n%s",mon_desc(tmp));
if(!book_overflow(retbuf,tmpbuf,booksize))
strcat(retbuf,tmpbuf);
--- 327,339 ----
strcpy(retbuf,"This beastuary contains:");
/* lets print info on as many monsters as will fit in our
* document.
*/
! while((tmp=get_random_mon(level*3))!=NULL) {
+ LOG(llevDebug,"Got monster: %s",tmp->name);
/* monster description */
sprintf(tmpbuf,"\n---\n%s",mon_desc(tmp));
if(!book_overflow(retbuf,tmpbuf,booksize))
strcat(retbuf,tmpbuf);
***************
*** 461,476 ****
if(!did_first_sp)
if(RANDOM()%4) /* usually, lets make a recursive call... */
sprintf(retbuf, spellpath_msg(level,booksize));
else /* give up, cause knowning no spells exist for path is info too. */
strcat(retbuf,"\n - no known spells exist -\n");
- #ifdef BOOK_MSG_DEBUG
else {
LOG(llevDebug,"\n spellpath_msg() created strng: %d\n",strlen(retbuf));
fprintf(logfile," MADE THIS: path=%d pray=%d\n%s\n",path,prayers,retbuf);
- }
#endif
return retbuf;
}
/* artifact_msg() - generate a message detailing the properties
* of 1-6 artifacts drawn sequentially from the artifact list.
--- 474,490 ----
if(!did_first_sp)
if(RANDOM()%4) /* usually, lets make a recursive call... */
sprintf(retbuf, spellpath_msg(level,booksize));
else /* give up, cause knowning no spells exist for path is info too. */
strcat(retbuf,"\n - no known spells exist -\n");
else {
+ #ifdef BOOK_MSG_DEBUG
LOG(llevDebug,"\n spellpath_msg() created strng: %d\n",strlen(retbuf));
fprintf(logfile," MADE THIS: path=%d pray=%d\n%s\n",path,prayers,retbuf);
#endif
+ strcat(retbuf,"\n");
+ }
return retbuf;
}
/* artifact_msg() - generate a message detailing the properties
* of 1-6 artifacts drawn sequentially from the artifact list.
***************
*** 755,765 ****
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 ---");
}
#ifdef BOOK_MSG_DEBUG
LOG(llevDebug,"\n god_info_msg() created strng: %d\n",strlen(retbuf));
fprintf(logfile," MADE THIS:\n%s",retbuf);
#endif
--- 769,779 ----
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");
}
#ifdef BOOK_MSG_DEBUG
LOG(llevDebug,"\n god_info_msg() created strng: %d\n",strlen(retbuf));
fprintf(logfile," MADE THIS:\n%s",retbuf);
#endif
***************
*** 766,776 ****
return retbuf;
}
int book_overflow(char *buf1, char *buf2, int booksize) {
! if( buf_overflow(buf1,buf2,BOOK_BUF)
|| buf_overflow(buf1,buf2,booksize))
return 1;
return 0;
}
--- 780,790 ----
return retbuf;
}
int book_overflow(char *buf1, char *buf2, int booksize) {
! if( buf_overflow(buf1,buf2,BOOK_BUF-2) /* 2 less so always room for trailing \n */
|| buf_overflow(buf1,buf2,booksize))
return 1;
return 0;
}