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.12 by root, Mon Dec 18 03:00:02 2006 UTC vs.
Revision 1.39 by root, Sun Jan 4 22:39:59 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 (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
4 Copyright (C) 2003 Mark Wedel & Crossfire Development Team 5 * Copyright (©) 2003,2007 Mark Wedel & Crossfire Development Team
5 Copyright (C) 1992 Frank Tore Johansen 6 * Copyright (©) 1992,2007 Frank Tore Johansen
6 7 *
7 This program is free software; you can redistribute it and/or modify 8 * Deliantra is free software: you can redistribute it and/or modify
8 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
9 the Free Software Foundation; either version 2 of the License, or 10 * the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version. 11 * (at your option) any later version.
11 12 *
12 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,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details. 16 * GNU General Public License for more details.
16 17 *
17 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
18 along with this program; if not, write to the Free Software 19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 *
20 21 * The authors can be reached via e-mail to <support@deliantra.net>
21 The authors can be reached via e-mail at <crossfire@schmorp.de>
22*/ 22 */
23 23
24#include <global.h> 24#include <global.h>
25#ifndef __CEXTRACT__
26# include <sproto.h> 25#include <sproto.h>
27#endif
28#include <spells.h> 26#include <spells.h>
29
30 27
31#ifndef sqr 28#ifndef sqr
32# define sqr(x) ((x)*(x)) 29# define sqr(x) ((x)*(x))
33#endif 30#endif
34
35 31
36/* peterm: 32/* peterm:
37 * write_rune: 33 * write_rune:
38 * op: rune writer 34 * op: rune writer
39 * skop: skill object used for casting this rune 35 * skop: skill object used for casting this rune
40 * dir: orientation of rune, direction rune's contained spell will 36 * dir: orientation of rune, direction rune's contained spell will
41 * be cast in, if applicable 37 * be cast in, if applicable
42 * inspell: spell object to put into the rune, can be null if doing 38 * spell: spell object to put into the rune
43 * a marking rune.
44 * level: level of casting of the rune 39 * level: level of casting of the rune
45 * 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
46 * a rune of marking 41 * a rune of marking
47 */ 42 */
48
49int 43int
50write_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)
51{ 45{
52 object *tmp, *rune_spell, *rune; 46 object *tmp, *rune_spell, *rune;
53 char buf[MAX_BUF];
54 maptile *m; 47 maptile *m;
55 sint16 nx, ny; 48 sint16 nx, ny;
56 49
57 if (!dir) 50 if (!dir)
58 dir = 1; 51 dir = 1;
59 52
60 nx = op->x + freearr_x[dir]; 53 nx = op->x + freearr_x[dir];
61 ny = op->y + freearr_y[dir]; 54 ny = op->y + freearr_y[dir];
62 m = op->map; 55 m = op->map;
63 56
64 if (get_map_flags (m, &m, nx, ny, &nx, &ny)) 57 if (get_map_flags (m, &m, nx, ny, &nx, &ny) & (P_OUT_OF_MAP | P_SAFE | P_NO_MAGIC | P_NO_CLERIC))
65 { 58 {
66 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!");
67 return 0; 60 return 0;
68 } 61 }
69 62
70 for (tmp = get_map_ob (m, nx, ny); tmp != NULL; tmp = tmp->above) 63 for (tmp = m->at (nx, ny).bot; tmp; tmp = tmp->above)
71 if (tmp->type == RUNE) 64 if (tmp->type == RUNE)
72 break; 65 break;
73 66
74 if (tmp) 67 if (tmp)
75 { 68 {
76 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.");
77 return 0; 70 return 0;
78 } 71 }
79 72
80 if (spell->other_arch) 73 if (spell->other_arch)
81 rune_spell = arch_to_object (spell->other_arch); 74 rune_spell = arch_to_object (spell->other_arch);
93 return 0; 86 return 0;
94 } 87 }
95 88
96 rune_spell = NULL; 89 rune_spell = NULL;
97 for (tmp = op->inv; tmp; tmp = tmp->below) 90 for (tmp = op->inv; tmp; tmp = tmp->below)
98 {
99 if (tmp->type == SPELL) 91 if (tmp->type == SPELL)
100 { 92 {
101 ms = item_matched_string (op, tmp, runename); 93 ms = item_matched_string (op, tmp, runename);
102 if (ms > bestmatch) 94 if (ms > bestmatch)
103 { 95 {
104 bestmatch = ms; 96 bestmatch = ms;
105 rune_spell = tmp; 97 rune_spell = tmp;
106 } 98 }
107 } 99 }
108 }
109 100
110 if (!rune_spell) 101 if (!rune_spell)
111 { 102 {
112 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);
113 return 0; 104 return 0;
114 } 105 }
115 106
116 if (rune_spell->skill != spell->skill) 107 if (rune_spell->skill != spell->skill)
117 { 108 {
118 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);
119 return 0; 110 return 0;
120 } 111 }
121 112
122 if (caster->path_denied & spell->path_attuned) 113 if (caster->path_denied & spell->path_attuned && !caster->flag [FLAG_WIZCAST])
123 { 114 {
124 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);
125 return 0; 116 return 0;
126 } 117 }
127 118
128 if (caster_level (caster, rune_spell) < rune_spell->level) 119 if (casting_level (caster, rune_spell) < rune_spell->level && !caster->flag [FLAG_WIZCAST])
129 { 120 {
130 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);
131 return 0; 122 return 0;
132 } 123 }
133 124
134 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)
135 { 126 {
142 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.");
143 return 0; 134 return 0;
144 } 135 }
145 136
146 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);
147 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);
148 } 139 }
149 140
150 /* 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 */
151 if (rune_spell->type == RUNE) 142 if (rune_spell->type == RUNE)
152 {
153 rune = rune_spell; 143 rune = rune_spell;
154 }
155 else 144 else
156 { 145 {
157 rune = get_archetype (GENERIC_RUNE); 146 rune = get_archetype (GENERIC_RUNE);
158 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);
159 rune->msg = buf; 148 rune->insert (rune_spell->clone ());
160 tmp = rune_spell->clone ();
161 insert_ob_in_ob (tmp, rune);
162 149
163 if (spell->face != blank_face) 150 if (spell->face != blank_face)
164 rune->face = spell->face; 151 rune->face = spell->face;
165 } 152 }
166 153
167 rune->level = caster_level (caster, spell); 154 rune->level = casting_level (caster, spell);
168 rune->stats.Cha = rune->level / 2; /* the invisibility parameter */ 155 rune->stats.Cha = rune->level / 2; /* the invisibility parameter */
169 rune->x = nx;
170 rune->y = ny;
171 rune->map = m;
172 rune->direction = dir; /* where any spell will go upon detonation */ 156 rune->direction = dir; /* where any spell will go upon detonation */
173 rune->set_owner (op); /* runes without need no owner */ 157 rune->set_owner (op); /* runes without need no owner */
174 set_spell_skill (op, caster, spell, rune); 158 set_spell_skill (op, caster, spell, rune);
175 insert_ob_in_map (rune, m, op, 0); 159
160 m->insert (rune, nx, ny, op);
176 return 1; 161 return 1;
177
178} 162}
179
180
181 163
182/* move_rune: peterm 164/* move_rune: peterm
183 comments on runes: 165 comments on runes:
184 rune->level : level at which rune will cast its spell. 166 rune->level : level at which rune will cast its spell.
185 rune->hp : number of detonations before rune goes away 167 rune->hp : number of detonations before rune goes away
189 rune->attacktype: type of damage it does, if not casting spells 171 rune->attacktype: type of damage it does, if not casting spells
190 rune->other_arch: spell in the rune 172 rune->other_arch: spell in the rune
191 rune->Cha : how hidden the rune is 173 rune->Cha : how hidden the rune is
192 rune->maxhp : number of spells the rune casts 174 rune->maxhp : number of spells the rune casts
193*/ 175*/
194
195void 176void
196move_rune (object *op) 177move_rune (object *op)
197{ 178{
198 int det = 0; 179 /* runes of level zero cannot detonate. */
199
200 if (!op->level) 180 if (!op->level)
201 {
202 return; 181 return;
203 } /* runes of level zero cannot detonate. */ 182
204 det = op->invisible; 183 int det = op->invisible;
184
205 if (!(rndm (0, MAX (1, (op->stats.Cha)) - 1))) 185 if (!(rndm (0, MAX (1, (op->stats.Cha)) - 1)))
206 { 186 {
207 op->invisible = 0; 187 op->invisible = 0;
208 op->speed_left -= 1; 188 op->speed_left -= 1;
209 } 189 }
210 else 190 else
211 op->invisible = 1; 191 op->invisible = 1;
192
212 if (op->invisible != det) 193 if (op->invisible != det)
213 update_object (op, UP_OBJ_FACE); 194 update_object (op, UP_OBJ_CHANGE);
214} 195}
215
216 196
217/* peterm: rune_attack 197/* peterm: rune_attack
218 * function handles those runes which detonate but do not cast spells. 198 * function handles those runes which detonate but do not cast spells.
219 */ 199 */
220
221
222void 200void
223rune_attack (object *op, object *victim) 201rune_attack (object *op, object *victim)
224{ 202{
225 if (victim) 203 if (victim)
226 { 204 {
276 new_draw_info (NDI_UNIQUE, 0, victim, trap->msg); 254 new_draw_info (NDI_UNIQUE, 0, victim, trap->msg);
277 255
278 /* 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
279 * knows what hit him. 257 * knows what hit him.
280 */ 258 */
281 env = object_get_env_recursive (trap); 259 env = trap->outer_env ();
282 260
283 /* 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.
284 * 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.
285 * At the same time, the trap will stick around until detonated 263 * At the same time, the trap will stick around until detonated
286 */ 264 */
287 get_rangevector (env, victim, &rv, 0); 265 get_rangevector (env, victim, &rv, 0);
288 if (rv.distance > 1) 266 if (rv.distance > 1)
289 return; 267 return;
290 268
269 env->play_sound (trap->sound ? trap->sound : sound_find ("trap_spring"));
270
291 trap_show (trap, env); 271 trap_show (trap, env);
292 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
293 /* Only if it is a spell do we proceed here */ 277 /* Only if it is a spell do we proceed here */
294 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))
295 { 279 {
296
297 if (trap->destroyed ()) 280 if (trap->destroyed ())
298 return; 281 return;
299 282
300 // breaks summon golem spells, which, for inexplicable reasons, 283 // breaks summon golem spells, which, for inexplicable reasons,
301 // 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
357 { 340 {
358 new_draw_info (NDI_UNIQUE, 0, op, "There's nothing there!"); 341 new_draw_info (NDI_UNIQUE, 0, op, "There's nothing there!");
359 return 0; 342 return 0;
360 } 343 }
361 344
362 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)
363 { 346 {
364 if (tmp->type == RUNE || tmp->type == TRAP) 347 if (tmp->type == RUNE || tmp->type == TRAP)
365 break; 348 break;
366 349
367 /* we could put a probability chance here, but since nothing happens 350 /* we could put a probability chance here, but since nothing happens
368 * 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
369 * 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.
370 */ 353 */
371 if (tmp->type == SIGN && !strcmp (tmp->arch->name, "rune_mark")) 354 if (tmp->type == SIGN && tmp->arch->archname == shstr_rune_mark)
372 { 355 {
373 tmp->destroy (); 356 tmp->destroy ();
374 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!");
375 return 1; 358 return 1;
376 } 359 }
377 360
378 /* now search tmp's inventory for traps 361 /* now search tmp's inventory for traps
379 * 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.
380 */ 363 */
381 for (tmp2 = tmp->inv; tmp2 != NULL; tmp2 = tmp2->below) 364 for (tmp2 = tmp->inv; tmp2; tmp2 = tmp2->below)
382 { 365 {
383 if (tmp2->type == RUNE || tmp2->type == TRAP) 366 if (tmp2->type == RUNE || tmp2->type == TRAP)
384 { 367 {
385 tmp = tmp2; 368 tmp = tmp2;
386 searchflag = 0; 369 searchflag = 0;
387 break; 370 break;
388 } 371 }
389 } 372 }
373
390 if (!searchflag) 374 if (!searchflag)
391 break; 375 break;
392 } 376 }
393 377
394 /* no rune there. */ 378 /* no rune there. */
395 if (tmp == NULL) 379 if (tmp == NULL)
396 { 380 {
397 new_draw_info (NDI_UNIQUE, 0, op, "There's nothing there!"); 381 new_draw_info (NDI_UNIQUE, 0, op, "There's nothing there!");
398 return 0; 382 return 0;
399 } 383 }
384
400 trap_disarm (op, tmp, 0, skill); 385 trap_disarm (op, tmp, 0, skill);
401 return 1; 386 return 1;
402
403} 387}
404 388
405int 389int
406trap_see (object *op, object *trap) 390trap_see (object *op, object *trap)
407{ 391{
414 + trap->level + trap->stats.Cha - op->level) / 10.0 * 50.0)))))) 398 + trap->level + trap->stats.Cha - op->level) / 10.0 * 50.0))))))
415 { 399 {
416 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);
417 return 1; 401 return 1;
418 } 402 }
403
419 return 0; 404 return 0;
420} 405}
421 406
422int 407int
423trap_show (object *trap, object *where) 408trap_show (object *trap, object *where)
424{ 409{
425 object *tmp2;
426
427 if (where == NULL) 410 if (where == NULL)
428 return 0; 411 return 0;
412
429 tmp2 = get_archetype ("runedet"); 413 object *tmp = get_archetype ("runedet");
430 tmp2->face = &new_faces[GET_ANIMATION (trap, 0)]; 414 tmp->face = GET_ANIMATION (trap, 0);
431 tmp2->x = where->x; 415 tmp->insert_at (where, 0);
432 tmp2->y = where->y; 416
433 tmp2->map = where->map;
434 insert_ob_in_map (tmp2, where->map, NULL, 0);
435 return 1; 417 return 1;
436
437} 418}
438
439 419
440int 420int
441trap_disarm (object *disarmer, object *trap, int risk, object *skill) 421trap_disarm (object *disarmer, object *trap, int risk, object *skill)
442{ 422{
443 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 */
444 before we kill it */
445 424
446 /* this formula awards a more reasonable amount of exp */ 425 /* this formula awards a more reasonable amount of exp */
447 trapworth = MAX (1, trap->level) * disarmer->map->difficulty * 426 trapworth = MAX (1, trap->level)
427 * disarmer->map->difficulty
448 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;
449 430
450 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)))
451 { 432 {
452 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);
453 trap->destroy (1); 434 trap->destroy ();
454 435
455 /* 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
456 * get exp for it. 437 * get exp for it.
457 */ 438 */
458 if (trap->owner && trap->owner->type != PLAYER && risk) 439 if (trap->owner && trap->owner->type != PLAYER && risk)
470 } 451 }
471 return 0; 452 return 0;
472 } 453 }
473} 454}
474 455
475
476/* 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
477 * default traps are too strong for wimpy level 1 players, and 457 * default traps are too strong for wimpy level 1 players, and
478 * unthreatening to anyone of high level 458 * unthreatening to anyone of high level
479 */ 459 */
480
481void 460void
482trap_adjust (object *trap, int difficulty) 461trap_adjust (object *trap, int difficulty)
483{ 462{
484 int i; 463 int i;
485 464

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines