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