Atrinik Server  4.0
bullet.c
Go to the documentation of this file.
1 /*************************************************************************
2  * Atrinik, a Multiplayer Online Role Playing Game *
3  * *
4  * Copyright (C) 2009-2014 Alex Tokar and Atrinik Development Team *
5  * *
6  * Fork from Crossfire (Multiplayer game for X-windows). *
7  * *
8  * This program is free software; you can redistribute it and/or modify *
9  * it under the terms of the GNU General Public License as published by *
10  * the Free Software Foundation; either version 2 of the License, or *
11  * (at your option) any later version. *
12  * *
13  * This program is distributed in the hope that it will be useful, *
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16  * GNU General Public License for more details. *
17  * *
18  * You should have received a copy of the GNU General Public License *
19  * along with this program; if not, write to the Free Software *
20  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
21  * *
22  * The author can be reached at admin@atrinik.org *
23  ************************************************************************/
24 
30 #include <global.h>
31 #include <object.h>
32 #include <player.h>
33 #include <object_methods.h>
34 
36 static void
37 process_func (object *op)
38 {
39  HARD_ASSERT(op != NULL);
40 
41  /* Custom handling for the magic missile spell bullets, so that they
42  * follow the target. */
43  if (op->stats.sp == SP_MAGIC_MISSILE) {
44  rv_vector rv;
45 
46  if (!OBJECT_VALID(op->enemy, op->enemy_count) ||
47  !get_rangevector(op, op->enemy, &rv, 0)) {
48  object_remove(op, 0);
49  object_destroy(op);
50  return;
51  }
52 
53  op->direction = rv.direction;
55  }
56 
58 }
59 
61 static int
62 projectile_hit_func (object *op, object *victim)
63 {
64  HARD_ASSERT(op != NULL);
65  HARD_ASSERT(victim != NULL);
66 
67  /* Handle probe. */
68  if (op->stats.sp == SP_PROBE && IS_LIVE(victim)) {
69  object *owner = object_owner(op);
70  if (owner != NULL) {
71  draw_info_format(COLOR_WHITE, owner,
72  "Your probe analyzes %s.",
73  victim->name);
74  examine(owner, victim, NULL);
75  }
76 
77  return OBJECT_METHOD_OK;
78  }
79 
80  return common_object_projectile_hit(op, victim);
81 }
82 
87 {
88  OBJECT_METHODS(BULLET)->process_func =
90  OBJECT_METHODS(BULLET)->projectile_move_func =
92  OBJECT_METHODS(BULLET)->projectile_stop_func =
94  OBJECT_METHODS(BULLET)->projectile_hit_func =
96  OBJECT_METHODS(BULLET)->move_on_func =
98 }
void object_destroy(object *ob)
Definition: object.c:1441
int get_rangevector(object *op1, object *op2, rv_vector *retval, int flags)
Definition: map.c:2238
int direction
Definition: map.h:787
tag_t enemy_count
Definition: object.h:216
object * common_object_projectile_move(object *op)
Definition: projectile.c:152
int common_object_projectile_move_on(object *op, object *victim, object *originator, int state)
Definition: projectile.c:376
#define IS_LIVE(op)
Definition: define.h:841
int16_t sp
Definition: living.h:78
static int projectile_hit_func(object *op, object *victim)
Definition: bullet.c:62
struct obj * enemy
Definition: object.h:196
void object_remove(object *op, int flags)
Definition: object.c:1623
OBJECT_TYPE_INIT_DEFINE(bullet)
Definition: bullet.c:86
int8_t direction
Definition: object.h:350
object * common_object_projectile_stop_spell(object *op, int reason)
Definition: projectile.c:284
const char * name
Definition: object.h:168
static void process_func(object *op)
Definition: bullet.c:37
int common_object_projectile_hit(object *op, object *victim)
Definition: projectile.c:344
living stats
Definition: object.h:481
#define OBJECT_METHODS(type)
object * object_owner(object *op)
Definition: object.c:857
void examine(object *op, object *tmp, StringBuffer *sb_capture)
Definition: player.c:1521
#define OBJECT_METHOD_OK
#define OBJECT_VALID(_ob_, _count_)
Definition: object.h:548
#define SET_ANIMATION_STATE(ob)
Definition: global.h:287
#define BULLET
Definition: define.h:126
void common_object_projectile_process(object *op)
Definition: projectile.c:68