1 | /* |
1 | /* |
2 | * CrossFire, A Multiplayer game for X-windows |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 | * |
3 | * |
4 | * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team |
4 | * Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * Copyright (C) 2003 Mark Wedel & Crossfire Development Team |
5 | * Copyright (©) 2003 Mark Wedel & Crossfire Development Team |
6 | * Copyright (C) 1992 Frank Tore Johansen |
6 | * Copyright (©) 1992 Frank Tore Johansen |
7 | * |
7 | * |
8 | * This program is free software; you can redistribute it and/or modify |
8 | * Deliantra is free software: you can redistribute it and/or modify it under |
9 | * it under the terms of the GNU General Public License as published by |
9 | * the terms of the Affero GNU General Public License as published by the |
10 | * the Free Software Foundation; either version 2 of the License, or |
10 | * Free Software Foundation, either version 3 of the License, or (at your |
11 | * (at your option) any later version. |
11 | * option) any later version. |
12 | * |
12 | * |
13 | * This program is distributed in the hope that it will be useful, |
13 | * This program is distributed in the hope that it will be useful, |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | * GNU General Public License for more details. |
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 | * |
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 at <crossfire@schmorp.de> |
22 | * The authors can be reached via e-mail to <support@deliantra.net> |
23 | */ |
23 | */ |
24 | |
24 | |
25 | #include <global.h> |
25 | #include <global.h> |
26 | #include <sproto.h> |
26 | #include <sproto.h> |
27 | #include <spells.h> |
27 | #include <spells.h> |
28 | |
28 | |
29 | #ifndef sqr |
29 | #ifndef sqr |
30 | # define sqr(x) ((x)*(x)) |
30 | # define sqr(x) ((x)*(x)) |
31 | #endif |
31 | #endif |
32 | |
32 | |
33 | /* peterm: |
33 | /* peterm: |
34 | * write_rune: |
34 | * write_rune: |
35 | * op: rune writer |
35 | * op: rune writer |
36 | * skop: skill object used for casting this rune |
36 | * skop: skill object used for casting this rune |
37 | * dir: orientation of rune, direction rune's contained spell will |
37 | * dir: orientation of rune, direction rune's contained spell will |
38 | * be cast in, if applicable |
38 | * be cast in, if applicable |
39 | * inspell: spell object to put into the rune, can be null if doing |
39 | * spell: spell object to put into the rune |
40 | * a marking rune. |
|
|
41 | * level: level of casting of the rune |
40 | * level: level of casting of the rune |
42 | * 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 |
43 | * a rune of marking |
42 | * a rune of marking |
44 | */ |
43 | */ |
45 | |
|
|
46 | int |
44 | int |
47 | write_rune (object *op, object *caster, object *spell, int dir, const char *runename) |
45 | write_rune (object *op, object *caster, object *spell, int dir, const char *runename) |
48 | { |
46 | { |
49 | object *tmp, *rune_spell, *rune; |
47 | object *tmp, *rune_spell, *rune; |
50 | char buf[MAX_BUF]; |
|
|
51 | maptile *m; |
48 | maptile *m; |
52 | sint16 nx, ny; |
49 | sint16 nx, ny; |
53 | |
50 | |
54 | if (!dir) |
51 | if (!dir) |
55 | dir = 1; |
52 | dir = 1; |
… | |
… | |
73 | new_draw_info (NDI_UNIQUE, 0, op, "You can't write a rune on top of another rune."); |
70 | new_draw_info (NDI_UNIQUE, 0, op, "You can't write a rune on top of another rune."); |
74 | return 0; |
71 | return 0; |
75 | } |
72 | } |
76 | |
73 | |
77 | if (spell->other_arch) |
74 | if (spell->other_arch) |
78 | rune_spell = arch_to_object (spell->other_arch); |
75 | rune_spell = spell->other_arch->instance (); |
79 | else |
76 | else |
80 | { |
77 | { |
81 | /* Player specified spell. The player has to know the spell, so |
78 | /* Player specified spell. The player has to know the spell, so |
82 | * 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 |
83 | * use the item_matched_string for our typical matching method. |
80 | * use the item_matched_string for our typical matching method. |
… | |
… | |
102 | } |
99 | } |
103 | } |
100 | } |
104 | |
101 | |
105 | if (!rune_spell) |
102 | if (!rune_spell) |
106 | { |
103 | { |
107 | new_draw_info_format (NDI_UNIQUE, 0, op, "You don't know any spell named %s", runename); |
104 | new_draw_info_format (NDI_UNIQUE, 0, op, "You don't know any spell named %s.", runename); |
108 | return 0; |
105 | return 0; |
109 | } |
106 | } |
110 | |
107 | |
111 | if (rune_spell->skill != spell->skill) |
108 | if (rune_spell->skill != spell->skill) |
112 | { |
109 | { |
113 | new_draw_info_format (NDI_UNIQUE, 0, op, "You can't cast %s with %s", &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); |
114 | return 0; |
111 | return 0; |
115 | } |
112 | } |
116 | |
113 | |
117 | if (caster->path_denied & spell->path_attuned && !caster->flag [FLAG_WIZCAST]) |
114 | if (caster->path_denied & spell->path_attuned && !caster->flag [FLAG_WIZCAST]) |
118 | { |
115 | { |
119 | new_draw_info_format (NDI_UNIQUE, 0, op, "%s belongs to a spell path denied to you.", &rune_spell->name); |
116 | new_draw_info_format (NDI_UNIQUE, 0, op, "%s belongs to a spell path denied to you.", &rune_spell->name); |
120 | return 0; |
117 | return 0; |
121 | } |
118 | } |
122 | |
119 | |
123 | if (caster_level (caster, rune_spell) < rune_spell->level && !caster->flag [FLAG_WIZCAST]) |
120 | if (casting_level (caster, rune_spell) < rune_spell->level && !caster->flag [FLAG_WIZCAST]) |
124 | { |
121 | { |
125 | new_draw_info_format (NDI_UNIQUE, 0, op, "%s is beyond your ability to cast!", &rune_spell->name); |
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); |
126 | return 0; |
123 | return 0; |
127 | } |
124 | } |
128 | |
125 | |
129 | 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) |
130 | { |
127 | { |
… | |
… | |
137 | 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."); |
138 | return 0; |
135 | return 0; |
139 | } |
136 | } |
140 | |
137 | |
141 | 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); |
142 | 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); |
143 | } |
140 | } |
144 | |
141 | |
145 | /* 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 */ |
146 | if (rune_spell->type == RUNE) |
143 | if (rune_spell->type == RUNE) |
147 | rune = rune_spell; |
144 | rune = rune_spell; |
148 | else |
145 | else |
149 | { |
146 | { |
150 | rune = get_archetype (GENERIC_RUNE); |
147 | rune = archetype::get (GENERIC_RUNE); |
151 | 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); |
152 | rune->msg = buf; |
|
|
153 | rune->insert (rune_spell->clone ()); |
149 | rune->insert (rune_spell->clone ()); |
154 | |
150 | |
155 | if (spell->face != blank_face) |
151 | if (spell->face != blank_face) |
156 | rune->face = spell->face; |
152 | rune->face = spell->face; |
157 | } |
153 | } |
158 | |
154 | |
159 | rune->level = caster_level (caster, spell); |
155 | rune->level = casting_level (caster, spell); |
160 | rune->stats.Cha = rune->level / 2; /* the invisibility parameter */ |
156 | rune->stats.Cha = rune->level / 2; /* the invisibility parameter */ |
161 | rune->direction = dir; /* where any spell will go upon detonation */ |
157 | rune->direction = dir; /* where any spell will go upon detonation */ |
162 | rune->set_owner (op); /* runes without need no owner */ |
158 | rune->set_owner (op); /* runes without need no owner */ |
163 | set_spell_skill (op, caster, spell, rune); |
159 | set_spell_skill (op, caster, spell, rune); |
164 | |
160 | |
… | |
… | |
185 | if (!op->level) |
181 | if (!op->level) |
186 | return; |
182 | return; |
187 | |
183 | |
188 | int det = op->invisible; |
184 | int det = op->invisible; |
189 | |
185 | |
190 | if (!(rndm (0, MAX (1, (op->stats.Cha)) - 1))) |
186 | if (!(rndm (0, max (0, op->stats.Cha - 1)))) |
191 | { |
187 | { |
192 | op->invisible = 0; |
188 | op->invisible = 0; |
193 | op->speed_left -= 1; |
189 | op->speed_left -= 1; |
194 | } |
190 | } |
195 | else |
191 | else |
196 | op->invisible = 1; |
192 | op->invisible = 1; |
197 | |
193 | |
198 | if (op->invisible != det) |
194 | if (op->invisible != det) |
199 | update_object (op, UP_OBJ_FACE); |
195 | update_object (op, UP_OBJ_CHANGE); |
200 | } |
196 | } |
201 | |
|
|
202 | |
197 | |
203 | /* peterm: rune_attack |
198 | /* peterm: rune_attack |
204 | * function handles those runes which detonate but do not cast spells. |
199 | * function handles those runes which detonate but do not cast spells. |
205 | */ |
200 | */ |
206 | |
201 | static void |
207 | |
|
|
208 | void |
|
|
209 | rune_attack (object *op, object *victim) |
202 | rune_attack (object *op, object *victim) |
210 | { |
203 | { |
211 | if (victim) |
204 | if (victim) |
212 | { |
205 | { |
213 | hit_player (victim, op->stats.dam, op, op->attacktype, 1); |
206 | hit_player (victim, op->stats.dam, op, op->attacktype, 1); |
… | |
… | |
230 | else |
223 | else |
231 | hit_map (op, 0, op->attacktype, 1); |
224 | hit_map (op, 0, op->attacktype, 1); |
232 | } |
225 | } |
233 | |
226 | |
234 | /* This function generalizes attacks by runes/traps. This ought to make |
227 | /* This function generalizes attacks by runes/traps. This ought to make |
235 | * it possible for runes to attack from the inventory, |
228 | * it possible for runes to attack from the inventory, |
236 | * it'll spring the trap on the victim. |
229 | * it'll spring the trap on the victim. |
237 | */ |
230 | */ |
238 | void |
231 | void |
239 | spring_trap (object *trap, object *victim) |
232 | spring_trap (object *trap, object *victim) |
240 | { |
233 | { |
… | |
… | |
244 | |
237 | |
245 | /* Prevent recursion */ |
238 | /* Prevent recursion */ |
246 | if (trap->stats.hp <= 0) |
239 | if (trap->stats.hp <= 0) |
247 | return; |
240 | return; |
248 | |
241 | |
249 | if (QUERY_FLAG (trap, FLAG_IS_LINKED)) |
242 | if (trap->flag [FLAG_IS_LINKED]) |
250 | use_trigger (trap); |
243 | use_trigger (trap, victim); |
251 | |
244 | |
252 | /* Only living objects can trigger runes that don't cast spells, as |
245 | /* Only living objects can trigger runes that don't cast spells, as |
253 | * doing direct damage to a non-living object doesn't work anyway. |
246 | * doing direct damage to a non-living object doesn't work anyway. |
254 | * Typical example is an arrow attacking a door. |
247 | * Typical example is an arrow attacking a door. |
255 | */ |
248 | */ |
256 | if (!QUERY_FLAG (victim, FLAG_ALIVE) && !trap->inv && !trap->other_arch) |
249 | if (!victim->flag [FLAG_ALIVE] && !trap->inv && !trap->other_arch) |
257 | return; |
250 | return; |
258 | |
251 | |
259 | trap->stats.hp--; /*decrement detcount */ |
252 | trap->stats.hp--; /*decrement detcount */ |
260 | |
253 | |
261 | if (victim && victim->type == PLAYER) |
254 | if (victim && victim->type == PLAYER) |
262 | new_draw_info (NDI_UNIQUE, 0, victim, trap->msg); |
255 | new_draw_info (NDI_UNIQUE, 0, victim, trap->msg); |
263 | |
256 | |
264 | /* Flash an image of the trap on the map so the poor sod |
257 | /* Flash an image of the trap on the map so the poor sod |
265 | * knows what hit him. |
258 | * knows what hit him. |
266 | */ |
259 | */ |
267 | env = object_get_env_recursive (trap); |
260 | env = trap->outer_env_or_self (); |
268 | |
261 | |
269 | /* If the victim is not next to this trap, don't set it off. |
262 | /* If the victim is not next to this trap, don't set it off. |
270 | * players shouldn't get hit by firing arrows at a door for example. |
263 | * players shouldn't get hit by firing arrows at a door for example. |
271 | * At the same time, the trap will stick around until detonated |
264 | * At the same time, the trap will stick around until detonated |
272 | */ |
265 | */ |
273 | get_rangevector (env, victim, &rv, 0); |
266 | get_rangevector (env, victim, &rv, 0); |
274 | if (rv.distance > 1) |
267 | if (rv.distance > 1) |
275 | return; |
268 | return; |
276 | |
269 | |
|
|
270 | env->play_sound (trap->sound ? trap->sound : sound_find ("trap_spring")); |
|
|
271 | |
277 | trap_show (trap, env); |
272 | trap_show (trap, env); |
278 | |
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 | |
279 | /* Only if it is a spell do we proceed here */ |
278 | /* Only if it is a spell do we proceed here */ |
280 | if ((trap->inv && trap->inv->type == SPELL) || (trap->other_arch && trap->other_arch->clone.type == SPELL)) |
279 | if ((trap->inv && trap->inv->type == SPELL) || (trap->other_arch && trap->other_arch->type == SPELL)) |
281 | { |
280 | { |
282 | |
|
|
283 | if (trap->destroyed ()) |
281 | if (trap->destroyed ()) |
284 | return; |
282 | return; |
285 | |
283 | |
286 | // breaks summon golem spells, which, for inexplicable reasons, |
284 | // breaks summon golem spells, which, for inexplicable reasons, |
287 | // do not work like summon golem spells at all but still require |
285 | // do not work like summon golem spells at all but still require |
288 | // direction "0" to work at all. |
286 | // direction "0" to work at all. |
289 | //if (trap->direction) |
287 | //if (trap->direction) |
290 | // rv.direction = trap->direction; |
288 | // rv.direction = trap->direction; |
291 | |
289 | |
292 | for (i = 0; i < MAX (1, trap->stats.maxhp); i++) |
290 | for (i = 0; i < max (1, trap->stats.maxhp); i++) |
293 | { |
291 | { |
294 | if (trap->inv) |
292 | if (trap->inv) |
295 | cast_spell (env, trap, trap->direction, trap->inv, NULL); |
293 | cast_spell (env, trap, trap->direction, trap->inv, NULL); |
296 | else |
294 | else |
297 | { |
295 | { |
298 | object *spell = arch_to_object (trap->other_arch); |
296 | object *spell = trap->other_arch->instance (); |
299 | |
297 | |
300 | cast_spell (env, trap, trap->direction, spell, NULL); |
298 | cast_spell (env, trap, trap->direction, spell, NULL); |
301 | spell->destroy (); |
299 | spell->destroy (); |
302 | } |
300 | } |
303 | } |
301 | } |
… | |
… | |
311 | |
309 | |
312 | if (trap->stats.hp <= 0) |
310 | if (trap->stats.hp <= 0) |
313 | { |
311 | { |
314 | trap->type = SIGN; /* make the trap impotent */ |
312 | trap->type = SIGN; /* make the trap impotent */ |
315 | 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 */ |
316 | SET_FLAG (trap, FLAG_IS_USED_UP); |
314 | trap->set_flag (FLAG_IS_USED_UP); |
317 | } |
315 | } |
318 | } |
316 | } |
319 | |
317 | |
320 | /* dispel_rune: by peterm |
318 | /* dispel_rune: by peterm |
321 | * dispels the target rune, depending on the level of the actor |
319 | * dispels the target rune, depending on the level of the actor |
322 | * 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 |
323 | * a chance that the trap/rune will detonate |
321 | * a chance that the trap/rune will detonate |
324 | */ |
322 | */ |
325 | int |
323 | int |
326 | dispel_rune (object *op, object *caster, object *spell, object *skill, int dir) |
324 | dispel_rune (object *op, object *caster, object *spell, object *skill, int dir) |
327 | { |
325 | { |
328 | object *tmp, *tmp2; |
326 | object *tmp, *tmp2; |
… | |
… | |
335 | m = op->map; |
333 | m = op->map; |
336 | |
334 | |
337 | mflags = get_map_flags (m, &m, x, y, &x, &y); |
335 | mflags = get_map_flags (m, &m, x, y, &x, &y); |
338 | |
336 | |
339 | /* 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/ |
340 | * player is standing on top? |
338 | * player is standing on top? |
341 | */ |
339 | */ |
342 | if (mflags & P_OUT_OF_MAP) |
340 | if (mflags & P_OUT_OF_MAP) |
343 | { |
341 | { |
344 | new_draw_info (NDI_UNIQUE, 0, op, "There's nothing there!"); |
342 | new_draw_info (NDI_UNIQUE, 0, op, "There's nothing there!"); |
345 | return 0; |
343 | return 0; |
346 | } |
344 | } |
347 | |
345 | |
348 | for (tmp = GET_MAP_OB (m, x, y); tmp != NULL; tmp = tmp->above) |
346 | for (tmp = GET_MAP_OB (m, x, y); tmp; tmp = tmp->above) |
349 | { |
347 | { |
350 | if (tmp->type == RUNE || tmp->type == TRAP) |
348 | if (tmp->type == RUNE || tmp->type == TRAP) |
351 | break; |
349 | break; |
352 | |
350 | |
353 | /* we could put a probability chance here, but since nothing happens |
351 | /* we could put a probability chance here, but since nothing happens |
354 | * 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 |
355 | * 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. |
356 | */ |
354 | */ |
357 | if (tmp->type == SIGN && !strcmp (tmp->arch->name, "rune_mark")) |
355 | if (tmp->type == SIGN && tmp->arch->archname == shstr_rune_mark) |
358 | { |
356 | { |
359 | tmp->destroy (); |
357 | tmp->destroy (); |
360 | 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!"); |
361 | return 1; |
359 | return 1; |
362 | } |
360 | } |
363 | |
361 | |
364 | /* now search tmp's inventory for traps |
362 | /* now search tmp's inventory for traps |
365 | * 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. |
366 | */ |
364 | */ |
367 | for (tmp2 = tmp->inv; tmp2 != NULL; tmp2 = tmp2->below) |
365 | for (tmp2 = tmp->inv; tmp2; tmp2 = tmp2->below) |
368 | { |
366 | { |
369 | if (tmp2->type == RUNE || tmp2->type == TRAP) |
367 | if (tmp2->type == RUNE || tmp2->type == TRAP) |
370 | { |
368 | { |
371 | tmp = tmp2; |
369 | tmp = tmp2; |
372 | searchflag = 0; |
370 | searchflag = 0; |
373 | break; |
371 | break; |
374 | } |
372 | } |
375 | } |
373 | } |
|
|
374 | |
376 | if (!searchflag) |
375 | if (!searchflag) |
377 | break; |
376 | break; |
378 | } |
377 | } |
379 | |
378 | |
380 | /* no rune there. */ |
379 | /* no rune there. */ |
381 | if (tmp == NULL) |
380 | if (tmp == NULL) |
382 | { |
381 | { |
383 | new_draw_info (NDI_UNIQUE, 0, op, "There's nothing there!"); |
382 | new_draw_info (NDI_UNIQUE, 0, op, "There's nothing there!"); |
384 | return 0; |
383 | return 0; |
385 | } |
384 | } |
|
|
385 | |
386 | trap_disarm (op, tmp, 0, skill); |
386 | trap_disarm (op, tmp, 0, skill); |
387 | return 1; |
387 | return 1; |
388 | |
|
|
389 | } |
388 | } |
390 | |
389 | |
391 | int |
390 | int |
392 | trap_see (object *op, object *trap) |
391 | trap_see (object *op, object *trap) |
393 | { |
392 | { |
394 | int chance; |
|
|
395 | |
|
|
396 | chance = random_roll (0, 99, op, PREFER_HIGH);; |
393 | int chance = random_roll (0, 99, op, PREFER_HIGH); |
397 | |
394 | |
398 | /* decide if we see the rune or not */ |
395 | /* decide if we see the rune or not */ |
399 | 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 |
400 | + trap->level + trap->stats.Cha - op->level) / 10.0 * 50.0)))))) |
397 | + trap->level + trap->stats.Cha - op->level) / 10.0 * 50.0)))))) |
401 | { |
398 | { |
402 | 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); |
403 | return 1; |
400 | return 1; |
404 | } |
401 | } |
|
|
402 | |
405 | return 0; |
403 | return 0; |
406 | } |
404 | } |
407 | |
405 | |
408 | int |
406 | int |
409 | trap_show (object *trap, object *where) |
407 | trap_show (object *trap, object *where) |
410 | { |
408 | { |
411 | if (where == NULL) |
409 | if (where == NULL) |
412 | return 0; |
410 | return 0; |
413 | |
411 | |
414 | object *tmp = get_archetype ("runedet"); |
412 | object *tmp = archetype::get (shstr_runedet); |
415 | tmp->face = &new_faces[GET_ANIMATION (trap, 0)]; |
413 | tmp->face = trap->get_anim_frame (0); |
416 | tmp->insert_at (where, 0); |
414 | tmp->insert_at (where, 0); |
417 | |
415 | |
418 | return 1; |
416 | return 1; |
419 | } |
417 | } |
420 | |
418 | |
421 | int |
419 | int |
422 | trap_disarm (object *disarmer, object *trap, int risk, object *skill) |
420 | trap_disarm (object *disarmer, object *trap, int risk, object *skill) |
423 | { |
421 | { |
424 | 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 */ |
425 | before we kill it */ |
|
|
426 | |
423 | |
427 | /* this formula awards a more reasonable amount of exp */ |
424 | /* this formula awards a more reasonable amount of exp */ |
428 | trapworth = MAX (1, trap->level) * disarmer->map->difficulty * |
425 | trapworth = max (1, trap->level) |
|
|
426 | * disarmer->map->difficulty |
429 | sqr (MAX (trap->stats.dam, trap->inv ? trap->inv->level : 1)) / skill->level; |
427 | * sqr (max (trap->stats.dam, trap->inv ? trap->inv->level : 1)) |
|
|
428 | / skill->level; |
430 | |
429 | |
431 | if (!(random_roll (0, (MAX (2, MIN (20, trap->level - skill->level + 5 - disarmer->stats.Dex / 2)) - 1), disarmer, PREFER_LOW))) |
430 | if (!(random_roll (0, (max (2, min (20, trap->level - skill->level + 5 - disarmer->stats.Dex / 2)) - 1), disarmer, PREFER_LOW))) |
432 | { |
431 | { |
433 | new_draw_info_format (NDI_UNIQUE, 0, disarmer, "You successfully disarm the %s!", &trap->name); |
432 | new_draw_info_format (NDI_UNIQUE, 0, disarmer, "You successfully disarm the %s!", &trap->name); |
434 | trap->destroy (1); |
433 | trap->destroy (); |
435 | |
434 | |
436 | /* 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 |
437 | * get exp for it. |
436 | * get exp for it. |
438 | */ |
437 | */ |
439 | if (trap->owner && trap->owner->type != PLAYER && risk) |
438 | if (trap->owner && trap->owner->type != PLAYER && risk) |
… | |
… | |
442 | return 1; /* give minimal exp and say success */ |
441 | return 1; /* give minimal exp and say success */ |
443 | } |
442 | } |
444 | else |
443 | else |
445 | { |
444 | { |
446 | new_draw_info_format (NDI_UNIQUE, 0, disarmer, "You fail to disarm the %s.", &trap->name); |
445 | new_draw_info_format (NDI_UNIQUE, 0, disarmer, "You fail to disarm the %s.", &trap->name); |
447 | if (!(random_roll (0, (MAX (2, skill->level - trap->level + disarmer->stats.Dex / 2 - 6)) - 1, disarmer, PREFER_LOW)) && risk) |
446 | if (!(random_roll (0, (max (2, skill->level - trap->level + disarmer->stats.Dex / 2 - 6)) - 1, disarmer, PREFER_LOW)) && risk) |
448 | { |
447 | { |
449 | 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!"); |
450 | spring_trap (trap, disarmer); |
449 | spring_trap (trap, disarmer); |
451 | } |
450 | } |
452 | return 0; |
451 | return 0; |
453 | } |
452 | } |
454 | } |
453 | } |
455 | |
454 | |
456 | |
|
|
457 | /* 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 |
458 | * default traps are too strong for wimpy level 1 players, and |
456 | * default traps are too strong for wimpy level 1 players, and |
459 | * unthreatening to anyone of high level |
457 | * unthreatening to anyone of high level |
460 | */ |
458 | */ |
461 | |
|
|
462 | void |
459 | void |
463 | trap_adjust (object *trap, int difficulty) |
460 | trap_adjust (object *trap, int difficulty) |
464 | { |
461 | { |
465 | int i; |
462 | int i; |
466 | |
463 | |
467 | /* 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 |
468 | * 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 |
469 | * a peak probability at difficulty |
466 | * a peak probability at difficulty |
470 | */ |
467 | */ |
471 | |
468 | |
472 | trap->level = rndm (0, difficulty - 1) + rndm (0, difficulty - 1); |
469 | trap->level = rndm (0, difficulty - 1) + rndm (0, difficulty - 1); |
473 | if (trap->level < 1) |
470 | if (trap->level < 1) |
474 | trap->level = 1; |
471 | trap->level = 1; |