Atrinik Server  4.0
pedestal.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 <pedestal.h>
36 
38 static int
39 trigger_button_func (object *op, object *cause, int state)
40 {
41  HARD_ASSERT(op != NULL);
42  HARD_ASSERT(cause != NULL);
43 
44  op->value = 0;
45 
46  FOR_MAP_PREPARE(op->map, op->x, op->y, tmp) {
47  tmp = HEAD(tmp);
48  if (tmp == op) {
49  continue;
50  }
51 
52  if (QUERY_FLAG(tmp, FLAG_FLYING)) {
53  if (!QUERY_FLAG(op, FLAG_FLY_ON)) {
54  continue;
55  }
56  } else if (!QUERY_FLAG(op, FLAG_WALK_ON)) {
57  continue;
58  }
59 
60  if (!pedestal_matches_obj(op, tmp)) {
61  continue;
62  }
63 
64  op->value = 1;
65  break;
66  } FOR_MAP_FINISH();
67 
68  return OBJECT_METHOD_OK;
69 }
70 
75 {
76  OBJECT_METHODS(PEDESTAL)->trigger_button_func = trigger_button_func;
78 }
79 
90 bool
91 pedestal_matches_obj (object *op, object *tmp)
92 {
93  HARD_ASSERT(op != NULL);
94  HARD_ASSERT(tmp != NULL);
95 
96  /* Check type. */
97  if (op->stats.hp != 0 && tmp->type != op->stats.hp) {
98  return false;
99  }
100 
101  /* Check name. */
102  if (op->slaying != NULL && tmp->name != op->slaying) {
103  return false;
104  }
105 
106  /* Check archname. */
107  if (op->race != NULL && tmp->arch->name != op->race) {
108  return false;
109  }
110 
111  return true;
112 }
object_methods_t * object_methods_get(int type)
const char * race
Definition: object.h:174
#define PEDESTAL
Definition: define.h:186
#define FLAG_FLY_ON
Definition: define.h:968
const char * slaying
Definition: object.h:180
#define BUTTON
Definition: define.h:397
#define QUERY_FLAG(xyz, p)
Definition: define.h:761
struct archetype * arch
Definition: object.h:225
int32_t hp
Definition: living.h:72
int16_t y
Definition: object.h:276
static int trigger_button_func(object *op, object *cause, int state)
Definition: pedestal.c:39
OBJECT_TYPE_INIT_DEFINE(pedestal)
Definition: pedestal.c:74
struct mapdef * map
Definition: object.h:139
const char * name
Definition: object.h:168
#define FLAG_FLYING
Definition: define.h:918
#define HEAD(op)
Definition: object.h:657
#define FOR_MAP_FINISH()
Definition: define.h:1759
int16_t x
Definition: object.h:273
living stats
Definition: object.h:481
uint8_t type
Definition: object.h:360
#define OBJECT_METHODS(type)
shstr * name
More definite name, like "kobold".
Definition: arch.h:46
#define OBJECT_METHOD_OK
#define FLAG_WALK_ON
Definition: define.h:904
bool pedestal_matches_obj(object *op, object *tmp)
Definition: pedestal.c:91
int64_t value
Definition: object.h:240
#define FOR_MAP_PREPARE(map_, mx_, my_, it_)
Definition: define.h:1752