… | |
… | |
3 | * |
3 | * |
4 | * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
4 | * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team |
5 | * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
7 | * |
7 | * |
8 | * Deliantra is free software: you can redistribute it and/or modify |
8 | * Deliantra is free software: you can redistribute it and/or modify it under |
9 | * it under the terms of the GNU General Public License as published by |
9 | * the terms of the Affero GNU General Public License as published by the |
10 | * the Free Software Foundation, either version 3 of the License, or |
10 | * Free Software Foundation, either version 3 of the License, or (at your |
11 | * (at your option) any later version. |
11 | * option) any later version. |
12 | * |
12 | * |
13 | * 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, |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | * GNU General Public License for more details. |
16 | * GNU General Public License for more details. |
17 | * |
17 | * |
18 | * You should have received a copy of the GNU General Public License |
18 | * You should have received a copy of the Affero GNU General Public License |
19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
19 | * and the GNU General Public License along with this program. If not, see |
|
|
20 | * <http://www.gnu.org/licenses/>. |
20 | * |
21 | * |
21 | * The authors can be reached via e-mail to <support@deliantra.net> |
22 | * The authors can be reached via e-mail to <support@deliantra.net> |
22 | */ |
23 | */ |
23 | |
24 | |
24 | /* This file contains code relevant to the BOOKS hack -- designed |
25 | /* This file contains code relevant to the BOOKS hack -- designed |
… | |
… | |
817 | else |
818 | else |
818 | t = t->next; |
819 | t = t->next; |
819 | |
820 | |
820 | #ifdef ARCHIVE_DEBUG |
821 | #ifdef ARCHIVE_DEBUG |
821 | if (t) |
822 | if (t) |
822 | LOG (llevDebug, "Found title match (list %d): %s %s (%d)\n", msgtype, t->name, t->authour, t->msg_index); |
823 | LOG (llevDebug, "Found title match (list %d): %s %s (%d)\n", msgtype, &t->name, &t->authour, t->msg_index); |
823 | #endif |
824 | #endif |
824 | |
825 | |
825 | return t; |
826 | return t; |
826 | } |
827 | } |
827 | |
828 | |
… | |
… | |
932 | */ |
933 | */ |
933 | |
934 | |
934 | static int |
935 | static int |
935 | unique_book (const object *book, int msgtype) |
936 | unique_book (const object *book, int msgtype) |
936 | { |
937 | { |
937 | title *test; |
|
|
938 | |
|
|
939 | if (!booklist) |
938 | if (!booklist) |
940 | return 1; /* No archival entries! Must be unique! */ |
939 | return 1; /* No archival entries! Must be unique! */ |
941 | |
940 | |
942 | /* Go through the booklist. If the author and name match, not unique so |
941 | /* Go through the booklist. If the author and name match, not unique so |
943 | * return 0. |
942 | * return 0. |
944 | */ |
943 | */ |
945 | for (test = get_titlelist (msgtype)->first_book; test; test = test->next) |
944 | for (title *test = get_titlelist (msgtype)->first_book; test; test = test->next) |
946 | { |
|
|
947 | if (!strcmp (test->name, book->name) && !strcmp (book->title, test->authour)) |
945 | if (test->name == book->name && book->title == test->authour) |
948 | return 0; |
946 | return 0; |
949 | } |
947 | |
950 | return 1; |
948 | return 1; |
951 | } |
949 | } |
952 | |
950 | |
953 | /* add_book_to_list() */ |
951 | /* add_book_to_list() */ |
954 | |
952 | |
… | |
… | |
978 | |
976 | |
979 | /* We have stuff we need to write now */ |
977 | /* We have stuff we need to write now */ |
980 | need_to_write_bookarchive = 1; |
978 | need_to_write_bookarchive = 1; |
981 | |
979 | |
982 | #ifdef ARCHIVE_DEBUG |
980 | #ifdef ARCHIVE_DEBUG |
983 | LOG (llevDebug, "Archiving new title: %s %s (%d)\n", book->name, book->title, msgtype); |
981 | LOG (llevDebug, "Archiving new title: %s %s (%d)\n", &book->name, &book->title, msgtype); |
984 | #endif |
982 | #endif |
985 | |
983 | |
986 | } |
984 | } |
987 | |
985 | |
988 | |
986 | |
… | |
… | |
1020 | /* alter book properties */ |
1018 | /* alter book properties */ |
1021 | if (object *tmpbook = get_archetype (t->archname)) |
1019 | if (object *tmpbook = get_archetype (t->archname)) |
1022 | { |
1020 | { |
1023 | tmpbook->msg = book->msg; |
1021 | tmpbook->msg = book->msg; |
1024 | tmpbook->copy_to (book); |
1022 | tmpbook->copy_to (book); |
1025 | tmpbook->destroy (true); |
1023 | tmpbook->destroy (); |
1026 | } |
1024 | } |
1027 | |
1025 | |
1028 | book->title = t->authour; |
1026 | book->title = t->authour; |
1029 | book->name = t->name; |
1027 | book->name = t->name; |
1030 | book->level = t->level; |
1028 | book->level = t->level; |
… | |
… | |
1054 | if (numb == maxnames) |
1052 | if (numb == maxnames) |
1055 | { |
1053 | { |
1056 | #ifdef ARCHIVE_DEBUG |
1054 | #ifdef ARCHIVE_DEBUG |
1057 | LOG (llevDebug, "titles for list %d full (%d possible).\n", msgtype, maxnames); |
1055 | LOG (llevDebug, "titles for list %d full (%d possible).\n", msgtype, maxnames); |
1058 | #endif |
1056 | #endif |
1059 | break; |
|
|
1060 | } |
1057 | } |
1061 | /* shouldnt change map-maker books */ |
1058 | /* shouldnt change map-maker books */ |
1062 | else if (!book->title) |
1059 | else if (!book->title) |
1063 | do |
1060 | do |
1064 | { |
1061 | { |
… | |
… | |
1079 | */ |
1076 | */ |
1080 | |
1077 | |
1081 | if (tries == MAX_TITLE_CHECK || numb == maxnames) |
1078 | if (tries == MAX_TITLE_CHECK || numb == maxnames) |
1082 | { /* got to check maxnames again */ |
1079 | { /* got to check maxnames again */ |
1083 | #ifdef ARCHIVE_DEBUG |
1080 | #ifdef ARCHIVE_DEBUG |
1084 | LOG (llevDebug, "Failed to obtain unique title for %s %s (names:%d/%d)\n", book->name, book->title, numb, maxnames); |
1081 | LOG (llevDebug, "Failed to obtain unique title for %s %s (names:%d/%d)\n", &book->name, &book->title, numb, maxnames); |
1085 | #endif |
1082 | #endif |
1086 | /* restore old book properties here */ |
1083 | /* restore old book properties here */ |
1087 | book->title = old_title; |
1084 | book->title = old_title; |
1088 | |
1085 | |
1089 | if (RANDOM () % 4) |
1086 | if (rndm (4)) |
1090 | { |
1087 | { |
1091 | /* Lets give the book a description to individualize it some */ |
1088 | /* Lets give the book a description to individualize it some */ |
1092 | char new_name[MAX_BUF]; |
1089 | char new_name[MAX_BUF]; |
1093 | |
1090 | |
1094 | snprintf (new_name, MAX_BUF, "%s %s", book_descrpt[rndm (nbr)], old_name); |
1091 | snprintf (new_name, MAX_BUF, "%s %s", book_descrpt[rndm (nbr)], old_name); |
… | |
… | |
1143 | return (object *) NULL; |
1140 | return (object *) NULL; |
1144 | |
1141 | |
1145 | if (!level) |
1142 | if (!level) |
1146 | { |
1143 | { |
1147 | /* lets get a random monster from the mon_info linked list */ |
1144 | /* lets get a random monster from the mon_info linked list */ |
1148 | monnr = RANDOM () % nrofmon; |
1145 | monnr = rndm (nrofmon); |
1149 | |
1146 | |
1150 | for (mon = first_mon_info, i = 0; mon; mon = mon->next) |
1147 | for (mon = first_mon_info, i = 0; mon; mon = mon->next) |
1151 | if (i++ == monnr) |
1148 | if (i++ == monnr) |
1152 | break; |
1149 | break; |
1153 | |
1150 | |
… | |
… | |
1180 | { |
1177 | { |
1181 | LOG (llevError, "get_random_mon() couldn't return monster for level %d\n", level); |
1178 | LOG (llevError, "get_random_mon() couldn't return monster for level %d\n", level); |
1182 | return NULL; |
1179 | return NULL; |
1183 | } |
1180 | } |
1184 | |
1181 | |
1185 | monnr = RANDOM () % i; |
1182 | monnr = rndm (i); |
1186 | for (mon = first_mon_info; mon; mon = mon->next) |
1183 | for (mon = first_mon_info; mon; mon = mon->next) |
1187 | if (mon->ob->level >= level && monnr-- == 0) |
1184 | if (mon->ob->level >= level && monnr-- == 0) |
1188 | return mon->ob; |
1185 | return mon->ob; |
1189 | |
1186 | |
1190 | if (!mon) |
1187 | if (!mon) |
… | |
… | |
1273 | /* Note that the value this returns is not based on level */ |
1270 | /* Note that the value this returns is not based on level */ |
1274 | tmp = get_next_mon (tmp); |
1271 | tmp = get_next_mon (tmp); |
1275 | } |
1272 | } |
1276 | |
1273 | |
1277 | #ifdef BOOK_MSG_DEBUG |
1274 | #ifdef BOOK_MSG_DEBUG |
1278 | LOG (llevDebug, "\n mon_info_msg() created strng: %d\n", strlen (retbuf)); |
1275 | LOG (llevDebug, "\n mon_info_msg() created string: %d\n", strlen (retbuf)); |
1279 | fprintf (logfile, " MADE THIS:\n%s\n", retbuf); |
1276 | LOG (llevDebug, " MADE THIS:\n%s\n", retbuf); |
1280 | #endif |
1277 | #endif |
1281 | |
1278 | |
1282 | return retbuf; |
1279 | return retbuf; |
1283 | } |
1280 | } |
1284 | |
1281 | |
… | |
… | |
1294 | artifact_msg (int level, int booksize) |
1291 | artifact_msg (int level, int booksize) |
1295 | { |
1292 | { |
1296 | artifactlist *al = NULL; |
1293 | artifactlist *al = NULL; |
1297 | artifact *art; |
1294 | artifact *art; |
1298 | int chance, i, type, index; |
1295 | int chance, i, type, index; |
1299 | int book_entries = level > 5 ? RANDOM () % 3 + RANDOM () % 3 + 2 : RANDOM () % level + 1; |
1296 | int book_entries = level > 5 ? rndm (3) + rndm (3) + 2 : rndm (level) + 1; |
1300 | const char *ch; |
1297 | const char *ch; |
1301 | char name[MAX_BUF], buf[BOOK_BUF], sbuf[MAX_BUF]; |
1298 | char name[MAX_BUF], buf[BOOK_BUF], sbuf[MAX_BUF]; |
1302 | static char retbuf[BOOK_BUF]; |
1299 | static char retbuf[BOOK_BUF]; |
1303 | object *tmp = NULL; |
1300 | object *tmp = NULL; |
1304 | |
1301 | |
… | |
… | |
1312 | * for that type exists! |
1309 | * for that type exists! |
1313 | */ |
1310 | */ |
1314 | i = 0; |
1311 | i = 0; |
1315 | do |
1312 | do |
1316 | { |
1313 | { |
1317 | index = RANDOM () % (sizeof (art_name_array) / sizeof (arttypename)); |
1314 | index = rndm (sizeof (art_name_array) / sizeof (arttypename)); |
1318 | type = art_name_array[index].type; |
1315 | type = art_name_array[index].type; |
1319 | al = find_artifactlist (type); |
1316 | al = find_artifactlist (type); |
1320 | i++; |
1317 | i++; |
1321 | } |
1318 | } |
1322 | while ((al == NULL) && (i < 10)); |
1319 | while ((al == NULL) && (i < 10)); |
… | |
… | |
1325 | return "None"; |
1322 | return "None"; |
1326 | |
1323 | |
1327 | /* There is no reason to start on the artifact list at the begining. Lets |
1324 | /* There is no reason to start on the artifact list at the begining. Lets |
1328 | * take our starting position randomly... */ |
1325 | * take our starting position randomly... */ |
1329 | art = al->items; |
1326 | art = al->items; |
1330 | for (i = RANDOM () % level + RANDOM () % 2 + 1; i > 0; i--) |
1327 | for (i = rndm (level) + rndm (2) + 1; i > 0; i--) |
1331 | { |
1328 | { |
1332 | if (art == NULL) |
1329 | if (!art) |
1333 | art = al->items; /* hmm, out of stuff, loop back around */ |
1330 | art = al->items; /* hmm, out of stuff, loop back around */ |
|
|
1331 | |
1334 | art = art->next; |
1332 | art = art->next; |
1335 | } |
1333 | } |
1336 | |
1334 | |
1337 | /* the base 'generic' name for our artifact */ |
1335 | /* the base 'generic' name for our artifact */ |
1338 | assign (name, art_name_array[index].name); |
1336 | assign (name, art_name_array[index].name); |
… | |
… | |
1351 | |
1349 | |
1352 | /* separator of items */ |
1350 | /* separator of items */ |
1353 | strcpy (buf, "--- \n"); |
1351 | strcpy (buf, "--- \n"); |
1354 | |
1352 | |
1355 | /* Name */ |
1353 | /* Name */ |
1356 | if (art->allowed != NULL && strcmp (art->allowed->name, "All")) |
1354 | if (art->allowed && art->allowed->name != shstr_All) |
1357 | { |
1355 | { |
1358 | linked_char *temp, *next = art->allowed; |
1356 | linked_char *temp, *next = art->allowed; |
1359 | |
1357 | |
1360 | do |
1358 | do |
1361 | { |
1359 | { |
1362 | temp = next; |
1360 | temp = next; |
1363 | next = next->next; |
1361 | next = next->next; |
1364 | } |
1362 | } |
1365 | while (next && !RANDOM () % 2); |
1363 | while (next && rndm (2)); |
1366 | sprintf (buf, "%s A %s of %s", buf, &temp->name, &art->item->name); |
1364 | sprintf (buf, "%s A %s of %s", buf, &temp->name, &art->item->name); |
1367 | } |
1365 | } |
1368 | else /* default name is used */ |
1366 | else /* default name is used */ |
1369 | sprintf (buf, "%s The %s of %s", buf, name, &art->item->name); |
1367 | sprintf (buf, "%s The %s of %s", buf, name, &art->item->name); |
1370 | |
1368 | |
… | |
… | |
1383 | /* value of artifact */ |
1381 | /* value of artifact */ |
1384 | sprintf (buf, "%s item with a value that is %d times normal.\n", buf, art->item->value); |
1382 | sprintf (buf, "%s item with a value that is %d times normal.\n", buf, art->item->value); |
1385 | |
1383 | |
1386 | /* include the message about the artifact, if exists, and book |
1384 | /* include the message about the artifact, if exists, and book |
1387 | * level is kinda high */ |
1385 | * level is kinda high */ |
1388 | if (art->item->msg && (RANDOM () % 4 + 1) < level && !((strlen (art->item->msg) + strlen (buf)) > BOOK_BUF)) |
1386 | if (art->item->msg |
|
|
1387 | && rndm (4) + 1 < level |
|
|
1388 | && !(strlen (art->item->msg) + strlen (buf) > BOOK_BUF)) |
1389 | strcat (buf, art->item->msg); |
1389 | strcat (buf, art->item->msg); |
1390 | |
1390 | |
1391 | /* properties of the artifact */ |
1391 | /* properties of the artifact */ |
1392 | tmp = object::create (); |
1392 | tmp = object::create (); |
1393 | add_abilities (tmp, art->item); |
1393 | add_abilities (tmp, art->item); |
1394 | tmp->type = type; |
1394 | tmp->type = type; |
1395 | SET_FLAG (tmp, FLAG_IDENTIFIED); |
1395 | SET_FLAG (tmp, FLAG_IDENTIFIED); |
1396 | if ((ch = describe_item (tmp, NULL)) != NULL && strlen (ch) > 1) |
1396 | if ((ch = describe_item (tmp, NULL)) != NULL && strlen (ch) > 1) |
1397 | sprintf (buf, "%s Properties of this artifact include: \n %s \n", buf, ch); |
1397 | sprintf (buf, "%s Properties of this artifact include: \n %s \n", buf, ch); |
1398 | tmp->destroy (true); |
1398 | tmp->destroy (); |
1399 | /* add the buf if it will fit */ |
1399 | /* add the buf if it will fit */ |
1400 | if (!book_overflow (retbuf, buf, booksize)) |
1400 | if (!book_overflow (retbuf, buf, booksize)) |
1401 | strcat (retbuf, buf); |
1401 | strcat (retbuf, buf); |
1402 | else |
1402 | else |
1403 | break; |
1403 | break; |
… | |
… | |
1405 | art = art->next; |
1405 | art = art->next; |
1406 | book_entries--; |
1406 | book_entries--; |
1407 | } |
1407 | } |
1408 | |
1408 | |
1409 | #ifdef BOOK_MSG_DEBUG |
1409 | #ifdef BOOK_MSG_DEBUG |
1410 | LOG (llevDebug, "artifact_msg() created strng: %d\n", strlen (retbuf)); |
1410 | LOG (llevDebug, "artifact_msg() created string: %d\n", strlen (retbuf)); |
1411 | fprintf (logfile, " MADE THIS:\n%s", retbuf); |
1411 | LOG (llevDebug, " MADE THIS:\n%s", retbuf); |
1412 | #endif |
1412 | #endif |
1413 | return retbuf; |
1413 | return retbuf; |
1414 | } |
1414 | } |
1415 | |
1415 | |
1416 | /***************************************************************************** |
1416 | /***************************************************************************** |
… | |
… | |
1425 | char * |
1425 | char * |
1426 | spellpath_msg (int level, int booksize) |
1426 | spellpath_msg (int level, int booksize) |
1427 | { |
1427 | { |
1428 | static char retbuf[BOOK_BUF]; |
1428 | static char retbuf[BOOK_BUF]; |
1429 | char tmpbuf[BOOK_BUF]; |
1429 | char tmpbuf[BOOK_BUF]; |
1430 | int path = RANDOM () % NRSPELLPATHS, prayers = RANDOM () % 2; |
1430 | int path = rndm (NRSPELLPATHS), prayers = rndm (2); |
1431 | int did_first_sp = 0; |
1431 | int did_first_sp = 0; |
1432 | uint32 pnum = (path == -1) ? PATH_NULL : spellpathdef[path]; |
1432 | uint32 pnum = (path == -1) ? PATH_NULL : spellpathdef[path]; |
1433 | archetype *at; |
1433 | archetype *at; |
1434 | |
1434 | |
1435 | /* Preamble */ |
1435 | /* Preamble */ |
… | |
… | |
1463 | } |
1463 | } |
1464 | } |
1464 | } |
1465 | /* Geez, no spells were generated. */ |
1465 | /* Geez, no spells were generated. */ |
1466 | if (!did_first_sp) |
1466 | if (!did_first_sp) |
1467 | { |
1467 | { |
1468 | if (RANDOM () % 4) /* usually, lets make a recursive call... */ |
1468 | if (rndm (4)) /* usually, lets make a recursive call... */ |
1469 | spellpath_msg (level, booksize); |
1469 | spellpath_msg (level, booksize); |
1470 | 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. */ |
1471 | strcat (retbuf, "\n - no known spells exist -\n"); |
1471 | strcat (retbuf, "\n - no known spells exist -\n"); |
1472 | } |
1472 | } |
1473 | else |
1473 | else |
1474 | { |
1474 | { |
1475 | strcat (retbuf, "\n"); |
1475 | strcat (retbuf, "\n"); |
1476 | } |
1476 | } |
|
|
1477 | |
|
|
1478 | #ifdef BOOK_MSG_DEBUG |
|
|
1479 | LOG (llevDebug, "spellpath_msg() created string: %d\n", strlen (retbuf)); |
|
|
1480 | LOG (llevDebug, " MADE THIS:\n%s", retbuf); |
|
|
1481 | #endif |
1477 | return retbuf; |
1482 | return retbuf; |
1478 | } |
1483 | } |
1479 | |
1484 | |
1480 | /* formula_msg() - generate a message detailing the properties |
1485 | /* formula_msg() - generate a message detailing the properties |
1481 | * of a randomly selected alchemical formula. |
1486 | * of a randomly selected alchemical formula. |
… | |
… | |
1489 | int chance; |
1494 | int chance; |
1490 | |
1495 | |
1491 | /* the higher the book level, the more complex (ie number of |
1496 | /* the higher the book level, the more complex (ie number of |
1492 | * ingredients) the formula can be. |
1497 | * ingredients) the formula can be. |
1493 | */ |
1498 | */ |
1494 | fl = get_formulalist (((RANDOM () % level) / 3) + 1); |
1499 | fl = get_formulalist (rndm (level) / 3 + 1); |
1495 | |
1500 | |
1496 | if (!fl) |
1501 | if (!fl) |
1497 | fl = get_formulalist (1); /* safety */ |
1502 | fl = get_formulalist (1); /* safety */ |
1498 | |
1503 | |
1499 | if (fl->total_chance == 0) |
1504 | if (fl->total_chance == 0) |
… | |
… | |
1503 | add_author (book, 4); |
1508 | add_author (book, 4); |
1504 | return; |
1509 | return; |
1505 | } |
1510 | } |
1506 | |
1511 | |
1507 | /* get a random formula, weighted by its bookchance */ |
1512 | /* get a random formula, weighted by its bookchance */ |
1508 | chance = RANDOM () % fl->total_chance; |
1513 | chance = rndm (fl->total_chance); |
1509 | for (formula = fl->items; formula != NULL; formula = formula->next) |
1514 | for (formula = fl->items; formula; formula = formula->next) |
1510 | { |
1515 | { |
1511 | chance -= formula->chance; |
1516 | chance -= formula->chance; |
1512 | if (chance <= 0) |
1517 | if (chance <= 0) |
1513 | break; |
1518 | break; |
1514 | } |
1519 | } |
… | |
… | |
1524 | { |
1529 | { |
1525 | /* looks like a formula was found. Base the amount |
1530 | /* looks like a formula was found. Base the amount |
1526 | * of information on the booklevel and the spellevel |
1531 | * of information on the booklevel and the spellevel |
1527 | * of the formula. */ |
1532 | * of the formula. */ |
1528 | |
1533 | |
1529 | const char *op_name = formula->arch_name[RANDOM () % formula->arch_names]; |
1534 | const char *op_name = formula->arch_name [rndm (formula->arch_names)]; |
1530 | archetype *at; |
1535 | archetype *at; |
1531 | |
1536 | |
1532 | /* preamble */ |
1537 | /* preamble */ |
1533 | sprintf (retbuf, "Herein is described a project using %s: \n", formula->skill ? &formula->skill : "an unknown skill"); |
1538 | sprintf (retbuf, "Herein is described a project using %s: \n", formula->skill ? &formula->skill : "an unknown skill"); |
1534 | |
1539 | |
… | |
… | |
1536 | op_name = at->object::name; |
1541 | op_name = at->object::name; |
1537 | else |
1542 | else |
1538 | LOG (llevError, "formula_msg() can't find arch %s for formula.\n", op_name); |
1543 | LOG (llevError, "formula_msg() can't find arch %s for formula.\n", op_name); |
1539 | |
1544 | |
1540 | /* item name */ |
1545 | /* item name */ |
1541 | if (strcmp (formula->title, "NONE")) |
1546 | if (formula->title != shstr_NONE) |
1542 | { |
1547 | { |
1543 | sprintf (retbuf, "%sThe %s of %s", retbuf, op_name, &formula->title); |
1548 | sprintf (retbuf, "%sThe %s of %s", retbuf, op_name, &formula->title); |
1544 | /* This results in things like pile of philo. sulfur. |
1549 | /* This results in things like pile of philo. sulfur. |
1545 | * while philo. sulfur may look better, without this, |
1550 | * while philo. sulfur may look better, without this, |
1546 | * you get things like 'the wise' because its missing the |
1551 | * you get things like 'the wise' because its missing the |
1547 | * water of section. |
1552 | * water of section. |
1548 | */ |
1553 | */ |
1549 | sprintf (title, "%s: %s of %s", |
1554 | sprintf (title, "%s: %s of %s", |
1550 | formula_book_name[RANDOM () % (sizeof (formula_book_name) / sizeof (char *))], op_name, &formula->title); |
1555 | formula_book_name [rndm (sizeof (formula_book_name) / sizeof (char *))], op_name, &formula->title); |
1551 | } |
1556 | } |
1552 | else |
1557 | else |
1553 | { |
1558 | { |
1554 | sprintf (retbuf, "%sThe %s", retbuf, op_name); |
1559 | sprintf (retbuf, "%sThe %s", retbuf, op_name); |
1555 | sprintf (title, "%s: %s", formula_book_name[RANDOM () % (sizeof (formula_book_name) / sizeof (char *))], op_name); |
1560 | sprintf (title, "%s: %s", formula_book_name [rndm (sizeof (formula_book_name) / sizeof (char *))], op_name); |
1556 | if (at->title) |
1561 | if (at->title) |
1557 | { |
1562 | { |
1558 | strcat (retbuf, " "); |
1563 | strcat (retbuf, " "); |
1559 | strcat (retbuf, at->title); |
1564 | strcat (retbuf, at->title); |
1560 | strcat (title, " "); |
1565 | strcat (title, " "); |
1561 | strcat (title, at->title); |
1566 | strcat (title, at->title); |
1562 | } |
1567 | } |
1563 | } |
1568 | } |
|
|
1569 | |
1564 | /* Lets name the book something meaningful ! */ |
1570 | /* Lets name the book something meaningful ! */ |
1565 | book->name = title; |
1571 | book->name = title; |
1566 | book->title = NULL; |
1572 | book->title = NULL; |
1567 | |
1573 | |
1568 | /* ingredients to make it */ |
1574 | /* ingredients to make it */ |
… | |
… | |
1644 | * this ... |
1650 | * this ... |
1645 | */ |
1651 | */ |
1646 | while (level > 0) |
1652 | while (level > 0) |
1647 | { |
1653 | { |
1648 | sprintf (buf, " "); |
1654 | sprintf (buf, " "); |
1649 | if (level == 2 && RANDOM () % 2) |
1655 | if (level == 2 && rndm (2)) |
1650 | { /* enemy god */ |
1656 | { /* enemy god */ |
1651 | const char *enemy = god->title; |
1657 | const char *enemy = god->title; |
1652 | |
1658 | |
1653 | if (enemy) |
1659 | if (enemy) |
1654 | sprintf (buf, "The gods %s and %s are enemies.\n ---\n", name, enemy); |
1660 | sprintf (buf, "The gods %s and %s are enemies.\n ---\n", name, enemy); |
1655 | } |
1661 | } |
1656 | |
1662 | |
1657 | if (level == 3 && RANDOM () % 2) |
1663 | if (level == 3 && rndm (2)) |
1658 | { /* enemy race, what the god's holy word effects */ |
1664 | { /* enemy race, what the god's holy word effects */ |
1659 | const char *enemy = god->slaying; |
1665 | const char *enemy = god->slaying; |
1660 | |
1666 | |
1661 | if (enemy && !(god->path_denied & PATH_TURNING)) |
1667 | if (enemy && !(god->path_denied & PATH_TURNING)) |
1662 | if ((i = nstrtok (enemy, ",")) > 0) |
1668 | if ((i = nstrtok (enemy, ",")) > 0) |
… | |
… | |
1671 | sprintf (tmpbuf, "race of%s", strtoktolin (enemy, ",")); |
1677 | sprintf (tmpbuf, "race of%s", strtoktolin (enemy, ",")); |
1672 | sprintf (buf, "%s%s\n ---\n", buf, tmpbuf); |
1678 | sprintf (buf, "%s%s\n ---\n", buf, tmpbuf); |
1673 | } |
1679 | } |
1674 | } |
1680 | } |
1675 | |
1681 | |
1676 | if (level == 4 && RANDOM () % 2) |
1682 | if (level == 4 && rndm (2)) |
1677 | { /* Priest of god gets these protect,vulnerable... */ |
1683 | { /* Priest of god gets these protect,vulnerable... */ |
1678 | char tmpbuf[MAX_BUF]; |
1684 | char tmpbuf[MAX_BUF]; |
1679 | |
1685 | |
1680 | if (const char *cp = describe_resistance (god, 1)) |
1686 | if (const char *cp = describe_resistance (god, 1)) |
1681 | { /* This god does have protections */ |
1687 | { /* This god does have protections */ |
… | |
… | |
1687 | } |
1693 | } |
1688 | else |
1694 | else |
1689 | sprintf (buf, " "); |
1695 | sprintf (buf, " "); |
1690 | } |
1696 | } |
1691 | |
1697 | |
1692 | if (level == 5 && RANDOM () % 2) |
1698 | if (level == 5 && rndm (2)) |
1693 | { /* aligned race, summoning */ |
1699 | { /* aligned race, summoning */ |
1694 | const char *race = god->race; /* aligned race */ |
1700 | const char *race = god->race; /* aligned race */ |
1695 | |
1701 | |
1696 | if (race && !(god->path_denied & PATH_SUMMON)) |
1702 | if (race && !(god->path_denied & PATH_SUMMON)) |
1697 | if ((i = nstrtok (race, ",")) > 0) |
1703 | if ((i = nstrtok (race, ",")) > 0) |
… | |
… | |
1705 | sprintf (tmpbuf, "race of%s", strtoktolin (race, ",")); |
1711 | sprintf (tmpbuf, "race of%s", strtoktolin (race, ",")); |
1706 | sprintf (buf, "%s%s\n ---\n", buf, tmpbuf); |
1712 | sprintf (buf, "%s%s\n ---\n", buf, tmpbuf); |
1707 | } |
1713 | } |
1708 | } |
1714 | } |
1709 | |
1715 | |
1710 | if (level == 6 && RANDOM () % 2) |
1716 | if (level == 6 && rndm (2)) |
1711 | { /* blessing,curse properties of the god */ |
1717 | { /* blessing,curse properties of the god */ |
1712 | char tmpbuf[MAX_BUF]; |
1718 | char tmpbuf[MAX_BUF]; |
1713 | |
1719 | |
1714 | if (const char *cp = describe_resistance (god, 1)) |
1720 | if (const char *cp = describe_resistance (god, 1)) |
1715 | { /* This god does have protections */ |
1721 | { /* This god does have protections */ |
… | |
… | |
1722 | else |
1728 | else |
1723 | sprintf (buf, " "); |
1729 | sprintf (buf, " "); |
1724 | |
1730 | |
1725 | } |
1731 | } |
1726 | |
1732 | |
1727 | if (level == 8 && RANDOM () % 2) |
1733 | if (level == 8 && rndm (2)) |
1728 | { /* immunity, holy possession */ |
1734 | { /* immunity, holy possession */ |
1729 | int has_effect = 0, tmpvar; |
1735 | int has_effect = 0, tmpvar; |
1730 | char tmpbuf[MAX_BUF]; |
1736 | char tmpbuf[MAX_BUF]; |
1731 | |
1737 | |
1732 | sprintf (tmpbuf, "\n"); |
1738 | sprintf (tmpbuf, "\n"); |
… | |
… | |
1750 | } |
1756 | } |
1751 | else |
1757 | else |
1752 | sprintf (buf, " "); |
1758 | sprintf (buf, " "); |
1753 | } |
1759 | } |
1754 | |
1760 | |
1755 | if (level == 12 && RANDOM () % 2) |
1761 | if (level == 12 && rndm (2)) |
1756 | { /* spell paths */ |
1762 | { /* spell paths */ |
1757 | int has_effect = 0, tmpvar; |
1763 | int has_effect = 0, tmpvar; |
1758 | char tmpbuf[MAX_BUF]; |
1764 | char tmpbuf[MAX_BUF]; |
1759 | |
1765 | |
1760 | sprintf (tmpbuf, "\n"); |
1766 | sprintf (tmpbuf, "\n"); |
… | |
… | |
1804 | { /* we got no information beyond the preamble! */ |
1810 | { /* we got no information beyond the preamble! */ |
1805 | strcat (retbuf, " [Unfortunately the rest of the information is\n"); |
1811 | strcat (retbuf, " [Unfortunately the rest of the information is\n"); |
1806 | strcat (retbuf, " hopelessly garbled!]\n ---\n"); |
1812 | strcat (retbuf, " hopelessly garbled!]\n ---\n"); |
1807 | } |
1813 | } |
1808 | #ifdef BOOK_MSG_DEBUG |
1814 | #ifdef BOOK_MSG_DEBUG |
1809 | LOG (llevDebug, "\n god_info_msg() created strng: %d\n", strlen (retbuf)); |
1815 | LOG (llevDebug, "\n god_info_msg() created string: %d\n", strlen (retbuf)); |
1810 | fprintf (logfile, " MADE THIS:\n%s", retbuf); |
1816 | LOG (llevDebug, " MADE THIS:\n%s", retbuf); |
1811 | #endif |
1817 | #endif |
1812 | return retbuf; |
1818 | return retbuf; |
1813 | } |
1819 | } |
1814 | |
1820 | |
1815 | /* tailor_readable_ob()- The main routine. This chooses a random |
1821 | /* tailor_readable_ob()- The main routine. This chooses a random |
… | |
… | |
1830 | */ |
1836 | */ |
1831 | void |
1837 | void |
1832 | tailor_readable_ob (object *book, int msg_type) |
1838 | tailor_readable_ob (object *book, int msg_type) |
1833 | { |
1839 | { |
1834 | char msgbuf[BOOK_BUF]; |
1840 | char msgbuf[BOOK_BUF]; |
1835 | int level = book->level ? (RANDOM () % book->level) + 1 : 1; |
1841 | int level = book->level ? rndm (book->level) + 1 : 1; |
1836 | int book_buf_size; |
1842 | int book_buf_size; |
1837 | |
1843 | |
1838 | /* safety */ |
1844 | /* safety */ |
1839 | if (book->type != BOOK) |
1845 | if (book->type != BOOK) |
1840 | return; |
1846 | return; |
… | |
… | |
1854 | * 2) make sure there is an entry in max_titles[] array. |
1860 | * 2) make sure there is an entry in max_titles[] array. |
1855 | * 3) make sure there are entries for your case in new_text_title() |
1861 | * 3) make sure there are entries for your case in new_text_title() |
1856 | * and add_authour(). |
1862 | * and add_authour(). |
1857 | * 4) you may want separate authour/book name arrays in read.h |
1863 | * 4) you may want separate authour/book name arrays in read.h |
1858 | */ |
1864 | */ |
1859 | msg_type = msg_type > 0 ? msg_type : (RANDOM () % 8); |
1865 | msg_type = msg_type > 0 ? msg_type : rndm (8); |
1860 | switch (msg_type) |
1866 | switch (msg_type) |
1861 | { |
1867 | { |
1862 | case 1: /* monster attrib */ |
1868 | case 1: /* monster attrib */ |
1863 | strcpy (msgbuf, mon_info_msg (level, book_buf_size)); |
1869 | strcpy (msgbuf, mon_info_msg (level, book_buf_size)); |
1864 | break; |
1870 | break; |