ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/common/readable.C
(Generate patch)

Comparing deliantra/server/common/readable.C (file contents):
Revision 1.4 by elmex, Sun Sep 3 14:33:47 2006 UTC vs.
Revision 1.5 by root, Sun Sep 10 16:00:23 2006 UTC

1
1/* 2/*
2 * static char *rcsid_readable_c = 3 * static char *rcsid_readable_c =
3 * "$Id: readable.C,v 1.4 2006/09/03 14:33:47 elmex Exp $"; 4 * "$Id: readable.C,v 1.5 2006/09/10 16:00:23 root Exp $";
4 */ 5 */
5 6
6/* 7/*
7 CrossFire, A Multiplayer game for X-windows 8 CrossFire, A Multiplayer game for X-windows
8 9
67 * be sure to copy it over to the new lib directory when you change versions. 68 * be sure to copy it over to the new lib directory when you change versions.
68 * -b.t. 69 * -b.t.
69 */ 70 */
70 71
71/* This flag is useful to see what kind of output messages are created */ 72/* This flag is useful to see what kind of output messages are created */
73
72/* #define BOOK_MSG_DEBUG */ 74/* #define BOOK_MSG_DEBUG */
73 75
74/* This flag is useful for debuging archiving action */ 76/* This flag is useful for debuging archiving action */
77
75/* #define ARCHIVE_DEBUG */ 78/* #define ARCHIVE_DEBUG */
76 79
77/* Moved these structures from struct.h to this file in 0.94.3 - they 80/* Moved these structures from struct.h to this file in 0.94.3 - they
78 * are not needed anyplace else, so why have them globally declared? 81 * are not needed anyplace else, so why have them globally declared?
79 */ 82 */
80 83
81/* 'title' and 'titlelist' are used by the readable code */ 84/* 'title' and 'titlelist' are used by the readable code */
82typedef struct titlestruct : zero_initialised 85typedef struct titlestruct:zero_initialised
83{ 86{
84 shstr name; /* the name of the book */ 87 shstr name; /* the name of the book */
85 shstr authour; /* the name of the book authour */ 88 shstr authour; /* the name of the book authour */
86 shstr archname; /* the archetype name of the book */ 89 shstr archname; /* the archetype name of the book */
87 int level; /* level of difficulty of this message */ 90 int level; /* level of difficulty of this message */
88 int size; /* size of the book message */ 91 int size; /* size of the book message */
89 int msg_index; /* an index value derived from book message */ 92 int msg_index; /* an index value derived from book message */
90 struct titlestruct *next; 93 struct titlestruct *next;
91} title; 94} title;
92 95
93typedef struct titleliststruct : zero_initialised 96typedef struct titleliststruct:zero_initialised
94{ 97{
95 int number; /* number of items in the list */ 98 int number; /* number of items in the list */
96 struct titlestruct *first_book; /* pointer to first book in this list */ 99 struct titlestruct *first_book; /* pointer to first book in this list */
97 struct titleliststruct *next; /* pointer to next book list */ 100 struct titleliststruct *next; /* pointer to next book list */
98} titlelist; 101} titlelist;
99 102
100/* special structure, used only by art_name_array[] */ 103/* special structure, used only by art_name_array[] */
101 104
102typedef struct namebytype 105typedef struct namebytype
103 { 106{
104 const char *name; /* generic name to call artifacts of this type */ 107 const char *name; /* generic name to call artifacts of this type */
105 int type; /* matching type */ 108 int type; /* matching type */
106 } 109}
107arttypename; 110arttypename;
108 111
109 112
110/* booklist is the buffer of books read in from the bookarch file */ 113/* booklist is the buffer of books read in from the bookarch file */
111static titlelist *booklist = NULL; 114static titlelist *booklist = NULL;
113static objectlink *first_mon_info = NULL; 116static objectlink *first_mon_info = NULL;
114 117
115/* these are needed for creation of a linked list of 118/* these are needed for creation of a linked list of
116 * pointers to all (hostile) monster objects */ 119 * pointers to all (hostile) monster objects */
117 120
118static int nrofmon = 0, need_to_write_bookarchive=0; 121static int nrofmon = 0, need_to_write_bookarchive = 0;
119 122
120 123
121/* this is needed to keep track of status of initialization 124/* this is needed to keep track of status of initialization
122 * of the message file */ 125 * of the message file */
123static int nrofmsg = 0; 126static int nrofmsg = 0;
129 132
130/* 133/*
131 * Spellpath information 134 * Spellpath information
132 */ 135 */
133 136
134static uint32 spellpathdef[NRSPELLPATHS] = 137static uint32 spellpathdef[NRSPELLPATHS] = {
135{
136 PATH_PROT, 138 PATH_PROT,
137 PATH_FIRE, 139 PATH_FIRE,
138 PATH_FROST, 140 PATH_FROST,
139 PATH_ELEC, 141 PATH_ELEC,
140 PATH_MISSILE, 142 PATH_MISSILE,
141 PATH_SELF, 143 PATH_SELF,
142 PATH_SUMMON, 144 PATH_SUMMON,
143 PATH_ABJURE, 145 PATH_ABJURE,
144 PATH_RESTORE, 146 PATH_RESTORE,
145 PATH_DETONATE, 147 PATH_DETONATE,
146 PATH_MIND, 148 PATH_MIND,
147 PATH_CREATE, 149 PATH_CREATE,
148 PATH_TELE, 150 PATH_TELE,
149 PATH_INFO, 151 PATH_INFO,
150 PATH_TRANSMUTE, 152 PATH_TRANSMUTE,
151 PATH_TRANSFER, 153 PATH_TRANSFER,
152 PATH_TURNING, 154 PATH_TURNING,
153 PATH_WOUNDING, 155 PATH_WOUNDING,
154 PATH_DEATH, 156 PATH_DEATH,
155 PATH_LIGHT 157 PATH_LIGHT
156}; 158};
157 159
158static const char* const path_book_name[] = 160static const char *const path_book_name[] = {
159{
160 "codex", 161 "codex",
161 "compendium", 162 "compendium",
162 "exposition", 163 "exposition",
163 "tables", 164 "tables",
164 "treatise" 165 "treatise"
165}; 166};
166 167
167/* used by spellpath texts */ 168/* used by spellpath texts */
168static const char* const path_author[] = 169static const char *const path_author[] = {
169{
170 "aether", 170 "aether",
171 "astral byways", 171 "astral byways",
172 "connections", 172 "connections",
173 "the Grey Council", 173 "the Grey Council",
174 "deep pathways", 174 "deep pathways",
175 "knowledge", 175 "knowledge",
176 "magic", 176 "magic",
177 "mystic ways", 177 "mystic ways",
178 "pathways", 178 "pathways",
179 "power", 179 "power",
180 "spells", 180 "spells",
181 "transforms", 181 "transforms",
182 "the mystic veil", 182 "the mystic veil",
183 "unknown spells" 183 "unknown spells"
184}; 184};
185 185
186/* 186/*
187 * Artiface/item information 187 * Artiface/item information
188 */ 188 */
189 189
190/* if it isnt listed here, then art_attr_msg will never generate 190/* if it isnt listed here, then art_attr_msg will never generate
191 * a message for this type of artifact. -b.t. */ 191 * a message for this type of artifact. -b.t. */
192 192
193static arttypename art_name_array[] = 193static arttypename art_name_array[] = {
194{
195 {"Helmet", HELMET}, 194 {"Helmet", HELMET},
196 {"Amulet", AMULET}, 195 {"Amulet", AMULET},
197 {"Shield", SHIELD}, 196 {"Shield", SHIELD},
198 {"Bracers", BRACERS}, 197 {"Bracers", BRACERS},
199 {"Boots", BOOTS}, 198 {"Boots", BOOTS},
200 {"Cloak", CLOAK}, 199 {"Cloak", CLOAK},
201 {"Gloves", GLOVES}, 200 {"Gloves", GLOVES},
202 {"Gridle", GIRDLE}, 201 {"Gridle", GIRDLE},
203 {"Ring", RING}, 202 {"Ring", RING},
204 {"Horn", HORN}, 203 {"Horn", HORN},
205 {"Missile Weapon", BOW}, 204 {"Missile Weapon", BOW},
206 {"Missile", ARROW}, 205 {"Missile", ARROW},
207 {"Hand Weapon", WEAPON}, 206 {"Hand Weapon", WEAPON},
208 {"Artifact", SKILL}, 207 {"Artifact", SKILL},
209 {"Food", FOOD}, 208 {"Food", FOOD},
210 {"Body Armour", ARMOUR} 209 {"Body Armour", ARMOUR}
211}; 210};
212 211
213static const char* const art_book_name[] = 212static const char *const art_book_name[] = {
214{
215 "collection", 213 "collection",
216 "file", 214 "file",
217 "files", 215 "files",
218 "guide", 216 "guide",
219 "handbook", 217 "handbook",
220 "index", 218 "index",
221 "inventory", 219 "inventory",
222 "list", 220 "list",
223 "listing", 221 "listing",
224 "record", 222 "record",
225 "record book" 223 "record book"
226}; 224};
227 225
228/* used by artifact texts */ 226/* used by artifact texts */
229static const char* const art_author[] = 227static const char *const art_author[] = {
230{
231 "ancient things", 228 "ancient things",
232 "artifacts", 229 "artifacts",
233 "Havlor", /* ancient warrior scribe :) */ 230 "Havlor", /* ancient warrior scribe :) */
234 "items", 231 "items",
235 "lost artifacts", 232 "lost artifacts",
236 "the ancients", 233 "the ancients",
237 "useful things" 234 "useful things"
238}; 235};
239 236
240/* 237/*
241 * Monster book information 238 * Monster book information
242 */ 239 */
243 240
244static const char* const mon_book_name[] = 241static const char *const mon_book_name[] = {
245{
246 "beastuary", 242 "beastuary",
247 "catalog", 243 "catalog",
248 "compilation", 244 "compilation",
249 "collection", 245 "collection",
250 "encyclopedia", 246 "encyclopedia",
251 "guide", 247 "guide",
252 "handbook", 248 "handbook",
253 "list", 249 "list",
254 "manual", 250 "manual",
255 "notes", 251 "notes",
256 "record", 252 "record",
257 "register", 253 "register",
258 "volume" 254 "volume"
259}; 255};
260 256
261 257
262/* used by monster beastuary texts */ 258/* used by monster beastuary texts */
263static const char* const mon_author[] = 259static const char *const mon_author[] = {
264{
265 "beasts", 260 "beasts",
266 "creatures", 261 "creatures",
267 "dezidens", 262 "dezidens",
268 "dwellers", 263 "dwellers",
269 "evil nature", 264 "evil nature",
270 "life", 265 "life",
271 "monsters", 266 "monsters",
272 "nature", 267 "nature",
273 "new life", 268 "new life",
274 "residents", 269 "residents",
275 "the spawn", 270 "the spawn",
276 "the living", 271 "the living",
277 "things" 272 "things"
278}; 273};
279 274
280/* 275/*
281 * God book information 276 * God book information
282 */ 277 */
283 278
284static const char* const gods_book_name[] = 279static const char *const gods_book_name[] = {
285{
286 "devotional", 280 "devotional",
287 "devout notes", 281 "devout notes",
288 "divine text", 282 "divine text",
289 "divine work", 283 "divine work",
290 "holy book", 284 "holy book",
291 "holy record", 285 "holy record",
292 "moral text", 286 "moral text",
293 "sacred guide", 287 "sacred guide",
294 "testament", 288 "testament",
295 "transcript" 289 "transcript"
296}; 290};
297 291
298/* used by gods texts */ 292/* used by gods texts */
299static const char* const gods_author[] = 293static const char *const gods_author[] = {
300{
301 "cults", 294 "cults",
302 "joy", 295 "joy",
303 "lasting curse", 296 "lasting curse",
304 "madness", 297 "madness",
305 "religions", 298 "religions",
306 "the dead", 299 "the dead",
307 "the gods", 300 "the gods",
308 "the heirophant", 301 "the heirophant",
309 "the poor priest", 302 "the poor priest",
310 "the priestess", 303 "the priestess",
311 "pain", 304 "pain",
312 "white" 305 "white"
313}; 306};
314 307
315 308
316/* 309/*
317 * Alchemy (formula) information 310 * Alchemy (formula) information
318 */ 311 */
319 312
320static const char* const formula_book_name[] = 313static const char *const formula_book_name[] = {
321{
322 "cookbook", 314 "cookbook",
323 "formulary", 315 "formulary",
324 "lab book", 316 "lab book",
325 "lab notes", 317 "lab notes",
326 "recipe book", 318 "recipe book",
327 "experiment record", 319 "experiment record",
328 "work plan", 320 "work plan",
329 "design notes" 321 "design notes"
330}; 322};
331 323
332/* this isn't used except for empty books */ 324/* this isn't used except for empty books */
333static const char* const formula_author[] = 325static const char *const formula_author[] = {
334{
335 "Albertus Magnus", 326 "Albertus Magnus",
336 "alchemy", 327 "alchemy",
337 "balms", 328 "balms",
338 "creation", 329 "creation",
339 "dusts", 330 "dusts",
340 "magical manufacture", 331 "magical manufacture",
341 "making", 332 "making",
342 "philosophical items", 333 "philosophical items",
343 "potions", 334 "potions",
344 "powders", 335 "powders",
345 "the cauldron", 336 "the cauldron",
346 "the lamp black", 337 "the lamp black",
347 "transmutation", 338 "transmutation",
348 "waters" 339 "waters"
349}; 340};
350 341
351/* 342/*
352 * Generic book information 343 * Generic book information
353 */ 344 */
354 345
355/* used by msg file and 'generic' books */ 346/* used by msg file and 'generic' books */
356static const char* const light_book_name[] = 347static const char *const light_book_name[] = {
357{
358 "calendar", 348 "calendar",
359 "datebook", 349 "datebook",
360 "diary", 350 "diary",
361 "guidebook", 351 "guidebook",
362 "handbook", 352 "handbook",
363 "ledger", 353 "ledger",
364 "notes", 354 "notes",
365 "notebook", 355 "notebook",
366 "octavo", 356 "octavo",
367 "pamphlet", 357 "pamphlet",
368 "practicum", 358 "practicum",
369 "script", 359 "script",
370 "transcript" 360 "transcript"
371}; 361};
372 362
373static const char* const heavy_book_name[] = 363static const char *const heavy_book_name[] = {
374{
375 "catalog", 364 "catalog",
376 "compendium", 365 "compendium",
377 "guide", 366 "guide",
378 "manual", 367 "manual",
379 "opus", 368 "opus",
380 "tome", 369 "tome",
381 "treatise", 370 "treatise",
382 "volume", 371 "volume",
383 "work" 372 "work"
384}; 373};
385 374
386 375
387/* used by 'generic' books */ 376/* used by 'generic' books */
388static const char* const book_author[] = 377static const char *const book_author[] = {
389{
390 "Abdulah", 378 "Abdulah",
391 "Al'hezred", 379 "Al'hezred",
392 "Alywn", 380 "Alywn",
393 "Arundel", 381 "Arundel",
394 "Arvind", 382 "Arvind",
395 "Aerlingas", 383 "Aerlingas",
396 "Bacon", 384 "Bacon",
397 "Baliqendii", 385 "Baliqendii",
398 "Bosworth", 386 "Bosworth",
399 "Beathis", 387 "Beathis",
400 "Bertil", 388 "Bertil",
401 "Cauchy", 389 "Cauchy",
402 "Chakrabarti", 390 "Chakrabarti",
403 "der Waalis", 391 "der Waalis",
404 "Dirk", 392 "Dirk",
405 "Djwimii", 393 "Djwimii",
406 "Eisenstaadt", 394 "Eisenstaadt",
407 "Fendris", 395 "Fendris",
408 "Frank", 396 "Frank",
409 "Habbi", 397 "Habbi",
410 "Harlod", 398 "Harlod",
411 "Ichibod", 399 "Ichibod",
412 "Janus", 400 "Janus",
413 "June", 401 "June",
414 "Magnuson", 402 "Magnuson",
415 "Nandii", 403 "Nandii",
416 "Nitfeder", 404 "Nitfeder",
417 "Norris", 405 "Norris",
418 "Parael", 406 "Parael",
419 "Penhew", 407 "Penhew",
420 "Sophia", 408 "Sophia",
421 "Skilly", 409 "Skilly",
422 "Tahir", 410 "Tahir",
423 "Thockmorton", 411 "Thockmorton",
424 "Thomas", 412 "Thomas",
425 "van Helsing", 413 "van Helsing",
426 "van Pelt", 414 "van Pelt",
427 "Voormis", 415 "Voormis",
428 "Xavier", 416 "Xavier",
429 "Xeno", 417 "Xeno",
430 "Zardoz", 418 "Zardoz",
431 "Zagy" 419 "Zagy"
432}; 420};
433 421
434static const char* const book_descrpt[] = 422static const char *const book_descrpt[] = {
435{
436 "ancient", 423 "ancient",
437 "cryptic", 424 "cryptic",
438 "cryptical", 425 "cryptical",
439 "dusty", 426 "dusty",
440 "hiearchical", 427 "hiearchical",
441 "grizzled", 428 "grizzled",
442 "gold-guilt", 429 "gold-guilt",
443 "great", 430 "great",
444 "lost", 431 "lost",
445 "magnificent", 432 "magnificent",
446 "musty", 433 "musty",
447 "mythical", 434 "mythical",
448 "mystical", 435 "mystical",
449 "rustic", 436 "rustic",
450 "stained", 437 "stained",
451 "silvered", 438 "silvered",
452 "transcendental", 439 "transcendental",
453 "weathered" 440 "weathered"
454}; 441};
442
455/* Each line of this array is a readable subtype 443/* Each line of this array is a readable subtype
456 * Be careful to keep the order. If you add readable subtype, add them 444 * Be careful to keep the order. If you add readable subtype, add them
457 * at the bottom of the list. Never delete a subtype because index is used as 445 * at the bottom of the list. Never delete a subtype because index is used as
458 * subtype paramater in arch files! 446 * subtype paramater in arch files!
459 */ 447 */
460static readable_message_type readable_message_types[] = 448static readable_message_type readable_message_types[] = {
461{
462 /*subtype 0 */ {0,0}, 449 /*subtype 0 */ {0, 0},
463 /* book messages subtypes */ 450 /* book messages subtypes */
464 /*subtype 1 */ {MSG_TYPE_BOOK, MSG_TYPE_BOOK_CLASP_1}, 451 /*subtype 1 */ {MSG_TYPE_BOOK, MSG_TYPE_BOOK_CLASP_1},
465 {MSG_TYPE_BOOK, MSG_TYPE_BOOK_CLASP_2}, 452 {MSG_TYPE_BOOK, MSG_TYPE_BOOK_CLASP_2},
466 {MSG_TYPE_BOOK, MSG_TYPE_BOOK_ELEGANT_1}, 453 {MSG_TYPE_BOOK, MSG_TYPE_BOOK_ELEGANT_1},
467 {MSG_TYPE_BOOK, MSG_TYPE_BOOK_ELEGANT_2}, 454 {MSG_TYPE_BOOK, MSG_TYPE_BOOK_ELEGANT_2},
468 {MSG_TYPE_BOOK, MSG_TYPE_BOOK_QUARTO_1}, 455 {MSG_TYPE_BOOK, MSG_TYPE_BOOK_QUARTO_1},
469 {MSG_TYPE_BOOK, MSG_TYPE_BOOK_QUARTO_2}, 456 {MSG_TYPE_BOOK, MSG_TYPE_BOOK_QUARTO_2},
470 {MSG_TYPE_BOOK, MSG_TYPE_BOOK_SPELL_EVOKER}, 457 {MSG_TYPE_BOOK, MSG_TYPE_BOOK_SPELL_EVOKER},
471 {MSG_TYPE_BOOK, MSG_TYPE_BOOK_SPELL_PRAYER}, 458 {MSG_TYPE_BOOK, MSG_TYPE_BOOK_SPELL_PRAYER},
472 {MSG_TYPE_BOOK, MSG_TYPE_BOOK_SPELL_PYRO}, 459 {MSG_TYPE_BOOK, MSG_TYPE_BOOK_SPELL_PYRO},
473 /*subtype 10 */ {MSG_TYPE_BOOK, MSG_TYPE_BOOK_SPELL_SORCERER}, 460 /*subtype 10 */ {MSG_TYPE_BOOK, MSG_TYPE_BOOK_SPELL_SORCERER},
474 {MSG_TYPE_BOOK, MSG_TYPE_BOOK_SPELL_SUMMONER}, 461 {MSG_TYPE_BOOK, MSG_TYPE_BOOK_SPELL_SUMMONER},
475 /* card messages subtypes*/ 462 /* card messages subtypes */
476 {MSG_TYPE_CARD, MSG_TYPE_CARD_SIMPLE_1}, 463 {MSG_TYPE_CARD, MSG_TYPE_CARD_SIMPLE_1},
477 {MSG_TYPE_CARD, MSG_TYPE_CARD_SIMPLE_2}, 464 {MSG_TYPE_CARD, MSG_TYPE_CARD_SIMPLE_2},
478 {MSG_TYPE_CARD, MSG_TYPE_CARD_SIMPLE_3}, 465 {MSG_TYPE_CARD, MSG_TYPE_CARD_SIMPLE_3},
479 {MSG_TYPE_CARD, MSG_TYPE_CARD_ELEGANT_1}, 466 {MSG_TYPE_CARD, MSG_TYPE_CARD_ELEGANT_1},
480 {MSG_TYPE_CARD, MSG_TYPE_CARD_ELEGANT_2}, 467 {MSG_TYPE_CARD, MSG_TYPE_CARD_ELEGANT_2},
481 {MSG_TYPE_CARD, MSG_TYPE_CARD_ELEGANT_3}, 468 {MSG_TYPE_CARD, MSG_TYPE_CARD_ELEGANT_3},
482 {MSG_TYPE_CARD, MSG_TYPE_CARD_STRANGE_1}, 469 {MSG_TYPE_CARD, MSG_TYPE_CARD_STRANGE_1},
483 {MSG_TYPE_CARD, MSG_TYPE_CARD_STRANGE_2}, 470 {MSG_TYPE_CARD, MSG_TYPE_CARD_STRANGE_2},
484 /*subtype 20 */ {MSG_TYPE_CARD, MSG_TYPE_CARD_STRANGE_3}, 471 /*subtype 20 */ {MSG_TYPE_CARD, MSG_TYPE_CARD_STRANGE_3},
485 {MSG_TYPE_CARD, MSG_TYPE_CARD_MONEY_1}, 472 {MSG_TYPE_CARD, MSG_TYPE_CARD_MONEY_1},
486 {MSG_TYPE_CARD, MSG_TYPE_CARD_MONEY_2}, 473 {MSG_TYPE_CARD, MSG_TYPE_CARD_MONEY_2},
487 {MSG_TYPE_CARD, MSG_TYPE_CARD_MONEY_3}, 474 {MSG_TYPE_CARD, MSG_TYPE_CARD_MONEY_3},
488 475
489 /* Paper messages subtypes */ 476 /* Paper messages subtypes */
490 {MSG_TYPE_PAPER, MSG_TYPE_PAPER_NOTE_1}, 477 {MSG_TYPE_PAPER, MSG_TYPE_PAPER_NOTE_1},
491 {MSG_TYPE_PAPER, MSG_TYPE_PAPER_NOTE_2}, 478 {MSG_TYPE_PAPER, MSG_TYPE_PAPER_NOTE_2},
492 {MSG_TYPE_PAPER, MSG_TYPE_PAPER_NOTE_3}, 479 {MSG_TYPE_PAPER, MSG_TYPE_PAPER_NOTE_3},
493 {MSG_TYPE_PAPER, MSG_TYPE_PAPER_LETTER_OLD_1}, 480 {MSG_TYPE_PAPER, MSG_TYPE_PAPER_LETTER_OLD_1},
494 {MSG_TYPE_PAPER, MSG_TYPE_PAPER_LETTER_OLD_2}, 481 {MSG_TYPE_PAPER, MSG_TYPE_PAPER_LETTER_OLD_2},
495 {MSG_TYPE_PAPER, MSG_TYPE_PAPER_LETTER_NEW_1}, 482 {MSG_TYPE_PAPER, MSG_TYPE_PAPER_LETTER_NEW_1},
496 /*subtype 30 */ {MSG_TYPE_PAPER, MSG_TYPE_PAPER_LETTER_NEW_2}, 483 /*subtype 30 */ {MSG_TYPE_PAPER, MSG_TYPE_PAPER_LETTER_NEW_2},
497 {MSG_TYPE_PAPER, MSG_TYPE_PAPER_ENVELOPE_1}, 484 {MSG_TYPE_PAPER, MSG_TYPE_PAPER_ENVELOPE_1},
498 {MSG_TYPE_PAPER, MSG_TYPE_PAPER_ENVELOPE_2}, 485 {MSG_TYPE_PAPER, MSG_TYPE_PAPER_ENVELOPE_2},
499 {MSG_TYPE_PAPER, MSG_TYPE_PAPER_SCROLL_OLD_1}, 486 {MSG_TYPE_PAPER, MSG_TYPE_PAPER_SCROLL_OLD_1},
500 {MSG_TYPE_PAPER, MSG_TYPE_PAPER_SCROLL_OLD_2}, 487 {MSG_TYPE_PAPER, MSG_TYPE_PAPER_SCROLL_OLD_2},
501 {MSG_TYPE_PAPER, MSG_TYPE_PAPER_SCROLL_NEW_1}, 488 {MSG_TYPE_PAPER, MSG_TYPE_PAPER_SCROLL_NEW_1},
502 {MSG_TYPE_PAPER, MSG_TYPE_PAPER_SCROLL_NEW_2}, 489 {MSG_TYPE_PAPER, MSG_TYPE_PAPER_SCROLL_NEW_2},
503 {MSG_TYPE_PAPER, MSG_TYPE_PAPER_SCROLL_MAGIC}, 490 {MSG_TYPE_PAPER, MSG_TYPE_PAPER_SCROLL_MAGIC},
504 491
505 /* road signs messages subtypes */ 492 /* road signs messages subtypes */
506 {MSG_TYPE_SIGN, MSG_TYPE_SIGN_BASIC}, 493 {MSG_TYPE_SIGN, MSG_TYPE_SIGN_BASIC},
507 {MSG_TYPE_SIGN, MSG_TYPE_SIGN_DIR_LEFT}, 494 {MSG_TYPE_SIGN, MSG_TYPE_SIGN_DIR_LEFT},
508 /*subtype 40 */ {MSG_TYPE_SIGN, MSG_TYPE_SIGN_DIR_RIGHT}, 495 /*subtype 40 */ {MSG_TYPE_SIGN, MSG_TYPE_SIGN_DIR_RIGHT},
509 {MSG_TYPE_SIGN, MSG_TYPE_SIGN_DIR_BOTH}, 496 {MSG_TYPE_SIGN, MSG_TYPE_SIGN_DIR_BOTH},
510 497
511 /* stones and monument messages */ 498 /* stones and monument messages */
512 {MSG_TYPE_MONUMENT, MSG_TYPE_MONUMENT_STONE_1}, 499 {MSG_TYPE_MONUMENT, MSG_TYPE_MONUMENT_STONE_1},
513 {MSG_TYPE_MONUMENT, MSG_TYPE_MONUMENT_STONE_2}, 500 {MSG_TYPE_MONUMENT, MSG_TYPE_MONUMENT_STONE_2},
514 {MSG_TYPE_MONUMENT, MSG_TYPE_MONUMENT_STONE_3}, 501 {MSG_TYPE_MONUMENT, MSG_TYPE_MONUMENT_STONE_3},
515 {MSG_TYPE_MONUMENT, MSG_TYPE_MONUMENT_STATUE_1}, 502 {MSG_TYPE_MONUMENT, MSG_TYPE_MONUMENT_STATUE_1},
516 {MSG_TYPE_MONUMENT, MSG_TYPE_MONUMENT_STATUE_2}, 503 {MSG_TYPE_MONUMENT, MSG_TYPE_MONUMENT_STATUE_2},
517 {MSG_TYPE_MONUMENT, MSG_TYPE_MONUMENT_STATUE_3}, 504 {MSG_TYPE_MONUMENT, MSG_TYPE_MONUMENT_STATUE_3},
518 {MSG_TYPE_MONUMENT, MSG_TYPE_MONUMENT_GRAVESTONE_1}, 505 {MSG_TYPE_MONUMENT, MSG_TYPE_MONUMENT_GRAVESTONE_1},
519 {MSG_TYPE_MONUMENT, MSG_TYPE_MONUMENT_GRAVESTONE_2}, 506 {MSG_TYPE_MONUMENT, MSG_TYPE_MONUMENT_GRAVESTONE_2},
520 /*subtype 50 */ {MSG_TYPE_MONUMENT, MSG_TYPE_MONUMENT_GRAVESTONE_3}, 507 /*subtype 50 */ {MSG_TYPE_MONUMENT, MSG_TYPE_MONUMENT_GRAVESTONE_3},
521 {MSG_TYPE_MONUMENT, MSG_TYPE_MONUMENT_WALL_1}, 508 {MSG_TYPE_MONUMENT, MSG_TYPE_MONUMENT_WALL_1},
522 {MSG_TYPE_MONUMENT, MSG_TYPE_MONUMENT_WALL_2}, 509 {MSG_TYPE_MONUMENT, MSG_TYPE_MONUMENT_WALL_2},
523 {MSG_TYPE_MONUMENT, MSG_TYPE_MONUMENT_WALL_3} 510 {MSG_TYPE_MONUMENT, MSG_TYPE_MONUMENT_WALL_3}
524}; 511};
525int last_readable_subtype = sizeof(readable_message_types)/sizeof(readable_message_type); 512int last_readable_subtype = sizeof (readable_message_types) / sizeof (readable_message_type);
526 513
527static int max_titles[6] = 514static int max_titles[6] = {
528{
529 ((sizeof (light_book_name) / sizeof (char *)) + (sizeof (heavy_book_name) / sizeof (char *))) * (sizeof (book_author) / sizeof (char *)), 515 ((sizeof (light_book_name) / sizeof (char *)) + (sizeof (heavy_book_name) / sizeof (char *))) * (sizeof (book_author) / sizeof (char *)),
530 (sizeof (mon_book_name) / sizeof (char *)) * (sizeof (mon_author) / sizeof (char *)), 516 (sizeof (mon_book_name) / sizeof (char *)) * (sizeof (mon_author) / sizeof (char *)),
531 (sizeof (art_book_name) / sizeof (char *)) * (sizeof (art_author) / sizeof (char *)), 517 (sizeof (art_book_name) / sizeof (char *)) * (sizeof (art_author) / sizeof (char *)),
532 (sizeof (path_book_name) / sizeof (char *)) * (sizeof (path_author) / sizeof (char *)), 518 (sizeof (path_book_name) / sizeof (char *)) * (sizeof (path_author) / sizeof (char *)),
533 (sizeof (formula_book_name) / sizeof (char *)) * (sizeof (formula_author) / sizeof (char *)), 519 (sizeof (formula_book_name) / sizeof (char *)) * (sizeof (formula_author) / sizeof (char *)),
534 (sizeof (gods_book_name) / sizeof (char *)) * (sizeof (gods_author) / sizeof (char *)) 520 (sizeof (gods_book_name) / sizeof (char *)) * (sizeof (gods_author) / sizeof (char *))
535}; 521};
536 522
537/****************************************************************************** 523/******************************************************************************
538 * 524 *
539 * Start of misc. readable functions used by others functions in this file 525 * Start of misc. readable functions used by others functions in this file
541 *****************************************************************************/ 527 *****************************************************************************/
542 528
543static titlelist * 529static titlelist *
544get_empty_booklist (void) 530get_empty_booklist (void)
545{ 531{
546 titlelist *bl = new titlelist; 532 titlelist *bl = new titlelist;
547 533
548 bl->number = 0; 534 bl->number = 0;
549 bl->first_book = NULL; 535 bl->first_book = NULL;
550 bl->next = NULL; 536 bl->next = NULL;
551 return bl; 537 return bl;
552} 538}
553 539
554static title * 540static title *
555get_empty_book (void) 541get_empty_book (void)
556{ 542{
557 title *t = new title; 543 title *t = new title;
558 544
559 t->name = NULL; 545 t->name = NULL;
560 t->archname = NULL; 546 t->archname = NULL;
561 t->authour = NULL; 547 t->authour = NULL;
562 t->level = 0; 548 t->level = 0;
563 t->size = 0; 549 t->size = 0;
564 t->msg_index = 0; 550 t->msg_index = 0;
565 t->next = NULL; 551 t->next = NULL;
566 return t; 552 return t;
567} 553}
568 554
569/* get_titlelist() - returns pointer to the title list referanced by i */ 555/* get_titlelist() - returns pointer to the title list referanced by i */
570 556
571static titlelist * 557static titlelist *
572get_titlelist (int i) 558get_titlelist (int i)
573{ 559{
574 titlelist *tl = booklist; 560 titlelist *tl = booklist;
575 int number = i; 561 int number = i;
576 562
577 if (number < 0) 563 if (number < 0)
578 return tl;
579
580 while (tl && number)
581 {
582 if (!tl->next)
583 tl->next = get_empty_booklist ();
584 tl = tl->next;
585 number--;
586 }
587
588 return tl; 564 return tl;
565
566 while (tl && number)
567 {
568 if (!tl->next)
569 tl->next = get_empty_booklist ();
570 tl = tl->next;
571 number--;
572 }
573
574 return tl;
589} 575}
590 576
591/* HANDMADE STRING FUNCTIONS.., perhaps these belong in another file 577/* HANDMADE STRING FUNCTIONS.., perhaps these belong in another file
592 * (shstr.c ?), but the quantity BOOK_BUF will need to be defined. */ 578 * (shstr.c ?), but the quantity BOOK_BUF will need to be defined. */
593 579
594/* nstrtok() - simple routine to return the number of list 580/* nstrtok() - simple routine to return the number of list
595 * items in buf1 as separated by the value of buf2 581 * items in buf1 as separated by the value of buf2
596 */ 582 */
597 583
598int 584int
599nstrtok (const char *buf1, const char *buf2) 585nstrtok (const char *buf1, const char *buf2)
600{ 586{
601 char *tbuf, sbuf[12], buf[MAX_BUF]; 587 char *tbuf, sbuf[12], buf[MAX_BUF];
602 int number = 0; 588 int number = 0;
603 589
604 if (!buf1 || !buf2) 590 if (!buf1 || !buf2)
605 return 0; 591 return 0;
606 sprintf (buf, "%s", buf1); 592 sprintf (buf, "%s", buf1);
607 sprintf (sbuf, "%s", buf2); 593 sprintf (sbuf, "%s", buf2);
608 tbuf = strtok (buf, sbuf); 594 tbuf = strtok (buf, sbuf);
609 while (tbuf) 595 while (tbuf)
610 { 596 {
611 number++; 597 number++;
612 tbuf = strtok (NULL, sbuf); 598 tbuf = strtok (NULL, sbuf);
613 } 599 }
614 return number; 600 return number;
615} 601}
616 602
617/* strtoktolin() - takes a string in buf1 and separates it into 603/* strtoktolin() - takes a string in buf1 and separates it into
618 * a list of strings delimited by buf2. Then returns a comma 604 * a list of strings delimited by buf2. Then returns a comma
619 * separated string w/ decent punctuation. 605 * separated string w/ decent punctuation.
620 */ 606 */
621 607
622char * 608char *
623strtoktolin (const char *buf1, const char *buf2) 609strtoktolin (const char *buf1, const char *buf2)
624{ 610{
625 int maxi, i = nstrtok (buf1, buf2); 611 int maxi, i = nstrtok (buf1, buf2);
626 char *tbuf, buf[MAX_BUF], sbuf[12]; 612 char *tbuf, buf[MAX_BUF], sbuf[12];
627 static char rbuf[BOOK_BUF]; 613 static char rbuf[BOOK_BUF];
628 614
629 maxi = i; 615 maxi = i;
630 strcpy(buf, buf1); 616 strcpy (buf, buf1);
631 strcpy(sbuf, buf2); 617 strcpy (sbuf, buf2);
632 strcpy(rbuf, " "); 618 strcpy (rbuf, " ");
633 tbuf = strtok (buf, sbuf); 619 tbuf = strtok (buf, sbuf);
634 while (tbuf && i > 0) 620 while (tbuf && i > 0)
635 { 621 {
636 strcat (rbuf, tbuf); 622 strcat (rbuf, tbuf);
637 i--; 623 i--;
638 if (i == 1 && maxi > 1) 624 if (i == 1 && maxi > 1)
639 strcat (rbuf, " and "); 625 strcat (rbuf, " and ");
640 else if (i > 0 && maxi > 1) 626 else if (i > 0 && maxi > 1)
641 strcat (rbuf, ", "); 627 strcat (rbuf, ", ");
642 else 628 else
643 strcat (rbuf, "."); 629 strcat (rbuf, ".");
644 tbuf = strtok (NULL, sbuf); 630 tbuf = strtok (NULL, sbuf);
645 } 631 }
646 return (char *) rbuf; 632 return (char *) rbuf;
647} 633}
648 634
649int 635int
650book_overflow (const char *buf1, const char *buf2, int booksize) 636book_overflow (const char *buf1, const char *buf2, int booksize)
651{ 637{
652 638
653 if (buf_overflow (buf1, buf2, BOOK_BUF - 2) /* 2 less so always room for trailing \n */ 639 if (buf_overflow (buf1, buf2, BOOK_BUF - 2) /* 2 less so always room for trailing \n */
654 || buf_overflow (buf1, buf2, booksize)) 640 || buf_overflow (buf1, buf2, booksize))
655 return 1;
656 return 0; 641 return 1;
642 return 0;
657 643
658 644
659} 645}
660 646
661/***************************************************************************** 647/*****************************************************************************
666 652
667/* init_msgfile() - if not called before, initialize the info list 653/* init_msgfile() - if not called before, initialize the info list
668 * reads the messages file into the list pointed to by first_msg 654 * reads the messages file into the list pointed to by first_msg
669*/ 655*/
670 656
671static void 657static void
672init_msgfile (void) 658init_msgfile (void)
673{ 659{
674 FILE *fp; 660 FILE *fp;
675 char buf[MAX_BUF], msgbuf[HUGE_BUF], fname[MAX_BUF], *cp; 661 char buf[MAX_BUF], msgbuf[HUGE_BUF], fname[MAX_BUF], *cp;
676 int comp; 662 int comp;
677 static int did_init_msgfile; 663 static int did_init_msgfile;
678 664
679 if (did_init_msgfile) 665 if (did_init_msgfile)
680 return; 666 return;
681 did_init_msgfile = 1; 667 did_init_msgfile = 1;
682 668
683 sprintf (fname, "%s/messages", settings.datadir); 669 sprintf (fname, "%s/messages", settings.datadir);
684 LOG (llevDebug, "Reading messages from %s...", fname); 670 LOG (llevDebug, "Reading messages from %s...", fname);
685 671
686 if ((fp = open_and_uncompress (fname, 0, &comp)) != NULL) 672 if ((fp = open_and_uncompress (fname, 0, &comp)) != NULL)
687 { 673 {
688 linked_char *tmp = NULL; 674 linked_char *tmp = NULL;
675
689 while (fgets (buf, MAX_BUF, fp) != NULL) 676 while (fgets (buf, MAX_BUF, fp) != NULL)
677 {
678 if (*buf == '#')
679 continue;
680 if ((cp = strchr (buf, '\n')) != NULL)
681 *cp = '\0';
682 cp = buf;
683 while (*cp == ' ') /* Skip blanks */
684 cp++;
685 if (!strncmp (cp, "ENDMSG", 6))
690 { 686 {
691 if (*buf == '#') 687 if (strlen (msgbuf) > BOOK_BUF)
692 continue;
693 if ((cp = strchr (buf, '\n')) != NULL)
694 *cp = '\0';
695 cp = buf;
696 while (*cp == ' ') /* Skip blanks */
697 cp++;
698 if (!strncmp (cp, "ENDMSG", 6))
699 { 688 {
700 if (strlen (msgbuf) > BOOK_BUF)
701 {
702 LOG (llevDebug, "Warning: this string exceeded max book buf size:"); 689 LOG (llevDebug, "Warning: this string exceeded max book buf size:");
703 LOG (llevDebug, " %s", msgbuf); 690 LOG (llevDebug, " %s", msgbuf);
704 }
705 tmp->name = msgbuf;
706 tmp->next = first_msg;
707 first_msg = tmp;
708 nrofmsg++;
709 continue;
710 } 691 }
692 tmp->name = msgbuf;
693 tmp->next = first_msg;
694 first_msg = tmp;
695 nrofmsg++;
696 continue;
697 }
711 else if (!strncmp (cp, "MSG", 3)) 698 else if (!strncmp (cp, "MSG", 3))
712 { 699 {
713 tmp = new linked_char; 700 tmp = new linked_char;
701
714 strcpy (msgbuf, " "); /* reset msgbuf for new message */ 702 strcpy (msgbuf, " "); /* reset msgbuf for new message */
715 continue; 703 continue;
716 } 704 }
717 else if (!buf_overflow (msgbuf, cp, HUGE_BUF - 1)) 705 else if (!buf_overflow (msgbuf, cp, HUGE_BUF - 1))
718 {
719 strcat (msgbuf, cp);
720 strcat (msgbuf, "\n");
721 }
722 } 706 {
707 strcat (msgbuf, cp);
708 strcat (msgbuf, "\n");
709 }
710 }
723 close_and_delete (fp, comp); 711 close_and_delete (fp, comp);
724 } 712 }
725 713
726#ifdef BOOK_MSG_DEBUG 714#ifdef BOOK_MSG_DEBUG
727 LOG (llevDebug, "\ninit_info_listfile() got %d messages.\n", nrofmsg); 715 LOG (llevDebug, "\ninit_info_listfile() got %d messages.\n", nrofmsg);
728#endif 716#endif
729 LOG (llevDebug, "done.\n"); 717 LOG (llevDebug, "done.\n");
730} 718}
731 719
732 720
733/* init_book_archive() - if not called before, initialize the info list 721/* init_book_archive() - if not called before, initialize the info list
734 * This reads in the bookarch file into memory. bookarch is the file 722 * This reads in the bookarch file into memory. bookarch is the file
735 * created and updated across multiple runs of the program. 723 * created and updated across multiple runs of the program.
736 */ 724 */
737 725
738static void 726static void
739init_book_archive (void) 727init_book_archive (void)
740{ 728{
741 FILE *fp; 729 FILE *fp;
742 int comp, nroftitle = 0; 730 int comp, nroftitle = 0;
743 char buf[MAX_BUF], fname[MAX_BUF], *cp; 731 char buf[MAX_BUF], fname[MAX_BUF], *cp;
744 title *book = NULL; 732 title *book = NULL;
745 titlelist *bl = get_empty_booklist (); 733 titlelist *bl = get_empty_booklist ();
746 static int did_init_barch; 734 static int did_init_barch;
747 735
748 if (did_init_barch) 736 if (did_init_barch)
749 return; 737 return;
750 did_init_barch = 1; 738 did_init_barch = 1;
751 739
752 if (!booklist) 740 if (!booklist)
753 booklist = bl; 741 booklist = bl;
754 742
755 sprintf (fname, "%s/bookarch", settings.localdir); 743 sprintf (fname, "%s/bookarch", settings.localdir);
756 LOG (llevDebug, " Reading bookarch from %s...\n", fname); 744 LOG (llevDebug, " Reading bookarch from %s...\n", fname);
757 745
758 if ((fp = open_and_uncompress (fname, 0, &comp)) != NULL) 746 if ((fp = open_and_uncompress (fname, 0, &comp)) != NULL)
759 { 747 {
760 int value, type = 0; 748 int value, type = 0;
761 size_t i; 749 size_t i;
762 750
763 while (fgets (buf, MAX_BUF, fp) != NULL) 751 while (fgets (buf, MAX_BUF, fp) != NULL)
752 {
753 if (*buf == '#')
754 continue;
755 if ((cp = strchr (buf, '\n')) != NULL)
756 *cp = '\0';
757 cp = buf;
758 while (*cp == ' ') /* Skip blanks */
759 cp++;
760 if (!strncmp (cp, "title", 4))
764 { 761 {
765 if (*buf == '#')
766 continue;
767 if ((cp = strchr (buf, '\n')) != NULL)
768 *cp = '\0';
769 cp = buf;
770 while (*cp == ' ') /* Skip blanks */
771 cp++;
772 if (!strncmp (cp, "title", 4))
773 {
774 book = get_empty_book (); /* init new book entry */ 762 book = get_empty_book (); /* init new book entry */
775 book->name = strchr (cp, ' ') + 1; 763 book->name = strchr (cp, ' ') + 1;
776 type = -1; 764 type = -1;
777 nroftitle++; 765 nroftitle++;
778 continue; 766 continue;
779 } 767 }
780 if (!strncmp (cp, "authour", 4)) 768 if (!strncmp (cp, "authour", 4))
781 {
782 book->authour = strchr (cp, ' ') + 1;
783 }
784 if (!strncmp (cp, "arch", 4))
785 {
786 book->archname = strchr (cp, ' ') + 1;
787 }
788 else if (sscanf (cp, "level %d", &value))
789 {
790 book->level = (uint16) value;
791 }
792 else if (sscanf (cp, "type %d", &value))
793 {
794 type = (uint16) value;
795 }
796 else if (sscanf (cp, "size %d", &value))
797 {
798 book->size = (uint16) value;
799 }
800 else if (sscanf (cp, "index %d", &value))
801 {
802 book->msg_index = (uint16) value;
803 }
804 else if (!strncmp (cp, "end", 3))
805 { /* link it */
806 bl = get_titlelist (type);
807 book->next = bl->first_book;
808 bl->first_book = book;
809 bl->number++;
810 }
811 }
812 LOG (llevDebug, " book archives(used/avail): ");
813 for (bl = booklist, i = 0; bl != NULL && i < sizeof(max_titles)/sizeof(*max_titles); bl = bl->next, i++)
814 { 769 {
770 book->authour = strchr (cp, ' ') + 1;
771 }
772 if (!strncmp (cp, "arch", 4))
773 {
774 book->archname = strchr (cp, ' ') + 1;
775 }
776 else if (sscanf (cp, "level %d", &value))
777 {
778 book->level = (uint16) value;
779 }
780 else if (sscanf (cp, "type %d", &value))
781 {
782 type = (uint16) value;
783 }
784 else if (sscanf (cp, "size %d", &value))
785 {
786 book->size = (uint16) value;
787 }
788 else if (sscanf (cp, "index %d", &value))
789 {
790 book->msg_index = (uint16) value;
791 }
792 else if (!strncmp (cp, "end", 3))
793 { /* link it */
794 bl = get_titlelist (type);
795 book->next = bl->first_book;
796 bl->first_book = book;
797 bl->number++;
798 }
799 }
800 LOG (llevDebug, " book archives(used/avail): ");
801 for (bl = booklist, i = 0; bl != NULL && i < sizeof (max_titles) / sizeof (*max_titles); bl = bl->next, i++)
802 {
815 LOG (llevDebug, "(%d/%d)", bl->number, max_titles[i]); 803 LOG (llevDebug, "(%d/%d)", bl->number, max_titles[i]);
816 } 804 }
817 LOG (llevDebug, "\n"); 805 LOG (llevDebug, "\n");
818 close_and_delete (fp, comp); 806 close_and_delete (fp, comp);
819 } 807 }
820 808
821#ifdef BOOK_MSG_DEBUG 809#ifdef BOOK_MSG_DEBUG
822 LOG (llevDebug, "\n init_book_archive() got %d titles.\n", nroftitle); 810 LOG (llevDebug, "\n init_book_archive() got %d titles.\n", nroftitle);
823#endif 811#endif
824 LOG (llevDebug, " done.\n"); 812 LOG (llevDebug, " done.\n");
825} 813}
826 814
827/* init_mon_info() - creates the linked list of pointers to 815/* init_mon_info() - creates the linked list of pointers to
828 * monster archetype objects if not called previously 816 * monster archetype objects if not called previously
829 */ 817 */
830 818
831static void 819static void
832init_mon_info (void) 820init_mon_info (void)
833{ 821{
834 archetype *at; 822 archetype *at;
835 static int did_init_mon_info = 0; 823 static int did_init_mon_info = 0;
836 824
837 if (did_init_mon_info) 825 if (did_init_mon_info)
838 return; 826 return;
839 did_init_mon_info = 1; 827 did_init_mon_info = 1;
840 828
841 829
842 for (at = first_archetype; at != NULL; at = at->next) 830 for (at = first_archetype; at != NULL; at = at->next)
831 {
832 if (QUERY_FLAG (&at->clone, FLAG_MONSTER) && (!QUERY_FLAG (&at->clone, FLAG_CHANGING) || QUERY_FLAG (&at->clone, FLAG_UNAGGRESSIVE)))
843 { 833 {
844 if (QUERY_FLAG (&at->clone, FLAG_MONSTER) &&
845 (!QUERY_FLAG (&at->clone, FLAG_CHANGING)
846 || QUERY_FLAG (&at->clone, FLAG_UNAGGRESSIVE))
847 )
848 {
849 objectlink *mon = (objectlink *) malloc (sizeof (objectlink)); 834 objectlink *mon = (objectlink *) malloc (sizeof (objectlink));
835
850 mon->ob = &at->clone; 836 mon->ob = &at->clone;
851 mon->id = nrofmon; 837 mon->id = nrofmon;
852 mon->next = first_mon_info; 838 mon->next = first_mon_info;
853 first_mon_info = mon; 839 first_mon_info = mon;
854 nrofmon++; 840 nrofmon++;
855 }
856 } 841 }
842 }
857 LOG (llevDebug, "init_mon_info() got %d monsters\n", nrofmon); 843 LOG (llevDebug, "init_mon_info() got %d monsters\n", nrofmon);
858} 844}
859 845
860 846
861/* init_readable() - initialize linked lists utilized by 847/* init_readable() - initialize linked lists utilized by
862 * message functions in tailor_readable_ob() 848 * message functions in tailor_readable_ob()
863 * 849 *
864 * This is the function called by the main routine to initialize 850 * This is the function called by the main routine to initialize
865 * all the readable information. 851 * all the readable information.
866 */ 852 */
867 853
868void 854void
869init_readable (void) 855init_readable (void)
870{ 856{
871 static int did_this; 857 static int did_this;
872 858
873 if (did_this) return; 859 if (did_this)
860 return;
874 did_this = 1; 861 did_this = 1;
875 862
876 LOG (llevDebug, "Initializing reading data..."); 863 LOG (llevDebug, "Initializing reading data...");
877 init_msgfile (); 864 init_msgfile ();
878 init_book_archive (); 865 init_book_archive ();
879 init_mon_info (); 866 init_mon_info ();
880 LOG (llevDebug, " Done\n"); 867 LOG (llevDebug, " Done\n");
881 868
882} 869}
883 870
884/***************************************************************************** 871/*****************************************************************************
885 * 872 *
891 878
892/* find_title() - Search the titlelist (based on msgtype) to see if 879/* find_title() - Search the titlelist (based on msgtype) to see if
893 * book matches something already there. IF so, return that title. 880 * book matches something already there. IF so, return that title.
894 */ 881 */
895 882
896static title * 883static title *
897find_title (const object *book, int msgtype) 884find_title (const object *book, int msgtype)
898{ 885{
899 title *t = NULL; 886 title *t = NULL;
900 titlelist *tl = get_titlelist (msgtype); 887 titlelist *tl = get_titlelist (msgtype);
901 int length = strlen (book->msg); 888 int length = strlen (book->msg);
902 int index = strtoint (book->msg); 889 int index = strtoint (book->msg);
903 890
904 if (msgtype < 0) 891 if (msgtype < 0)
905 return (title *) NULL; 892 return (title *) NULL;
906 893
907 if (tl) 894 if (tl)
908 t = tl->first_book; 895 t = tl->first_book;
909 while (t) 896 while (t)
910 if (t->size == length && t->msg_index == index) 897 if (t->size == length && t->msg_index == index)
911 break; 898 break;
912 else 899 else
913 t = t->next; 900 t = t->next;
914 901
915#ifdef ARCHIVE_DEBUG 902#ifdef ARCHIVE_DEBUG
916 if (t) 903 if (t)
917 LOG (llevDebug, "Found title match (list %d): %s %s (%d)\n", 904 LOG (llevDebug, "Found title match (list %d): %s %s (%d)\n", msgtype, t->name, t->authour, t->msg_index);
918 msgtype, t->name, t->authour, t->msg_index);
919#endif 905#endif
920 906
921 return t; 907 return t;
922} 908}
923 909
924/* new_text_name() - Only for objects of type BOOK. SPELLBOOK stuff is 910/* new_text_name() - Only for objects of type BOOK. SPELLBOOK stuff is
925 * handled directly in change_book_name(). Names are based on text 911 * handled directly in change_book_name(). Names are based on text
926 * msgtype 912 * msgtype
927 * this sets book book->name based on msgtype given. What name 913 * this sets book book->name based on msgtype given. What name
928 * is given is based on various criteria 914 * is given is based on various criteria
929 */ 915 */
930 916
931static void 917static void
932new_text_name (object *book, int msgtype) 918new_text_name (object *book, int msgtype)
933{ 919{
934 int nbr; 920 int nbr;
935 char name[MAX_BUF]; 921 char name[MAX_BUF];
936 922
937 if (book->type != BOOK) 923 if (book->type != BOOK)
938 return; 924 return;
939 925
940 switch (msgtype) 926 switch (msgtype)
941 { 927 {
942 case 1: /*monster */ 928 case 1: /*monster */
943 nbr = sizeof (mon_book_name) / sizeof (char *); 929 nbr = sizeof (mon_book_name) / sizeof (char *);
944 strcpy (name, mon_book_name[RANDOM () % nbr]); 930 strcpy (name, mon_book_name[RANDOM () % nbr]);
945 break; 931 break;
946 case 2: /*artifact */ 932 case 2: /*artifact */
947 nbr = sizeof (art_book_name) / sizeof (char *); 933 nbr = sizeof (art_book_name) / sizeof (char *);
948 strcpy (name, art_book_name[RANDOM () % nbr]); 934 strcpy (name, art_book_name[RANDOM () % nbr]);
949 break; 935 break;
950 case 3: /*spellpath */ 936 case 3: /*spellpath */
951 nbr = sizeof (path_book_name) / sizeof (char *); 937 nbr = sizeof (path_book_name) / sizeof (char *);
952 strcpy (name, path_book_name[RANDOM () % nbr]); 938 strcpy (name, path_book_name[RANDOM () % nbr]);
953 break; 939 break;
954 case 4: /*alchemy */ 940 case 4: /*alchemy */
955 nbr = sizeof (formula_book_name) / sizeof (char *); 941 nbr = sizeof (formula_book_name) / sizeof (char *);
956 strcpy (name, formula_book_name[RANDOM () % nbr]); 942 strcpy (name, formula_book_name[RANDOM () % nbr]);
957 break; 943 break;
958 case 5: /*gods */ 944 case 5: /*gods */
959 nbr = sizeof (gods_book_name) / sizeof (char *); 945 nbr = sizeof (gods_book_name) / sizeof (char *);
960 strcpy (name, gods_book_name[RANDOM () % nbr]); 946 strcpy (name, gods_book_name[RANDOM () % nbr]);
961 break; 947 break;
962 case 6: /*msg file */ 948 case 6: /*msg file */
963 default: 949 default:
964 if (book->weight > 2000) 950 if (book->weight > 2000)
965 { /* based on weight */ 951 { /* based on weight */
966 nbr = sizeof (heavy_book_name) / sizeof (char *); 952 nbr = sizeof (heavy_book_name) / sizeof (char *);
967 strcpy (name, heavy_book_name[RANDOM () % nbr]); 953 strcpy (name, heavy_book_name[RANDOM () % nbr]);
968 } 954 }
969 else if (book->weight < 2001) 955 else if (book->weight < 2001)
970 { 956 {
971 nbr = sizeof (light_book_name) / sizeof (char *); 957 nbr = sizeof (light_book_name) / sizeof (char *);
972 strcpy (name, light_book_name[RANDOM () % nbr]); 958 strcpy (name, light_book_name[RANDOM () % nbr]);
973 } 959 }
974 break; 960 break;
975 } 961 }
976 962
977 book->name = name; 963 book->name = name;
978} 964}
979 965
980/* add_book_author() 966/* add_book_author()
981 * A lot like new_text_name above, but instead chooses an author 967 * A lot like new_text_name above, but instead chooses an author
982 * and sets op->title to that value 968 * and sets op->title to that value
983 */ 969 */
984 970
985static void 971static void
986add_author (object *op, int msgtype) 972add_author (object *op, int msgtype)
987{ 973{
988 char title[MAX_BUF], name[MAX_BUF]; 974 char title[MAX_BUF], name[MAX_BUF];
989 int nbr = sizeof (book_author) / sizeof (char *); 975 int nbr = sizeof (book_author) / sizeof (char *);
990 976
991 if (msgtype < 0 || strlen (op->msg) < 5) 977 if (msgtype < 0 || strlen (op->msg) < 5)
992 return; 978 return;
993 979
994 switch (msgtype) 980 switch (msgtype)
995 { 981 {
996 case 1: /* monster */ 982 case 1: /* monster */
997 nbr = sizeof (mon_author) / sizeof (char *); 983 nbr = sizeof (mon_author) / sizeof (char *);
998 strcpy (name, mon_author[RANDOM () % nbr]); 984 strcpy (name, mon_author[RANDOM () % nbr]);
999 break; 985 break;
1000 case 2: /* artifacts */ 986 case 2: /* artifacts */
1001 nbr = sizeof (art_author) / sizeof (char *); 987 nbr = sizeof (art_author) / sizeof (char *);
1002 strcpy (name, art_author[RANDOM () % nbr]); 988 strcpy (name, art_author[RANDOM () % nbr]);
1003 break; 989 break;
1004 case 3: /* spellpath */ 990 case 3: /* spellpath */
1005 nbr = sizeof (path_author) / sizeof (char *); 991 nbr = sizeof (path_author) / sizeof (char *);
1006 strcpy (name, path_author[RANDOM () % nbr]); 992 strcpy (name, path_author[RANDOM () % nbr]);
1007 break; 993 break;
1008 case 4: /* alchemy */ 994 case 4: /* alchemy */
1009 nbr = sizeof (formula_author) / sizeof (char *); 995 nbr = sizeof (formula_author) / sizeof (char *);
1010 strcpy (name, formula_author[RANDOM () % nbr]); 996 strcpy (name, formula_author[RANDOM () % nbr]);
1011 break; 997 break;
1012 case 5: /* gods */ 998 case 5: /* gods */
1013 nbr = sizeof (gods_author) / sizeof (char *); 999 nbr = sizeof (gods_author) / sizeof (char *);
1014 strcpy (name, gods_author[RANDOM () % nbr]); 1000 strcpy (name, gods_author[RANDOM () % nbr]);
1015 break; 1001 break;
1016 case 6: /* msg file */ 1002 case 6: /* msg file */
1017 default: 1003 default:
1018 strcpy (name, book_author[RANDOM () % nbr]); 1004 strcpy (name, book_author[RANDOM () % nbr]);
1019 } 1005 }
1020 1006
1021 sprintf (title, "of %s", name); 1007 sprintf (title, "of %s", name);
1022 op->title = title; 1008 op->title = title;
1023} 1009}
1024 1010
1025/* unique_book() - check to see if the book title/msg is unique. We 1011/* unique_book() - check to see if the book title/msg is unique. We
1026 * go through the entire list of possibilities each time. If we find 1012 * go through the entire list of possibilities each time. If we find
1027 * a match, then unique_book returns true (because inst unique). 1013 * a match, then unique_book returns true (because inst unique).
1028 */ 1014 */
1029 1015
1030static int 1016static int
1031unique_book (const object *book, int msgtype) 1017unique_book (const object *book, int msgtype)
1032{ 1018{
1033 title *test; 1019 title *test;
1034 1020
1035 if (!booklist) 1021 if (!booklist)
1036 return 1; /* No archival entries! Must be unique! */ 1022 return 1; /* No archival entries! Must be unique! */
1037 1023
1038 /* Go through the booklist. If the author and name match, not unique so 1024 /* Go through the booklist. If the author and name match, not unique so
1039 * return 0. 1025 * return 0.
1040 */ 1026 */
1041 for (test = get_titlelist (msgtype)->first_book; test; test=test->next) { 1027 for (test = get_titlelist (msgtype)->first_book; test; test = test->next)
1028 {
1042 if (!strcmp(test->name, book->name) && !strcmp(book->title, test->authour)) 1029 if (!strcmp (test->name, book->name) && !strcmp (book->title, test->authour))
1043 return 0; 1030 return 0;
1044 } 1031 }
1045 return 1; 1032 return 1;
1046} 1033}
1047 1034
1048/* add_book_to_list() */ 1035/* add_book_to_list() */
1049 1036
1050static void 1037static void
1051add_book_to_list (const object *book, int msgtype) 1038add_book_to_list (const object *book, int msgtype)
1052{ 1039{
1053 titlelist *tl = get_titlelist (msgtype); 1040 titlelist *tl = get_titlelist (msgtype);
1054 title *t; 1041 title *t;
1055 1042
1056 if (!tl) 1043 if (!tl)
1057 { 1044 {
1058 LOG (llevError, "add_book_to_list can't get booklist!\n"); 1045 LOG (llevError, "add_book_to_list can't get booklist!\n");
1059 return; 1046 return;
1060 } 1047 }
1061 1048
1062 t = get_empty_book (); 1049 t = get_empty_book ();
1063 t->name = book->name; 1050 t->name = book->name;
1064 t->authour = book->title; 1051 t->authour = book->title;
1065 t->size = strlen (book->msg); 1052 t->size = strlen (book->msg);
1066 t->msg_index = strtoint (book->msg); 1053 t->msg_index = strtoint (book->msg);
1067 t->archname = book->arch->name; 1054 t->archname = book->arch->name;
1068 t->level = book->level; 1055 t->level = book->level;
1069 1056
1070 t->next = tl->first_book; 1057 t->next = tl->first_book;
1071 tl->first_book = t; 1058 tl->first_book = t;
1072 tl->number++; 1059 tl->number++;
1073 1060
1074 /* We have stuff we need to write now */ 1061 /* We have stuff we need to write now */
1075 need_to_write_bookarchive=1; 1062 need_to_write_bookarchive = 1;
1076 1063
1077#ifdef ARCHIVE_DEBUG 1064#ifdef ARCHIVE_DEBUG
1078 LOG (llevDebug, "Archiving new title: %s %s (%d)\n", book->name, 1065 LOG (llevDebug, "Archiving new title: %s %s (%d)\n", book->name, book->title, msgtype);
1079 book->title, msgtype);
1080#endif 1066#endif
1081 1067
1082} 1068}
1083 1069
1084 1070
1090 * levels and architypes. -b.t. 1076 * levels and architypes. -b.t.
1091 */ 1077 */
1092 1078
1093#define MAX_TITLE_CHECK 20 1079#define MAX_TITLE_CHECK 20
1094 1080
1095void 1081void
1096change_book (object *book, int msgtype) 1082change_book (object *book, int msgtype)
1097{ 1083{
1098 int nbr = sizeof (book_descrpt) / sizeof (char *); 1084 int nbr = sizeof (book_descrpt) / sizeof (char *);
1099 1085
1100 switch (book->type) 1086 switch (book->type)
1101 { 1087 {
1102 case BOOK: 1088 case BOOK:
1103 { 1089 {
1104 titlelist *tl = get_titlelist (msgtype); 1090 titlelist *tl = get_titlelist (msgtype);
1105 title *t = NULL; 1091 title *t = NULL;
1106 int tries = 0; 1092 int tries = 0;
1093
1107 /* look to see if our msg already been archived. If so, alter 1094 /* look to see if our msg already been archived. If so, alter
1108 * the book to match the archival text. If we fail to match, 1095 * the book to match the archival text. If we fail to match,
1109 * then we archive the new title/name/msg combo if there is 1096 * then we archive the new title/name/msg combo if there is
1110 * room on the titlelist. 1097 * room on the titlelist.
1111 */ 1098 */
1112 1099
1113 if ((strlen (book->msg) > 5) && (t = find_title (book, msgtype))) 1100 if ((strlen (book->msg) > 5) && (t = find_title (book, msgtype)))
1114 { 1101 {
1115 object *tmpbook; 1102 object *tmpbook;
1116 1103
1117 /* alter book properties */ 1104 /* alter book properties */
1118 if ((tmpbook = get_archetype (t->archname)) != NULL) 1105 if ((tmpbook = get_archetype (t->archname)) != NULL)
1106 {
1107 tmpbook->msg = book->msg;
1108 copy_object (tmpbook, book);
1109 free_object (tmpbook);
1110 }
1111
1112 book->title = t->authour;
1113 book->name = t->name;
1114 book->level = t->level;
1115 }
1116 /* Don't have any default title, so lets make up a new one */
1117 else
1118 {
1119 int numb, maxnames = max_titles[msgtype];
1120 const char *old_title;
1121 const char *old_name;
1122
1123 old_title = book->title;
1124 old_name = book->name;
1125
1126 /* some pre-generated books have title already set (from
1127 * maps), also don't bother looking for unique title if
1128 * we already used up all the available names! */
1129
1130 if (!tl)
1131 {
1132 LOG (llevError, "change_book_name(): can't find title list\n");
1133 numb = 0;
1134 }
1135 else
1136 numb = tl->number;
1137
1138 if (numb == maxnames)
1139 {
1140#ifdef ARCHIVE_DEBUG
1141 LOG (llevDebug, "titles for list %d full (%d possible).\n", msgtype, maxnames);
1142#endif
1143 break;
1144 }
1145 /* shouldnt change map-maker books */
1146 else if (!book->title)
1147 do
1148 {
1149 /* random book name */
1150 new_text_name (book, msgtype);
1151 add_author (book, msgtype); /* random author */
1152 tries++;
1153 }
1154 while (!unique_book (book, msgtype) && tries < MAX_TITLE_CHECK);
1155
1156 /* Now deal with 2 cases.
1157 * 1)If no space for a new title exists lets just restore
1158 * the old book properties. Remember, if the book had
1159 * matchd an older entry on the titlelist, we shouldnt
1160 * have called this routine in the first place!
1161 * 2) If we got a unique title, we need to add it to
1162 * the list.
1163 */
1164
1165 if (tries == MAX_TITLE_CHECK || numb == maxnames)
1166 { /* got to check maxnames again */
1167#ifdef ARCHIVE_DEBUG
1168 LOG (llevDebug, "Failed to obtain unique title for %s %s (names:%d/%d)\n", book->name, book->title, numb, maxnames);
1169#endif
1170 /* restore old book properties here */
1171 book->title = old_title;
1172
1173 if (RANDOM () % 4)
1119 { 1174 {
1120 tmpbook->msg = book->msg; 1175 /* Lets give the book a description to individualize it some */
1121 copy_object (tmpbook, book); 1176 char new_name[MAX_BUF];
1122 free_object (tmpbook);
1123 }
1124 1177
1125 book->title = t->authour; 1178 snprintf (new_name, MAX_BUF, "%s %s", book_descrpt[RANDOM () % nbr], old_name);
1179
1126 book->name = t->name; 1180 book->name = new_name;
1127 book->level = t->level;
1128 }
1129 /* Don't have any default title, so lets make up a new one */
1130 else
1131 {
1132 int numb, maxnames = max_titles[msgtype];
1133 const char *old_title;
1134 const char *old_name;
1135
1136 old_title = book->title;
1137 old_name = book->name;
1138
1139 /* some pre-generated books have title already set (from
1140 * maps), also don't bother looking for unique title if
1141 * we already used up all the available names! */
1142
1143 if (!tl)
1144 {
1145 LOG (llevError, "change_book_name(): can't find title list\n");
1146 numb = 0;
1147 } 1181 }
1148 else 1182 else
1149 numb = tl->number;
1150
1151 if (numb == maxnames)
1152 { 1183 {
1153#ifdef ARCHIVE_DEBUG 1184 book->name = old_name;
1154 LOG (llevDebug, "titles for list %d full (%d possible).\n",
1155 msgtype, maxnames);
1156#endif
1157 break;
1158 } 1185 }
1159 /* shouldnt change map-maker books */
1160 else if (!book->title)
1161 do
1162 {
1163 /* random book name */
1164 new_text_name (book, msgtype);
1165 add_author (book, msgtype); /* random author */
1166 tries++;
1167 }
1168 while (!unique_book (book, msgtype) && tries < MAX_TITLE_CHECK);
1169
1170 /* Now deal with 2 cases.
1171 * 1)If no space for a new title exists lets just restore
1172 * the old book properties. Remember, if the book had
1173 * matchd an older entry on the titlelist, we shouldnt
1174 * have called this routine in the first place!
1175 * 2) If we got a unique title, we need to add it to
1176 * the list.
1177 */
1178
1179 if (tries == MAX_TITLE_CHECK || numb == maxnames)
1180 { /* got to check maxnames again */
1181#ifdef ARCHIVE_DEBUG
1182 LOG (llevDebug, "Failed to obtain unique title for %s %s (names:%d/%d)\n",
1183 book->name, book->title, numb, maxnames);
1184#endif
1185 /* restore old book properties here */
1186 book->title = old_title;
1187
1188 if (RANDOM () % 4) {
1189 /* Lets give the book a description to individualize it some */
1190 char new_name[MAX_BUF];
1191 snprintf (new_name, MAX_BUF, "%s %s", book_descrpt[RANDOM () % nbr], old_name);
1192
1193 book->name = new_name;
1194 } else {
1195 book->name = old_name;
1196 }
1197 } 1186 }
1198 else if (book->title && strlen (book->msg) > 5) { /* archive if long msg texts */ 1187 else if (book->title && strlen (book->msg) > 5)
1188 { /* archive if long msg texts */
1199 add_book_to_list (book, msgtype); 1189 add_book_to_list (book, msgtype);
1200 } 1190 }
1201 } 1191 }
1202 break; 1192 break;
1203 } 1193 }
1204 1194
1205 default: 1195 default:
1206 LOG (llevError, "change_book_name() called w/ illegal obj type.\n"); 1196 LOG (llevError, "change_book_name() called w/ illegal obj type.\n");
1207 return; 1197 return;
1208 } 1198 }
1209} 1199}
1210 1200
1211/***************************************************************************** 1201/*****************************************************************************
1212 * 1202 *
1213 * This is the start of the area that generates the actual contents 1203 * This is the start of the area that generates the actual contents
1227 */ 1217 */
1228 1218
1229object * 1219object *
1230get_random_mon (int level) 1220get_random_mon (int level)
1231{ 1221{
1232 objectlink *mon = first_mon_info; 1222 objectlink *mon = first_mon_info;
1233 int i = 0, monnr; 1223 int i = 0, monnr;
1234 1224
1235 /* safety check. Problem w/ init_mon_info list? */ 1225 /* safety check. Problem w/ init_mon_info list? */
1236 if (!nrofmon || !mon) 1226 if (!nrofmon || !mon)
1237 return (object *) NULL; 1227 return (object *) NULL;
1238 1228
1239 if (!level) 1229 if (!level)
1240 { 1230 {
1241 /* lets get a random monster from the mon_info linked list */ 1231 /* lets get a random monster from the mon_info linked list */
1242 monnr = RANDOM () % nrofmon; 1232 monnr = RANDOM () % nrofmon;
1243 1233
1244 for (mon = first_mon_info, i = 0; mon; mon = mon->next)
1245 if (i++ == monnr)
1246 break;
1247
1248 if (!mon)
1249 {
1250 LOG (llevError, "get_random_mon: Didn't find a monster when we should have\n");
1251 return NULL;
1252 }
1253 return mon->ob;
1254 }
1255
1256 /* Case where we are searching by level. Redone 971225 to be clearer
1257 * and more random. Before, it looks like it took a random monster from
1258 * the list, and then returned the first monster after that which was
1259 * appropriate level. This wasn't very random because if you had a
1260 * bunch of low level monsters and then a high level one, if the random
1261 * determine took one of the low level ones, it would just forward to the
1262 * high level one and return that. Thus, monsters that immediatly followed
1263 * a bunch of low level monsters would be more heavily returned. It also
1264 * means some of the dragons would be poorly represented, since they
1265 * are a group of high level monsters all around each other.
1266 */
1267
1268 /* First count number of monsters meeting level criteria */
1269 for (mon = first_mon_info, i = 0; mon; mon = mon->next) 1234 for (mon = first_mon_info, i = 0; mon; mon = mon->next)
1270 if (mon->ob->level >= level) 1235 if (i++ == monnr)
1271 i++; 1236 break;
1272 1237
1273 if (i == 0) 1238 if (!mon)
1274 { 1239 {
1275 LOG (llevError, "get_random_mon() couldn't return monster for level %d\n", 1240 LOG (llevError, "get_random_mon: Didn't find a monster when we should have\n");
1276 level);
1277 return NULL; 1241 return NULL;
1278 } 1242 }
1243 return mon->ob;
1244 }
1279 1245
1246 /* Case where we are searching by level. Redone 971225 to be clearer
1247 * and more random. Before, it looks like it took a random monster from
1248 * the list, and then returned the first monster after that which was
1249 * appropriate level. This wasn't very random because if you had a
1250 * bunch of low level monsters and then a high level one, if the random
1251 * determine took one of the low level ones, it would just forward to the
1252 * high level one and return that. Thus, monsters that immediatly followed
1253 * a bunch of low level monsters would be more heavily returned. It also
1254 * means some of the dragons would be poorly represented, since they
1255 * are a group of high level monsters all around each other.
1256 */
1257
1258 /* First count number of monsters meeting level criteria */
1259 for (mon = first_mon_info, i = 0; mon; mon = mon->next)
1260 if (mon->ob->level >= level)
1261 i++;
1262
1263 if (i == 0)
1264 {
1265 LOG (llevError, "get_random_mon() couldn't return monster for level %d\n", level);
1266 return NULL;
1267 }
1268
1280 monnr = RANDOM () % i; 1269 monnr = RANDOM () % i;
1281 for (mon = first_mon_info; mon; mon = mon->next) 1270 for (mon = first_mon_info; mon; mon = mon->next)
1282 if (mon->ob->level >= level && monnr-- == 0) 1271 if (mon->ob->level >= level && monnr-- == 0)
1283 return mon->ob; 1272 return mon->ob;
1284 1273
1285 if (!mon) 1274 if (!mon)
1286 { 1275 {
1287 LOG (llevError, "get_random_mon(): didn't find a monster when we should have\n"); 1276 LOG (llevError, "get_random_mon(): didn't find a monster when we should have\n");
1288 return NULL; 1277 return NULL;
1289 } 1278 }
1290 return NULL; /* Should be unreached, by keeps warnings down */ 1279 return NULL; /* Should be unreached, by keeps warnings down */
1291} 1280}
1292 1281
1293/* 1282/*
1294 * Returns a description of the monster. This really needs to be 1283 * Returns a description of the monster. This really needs to be
1295 * redone, as describe_item really gives a pretty internal description. 1284 * redone, as describe_item really gives a pretty internal description.
1296 */ 1285 */
1297 1286
1298char * 1287char *
1299mon_desc (const object *mon) 1288mon_desc (const object *mon)
1300{ 1289{
1301 static char retbuf[HUGE_BUF]; 1290 static char retbuf[HUGE_BUF];
1302 1291
1303 sprintf (retbuf, " *** %s ***\n", &mon->name); 1292 sprintf (retbuf, " *** %s ***\n", &mon->name);
1304 strcat (retbuf, describe_item(mon, NULL)); 1293 strcat (retbuf, describe_item (mon, NULL));
1305 1294
1306 return retbuf; 1295 return retbuf;
1307} 1296}
1308 1297
1309 1298
1310/* This function returns the next monsters after 'tmp'. If no match is 1299/* This function returns the next monsters after 'tmp'. If no match is
1311 * found, it returns NULL (changed 0.94.3 to do this, since the 1300 * found, it returns NULL (changed 0.94.3 to do this, since the
1313 */ 1302 */
1314 1303
1315object * 1304object *
1316get_next_mon (object *tmp) 1305get_next_mon (object *tmp)
1317{ 1306{
1318 objectlink *mon; 1307 objectlink *mon;
1319 1308
1320 for (mon = first_mon_info; mon; mon = mon->next) 1309 for (mon = first_mon_info; mon; mon = mon->next)
1321 if (mon->ob == tmp) 1310 if (mon->ob == tmp)
1322 break; 1311 break;
1323 1312
1324 /* didn't find a match */ 1313 /* didn't find a match */
1325 if (!mon) 1314 if (!mon)
1326 return NULL; 1315 return NULL;
1327 if (mon->next) 1316 if (mon->next)
1328 return mon->next->ob; 1317 return mon->next->ob;
1329 else 1318 else
1330 return first_mon_info->ob; 1319 return first_mon_info->ob;
1331 1320
1332} 1321}
1333 1322
1334 1323
1335 1324
1336/* mon_info_msg() - generate a message detailing the properties 1325/* mon_info_msg() - generate a message detailing the properties
1337 * of a randomly selected monster. 1326 * of a randomly selected monster.
1338 */ 1327 */
1339 1328
1340char * 1329char *
1341mon_info_msg (int level, int booksize) 1330mon_info_msg (int level, int booksize)
1342{ 1331{
1343 static char retbuf[BOOK_BUF]; 1332 static char retbuf[BOOK_BUF];
1344 char tmpbuf[HUGE_BUF]; 1333 char tmpbuf[HUGE_BUF];
1345 object *tmp; 1334 object *tmp;
1346 1335
1347 /*preamble */ 1336 /*preamble */
1348 strcpy (retbuf, "This beastiary contains:"); 1337 strcpy (retbuf, "This beastiary contains:");
1349 1338
1350 /* lets print info on as many monsters as will fit in our 1339 /* lets print info on as many monsters as will fit in our
1351 * document. 1340 * document.
1352 * 8-96 Had to change this a bit, otherwise there would 1341 * 8-96 Had to change this a bit, otherwise there would
1353 * have been an impossibly large number of combinations 1342 * have been an impossibly large number of combinations
1354 * of text! (and flood out the available number of titles 1343 * of text! (and flood out the available number of titles
1355 * in the archive in a snap!) -b.t. 1344 * in the archive in a snap!) -b.t.
1356 */ 1345 */
1357 tmp = get_random_mon (level * 3); 1346 tmp = get_random_mon (level * 3);
1358 while (tmp) { 1347 while (tmp)
1348 {
1359 /* monster description */ 1349 /* monster description */
1360 sprintf (tmpbuf, "\n---\n%s", mon_desc (tmp)); 1350 sprintf (tmpbuf, "\n---\n%s", mon_desc (tmp));
1361 1351
1362 if (!book_overflow (retbuf, tmpbuf, booksize)) 1352 if (!book_overflow (retbuf, tmpbuf, booksize))
1363 strcat (retbuf, tmpbuf); 1353 strcat (retbuf, tmpbuf);
1364 else 1354 else
1365 break; 1355 break;
1366 1356
1367 /* Note that the value this returns is not based on level */ 1357 /* Note that the value this returns is not based on level */
1368 tmp = get_next_mon (tmp); 1358 tmp = get_next_mon (tmp);
1369 } 1359 }
1370 1360
1371#ifdef BOOK_MSG_DEBUG 1361#ifdef BOOK_MSG_DEBUG
1372 LOG (llevDebug, "\n mon_info_msg() created strng: %d\n", strlen (retbuf)); 1362 LOG (llevDebug, "\n mon_info_msg() created strng: %d\n", strlen (retbuf));
1373 fprintf (logfile, " MADE THIS:\n%s\n", retbuf); 1363 fprintf (logfile, " MADE THIS:\n%s\n", retbuf);
1374#endif 1364#endif
1375 1365
1376 return retbuf; 1366 return retbuf;
1377} 1367}
1378 1368
1379 1369
1380/***************************************************************************** 1370/*****************************************************************************
1381 * Artifact msg generation code. 1371 * Artifact msg generation code.
1383 1373
1384/* artifact_msg() - generate a message detailing the properties 1374/* artifact_msg() - generate a message detailing the properties
1385 * of 1-6 artifacts drawn sequentially from the artifact list. 1375 * of 1-6 artifacts drawn sequentially from the artifact list.
1386 */ 1376 */
1387 1377
1388char * 1378char *
1389artifact_msg (int level, int booksize) 1379artifact_msg (int level, int booksize)
1390{ 1380{
1391 artifactlist *al = NULL; 1381 artifactlist *al = NULL;
1392 artifact *art; 1382 artifact *art;
1393 int chance, i, type, index; 1383 int chance, i, type, index;
1394 int book_entries = level > 5 ? RANDOM () % 3 + RANDOM () % 3 + 2 : RANDOM () % level + 1; 1384 int book_entries = level > 5 ? RANDOM () % 3 + RANDOM () % 3 + 2 : RANDOM () % level + 1;
1395 char *ch, name[MAX_BUF], buf[BOOK_BUF], sbuf[MAX_BUF]; 1385 char *ch, name[MAX_BUF], buf[BOOK_BUF], sbuf[MAX_BUF];
1396 static char retbuf[BOOK_BUF]; 1386 static char retbuf[BOOK_BUF];
1397 object *tmp = NULL; 1387 object *tmp = NULL;
1398 1388
1399 /* values greater than 5 create msg buffers that are too big! */ 1389 /* values greater than 5 create msg buffers that are too big! */
1400 if (book_entries > 5) 1390 if (book_entries > 5)
1401 book_entries = 5; 1391 book_entries = 5;
1402 1392
1403 /* lets determine what kind of artifact type randomly. 1393 /* lets determine what kind of artifact type randomly.
1404 * Right now legal artifacts only come from those listed 1394 * Right now legal artifacts only come from those listed
1405 * in art_name_array. Also, we check to be sure an artifactlist 1395 * in art_name_array. Also, we check to be sure an artifactlist
1406 * for that type exists! 1396 * for that type exists!
1407 */ 1397 */
1408 i=0; 1398 i = 0;
1399 do
1409 do { 1400 {
1410 index = RANDOM () % (sizeof (art_name_array) / sizeof (arttypename)); 1401 index = RANDOM () % (sizeof (art_name_array) / sizeof (arttypename));
1411 type = art_name_array[index].type; 1402 type = art_name_array[index].type;
1412 al = find_artifactlist (type); 1403 al = find_artifactlist (type);
1413 i++; 1404 i++;
1405 }
1414 } while ((al == NULL) && (i<10)); 1406 while ((al == NULL) && (i < 10));
1415 1407
1416 if (i==10) /* Unable to find a message */ 1408 if (i == 10) /* Unable to find a message */
1417 return("None"); 1409 return ("None");
1418 1410
1419 /* There is no reason to start on the artifact list at the begining. Lets 1411 /* There is no reason to start on the artifact list at the begining. Lets
1420 * take our starting position randomly... */ 1412 * take our starting position randomly... */
1421 art = al->items; 1413 art = al->items;
1422 for (i = RANDOM () % level + RANDOM () % 2 + 1; i > 0; i--) 1414 for (i = RANDOM () % level + RANDOM () % 2 + 1; i > 0; i--)
1423 { 1415 {
1424 if (art == NULL) 1416 if (art == NULL)
1425 art = al->items; /* hmm, out of stuff, loop back around */ 1417 art = al->items; /* hmm, out of stuff, loop back around */
1426 art = art->next; 1418 art = art->next;
1427 } 1419 }
1428 1420
1429 /* the base 'generic' name for our artifact */ 1421 /* the base 'generic' name for our artifact */
1430 strcpy(name, art_name_array[index].name); 1422 strcpy (name, art_name_array[index].name);
1431 1423
1432 /* Ok, lets print out the contents */ 1424 /* Ok, lets print out the contents */
1433 sprintf (retbuf, "Herein %s detailed %s...\n", book_entries > 1 ? "are" : "is", 1425 sprintf (retbuf, "Herein %s detailed %s...\n", book_entries > 1 ? "are" : "is", book_entries > 1 ? "some artifacts" : "an artifact");
1434 book_entries > 1 ? "some artifacts" : "an artifact");
1435 1426
1436 /* artifact msg attributes loop. Lets keep adding entries to the 'book' 1427 /* artifact msg attributes loop. Lets keep adding entries to the 'book'
1437 * as long as we have space up to the allowed max # (book_entires) 1428 * as long as we have space up to the allowed max # (book_entires)
1438 */ 1429 */
1439 while (book_entries > 0) 1430 while (book_entries > 0)
1440 { 1431 {
1441 1432
1442 if (art == NULL) 1433 if (art == NULL)
1443 art = al->items; 1434 art = al->items;
1444 1435
1445 /* separator of items */ 1436 /* separator of items */
1446 strcpy (buf, "--- \n"); 1437 strcpy (buf, "--- \n");
1447 1438
1448 /* Name */ 1439 /* Name */
1449 if (art->allowed != NULL && strcmp (art->allowed->name, "All")) 1440 if (art->allowed != NULL && strcmp (art->allowed->name, "All"))
1441 {
1442 linked_char *temp, *next = art->allowed;
1443
1444 do
1450 { 1445 {
1451 linked_char *temp, *next = art->allowed;
1452 do
1453 {
1454 temp = next; 1446 temp = next;
1455 next = next->next; 1447 next = next->next;
1456 } 1448 }
1457 while (next && !RANDOM () % 2); 1449 while (next && !RANDOM () % 2);
1458 sprintf (buf, "%s A %s of %s", buf, &temp->name, &art->item->name); 1450 sprintf (buf, "%s A %s of %s", buf, &temp->name, &art->item->name);
1459 } 1451 }
1460 else /* default name is used */ 1452 else /* default name is used */
1461 sprintf (buf, "%s The %s of %s", buf, name, &art->item->name); 1453 sprintf (buf, "%s The %s of %s", buf, name, &art->item->name);
1462 1454
1463 /* chance of finding */ 1455 /* chance of finding */
1464 chance = (int) (100 * ((float) art->chance / al->total_chance)); 1456 chance = (int) (100 * ((float) art->chance / al->total_chance));
1465 if (chance >= 20) 1457 if (chance >= 20)
1466 sprintf (sbuf, "an uncommon"); 1458 sprintf (sbuf, "an uncommon");
1467 else if (chance >= 10) 1459 else if (chance >= 10)
1468 sprintf (sbuf, "an unusual"); 1460 sprintf (sbuf, "an unusual");
1469 else if (chance >= 5) 1461 else if (chance >= 5)
1470 sprintf (sbuf, "a rare"); 1462 sprintf (sbuf, "a rare");
1471 else 1463 else
1472 sprintf (sbuf, "a very rare"); 1464 sprintf (sbuf, "a very rare");
1473 sprintf (buf, "%s is %s\n", buf, sbuf); 1465 sprintf (buf, "%s is %s\n", buf, sbuf);
1474 1466
1475 /* value of artifact */ 1467 /* value of artifact */
1476 sprintf (buf, "%s item with a value that is %d times normal.\n", 1468 sprintf (buf, "%s item with a value that is %d times normal.\n", buf, art->item->value);
1477 buf, art->item->value);
1478 1469
1479 /* include the message about the artifact, if exists, and book 1470 /* include the message about the artifact, if exists, and book
1480 * level is kinda high */ 1471 * level is kinda high */
1481 if (art->item->msg && (RANDOM () % 4 + 1) < level && 1472 if (art->item->msg && (RANDOM () % 4 + 1) < level && !((strlen (art->item->msg) + strlen (buf)) > BOOK_BUF))
1482 !((strlen (art->item->msg) + strlen (buf)) > BOOK_BUF))
1483 strcat(buf, art->item->msg); 1473 strcat (buf, art->item->msg);
1484 1474
1485 /* properties of the artifact */ 1475 /* properties of the artifact */
1486 tmp = get_object (); 1476 tmp = get_object ();
1487 add_abilities (tmp, art->item); 1477 add_abilities (tmp, art->item);
1488 tmp->type = type; 1478 tmp->type = type;
1489 SET_FLAG (tmp, FLAG_IDENTIFIED); 1479 SET_FLAG (tmp, FLAG_IDENTIFIED);
1490 if ((ch = describe_item (tmp, NULL)) != NULL && strlen (ch) > 1) 1480 if ((ch = describe_item (tmp, NULL)) != NULL && strlen (ch) > 1)
1491 sprintf (buf, "%s Properties of this artifact include: \n %s \n", 1481 sprintf (buf, "%s Properties of this artifact include: \n %s \n", buf, ch);
1492 buf, ch);
1493 free_object(tmp); 1482 free_object (tmp);
1494 /* add the buf if it will fit */ 1483 /* add the buf if it will fit */
1495 if (!book_overflow (retbuf, buf, booksize)) 1484 if (!book_overflow (retbuf, buf, booksize))
1496 strcat (retbuf, buf); 1485 strcat (retbuf, buf);
1497 else 1486 else
1498 break; 1487 break;
1499 1488
1500 art = art->next; 1489 art = art->next;
1501 book_entries--; 1490 book_entries--;
1502 } 1491 }
1503 1492
1504#ifdef BOOK_MSG_DEBUG 1493#ifdef BOOK_MSG_DEBUG
1505 LOG (llevDebug, "artifact_msg() created strng: %d\n", strlen (retbuf)); 1494 LOG (llevDebug, "artifact_msg() created strng: %d\n", strlen (retbuf));
1506 fprintf (logfile, " MADE THIS:\n%s", retbuf); 1495 fprintf (logfile, " MADE THIS:\n%s", retbuf);
1507#endif 1496#endif
1508 return retbuf; 1497 return retbuf;
1509} 1498}
1510 1499
1511/***************************************************************************** 1500/*****************************************************************************
1512 * Spellpath message generation 1501 * Spellpath message generation
1513 *****************************************************************************/ 1502 *****************************************************************************/
1515/* spellpath_msg() - generate a message detailing the member 1504/* spellpath_msg() - generate a message detailing the member
1516 * incantations/prayers (and some of their properties) belonging to 1505 * incantations/prayers (and some of their properties) belonging to
1517 * a given spellpath. 1506 * a given spellpath.
1518 */ 1507 */
1519 1508
1520char * 1509char *
1521spellpath_msg (int level, int booksize) 1510spellpath_msg (int level, int booksize)
1522{ 1511{
1523 static char retbuf[BOOK_BUF]; 1512 static char retbuf[BOOK_BUF];
1524 char tmpbuf[BOOK_BUF]; 1513 char tmpbuf[BOOK_BUF];
1525 int path = RANDOM () % NRSPELLPATHS, prayers = RANDOM () % 2; 1514 int path = RANDOM () % NRSPELLPATHS, prayers = RANDOM () % 2;
1526 int did_first_sp = 0; 1515 int did_first_sp = 0;
1527 uint32 pnum = (path == -1) ? PATH_NULL : spellpathdef[path]; 1516 uint32 pnum = (path == -1) ? PATH_NULL : spellpathdef[path];
1528 archetype *at; 1517 archetype *at;
1529 1518
1530 /* Preamble */ 1519 /* Preamble */
1531 sprintf (retbuf, "Herein are detailed the names of %s\n", 1520 sprintf (retbuf, "Herein are detailed the names of %s\n", prayers ? "prayers" : "incantations");
1532 prayers ? "prayers": "incantations");
1533 1521
1534 if (path == -1) 1522 if (path == -1)
1535 strcat (retbuf, "having no known spell path.\n"); 1523 strcat (retbuf, "having no known spell path.\n");
1536 else 1524 else
1537 sprintf (retbuf, "%sbelonging to the path of %s:\n", retbuf, 1525 sprintf (retbuf, "%sbelonging to the path of %s:\n", retbuf, spellpathnames[path]);
1538 spellpathnames[path]);
1539 1526
1540 for (at=first_archetype; at != NULL; at=at->next) { 1527 for (at = first_archetype; at != NULL; at = at->next)
1528 {
1541 /* Determine if this is an appropriate spell. Must 1529 /* Determine if this is an appropriate spell. Must
1542 * be of matching path, must be of appropriate type (prayer 1530 * be of matching path, must be of appropriate type (prayer
1543 * or not), and must be within the valid level range. 1531 * or not), and must be within the valid level range.
1544 */ 1532 */
1545 if (at->clone.type == SPELL && at->clone.path_attuned & pnum && 1533 if (at->clone.type == SPELL && at->clone.path_attuned & pnum &&
1546 ((at->clone.stats.grace && prayers) || (at->clone.stats.sp && !prayers)) && 1534 ((at->clone.stats.grace && prayers) || (at->clone.stats.sp && !prayers)) && (at->clone.level < (level * 8)))
1547 (at->clone.level < (level * 8))) { 1535 {
1548 strcpy (tmpbuf, at->clone.name); 1536 strcpy (tmpbuf, at->clone.name);
1549 1537
1550 if (book_overflow (retbuf, tmpbuf, booksize)) 1538 if (book_overflow (retbuf, tmpbuf, booksize))
1551 break; 1539 break;
1552 else { 1540 else
1553 if (did_first_sp)
1554 strcat (retbuf, ",\n");
1555 did_first_sp = 1;
1556 strcat (retbuf, tmpbuf);
1557 }
1558 } 1541 {
1542 if (did_first_sp)
1543 strcat (retbuf, ",\n");
1544 did_first_sp = 1;
1545 strcat (retbuf, tmpbuf);
1546 }
1547 }
1559 } 1548 }
1560 /* Geez, no spells were generated. */ 1549 /* Geez, no spells were generated. */
1561 if (!did_first_sp) { 1550 if (!did_first_sp)
1551 {
1562 if (RANDOM () % 4) /* usually, lets make a recursive call... */ 1552 if (RANDOM () % 4) /* usually, lets make a recursive call... */
1563 spellpath_msg (level, booksize); 1553 spellpath_msg (level, booksize);
1564 else /* give up, cause knowing no spells exist for path is info too. */ 1554 else /* give up, cause knowing no spells exist for path is info too. */
1565 strcat (retbuf, "\n - no known spells exist -\n"); 1555 strcat (retbuf, "\n - no known spells exist -\n");
1556 }
1557 else
1566 } 1558 {
1567 else {
1568 strcat (retbuf, "\n"); 1559 strcat (retbuf, "\n");
1569 } 1560 }
1570 return retbuf; 1561 return retbuf;
1571} 1562}
1572 1563
1573 1564
1574 1565
1575/* formula_msg() - generate a message detailing the properties 1566/* formula_msg() - generate a message detailing the properties
1576 * of a randomly selected alchemical formula. 1567 * of a randomly selected alchemical formula.
1577 */ 1568 */
1578 1569
1570void
1579void make_formula_book(object *book, int level) { 1571make_formula_book (object *book, int level)
1572{
1580 char retbuf[BOOK_BUF], title[MAX_BUF]; 1573 char retbuf[BOOK_BUF], title[MAX_BUF];
1581 recipelist *fl; 1574 recipelist *fl;
1582 recipe *formula = NULL; 1575 recipe *formula = NULL;
1583 int chance; 1576 int chance;
1584 1577
1585 /* the higher the book level, the more complex (ie number of 1578 /* the higher the book level, the more complex (ie number of
1586 * ingredients) the formula can be. 1579 * ingredients) the formula can be.
1587 */ 1580 */
1588 fl = get_formulalist (((RANDOM () % level) / 3) + 1); 1581 fl = get_formulalist (((RANDOM () % level) / 3) + 1);
1589 1582
1590 if (!fl) 1583 if (!fl)
1591 fl = get_formulalist (1); /* safety */ 1584 fl = get_formulalist (1); /* safety */
1592 1585
1593 if (fl->total_chance == 0) 1586 if (fl->total_chance == 0)
1594 { 1587 {
1595 book->msg = "<indecipherable text>\n"; 1588 book->msg = "<indecipherable text>\n";
1596 new_text_name(book, 4); 1589 new_text_name (book, 4);
1597 add_author(book,4); 1590 add_author (book, 4);
1598 return; 1591 return;
1599 } 1592 }
1600 1593
1601 /* get a random formula, weighted by its bookchance */ 1594 /* get a random formula, weighted by its bookchance */
1602 chance = RANDOM () % fl->total_chance; 1595 chance = RANDOM () % fl->total_chance;
1603 for (formula = fl->items; formula != NULL; formula = formula->next) { 1596 for (formula = fl->items; formula != NULL; formula = formula->next)
1597 {
1604 chance -= formula->chance; 1598 chance -= formula->chance;
1605 if (chance <= 0) 1599 if (chance <= 0)
1606 break; 1600 break;
1607 } 1601 }
1608 1602
1609 if (!formula || formula->arch_names <= 0) { 1603 if (!formula || formula->arch_names <= 0)
1604 {
1610 book->msg = "<indecipherable text>\n"; 1605 book->msg = "<indecipherable text>\n";
1611 new_text_name(book, 4); 1606 new_text_name (book, 4);
1612 add_author(book,4); 1607 add_author (book, 4);
1613 1608
1614 } else { 1609 }
1610 else
1611 {
1615 /* looks like a formula was found. Base the amount 1612 /* looks like a formula was found. Base the amount
1616 * of information on the booklevel and the spellevel 1613 * of information on the booklevel and the spellevel
1617 * of the formula. */ 1614 * of the formula. */
1618 1615
1619 const char *op_name = formula->arch_name[RANDOM()%formula->arch_names]; 1616 const char *op_name = formula->arch_name[RANDOM () % formula->arch_names];
1620 archetype *at; 1617 archetype *at;
1621 1618
1622 /* preamble */ 1619 /* preamble */
1623 sprintf(retbuf, "Herein is described a project using %s: \n", 1620 sprintf (retbuf, "Herein is described a project using %s: \n", formula->skill ? &formula->skill : "an unknown skill");
1624 formula->skill ? &formula->skill : "an unknown skill");
1625 1621
1626 if ((at = find_archetype (op_name)) != (archetype *) NULL) 1622 if ((at = find_archetype (op_name)) != (archetype *) NULL)
1627 op_name = at->clone.name; 1623 op_name = at->clone.name;
1628 else 1624 else
1629 LOG (llevError, "formula_msg() can't find arch %s for formula.\n", 1625 LOG (llevError, "formula_msg() can't find arch %s for formula.\n", op_name);
1630 op_name);
1631 1626
1632 /* item name */ 1627 /* item name */
1633 if (strcmp (formula->title, "NONE")) { 1628 if (strcmp (formula->title, "NONE"))
1629 {
1634 sprintf (retbuf, "%sThe %s of %s", retbuf, op_name, &formula->title); 1630 sprintf (retbuf, "%sThe %s of %s", retbuf, op_name, &formula->title);
1635 /* This results in things like pile of philo. sulfur. 1631 /* This results in things like pile of philo. sulfur.
1636 * while philo. sulfur may look better, without this, 1632 * while philo. sulfur may look better, without this,
1637 * you get things like 'the wise' because its missing the 1633 * you get things like 'the wise' because its missing the
1638 * water of section. 1634 * water of section.
1639 */ 1635 */
1640 sprintf(title,"%s: %s of %s", 1636 sprintf (title, "%s: %s of %s",
1641 formula_book_name[RANDOM() % (sizeof(formula_book_name) / sizeof(char*))], 1637 formula_book_name[RANDOM () % (sizeof (formula_book_name) / sizeof (char *))], op_name, &formula->title);
1642 op_name, &formula->title);
1643 } 1638 }
1644 else 1639 else
1645 { 1640 {
1646 sprintf (retbuf, "%sThe %s", retbuf, op_name); 1641 sprintf (retbuf, "%sThe %s", retbuf, op_name);
1647 sprintf(title,"%s: %s",
1648 formula_book_name[RANDOM() % (sizeof(formula_book_name) / sizeof(char*))], 1642 sprintf (title, "%s: %s", formula_book_name[RANDOM () % (sizeof (formula_book_name) / sizeof (char *))], op_name);
1649 op_name);
1650 if (at->clone.title) 1643 if (at->clone.title)
1651 { 1644 {
1652 strcat (retbuf, " "); 1645 strcat (retbuf, " ");
1653 strcat (retbuf, at->clone.title); 1646 strcat (retbuf, at->clone.title);
1654 strcat(title, " "); 1647 strcat (title, " ");
1655 strcat(title, at->clone.title); 1648 strcat (title, at->clone.title);
1656 } 1649 }
1657 } 1650 }
1658 /* Lets name the book something meaningful ! */ 1651 /* Lets name the book something meaningful ! */
1659 book->name = title; 1652 book->name = title;
1660 book->title = NULL; 1653 book->title = NULL;
1661 1654
1662 /* ingredients to make it */ 1655 /* ingredients to make it */
1663 if (formula->ingred != NULL) 1656 if (formula->ingred != NULL)
1664 { 1657 {
1665 linked_char *next; 1658 linked_char *next;
1666 archetype *at; 1659 archetype *at;
1667 1660
1668 at = find_archetype(formula->cauldron); 1661 at = find_archetype (formula->cauldron);
1669 1662
1670 sprintf(retbuf + strlen(retbuf), 1663 sprintf (retbuf + strlen (retbuf),
1671 " may be made at %s using the following ingredients:\n", 1664 " may be made at %s using the following ingredients:\n", at ? query_name (&at->clone) : "an unknown place");
1672 at?query_name(&at->clone):"an unknown place");
1673 1665
1674 for (next = formula->ingred; next != NULL; next = next->next) 1666 for (next = formula->ingred; next != NULL; next = next->next)
1675 { 1667 {
1676 strcat (retbuf, next->name); 1668 strcat (retbuf, next->name);
1677 strcat (retbuf, "\n"); 1669 strcat (retbuf, "\n");
1678 } 1670 }
1679 } 1671 }
1680 else 1672 else
1681 LOG (llevError, "formula_msg() no ingredient list for object %s of %s\n", 1673 LOG (llevError, "formula_msg() no ingredient list for object %s of %s\n", op_name, &formula->title);
1682 op_name, &formula->title);
1683 if (retbuf[strlen(retbuf)-1]!= '\n') strcat(retbuf, "\n"); 1674 if (retbuf[strlen (retbuf) - 1] != '\n')
1675 strcat (retbuf, "\n");
1684 1676
1685 book->msg = retbuf; 1677 book->msg = retbuf;
1686 } 1678 }
1687} 1679}
1688 1680
1689 1681
1690/* msgfile_msg() - generate a message drawn randomly from a 1682/* msgfile_msg() - generate a message drawn randomly from a
1691 * file in lib/. Level currently has no effect on the message 1683 * file in lib/. Level currently has no effect on the message
1692 * which is returned. 1684 * which is returned.
1693 */ 1685 */
1694 1686
1695char * 1687char *
1696msgfile_msg (int level, int booksize) 1688msgfile_msg (int level, int booksize)
1697{ 1689{
1698 static char retbuf[BOOK_BUF]; 1690 static char retbuf[BOOK_BUF];
1699 int i, msgnum; 1691 int i, msgnum;
1700 linked_char *msg = NULL; 1692 linked_char *msg = NULL;
1701 1693
1702 /* get a random message for the 'book' from linked list */ 1694 /* get a random message for the 'book' from linked list */
1703 if (nrofmsg > 1) 1695 if (nrofmsg > 1)
1704 { 1696 {
1705 msg = first_msg; 1697 msg = first_msg;
1706 msgnum = RANDOM () % nrofmsg; 1698 msgnum = RANDOM () % nrofmsg;
1707 for (i = 0; msg && i < nrofmsg && i != msgnum; i++) 1699 for (i = 0; msg && i < nrofmsg && i != msgnum; i++)
1708 msg = msg->next; 1700 msg = msg->next;
1709 } 1701 }
1710 1702
1711 if (msg && !book_overflow (retbuf, msg->name, booksize)) 1703 if (msg && !book_overflow (retbuf, msg->name, booksize))
1712 strcpy (retbuf, msg->name); 1704 strcpy (retbuf, msg->name);
1713 else 1705 else
1714 sprintf (retbuf, "\n <undecipherable text>"); 1706 sprintf (retbuf, "\n <undecipherable text>");
1715 1707
1716#ifdef BOOK_MSG_DEBUG 1708#ifdef BOOK_MSG_DEBUG
1717 LOG (llevDebug, "\n info_list_msg() created strng: %d\n", strlen (retbuf)); 1709 LOG (llevDebug, "\n info_list_msg() created strng: %d\n", strlen (retbuf));
1718 LOG (llevDebug, " MADE THIS:\n%s\n", retbuf); 1710 LOG (llevDebug, " MADE THIS:\n%s\n", retbuf);
1719#endif 1711#endif
1720 1712
1721 return retbuf; 1713 return retbuf;
1722} 1714}
1723 1715
1724 1716
1725/* god_info_msg() - generate a message detailing the properties 1717/* god_info_msg() - generate a message detailing the properties
1726 * of a random god. Used by the book hack. b.t. 1718 * of a random god. Used by the book hack. b.t.
1727 */ 1719 */
1728 1720
1729const char * 1721const char *
1730god_info_msg (int level, int booksize) 1722god_info_msg (int level, int booksize)
1731{ 1723{
1732 static char retbuf[BOOK_BUF]; 1724 static char retbuf[BOOK_BUF];
1733 const char *name = NULL; 1725 const char *name = NULL;
1734 char buf[BOOK_BUF]; 1726 char buf[BOOK_BUF];
1735 int i; 1727 int i;
1736 size_t introlen; 1728 size_t introlen;
1737 object *god = pntr_to_god_obj (get_rand_god ()); 1729 object *god = pntr_to_god_obj (get_rand_god ());
1738 1730
1739 if (!god) 1731 if (!god)
1740 return (char *) NULL; /* oops, problems... */ 1732 return (char *) NULL; /* oops, problems... */
1741 name = god->name; 1733 name = god->name;
1742 1734
1743 /* preamble.. */ 1735 /* preamble.. */
1744 sprintf (retbuf, "This document contains knowledge concerning\n"); 1736 sprintf (retbuf, "This document contains knowledge concerning\n");
1745 sprintf (retbuf, "%sthe diety %s", retbuf, name); 1737 sprintf (retbuf, "%sthe diety %s", retbuf, name);
1746 1738
1747 /* Always have as default information the god's descriptive terms. */ 1739 /* Always have as default information the god's descriptive terms. */
1748 if (nstrtok (god->msg, ",") > 0) 1740 if (nstrtok (god->msg, ",") > 0)
1749 { 1741 {
1750 strcat (retbuf, ", known as"); 1742 strcat (retbuf, ", known as");
1751 strcat (retbuf, strtoktolin (god->msg, ",")); 1743 strcat (retbuf, strtoktolin (god->msg, ","));
1752 } 1744 }
1753 else 1745 else
1754 strcat (retbuf, "..."); 1746 strcat (retbuf, "...");
1755 1747
1756 strcat (retbuf, "\n ---\n"); 1748 strcat (retbuf, "\n ---\n");
1757 introlen = strlen (retbuf); /* so we will know if no new info is added later */ 1749 introlen = strlen (retbuf); /* so we will know if no new info is added later */
1758 1750
1759 /* Information about the god is random, and based on the level of the 1751 /* Information about the god is random, and based on the level of the
1760 * 'book'. Probably there is a more intellegent way to implement 1752 * 'book'. Probably there is a more intellegent way to implement
1761 * this ... 1753 * this ...
1762 */ 1754 */
1763 1755
1764 while (level > 0) 1756 while (level > 0)
1765 { 1757 {
1766 sprintf (buf, " "); 1758 sprintf (buf, " ");
1767 if (level == 2 && RANDOM () % 2) 1759 if (level == 2 && RANDOM () % 2)
1768 { /* enemy god */ 1760 { /* enemy god */
1769 const char *enemy = god->title; 1761 const char *enemy = god->title;
1762
1770 if (enemy) 1763 if (enemy)
1771 sprintf (buf, "The gods %s and %s are enemies.\n ---\n", 1764 sprintf (buf, "The gods %s and %s are enemies.\n ---\n", name, enemy);
1772 name, enemy);
1773 } 1765 }
1774 if (level == 3 && RANDOM () % 2) 1766 if (level == 3 && RANDOM () % 2)
1775 { /* enemy race, what the god's holy word effects */ 1767 { /* enemy race, what the god's holy word effects */
1776 const char *enemy = god->slaying; 1768 const char *enemy = god->slaying;
1769
1777 if (enemy && !(god->path_denied & PATH_TURNING)) 1770 if (enemy && !(god->path_denied & PATH_TURNING))
1778 if ((i = nstrtok (enemy, ",")) > 0) 1771 if ((i = nstrtok (enemy, ",")) > 0)
1779 { 1772 {
1780 char tmpbuf[MAX_BUF]; 1773 char tmpbuf[MAX_BUF];
1774
1781 sprintf (buf, "The holy words of %s have the power to\n", name); 1775 sprintf (buf, "The holy words of %s have the power to\n", name);
1782 strcat (buf, "slay creatures belonging to the "); 1776 strcat (buf, "slay creatures belonging to the ");
1783 if (i > 1) 1777 if (i > 1)
1784 sprintf (tmpbuf, "following \n races:%s", 1778 sprintf (tmpbuf, "following \n races:%s", strtoktolin (enemy, ","));
1785 strtoktolin (enemy, ","));
1786 else 1779 else
1787 sprintf (tmpbuf, "race of%s", strtoktolin (enemy, ",")); 1780 sprintf (tmpbuf, "race of%s", strtoktolin (enemy, ","));
1788 sprintf (buf, "%s%s\n ---\n", buf, tmpbuf); 1781 sprintf (buf, "%s%s\n ---\n", buf, tmpbuf);
1789 }
1790 } 1782 }
1783 }
1791 if (level == 4 && RANDOM () % 2) 1784 if (level == 4 && RANDOM () % 2)
1792 { /* Priest of god gets these protect,vulnerable... */ 1785 { /* Priest of god gets these protect,vulnerable... */
1793 char tmpbuf[MAX_BUF],*cp; 1786 char tmpbuf[MAX_BUF], *cp;
1794 1787
1795 cp = describe_resistance(god, 1); 1788 cp = describe_resistance (god, 1);
1796 1789
1790 if (*cp)
1797 if (*cp) { /* This god does have protections */ 1791 { /* This god does have protections */
1798 sprintf (tmpbuf, "%s has a potent aura which is extended\n" 1792 sprintf (tmpbuf, "%s has a potent aura which is extended\n", name);
1799 ,name);
1800 strcat (tmpbuf, "faithful priests. The effects of this aura include:\n"); 1793 strcat (tmpbuf, "faithful priests. The effects of this aura include:\n");
1801 strcat(tmpbuf, cp); 1794 strcat (tmpbuf, cp);
1802 strcat (buf, tmpbuf); 1795 strcat (buf, tmpbuf);
1803 strcat (buf, "\n ---\n"); 1796 strcat (buf, "\n ---\n");
1797 }
1798 else
1799 sprintf (buf, " ");
1800 }
1801 if (level == 5 && RANDOM () % 2)
1802 { /* aligned race, summoning */
1803 const char *race = god->race; /* aligned race */
1804
1805 if (race && !(god->path_denied & PATH_SUMMON))
1806 if ((i = nstrtok (race, ",")) > 0)
1807 {
1808 char tmpbuf[MAX_BUF];
1809
1810 sprintf (buf, "Creatures sacred to %s include the \n", name);
1811 if (i > 1)
1812 sprintf (tmpbuf, "following \n races:%s", strtoktolin (race, ","));
1813 else
1814 sprintf (tmpbuf, "race of%s", strtoktolin (race, ","));
1815 sprintf (buf, "%s%s\n ---\n", buf, tmpbuf);
1816 }
1817 }
1818 if (level == 6 && RANDOM () % 2)
1819 { /* blessing,curse properties of the god */
1820 char tmpbuf[MAX_BUF], *cp;
1821
1822 cp = describe_resistance (god, 1);
1823
1824 if (*cp)
1825 { /* This god does have protections */
1826 sprintf (tmpbuf, "\nThe priests of %s are known to be able to \n", name);
1827 strcat (tmpbuf, "bestow a blessing which makes the recipient\n");
1828 strcat (tmpbuf, cp);
1829 strcat (buf, tmpbuf);
1830 strcat (buf, "\n ---\n");
1831 }
1832 else
1833 sprintf (buf, " ");
1834
1835 }
1836 if (level == 8 && RANDOM () % 2)
1837 { /* immunity, holy possession */
1838 int has_effect = 0, tmpvar;
1839 char tmpbuf[MAX_BUF];
1840
1841 sprintf (tmpbuf, "\n");
1842 sprintf (tmpbuf, "The priests of %s are known to make cast a mighty \n", name);
1843
1844 strcat (tmpbuf, "prayer of possession which gives the recipient\n");
1845
1846 for (tmpvar = 0; tmpvar < NROFATTACKS; tmpvar++)
1847 {
1848 if (god->resist[tmpvar] == 100)
1849 {
1850 has_effect = 1;
1851 sprintf (tmpbuf + strlen (tmpbuf), "Immunity to %s", attacktype_desc[tmpvar]);
1804 } 1852 }
1805 else 1853 }
1806 sprintf (buf, " "); 1854 if (has_effect)
1807 } 1855 {
1808 if (level == 5 && RANDOM () % 2)
1809 { /* aligned race, summoning */
1810 const char *race = god->race; /* aligned race */
1811 if (race && !(god->path_denied & PATH_SUMMON))
1812 if ((i = nstrtok (race, ",")) > 0)
1813 {
1814 char tmpbuf[MAX_BUF];
1815 sprintf (buf, "Creatures sacred to %s include the \n", name);
1816 if (i > 1)
1817 sprintf (tmpbuf, "following \n races:%s",
1818 strtoktolin (race, ","));
1819 else
1820 sprintf (tmpbuf, "race of%s", strtoktolin (race, ","));
1821 sprintf (buf, "%s%s\n ---\n", buf, tmpbuf);
1822 }
1823 }
1824 if (level == 6 && RANDOM () % 2)
1825 { /* blessing,curse properties of the god */
1826 char tmpbuf[MAX_BUF],*cp;
1827
1828 cp = describe_resistance(god, 1);
1829
1830 if (*cp) { /* This god does have protections */
1831 sprintf (tmpbuf, "\nThe priests of %s are known to be able to \n"
1832 ,name);
1833 strcat (tmpbuf, "bestow a blessing which makes the recipient\n");
1834 strcat(tmpbuf, cp);
1835 strcat (buf, tmpbuf); 1856 strcat (buf, tmpbuf);
1836 strcat (buf, "\n ---\n"); 1857 strcat (buf, "\n ---\n");
1837 } 1858 }
1838 else 1859 else
1839 sprintf (buf, " "); 1860 sprintf (buf, " ");
1840
1841 } 1861 }
1842 if (level == 8 && RANDOM () % 2)
1843 { /* immunity, holy possession */
1844 int has_effect = 0, tmpvar;
1845 char tmpbuf[MAX_BUF];
1846 sprintf (tmpbuf, "\n");
1847 sprintf (tmpbuf, "The priests of %s are known to make cast a mighty \n"
1848 ,name);
1849
1850 strcat (tmpbuf, "prayer of possession which gives the recipient\n");
1851
1852 for (tmpvar=0; tmpvar<NROFATTACKS; tmpvar++) {
1853 if (god->resist[tmpvar]==100) {
1854 has_effect = 1;
1855 sprintf(tmpbuf + strlen(tmpbuf),"Immunity to %s", attacktype_desc[tmpvar]);
1856 }
1857 }
1858 if (has_effect) {
1859 strcat (buf, tmpbuf);
1860 strcat (buf, "\n ---\n");
1861 }
1862 else
1863 sprintf (buf, " ");
1864 }
1865 if (level == 12 && RANDOM () % 2) 1862 if (level == 12 && RANDOM () % 2)
1866 { /* spell paths */ 1863 { /* spell paths */
1867 int has_effect = 0, tmpvar; 1864 int has_effect = 0, tmpvar;
1868 char tmpbuf[MAX_BUF]; 1865 char tmpbuf[MAX_BUF];
1866
1869 sprintf (tmpbuf, "\n"); 1867 sprintf (tmpbuf, "\n");
1870 sprintf (tmpbuf, "It is rarely known fact that the priests of %s\n" 1868 sprintf (tmpbuf, "It is rarely known fact that the priests of %s\n", name);
1871 ,name);
1872 strcat (tmpbuf, "are mystically transformed. Effects of this include:\n"); 1869 strcat (tmpbuf, "are mystically transformed. Effects of this include:\n");
1873 if ((tmpvar = god->path_attuned)) 1870 if ((tmpvar = god->path_attuned))
1874 { 1871 {
1875 has_effect = 1; 1872 has_effect = 1;
1876 DESCRIBE_PATH (tmpbuf, tmpvar, "Attuned"); 1873 DESCRIBE_PATH (tmpbuf, tmpvar, "Attuned");
1877 } 1874 }
1878 if ((tmpvar = god->path_repelled)) 1875 if ((tmpvar = god->path_repelled))
1879 { 1876 {
1880 has_effect = 1; 1877 has_effect = 1;
1881 DESCRIBE_PATH (tmpbuf, tmpvar, "Repelled"); 1878 DESCRIBE_PATH (tmpbuf, tmpvar, "Repelled");
1882 } 1879 }
1883 if ((tmpvar = god->path_denied)) 1880 if ((tmpvar = god->path_denied))
1884 { 1881 {
1885 has_effect = 1; 1882 has_effect = 1;
1886 DESCRIBE_PATH (tmpbuf, tmpvar, "Denied"); 1883 DESCRIBE_PATH (tmpbuf, tmpvar, "Denied");
1887 } 1884 }
1888 if (has_effect) 1885 if (has_effect)
1889 {
1890 strcat (buf, tmpbuf);
1891 strcat (buf, "\n ---\n");
1892 }
1893 else
1894 sprintf (buf, " ");
1895 } 1886 {
1887 strcat (buf, tmpbuf);
1888 strcat (buf, "\n ---\n");
1889 }
1890 else
1891 sprintf (buf, " ");
1892 }
1896 1893
1897 /* check to be sure new buffer size dont exceed either 1894 /* check to be sure new buffer size dont exceed either
1898 * the maximum buffer size, or the 'natural' size of the 1895 * the maximum buffer size, or the 'natural' size of the
1899 * book... 1896 * book...
1900 */ 1897 */
1901 if (book_overflow (retbuf, buf, booksize)) 1898 if (book_overflow (retbuf, buf, booksize))
1902 break; 1899 break;
1903 else if (strlen (buf) > 1) 1900 else if (strlen (buf) > 1)
1904 strcat (retbuf, buf); 1901 strcat (retbuf, buf);
1905 level--; 1902 level--;
1906 } 1903 }
1907 if (strlen (retbuf) == introlen) 1904 if (strlen (retbuf) == introlen)
1908 { /* we got no information beyond the preamble! */ 1905 { /* we got no information beyond the preamble! */
1909 strcat (retbuf, " [Unfortunately the rest of the information is\n"); 1906 strcat (retbuf, " [Unfortunately the rest of the information is\n");
1910 strcat (retbuf, " hopelessly garbled!]\n ---\n"); 1907 strcat (retbuf, " hopelessly garbled!]\n ---\n");
1911 } 1908 }
1912#ifdef BOOK_MSG_DEBUG 1909#ifdef BOOK_MSG_DEBUG
1913 LOG (llevDebug, "\n god_info_msg() created strng: %d\n", strlen (retbuf)); 1910 LOG (llevDebug, "\n god_info_msg() created strng: %d\n", strlen (retbuf));
1914 fprintf (logfile, " MADE THIS:\n%s", retbuf); 1911 fprintf (logfile, " MADE THIS:\n%s", retbuf);
1915#endif 1912#endif
1916 return retbuf; 1913 return retbuf;
1917} 1914}
1918 1915
1919/* tailor_readable_ob()- The main routine. This chooses a random 1916/* tailor_readable_ob()- The main routine. This chooses a random
1920 * message to put in given readable object (type==BOOK) which will 1917 * message to put in given readable object (type==BOOK) which will
1921 * be referred hereafter as a 'book'. We use the book level to de- 1918 * be referred hereafter as a 'book'. We use the book level to de-
1931 * If msg_type is a positive value, we use that to determine the 1928 * If msg_type is a positive value, we use that to determine the
1932 * message type - otherwise a random value is used. 1929 * message type - otherwise a random value is used.
1933 * 1930 *
1934 */ 1931 */
1935 1932
1936void 1933void
1937tailor_readable_ob (object *book, int msg_type) 1934tailor_readable_ob (object *book, int msg_type)
1938{ 1935{
1939 char msgbuf[BOOK_BUF]; 1936 char msgbuf[BOOK_BUF];
1940 int level = book->level ? (RANDOM () % book->level) + 1 : 1; 1937 int level = book->level ? (RANDOM () % book->level) + 1 : 1;
1941 int book_buf_size; 1938 int book_buf_size;
1942 1939
1943 /* safety */ 1940 /* safety */
1944 if (book->type != BOOK) 1941 if (book->type != BOOK)
1945 return; 1942 return;
1946 1943
1947 if (level <= 0) 1944 if (level <= 0)
1948 return; /* if no level no point in doing any more... */ 1945 return; /* if no level no point in doing any more... */
1949 1946
1950 /* Max text length this book can have. */ 1947 /* Max text length this book can have. */
1951 book_buf_size = BOOKSIZE (book); 1948 book_buf_size = BOOKSIZE (book);
1952 1949
1953 /* &&& The message switch &&& */ 1950 /* &&& The message switch &&& */
1954 /* Below all of the possible types of messages in the "book"s. 1951 /* Below all of the possible types of messages in the "book"s.
1955 */ 1952 */
1956 /* 1953 /*
1957 * IF you add a new type of book msg, you will have to do several things. 1954 * IF you add a new type of book msg, you will have to do several things.
1958 * 1) make sure there is an entry in the msg switch below! 1955 * 1) make sure there is an entry in the msg switch below!
1959 * 2) make sure there is an entry in max_titles[] array. 1956 * 2) make sure there is an entry in max_titles[] array.
1960 * 3) make sure there are entries for your case in new_text_title() 1957 * 3) make sure there are entries for your case in new_text_title()
1961 * and add_authour(). 1958 * and add_authour().
1962 * 4) you may want separate authour/book name arrays in read.h 1959 * 4) you may want separate authour/book name arrays in read.h
1963 */ 1960 */
1964 1961
1965 msg_type = msg_type > 0 ? msg_type : (RANDOM () % 6); 1962 msg_type = msg_type > 0 ? msg_type : (RANDOM () % 6);
1966 switch (msg_type) 1963 switch (msg_type)
1967 { 1964 {
1968 case 1: /* monster attrib */ 1965 case 1: /* monster attrib */
1969 strcpy (msgbuf, mon_info_msg (level, book_buf_size)); 1966 strcpy (msgbuf, mon_info_msg (level, book_buf_size));
1970 break; 1967 break;
1971 case 2: /* artifact attrib */ 1968 case 2: /* artifact attrib */
1972 strcpy (msgbuf, artifact_msg (level, book_buf_size)); 1969 strcpy (msgbuf, artifact_msg (level, book_buf_size));
1973 break; 1970 break;
1974 case 3: /* grouping incantations/prayers by path */ 1971 case 3: /* grouping incantations/prayers by path */
1975 strcpy (msgbuf, spellpath_msg (level, book_buf_size)); 1972 strcpy (msgbuf, spellpath_msg (level, book_buf_size));
1976 break; 1973 break;
1977 case 4: /* describe an alchemy formula */ 1974 case 4: /* describe an alchemy formula */
1978 make_formula_book(book, level); 1975 make_formula_book (book, level);
1979 /* make_formula_book already gives title */ 1976 /* make_formula_book already gives title */
1980 return; 1977 return;
1981 break; 1978 break;
1982 case 5: /* bits of information about a god */ 1979 case 5: /* bits of information about a god */
1983 strcpy (msgbuf, god_info_msg (level, book_buf_size)); 1980 strcpy (msgbuf, god_info_msg (level, book_buf_size));
1984 break; 1981 break;
1985 case 0: /* use info list in lib/ */ 1982 case 0: /* use info list in lib/ */
1986 default: 1983 default:
1987 strcpy (msgbuf, msgfile_msg (level, book_buf_size)); 1984 strcpy (msgbuf, msgfile_msg (level, book_buf_size));
1988 break; 1985 break;
1989 } 1986 }
1990 1987
1991 strcat (msgbuf, "\n"); /* safety -- we get ugly map saves/crashes w/o this */ 1988 strcat (msgbuf, "\n"); /* safety -- we get ugly map saves/crashes w/o this */
1992 if (strlen (msgbuf) > 1) 1989 if (strlen (msgbuf) > 1)
1993 { 1990 {
1994 book->msg = msgbuf; 1991 book->msg = msgbuf;
1995 /* lets give the "book" a new name, which may be a compound word */ 1992 /* lets give the "book" a new name, which may be a compound word */
1996 change_book (book, msg_type); 1993 change_book (book, msg_type);
1997 } 1994 }
1998 1995
1999} 1996}
2000 1997
2001 1998
2002/***************************************************************************** 1999/*****************************************************************************
2003 * 2000 *
2004 * Cleanup routine for readble stuff. 2001 * Cleanup routine for readble stuff.
2005 * 2002 *
2006 *****************************************************************************/ 2003 *****************************************************************************/
2007 2004
2008void 2005void
2009free_all_readable (void) 2006free_all_readable (void)
2010{ 2007{
2011 titlelist *tlist, *tnext; 2008 titlelist *tlist, *tnext;
2012 title *title1, *titlenext; 2009 title *title1, *titlenext;
2013 linked_char *lmsg, *nextmsg; 2010 linked_char *lmsg, *nextmsg;
2014 objectlink *monlink, *nextmon; 2011 objectlink *monlink, *nextmon;
2015 2012
2016 LOG (llevDebug, "freeing all book information\n"); 2013 LOG (llevDebug, "freeing all book information\n");
2017 2014
2018 for (tlist = booklist; tlist != NULL; tlist = tnext) 2015 for (tlist = booklist; tlist != NULL; tlist = tnext)
2019 { 2016 {
2020 tnext = tlist->next; 2017 tnext = tlist->next;
2021 2018
2022 for (title1 = tlist->first_book; title1; title1 = titlenext) 2019 for (title1 = tlist->first_book; title1; title1 = titlenext)
2023 { 2020 {
2024 titlenext = title1->next; 2021 titlenext = title1->next;
2025 delete title1; 2022 delete title1;
2026 } 2023 }
2027 2024
2028 delete tlist; 2025 delete tlist;
2029 } 2026 }
2030 for (lmsg = first_msg; lmsg; lmsg = nextmsg) 2027 for (lmsg = first_msg; lmsg; lmsg = nextmsg)
2031 { 2028 {
2032 nextmsg = lmsg->next; 2029 nextmsg = lmsg->next;
2033 delete lmsg; 2030 delete lmsg;
2034 } 2031 }
2035 for (monlink = first_mon_info; monlink; monlink = nextmon) 2032 for (monlink = first_mon_info; monlink; monlink = nextmon)
2036 { 2033 {
2037 nextmon = monlink->next; 2034 nextmon = monlink->next;
2038 free (monlink); 2035 free (monlink);
2039 } 2036 }
2040} 2037}
2041 2038
2042 2039
2043/***************************************************************************** 2040/*****************************************************************************
2044 * 2041 *
2046 * 2043 *
2047 ****************************************************************************/ 2044 ****************************************************************************/
2048 2045
2049/* write_book_archive() - write out the updated book archive */ 2046/* write_book_archive() - write out the updated book archive */
2050 2047
2051void 2048void
2052write_book_archive (void) 2049write_book_archive (void)
2053{ 2050{
2054 FILE *fp; 2051 FILE *fp;
2055 int index = 0; 2052 int index = 0;
2056 char fname[MAX_BUF]; 2053 char fname[MAX_BUF];
2057 title *book = NULL; 2054 title *book = NULL;
2058 titlelist *bl = get_titlelist (0); 2055 titlelist *bl = get_titlelist (0);
2059 2056
2060 /* If nothing changed, don't write anything */ 2057 /* If nothing changed, don't write anything */
2061 if (!need_to_write_bookarchive) return; 2058 if (!need_to_write_bookarchive)
2059 return;
2062 need_to_write_bookarchive=0; 2060 need_to_write_bookarchive = 0;
2063 2061
2064 sprintf (fname, "%s/bookarch", settings.localdir); 2062 sprintf (fname, "%s/bookarch", settings.localdir);
2065 LOG (llevDebug, "Updating book archive: %s...\n", fname); 2063 LOG (llevDebug, "Updating book archive: %s...\n", fname);
2066 2064
2067 if ((fp = fopen (fname, "w")) == NULL) 2065 if ((fp = fopen (fname, "w")) == NULL)
2068 { 2066 {
2069 LOG (llevDebug, "Can't open book archive file %s\n", fname); 2067 LOG (llevDebug, "Can't open book archive file %s\n", fname);
2070 } 2068 }
2071 else 2069 else
2072 { 2070 {
2073 while (bl) 2071 while (bl)
2074 { 2072 {
2075 for (book = bl->first_book; book; book = book->next) 2073 for (book = bl->first_book; book; book = book->next)
2076 if (book && book->authour) 2074 if (book && book->authour)
2077 { 2075 {
2078 fprintf (fp, "title %s\n", &book->name); 2076 fprintf (fp, "title %s\n", &book->name);
2079 fprintf (fp, "authour %s\n", &book->authour); 2077 fprintf (fp, "authour %s\n", &book->authour);
2080 fprintf (fp, "arch %s\n", &book->archname); 2078 fprintf (fp, "arch %s\n", &book->archname);
2081 fprintf (fp, "level %d\n", book->level); 2079 fprintf (fp, "level %d\n", book->level);
2082 fprintf (fp, "type %d\n", index); 2080 fprintf (fp, "type %d\n", index);
2083 fprintf (fp, "size %d\n", book->size); 2081 fprintf (fp, "size %d\n", book->size);
2084 fprintf (fp, "index %d\n", book->msg_index); 2082 fprintf (fp, "index %d\n", book->msg_index);
2085 fprintf (fp, "end\n"); 2083 fprintf (fp, "end\n");
2086 }
2087 bl = bl->next;
2088 index++;
2089 } 2084 }
2085 bl = bl->next;
2086 index++;
2087 }
2090 fclose (fp); 2088 fclose (fp);
2091 chmod (fname, SAVE_MODE); 2089 chmod (fname, SAVE_MODE);
2092 } 2090 }
2093} 2091}
2092readable_message_type *
2094readable_message_type* get_readable_message_type(object* readable){ 2093get_readable_message_type (object *readable)
2094{
2095 uint8 subtype = readable->subtype; 2095 uint8 subtype = readable->subtype;
2096
2096 if (subtype>last_readable_subtype) 2097 if (subtype > last_readable_subtype)
2097 return &(readable_message_types[0]); 2098 return &(readable_message_types[0]);
2098 return &(readable_message_types[subtype]); 2099 return &(readable_message_types[subtype]);
2099} 2100}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines