Atrinik Server  4.0
marker.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 <arch.h>
32 #include <object_methods.h>
33 
35 static int
36 move_on_func (object *op, object *victim, object *originator, int state)
37 {
38  HARD_ASSERT(op != NULL);
39  HARD_ASSERT(victim != NULL);
40 
41  if (victim->type != PLAYER || state == 0) {
42  return OBJECT_METHOD_OK;
43  }
44 
45  if (op->slaying != NULL) {
46  FOR_INV_PREPARE(victim, tmp) {
47  if (tmp->type == FORCE && tmp->slaying == op->slaying) {
48  object_remove(tmp, 0);
49  object_destroy(tmp);
50  break;
51  }
52  } FOR_INV_FINISH();
53  }
54 
55  if (op->race == NULL) {
56  return OBJECT_METHOD_OK;
57  }
58 
59  FOR_INV_PREPARE(victim, tmp) {
60  if (tmp->type == FORCE && tmp->slaying == op->race) {
61  return OBJECT_METHOD_OK;
62  }
63  } FOR_INV_FINISH();
64 
65  object *force = arch_get("force");
66  force->speed = 0;
67 
68  if (op->stats.food != 0) {
69  force->speed = 0.01;
70  force->speed_left = -op->stats.food;
71  SET_FLAG(force, FLAG_IS_USED_UP);
72  }
73 
74  object_update_speed(force);
75  FREE_AND_COPY_HASH(force->slaying, op->race);
76  object_insert_into(force, victim, 0);
77 
78  if (op->msg != NULL) {
79  draw_info(COLOR_NAVY, victim, op->msg);
80  }
81 
82  if (op->stats.hp > 0) {
83  op->stats.hp--;
84 
85  if (op->stats.hp == 0) {
86  object_destruct(op);
87  return OBJECT_METHOD_OK;
88  }
89  }
90 
91  return OBJECT_METHOD_OK;
92 }
93 
98 {
99  OBJECT_METHODS(MARKER)->move_on_func = move_on_func;
100 }
#define FREE_AND_COPY_HASH(_sv_, _nv_)
Definition: global.h:100
void object_destroy(object *ob)
Definition: object.c:1441
OBJECT_TYPE_INIT_DEFINE(marker)
Definition: marker.c:97
const char * race
Definition: object.h:174
#define MARKER
Definition: define.h:284
#define FOR_INV_PREPARE(op_, it_)
Definition: define.h:1691
#define FOR_INV_FINISH()
Definition: define.h:1698
double speed_left
Definition: object.h:472
const char * slaying
Definition: object.h:180
object * arch_get(const char *name)
Definition: arch.c:430
void object_destruct(object *op)
Definition: object.c:1521
#define PLAYER
Definition: define.h:122
void object_remove(object *op, int flags)
Definition: object.c:1623
int32_t hp
Definition: living.h:72
object * object_insert_into(object *op, object *where, int flag)
Definition: object.c:2158
#define SET_FLAG(xyz, p)
Definition: define.h:741
#define FLAG_IS_USED_UP
Definition: define.h:976
double speed
Definition: object.h:469
living stats
Definition: object.h:481
uint8_t type
Definition: object.h:360
#define OBJECT_METHODS(type)
const char * msg
Definition: object.h:183
#define OBJECT_METHOD_OK
static int move_on_func(object *op, object *victim, object *originator, int state)
Definition: marker.c:36
void object_update_speed(object *op)
Definition: object.c:1043
static object marker
Definition: main.c:51
#define FORCE
Definition: define.h:465
int16_t food
Definition: living.h:84