Atrinik Server  4.0
skills.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 <book.h>
32 #include <skillist.h>
33 #include <object.h>
34 
43 void find_traps(object *pl, int level)
44 {
45  object *tmp, *tmp2;
46  mapstruct *m;
47  int xt, yt, i, suc = 0;
48 
49  /* First we search all around us for runes and traps, which are
50  * all type RUNE */
51  for (i = 0; i < 9; i++) {
52  /* Check everything in the square for trapness */
53  xt = pl->x + freearr_x[i];
54  yt = pl->y + freearr_y[i];
55 
56  if (!(m = get_map_from_coord(pl->map, &xt, &yt))) {
57  continue;
58  }
59 
60  for (tmp = GET_MAP_OB(m, xt, yt); tmp != NULL; tmp = tmp->above) {
61  /* And now we'd better do an inventory traversal of each
62  * of these objects' inventory */
63  if (pl != tmp && (tmp->type == PLAYER || tmp->type == MONSTER)) {
64  continue;
65  }
66 
67  for (tmp2 = tmp->inv; tmp2; tmp2 = tmp2->below) {
68  if (tmp2->type == RUNE) {
69  if (trap_see(pl, tmp2, level)) {
70  trap_show(tmp2, tmp);
71 
72  if (!suc) {
73  suc = 1;
74  }
75  } else {
76  /* Give out a "we have found signs of traps"
77  * if the traps level is not 1.8 times higher. */
78  if (tmp2->level <= (level * 1.8f)) {
79  suc = 2;
80  }
81  }
82  }
83  }
84 
85  if (tmp->type == RUNE) {
86  if (trap_see(pl, tmp, level)) {
87  trap_show(tmp, tmp);
88 
89  if (!suc) {
90  suc = 1;
91  }
92  } else {
93  /* Give out a "we have found signs of traps"
94  * if the traps level is not 1.8 times higher. */
95  if (tmp->level <= (level * 1.8f)) {
96  suc = 2;
97  }
98  }
99  }
100  }
101  }
102 
103  if (!suc) {
104  draw_info(COLOR_WHITE, pl, "You can't detect any trap here.");
105  } else if (suc == 2) {
106  draw_info(COLOR_WHITE, pl, "You detect trap signs!");
107  }
108 }
109 
115 void remove_trap(object *op)
116 {
117  object *tmp, *tmp2;
118  mapstruct *m;
119  int i, x, y;
120 
121  for (i = 0; i < 9; i++) {
122  x = op->x + freearr_x[i];
123  y = op->y + freearr_y[i];
124 
125  if (!(m = get_map_from_coord(op->map, &x, &y))) {
126  continue;
127  }
128 
129  /* Check everything in the square for trapness */
130  for (tmp = GET_MAP_OB(m, x, y); tmp != NULL; tmp = tmp->above) {
131  /* And now we'd better do an inventory traversal of each
132  * of these objects' inventory */
133  for (tmp2 = tmp->inv; tmp2; tmp2 = tmp2->below) {
134  if (tmp2->type == RUNE && tmp2->stats.Int <= 1) {
136  trap_show(tmp2, tmp);
137  }
138 
139  trap_disarm(op, tmp2);
140  return;
141  }
142  }
143 
144  if (tmp->type == RUNE && tmp->stats.Int <= 1) {
146  trap_show(tmp, tmp);
147  }
148 
149  trap_disarm(op, tmp);
150  return;
151  }
152  }
153  }
154 
155  draw_info(COLOR_WHITE, op, "There is no trap to remove nearby.");
156 }
#define MONSTER
Definition: define.h:353
#define FLAG_SYS_OBJECT
Definition: define.h:1243
mapstruct * get_map_from_coord(mapstruct *m, int *x, int *y)
Definition: map.c:1869
struct obj * above
Definition: object.h:120
#define PLAYER
Definition: define.h:122
int trap_disarm(object *disarmer, object *trap)
Definition: rune.c:117
#define QUERY_FLAG(xyz, p)
Definition: define.h:761
int8_t Int
Definition: living.h:112
int16_t y
Definition: object.h:276
struct mapdef * map
Definition: object.h:139
#define FLAG_IS_INVISIBLE
Definition: define.h:888
struct obj * below
Definition: object.h:114
void find_traps(object *pl, int level)
Definition: skills.c:43
int16_t x
Definition: object.h:273
living stats
Definition: object.h:481
int freearr_x[SIZEOFFREE]
Definition: object.c:84
uint8_t type
Definition: object.h:360
#define RUNE
Definition: define.h:522
struct obj * inv
Definition: object.h:123
void remove_trap(object *op)
Definition: skills.c:115
int trap_show(object *trap, object *where)
Definition: rune.c:73
int trap_see(object *op, object *trap, int level)
Definition: rune.c:46
Definition: map.h:536
int8_t level
Definition: object.h:347
int freearr_y[SIZEOFFREE]
Definition: object.c:99