Atrinik Server  4.0
gate.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 <object.h>
34 #include <object_methods.h>
35 
37 static void
38 process_func (object *op)
39 {
40  HARD_ASSERT(op != NULL);
41 
42  if (op->stats.maxhp != 0 && op->stats.hp != 0) {
43  if (--op->stats.hp == 0) {
44  op->value = !op->value;
45  op->stats.food = 0;
46  } else {
47  return;
48  }
49  }
50 
51  /* Going down. */
52  if (op->value != 0) {
53  if (--op->stats.wc <= 0) {
54  op->stats.wc = 0;
55 
56  if (op->stats.food != 0) {
57  op->stats.hp = op->stats.maxhp;
58  } else {
59  op->speed = 0;
61  }
62  }
63 
64  if (op->stats.wc < (NUM_ANIMATIONS(op) / NUM_FACINGS(op) / 2 + 1)) {
65  if (op->stats.ac != 0) {
67  }
68 
71  }
72  } else {
73  /* Going up. */
74 
75  if (++op->stats.wc >= (NUM_ANIMATIONS(op) / NUM_FACINGS(op)) / 2) {
76  bool is_blocked = false;
77  FOR_MAP_PREPARE(op->map, op->x, op->y, tmp) {
78  if (!QUERY_FLAG(tmp, FLAG_CAN_ROLL) && !IS_LIVE(tmp)) {
79  continue;
80  }
81 
82  if (IS_LIVE(tmp)) {
83  attack_hit(tmp, op, op->stats.dam);
84  draw_info_format(COLOR_WHITE, tmp,
85  "You are crushed by the %s!",
86  op->name);
87  }
88 
89  int i = map_free_spot(op->map,
90  op->x,
91  op->y,
92  1,
93  SIZEOFFREE1, tmp->arch,
94  tmp);
95  /* If there is a free spot, move the object someplace. */
96  if (i != -1) {
97  object_remove(tmp, 0);
98  tmp->x += freearr_x[i];
99  tmp->y += freearr_y[i];
100  object_insert_map(tmp, op->map, op, 0);
101  } else {
102  /* No free spot, so the gate is blocked. */
103  is_blocked = true;
104  }
105  } FOR_MAP_FINISH();
106 
107  if (is_blocked) {
108  op->stats.wc--;
109  } else if (!QUERY_FLAG(op, FLAG_NO_PASS)) {
110  if (op->stats.ac != 0) {
112  }
113 
114  SET_FLAG(op, FLAG_NO_PASS);
116  }
117 
118  if (op->stats.wc >= (NUM_ANIMATIONS(op) / NUM_FACINGS(op)) - 1) {
119  op->stats.wc = (NUM_ANIMATIONS(op) / NUM_FACINGS(op)) - 1;
120 
121  if (op->stats.food != 0) {
122  op->stats.hp = op->stats.maxhp;
123  } else {
124  op->speed = 0;
126  }
127  }
128  }
129  }
130 
131  op->state = op->stats.wc;
132  SET_ANIMATION(op, ((NUM_ANIMATIONS(op) / NUM_FACINGS(op)) *
133  op->direction + op->stats.wc));
135 }
136 
138 static int
139 trigger_func (object *op, object *cause, int state)
140 {
141  HARD_ASSERT(op != NULL);
142  HARD_ASSERT(cause != NULL);
143 
144  if (!DBL_EQUAL(op->speed, 0.0) && op->stats.maxhp) {
145  return OBJECT_METHOD_OK;
146  }
147 
148  op->speed = 0.5;
150 
151  if (op->stats.maxhp != 0) {
152  op->stats.food = 1;
153  op->value = !op->value;
154  } else {
155  op->value = op->stats.maxsp != 0 ? !state : state;
156  }
157 
158  return OBJECT_METHOD_OK;
159 }
160 
165 {
166  OBJECT_METHODS(GATE)->trigger_func = trigger_func;
167  OBJECT_METHODS(GATE)->process_func = process_func;
168 }
int16_t ac
Definition: living.h:93
#define UP_OBJ_FACE
Definition: object.h:537
#define NUM_FACINGS(ob)
Definition: global.h:300
#define SIZEOFFREE1
Definition: define.h:654
OBJECT_TYPE_INIT_DEFINE(gate)
Definition: gate.c:164
#define SET_ANIMATION(ob, newanim)
Definition: global.h:282
#define IS_LIVE(op)
Definition: define.h:841
int map_free_spot(mapstruct *m, int x, int y, int start, int stop, archetype_t *at, object *op)
Definition: map.c:2942
#define QUERY_FLAG(xyz, p)
Definition: define.h:761
void object_remove(object *op, int flags)
Definition: object.c:1623
int16_t maxsp
Definition: living.h:81
int32_t hp
Definition: living.h:72
int16_t y
Definition: object.h:276
int32_t maxhp
Definition: living.h:75
void object_update(object *op, int action)
Definition: object.c:1117
int8_t direction
Definition: object.h:350
#define FLAG_CAN_ROLL
Definition: define.h:950
struct mapdef * map
Definition: object.h:139
int16_t dam
Definition: living.h:87
const char * name
Definition: object.h:168
#define SET_FLAG(xyz, p)
Definition: define.h:741
uint8_t state
Definition: object.h:344
static int trigger_func(object *op, object *cause, int state)
Definition: gate.c:139
double speed
Definition: object.h:469
#define FOR_MAP_FINISH()
Definition: define.h:1759
int16_t x
Definition: object.h:273
int16_t wc
Definition: living.h:90
object * object_insert_map(object *op, mapstruct *m, object *originator, int flag)
Definition: object.c:1741
static void process_func(object *op)
Definition: gate.c:38
#define FLAG_BLOCKSVIEW
Definition: define.h:1008
#define GATE
Definition: define.h:393
#define NUM_ANIMATIONS(ob)
Definition: global.h:298
living stats
Definition: object.h:481
int attack_hit(object *op, object *hitter, int dam)
Definition: attack.c:669
int freearr_x[SIZEOFFREE]
Definition: object.c:84
#define CLEAR_FLAG(xyz, p)
Definition: define.h:751
#define OBJECT_METHODS(type)
#define OBJECT_METHOD_OK
#define FLAG_NO_PASS
Definition: define.h:908
void object_update_speed(object *op)
Definition: object.c:1043
int freearr_y[SIZEOFFREE]
Definition: object.c:99
#define UP_OBJ_FLAGS
Definition: object.h:535
int64_t value
Definition: object.h:240
#define FOR_MAP_PREPARE(map_, mx_, my_, it_)
Definition: define.h:1752
int16_t food
Definition: living.h:84