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.11 by root, Sun Oct 15 02:16:34 2006 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines