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.41 by root, Thu Nov 8 19:43:23 2007 UTC vs.
Revision 1.54 by elmex, Mon Jan 12 00:17:22 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 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 8 * Deliantra is free software: you can redistribute it and/or modify
9 * 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
20 * 20 *
21 * The authors can be reached via e-mail to <support@deliantra.net> 21 * The authors can be reached via e-mail to <support@deliantra.net>
22 */ 22 */
23 23
24#include <global.h> 24#include <global.h>
25#include <funcpoint.h>
26#include <living.h> 25#include <living.h>
27#include <spells.h> 26#include <spells.h>
27
28const char *const coins[NUM_COINS + 1] = { "royalty", "platinacoin", "goldcoin", "silvercoin", 0 };
28 29
29/* the ordering of this is actually doesn't make a difference 30/* the ordering of this is actually doesn't make a difference
30 * However, for ease of use, new entries should go at the end 31 * However, for ease of use, new entries should go at the end
31 * so those people that debug the code that get used to something 32 * so those people that debug the code that get used to something
32 * being in the location 4 don't get confused. 33 * being in the location 4 don't get confused.
251}; 252};
252 253
253int 254int
254get_power_from_ench (int ench) 255get_power_from_ench (int ench)
255{ 256{
256 if (ench < 0) ench = 0;
257 if (ench > 20) ench = 20;
258
259 return enc_to_item_power[ench]; 257 return enc_to_item_power [clamp (ench, 0, 20)];
260} 258}
261 259
262/* This takes an object 'op' and figures out what its item_power 260/* This takes an object 'op' and figures out what its item_power
263 * rating should be. This should only really be used by the treasure 261 * rating should be. This should only really be used by the treasure
264 * generation code, and when loading legacy objects. It returns 262 * generation code, and when loading legacy objects. It returns
298 if (op->type == WEAPON) 296 if (op->type == WEAPON)
299 { 297 {
300 for (i = 1; i < NROFATTACKS; i++) 298 for (i = 1; i < NROFATTACKS; i++)
301 if (op->attacktype & (1 << i)) 299 if (op->attacktype & (1 << i))
302 enc++; 300 enc++;
301
303 if (op->slaying) 302 if (op->slaying)
304 enc += 2; /* What it slays is probably more relevent */ 303 enc += 2; /* What it slays is probably more relevent */
305 } 304 }
305
306 /* Items the player can equip */ 306 /* Items the player can equip */
307 if ((op->type == WEAPON) || (op->type == ARMOUR) || (op->type == HELMET) || 307 if ((op->type == WEAPON) || (op->type == ARMOUR) || (op->type == HELMET) ||
308 (op->type == SHIELD) || (op->type == RING) || 308 (op->type == SHIELD) || (op->type == RING) ||
309 (op->type == BOOTS) || (op->type == GLOVES) || 309 (op->type == BOOTS) || (op->type == GLOVES) ||
310 (op->type == AMULET) || (op->type == GIRDLE) || (op->type == BRACERS) || (op->type == CLOAK)) 310 (op->type == AMULET) || (op->type == GIRDLE) || (op->type == BRACERS) || (op->type == CLOAK))
313 enc += op->stats.hp; /* hp regen */ 313 enc += op->stats.hp; /* hp regen */
314 enc += op->stats.sp; /* mana regen */ 314 enc += op->stats.sp; /* mana regen */
315 enc += op->stats.grace; /* grace regen */ 315 enc += op->stats.grace; /* grace regen */
316 enc += op->stats.exp; /* speed bonus */ 316 enc += op->stats.exp; /* speed bonus */
317 } 317 }
318
318 enc += op->stats.luck; 319 enc += op->stats.luck;
319 320
320 /* Do spell paths now */ 321 /* Do spell paths now */
321 for (i = 1; i < NRSPELLPATHS; i++) 322 for (i = 1; i < NRSPELLPATHS; i++)
322 { 323 {
354 int i; 355 int i;
355 356
356 for (i = 0; i < item_types_size; i++) 357 for (i = 0; i < item_types_size; i++)
357 if (item_types[i].number == itemtype) 358 if (item_types[i].number == itemtype)
358 return &item_types[i]; 359 return &item_types[i];
360
359 return NULL; 361 return NULL;
360} 362}
361 363
362/* returns the typedata that has a name equal to itemtype, if there 364/* returns the typedata that has a name equal to itemtype, if there
363 * isn't one, return the plural name that matches, if there still isn't 365 * isn't one, return the plural name that matches, if there still isn't
368 int i; 370 int i;
369 371
370 for (i = 0; i < item_types_size; i++) 372 for (i = 0; i < item_types_size; i++)
371 if (!strcmp (item_types[i].name, name)) 373 if (!strcmp (item_types[i].name, name))
372 return &item_types[i]; 374 return &item_types[i];
375
373 for (i = 0; i < item_types_size; i++) 376 for (i = 0; i < item_types_size; i++)
374 if (!strcmp (item_types[i].name_pl, name)) 377 if (!strcmp (item_types[i].name_pl, name))
375 { 378 {
376 LOG (llevInfo, 379 LOG (llevInfo,
377 "get_typedata_by_name: I have been sent the plural %s, the singular form %s is preffered\n", name, item_types[i].name); 380 "get_typedata_by_name: I have been sent the plural %s, the singular form %s is prefered\n", name, item_types[i].name);
378 return &item_types[i]; 381 return &item_types[i];
379 } 382 }
383
380 return NULL; 384 return NULL;
381} 385}
382 386
383/* describe_resistance generates the visible naming for resistances. 387/* describe_resistance generates the visible naming for resistances.
384 * returns a static array of the description. This can return 388 * returns a static array of the description. This can return
417 */ 421 */
418const char * 422const char *
419query_weight (const object *op) 423query_weight (const object *op)
420{ 424{
421 static char buf[10]; 425 static char buf[10];
422 sint32 i = (op->nrof ? op->nrof : 1) * op->weight + op->carrying; 426 sint32 i = op->total_weight ();
423 427
424 if (op->weight < 0) 428 if (op->weight < 0)
425 return " "; 429 return " ";
426 430
427 if (i % 1000) 431 if (i % 1000)
536 * contain any information about object status (worn/cursed/etc.) 540 * contain any information about object status (worn/cursed/etc.)
537 */ 541 */
538const char * 542const char *
539query_short_name (const object *op) 543query_short_name (const object *op)
540{ 544{
545 if (!op->name)
546 return "(null)";
547
548 if (!op->nrof
549 && !op->weight
550 && !op->title
551 && !is_magical (op)
552 && op->slaying != shstr_money)
553 return op->name; /* To speed things up (or make things slower?) */
554
541 static dynbuf_text buf; buf.clear (); 555 static dynbuf_text buf; buf.clear ();
542
543 if (op->name == NULL)
544 return "(null)";
545
546 if (!op->nrof && !op->weight && !op->title && !is_magical (op))
547 return op->name; /* To speed things up (or make things slower?) */
548 556
549 buf << (op->nrof <= 1 ? op->name : op->name_pl); 557 buf << (op->nrof <= 1 ? op->name : op->name_pl);
550 558
551 if (op->title && QUERY_FLAG (op, FLAG_IDENTIFIED)) 559 if (op->title && QUERY_FLAG (op, FLAG_IDENTIFIED))
552 buf << ' ' << op->title; 560 buf << ' ' << op->title;
565 if (op->type != SPELLBOOK) 573 if (op->type != SPELLBOOK)
566 buf.printf (" (lvl %d)", op->level); 574 buf.printf (" (lvl %d)", op->level);
567 } 575 }
568 break; 576 break;
569 577
578 case ALTAR:
579 case TRIGGER_ALTAR:
580 case IDENTIFY_ALTAR:
581 case CONVERTER:
582 if (op->slaying == shstr_money)
583 {
584 bool wrap = !!buf.size ();
585
586 if (wrap) buf << " [";
587
588 archetype *coin = 0;
589
590 for (char const *const *c = coins; *coins; ++c)
591 if ((coin = archetype::find (*c)))
592 if (op->stats.food % coin->value == 0)
593 break;
594
595 sint32 coins = op->stats.food / coin->value;
596
597 buf.printf ("drop %d %s (or equivalent)", coins, coins == 1 ? &coin->name : &coin->name_pl);
598
599 if (wrap) buf << ']';
600 }
601 break;
602
570 case SKILL: 603 case SKILL:
571 case AMULET: 604 case AMULET:
572 case RING: 605 case RING:
573 if (!op->title) 606 if (!op->title)
574 { 607 {
577 610
578 if (s && *s) 611 if (s && *s)
579 buf << " " << s; 612 buf << " " << s;
580 } 613 }
581 break; 614 break;
615
582 default: 616 default:
583 if (op->magic && ((QUERY_FLAG (op, FLAG_BEEN_APPLIED) && need_identify (op)) || QUERY_FLAG (op, FLAG_IDENTIFIED))) 617 if (op->magic && ((QUERY_FLAG (op, FLAG_BEEN_APPLIED) && need_identify (op)) || QUERY_FLAG (op, FLAG_IDENTIFIED)))
584 buf.printf (" %+d", op->magic); 618 buf.printf (" %+d", op->magic);
585 } 619 }
586 620
683 default: 717 default:
684 buf << " (applied)"; 718 buf << " (applied)";
685 } 719 }
686 } 720 }
687 721
722 switch (op->type)
723 {
724 case LAMP:
725 if (op->glow_radius)
726 buf << " (on)";
727 else if (op->stats.food <= 0)
728 buf << " (empty)";
729 else
730 buf << " (off)";
731 break;
732
733 case TORCH:
734 if (op->glow_radius)
735 buf << " (burning)";
736 else if (op->stats.food <= 0)
737 buf << " (burned out)";
738 break;
739 }
740
688 if (QUERY_FLAG (op, FLAG_UNPAID)) 741 if (QUERY_FLAG (op, FLAG_UNPAID))
689 buf << " (unpaid)"; 742 buf << " (unpaid)";
690 743
691 return buf; 744 return buf;
692} 745}
776 */ 829 */
777 if (op->has_active_speed ()) 830 if (op->has_active_speed ())
778 switch ((int) ((FABS (op->speed)) * 15)) 831 switch ((int) ((FABS (op->speed)) * 15))
779 { 832 {
780 case 0: 833 case 0:
781 buf << "(very slow movement"; 834 buf << "(very slow movement)";
782 break; 835 break;
783 case 1: 836 case 1:
784 buf << "(slow movement)"; 837 buf << "(slow movement)";
785 break; 838 break;
786 case 2: 839 case 2:
975 buf << "fully charged."; 1028 buf << "fully charged.";
976 else 1029 else
977 buf << "almost full."; 1030 buf << "almost full.";
978 break; 1031 break;
979 1032
1033 case LAMP:
1034 {
1035 int percent = ((double) 100 / op->arch->stats.food) * op->stats.food;
1036 buf << "(fuel: ";
1037 if (percent == 0)
1038 buf << "empty";
1039 else if (percent < 10)
1040 buf << "very low";
1041 else if (percent < 25)
1042 buf << "low";
1043 else if (percent < 50)
1044 buf << "half empty";
1045 else if (percent < 75)
1046 buf << "half full";
1047 else if (percent < 95)
1048 buf << "well filled";
1049 else if (percent <= 100)
1050 buf << "full";
1051 buf << ")";
1052 }
1053 break;
1054
980 case FOOD: 1055 case FOOD:
981 case FLESH: 1056 case FLESH:
982 case DRINK: 1057 case DRINK:
983 if (identified || QUERY_FLAG (op, FLAG_BEEN_APPLIED)) 1058 if (identified || QUERY_FLAG (op, FLAG_BEEN_APPLIED))
984 { 1059 {
1162} 1237}
1163 1238
1164void 1239void
1165examine (object *op, object *tmp) 1240examine (object *op, object *tmp)
1166{ 1241{
1167 std::string s = tmp->describe (op); 1242 std::string info = tmp->describe (op);
1168 1243 op->contr->infobox (MSG_CHANNEL ("examine"), info.c_str ());
1169 new_draw_info (NDI_UNIQUE, 0, op, s.c_str ());
1170} 1244}
1171 1245
1172/* 1246/*
1173 * inventory prints object's inventory. If inv==NULL then print player's 1247 * inventory prints object's inventory. If inv==NULL then print player's
1174 * inventory. 1248 * inventory.
1179{ 1253{
1180 static dynbuf_text buf; buf.clear (); 1254 static dynbuf_text buf; buf.clear ();
1181 1255
1182 for (object *tmp = inv; tmp; tmp = tmp->below) 1256 for (object *tmp = inv; tmp; tmp = tmp->below)
1183 if (who && QUERY_FLAG (who, FLAG_WIZ)) 1257 if (who && QUERY_FLAG (who, FLAG_WIZ))
1184 buf.printf ("%s- %-28.28s (%5d) %-8s\n", indent, query_name (tmp), tmp->count, query_weight (tmp)); 1258 buf.printf ("%s- %-28.28s (%5d) %-8s\n", indent, tmp->query_name (), tmp->count, tmp->query_weight ());
1185 else if (!tmp->invisible && (type == CONTAINER || QUERY_FLAG (tmp, FLAG_APPLIED))) 1259 else if (!tmp->invisible && (type == CONTAINER || QUERY_FLAG (tmp, FLAG_APPLIED)))
1186 buf.printf ("%s- %-36.36s %-8s\n", indent, query_name (tmp), query_weight (tmp)); 1260 buf.printf ("%s- %-36.36s %-8s\n", indent, tmp->query_name (), tmp->query_weight ());
1187 1261
1188 if (buf.size ()) 1262 if (buf.size ())
1189 buf.printf ("%s(total weight: %s)\n", indent, query_weight (this)); 1263 buf.printf ("%s(total weight: %s)\n", indent, query_weight ());
1190 else 1264 else
1191 buf.printf ("%s(empty)\n", indent); 1265 buf.printf ("%s(empty)\n", indent);
1192 1266
1193 return buf; 1267 return buf;
1194} 1268}
1326 * Supposed to fix face-values as well here, but later. 1400 * Supposed to fix face-values as well here, but later.
1327 */ 1401 */
1328void 1402void
1329identify (object *op) 1403identify (object *op)
1330{ 1404{
1331 object *pl;
1332
1333 SET_FLAG (op, FLAG_IDENTIFIED); 1405 SET_FLAG (op, FLAG_IDENTIFIED);
1334 CLEAR_FLAG (op, FLAG_KNOWN_MAGICAL); 1406 CLEAR_FLAG (op, FLAG_KNOWN_MAGICAL);
1335 CLEAR_FLAG (op, FLAG_NO_SKILL_IDENT); 1407 CLEAR_FLAG (op, FLAG_NO_SKILL_IDENT);
1336 1408
1337 /* 1409 /*
1344 { 1416 {
1345 if (op->inv && op->randomitems) 1417 if (op->inv && op->randomitems)
1346 op->title = op->inv->name; 1418 op->title = op->inv->name;
1347 else if (op->arch) 1419 else if (op->arch)
1348 { 1420 {
1349 op->name = op->arch->object::name; 1421 op->name = op->arch->object::name;
1350 op->name_pl = op->arch->object::name_pl; 1422 op->name_pl = op->arch->object::name_pl;
1351 } 1423 }
1352 } 1424 }
1353 1425
1354 /* If the object is on a map, make sure we update its face */ 1426 /* If the object is on a map, make sure we update its face */
1355 if (op->map) 1427 if (op->map)
1356 update_object (op, UP_OBJ_CHANGE); 1428 update_object (op, UP_OBJ_CHANGE);
1357 else 1429
1358 { 1430 if (object *pl = op->visible_to ())
1359 pl = op->in_player ();
1360 if (pl)
1361 /* A lot of the values can change from an update - might as well send 1431 /* A lot of the values can change from an update - might as well send
1362 * it all. 1432 * it all.
1363 */ 1433 */
1364 esrv_send_item (pl, op); 1434 esrv_send_item (pl, op);
1365 }
1366} 1435}
1367 1436

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines