ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/server/egoitem.C
Revision: 1.2
Committed: Sun Sep 10 15:59:57 2006 UTC (17 years, 8 months ago) by root
Content type: text/plain
Branch: MAIN
Changes since 1.1: +41 -37 lines
Log Message:
indent

File Contents

# Content
1
2 /*
3 * static char *rcsid_egoitem_c =
4 * "$Id: egoitem.C,v 1.1 2006-08-13 17:16:04 elmex Exp $";
5 */
6
7
8 #include <global.h>
9 #ifndef __CEXTRACT__
10 # include <sproto.h>
11 #endif
12
13 /* GROS: I put this here, because no other file seemed quite good. Returns 1 if
14 * the artifact could be created.
15 */
16 int
17 create_artifact (object *op, const char *artifactname)
18 {
19 artifactlist *al;
20 artifact *art;
21 char *temptitle;
22
23 al = find_artifactlist (op->type);
24 if (al == NULL)
25 return 0;
26 for (art = al->items; art != NULL; art = art->next)
27 {
28 temptitle = (char *) (malloc (strlen (art->item->name) + 5));
29 strcpy (temptitle, " of ");
30 strcat (temptitle, art->item->name);
31 if (!strcmp (temptitle, artifactname))
32 {
33 give_artifact_abilities (op, art->item);
34 free (temptitle);
35 return 1;
36 }
37
38 free (temptitle);
39 };
40 return 0;
41 }
42
43
44 /* peterm: do_power_crystal
45
46 object *op, object *crystal
47
48 This function handles the application of power crystals.
49 Power crystals, when applied, either suck power from the applier,
50 if he's at full spellpoints, or gives him power, if it's got
51 spellpoins stored.
52
53 */
54
55 int
56 apply_power_crystal (object *op, object *crystal)
57 {
58 int available_power;
59 int power_space;
60 int power_grab;
61
62 available_power = op->stats.sp - op->stats.maxsp;
63 power_space = crystal->stats.maxsp - crystal->stats.sp;
64 power_grab = 0;
65 if (available_power >= 0 && power_space > 0)
66 power_grab = (int) MIN (power_space, 0.5 * op->stats.sp);
67 if (available_power < 0 && crystal->stats.sp > 0)
68 power_grab = -MIN (-available_power, crystal->stats.sp);
69
70 op->stats.sp -= power_grab;
71 crystal->stats.sp += power_grab;
72 crystal->speed = (float) crystal->stats.sp / (float) crystal->stats.maxsp;
73 update_ob_speed (crystal);
74 if (op->type == PLAYER)
75 esrv_update_item (UPD_ANIMSPEED, op, crystal);
76
77 return 1;
78 }