ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/server/egoitem.C
Revision: 1.3
Committed: Thu Sep 14 22:34:04 2006 UTC (17 years, 8 months ago) by root
Content type: text/plain
Branch: MAIN
Changes since 1.2: +0 -7 lines
Log Message:
indent

File Contents

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