Atrinik Server  4.0
check_inv.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 
32 #include <global.h>
33 #include <arch.h>
34 #include <object_methods.h>
35 #include <check_inv.h>
36 
48 object *
49 check_inv (object *op, object *ob)
50 {
51  HARD_ASSERT(op != NULL);
52  HARD_ASSERT(ob != NULL);
53 
54  FOR_INV_PREPARE(ob, tmp) {
55  if (tmp->inv != NULL && !IS_SYS_INVISIBLE(tmp)) {
56  object *ret = check_inv(op, tmp);
57  if (ret != NULL) {
58  return ret;
59  }
60  } else {
61  if (op->stats.hp != 0 && tmp->type != op->stats.hp) {
62  continue;
63  }
64 
65  if (op->slaying != NULL) {
66  if (op->stats.sp != 0) {
67  if (tmp->slaying != op->slaying) {
68  continue;
69  }
70  } else {
71  if (tmp->name != op->slaying) {
72  continue;
73  }
74  }
75  }
76 
77  if (op->race != NULL && tmp->arch->name != op->race) {
78  continue;
79  }
80 
81  return tmp;
82  }
83  } FOR_INV_FINISH();
84 
85  return NULL;
86 }
87 
89 static int
90 move_on_func (object *op, object *victim, object *originator, int state)
91 {
92  HARD_ASSERT(op != NULL);
93  HARD_ASSERT(victim != NULL);
94 
95  if (victim->type != PLAYER) {
96  return OBJECT_METHOD_OK;
97  }
98 
99  object *match = check_inv(op, victim);
100  if (match != NULL && op->last_sp != 0) {
101  if (op->last_heal != 0) {
102  decrease_ob(match);
103  }
104 
105  connection_trigger(op, state);
106  } else if (match == NULL && op->last_sp == 0) {
107  connection_trigger(op, state);
108  }
109 
110  return OBJECT_METHOD_OK;
111 }
112 
117 {
118  OBJECT_METHODS(CHECK_INV)->move_on_func = move_on_func;
119 }
const char * race
Definition: object.h:174
#define FOR_INV_PREPARE(op_, it_)
Definition: define.h:1691
#define FOR_INV_FINISH()
Definition: define.h:1698
int16_t last_heal
Definition: object.h:310
const char * slaying
Definition: object.h:180
int16_t last_sp
Definition: object.h:313
#define PLAYER
Definition: define.h:122
int16_t sp
Definition: living.h:78
#define IS_SYS_INVISIBLE(__ob_)
Definition: define.h:1353
int32_t hp
Definition: living.h:72
#define decrease_ob(xyz)
Definition: object.h:624
OBJECT_TYPE_INIT_DEFINE(check_inv)
Definition: check_inv.c:116
void connection_trigger(object *op, int state)
Definition: connection.c:258
object * check_inv(object *op, object *ob)
Definition: check_inv.c:49
living stats
Definition: object.h:481
uint8_t type
Definition: object.h:360
#define OBJECT_METHODS(type)
static int move_on_func(object *op, object *victim, object *originator, int state)
Definition: check_inv.c:90
#define OBJECT_METHOD_OK
#define CHECK_INV
Definition: define.h:308