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