ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/server/rune.C
(Generate patch)

Comparing deliantra/server/server/rune.C (file contents):
Revision 1.3 by root, Sun Sep 3 00:18:42 2006 UTC vs.
Revision 1.55 by root, Mon Oct 29 23:55:55 2012 UTC

1/* 1/*
2 * static char *rcsid_rune_c = 2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 * "$Id: rune.C,v 1.3 2006/09/03 00:18:42 root Exp $"; 3 *
4 * Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (©) 2003 Mark Wedel & Crossfire Development Team
6 * Copyright (©) 1992 Frank Tore Johansen
7 *
8 * Deliantra is free software: you can redistribute it and/or modify it under
9 * the terms of the Affero GNU General Public License as published by the
10 * Free Software Foundation, either version 3 of the License, or (at your
11 * 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 Affero GNU General Public License
19 * and the GNU General Public License along with this program. If not, see
20 * <http://www.gnu.org/licenses/>.
21 *
22 * The authors can be reached via e-mail to <support@deliantra.net>
4 */ 23 */
5 24
6/*
7 CrossFire, A Multiplayer game for X-windows
8
9 Copyright (C) 2003 Mark Wedel & Crossfire Development Team
10 Copyright (C) 1992 Frank Tore Johansen
11
12 This program is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 2 of the License, or
15 (at your option) any later version.
16
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
21
22 You should have received a copy of the GNU General Public License
23 along with this program; if not, write to the Free Software
24 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25
26 The authors can be reached via e-mail at crossfire-devel@real-time.com
27*/
28
29#include <global.h> 25#include <global.h>
30#ifndef __CEXTRACT__
31#include <sproto.h> 26#include <sproto.h>
27#include <spells.h>
28
29#ifndef sqr
30# define sqr(x) ((x)*(x))
32#endif 31#endif
33#include <spells.h>
34
35
36#ifndef sqr
37#define sqr(x) ((x)*(x))
38#endif
39
40 32
41/* peterm: 33/* peterm:
42 * write_rune: 34 * write_rune:
43 * op: rune writer 35 * op: rune writer
44 * skop: skill object used for casting this rune 36 * skop: skill object used for casting this rune
45 * dir: orientation of rune, direction rune's contained spell will 37 * dir: orientation of rune, direction rune's contained spell will
46 * be cast in, if applicable 38 * be cast in, if applicable
47 * inspell: spell object to put into the rune, can be null if doing 39 * spell: spell object to put into the rune
48 * a marking rune.
49 * level: level of casting of the rune 40 * level: level of casting of the rune
50 * runename: name of the rune or message displayed by the rune for 41 * runename: name of the rune or message displayed by the rune for
51 * a rune of marking 42 * a rune of marking
52 */ 43 */
53 44int
54int write_rune(object *op,object *caster, object *spell, int dir, const char *runename) { 45write_rune (object *op, object *caster, object *spell, int dir, const char *runename)
46{
55 object *tmp, *rune_spell, *rune; 47 object *tmp, *rune_spell, *rune;
56 char buf[MAX_BUF]; 48 maptile *m;
57 mapstruct *m;
58 sint16 nx,ny; 49 sint16 nx, ny;
59 50
60 if(!dir) { 51 if (!dir)
61 dir=1; 52 dir = 1;
62 }
63 53
64 nx=op->x+freearr_x[dir]; 54 nx = op->x + freearr_x[dir];
65 ny=op->y+freearr_y[dir]; 55 ny = op->y + freearr_y[dir];
66 m = op->map; 56 m = op->map;
67 57
68 if (get_map_flags(m, &m, nx, ny, &nx, &ny)) { 58 if (get_map_flags (m, &m, nx, ny, &nx, &ny) & (P_OUT_OF_MAP | P_SAFE | P_NO_MAGIC | P_NO_CLERIC))
59 {
69 new_draw_info(NDI_UNIQUE, 0,op,"Can't make a rune there!"); 60 new_draw_info (NDI_UNIQUE, 0, op, "Can't make a rune there!");
70 return 0;
71 }
72 for(tmp=get_map_ob(m,nx,ny);tmp!=NULL;tmp=tmp->above)
73 if(tmp->type==RUNE) break;
74
75 if(tmp){
76 new_draw_info(NDI_UNIQUE, 0,op,"You can't write a rune there.");
77 return 0; 61 return 0;
78 } 62 }
79 63
64 for (tmp = m->at (nx, ny).bot; tmp; tmp = tmp->above)
65 if (tmp->type == RUNE)
66 break;
67
68 if (tmp)
69 {
70 new_draw_info (NDI_UNIQUE, 0, op, "You can't write a rune on top of another rune.");
71 return 0;
72 }
73
80 if (spell->other_arch) { 74 if (spell->other_arch)
81 rune_spell = arch_to_object(spell->other_arch); 75 rune_spell = spell->other_arch->instance ();
82 } else { 76 else
77 {
83 /* Player specified spell. The player has to know the spell, so 78 /* Player specified spell. The player has to know the spell, so
84 * lets just look through the players inventory see if they know it 79 * lets just look through the players inventory see if they know it
85 * use the item_matched_string for our typical matching method. 80 * use the item_matched_string for our typical matching method.
86 */ 81 */
87 int bestmatch = 0, ms; 82 int bestmatch = 0, ms;
88 83
89 if (!runename || *runename == 0) { 84 if (!runename || *runename == 0)
85 {
90 new_draw_info(NDI_UNIQUE, 0, op, "Write a rune of what?"); 86 new_draw_info (NDI_UNIQUE, 0, op, "Write a rune of what?");
91 return 0; 87 return 0;
92 } 88 }
93 89
94 rune_spell=NULL; 90 rune_spell = NULL;
95 for (tmp=op->inv; tmp; tmp=tmp->below) { 91 for (tmp = op->inv; tmp; tmp = tmp->below)
96 if (tmp->type == SPELL) { 92 if (tmp->type == SPELL)
93 {
97 ms = item_matched_string(op, tmp, runename); 94 ms = item_matched_string (op, tmp, runename);
98 if (ms > bestmatch) { 95 if (ms > bestmatch)
96 {
99 bestmatch = ms; 97 bestmatch = ms;
100 rune_spell = tmp; 98 rune_spell = tmp;
101 } 99 }
102 } 100 }
103 } 101
104 if (!rune_spell) { 102 if (!rune_spell)
103 {
105 new_draw_info_format(NDI_UNIQUE, 0, op, "You don't know any spell named %s", 104 new_draw_info_format (NDI_UNIQUE, 0, op, "You don't know any spell named %s.", runename);
106 runename);
107 return 0; 105 return 0;
108 } 106 }
107
109 if (rune_spell->skill != spell->skill) { 108 if (rune_spell->skill != spell->skill)
110 new_draw_info_format(NDI_UNIQUE, 0, op, "You can't cast %s with %s", 109 {
111 &rune_spell->name, &spell->name); 110 new_draw_info_format (NDI_UNIQUE, 0, op, "You can't cast %s with %s. H<The spell must be of the %s spell school.>", &rune_spell->name, &spell->name, &spell->skill);
112 return 0; 111 return 0;
112 }
113
114 if (caster->path_denied & spell->path_attuned && !caster->flag [FLAG_WIZCAST])
113 } 115 {
114 if (caster->path_denied & spell->path_attuned) {
115 new_draw_info_format(NDI_UNIQUE, 0,op, "%s belongs to a spell path denied to you.", 116 new_draw_info_format (NDI_UNIQUE, 0, op, "%s belongs to a spell path denied to you.", &rune_spell->name);
116 &rune_spell->name);
117 return 0; 117 return 0;
118 }
119
120 if (casting_level (caster, rune_spell) < rune_spell->level && !caster->flag [FLAG_WIZCAST])
118 } 121 {
119 if (caster_level(caster, rune_spell) < rune_spell->level) { 122 new_draw_info_format (NDI_UNIQUE, 0, op, "%s is beyond your ability to cast! H<Your effetcive casting level is too low.>", &rune_spell->name);
120 new_draw_info_format(NDI_UNIQUE, 0,op, "%s is beyond your ability to cast!",
121 &rune_spell->name);
122 return 0; 123 return 0;
123 } 124 }
125
124 if (SP_level_spellpoint_cost(caster, rune_spell, SPELL_MANA) > op->stats.sp) { 126 if (SP_level_spellpoint_cost (caster, rune_spell, SPELL_MANA) > op->stats.sp)
127 {
125 new_draw_info(NDI_UNIQUE, 0,op,"You don't have enough mana."); 128 new_draw_info (NDI_UNIQUE, 0, op, "You don't have enough mana.");
126 return 0; 129 return 0;
127 } 130 }
131
128 if (SP_level_spellpoint_cost(caster, rune_spell, SPELL_GRACE) > op->stats.grace) { 132 if (SP_level_spellpoint_cost (caster, rune_spell, SPELL_GRACE) > op->stats.grace)
133 {
129 new_draw_info(NDI_UNIQUE, 0,op,"You don't have enough grace."); 134 new_draw_info (NDI_UNIQUE, 0, op, "You don't have enough grace.");
130 return 0; 135 return 0;
131 } 136 }
137
132 op->stats.grace -= SP_level_spellpoint_cost(caster, rune_spell, SPELL_GRACE); 138 op->stats.grace -= SP_level_spellpoint_cost (caster, rune_spell, SPELL_GRACE);
133 op->stats.sp -= SP_level_spellpoint_cost(caster, rune_spell, SPELL_MANA); 139 op->stats.sp -= SP_level_spellpoint_cost (caster, rune_spell, SPELL_MANA);
134 } 140 }
141
135 /* already proper rune. Note this should only be the case if other_arch was set */ 142 /* already proper rune. Note this should only be the case if other_arch was set */
136 if (rune_spell->type == RUNE) { 143 if (rune_spell->type == RUNE)
137 rune = rune_spell; 144 rune = rune_spell;
138 } else { 145 else
146 {
139 rune = get_archetype(GENERIC_RUNE); 147 rune = archetype::get (GENERIC_RUNE);
140 sprintf(buf,"You set off a rune of %s\n",&rune_spell->name); 148 rune->msg = format ("You set off a rune of %s\n", &rune_spell->name);
141 rune->msg=buf; 149 rune->insert (rune_spell->clone ());
142 tmp = get_object(); 150
143 copy_object(rune_spell, tmp);
144 insert_ob_in_ob(tmp, rune);
145 if (spell->face != blank_face) 151 if (spell->face != blank_face)
146 rune->face = spell->face; 152 rune->face = spell->face;
147 } 153 }
154
148 rune->level = caster_level(caster, spell); 155 rune->level = casting_level (caster, spell);
149 rune->stats.Cha = rune->level/2; /* the invisibility parameter */ 156 rune->stats.Cha = rune->level / 2; /* the invisibility parameter */
150 rune->x=nx;
151 rune->y=ny;
152 rune->map = m;
153 rune->direction=dir; /* where any spell will go upon detonation */ 157 rune->direction = dir; /* where any spell will go upon detonation */
154 set_owner(rune,op); /* runes without need no owner */ 158 rune->set_owner (op); /* runes without need no owner */
155 set_spell_skill(op, caster, spell, rune); 159 set_spell_skill (op, caster, spell, rune);
156 insert_ob_in_map(rune,m,op,0); 160
161 m->insert (rune, nx, ny, op);
157 return 1; 162 return 1;
158
159} 163}
160
161
162 164
163/* move_rune: peterm 165/* move_rune: peterm
164 comments on runes: 166 comments on runes:
165 rune->level : level at which rune will cast its spell. 167 rune->level : level at which rune will cast its spell.
166 rune->hp : number of detonations before rune goes away 168 rune->hp : number of detonations before rune goes away
170 rune->attacktype: type of damage it does, if not casting spells 172 rune->attacktype: type of damage it does, if not casting spells
171 rune->other_arch: spell in the rune 173 rune->other_arch: spell in the rune
172 rune->Cha : how hidden the rune is 174 rune->Cha : how hidden the rune is
173 rune->maxhp : number of spells the rune casts 175 rune->maxhp : number of spells the rune casts
174*/ 176*/
175 177void
176void move_rune(object *op) { 178move_rune (object *op)
177 int det=0; 179{
178 if(!op->level) {return;} /* runes of level zero cannot detonate. */ 180 /* runes of level zero cannot detonate. */
181 if (!op->level)
182 return;
183
179 det=op->invisible; 184 int det = op->invisible;
185
180 if(!(rndm(0, MAX(1,(op->stats.Cha))-1))) { 186 if (!(rndm (0, max (0, op->stats.Cha - 1))))
187 {
181 op->invisible=0; 188 op->invisible = 0;
182 op->speed_left-=1; 189 op->speed_left -= 1;
183 } 190 }
184 else 191 else
185 op->invisible=1; 192 op->invisible = 1;
193
186 if(op->invisible!=det) 194 if (op->invisible != det)
187 update_object(op,UP_OBJ_FACE); 195 update_object (op, UP_OBJ_CHANGE);
188} 196}
189
190 197
191/* peterm: rune_attack 198/* peterm: rune_attack
192 * function handles those runes which detonate but do not cast spells. 199 * function handles those runes which detonate but do not cast spells.
193 */ 200 */
194 201static void
195
196void rune_attack(object *op,object *victim) 202rune_attack (object *op, object *victim)
197{ 203{
198 if(victim) { 204 if (victim)
199 tag_t tag = victim->count; 205 {
200 hit_player(victim,op->stats.dam,op,op->attacktype,1); 206 hit_player (victim, op->stats.dam, op, op->attacktype, 1);
201 if (was_destroyed (victim, tag)) 207
208 if (victim->destroyed ())
202 return; 209 return;
210
203 /* if there's a disease in the needle, put it in the player */ 211 /* if there's a disease in the needle, put it in the player */
204 if(HAS_RANDOM_ITEMS(op)) create_treasure(op->randomitems,op,0, 212 if (op->has_random_items ())
205 (victim->map?victim->map->difficulty:1),0); 213 create_treasure (op->randomitems, op, 0, (victim->map ? victim->map->difficulty : 1), 0);
214
206 if(op->inv && op->inv->type == DISEASE) { 215 if (op->inv && op->inv->type == DISEASE)
216 {
207 object *disease=op->inv; 217 object *disease = op->inv;
218
208 infect_object(victim, disease, 1); 219 infect_object (victim, disease, 1);
209 remove_ob(disease); 220 disease->destroy ();
210 free_object(disease);
211 } 221 }
212 } 222 }
223 else
213 else hit_map(op,0,op->attacktype,1); 224 hit_map (op, 0, op->attacktype, 1);
214} 225}
215 226
216/* This function generalizes attacks by runes/traps. This ought to make 227/* This function generalizes attacks by runes/traps. This ought to make
217 * it possible for runes to attack from the inventory, 228 * it possible for runes to attack from the inventory,
218 * it'll spring the trap on the victim. 229 * it'll spring the trap on the victim.
219 */ 230 */
231void
220void spring_trap(object *trap,object *victim) 232spring_trap (object *trap, object *victim)
221{ 233{
222 object *env; 234 object *env;
223 tag_t trap_tag = trap->count;
224 rv_vector rv; 235 rv_vector rv;
225 int i; 236 int i;
226 237
227 /* Prevent recursion */ 238 /* Prevent recursion */
228 if (trap->stats.hp <= 0) 239 if (trap->stats.hp <= 0)
240 return;
241
242 if (trap->flag [FLAG_IS_LINKED])
243 use_trigger (trap, victim);
244
245 /* Only living objects can trigger runes that don't cast spells, as
246 * doing direct damage to a non-living object doesn't work anyway.
247 * Typical example is an arrow attacking a door.
248 */
249 if (!victim->flag [FLAG_ALIVE] && !trap->inv && !trap->other_arch)
250 return;
251
252 trap->stats.hp--; /*decrement detcount */
253
254 if (victim && victim->type == PLAYER)
255 new_draw_info (NDI_UNIQUE, 0, victim, trap->msg);
256
257 /* Flash an image of the trap on the map so the poor sod
258 * knows what hit him.
259 */
260 env = trap->outer_env_or_self ();
261
262 /* If the victim is not next to this trap, don't set it off.
263 * players shouldn't get hit by firing arrows at a door for example.
264 * At the same time, the trap will stick around until detonated
265 */
266 get_rangevector (env, victim, &rv, 0);
267 if (rv.distance > 1)
268 return;
269
270 env->play_sound (trap->sound ? trap->sound : sound_find ("trap_spring"));
271
272 trap_show (trap, env);
273
274 if (victim->type == PLAYER) // only count players as enemies
275 trap->enemy = victim; // set the victim as the traps enemy, so that summoned
276 // creatures know who to attack.
277
278 /* Only if it is a spell do we proceed here */
279 if ((trap->inv && trap->inv->type == SPELL) || (trap->other_arch && trap->other_arch->type == SPELL))
280 {
281 if (trap->destroyed ())
229 return; 282 return;
230 283
231 if (QUERY_FLAG(trap,FLAG_IS_LINKED)) 284 // breaks summon golem spells, which, for inexplicable reasons,
232 use_trigger(trap); 285 // do not work like summon golem spells at all but still require
286 // direction "0" to work at all.
287 //if (trap->direction)
288 // rv.direction = trap->direction;
233 289
234 /* Only living objects can trigger runes that don't cast spells, as 290 for (i = 0; i < max (1, trap->stats.maxhp); i++)
235 * doing direct damage to a non-living object doesn't work anyway. 291 {
236 * Typical example is an arrow attacking a door. 292 if (trap->inv)
237 */ 293 cast_spell (env, trap, trap->direction, trap->inv, NULL);
238 if ( ! QUERY_FLAG (victim, FLAG_ALIVE) && !trap->inv && !trap->other_arch) 294 else
295 {
296 object *spell = trap->other_arch->instance ();
297
298 cast_spell (env, trap, trap->direction, spell, NULL);
299 spell->destroy ();
300 }
301 }
302 }
303 else
304 {
305 rune_attack (trap, victim);
306 if (trap->destroyed ())
239 return; 307 return;
240
241 trap->stats.hp--; /*decrement detcount */
242
243 if(victim && victim->type==PLAYER)
244 new_draw_info(NDI_UNIQUE, 0,victim,trap->msg);
245
246 /* Flash an image of the trap on the map so the poor sod
247 * knows what hit him.
248 */
249 env = object_get_env_recursive(trap);
250
251 /* If the victim is not next to this trap, don't set it off.
252 * players shouldn't get hit by firing arrows at a door for example.
253 * At the same time, the trap will stick around until detonated
254 */
255 get_rangevector(env, victim, &rv, 0);
256 if (rv.distance > 1) return;
257
258 trap_show(trap,env);
259
260 /* Only if it is a spell do we proceed here */
261 if ((trap->inv && trap->inv->type == SPELL) ||
262 (trap->other_arch && trap->other_arch->clone.type == SPELL)) {
263
264 if (was_destroyed (trap, trap_tag))
265 return;
266
267 // breaks summon golem spells, which, for inexplicable reasons,
268 // do not work like summon golem spells at all but still require
269 // direction "0" to work at all.
270 //if (trap->direction)
271 // rv.direction = trap->direction;
272
273 for(i = 0; i < MAX(1, trap->stats.maxhp); i++) {
274 if (trap->inv)
275 cast_spell(env,trap,trap->direction,trap->inv,NULL);
276 else {
277 object *spell = arch_to_object(trap->other_arch);
278 cast_spell(env,trap,trap->direction,spell,NULL);
279 free_object(spell);
280 }
281 }
282 } else {
283 rune_attack(trap,victim);
284 if (was_destroyed (trap, trap_tag))
285 return;
286 } 308 }
287 309
288 if (trap->stats.hp <= 0) { 310 if (trap->stats.hp <= 0)
311 {
289 trap->type=SIGN; /* make the trap impotent */ 312 trap->type = SIGN; /* make the trap impotent */
290 trap->stats.food=20; /* make it stick around until its spells are gone */ 313 trap->stats.food = 20; /* make it stick around until its spells are gone */
291 SET_FLAG(trap,FLAG_IS_USED_UP); 314 trap->set_flag (FLAG_IS_USED_UP);
292 } 315 }
293} 316}
294 317
295/* dispel_rune: by peterm 318/* dispel_rune: by peterm
296 * dispels the target rune, depending on the level of the actor 319 * dispels the target rune, depending on the level of the actor
297 * and the level of the rune risk flag, if true, means that there is 320 * and the level of the rune risk flag, if true, means that there is
298 * a chance that the trap/rune will detonate 321 * a chance that the trap/rune will detonate
299 */ 322 */
323int
300int dispel_rune(object *op,object *caster, object *spell, object *skill, int dir) 324dispel_rune (object *op, object *caster, object *spell, object *skill, int dir)
301{ 325{
302 object *tmp,*tmp2; 326 object *tmp, *tmp2;
303 int searchflag = 1, mflags; 327 int searchflag = 1, mflags;
304 sint16 x,y; 328 sint16 x, y;
305 mapstruct *m; 329 maptile *m;
306 330
307 x = op->x+freearr_x[dir]; 331 x = op->x + freearr_x[dir];
308 y = op->y+freearr_y[dir]; 332 y = op->y + freearr_y[dir];
309 m = op->map; 333 m = op->map;
310 334
311 mflags = get_map_flags(m, &m, x, y, &x, &y); 335 mflags = get_map_flags (m, &m, x, y, &x, &y);
312 336
313 /* Should we perhaps not allow player to disable traps if a monster/ 337 /* Should we perhaps not allow player to disable traps if a monster/
314 * player is standing on top? 338 * player is standing on top?
315 */ 339 */
316 if (mflags & P_OUT_OF_MAP) { 340 if (mflags & P_OUT_OF_MAP)
341 {
317 new_draw_info(NDI_UNIQUE, 0,op,"There's nothing there!"); 342 new_draw_info (NDI_UNIQUE, 0, op, "There's nothing there!");
318 return 0; 343 return 0;
344 }
345
346 for (tmp = GET_MAP_OB (m, x, y); tmp; tmp = tmp->above)
319 } 347 {
320
321 for(tmp=get_map_ob(m,x, y); tmp!=NULL; tmp=tmp->above) {
322 if(tmp->type==RUNE || tmp->type==TRAP) break; 348 if (tmp->type == RUNE || tmp->type == TRAP)
349 break;
323 350
324 /* we could put a probability chance here, but since nothing happens 351 /* we could put a probability chance here, but since nothing happens
325 * if you fail, no point on that. I suppose we could do a level 352 * if you fail, no point on that. I suppose we could do a level
326 * comparison so low level players can't erase high level players runes. 353 * comparison so low level players can't erase high level players runes.
327 */ 354 */
328 if (tmp->type == SIGN && !strcmp(tmp->arch->name,"rune_mark")) { 355 if (tmp->type == SIGN && tmp->arch->archname == shstr_rune_mark)
329 remove_ob(tmp); 356 {
330 free_object(tmp); 357 tmp->destroy ();
331 new_draw_info(NDI_UNIQUE, 0,op,"You wipe out the rune of marking!"); 358 new_draw_info (NDI_UNIQUE, 0, op, "You wipe out the rune of marking!");
332 return 1; 359 return 1;
333 } 360 }
334 361
335 /* now search tmp's inventory for traps 362 /* now search tmp's inventory for traps
336 * This is for chests, where the rune is in the chests inventory. 363 * This is for chests, where the rune is in the chests inventory.
337 */ 364 */
338 for(tmp2=tmp->inv;tmp2!=NULL;tmp2=tmp2->below) { 365 for (tmp2 = tmp->inv; tmp2; tmp2 = tmp2->below)
366 {
339 if(tmp2->type==RUNE || tmp2->type==TRAP) { 367 if (tmp2->type == RUNE || tmp2->type == TRAP)
368 {
340 tmp=tmp2; 369 tmp = tmp2;
341 searchflag=0; 370 searchflag = 0;
342 break; 371 break;
343 } 372 }
344 } 373 }
374
345 if(!searchflag) break; 375 if (!searchflag)
376 break;
346 } 377 }
347 378
348 /* no rune there. */ 379 /* no rune there. */
349 if(tmp==NULL) { 380 if (tmp == NULL)
381 {
350 new_draw_info(NDI_UNIQUE, 0,op,"There's nothing there!"); 382 new_draw_info (NDI_UNIQUE, 0, op, "There's nothing there!");
351 return 0; 383 return 0;
352 } 384 }
385
353 trap_disarm(op,tmp,0, skill); 386 trap_disarm (op, tmp, 0, skill);
354 return 1; 387 return 1;
355
356} 388}
357 389
390int
358int trap_see(object *op,object *trap) { 391trap_see (object *op, object *trap)
359 int chance; 392{
360
361 chance = random_roll(0, 99, op, PREFER_HIGH);; 393 int chance = random_roll (0, 99, op, PREFER_HIGH);
362 394
363 /* decide if we see the rune or not */ 395 /* decide if we see the rune or not */
364 if((trap->stats.Cha==1) || (chance > MIN(95,MAX(5,((int)((float) (op->map->difficulty 396 if ((trap->stats.Cha == 1) || (chance > min (95, max (5, ((int) ((float) (op->map->difficulty
365 + trap->level + trap->stats.Cha-op->level)/10.0 * 50.0)))))) { 397 + trap->level + trap->stats.Cha - op->level) / 10.0 * 50.0))))))
398 {
366 new_draw_info_format(NDI_UNIQUE, 0,op,"You spot a %s!",&trap->name); 399 new_draw_info_format (NDI_UNIQUE, 0, op, "You spot a %s!", &trap->name);
367 return 1; 400 return 1;
368 } 401 }
402
403 return 0;
404}
405
406int
407trap_show (object *trap, object *where)
408{
409 if (where == NULL)
369 return 0; 410 return 0;
370}
371 411
372int trap_show(object *trap, object *where) { 412 object *tmp = archetype::get (shstr_runedet);
373 object *tmp2; 413 tmp->face = trap->get_anim_frame (0);
414 tmp->insert_at (where, 0);
374 415
375 if(where==NULL) return 0;
376 tmp2=get_archetype("runedet");
377 tmp2->face=&new_faces[GET_ANIMATION(trap, 0)];
378 tmp2->x=where->x;tmp2->y=where->y;tmp2->map=where->map;
379 insert_ob_in_map(tmp2,where->map,NULL,0);
380 return 1; 416 return 1;
381
382} 417}
383 418
384 419int
385int trap_disarm(object *disarmer, object *trap, int risk, object *skill) { 420trap_disarm (object *disarmer, object *trap, int risk, object *skill)
421{
386 int trapworth; /* need to compute the experience worth of the trap 422 int trapworth; /* need to compute the experience worth of the trap before we kill it */
387 before we kill it */
388 423
389 /* this formula awards a more reasonable amount of exp */ 424 /* this formula awards a more reasonable amount of exp */
390 trapworth = MAX(1,trap->level) * disarmer->map->difficulty * 425 trapworth = max (1, trap->level)
426 * disarmer->map->difficulty
391 sqr(MAX(trap->stats.dam,trap->inv?trap->inv->level:1)) / 427 * sqr (max (trap->stats.dam, trap->inv ? trap->inv->level : 1))
392 skill->level; 428 / skill->level;
393 429
394 if(!(random_roll(0, (MAX(2, MIN(20,trap->level-skill->level 430 if (!(random_roll (0, (max (2, min (20, trap->level - skill->level + 5 - disarmer->stats.Dex / 2)) - 1), disarmer, PREFER_LOW)))
395 +5 - disarmer->stats.Dex/2))-1), disarmer, PREFER_LOW))) 431 {
396 { 432 new_draw_info_format (NDI_UNIQUE, 0, disarmer, "You successfully disarm the %s!", &trap->name);
397 new_draw_info_format(NDI_UNIQUE, 0,disarmer, 433 trap->destroy ();
398 "You successfully disarm the %s!",&trap->name); 434
399 destroy_object(trap);
400 /* If it is your own trap, (or any players trap), don't you don't 435 /* If it is your own trap, (or any players trap), don't you don't
401 * get exp for it. 436 * get exp for it.
402 */ 437 */
403 if (trap->owner && trap->owner->type!=PLAYER && risk) 438 if (trap->owner && trap->owner->type != PLAYER && risk)
404 return trapworth; 439 return trapworth;
405 else return 1; /* give minimal exp and say success */
406 }
407 else 440 else
441 return 1; /* give minimal exp and say success */
442 }
443 else
444 {
445 new_draw_info_format (NDI_UNIQUE, 0, disarmer, "You fail to disarm the %s.", &trap->name);
446 if (!(random_roll (0, (max (2, skill->level - trap->level + disarmer->stats.Dex / 2 - 6)) - 1, disarmer, PREFER_LOW)) && risk)
408 { 447 {
409 new_draw_info_format(NDI_UNIQUE, 0,disarmer,
410 "You fail to disarm the %s.",&trap->name);
411 if(! (random_roll(0, (MAX(2,skill->level-trap->level
412 + disarmer->stats.Dex/2-6))-1, disarmer, PREFER_LOW)) &&risk) {
413 new_draw_info(NDI_UNIQUE, 0,disarmer,"In fact, you set it off!"); 448 new_draw_info (NDI_UNIQUE, 0, disarmer, "In fact, you set it off!");
414 spring_trap(trap,disarmer); 449 spring_trap (trap, disarmer);
415 } 450 }
416 return 0; 451 return 0;
417 } 452 }
418} 453}
419
420 454
421/* traps need to be adjusted for the difficulty of the map. The 455/* traps need to be adjusted for the difficulty of the map. The
422 * default traps are too strong for wimpy level 1 players, and 456 * default traps are too strong for wimpy level 1 players, and
423 * unthreatening to anyone of high level 457 * unthreatening to anyone of high level
424 */ 458 */
425 459void
426void trap_adjust(object *trap, int difficulty) { 460trap_adjust (object *trap, int difficulty)
461{
427 int i; 462 int i;
428 463
429 /* now we set the trap level to match the difficulty of the level 464 /* now we set the trap level to match the difficulty of the level
430 * the formula below will give a level from 1 to (2*difficulty) with 465 * the formula below will give a level from 1 to (2*difficulty) with
431 * a peak probability at difficulty 466 * a peak probability at difficulty
432 */ 467 */
433 468
434 trap->level = rndm(0, difficulty-1) + rndm(0, difficulty-1); 469 trap->level = rndm (0, difficulty - 1) + rndm (0, difficulty - 1);
435 if(trap->level < 1) 470 if (trap->level < 1)
436 trap->level = 1; 471 trap->level = 1;
437 472
438 /* set the hiddenness of the trap, similar formula to above */ 473 /* set the hiddenness of the trap, similar formula to above */
439 trap->stats.Cha = rndm(0, 19) + rndm(0, difficulty-1) + rndm(0, difficulty-1); 474 trap->stats.Cha = rndm (0, 19) + rndm (0, difficulty - 1) + rndm (0, difficulty - 1);
440 475
441 if (!trap->other_arch && !trap->inv) { 476 if (!trap->other_arch && !trap->inv)
477 {
442 /* set the damage of the trap. 478 /* set the damage of the trap.
443 * we get 0-4 pts of damage per level of difficulty of the map in 479 * we get 0-4 pts of damage per level of difficulty of the map in
444 * the trap 480 * the trap
445 */ 481 */
446 482
447 trap->stats.dam = 0; 483 trap->stats.dam = 0;
448 for(i=0;i<difficulty;i++) 484 for (i = 0; i < difficulty; i++)
449 trap->stats.dam+=rndm(0, 4); 485 trap->stats.dam += rndm (0, 4);
450 486
451 /* the poison trap special case */ 487 /* the poison trap special case */
452 if(trap->attacktype & AT_POISON) { 488 if (trap->attacktype & AT_POISON)
489 {
453 trap->stats.dam = rndm(0, difficulty-1); 490 trap->stats.dam = rndm (0, difficulty - 1);
454 if(trap->stats.dam < 1) 491 if (trap->stats.dam < 1)
455 trap->stats.dam = 1; 492 trap->stats.dam = 1;
456 } 493 }
457 494
458 /* so we get an appropriate amnt of exp for AT_DEATH traps */ 495 /* so we get an appropriate amnt of exp for AT_DEATH traps */
459 if(trap->attacktype & AT_DEATH) trap->stats.dam = 127; 496 if (trap->attacktype & AT_DEATH)
497 trap->stats.dam = 127;
460 } 498 }
461 499
462} 500}
463

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines