Crossfire Server, Branches 1.12  R18729
power_crystal.c
Go to the documentation of this file.
1 /*
2  CrossFire, A Multiplayer game for X-windows
3 
4  Copyright (C) 2007 Mark Wedel & Crossfire Development Team
5  Copyright (C) 1992 Frank Tore Johansen
6 
7  This program is free software; you can redistribute it and/or modify
8  it under the terms of the GNU General Public License as published by
9  the Free Software Foundation; either version 2 of the License, or
10  (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 
21  The authors can be reached via e-mail at crossfire-devel@real-time.com
22 */
27 #include <global.h>
28 #include <ob_methods.h>
29 #include <ob_types.h>
30 #include <sproto.h>
31 
32 static method_ret power_crystal_type_apply(ob_methods *context, object *op, object *applier, int aflags);
33 
40 }
41 
53 static method_ret power_crystal_type_apply(ob_methods *context, object *op, object *applier, int aflags) {
54  int available_power;
55  int power_space;
56  int power_grab;
57 
58  available_power = applier->stats.sp-applier->stats.maxsp;
59  power_space = op->stats.maxsp-op->stats.sp;
60  power_grab = 0;
61  if (available_power >= 0 && power_space > 0)
62  power_grab = MIN(power_space, 0.5*applier->stats.sp);
63  if (available_power < 0 && op->stats.sp > 0)
64  power_grab = -MIN(-available_power, op->stats.sp);
65 
66  applier->stats.sp -= power_grab;
67  op->stats.sp += power_grab;
68  op->speed = (float)op->stats.sp/(float)op->stats.maxsp;
69  update_ob_speed(op);
70  if (applier->type == PLAYER)
71  esrv_update_item(UPD_ANIMSPEED, applier, op);
72  return METHOD_OK;
73 }
void register_describe(int ob_type, describe_func method)
Definition: ob_types.c:97
void esrv_update_item(int flags, object *pl, object *op)
Definition: standalone.c:200
sint16 sp
Definition: living.h:83
#define UPD_ANIMSPEED
Definition: newclient.h:260
#define PLAYER
Definition: define.h:113
sint16 maxsp
Definition: living.h:84
char method_ret
Definition: ob_methods.h:41
#define METHOD_OK
Definition: ob_methods.h:42
static method_ret power_crystal_type_apply(ob_methods *context, object *op, object *applier, int aflags)
Definition: power_crystal.c:53
void common_ob_describe(const ob_methods *context, const object *op, const object *observer, char *buf, size_t size)
Definition: describe.c:39
void register_apply(int ob_type, apply_func method)
Definition: ob_types.c:79
float speed
Definition: object.h:181
#define MIN(x, y)
Definition: define.h:67
living stats
Definition: object.h:219
void update_ob_speed(object *op)
Definition: object.c:1008
void init_type_power_crystal(void)
Definition: power_crystal.c:37
uint8 type
Definition: object.h:189
#define POWER_CRYSTAL
Definition: define.h:328