Atrinik Server  4.0
push.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 
36 void command_push(object *op, const char *command, char *params)
37 {
38  object *tmp;
39  mapstruct *m;
40  int x, y, dir;
41 
42  dir = op->direction;
43 
44  /* We check for all conditions where the player can't push anything. */
45  if (dir <= 0 || QUERY_FLAG(op, FLAG_PARALYZED)) {
46  draw_info(COLOR_WHITE, op, "You are unable to push anything.");
47  return;
48  }
49 
50  x = op->x + freearr_x[dir];
51  y = op->y + freearr_y[dir];
52  m = get_map_from_coord(op->map, &x, &y);
53 
54  if (!m) {
55  return;
56  }
57 
58  for (tmp = GET_MAP_OB(m, x, y); tmp; tmp = tmp->above) {
59  if (QUERY_FLAG(tmp, FLAG_CAN_ROLL)) {
60  break;
61  }
62  }
63 
64  if (!tmp) {
65  draw_info(COLOR_WHITE, op, "You fail to push anything.");
66  return;
67  }
68 
69  tmp->direction = dir;
70 
71  char *name = object_get_name_s(tmp, op);
72 
73  /* Try to push the object. */
74  if (!push_ob(tmp, dir, op)) {
75  draw_info_format(COLOR_WHITE, op, "You fail to push the %s.", name);
76  return;
77  }
78 
79  draw_info_format(COLOR_WHITE, op, "You push the %s.", name);
80 
81  /* Now we move the player who was pushing the object. */
82  move_ob(op, dir, op);
83  efree(name);
84 }
mapstruct * get_map_from_coord(mapstruct *m, int *x, int *y)
Definition: map.c:1869
struct obj * above
Definition: object.h:120
#define FLAG_PARALYZED
Definition: define.h:876
#define QUERY_FLAG(xyz, p)
Definition: define.h:761
char * object_get_name_s(const object *op, const object *caller)
Definition: item.c:398
int push_ob(object *op, int dir, object *pusher)
Definition: move.c:284
int16_t y
Definition: object.h:276
int8_t direction
Definition: object.h:350
#define FLAG_CAN_ROLL
Definition: define.h:950
struct mapdef * map
Definition: object.h:139
int16_t x
Definition: object.h:273
int freearr_x[SIZEOFFREE]
Definition: object.c:84
void command_push(object *op, const char *command, char *params)
Definition: push.c:36
int move_ob(object *op, int dir, object *originator)
Definition: move.c:155
Definition: map.h:536
int freearr_y[SIZEOFFREE]
Definition: object.c:99