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 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * Copyright (C) 2003 Mark Wedel & Crossfire Development Team |
5 | * Copyright (©) 2003,2007 Mark Wedel & Crossfire Development Team |
6 | * Copyright (C) 1992 Frank Tore Johansen |
6 | * Copyright (©) 1992,2007 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 |
9 | * it under the terms of the GNU General Public License as published by |
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 |
10 | * the Free Software Foundation, either version 3 of the License, or |
11 | * (at your option) any later version. |
11 | * (at your 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 | * |
17 | * |
18 | * You should have received a copy of the GNU General Public License |
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 |
19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
|
|
21 | * |
20 | * |
22 | * The authors can be reached via e-mail at <crossfire@schmorp.de> |
21 | * The authors can be reached via e-mail to <support@deliantra.net> |
23 | */ |
22 | */ |
24 | |
23 | |
25 | #include <global.h> |
24 | #include <global.h> |
26 | #include <sproto.h> |
25 | #include <sproto.h> |
27 | #include <spells.h> |
26 | #include <spells.h> |
… | |
… | |
56 | |
55 | |
57 | nx = op->x + freearr_x[dir]; |
56 | nx = op->x + freearr_x[dir]; |
58 | ny = op->y + freearr_y[dir]; |
57 | ny = op->y + freearr_y[dir]; |
59 | m = op->map; |
58 | m = op->map; |
60 | |
59 | |
61 | if (get_map_flags (m, &m, nx, ny, &nx, &ny) && (P_OUT_OF_MAP | P_SAFE | P_NO_MAGIC | P_NO_CLERIC)) |
60 | if (get_map_flags (m, &m, nx, ny, &nx, &ny) & (P_OUT_OF_MAP | P_SAFE | P_NO_MAGIC | P_NO_CLERIC)) |
62 | { |
61 | { |
63 | new_draw_info (NDI_UNIQUE, 0, op, "Can't make a rune there!"); |
62 | new_draw_info (NDI_UNIQUE, 0, op, "Can't make a rune there!"); |
64 | return 0; |
63 | return 0; |
65 | } |
64 | } |
66 | |
65 | |
… | |
… | |
68 | if (tmp->type == RUNE) |
67 | if (tmp->type == RUNE) |
69 | break; |
68 | break; |
70 | |
69 | |
71 | if (tmp) |
70 | if (tmp) |
72 | { |
71 | { |
73 | new_draw_info (NDI_UNIQUE, 0, op, "You can't write a rune there."); |
72 | new_draw_info (NDI_UNIQUE, 0, op, "You can't write a rune on top of another rune."); |
74 | return 0; |
73 | return 0; |
75 | } |
74 | } |
76 | |
75 | |
77 | if (spell->other_arch) |
76 | if (spell->other_arch) |
78 | rune_spell = arch_to_object (spell->other_arch); |
77 | rune_spell = arch_to_object (spell->other_arch); |
… | |
… | |
90 | return 0; |
89 | return 0; |
91 | } |
90 | } |
92 | |
91 | |
93 | rune_spell = NULL; |
92 | rune_spell = NULL; |
94 | for (tmp = op->inv; tmp; tmp = tmp->below) |
93 | for (tmp = op->inv; tmp; tmp = tmp->below) |
95 | { |
|
|
96 | if (tmp->type == SPELL) |
94 | if (tmp->type == SPELL) |
97 | { |
95 | { |
98 | ms = item_matched_string (op, tmp, runename); |
96 | ms = item_matched_string (op, tmp, runename); |
99 | if (ms > bestmatch) |
97 | if (ms > bestmatch) |
100 | { |
98 | { |
101 | bestmatch = ms; |
99 | bestmatch = ms; |
102 | rune_spell = tmp; |
100 | rune_spell = tmp; |
103 | } |
101 | } |
104 | } |
102 | } |
105 | } |
|
|
106 | |
103 | |
107 | if (!rune_spell) |
104 | if (!rune_spell) |
108 | { |
105 | { |
109 | new_draw_info_format (NDI_UNIQUE, 0, op, "You don't know any spell named %s", runename); |
106 | new_draw_info_format (NDI_UNIQUE, 0, op, "You don't know any spell named %s", runename); |
110 | return 0; |
107 | return 0; |
… | |
… | |
114 | { |
111 | { |
115 | new_draw_info_format (NDI_UNIQUE, 0, op, "You can't cast %s with %s", &rune_spell->name, &spell->name); |
112 | new_draw_info_format (NDI_UNIQUE, 0, op, "You can't cast %s with %s", &rune_spell->name, &spell->name); |
116 | return 0; |
113 | return 0; |
117 | } |
114 | } |
118 | |
115 | |
119 | if (caster->path_denied & spell->path_attuned) |
116 | if (caster->path_denied & spell->path_attuned && !caster->flag [FLAG_WIZCAST]) |
120 | { |
117 | { |
121 | new_draw_info_format (NDI_UNIQUE, 0, op, "%s belongs to a spell path denied to you.", &rune_spell->name); |
118 | new_draw_info_format (NDI_UNIQUE, 0, op, "%s belongs to a spell path denied to you.", &rune_spell->name); |
122 | return 0; |
119 | return 0; |
123 | } |
120 | } |
124 | |
121 | |
125 | if (caster_level (caster, rune_spell) < rune_spell->level) |
122 | if (casting_level (caster, rune_spell) < rune_spell->level && !caster->flag [FLAG_WIZCAST]) |
126 | { |
123 | { |
127 | new_draw_info_format (NDI_UNIQUE, 0, op, "%s is beyond your ability to cast!", &rune_spell->name); |
124 | new_draw_info_format (NDI_UNIQUE, 0, op, "%s is beyond your ability to cast!", &rune_spell->name); |
128 | return 0; |
125 | return 0; |
129 | } |
126 | } |
130 | |
127 | |
… | |
… | |
156 | |
153 | |
157 | if (spell->face != blank_face) |
154 | if (spell->face != blank_face) |
158 | rune->face = spell->face; |
155 | rune->face = spell->face; |
159 | } |
156 | } |
160 | |
157 | |
161 | rune->level = caster_level (caster, spell); |
158 | rune->level = casting_level (caster, spell); |
162 | rune->stats.Cha = rune->level / 2; /* the invisibility parameter */ |
159 | rune->stats.Cha = rune->level / 2; /* the invisibility parameter */ |
163 | rune->direction = dir; /* where any spell will go upon detonation */ |
160 | rune->direction = dir; /* where any spell will go upon detonation */ |
164 | rune->set_owner (op); /* runes without need no owner */ |
161 | rune->set_owner (op); /* runes without need no owner */ |
165 | set_spell_skill (op, caster, spell, rune); |
162 | set_spell_skill (op, caster, spell, rune); |
166 | |
163 | |
… | |
… | |
196 | } |
193 | } |
197 | else |
194 | else |
198 | op->invisible = 1; |
195 | op->invisible = 1; |
199 | |
196 | |
200 | if (op->invisible != det) |
197 | if (op->invisible != det) |
201 | update_object (op, UP_OBJ_FACE); |
198 | update_object (op, UP_OBJ_CHANGE); |
202 | } |
199 | } |
203 | |
|
|
204 | |
200 | |
205 | /* peterm: rune_attack |
201 | /* peterm: rune_attack |
206 | * function handles those runes which detonate but do not cast spells. |
202 | * function handles those runes which detonate but do not cast spells. |
207 | */ |
203 | */ |
208 | |
|
|
209 | |
|
|
210 | void |
204 | void |
211 | rune_attack (object *op, object *victim) |
205 | rune_attack (object *op, object *victim) |
212 | { |
206 | { |
213 | if (victim) |
207 | if (victim) |
214 | { |
208 | { |
… | |
… | |
224 | if (op->inv && op->inv->type == DISEASE) |
218 | if (op->inv && op->inv->type == DISEASE) |
225 | { |
219 | { |
226 | object *disease = op->inv; |
220 | object *disease = op->inv; |
227 | |
221 | |
228 | infect_object (victim, disease, 1); |
222 | infect_object (victim, disease, 1); |
229 | disease->destroy (); |
223 | disease->destroy (true); |
230 | } |
224 | } |
231 | } |
225 | } |
232 | else |
226 | else |
233 | hit_map (op, 0, op->attacktype, 1); |
227 | hit_map (op, 0, op->attacktype, 1); |
234 | } |
228 | } |
… | |
… | |
264 | new_draw_info (NDI_UNIQUE, 0, victim, trap->msg); |
258 | new_draw_info (NDI_UNIQUE, 0, victim, trap->msg); |
265 | |
259 | |
266 | /* Flash an image of the trap on the map so the poor sod |
260 | /* Flash an image of the trap on the map so the poor sod |
267 | * knows what hit him. |
261 | * knows what hit him. |
268 | */ |
262 | */ |
269 | env = object_get_env_recursive (trap); |
263 | env = trap->outer_env (); |
270 | |
264 | |
271 | /* If the victim is not next to this trap, don't set it off. |
265 | /* If the victim is not next to this trap, don't set it off. |
272 | * players shouldn't get hit by firing arrows at a door for example. |
266 | * players shouldn't get hit by firing arrows at a door for example. |
273 | * At the same time, the trap will stick around until detonated |
267 | * At the same time, the trap will stick around until detonated |
274 | */ |
268 | */ |
275 | get_rangevector (env, victim, &rv, 0); |
269 | get_rangevector (env, victim, &rv, 0); |
276 | if (rv.distance > 1) |
270 | if (rv.distance > 1) |
277 | return; |
271 | return; |
278 | |
272 | |
|
|
273 | env->play_sound (trap->sound ? trap->sound : sound_find ("trap_spring")); |
|
|
274 | |
279 | trap_show (trap, env); |
275 | trap_show (trap, env); |
280 | |
276 | |
|
|
277 | if (victim->type == PLAYER) // only count players as enemies |
|
|
278 | trap->enemy = victim; // set the victim as the traps enemy, so that summoned |
|
|
279 | // creatures know who to attack. |
|
|
280 | |
281 | /* Only if it is a spell do we proceed here */ |
281 | /* Only if it is a spell do we proceed here */ |
282 | if ((trap->inv && trap->inv->type == SPELL) || (trap->other_arch && trap->other_arch->clone.type == SPELL)) |
282 | if ((trap->inv && trap->inv->type == SPELL) || (trap->other_arch && trap->other_arch->type == SPELL)) |
283 | { |
283 | { |
284 | |
|
|
285 | if (trap->destroyed ()) |
284 | if (trap->destroyed ()) |
286 | return; |
285 | return; |
287 | |
286 | |
288 | // breaks summon golem spells, which, for inexplicable reasons, |
287 | // breaks summon golem spells, which, for inexplicable reasons, |
289 | // do not work like summon golem spells at all but still require |
288 | // do not work like summon golem spells at all but still require |
… | |
… | |
298 | else |
297 | else |
299 | { |
298 | { |
300 | object *spell = arch_to_object (trap->other_arch); |
299 | object *spell = arch_to_object (trap->other_arch); |
301 | |
300 | |
302 | cast_spell (env, trap, trap->direction, spell, NULL); |
301 | cast_spell (env, trap, trap->direction, spell, NULL); |
303 | spell->destroy (); |
302 | spell->destroy (true); |
304 | } |
303 | } |
305 | } |
304 | } |
306 | } |
305 | } |
307 | else |
306 | else |
308 | { |
307 | { |
… | |
… | |
354 | |
353 | |
355 | /* we could put a probability chance here, but since nothing happens |
354 | /* we could put a probability chance here, but since nothing happens |
356 | * if you fail, no point on that. I suppose we could do a level |
355 | * if you fail, no point on that. I suppose we could do a level |
357 | * comparison so low level players can't erase high level players runes. |
356 | * comparison so low level players can't erase high level players runes. |
358 | */ |
357 | */ |
359 | if (tmp->type == SIGN && !strcmp (tmp->arch->name, "rune_mark")) |
358 | if (tmp->type == SIGN && !strcmp (tmp->arch->archname, "rune_mark")) |
360 | { |
359 | { |
361 | tmp->destroy (); |
360 | tmp->destroy (true); |
362 | new_draw_info (NDI_UNIQUE, 0, op, "You wipe out the rune of marking!"); |
361 | new_draw_info (NDI_UNIQUE, 0, op, "You wipe out the rune of marking!"); |
363 | return 1; |
362 | return 1; |
364 | } |
363 | } |
365 | |
364 | |
366 | /* now search tmp's inventory for traps |
365 | /* now search tmp's inventory for traps |
… | |
… | |
383 | if (tmp == NULL) |
382 | if (tmp == NULL) |
384 | { |
383 | { |
385 | new_draw_info (NDI_UNIQUE, 0, op, "There's nothing there!"); |
384 | new_draw_info (NDI_UNIQUE, 0, op, "There's nothing there!"); |
386 | return 0; |
385 | return 0; |
387 | } |
386 | } |
|
|
387 | |
388 | trap_disarm (op, tmp, 0, skill); |
388 | trap_disarm (op, tmp, 0, skill); |
389 | return 1; |
389 | return 1; |
390 | |
|
|
391 | } |
390 | } |
392 | |
391 | |
393 | int |
392 | int |
394 | trap_see (object *op, object *trap) |
393 | trap_see (object *op, object *trap) |
395 | { |
394 | { |
… | |
… | |
402 | + trap->level + trap->stats.Cha - op->level) / 10.0 * 50.0)))))) |
401 | + trap->level + trap->stats.Cha - op->level) / 10.0 * 50.0)))))) |
403 | { |
402 | { |
404 | new_draw_info_format (NDI_UNIQUE, 0, op, "You spot a %s!", &trap->name); |
403 | new_draw_info_format (NDI_UNIQUE, 0, op, "You spot a %s!", &trap->name); |
405 | return 1; |
404 | return 1; |
406 | } |
405 | } |
|
|
406 | |
407 | return 0; |
407 | return 0; |
408 | } |
408 | } |
409 | |
409 | |
410 | int |
410 | int |
411 | trap_show (object *trap, object *where) |
411 | trap_show (object *trap, object *where) |
412 | { |
412 | { |
413 | if (where == NULL) |
413 | if (where == NULL) |
414 | return 0; |
414 | return 0; |
415 | |
415 | |
416 | object *tmp = get_archetype ("runedet"); |
416 | object *tmp = get_archetype ("runedet"); |
417 | tmp->face = &new_faces[GET_ANIMATION (trap, 0)]; |
417 | tmp->face = GET_ANIMATION (trap, 0); |
418 | tmp->insert_at (where, 0); |
418 | tmp->insert_at (where, 0); |
419 | |
419 | |
420 | return 1; |
420 | return 1; |
421 | } |
421 | } |
422 | |
422 | |
423 | int |
423 | int |
424 | trap_disarm (object *disarmer, object *trap, int risk, object *skill) |
424 | trap_disarm (object *disarmer, object *trap, int risk, object *skill) |
425 | { |
425 | { |
426 | int trapworth; /* need to compute the experience worth of the trap |
426 | int trapworth; /* need to compute the experience worth of the trap before we kill it */ |
427 | before we kill it */ |
|
|
428 | |
427 | |
429 | /* this formula awards a more reasonable amount of exp */ |
428 | /* this formula awards a more reasonable amount of exp */ |
430 | trapworth = MAX (1, trap->level) * disarmer->map->difficulty * |
429 | trapworth = MAX (1, trap->level) |
|
|
430 | * disarmer->map->difficulty |
431 | sqr (MAX (trap->stats.dam, trap->inv ? trap->inv->level : 1)) / skill->level; |
431 | * sqr (MAX (trap->stats.dam, trap->inv ? trap->inv->level : 1)) |
|
|
432 | / skill->level; |
432 | |
433 | |
433 | if (!(random_roll (0, (MAX (2, MIN (20, trap->level - skill->level + 5 - disarmer->stats.Dex / 2)) - 1), disarmer, PREFER_LOW))) |
434 | if (!(random_roll (0, (MAX (2, MIN (20, trap->level - skill->level + 5 - disarmer->stats.Dex / 2)) - 1), disarmer, PREFER_LOW))) |
434 | { |
435 | { |
435 | new_draw_info_format (NDI_UNIQUE, 0, disarmer, "You successfully disarm the %s!", &trap->name); |
436 | new_draw_info_format (NDI_UNIQUE, 0, disarmer, "You successfully disarm the %s!", &trap->name); |
436 | trap->destroy (1); |
437 | trap->destroy (true); |
437 | |
438 | |
438 | /* If it is your own trap, (or any players trap), don't you don't |
439 | /* If it is your own trap, (or any players trap), don't you don't |
439 | * get exp for it. |
440 | * get exp for it. |
440 | */ |
441 | */ |
441 | if (trap->owner && trap->owner->type != PLAYER && risk) |
442 | if (trap->owner && trap->owner->type != PLAYER && risk) |
… | |
… | |
453 | } |
454 | } |
454 | return 0; |
455 | return 0; |
455 | } |
456 | } |
456 | } |
457 | } |
457 | |
458 | |
458 | |
|
|
459 | /* traps need to be adjusted for the difficulty of the map. The |
459 | /* traps need to be adjusted for the difficulty of the map. The |
460 | * default traps are too strong for wimpy level 1 players, and |
460 | * default traps are too strong for wimpy level 1 players, and |
461 | * unthreatening to anyone of high level |
461 | * unthreatening to anyone of high level |
462 | */ |
462 | */ |
463 | |
|
|
464 | void |
463 | void |
465 | trap_adjust (object *trap, int difficulty) |
464 | trap_adjust (object *trap, int difficulty) |
466 | { |
465 | { |
467 | int i; |
466 | int i; |
468 | |
467 | |