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> |
… | |
… | |
34 | * write_rune: |
33 | * write_rune: |
35 | * op: rune writer |
34 | * op: rune writer |
36 | * skop: skill object used for casting this rune |
35 | * skop: skill object used for casting this rune |
37 | * dir: orientation of rune, direction rune's contained spell will |
36 | * dir: orientation of rune, direction rune's contained spell will |
38 | * be cast in, if applicable |
37 | * be cast in, if applicable |
39 | * inspell: spell object to put into the rune, can be null if doing |
38 | * spell: spell object to put into the rune |
40 | * a marking rune. |
|
|
41 | * level: level of casting of the rune |
39 | * level: level of casting of the rune |
42 | * runename: name of the rune or message displayed by the rune for |
40 | * runename: name of the rune or message displayed by the rune for |
43 | * a rune of marking |
41 | * a rune of marking |
44 | */ |
42 | */ |
45 | |
|
|
46 | int |
43 | int |
47 | write_rune (object *op, object *caster, object *spell, int dir, const char *runename) |
44 | write_rune (object *op, object *caster, object *spell, int dir, const char *runename) |
48 | { |
45 | { |
49 | object *tmp, *rune_spell, *rune; |
46 | object *tmp, *rune_spell, *rune; |
50 | char buf[MAX_BUF]; |
|
|
51 | maptile *m; |
47 | maptile *m; |
52 | sint16 nx, ny; |
48 | sint16 nx, ny; |
53 | |
49 | |
54 | if (!dir) |
50 | if (!dir) |
55 | dir = 1; |
51 | dir = 1; |
… | |
… | |
102 | } |
98 | } |
103 | } |
99 | } |
104 | |
100 | |
105 | if (!rune_spell) |
101 | if (!rune_spell) |
106 | { |
102 | { |
107 | new_draw_info_format (NDI_UNIQUE, 0, op, "You don't know any spell named %s", runename); |
103 | new_draw_info_format (NDI_UNIQUE, 0, op, "You don't know any spell named %s.", runename); |
108 | return 0; |
104 | return 0; |
109 | } |
105 | } |
110 | |
106 | |
111 | if (rune_spell->skill != spell->skill) |
107 | if (rune_spell->skill != spell->skill) |
112 | { |
108 | { |
113 | new_draw_info_format (NDI_UNIQUE, 0, op, "You can't cast %s with %s", &rune_spell->name, &spell->name); |
109 | 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; |
110 | return 0; |
115 | } |
111 | } |
116 | |
112 | |
117 | if (caster->path_denied & spell->path_attuned && !caster->flag [FLAG_WIZCAST]) |
113 | if (caster->path_denied & spell->path_attuned && !caster->flag [FLAG_WIZCAST]) |
118 | { |
114 | { |
119 | new_draw_info_format (NDI_UNIQUE, 0, op, "%s belongs to a spell path denied to you.", &rune_spell->name); |
115 | new_draw_info_format (NDI_UNIQUE, 0, op, "%s belongs to a spell path denied to you.", &rune_spell->name); |
120 | return 0; |
116 | return 0; |
121 | } |
117 | } |
122 | |
118 | |
123 | if (caster_level (caster, rune_spell) < rune_spell->level && !caster->flag [FLAG_WIZCAST]) |
119 | if (casting_level (caster, rune_spell) < rune_spell->level && !caster->flag [FLAG_WIZCAST]) |
124 | { |
120 | { |
125 | new_draw_info_format (NDI_UNIQUE, 0, op, "%s is beyond your ability to cast!", &rune_spell->name); |
121 | 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; |
122 | return 0; |
127 | } |
123 | } |
128 | |
124 | |
129 | if (SP_level_spellpoint_cost (caster, rune_spell, SPELL_MANA) > op->stats.sp) |
125 | if (SP_level_spellpoint_cost (caster, rune_spell, SPELL_MANA) > op->stats.sp) |
130 | { |
126 | { |
… | |
… | |
137 | new_draw_info (NDI_UNIQUE, 0, op, "You don't have enough grace."); |
133 | new_draw_info (NDI_UNIQUE, 0, op, "You don't have enough grace."); |
138 | return 0; |
134 | return 0; |
139 | } |
135 | } |
140 | |
136 | |
141 | op->stats.grace -= SP_level_spellpoint_cost (caster, rune_spell, SPELL_GRACE); |
137 | 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); |
138 | op->stats.sp -= SP_level_spellpoint_cost (caster, rune_spell, SPELL_MANA); |
143 | } |
139 | } |
144 | |
140 | |
145 | /* already proper rune. Note this should only be the case if other_arch was set */ |
141 | /* already proper rune. Note this should only be the case if other_arch was set */ |
146 | if (rune_spell->type == RUNE) |
142 | if (rune_spell->type == RUNE) |
147 | rune = rune_spell; |
143 | rune = rune_spell; |
148 | else |
144 | else |
149 | { |
145 | { |
150 | rune = get_archetype (GENERIC_RUNE); |
146 | rune = get_archetype (GENERIC_RUNE); |
151 | sprintf (buf, "You set off a rune of %s\n", &rune_spell->name); |
147 | rune->msg = format ("You set off a rune of %s\n", &rune_spell->name); |
152 | rune->msg = buf; |
|
|
153 | rune->insert (rune_spell->clone ()); |
148 | rune->insert (rune_spell->clone ()); |
154 | |
149 | |
155 | if (spell->face != blank_face) |
150 | if (spell->face != blank_face) |
156 | rune->face = spell->face; |
151 | rune->face = spell->face; |
157 | } |
152 | } |
158 | |
153 | |
159 | rune->level = caster_level (caster, spell); |
154 | rune->level = casting_level (caster, spell); |
160 | rune->stats.Cha = rune->level / 2; /* the invisibility parameter */ |
155 | rune->stats.Cha = rune->level / 2; /* the invisibility parameter */ |
161 | rune->direction = dir; /* where any spell will go upon detonation */ |
156 | rune->direction = dir; /* where any spell will go upon detonation */ |
162 | rune->set_owner (op); /* runes without need no owner */ |
157 | rune->set_owner (op); /* runes without need no owner */ |
163 | set_spell_skill (op, caster, spell, rune); |
158 | set_spell_skill (op, caster, spell, rune); |
164 | |
159 | |
… | |
… | |
194 | } |
189 | } |
195 | else |
190 | else |
196 | op->invisible = 1; |
191 | op->invisible = 1; |
197 | |
192 | |
198 | if (op->invisible != det) |
193 | if (op->invisible != det) |
199 | update_object (op, UP_OBJ_FACE); |
194 | update_object (op, UP_OBJ_CHANGE); |
200 | } |
195 | } |
201 | |
|
|
202 | |
196 | |
203 | /* peterm: rune_attack |
197 | /* peterm: rune_attack |
204 | * function handles those runes which detonate but do not cast spells. |
198 | * function handles those runes which detonate but do not cast spells. |
205 | */ |
199 | */ |
206 | |
|
|
207 | |
|
|
208 | void |
200 | void |
209 | rune_attack (object *op, object *victim) |
201 | rune_attack (object *op, object *victim) |
210 | { |
202 | { |
211 | if (victim) |
203 | if (victim) |
212 | { |
204 | { |
… | |
… | |
245 | /* Prevent recursion */ |
237 | /* Prevent recursion */ |
246 | if (trap->stats.hp <= 0) |
238 | if (trap->stats.hp <= 0) |
247 | return; |
239 | return; |
248 | |
240 | |
249 | if (QUERY_FLAG (trap, FLAG_IS_LINKED)) |
241 | if (QUERY_FLAG (trap, FLAG_IS_LINKED)) |
250 | use_trigger (trap); |
242 | use_trigger (trap, victim); |
251 | |
243 | |
252 | /* Only living objects can trigger runes that don't cast spells, as |
244 | /* 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. |
245 | * doing direct damage to a non-living object doesn't work anyway. |
254 | * Typical example is an arrow attacking a door. |
246 | * Typical example is an arrow attacking a door. |
255 | */ |
247 | */ |
… | |
… | |
262 | new_draw_info (NDI_UNIQUE, 0, victim, trap->msg); |
254 | new_draw_info (NDI_UNIQUE, 0, victim, trap->msg); |
263 | |
255 | |
264 | /* Flash an image of the trap on the map so the poor sod |
256 | /* Flash an image of the trap on the map so the poor sod |
265 | * knows what hit him. |
257 | * knows what hit him. |
266 | */ |
258 | */ |
267 | env = object_get_env_recursive (trap); |
259 | env = trap->outer_env (); |
268 | |
260 | |
269 | /* If the victim is not next to this trap, don't set it off. |
261 | /* 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. |
262 | * 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 |
263 | * At the same time, the trap will stick around until detonated |
272 | */ |
264 | */ |
273 | get_rangevector (env, victim, &rv, 0); |
265 | get_rangevector (env, victim, &rv, 0); |
274 | if (rv.distance > 1) |
266 | if (rv.distance > 1) |
275 | return; |
267 | return; |
276 | |
268 | |
|
|
269 | env->play_sound (trap->sound ? trap->sound : sound_find ("trap_spring")); |
|
|
270 | |
277 | trap_show (trap, env); |
271 | trap_show (trap, env); |
278 | |
272 | |
|
|
273 | if (victim->type == PLAYER) // only count players as enemies |
|
|
274 | trap->enemy = victim; // set the victim as the traps enemy, so that summoned |
|
|
275 | // creatures know who to attack. |
|
|
276 | |
279 | /* Only if it is a spell do we proceed here */ |
277 | /* 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)) |
278 | if ((trap->inv && trap->inv->type == SPELL) || (trap->other_arch && trap->other_arch->type == SPELL)) |
281 | { |
279 | { |
282 | |
|
|
283 | if (trap->destroyed ()) |
280 | if (trap->destroyed ()) |
284 | return; |
281 | return; |
285 | |
282 | |
286 | // breaks summon golem spells, which, for inexplicable reasons, |
283 | // breaks summon golem spells, which, for inexplicable reasons, |
287 | // do not work like summon golem spells at all but still require |
284 | // do not work like summon golem spells at all but still require |
… | |
… | |
343 | { |
340 | { |
344 | new_draw_info (NDI_UNIQUE, 0, op, "There's nothing there!"); |
341 | new_draw_info (NDI_UNIQUE, 0, op, "There's nothing there!"); |
345 | return 0; |
342 | return 0; |
346 | } |
343 | } |
347 | |
344 | |
348 | for (tmp = GET_MAP_OB (m, x, y); tmp != NULL; tmp = tmp->above) |
345 | for (tmp = GET_MAP_OB (m, x, y); tmp; tmp = tmp->above) |
349 | { |
346 | { |
350 | if (tmp->type == RUNE || tmp->type == TRAP) |
347 | if (tmp->type == RUNE || tmp->type == TRAP) |
351 | break; |
348 | break; |
352 | |
349 | |
353 | /* we could put a probability chance here, but since nothing happens |
350 | /* 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 |
351 | * 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. |
352 | * comparison so low level players can't erase high level players runes. |
356 | */ |
353 | */ |
357 | if (tmp->type == SIGN && !strcmp (tmp->arch->name, "rune_mark")) |
354 | if (tmp->type == SIGN && tmp->arch->archname == shstr_rune_mark) |
358 | { |
355 | { |
359 | tmp->destroy (); |
356 | tmp->destroy (); |
360 | new_draw_info (NDI_UNIQUE, 0, op, "You wipe out the rune of marking!"); |
357 | new_draw_info (NDI_UNIQUE, 0, op, "You wipe out the rune of marking!"); |
361 | return 1; |
358 | return 1; |
362 | } |
359 | } |
363 | |
360 | |
364 | /* now search tmp's inventory for traps |
361 | /* now search tmp's inventory for traps |
365 | * This is for chests, where the rune is in the chests inventory. |
362 | * This is for chests, where the rune is in the chests inventory. |
366 | */ |
363 | */ |
367 | for (tmp2 = tmp->inv; tmp2 != NULL; tmp2 = tmp2->below) |
364 | for (tmp2 = tmp->inv; tmp2; tmp2 = tmp2->below) |
368 | { |
365 | { |
369 | if (tmp2->type == RUNE || tmp2->type == TRAP) |
366 | if (tmp2->type == RUNE || tmp2->type == TRAP) |
370 | { |
367 | { |
371 | tmp = tmp2; |
368 | tmp = tmp2; |
372 | searchflag = 0; |
369 | searchflag = 0; |
373 | break; |
370 | break; |
374 | } |
371 | } |
375 | } |
372 | } |
|
|
373 | |
376 | if (!searchflag) |
374 | if (!searchflag) |
377 | break; |
375 | break; |
378 | } |
376 | } |
379 | |
377 | |
380 | /* no rune there. */ |
378 | /* no rune there. */ |
381 | if (tmp == NULL) |
379 | if (tmp == NULL) |
382 | { |
380 | { |
383 | new_draw_info (NDI_UNIQUE, 0, op, "There's nothing there!"); |
381 | new_draw_info (NDI_UNIQUE, 0, op, "There's nothing there!"); |
384 | return 0; |
382 | return 0; |
385 | } |
383 | } |
|
|
384 | |
386 | trap_disarm (op, tmp, 0, skill); |
385 | trap_disarm (op, tmp, 0, skill); |
387 | return 1; |
386 | return 1; |
388 | |
|
|
389 | } |
387 | } |
390 | |
388 | |
391 | int |
389 | int |
392 | trap_see (object *op, object *trap) |
390 | trap_see (object *op, object *trap) |
393 | { |
391 | { |
… | |
… | |
400 | + trap->level + trap->stats.Cha - op->level) / 10.0 * 50.0)))))) |
398 | + trap->level + trap->stats.Cha - op->level) / 10.0 * 50.0)))))) |
401 | { |
399 | { |
402 | new_draw_info_format (NDI_UNIQUE, 0, op, "You spot a %s!", &trap->name); |
400 | new_draw_info_format (NDI_UNIQUE, 0, op, "You spot a %s!", &trap->name); |
403 | return 1; |
401 | return 1; |
404 | } |
402 | } |
|
|
403 | |
405 | return 0; |
404 | return 0; |
406 | } |
405 | } |
407 | |
406 | |
408 | int |
407 | int |
409 | trap_show (object *trap, object *where) |
408 | trap_show (object *trap, object *where) |
410 | { |
409 | { |
411 | if (where == NULL) |
410 | if (where == NULL) |
412 | return 0; |
411 | return 0; |
413 | |
412 | |
414 | object *tmp = get_archetype ("runedet"); |
413 | object *tmp = get_archetype ("runedet"); |
415 | tmp->face = &new_faces[GET_ANIMATION (trap, 0)]; |
414 | tmp->face = GET_ANIMATION (trap, 0); |
416 | tmp->insert_at (where, 0); |
415 | tmp->insert_at (where, 0); |
417 | |
416 | |
418 | return 1; |
417 | return 1; |
419 | } |
418 | } |
420 | |
419 | |
421 | int |
420 | int |
422 | trap_disarm (object *disarmer, object *trap, int risk, object *skill) |
421 | trap_disarm (object *disarmer, object *trap, int risk, object *skill) |
423 | { |
422 | { |
424 | int trapworth; /* need to compute the experience worth of the trap |
423 | int trapworth; /* need to compute the experience worth of the trap before we kill it */ |
425 | before we kill it */ |
|
|
426 | |
424 | |
427 | /* this formula awards a more reasonable amount of exp */ |
425 | /* this formula awards a more reasonable amount of exp */ |
428 | trapworth = MAX (1, trap->level) * disarmer->map->difficulty * |
426 | trapworth = MAX (1, trap->level) |
|
|
427 | * disarmer->map->difficulty |
429 | sqr (MAX (trap->stats.dam, trap->inv ? trap->inv->level : 1)) / skill->level; |
428 | * sqr (MAX (trap->stats.dam, trap->inv ? trap->inv->level : 1)) |
|
|
429 | / skill->level; |
430 | |
430 | |
431 | if (!(random_roll (0, (MAX (2, MIN (20, trap->level - skill->level + 5 - disarmer->stats.Dex / 2)) - 1), disarmer, PREFER_LOW))) |
431 | if (!(random_roll (0, (MAX (2, MIN (20, trap->level - skill->level + 5 - disarmer->stats.Dex / 2)) - 1), disarmer, PREFER_LOW))) |
432 | { |
432 | { |
433 | new_draw_info_format (NDI_UNIQUE, 0, disarmer, "You successfully disarm the %s!", &trap->name); |
433 | new_draw_info_format (NDI_UNIQUE, 0, disarmer, "You successfully disarm the %s!", &trap->name); |
434 | trap->destroy (1); |
434 | trap->destroy (); |
435 | |
435 | |
436 | /* If it is your own trap, (or any players trap), don't you don't |
436 | /* If it is your own trap, (or any players trap), don't you don't |
437 | * get exp for it. |
437 | * get exp for it. |
438 | */ |
438 | */ |
439 | if (trap->owner && trap->owner->type != PLAYER && risk) |
439 | if (trap->owner && trap->owner->type != PLAYER && risk) |
… | |
… | |
451 | } |
451 | } |
452 | return 0; |
452 | return 0; |
453 | } |
453 | } |
454 | } |
454 | } |
455 | |
455 | |
456 | |
|
|
457 | /* traps need to be adjusted for the difficulty of the map. The |
456 | /* traps need to be adjusted for the difficulty of the map. The |
458 | * default traps are too strong for wimpy level 1 players, and |
457 | * default traps are too strong for wimpy level 1 players, and |
459 | * unthreatening to anyone of high level |
458 | * unthreatening to anyone of high level |
460 | */ |
459 | */ |
461 | |
|
|
462 | void |
460 | void |
463 | trap_adjust (object *trap, int difficulty) |
461 | trap_adjust (object *trap, int difficulty) |
464 | { |
462 | { |
465 | int i; |
463 | int i; |
466 | |
464 | |