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, 9 months ago) by root
Content type: text/plain
Branch: MAIN
Changes since 1.1: +41 -37 lines
Log Message:
indent

File Contents

# User Rev Content
1 root 1.2
2 elmex 1.1 /*
3     * static char *rcsid_egoitem_c =
4 root 1.2 * "$Id: egoitem.C,v 1.1 2006-08-13 17:16:04 elmex Exp $";
5 elmex 1.1 */
6 root 1.2
7 elmex 1.1
8     #include <global.h>
9     #ifndef __CEXTRACT__
10 root 1.2 # include <sproto.h>
11 elmex 1.1 #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 root 1.2 int
17     create_artifact (object *op, const char *artifactname)
18 elmex 1.1 {
19 root 1.2 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 elmex 1.1 {
33 root 1.2 give_artifact_abilities (op, art->item);
34     free (temptitle);
35     return 1;
36     }
37    
38     free (temptitle);
39     };
40     return 0;
41 elmex 1.1 }
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 root 1.2 int
56     apply_power_crystal (object *op, object *crystal)
57     {
58 elmex 1.1 int available_power;
59     int power_space;
60     int power_grab;
61    
62 root 1.2 available_power = op->stats.sp - op->stats.maxsp;
63 elmex 1.1 power_space = crystal->stats.maxsp - crystal->stats.sp;
64     power_grab = 0;
65 root 1.2 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 elmex 1.1 if (op->type == PLAYER)
75 root 1.2 esrv_update_item (UPD_ANIMSPEED, op, crystal);
76 elmex 1.1
77     return 1;
78     }