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.51 by root, Sun Sep 7 21:31:23 2008 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 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.
298 if (op->type == WEAPON) 299 if (op->type == WEAPON)
299 { 300 {
300 for (i = 1; i < NROFATTACKS; i++) 301 for (i = 1; i < NROFATTACKS; i++)
301 if (op->attacktype & (1 << i)) 302 if (op->attacktype & (1 << i))
302 enc++; 303 enc++;
304
303 if (op->slaying) 305 if (op->slaying)
304 enc += 2; /* What it slays is probably more relevent */ 306 enc += 2; /* What it slays is probably more relevent */
305 } 307 }
308
306 /* Items the player can equip */ 309 /* Items the player can equip */
307 if ((op->type == WEAPON) || (op->type == ARMOUR) || (op->type == HELMET) || 310 if ((op->type == WEAPON) || (op->type == ARMOUR) || (op->type == HELMET) ||
308 (op->type == SHIELD) || (op->type == RING) || 311 (op->type == SHIELD) || (op->type == RING) ||
309 (op->type == BOOTS) || (op->type == GLOVES) || 312 (op->type == BOOTS) || (op->type == GLOVES) ||
310 (op->type == AMULET) || (op->type == GIRDLE) || (op->type == BRACERS) || (op->type == CLOAK)) 313 (op->type == AMULET) || (op->type == GIRDLE) || (op->type == BRACERS) || (op->type == CLOAK))
313 enc += op->stats.hp; /* hp regen */ 316 enc += op->stats.hp; /* hp regen */
314 enc += op->stats.sp; /* mana regen */ 317 enc += op->stats.sp; /* mana regen */
315 enc += op->stats.grace; /* grace regen */ 318 enc += op->stats.grace; /* grace regen */
316 enc += op->stats.exp; /* speed bonus */ 319 enc += op->stats.exp; /* speed bonus */
317 } 320 }
321
318 enc += op->stats.luck; 322 enc += op->stats.luck;
319 323
320 /* Do spell paths now */ 324 /* Do spell paths now */
321 for (i = 1; i < NRSPELLPATHS; i++) 325 for (i = 1; i < NRSPELLPATHS; i++)
322 { 326 {
354 int i; 358 int i;
355 359
356 for (i = 0; i < item_types_size; i++) 360 for (i = 0; i < item_types_size; i++)
357 if (item_types[i].number == itemtype) 361 if (item_types[i].number == itemtype)
358 return &item_types[i]; 362 return &item_types[i];
363
359 return NULL; 364 return NULL;
360} 365}
361 366
362/* returns the typedata that has a name equal to itemtype, if there 367/* 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 368 * isn't one, return the plural name that matches, if there still isn't
368 int i; 373 int i;
369 374
370 for (i = 0; i < item_types_size; i++) 375 for (i = 0; i < item_types_size; i++)
371 if (!strcmp (item_types[i].name, name)) 376 if (!strcmp (item_types[i].name, name))
372 return &item_types[i]; 377 return &item_types[i];
378
373 for (i = 0; i < item_types_size; i++) 379 for (i = 0; i < item_types_size; i++)
374 if (!strcmp (item_types[i].name_pl, name)) 380 if (!strcmp (item_types[i].name_pl, name))
375 { 381 {
376 LOG (llevInfo, 382 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); 383 "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]; 384 return &item_types[i];
379 } 385 }
386
380 return NULL; 387 return NULL;
381} 388}
382 389
383/* describe_resistance generates the visible naming for resistances. 390/* describe_resistance generates the visible naming for resistances.
384 * returns a static array of the description. This can return 391 * returns a static array of the description. This can return
417 */ 424 */
418const char * 425const char *
419query_weight (const object *op) 426query_weight (const object *op)
420{ 427{
421 static char buf[10]; 428 static char buf[10];
422 sint32 i = (op->nrof ? op->nrof : 1) * op->weight + op->carrying; 429 sint32 i = op->total_weight ();
423 430
424 if (op->weight < 0) 431 if (op->weight < 0)
425 return " "; 432 return " ";
426 433
427 if (i % 1000) 434 if (i % 1000)
536 * contain any information about object status (worn/cursed/etc.) 543 * contain any information about object status (worn/cursed/etc.)
537 */ 544 */
538const char * 545const char *
539query_short_name (const object *op) 546query_short_name (const object *op)
540{ 547{
548 if (op->name == 0)
549 return "(null)";
550
551 if (!op->nrof
552 && !op->weight
553 && !op->title
554 && !is_magical (op)
555 && op->slaying != shstr_money)
556 return op->name; /* To speed things up (or make things slower?) */
557
541 static dynbuf_text buf; buf.clear (); 558 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 559
549 buf << (op->nrof <= 1 ? op->name : op->name_pl); 560 buf << (op->nrof <= 1 ? op->name : op->name_pl);
550 561
551 if (op->title && QUERY_FLAG (op, FLAG_IDENTIFIED)) 562 if (op->title && QUERY_FLAG (op, FLAG_IDENTIFIED))
552 buf << ' ' << op->title; 563 buf << ' ' << op->title;
565 if (op->type != SPELLBOOK) 576 if (op->type != SPELLBOOK)
566 buf.printf (" (lvl %d)", op->level); 577 buf.printf (" (lvl %d)", op->level);
567 } 578 }
568 break; 579 break;
569 580
581 case ALTAR:
582 case TRIGGER_ALTAR:
583 case IDENTIFY_ALTAR:
584 case CONVERTER:
585 if (op->slaying == shstr_money)
586 {
587 bool wrap = !!buf.size ();
588
589 if (wrap) buf << " [";
590
591 archetype *coin = 0;
592
593 for (char const *const *c = coins; *coins; ++c)
594 if ((coin = archetype::find (*c)))
595 if (op->stats.food % coin->value == 0)
596 break;
597
598 sint32 coins = op->stats.food / coin->value;
599
600 buf.printf ("drop %d %s (or equivalent)", coins, coins == 1 ? &coin->name : &coin->name_pl);
601
602 if (wrap) buf << ']';
603 }
604 break;
605
570 case SKILL: 606 case SKILL:
571 case AMULET: 607 case AMULET:
572 case RING: 608 case RING:
573 if (!op->title) 609 if (!op->title)
574 { 610 {
577 613
578 if (s && *s) 614 if (s && *s)
579 buf << " " << s; 615 buf << " " << s;
580 } 616 }
581 break; 617 break;
618
582 default: 619 default:
583 if (op->magic && ((QUERY_FLAG (op, FLAG_BEEN_APPLIED) && need_identify (op)) || QUERY_FLAG (op, FLAG_IDENTIFIED))) 620 if (op->magic && ((QUERY_FLAG (op, FLAG_BEEN_APPLIED) && need_identify (op)) || QUERY_FLAG (op, FLAG_IDENTIFIED)))
584 buf.printf (" %+d", op->magic); 621 buf.printf (" %+d", op->magic);
585 } 622 }
586 623
776 */ 813 */
777 if (op->has_active_speed ()) 814 if (op->has_active_speed ())
778 switch ((int) ((FABS (op->speed)) * 15)) 815 switch ((int) ((FABS (op->speed)) * 15))
779 { 816 {
780 case 0: 817 case 0:
781 buf << "(very slow movement"; 818 buf << "(very slow movement)";
782 break; 819 break;
783 case 1: 820 case 1:
784 buf << "(slow movement)"; 821 buf << "(slow movement)";
785 break; 822 break;
786 case 2: 823 case 2:
1162} 1199}
1163 1200
1164void 1201void
1165examine (object *op, object *tmp) 1202examine (object *op, object *tmp)
1166{ 1203{
1167 std::string s = tmp->describe (op); 1204 std::string info = tmp->describe (op);
1168 1205 op->contr->infobox (MSG_CHANNEL ("examine"), info.c_str ());
1169 new_draw_info (NDI_UNIQUE, 0, op, s.c_str ());
1170} 1206}
1171 1207
1172/* 1208/*
1173 * inventory prints object's inventory. If inv==NULL then print player's 1209 * inventory prints object's inventory. If inv==NULL then print player's
1174 * inventory. 1210 * inventory.
1326 * Supposed to fix face-values as well here, but later. 1362 * Supposed to fix face-values as well here, but later.
1327 */ 1363 */
1328void 1364void
1329identify (object *op) 1365identify (object *op)
1330{ 1366{
1331 object *pl;
1332
1333 SET_FLAG (op, FLAG_IDENTIFIED); 1367 SET_FLAG (op, FLAG_IDENTIFIED);
1334 CLEAR_FLAG (op, FLAG_KNOWN_MAGICAL); 1368 CLEAR_FLAG (op, FLAG_KNOWN_MAGICAL);
1335 CLEAR_FLAG (op, FLAG_NO_SKILL_IDENT); 1369 CLEAR_FLAG (op, FLAG_NO_SKILL_IDENT);
1336 1370
1337 /* 1371 /*
1344 { 1378 {
1345 if (op->inv && op->randomitems) 1379 if (op->inv && op->randomitems)
1346 op->title = op->inv->name; 1380 op->title = op->inv->name;
1347 else if (op->arch) 1381 else if (op->arch)
1348 { 1382 {
1349 op->name = op->arch->object::name; 1383 op->name = op->arch->object::name;
1350 op->name_pl = op->arch->object::name_pl; 1384 op->name_pl = op->arch->object::name_pl;
1351 } 1385 }
1352 } 1386 }
1353 1387
1354 /* If the object is on a map, make sure we update its face */ 1388 /* If the object is on a map, make sure we update its face */
1355 if (op->map) 1389 if (op->map)
1356 update_object (op, UP_OBJ_CHANGE); 1390 update_object (op, UP_OBJ_CHANGE);
1357 else 1391
1358 { 1392 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 1393 /* A lot of the values can change from an update - might as well send
1362 * it all. 1394 * it all.
1363 */ 1395 */
1364 esrv_send_item (pl, op); 1396 esrv_send_item (pl, op);
1365 }
1366} 1397}
1367 1398

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines