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