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

Comparing deliantra/server/common/item.C (file contents):
Revision 1.74 by root, Fri Mar 26 01:04:44 2010 UTC vs.
Revision 1.81 by root, Mon Apr 5 20:33:13 2010 UTC

47 * Note that using the term 'human' may not be very accurate, humanoid 47 * Note that using the term 'human' may not be very accurate, humanoid
48 * may be better. 48 * may be better.
49 * Basically, for the use/nonuse, the code does something like: 49 * Basically, for the use/nonuse, the code does something like:
50 * "This item goes %s\n", with the use/nonuse values filling in the %s 50 * "This item goes %s\n", with the use/nonuse values filling in the %s
51 */ 51 */
52// see include/object.h
52Body_Locations body_locations[NUM_BODY_LOCATIONS] = { 53Body_Locations body_locations[NUM_BODY_LOCATIONS] = {
53 {KW_body_skill , "You can use it as your skill" , "It is used as a skill"}, 54 {KW_body_skill , "You can use it as your skill" , "It is used as a skill"},
54 {KW_body_combat , "You can wield it as your weapon" , "It is used as a combat weapon"}, 55 {KW_body_combat , "You can wield it as your weapon" , "It is used as a combat weapon"},
55 {KW_body_range , "You can use it as your range weapon" , "It is used as a range weapon"}, 56 {KW_body_range , "You can use it as your range weapon" , "It is used as a range weapon"},
56 {KW_body_shield , "You can wield it as a shield" , "It is used as a shield"}, 57 {KW_body_shield , "You can wield it as a shield" , "It is used as a shield"},
70static char numbers_10[10][20] = { 71static char numbers_10[10][20] = {
71 "zero", "ten", "twenty", "thirty", "fourty", "fifty", "sixty", "seventy", 72 "zero", "ten", "twenty", "thirty", "fourty", "fifty", "sixty", "seventy",
72 "eighty", "ninety" 73 "eighty", "ninety"
73}; 74};
74 75
75static char levelnumbers[21][20] = { 76static char ordnumbers[21][20] = {
76 "zeroth", "first", "second", "third", "fourth", "fifth", "sixth", "seventh", 77 "zeroth", "first", "second", "third", "fourth", "fifth", "sixth", "seventh",
77 "eighth", "ninth", "tenth", "eleventh", "twelfth", "thirteenth", 78 "eighth", "ninth", "tenth", "eleventh", "twelfth", "thirteenth",
78 "fourteenth", "fifteenth", "sixteenth", "seventeenth", "eighteen", 79 "fourteenth", "fifteenth", "sixteenth", "seventeenth", "eighteenth",
79 "nineteen", "twentieth" 80 "nineteenth", "twentieth"
80}; 81};
81 82
82static char levelnumbers_10[11][20] = { 83static char ordnumbers_10[11][20] = {
83 "zeroth", "tenth", "twentieth", "thirtieth", "fortieth", "fiftieth", "sixtieth", 84 "zeroth", "tenth", "twentieth", "thirtieth", "fortieth", "fiftieth", "sixtieth",
84 "seventieth", "eightieth", "ninetieth" 85 "seventieth", "eightieth", "ninetieth"
85}; 86};
86 87
87/* The following is a large table of item types, the fields are: 88/* The following is a large table of item types, the fields are:
386/* 387/*
387 * Returns the pointer to a static buffer containing 388 * Returns the pointer to a static buffer containing
388 * the number requested (of the form first, second, third...) 389 * the number requested (of the form first, second, third...)
389 */ 390 */
390const char * 391const char *
391get_levelnumber (int i) 392ordinal (int i)
392{ 393{
393 static char buf[MAX_BUF]; 394 if (i < 0)
394 395 return format ("minus %s", ordinal (-i));
395 if (i > 99)
396 {
397 sprintf (buf, "%d.", i);
398 return buf;
399 }
400 396
401 if (i < 21) 397 if (i < 21)
402 return levelnumbers[i]; 398 return ordnumbers[i];
403 399
400 int digit = i % 10;
401
404 if (!(i % 10)) 402 if (i >= 100)
403 return format (
404 digit == 1 ? "%dst"
405 : digit == 2 ? "%dnd"
406 : digit == 3 ? "%drd"
407 : "%dth",
408 i
409 );
410
411 if (digit == 0)
405 return levelnumbers_10[i / 10]; 412 return ordnumbers_10[i / 10];
406 413 else
407 strcpy (buf, numbers_10[i / 10]); 414 return format ("%s%s", numbers_10[i / 10], ordnumbers[i % 10]);
408 strcat (buf, levelnumbers[i % 10]);
409 return buf;
410} 415}
411 416
412/* 417/*
413 * Returns pointer to static buffer containing ring's or amulet's 418 * Returns pointer to static buffer containing ring's or amulet's
414 * abilities 419 * abilities
625 { 630 {
626 case BOW: 631 case BOW:
627 case WAND: 632 case WAND:
628 case ROD: 633 case ROD:
629 case HORN: 634 case HORN:
630 buf << (op->env && op->env->current_weapon == op ? " (readied)" : " (applied)"); 635 buf << " (applied)";
631 break; 636 break;
632 case WEAPON: 637 case WEAPON:
633 buf << (op->env && op->env->current_weapon == op ? " (wielded)" : " (applied)"); 638 buf << " (applied)";
634 break; 639 break;
635 case ARMOUR: 640 case ARMOUR:
636 case HELMET: 641 case HELMET:
637 case SHIELD: 642 case SHIELD:
638 case RING: 643 case RING:
744 } 749 }
745 break; 750 break;
746 751
747 case EXIT: 752 case EXIT:
748 // random map exits "unfortunately" get patched, so this only works before entering 753 // random map exits "unfortunately" get patched, so this only works before entering
749 buf << (EXIT_PATH (op) == shstr_random_map_exit ? " (random map)" : " (exit)"); 754 if (EXIT_PATH (op) == shstr_random_map_exit)
755 buf << " (random map)";
756 else if (!EXIT_PATH (op))
757 buf << " (closed)";
750 break; 758 break;
751 759
752 default: 760 default:
753 if (op->magic && ((QUERY_FLAG (op, FLAG_BEEN_APPLIED) && need_identify (op)) || QUERY_FLAG (op, FLAG_IDENTIFIED))) 761 if (op->magic && ((QUERY_FLAG (op, FLAG_BEEN_APPLIED) && need_identify (op)) || QUERY_FLAG (op, FLAG_IDENTIFIED)))
754 buf.printf (" %+d", op->magic); 762 buf.printf (" %+d", op->magic);
944 if (op->stats.maxsp > 1000) 952 if (op->stats.maxsp > 1000)
945 { /*higher capacity crystals */ 953 { /*higher capacity crystals */
946 i = (op->stats.maxsp % 1000) / 100; 954 i = (op->stats.maxsp % 1000) / 100;
947 955
948 if (i) 956 if (i)
949 buf.printf ("(capacity %d.%dk). It is ", op->stats.maxsp / 1000, i); 957 buf.printf ("(capacity %d.%dk; it is ", op->stats.maxsp / 1000, i);
950 else 958 else
951 buf.printf ("(capacity %dk). It is ", op->stats.maxsp / 1000); 959 buf.printf ("(capacity %dk; it is ", op->stats.maxsp / 1000);
952 } 960 }
953 else 961 else
954 buf.printf ("(capacity %d). It is ", op->stats.maxsp); 962 buf.printf ("(capacity %d; it is ", op->stats.maxsp);
955 963
956 i = (op->stats.sp * 10) / op->stats.maxsp; 964 i = (op->stats.sp * 10) / op->stats.maxsp;
957 if (op->stats.sp == 0) 965 if (op->stats.sp == 0)
958 buf << "empty."; 966 buf << "empty";
959 else if (i == 0) 967 else if (i == 0)
960 buf << "almost empty."; 968 buf << "almost empty";
961 else if (i < 3) 969 else if (i < 3)
962 buf << "partially filled."; 970 buf << "partially filled";
963 else if (i < 6) 971 else if (i < 6)
964 buf << "half full."; 972 buf << "half full";
965 else if (i < 9) 973 else if (i < 9)
966 buf << "well charged."; 974 buf << "well charged";
967 else if (op->stats.sp == op->stats.maxsp) 975 else if (op->stats.sp == op->stats.maxsp)
968 buf << "fully charged."; 976 buf << "fully charged";
969 else 977 else
970 buf << "almost full."; 978 buf << "almost full";
979
980 buf << ')';
971 break; 981 break;
972 982
973 case LAMP: 983 case LAMP:
974 { 984 {
975 int percent = ((double) 100 / op->arch->stats.food) * op->stats.food; 985 int percent = ((double) 100 / op->arch->stats.food) * op->stats.food;
1175 1185
1176std::string 1186std::string
1177object::describe_item (object *who) 1187object::describe_item (object *who)
1178{ 1188{
1179 return std::string (::describe_item (this, who)); 1189 return std::string (::describe_item (this, who));
1190}
1191
1192static void
1193describe_dump_object (dynbuf &buf, object *ob)
1194{
1195 char *txt = dump_object (ob);
1196 for (char *p = txt; *p; ++p) if (*p == '\n') *p = '\r';
1197 buf << "\n" << txt << "\n";
1198
1199 if (!ob->is_arch ())
1200 describe_dump_object (buf, ob->arch);
1201}
1202
1203std::string
1204object::describe (object *who)
1205{
1206 dynbuf_text buf (1024, 1024);
1207
1208 buf.printf ("That is: %s.\r", long_desc (who).c_str ());
1209
1210 if (custom_name)
1211 buf.printf ("You call it %s.\r", &custom_name);
1212
1213 switch (type)
1214 {
1215 case SPELLBOOK:
1216 if (flag [FLAG_IDENTIFIED] && inv)
1217 buf.printf ("%s is a %s level %s spell.\r", &inv->name, ordinal (inv->level), &inv->skill);
1218 break;
1219
1220 case BOOK:
1221 if (msg)
1222 buf << "Something is written in it.\r";
1223 break;
1224
1225 case CONTAINER:
1226 if (race)
1227 {
1228 if (weight_limit && stats.Str < 100)
1229 buf.printf ("It can hold only %s and its weight limit is %.1f kg.\r",
1230 &race, weight_limit / (10.0 * (100 - stats.Str)));
1231 else
1232 buf.printf ("It can hold only %s.\r", &race);
1233 }
1234 else if (weight_limit && stats.Str < 100)
1235 buf.printf ("Its weight limit is %.1f kg.\r", weight_limit / (10.0 * (100 - stats.Str)));
1236 break;
1237
1238 case WAND:
1239 if (flag [FLAG_IDENTIFIED])
1240 buf.printf ("It has %d %s left.\r", stats.food, stats.food == 1 ? "charge" : "charges");
1241 break;
1242 }
1243
1244 if (material != MATERIAL_NULL && !msg)
1245 buf << (nrof > 1 ? "They are made of " : "It is made of ")
1246 << material->description
1247 << ".\r";
1248
1249 if (who)
1250 /* Where to wear this item */
1251 for (int i = 0; i < NUM_BODY_LOCATIONS; i++)
1252 if (slot[i].info)
1253 {
1254 buf << (who->slot[i].info ? body_locations[i].use_name : body_locations[i].nonuse_name);
1255
1256 if (slot[i].info < -1 && who->slot[i].info)
1257 buf.printf ("(%d)", -slot[i].info);
1258
1259 buf << ".\r";
1260 }
1261
1262 if (weight)
1263 buf.printf ("%s %3.3f kg.\r", nrof > 1 ? "They weigh" : "It weighs", weight * (nrof ? nrof : 1) / 1000.0);
1264
1265 if (flag [FLAG_STARTEQUIP])
1266 buf << (nrof > 1 ? "They were" : "It was")
1267 << " given by a god and will vanish when dropped.\r";
1268
1269 if (value && !flag [FLAG_STARTEQUIP] && !flag [FLAG_NO_PICK] && who)
1270 {
1271 buf.printf ("You reckon %s worth %s.\r", nrof > 1 ? "they are" : "it is", query_cost_string (this, who, F_TRUE | F_APPROX));
1272
1273 if (who->is_in_shop ())
1274 {
1275 if (flag [FLAG_UNPAID])
1276 buf.printf ("%s would cost you %s.\r", nrof > 1 ? "They" : "It", query_cost_string (this, who, F_BUY | F_SHOP));
1277 else
1278 buf.printf ("You are offered %s for %s.\r", query_cost_string (this, who, F_SELL + F_SHOP), nrof > 1 ? "them" : "it");
1279 }
1280 }
1281
1282 if (flag [FLAG_MONSTER])
1283 buf << describe_monster (who);
1284
1285 /* Is this item buildable? */
1286 if (flag [FLAG_IS_BUILDABLE])
1287 buf << "This is a buildable item.\r";
1288
1289 /* Does the object have a message? Don't show message for all object
1290 * types - especially if the first entry is a match
1291 */
1292 if (msg)
1293 {
1294 if (type != EXIT && type != BOOK && type != CORPSE && !move_on && !has_dialogue ())
1295 {
1296 buf << '\r';
1297
1298 /* This is just a hack so when identifying the items, we print
1299 * out the extra message
1300 */
1301 if (need_identify (this) && flag [FLAG_IDENTIFIED])
1302 buf << "The object has a story:\r";
1303
1304 buf << msg << '\n';
1305 }
1306 }
1307 else if (inv && inv->type == SPELL && flag [FLAG_IDENTIFIED]
1308 && (type == SPELLBOOK || type == ROD || type == WAND
1309 || type == ROD || type == POTION || type == SCROLL))
1310 // for spellbooks and other stuff that contains spells, print the spell message,
1311 // unless the object has a custom message handled above.
1312 buf << '\r' << inv->msg << '\n';
1313
1314 // try to display the duration for some potions and scrolls
1315 // this includes change ability potions and group spells,
1316 // but does not handle protection potions
1317 if (inv && inv->type == SPELL && flag [FLAG_IDENTIFIED]
1318 && (type == POTION || type == SCROLL))
1319 {
1320 object *spell = inv;
1321
1322 if (spell->subtype == SP_PARTY_SPELL)
1323 spell = spell->other_arch;
1324
1325 if (spell->subtype == SP_CHANGE_ABILITY)
1326 buf.printf ("\nH<The effect will last about %.10g seconds.>",
1327 TICK2TIME (change_ability_duration (spell, this)));
1328 }
1329
1330 // some help text for skill tools
1331 if (type == SKILL_TOOL)
1332 buf << "\nH<This item is a skill tool: as long as you have this item applied "
1333 "you can use the " << &skill << " skill as if you had learned it.>";
1334
1335 // Display a hint about inscribable items [empty books]
1336 // This includes the amount of text they can hold.
1337 if (type == INSCRIBABLE)
1338 {
1339 if (other_arch && other_arch->type == SCROLL)
1340 buf.printf ("\nH<You can use the inscription skill to inscribe a spell into it.>");
1341 else
1342 buf.printf ("\nH<You can use the inscription skill to inscribe text into it. It has room for up to %d characters.>",
1343 weight_limit);
1344 }
1345
1346 buf << '\n';
1347
1348 // the dungeon master additionally gets a complete dump
1349 if (who && who->flag [FLAG_WIZLOOK])
1350 {
1351 buf << "\nT<Object>\n";
1352 describe_dump_object (buf, this);
1353
1354 if (inv)
1355 {
1356 buf << "\nT<Top Inventory>\n";
1357 describe_dump_object (buf, inv);
1358 }
1359 }
1360
1361 return std::string (buf.linearise (), buf.size ());
1180} 1362}
1181 1363
1182void 1364void
1183examine (object *op, object *tmp) 1365examine (object *op, object *tmp)
1184{ 1366{

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines