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.53 by root, Sun Jan 11 06:08:40 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
776 */ 810 */
777 if (op->has_active_speed ()) 811 if (op->has_active_speed ())
778 switch ((int) ((FABS (op->speed)) * 15)) 812 switch ((int) ((FABS (op->speed)) * 15))
779 { 813 {
780 case 0: 814 case 0:
781 buf << "(very slow movement"; 815 buf << "(very slow movement)";
782 break; 816 break;
783 case 1: 817 case 1:
784 buf << "(slow movement)"; 818 buf << "(slow movement)";
785 break; 819 break;
786 case 2: 820 case 2:
1162} 1196}
1163 1197
1164void 1198void
1165examine (object *op, object *tmp) 1199examine (object *op, object *tmp)
1166{ 1200{
1167 std::string s = tmp->describe (op); 1201 std::string info = tmp->describe (op);
1168 1202 op->contr->infobox (MSG_CHANNEL ("examine"), info.c_str ());
1169 new_draw_info (NDI_UNIQUE, 0, op, s.c_str ());
1170} 1203}
1171 1204
1172/* 1205/*
1173 * inventory prints object's inventory. If inv==NULL then print player's 1206 * inventory prints object's inventory. If inv==NULL then print player's
1174 * inventory. 1207 * inventory.
1179{ 1212{
1180 static dynbuf_text buf; buf.clear (); 1213 static dynbuf_text buf; buf.clear ();
1181 1214
1182 for (object *tmp = inv; tmp; tmp = tmp->below) 1215 for (object *tmp = inv; tmp; tmp = tmp->below)
1183 if (who && QUERY_FLAG (who, FLAG_WIZ)) 1216 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)); 1217 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))) 1218 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)); 1219 buf.printf ("%s- %-36.36s %-8s\n", indent, tmp->query_name (), tmp->query_weight ());
1187 1220
1188 if (buf.size ()) 1221 if (buf.size ())
1189 buf.printf ("%s(total weight: %s)\n", indent, query_weight (this)); 1222 buf.printf ("%s(total weight: %s)\n", indent, query_weight ());
1190 else 1223 else
1191 buf.printf ("%s(empty)\n", indent); 1224 buf.printf ("%s(empty)\n", indent);
1192 1225
1193 return buf; 1226 return buf;
1194} 1227}
1326 * Supposed to fix face-values as well here, but later. 1359 * Supposed to fix face-values as well here, but later.
1327 */ 1360 */
1328void 1361void
1329identify (object *op) 1362identify (object *op)
1330{ 1363{
1331 object *pl;
1332
1333 SET_FLAG (op, FLAG_IDENTIFIED); 1364 SET_FLAG (op, FLAG_IDENTIFIED);
1334 CLEAR_FLAG (op, FLAG_KNOWN_MAGICAL); 1365 CLEAR_FLAG (op, FLAG_KNOWN_MAGICAL);
1335 CLEAR_FLAG (op, FLAG_NO_SKILL_IDENT); 1366 CLEAR_FLAG (op, FLAG_NO_SKILL_IDENT);
1336 1367
1337 /* 1368 /*
1344 { 1375 {
1345 if (op->inv && op->randomitems) 1376 if (op->inv && op->randomitems)
1346 op->title = op->inv->name; 1377 op->title = op->inv->name;
1347 else if (op->arch) 1378 else if (op->arch)
1348 { 1379 {
1349 op->name = op->arch->object::name; 1380 op->name = op->arch->object::name;
1350 op->name_pl = op->arch->object::name_pl; 1381 op->name_pl = op->arch->object::name_pl;
1351 } 1382 }
1352 } 1383 }
1353 1384
1354 /* If the object is on a map, make sure we update its face */ 1385 /* If the object is on a map, make sure we update its face */
1355 if (op->map) 1386 if (op->map)
1356 update_object (op, UP_OBJ_CHANGE); 1387 update_object (op, UP_OBJ_CHANGE);
1357 else 1388
1358 { 1389 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 1390 /* A lot of the values can change from an update - might as well send
1362 * it all. 1391 * it all.
1363 */ 1392 */
1364 esrv_send_item (pl, op); 1393 esrv_send_item (pl, op);
1365 }
1366} 1394}
1367 1395

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines