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