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.1 by elmex, Sun Aug 13 17:16:00 2006 UTC vs.
Revision 1.69 by root, Sat Nov 17 23:40:00 2018 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines