| 353 | DISABLE_WARNING_FORMAT_NONLITERAL |
| 354 | |
| 355 | staticfn int |
| 356 | learn(void) |
| 357 | { |
| 358 | int i; |
| 359 | short booktype; |
| 360 | char splname[BUFSZ]; |
| 361 | boolean costly = TRUE, faded_to_blank = FALSE; |
| 362 | struct obj *book = svc.context.spbook.book; |
| 363 | |
| 364 | /* JDS: lenses give 50% faster reading; 33% smaller read time */ |
| 365 | if (svc.context.spbook.delay && ublindf |
| 366 | && ublindf->otyp == LENSES && rn2(2)) |
| 367 | svc.context.spbook.delay++; |
| 368 | if (Confusion) { /* became confused while learning */ |
| 369 | (void) confused_book(book); |
| 370 | svc.context.spbook.book = 0; /* no longer studying */ |
| 371 | svc.context.spbook.o_id = 0; |
| 372 | nomul(svc.context.spbook.delay); /* remaining delay is uninterrupted */ |
| 373 | gm.multi_reason = "reading a book"; |
| 374 | gn.nomovemsg = 0; |
| 375 | svc.context.spbook.delay = 0; |
| 376 | return 0; |
| 377 | } |
| 378 | if (svc.context.spbook.delay) { |
| 379 | /* not if (svc.context.spbook.delay++), so at end delay == 0 */ |
| 380 | svc.context.spbook.delay++; |
| 381 | return 1; /* still busy */ |
| 382 | } |
| 383 | exercise(A_WIS, TRUE); /* you're studying. */ |
| 384 | booktype = book->otyp; |
| 385 | if (booktype == SPE_BOOK_OF_THE_DEAD) { |
| 386 | deadbook(book); |
| 387 | return 0; |
| 388 | } |
| 389 | |
| 390 | Sprintf(splname, |
| 391 | objects[booktype].oc_name_known ? "\"%s\"" : "the \"%s\" spell", |
| 392 | OBJ_NAME(objects[booktype])); |
| 393 | for (i = 0; i < MAXSPELL; i++) |
| 394 | if (spellid(i) == booktype || spellid(i) == NO_SPELL) |
| 395 | break; |
| 396 | |
| 397 | if (i == MAXSPELL) { |
| 398 | impossible("Too many spells memorized!"); |
| 399 | } else if (spellid(i) == booktype) { |
| 400 | /* normal book can be read and re-read a total of 4 times */ |
| 401 | if (book->spestudied > MAX_SPELL_STUDY) { |
| 402 | pline("This spellbook is too faint to be read any more."); |
| 403 | book->otyp = booktype = SPE_BLANK_PAPER; |
| 404 | faded_to_blank = TRUE; |
| 405 | /* reset spestudied as if polymorph had taken place */ |
| 406 | book->spestudied = rn2(book->spestudied); |
| 407 | } else { |
| 408 | Your("knowledge of %s is %s.", splname, |
| 409 | spellknow(i) ? "keener" : "restored"); |
| 410 | incrnknow(i, 1); |
| 411 | book->spestudied++; |
| 412 | exercise(A_WIS, TRUE); /* extra study */ |
nothing calls this directly
no test coverage detected