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.46 by root, Sun Apr 20 22:03:21 2008 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>
28 27
29const char *const coins[NUM_COINS + 1] = { "royalty", "platinacoin", "goldcoin", "silvercoin", 0 }; 28const char *const coins[NUM_COINS + 1] = { "royalty", "platinacoin", "goldcoin", "silvercoin", 0 };
30 29
253}; 252};
254 253
255int 254int
256get_power_from_ench (int ench) 255get_power_from_ench (int ench)
257{ 256{
258 if (ench < 0) ench = 0;
259 if (ench > 20) ench = 20;
260
261 return enc_to_item_power[ench]; 257 return enc_to_item_power [clamp (ench, 0, 20)];
262} 258}
263 259
264/* 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
265 * 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
266 * generation code, and when loading legacy objects. It returns 262 * generation code, and when loading legacy objects. It returns
300 if (op->type == WEAPON) 296 if (op->type == WEAPON)
301 { 297 {
302 for (i = 1; i < NROFATTACKS; i++) 298 for (i = 1; i < NROFATTACKS; i++)
303 if (op->attacktype & (1 << i)) 299 if (op->attacktype & (1 << i))
304 enc++; 300 enc++;
301
305 if (op->slaying) 302 if (op->slaying)
306 enc += 2; /* What it slays is probably more relevent */ 303 enc += 2; /* What it slays is probably more relevent */
307 } 304 }
305
308 /* Items the player can equip */ 306 /* Items the player can equip */
309 if ((op->type == WEAPON) || (op->type == ARMOUR) || (op->type == HELMET) || 307 if ((op->type == WEAPON) || (op->type == ARMOUR) || (op->type == HELMET) ||
310 (op->type == SHIELD) || (op->type == RING) || 308 (op->type == SHIELD) || (op->type == RING) ||
311 (op->type == BOOTS) || (op->type == GLOVES) || 309 (op->type == BOOTS) || (op->type == GLOVES) ||
312 (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))
315 enc += op->stats.hp; /* hp regen */ 313 enc += op->stats.hp; /* hp regen */
316 enc += op->stats.sp; /* mana regen */ 314 enc += op->stats.sp; /* mana regen */
317 enc += op->stats.grace; /* grace regen */ 315 enc += op->stats.grace; /* grace regen */
318 enc += op->stats.exp; /* speed bonus */ 316 enc += op->stats.exp; /* speed bonus */
319 } 317 }
318
320 enc += op->stats.luck; 319 enc += op->stats.luck;
321 320
322 /* Do spell paths now */ 321 /* Do spell paths now */
323 for (i = 1; i < NRSPELLPATHS; i++) 322 for (i = 1; i < NRSPELLPATHS; i++)
324 { 323 {
356 int i; 355 int i;
357 356
358 for (i = 0; i < item_types_size; i++) 357 for (i = 0; i < item_types_size; i++)
359 if (item_types[i].number == itemtype) 358 if (item_types[i].number == itemtype)
360 return &item_types[i]; 359 return &item_types[i];
360
361 return NULL; 361 return NULL;
362} 362}
363 363
364/* 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
365 * 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
370 int i; 370 int i;
371 371
372 for (i = 0; i < item_types_size; i++) 372 for (i = 0; i < item_types_size; i++)
373 if (!strcmp (item_types[i].name, name)) 373 if (!strcmp (item_types[i].name, name))
374 return &item_types[i]; 374 return &item_types[i];
375
375 for (i = 0; i < item_types_size; i++) 376 for (i = 0; i < item_types_size; i++)
376 if (!strcmp (item_types[i].name_pl, name)) 377 if (!strcmp (item_types[i].name_pl, name))
377 { 378 {
378 LOG (llevInfo, 379 LOG (llevInfo,
379 "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);
380 return &item_types[i]; 381 return &item_types[i];
381 } 382 }
383
382 return NULL; 384 return NULL;
383} 385}
384 386
385/* describe_resistance generates the visible naming for resistances. 387/* describe_resistance generates the visible naming for resistances.
386 * returns a static array of the description. This can return 388 * returns a static array of the description. This can return
538 * contain any information about object status (worn/cursed/etc.) 540 * contain any information about object status (worn/cursed/etc.)
539 */ 541 */
540const char * 542const char *
541query_short_name (const object *op) 543query_short_name (const object *op)
542{ 544{
543 if (op->name == 0) 545 if (!op->name)
544 return "(null)"; 546 return "(null)";
545 547
546 if (!op->nrof 548 if (!op->nrof
547 && !op->weight 549 && !op->weight
548 && !op->title 550 && !op->title
571 if (op->type != SPELLBOOK) 573 if (op->type != SPELLBOOK)
572 buf.printf (" (lvl %d)", op->level); 574 buf.printf (" (lvl %d)", op->level);
573 } 575 }
574 break; 576 break;
575 577
576 case ALTAR: 578 case ALTAR:
577 case TRIGGER_ALTAR: 579 case TRIGGER_ALTAR:
578 case IDENTIFY_ALTAR: 580 case IDENTIFY_ALTAR:
579 case CONVERTER: 581 case CONVERTER:
580 if (op->slaying == shstr_money) 582 if (op->slaying == shstr_money)
581 { 583 {
582 bool wrap = !!buf.size (); 584 bool wrap = !!buf.size ();
583 585
584 if (wrap) buf << " ["; 586 if (wrap) buf << " [";
585 587
586 archetype *coin = 0; 588 archetype *coin = 0;
587 589
588 for (char const *const *c = coins; *coins; ++c) 590 for (char const *const *c = coins; *coins; ++c)
589 if ((coin = archetype::find (*c))) 591 if ((coin = archetype::find (*c)))
590 if (op->stats.food % coin->value == 0) 592 if (op->stats.food % coin->value == 0)
591 break; 593 break;
592 594
593 sint32 coins = op->stats.food / coin->value; 595 sint32 coins = op->stats.food / coin->value;
594 596
595 buf.printf ("drop %d %s (or equivalent)", coins, coins == 1 ? &coin->name : &coin->name_pl); 597 buf.printf ("drop %d %s (or equivalent)", coins, coins == 1 ? &coin->name : &coin->name_pl);
596 598
597 if (wrap) buf << ']'; 599 if (wrap) buf << ']';
598 } 600 }
599 break; 601 break;
600 602
601 case SKILL: 603 case SKILL:
602 case AMULET: 604 case AMULET:
603 case RING: 605 case RING:
604 if (!op->title) 606 if (!op->title)
808 */ 810 */
809 if (op->has_active_speed ()) 811 if (op->has_active_speed ())
810 switch ((int) ((FABS (op->speed)) * 15)) 812 switch ((int) ((FABS (op->speed)) * 15))
811 { 813 {
812 case 0: 814 case 0:
813 buf << "(very slow movement"; 815 buf << "(very slow movement)";
814 break; 816 break;
815 case 1: 817 case 1:
816 buf << "(slow movement)"; 818 buf << "(slow movement)";
817 break; 819 break;
818 case 2: 820 case 2:
1210{ 1212{
1211 static dynbuf_text buf; buf.clear (); 1213 static dynbuf_text buf; buf.clear ();
1212 1214
1213 for (object *tmp = inv; tmp; tmp = tmp->below) 1215 for (object *tmp = inv; tmp; tmp = tmp->below)
1214 if (who && QUERY_FLAG (who, FLAG_WIZ)) 1216 if (who && QUERY_FLAG (who, FLAG_WIZ))
1215 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 ());
1216 else if (!tmp->invisible && (type == CONTAINER || QUERY_FLAG (tmp, FLAG_APPLIED))) 1218 else if (!tmp->invisible && (type == CONTAINER || QUERY_FLAG (tmp, FLAG_APPLIED)))
1217 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 ());
1218 1220
1219 if (buf.size ()) 1221 if (buf.size ())
1220 buf.printf ("%s(total weight: %s)\n", indent, query_weight (this)); 1222 buf.printf ("%s(total weight: %s)\n", indent, query_weight ());
1221 else 1223 else
1222 buf.printf ("%s(empty)\n", indent); 1224 buf.printf ("%s(empty)\n", indent);
1223 1225
1224 return buf; 1226 return buf;
1225} 1227}
1357 * Supposed to fix face-values as well here, but later. 1359 * Supposed to fix face-values as well here, but later.
1358 */ 1360 */
1359void 1361void
1360identify (object *op) 1362identify (object *op)
1361{ 1363{
1362 object *pl;
1363
1364 SET_FLAG (op, FLAG_IDENTIFIED); 1364 SET_FLAG (op, FLAG_IDENTIFIED);
1365 CLEAR_FLAG (op, FLAG_KNOWN_MAGICAL); 1365 CLEAR_FLAG (op, FLAG_KNOWN_MAGICAL);
1366 CLEAR_FLAG (op, FLAG_NO_SKILL_IDENT); 1366 CLEAR_FLAG (op, FLAG_NO_SKILL_IDENT);
1367 1367
1368 /* 1368 /*
1375 { 1375 {
1376 if (op->inv && op->randomitems) 1376 if (op->inv && op->randomitems)
1377 op->title = op->inv->name; 1377 op->title = op->inv->name;
1378 else if (op->arch) 1378 else if (op->arch)
1379 { 1379 {
1380 op->name = op->arch->object::name; 1380 op->name = op->arch->object::name;
1381 op->name_pl = op->arch->object::name_pl; 1381 op->name_pl = op->arch->object::name_pl;
1382 } 1382 }
1383 } 1383 }
1384 1384
1385 /* 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 */
1386 if (op->map) 1386 if (op->map)
1387 update_object (op, UP_OBJ_CHANGE); 1387 update_object (op, UP_OBJ_CHANGE);
1388 else 1388
1389 { 1389 if (object *pl = op->visible_to ())
1390 pl = op->in_player ();
1391 if (pl)
1392 /* 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
1393 * it all. 1391 * it all.
1394 */ 1392 */
1395 esrv_send_item (pl, op); 1393 esrv_send_item (pl, op);
1396 }
1397} 1394}
1398 1395

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines