Atrinik Server  4.0
rune.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 <player.h>
32 #include <object.h>
33 #include <rune.h>
34 
46 int trap_see(object *op, object *trap, int level)
47 {
48  int chance = rndm(0, 99);
49 
50  /* Decide if we can see the rune or not */
51  if ((trap->level <= level && rndm_chance(10)) || trap->stats.Int == 1 || (chance > MIN(95, MAX(5, ((int) ((float) (op->map->difficulty + trap->level + trap->stats.Int - op->level) / 10.0 * 50.0)))))) {
52  draw_info_format(COLOR_WHITE, op, "You spot a %s (lvl %d)!", trap->name, trap->level);
53 
54  if (trap->stats.Int != 1) {
55  CONTR(op)->stat_traps_found++;
56  }
57 
58  return 1;
59  }
60 
61  return 0;
62 }
63 
73 int trap_show(object *trap, object *where)
74 {
75  object *env;
76 
77  if (where == NULL) {
78  return 0;
79  }
80 
81  env = trap->env;
82 
83  if (!QUERY_FLAG(trap, FLAG_REMOVED)) {
84  /* We must remove and reinsert it so the layer is updated correctly. */
85  object_remove(trap, 0);
86  }
87 
89  CLEAR_MULTI_FLAG(trap, FLAG_IS_INVISIBLE);
90  trap->layer = LAYER_EFFECT;
91 
92  /* The trap is not hidden anymore. */
93  if (trap->stats.Int > 1) {
94  trap->stats.Int = 1;
95  }
96 
97  if (env && env->type != PLAYER && env->type != MONSTER &&
98  env->type != DOOR && !QUERY_FLAG(env, FLAG_NO_PASS)) {
99  object_insert_into(trap, env, 0);
100  set_trapped_flag(env);
101  } else if (where->map != NULL) {
102  object_insert_map(trap, where->map, NULL, 0);
103  }
104 
105  return 1;
106 }
107 
117 int trap_disarm(object *disarmer, object *trap)
118 {
119  object *env = trap->env;
120  int disarmer_level = disarmer->level;
121 
122  if ((trap->level <= disarmer_level && rndm_chance(10)) || !(rndm(0, (MAX(2, MIN(20, trap->level - disarmer_level + 5 - disarmer->stats.Dex / 2)) - 1)))) {
123  draw_info_format(COLOR_WHITE, disarmer, "You successfully remove the %s (lvl %d)!", trap->name, trap->level);
124  object_remove(trap, 0);
125  set_trapped_flag(env);
126  CONTR(disarmer)->stat_traps_disarmed++;
127  return 1;
128  } else {
129  draw_info_format(COLOR_WHITE, disarmer, "You fail to remove the %s (lvl %d).", trap->name, trap->level);
130 
131  if (trap->level > disarmer_level * 1.4f || rndm(0, 2)) {
132  if (!(rndm(0, (MAX(2, disarmer_level - trap->level + disarmer->stats.Dex / 2 - 6)) - 1))) {
133  draw_info(COLOR_WHITE, disarmer, "In fact, you set it off!");
134  rune_spring(trap, disarmer);
135  }
136  }
137 
138  return 0;
139  }
140 }
#define MONSTER
Definition: define.h:353
#define FLAG_SYS_OBJECT
Definition: define.h:1243
uint8_t layer
Definition: object.h:405
#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
void object_remove(object *op, int flags)
Definition: object.c:1623
object * object_insert_into(object *op, object *where, int flag)
Definition: object.c:2158
struct mapdef * map
Definition: object.h:139
#define FLAG_IS_INVISIBLE
Definition: define.h:888
const char * name
Definition: object.h:168
struct obj * env
Definition: object.h:130
#define FLAG_REMOVED
Definition: define.h:930
object * object_insert_map(object *op, mapstruct *m, object *originator, int flag)
Definition: object.c:1741
int difficulty
Definition: map.h:650
#define LAYER_EFFECT
Definition: map.h:61
living stats
Definition: object.h:481
int8_t Dex
Definition: living.h:106
uint8_t type
Definition: object.h:360
#define CLEAR_FLAG(xyz, p)
Definition: define.h:751
void rune_spring(object *op, object *victim)
Definition: rune.c:48
#define DOOR
Definition: define.h:194
void set_trapped_flag(object *op)
Definition: item.c:1386
#define FLAG_NO_PASS
Definition: define.h:908
int trap_show(object *trap, object *where)
Definition: rune.c:73
int trap_see(object *op, object *trap, int level)
Definition: rune.c:46
int8_t level
Definition: object.h:347