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.19 by root, Fri Feb 2 22:49:11 2007 UTC vs.
Revision 1.42 by root, Tue Sep 1 20:56:05 2009 UTC

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 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
46int 43int
47write_rune (object *op, object *caster, object *spell, int dir, const char *runename) 44write_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;
56 52
57 nx = op->x + freearr_x[dir]; 53 nx = op->x + freearr_x[dir];
58 ny = op->y + freearr_y[dir]; 54 ny = op->y + freearr_y[dir];
59 m = op->map; 55 m = op->map;
60 56
61 if (get_map_flags (m, &m, nx, ny, &nx, &ny) && (P_OUT_OF_MAP | P_SAFE | P_NO_MAGIC | P_NO_CLERIC)) 57 if (get_map_flags (m, &m, nx, ny, &nx, &ny) & (P_OUT_OF_MAP | P_SAFE | P_NO_MAGIC | P_NO_CLERIC))
62 { 58 {
63 new_draw_info (NDI_UNIQUE, 0, op, "Can't make a rune there!"); 59 new_draw_info (NDI_UNIQUE, 0, op, "Can't make a rune there!");
64 return 0; 60 return 0;
65 } 61 }
66 62
68 if (tmp->type == RUNE) 64 if (tmp->type == RUNE)
69 break; 65 break;
70 66
71 if (tmp) 67 if (tmp)
72 { 68 {
73 new_draw_info (NDI_UNIQUE, 0, op, "You can't write a rune there."); 69 new_draw_info (NDI_UNIQUE, 0, op, "You can't write a rune on top of another rune.");
74 return 0; 70 return 0;
75 } 71 }
76 72
77 if (spell->other_arch) 73 if (spell->other_arch)
78 rune_spell = arch_to_object (spell->other_arch); 74 rune_spell = arch_to_object (spell->other_arch);
90 return 0; 86 return 0;
91 } 87 }
92 88
93 rune_spell = NULL; 89 rune_spell = NULL;
94 for (tmp = op->inv; tmp; tmp = tmp->below) 90 for (tmp = op->inv; tmp; tmp = tmp->below)
95 {
96 if (tmp->type == SPELL) 91 if (tmp->type == SPELL)
97 { 92 {
98 ms = item_matched_string (op, tmp, runename); 93 ms = item_matched_string (op, tmp, runename);
99 if (ms > bestmatch) 94 if (ms > bestmatch)
100 { 95 {
101 bestmatch = ms; 96 bestmatch = ms;
102 rune_spell = tmp; 97 rune_spell = tmp;
103 } 98 }
104 } 99 }
105 }
106 100
107 if (!rune_spell) 101 if (!rune_spell)
108 { 102 {
109 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);
110 return 0; 104 return 0;
111 } 105 }
112 106
113 if (rune_spell->skill != spell->skill) 107 if (rune_spell->skill != spell->skill)
114 { 108 {
115 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);
116 return 0; 110 return 0;
117 } 111 }
118 112
119 if (caster->path_denied & spell->path_attuned) 113 if (caster->path_denied & spell->path_attuned && !caster->flag [FLAG_WIZCAST])
120 { 114 {
121 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);
122 return 0; 116 return 0;
123 } 117 }
124 118
125 if (caster_level (caster, rune_spell) < rune_spell->level) 119 if (casting_level (caster, rune_spell) < rune_spell->level && !caster->flag [FLAG_WIZCAST])
126 { 120 {
127 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);
128 return 0; 122 return 0;
129 } 123 }
130 124
131 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)
132 { 126 {
139 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.");
140 return 0; 134 return 0;
141 } 135 }
142 136
143 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);
144 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);
145 } 139 }
146 140
147 /* 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 */
148 if (rune_spell->type == RUNE) 142 if (rune_spell->type == RUNE)
149 rune = rune_spell; 143 rune = rune_spell;
150 else 144 else
151 { 145 {
152 rune = get_archetype (GENERIC_RUNE); 146 rune = get_archetype (GENERIC_RUNE);
153 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);
154 rune->msg = buf;
155 rune->insert (rune_spell->clone ()); 148 rune->insert (rune_spell->clone ());
156 149
157 if (spell->face != blank_face) 150 if (spell->face != blank_face)
158 rune->face = spell->face; 151 rune->face = spell->face;
159 } 152 }
160 153
161 rune->level = caster_level (caster, spell); 154 rune->level = casting_level (caster, spell);
162 rune->stats.Cha = rune->level / 2; /* the invisibility parameter */ 155 rune->stats.Cha = rune->level / 2; /* the invisibility parameter */
163 rune->direction = dir; /* where any spell will go upon detonation */ 156 rune->direction = dir; /* where any spell will go upon detonation */
164 rune->set_owner (op); /* runes without need no owner */ 157 rune->set_owner (op); /* runes without need no owner */
165 set_spell_skill (op, caster, spell, rune); 158 set_spell_skill (op, caster, spell, rune);
166 159
196 } 189 }
197 else 190 else
198 op->invisible = 1; 191 op->invisible = 1;
199 192
200 if (op->invisible != det) 193 if (op->invisible != det)
201 update_object (op, UP_OBJ_FACE); 194 update_object (op, UP_OBJ_CHANGE);
202} 195}
203
204 196
205/* peterm: rune_attack 197/* peterm: rune_attack
206 * function handles those runes which detonate but do not cast spells. 198 * function handles those runes which detonate but do not cast spells.
207 */ 199 */
208
209
210void 200void
211rune_attack (object *op, object *victim) 201rune_attack (object *op, object *victim)
212{ 202{
213 if (victim) 203 if (victim)
214 { 204 {
247 /* Prevent recursion */ 237 /* Prevent recursion */
248 if (trap->stats.hp <= 0) 238 if (trap->stats.hp <= 0)
249 return; 239 return;
250 240
251 if (QUERY_FLAG (trap, FLAG_IS_LINKED)) 241 if (QUERY_FLAG (trap, FLAG_IS_LINKED))
252 use_trigger (trap); 242 use_trigger (trap, victim);
253 243
254 /* 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
255 * 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.
256 * Typical example is an arrow attacking a door. 246 * Typical example is an arrow attacking a door.
257 */ 247 */
264 new_draw_info (NDI_UNIQUE, 0, victim, trap->msg); 254 new_draw_info (NDI_UNIQUE, 0, victim, trap->msg);
265 255
266 /* 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
267 * knows what hit him. 257 * knows what hit him.
268 */ 258 */
269 env = object_get_env_recursive (trap); 259 env = trap->outer_env_or_self ();
270 260
271 /* 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.
272 * 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.
273 * At the same time, the trap will stick around until detonated 263 * At the same time, the trap will stick around until detonated
274 */ 264 */
275 get_rangevector (env, victim, &rv, 0); 265 get_rangevector (env, victim, &rv, 0);
276 if (rv.distance > 1) 266 if (rv.distance > 1)
277 return; 267 return;
278 268
269 env->play_sound (trap->sound ? trap->sound : sound_find ("trap_spring"));
270
279 trap_show (trap, env); 271 trap_show (trap, env);
280 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
281 /* Only if it is a spell do we proceed here */ 277 /* 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)) 278 if ((trap->inv && trap->inv->type == SPELL) || (trap->other_arch && trap->other_arch->type == SPELL))
283 { 279 {
284
285 if (trap->destroyed ()) 280 if (trap->destroyed ())
286 return; 281 return;
287 282
288 // breaks summon golem spells, which, for inexplicable reasons, 283 // breaks summon golem spells, which, for inexplicable reasons,
289 // 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
345 { 340 {
346 new_draw_info (NDI_UNIQUE, 0, op, "There's nothing there!"); 341 new_draw_info (NDI_UNIQUE, 0, op, "There's nothing there!");
347 return 0; 342 return 0;
348 } 343 }
349 344
350 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)
351 { 346 {
352 if (tmp->type == RUNE || tmp->type == TRAP) 347 if (tmp->type == RUNE || tmp->type == TRAP)
353 break; 348 break;
354 349
355 /* we could put a probability chance here, but since nothing happens 350 /* 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 351 * 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. 352 * comparison so low level players can't erase high level players runes.
358 */ 353 */
359 if (tmp->type == SIGN && !strcmp (tmp->arch->name, "rune_mark")) 354 if (tmp->type == SIGN && tmp->arch->archname == shstr_rune_mark)
360 { 355 {
361 tmp->destroy (); 356 tmp->destroy ();
362 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!");
363 return 1; 358 return 1;
364 } 359 }
365 360
366 /* now search tmp's inventory for traps 361 /* now search tmp's inventory for traps
367 * 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.
368 */ 363 */
369 for (tmp2 = tmp->inv; tmp2 != NULL; tmp2 = tmp2->below) 364 for (tmp2 = tmp->inv; tmp2; tmp2 = tmp2->below)
370 { 365 {
371 if (tmp2->type == RUNE || tmp2->type == TRAP) 366 if (tmp2->type == RUNE || tmp2->type == TRAP)
372 { 367 {
373 tmp = tmp2; 368 tmp = tmp2;
374 searchflag = 0; 369 searchflag = 0;
375 break; 370 break;
376 } 371 }
377 } 372 }
373
378 if (!searchflag) 374 if (!searchflag)
379 break; 375 break;
380 } 376 }
381 377
382 /* no rune there. */ 378 /* no rune there. */
383 if (tmp == NULL) 379 if (tmp == NULL)
384 { 380 {
385 new_draw_info (NDI_UNIQUE, 0, op, "There's nothing there!"); 381 new_draw_info (NDI_UNIQUE, 0, op, "There's nothing there!");
386 return 0; 382 return 0;
387 } 383 }
384
388 trap_disarm (op, tmp, 0, skill); 385 trap_disarm (op, tmp, 0, skill);
389 return 1; 386 return 1;
390
391} 387}
392 388
393int 389int
394trap_see (object *op, object *trap) 390trap_see (object *op, object *trap)
395{ 391{
402 + trap->level + trap->stats.Cha - op->level) / 10.0 * 50.0)))))) 398 + trap->level + trap->stats.Cha - op->level) / 10.0 * 50.0))))))
403 { 399 {
404 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);
405 return 1; 401 return 1;
406 } 402 }
403
407 return 0; 404 return 0;
408} 405}
409 406
410int 407int
411trap_show (object *trap, object *where) 408trap_show (object *trap, object *where)
412{ 409{
413 if (where == NULL) 410 if (where == NULL)
414 return 0; 411 return 0;
415 412
416 object *tmp = get_archetype ("runedet"); 413 object *tmp = get_archetype ("runedet");
417 tmp->face = &new_faces[GET_ANIMATION (trap, 0)]; 414 tmp->face = trap->get_anim_frame (0);
418 tmp->insert_at (where, 0); 415 tmp->insert_at (where, 0);
419 416
420 return 1; 417 return 1;
421} 418}
422 419
423int 420int
424trap_disarm (object *disarmer, object *trap, int risk, object *skill) 421trap_disarm (object *disarmer, object *trap, int risk, object *skill)
425{ 422{
426 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 */
427 before we kill it */
428 424
429 /* this formula awards a more reasonable amount of exp */ 425 /* this formula awards a more reasonable amount of exp */
430 trapworth = MAX (1, trap->level) * disarmer->map->difficulty * 426 trapworth = MAX (1, trap->level)
427 * disarmer->map->difficulty
431 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;
432 430
433 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)))
434 { 432 {
435 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);
436 trap->destroy (1); 434 trap->destroy ();
437 435
438 /* 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
439 * get exp for it. 437 * get exp for it.
440 */ 438 */
441 if (trap->owner && trap->owner->type != PLAYER && risk) 439 if (trap->owner && trap->owner->type != PLAYER && risk)
453 } 451 }
454 return 0; 452 return 0;
455 } 453 }
456} 454}
457 455
458
459/* 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
460 * default traps are too strong for wimpy level 1 players, and 457 * default traps are too strong for wimpy level 1 players, and
461 * unthreatening to anyone of high level 458 * unthreatening to anyone of high level
462 */ 459 */
463
464void 460void
465trap_adjust (object *trap, int difficulty) 461trap_adjust (object *trap, int difficulty)
466{ 462{
467 int i; 463 int i;
468 464

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines