ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/common/readable.C
(Generate patch)

Comparing deliantra/server/common/readable.C (file contents):
Revision 1.43 by root, Thu Oct 15 20:45:01 2009 UTC vs.
Revision 1.46 by root, Thu Oct 15 23:02:28 2009 UTC

1/* 1/*
2 * This file is part of Deliantra, the Roguelike Realtime MMORPG. 2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 * 3 *
4 * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team 4 * Copyright (©) 2005,2006,2007,2008,2009 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 it under 8 * Deliantra is free software: you can redistribute it and/or modify it under
9 * the terms of the Affero GNU General Public License as published by the 9 * the terms of the Affero GNU General Public License as published by the
1192static const char * 1192static const char *
1193mon_desc (const object *mon) 1193mon_desc (const object *mon)
1194{ 1194{
1195 static dynbuf_text buf; buf.clear (); 1195 static dynbuf_text buf; buf.clear ();
1196 1196
1197 buf.printf (" *** %s ***\n", &mon->name); 1197 buf.printf ("B<< %s >>\r", &mon->name);
1198 buf << describe_item (mon, 0); 1198 buf << describe_item (mon, 0);
1199 1199
1200 return buf; 1200 return buf;
1201} 1201}
1202 1202
1269 artifactlist *al = NULL; 1269 artifactlist *al = NULL;
1270 artifact *art; 1270 artifact *art;
1271 int chance, i, type, index; 1271 int chance, i, type, index;
1272 int book_entries = level > 5 ? rndm (3) + rndm (3) + 2 : rndm (level) + 1; 1272 int book_entries = level > 5 ? rndm (3) + rndm (3) + 2 : rndm (level) + 1;
1273 const char *ch; 1273 const char *ch;
1274 char name[MAX_BUF], buf[BOOK_BUF], sbuf[MAX_BUF]; 1274 char name[MAX_BUF];
1275 static char retbuf[BOOK_BUF];
1276 object *tmp = NULL; 1275 object *tmp = NULL;
1276
1277 static dynbuf_text buf; buf.clear ();
1277 1278
1278 /* values greater than 5 create msg buffers that are too big! */ 1279 /* values greater than 5 create msg buffers that are too big! */
1279 if (book_entries > 5) 1280 if (book_entries > 5)
1280 book_entries = 5; 1281 book_entries = 5;
1281 1282
1310 1311
1311 /* the base 'generic' name for our artifact */ 1312 /* the base 'generic' name for our artifact */
1312 assign (name, art_name_array[index].name); 1313 assign (name, art_name_array[index].name);
1313 1314
1314 /* Ok, lets print out the contents */ 1315 /* Ok, lets print out the contents */
1315 sprintf (retbuf, "Herein %s detailed %s...\n", book_entries > 1 ? "are" : "is", book_entries > 1 ? "some artifacts" : "an artifact"); 1316 buf.printf ("Herein %s detailed %s...\n",
1317 book_entries > 1 ? "are" : "is",
1318 book_entries > 1 ? "some artifacts" : "an artifact");
1316 1319
1317 /* artifact msg attributes loop. Lets keep adding entries to the 'book' 1320 /* artifact msg attributes loop. Lets keep adding entries to the 'book'
1318 * as long as we have space up to the allowed max # (book_entires) 1321 * as long as we have space up to the allowed max # (book_entires)
1319 */ 1322 */
1320 while (book_entries > 0) 1323 while (book_entries > 0 && buf.size () < BOOK_BUF)
1321 { 1324 {
1322 1325
1323 if (art == NULL) 1326 if (!art)
1324 art = al->items; 1327 art = al->items;
1325 1328
1326 /* separator of items */ 1329 buf << '\n';
1327 strcpy (buf, "--- \n");
1328 1330
1329 /* Name */ 1331 /* Name */
1330 if (art->allowed && art->allowed->name != shstr_All) 1332 if (art->allowed && art->allowed->name != shstr_All)
1331 { 1333 {
1332 linked_char *temp, *next = art->allowed; 1334 linked_char *temp, *next = art->allowed;
1335 { 1337 {
1336 temp = next; 1338 temp = next;
1337 next = next->next; 1339 next = next->next;
1338 } 1340 }
1339 while (next && rndm (2)); 1341 while (next && rndm (2));
1342
1340 sprintf (buf, "%s A %s of %s", buf, &temp->name, &art->item->name); 1343 buf.printf ("A B<< %s of %s >>", &temp->name, &art->item->name);
1341 } 1344 }
1342 else /* default name is used */ 1345 else /* default name is used */
1343 sprintf (buf, "%s The %s of %s", buf, name, &art->item->name); 1346 buf.printf ("The B<< %s of %s >>", name, &art->item->name);
1347
1348 buf << " is ";
1344 1349
1345 /* chance of finding */ 1350 /* chance of finding */
1346 chance = (int) (100 * ((float) art->chance / al->total_chance)); 1351 chance = (int) (100 * ((float) art->chance / al->total_chance));
1347 if (chance >= 20) 1352 if (chance >= 20)
1348 sprintf (sbuf, "an uncommon"); 1353 buf << "an uncommon";
1349 else if (chance >= 10) 1354 else if (chance >= 10)
1350 sprintf (sbuf, "an unusual"); 1355 buf << "an unusual";
1351 else if (chance >= 5) 1356 else if (chance >= 5)
1352 sprintf (sbuf, "a rare"); 1357 buf << "a rare";
1353 else 1358 else
1354 sprintf (sbuf, "a very rare"); 1359 buf << "a very rare";
1355 sprintf (buf, "%s is %s\n", buf, sbuf);
1356 1360
1357 /* value of artifact */ 1361 /* value of artifact */
1358 sprintf (buf, "%s item with a value that is %d times normal.\n", buf, art->item->value); 1362 buf << " item with a value that is " << art->item->value << " times normal.\n";
1359 1363
1360 /* include the message about the artifact, if exists, and book 1364 /* include the message about the artifact, if exists, and book
1361 * level is kinda high */ 1365 * level is kinda high */
1362 if (art->item->msg 1366 if (art->item->msg
1363 && rndm (4) + 1 < level 1367 && rndm (4) + 1 < level)
1364 && !(strlen (art->item->msg) + strlen (buf) > BOOK_BUF))
1365 strcat (buf, art->item->msg); 1368 buf << art->item->msg;
1366 1369
1367 /* properties of the artifact */ 1370 /* properties of the artifact */
1368 tmp = object::create (); 1371 tmp = object::create ();
1369 add_abilities (tmp, art->item); 1372 add_abilities (tmp, art->item);
1370 tmp->type = type; 1373 tmp->type = type;
1371 SET_FLAG (tmp, FLAG_IDENTIFIED); 1374 SET_FLAG (tmp, FLAG_IDENTIFIED);
1372 if ((ch = describe_item (tmp, NULL)) != NULL && strlen (ch) > 1) 1375 if ((ch = describe_item (tmp, 0)) && strlen (ch) > 1)
1373 sprintf (buf, "%s Properties of this artifact include: \n %s \n", buf, ch); 1376 buf << "\rProperties of this artifact include:\r" << ch << "\n";
1377
1374 tmp->destroy (); 1378 tmp->destroy ();
1375 /* add the buf if it will fit */
1376 if (!book_overflow (retbuf, buf, booksize))
1377 strcat (retbuf, buf);
1378 else
1379 break;
1380 1379
1381 art = art->next; 1380 art = art->next;
1382 book_entries--; 1381 book_entries--;
1383 } 1382 }
1384 1383
1385#ifdef BOOK_MSG_DEBUG
1386 LOG (llevDebug, "artifact_msg() created string: %d\n", strlen (retbuf));
1387 LOG (llevDebug, " MADE THIS:\n%s", retbuf);
1388#endif
1389 return retbuf; 1384 return buf;
1390} 1385}
1391 1386
1392/***************************************************************************** 1387/*****************************************************************************
1393 * Spellpath message generation 1388 * Spellpath message generation
1394 *****************************************************************************/ 1389 *****************************************************************************/
1398 * a given spellpath. 1393 * a given spellpath.
1399 */ 1394 */
1400static char * 1395static char *
1401spellpath_msg (int level, int booksize) 1396spellpath_msg (int level, int booksize)
1402{ 1397{
1398 static dynbuf_text buf; buf.clear ();
1399
1403 static char retbuf[BOOK_BUF]; 1400 static char retbuf[BOOK_BUF];
1404 char tmpbuf[BOOK_BUF]; 1401 char tmpbuf[BOOK_BUF];
1405 int path = rndm (NRSPELLPATHS), prayers = rndm (2); 1402 int path = rndm (NRSPELLPATHS), prayers = rndm (2);
1406 int did_first_sp = 0;
1407 uint32 pnum = (path == -1) ? PATH_NULL : spellpathdef[path]; 1403 uint32 pnum = (path == -1) ? PATH_NULL : spellpathdef[path];
1408 archetype *at; 1404 archetype *at;
1409 1405
1410 /* Preamble */ 1406 /* Preamble */
1411 sprintf (retbuf, "Herein are detailed the names of %s\n", prayers ? "prayers" : "incantations"); 1407 buf << "Herein are detailed the names of "
1408 << (prayers ? "prayers" : "incantations");
1412 1409
1413 if (path == -1) 1410 if (path == -1)
1414 strcat (retbuf, "having no known spell path.\n"); 1411 buf << " having no known spell path.\n";
1415 else 1412 else
1416 sprintf (retbuf, "%sbelonging to the path of %s:\n", retbuf, spellpathnames[path]); 1413 buf << " belonging to the path of B<< " << spellpathnames[path] << " >>:\n\n";
1414
1415 int seen = 0;
1417 1416
1418 for_all_archetypes (at) 1417 for_all_archetypes (at)
1419 {
1420 /* Determine if this is an appropriate spell. Must 1418 /* Determine if this is an appropriate spell. Must
1421 * be of matching path, must be of appropriate type (prayer 1419 * be of matching path, must be of appropriate type (prayer
1422 * or not), and must be within the valid level range. 1420 * or not), and must be within the valid level range.
1423 */ 1421 */
1424 if (at->type == SPELL && at->path_attuned & pnum && 1422 if (at->type == SPELL && at->path_attuned & pnum &&
1425 ((at->stats.grace && prayers) || (at->stats.sp && !prayers)) && (at->level < (level * 8))) 1423 ((at->stats.grace && prayers) || (at->stats.sp && !prayers)) && (at->level < (level * 8)))
1426 { 1424 {
1427 assign (tmpbuf, at->object::name); 1425 seen = 1;
1428 1426 buf << at->object::name << '\r';
1429 if (book_overflow (retbuf, tmpbuf, booksize))
1430 break;
1431 else
1432 {
1433 if (did_first_sp)
1434 strcat (retbuf, ",\n");
1435 did_first_sp = 1;
1436 strcat (retbuf, tmpbuf);
1437 }
1438 } 1427 }
1439 } 1428
1440 /* Geez, no spells were generated. */ 1429 /* Geez, no spells were generated. */
1441 if (!did_first_sp) 1430 if (!seen)
1442 {
1443 if (rndm (4)) /* usually, lets make a recursive call... */ 1431 if (rndm (4)) /* usually, lets make a recursive call... */
1444 spellpath_msg (level, booksize); 1432 return spellpath_msg (level, booksize);
1445 else /* give up, cause knowing no spells exist for path is info too. */ 1433 else /* give up, cause knowing no spells exist for path is info too. */
1446 strcat (retbuf, "\n - no known spells exist -\n"); 1434 buf << "- no known spells exist.\n";
1447 }
1448 else
1449 {
1450 strcat (retbuf, "\n");
1451 }
1452 1435
1453#ifdef BOOK_MSG_DEBUG
1454 LOG (llevDebug, "spellpath_msg() created string: %d\n", strlen (retbuf));
1455 LOG (llevDebug, " MADE THIS:\n%s", retbuf);
1456#endif
1457 return retbuf; 1436 return buf;
1458} 1437}
1459 1438
1460/* formula_msg() - generate a message detailing the properties 1439/* formula_msg() - generate a message detailing the properties
1461 * of a randomly selected alchemical formula. 1440 * of a randomly selected alchemical formula.
1462 */ 1441 */
1463static void 1442static void
1464make_formula_book (object *book, int level) 1443make_formula_book (object *book, int level)
1465{ 1444{
1466 char retbuf[BOOK_BUF], title[MAX_BUF]; 1445 char title[MAX_BUF];
1467 recipelist *fl; 1446 recipelist *fl;
1468 recipe *formula = NULL; 1447 recipe *formula = NULL;
1469 int chance; 1448 int chance;
1449
1450 static dynbuf_text buf; buf.clear ();
1470 1451
1471 /* the higher the book level, the more complex (ie number of 1452 /* the higher the book level, the more complex (ie number of
1472 * ingredients) the formula can be. 1453 * ingredients) the formula can be.
1473 */ 1454 */
1474 fl = get_formulalist (rndm (level) / 3 + 1); 1455 fl = get_formulalist (rndm (level) / 3 + 1);
1487 /* get a random formula, weighted by its bookchance */ 1468 /* get a random formula, weighted by its bookchance */
1488 chance = rndm (fl->total_chance); 1469 chance = rndm (fl->total_chance);
1489 for (formula = fl->items; formula; formula = formula->next) 1470 for (formula = fl->items; formula; formula = formula->next)
1490 { 1471 {
1491 chance -= formula->chance; 1472 chance -= formula->chance;
1473
1492 if (chance <= 0) 1474 if (chance <= 0)
1493 break; 1475 break;
1494 } 1476 }
1495 1477
1496 if (!formula || formula->arch_names <= 0) 1478 if (!formula || formula->arch_names <= 0)
1497 { 1479 {
1498 book->msg = "<indecipherable text>\n"; 1480 book->msg = "<indecipherable text>\n";
1499 new_text_name (book, 4); 1481 new_text_name (book, 4);
1500 add_author (book, 4); 1482 add_author (book, 4);
1501 1483 return;
1502 } 1484 }
1485
1486 /* looks like a formula was found. Base the amount
1487 * of information on the booklevel and the spellevel
1488 * of the formula. */
1489
1490 const char *op_name = formula->arch_name [rndm (formula->arch_names)];
1491 archetype *at;
1492
1493 /* preamble */
1494 buf << "Herein is described a project using B<< "
1495 << (formula->skill ? &formula->skill : "an unknown skill")
1496 << " >>:\n\n";
1497
1498 if ((at = archetype::find (op_name)))
1499 op_name = at->object::name;
1503 else 1500 else
1501 LOG (llevError, "formula_msg() can't find arch %s for formula.\n", op_name);
1502
1503 /* item name */
1504 if (formula->title != shstr_NONE)
1505 {
1506 buf.printf ("The B<< %s of %s >>", op_name, &formula->title);
1507 /* This results in things like pile of philo. sulfur.
1508 * while philo. sulfur may look better, without this,
1509 * you get things like 'the wise' because its missing the
1510 * water of section.
1511 */
1512 sprintf (title, "%s: %s of %s",
1513 formula_book_name [rndm (sizeof (formula_book_name) / sizeof (char *))], op_name, &formula->title);
1504 { 1514 }
1505 /* looks like a formula was found. Base the amount 1515 else
1506 * of information on the booklevel and the spellevel 1516 {
1507 * of the formula. */ 1517 buf << "The B<< " << op_name;
1508 1518
1509 const char *op_name = formula->arch_name [rndm (formula->arch_names)]; 1519 sprintf (title, "%s: %s", formula_book_name [rndm (sizeof (formula_book_name) / sizeof (char *))], op_name);
1520 if (at->title)
1521 {
1522 buf << " " << at->title;
1523 strcat (title, " ");
1524 strcat (title, at->title);
1525 }
1526
1527 buf << " >>";
1528 }
1529
1530 /* Lets name the book something meaningful ! */
1531 book->name = title;
1532 book->title = NULL;
1533
1534 /* ingredients to make it */
1535 if (formula->ingred)
1536 {
1537 linked_char *next;
1510 archetype *at; 1538 archetype *at;
1511 1539
1512 /* preamble */
1513 sprintf (retbuf, "Herein is described a project using %s: \n", formula->skill ? &formula->skill : "an unknown skill");
1514
1515 if ((at = archetype::find (op_name)) != (archetype *) NULL)
1516 op_name = at->object::name;
1517 else
1518 LOG (llevError, "formula_msg() can't find arch %s for formula.\n", op_name);
1519
1520 /* item name */
1521 if (formula->title != shstr_NONE)
1522 {
1523 sprintf (retbuf, "%sThe %s of %s", retbuf, op_name, &formula->title);
1524 /* This results in things like pile of philo. sulfur.
1525 * while philo. sulfur may look better, without this,
1526 * you get things like 'the wise' because its missing the
1527 * water of section.
1528 */
1529 sprintf (title, "%s: %s of %s",
1530 formula_book_name [rndm (sizeof (formula_book_name) / sizeof (char *))], op_name, &formula->title);
1531 }
1532 else
1533 {
1534 sprintf (retbuf, "%sThe %s", retbuf, op_name);
1535 sprintf (title, "%s: %s", formula_book_name [rndm (sizeof (formula_book_name) / sizeof (char *))], op_name);
1536 if (at->title)
1537 {
1538 strcat (retbuf, " ");
1539 strcat (retbuf, at->title);
1540 strcat (title, " ");
1541 strcat (title, at->title);
1542 }
1543 }
1544
1545 /* Lets name the book something meaningful ! */
1546 book->name = title;
1547 book->title = NULL;
1548
1549 /* ingredients to make it */
1550 if (formula->ingred != NULL)
1551 {
1552 linked_char *next;
1553 archetype *at;
1554
1555 at = archetype::find (formula->cauldron); 1540 at = archetype::find (formula->cauldron);
1556 1541
1557 sprintf (retbuf + strlen (retbuf), 1542 buf.printf (" may be made at %s using the following ingredients:\n\n",
1558 " may be made at %s using the following ingredients:\n", at ? query_name (at) : "an unknown place"); 1543 at ? query_name (at) : "an appropriate place");
1559 1544
1560 for (next = formula->ingred; next != NULL; next = next->next) 1545 for (next = formula->ingred; next; next = next->next)
1561 { 1546 buf << next->name << '\r';
1562 strcat (retbuf, next->name); 1547 }
1563 strcat (retbuf, "\n");
1564 }
1565 }
1566 else 1548 else
1567 LOG (llevError, "formula_msg() no ingredient list for object %s of %s\n", op_name, &formula->title); 1549 LOG (llevError, "formula_msg() no ingredient list for object %s of %s\n", op_name, &formula->title);
1568 if (retbuf[strlen (retbuf) - 1] != '\n')
1569 strcat (retbuf, "\n");
1570 1550
1571 book->msg = retbuf; 1551 book->msg = buf;
1572 }
1573} 1552}
1574 1553
1575#define DESCRIBE_PATH(retbuf, variable, name) \ 1554#define DESCRIBE_PATH(retbuf, variable, name) \
1576 if(variable) { \ 1555 if(variable) { \
1577 int i,j=0; \ 1556 int i,j=0; \
1836 * 3) make sure there are entries for your case in new_text_title() 1815 * 3) make sure there are entries for your case in new_text_title()
1837 * and add_authour(). 1816 * and add_authour().
1838 * 4) you may want separate authour/book name arrays in read.h 1817 * 4) you may want separate authour/book name arrays in read.h
1839 */ 1818 */
1840 msg_type = msg_type > 0 ? msg_type : rndm (8); 1819 msg_type = msg_type > 0 ? msg_type : rndm (8);
1841 switch (msg_type) 1820 switch (msg_type*0+4)//D
1842 { 1821 {
1843 case 1: /* monster attrib */ 1822 case 1: /* monster attrib */
1844 strcpy (msgbuf, mon_info_msg (level, book_buf_size)); 1823 strcpy (msgbuf, mon_info_msg (level, book_buf_size));
1845 break; 1824 break;
1846 case 2: /* artifact attrib */ 1825 case 2: /* artifact attrib */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines