00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00027 #include <global.h>
00028 #include <ob_methods.h>
00029 #include <ob_types.h>
00030 #include <sproto.h>
00031
00032 static method_ret power_crystal_type_apply(ob_methods *context, object *op, object *applier, int aflags);
00033
00037 void init_type_power_crystal(void) {
00038 register_apply(POWER_CRYSTAL, power_crystal_type_apply);
00039 register_describe(POWER_CRYSTAL, common_ob_describe);
00040 }
00041
00053 static method_ret power_crystal_type_apply(ob_methods *context, object *op, object *applier, int aflags) {
00054 int available_power;
00055 int power_space;
00056 int power_grab;
00057
00058 available_power = applier->stats.sp-applier->stats.maxsp;
00059 power_space = op->stats.maxsp-op->stats.sp;
00060 power_grab = 0;
00061 if (available_power >= 0 && power_space > 0)
00062 power_grab = MIN(power_space, 0.5*applier->stats.sp);
00063 if (available_power < 0 && op->stats.sp > 0)
00064 power_grab = -MIN(-available_power, op->stats.sp);
00065
00066 applier->stats.sp -= power_grab;
00067 op->stats.sp += power_grab;
00068 op->speed = (float)op->stats.sp/(float)op->stats.maxsp;
00069 update_ob_speed(op);
00070 if (applier->type == PLAYER)
00071 esrv_update_item(UPD_ANIMSPEED, applier, op);
00072 return METHOD_OK;
00073 }