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.7 by root, Sat Sep 16 22:24:13 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 {
59 dir = 1; 51 dir = 1;
60 }
61 52
62 nx = op->x + freearr_x[dir]; 53 nx = op->x + freearr_x[dir];
63 ny = op->y + freearr_y[dir]; 54 ny = op->y + freearr_y[dir];
64 m = op->map; 55 m = op->map;
65 56
66 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))
67 { 58 {
68 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!");
69 return 0; 60 return 0;
70 } 61 }
62
71 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)
72 if (tmp->type == RUNE) 64 if (tmp->type == RUNE)
73 break; 65 break;
74 66
75 if (tmp) 67 if (tmp)
76 { 68 {
77 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.");
78 return 0; 70 return 0;
79 } 71 }
80 72
81 if (spell->other_arch) 73 if (spell->other_arch)
82 {
83 rune_spell = arch_to_object (spell->other_arch); 74 rune_spell = arch_to_object (spell->other_arch);
84 }
85 else 75 else
86 { 76 {
87 /* Player specified spell. The player has to know the spell, so 77 /* Player specified spell. The player has to know the spell, so
88 * lets just look through the players inventory see if they know it 78 * lets just look through the players inventory see if they know it
89 * use the item_matched_string for our typical matching method. 79 * use the item_matched_string for our typical matching method.
96 return 0; 86 return 0;
97 } 87 }
98 88
99 rune_spell = NULL; 89 rune_spell = NULL;
100 for (tmp = op->inv; tmp; tmp = tmp->below) 90 for (tmp = op->inv; tmp; tmp = tmp->below)
101 {
102 if (tmp->type == SPELL) 91 if (tmp->type == SPELL)
103 { 92 {
104 ms = item_matched_string (op, tmp, runename); 93 ms = item_matched_string (op, tmp, runename);
105 if (ms > bestmatch) 94 if (ms > bestmatch)
106 { 95 {
107 bestmatch = ms; 96 bestmatch = ms;
108 rune_spell = tmp; 97 rune_spell = tmp;
109 } 98 }
110 } 99 }
111 } 100
112 if (!rune_spell) 101 if (!rune_spell)
113 { 102 {
114 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);
115 return 0; 104 return 0;
116 } 105 }
106
117 if (rune_spell->skill != spell->skill) 107 if (rune_spell->skill != spell->skill)
118 { 108 {
119 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);
120 return 0; 110 return 0;
121 } 111 }
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 }
118
127 if (caster_level (caster, rune_spell) < rune_spell->level) 119 if (casting_level (caster, rune_spell) < rune_spell->level && !caster->flag [FLAG_WIZCAST])
128 {
129 new_draw_info_format (NDI_UNIQUE, 0, op, "%s is beyond your ability to cast!", &rune_spell->name);
130 return 0;
131 } 120 {
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);
122 return 0;
123 }
124
132 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)
133 { 126 {
134 new_draw_info (NDI_UNIQUE, 0, op, "You don't have enough mana."); 127 new_draw_info (NDI_UNIQUE, 0, op, "You don't have enough mana.");
135 return 0; 128 return 0;
136 } 129 }
130
137 if (SP_level_spellpoint_cost (caster, rune_spell, SPELL_GRACE) > op->stats.grace) 131 if (SP_level_spellpoint_cost (caster, rune_spell, SPELL_GRACE) > op->stats.grace)
138 { 132 {
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 }
136
142 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);
143 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);
144 } 139 }
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 {
148 rune = rune_spell; 143 rune = rune_spell;
149 }
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; 148 rune->insert (rune_spell->clone ());
155 tmp = get_object (); 149
156 copy_object (rune_spell, tmp);
157 insert_ob_in_ob (tmp, rune);
158 if (spell->face != blank_face) 150 if (spell->face != blank_face)
159 rune->face = spell->face; 151 rune->face = spell->face;
160 } 152 }
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->x = nx;
164 rune->y = ny;
165 rune->map = m;
166 rune->direction = dir; /* where any spell will go upon detonation */ 156 rune->direction = dir; /* where any spell will go upon detonation */
167 set_owner (rune, op); /* runes without need no owner */ 157 rune->set_owner (op); /* runes without need no owner */
168 set_spell_skill (op, caster, spell, rune); 158 set_spell_skill (op, caster, spell, rune);
169 insert_ob_in_map (rune, m, op, 0); 159
160 m->insert (rune, nx, ny, op);
170 return 1; 161 return 1;
171
172} 162}
173
174
175 163
176/* move_rune: peterm 164/* move_rune: peterm
177 comments on runes: 165 comments on runes:
178 rune->level : level at which rune will cast its spell. 166 rune->level : level at which rune will cast its spell.
179 rune->hp : number of detonations before rune goes away 167 rune->hp : number of detonations before rune goes away
183 rune->attacktype: type of damage it does, if not casting spells 171 rune->attacktype: type of damage it does, if not casting spells
184 rune->other_arch: spell in the rune 172 rune->other_arch: spell in the rune
185 rune->Cha : how hidden the rune is 173 rune->Cha : how hidden the rune is
186 rune->maxhp : number of spells the rune casts 174 rune->maxhp : number of spells the rune casts
187*/ 175*/
188
189void 176void
190move_rune (object *op) 177move_rune (object *op)
191{ 178{
192 int det = 0; 179 /* runes of level zero cannot detonate. */
193
194 if (!op->level) 180 if (!op->level)
195 {
196 return; 181 return;
197 } /* runes of level zero cannot detonate. */ 182
198 det = op->invisible; 183 int det = op->invisible;
184
199 if (!(rndm (0, MAX (1, (op->stats.Cha)) - 1))) 185 if (!(rndm (0, MAX (1, (op->stats.Cha)) - 1)))
200 { 186 {
201 op->invisible = 0; 187 op->invisible = 0;
202 op->speed_left -= 1; 188 op->speed_left -= 1;
203 } 189 }
204 else 190 else
205 op->invisible = 1; 191 op->invisible = 1;
192
206 if (op->invisible != det) 193 if (op->invisible != det)
207 update_object (op, UP_OBJ_FACE); 194 update_object (op, UP_OBJ_CHANGE);
208} 195}
209
210 196
211/* peterm: rune_attack 197/* peterm: rune_attack
212 * function handles those runes which detonate but do not cast spells. 198 * function handles those runes which detonate but do not cast spells.
213 */ 199 */
214
215
216void 200void
217rune_attack (object *op, object *victim) 201rune_attack (object *op, object *victim)
218{ 202{
219 if (victim) 203 if (victim)
220 { 204 {
222 206
223 if (victim->destroyed ()) 207 if (victim->destroyed ())
224 return; 208 return;
225 209
226 /* if there's a disease in the needle, put it in the player */ 210 /* if there's a disease in the needle, put it in the player */
227 if (HAS_RANDOM_ITEMS (op)) 211 if (op->has_random_items ())
228 create_treasure (op->randomitems, op, 0, (victim->map ? victim->map->difficulty : 1), 0); 212 create_treasure (op->randomitems, op, 0, (victim->map ? victim->map->difficulty : 1), 0);
229 213
230 if (op->inv && op->inv->type == DISEASE) 214 if (op->inv && op->inv->type == DISEASE)
231 { 215 {
232 object *disease = op->inv; 216 object *disease = op->inv;
233 217
234 infect_object (victim, disease, 1); 218 infect_object (victim, disease, 1);
235 remove_ob (disease); 219 disease->destroy ();
236 free_object (disease);
237 } 220 }
238 } 221 }
239 else 222 else
240 hit_map (op, 0, op->attacktype, 1); 223 hit_map (op, 0, op->attacktype, 1);
241} 224}
271 new_draw_info (NDI_UNIQUE, 0, victim, trap->msg); 254 new_draw_info (NDI_UNIQUE, 0, victim, trap->msg);
272 255
273 /* 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
274 * knows what hit him. 257 * knows what hit him.
275 */ 258 */
276 env = object_get_env_recursive (trap); 259 env = trap->outer_env ();
277 260
278 /* 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.
279 * 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.
280 * At the same time, the trap will stick around until detonated 263 * At the same time, the trap will stick around until detonated
281 */ 264 */
282 get_rangevector (env, victim, &rv, 0); 265 get_rangevector (env, victim, &rv, 0);
283 if (rv.distance > 1) 266 if (rv.distance > 1)
284 return; 267 return;
285 268
269 env->play_sound (trap->sound ? trap->sound : sound_find ("trap_spring"));
270
286 trap_show (trap, env); 271 trap_show (trap, env);
287 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
288 /* Only if it is a spell do we proceed here */ 277 /* Only if it is a spell do we proceed here */
289 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))
290 { 279 {
291
292 if (trap->destroyed ()) 280 if (trap->destroyed ())
293 return; 281 return;
294 282
295 // breaks summon golem spells, which, for inexplicable reasons, 283 // breaks summon golem spells, which, for inexplicable reasons,
296 // 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
305 else 293 else
306 { 294 {
307 object *spell = arch_to_object (trap->other_arch); 295 object *spell = arch_to_object (trap->other_arch);
308 296
309 cast_spell (env, trap, trap->direction, spell, NULL); 297 cast_spell (env, trap, trap->direction, spell, NULL);
310 free_object (spell); 298 spell->destroy ();
311 } 299 }
312 } 300 }
313 } 301 }
314 else 302 else
315 { 303 {
352 { 340 {
353 new_draw_info (NDI_UNIQUE, 0, op, "There's nothing there!"); 341 new_draw_info (NDI_UNIQUE, 0, op, "There's nothing there!");
354 return 0; 342 return 0;
355 } 343 }
356 344
357 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)
358 { 346 {
359 if (tmp->type == RUNE || tmp->type == TRAP) 347 if (tmp->type == RUNE || tmp->type == TRAP)
360 break; 348 break;
361 349
362 /* we could put a probability chance here, but since nothing happens 350 /* we could put a probability chance here, but since nothing happens
363 * 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
364 * 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.
365 */ 353 */
366 if (tmp->type == SIGN && !strcmp (tmp->arch->name, "rune_mark")) 354 if (tmp->type == SIGN && tmp->arch->archname == shstr_rune_mark)
367 { 355 {
368 remove_ob (tmp); 356 tmp->destroy ();
369 free_object (tmp);
370 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!");
371 return 1; 358 return 1;
372 } 359 }
373 360
374 /* now search tmp's inventory for traps 361 /* now search tmp's inventory for traps
375 * 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.
376 */ 363 */
377 for (tmp2 = tmp->inv; tmp2 != NULL; tmp2 = tmp2->below) 364 for (tmp2 = tmp->inv; tmp2; tmp2 = tmp2->below)
378 { 365 {
379 if (tmp2->type == RUNE || tmp2->type == TRAP) 366 if (tmp2->type == RUNE || tmp2->type == TRAP)
380 { 367 {
381 tmp = tmp2; 368 tmp = tmp2;
382 searchflag = 0; 369 searchflag = 0;
383 break; 370 break;
384 } 371 }
385 } 372 }
373
386 if (!searchflag) 374 if (!searchflag)
387 break; 375 break;
388 } 376 }
389 377
390 /* no rune there. */ 378 /* no rune there. */
391 if (tmp == NULL) 379 if (tmp == NULL)
392 { 380 {
393 new_draw_info (NDI_UNIQUE, 0, op, "There's nothing there!"); 381 new_draw_info (NDI_UNIQUE, 0, op, "There's nothing there!");
394 return 0; 382 return 0;
395 } 383 }
384
396 trap_disarm (op, tmp, 0, skill); 385 trap_disarm (op, tmp, 0, skill);
397 return 1; 386 return 1;
398
399} 387}
400 388
401int 389int
402trap_see (object *op, object *trap) 390trap_see (object *op, object *trap)
403{ 391{
410 + trap->level + trap->stats.Cha - op->level) / 10.0 * 50.0)))))) 398 + trap->level + trap->stats.Cha - op->level) / 10.0 * 50.0))))))
411 { 399 {
412 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);
413 return 1; 401 return 1;
414 } 402 }
403
415 return 0; 404 return 0;
416} 405}
417 406
418int 407int
419trap_show (object *trap, object *where) 408trap_show (object *trap, object *where)
420{ 409{
421 object *tmp2;
422
423 if (where == NULL) 410 if (where == NULL)
424 return 0; 411 return 0;
412
425 tmp2 = get_archetype ("runedet"); 413 object *tmp = get_archetype ("runedet");
426 tmp2->face = &new_faces[GET_ANIMATION (trap, 0)]; 414 tmp->face = GET_ANIMATION (trap, 0);
427 tmp2->x = where->x; 415 tmp->insert_at (where, 0);
428 tmp2->y = where->y; 416
429 tmp2->map = where->map;
430 insert_ob_in_map (tmp2, where->map, NULL, 0);
431 return 1; 417 return 1;
432
433} 418}
434
435 419
436int 420int
437trap_disarm (object *disarmer, object *trap, int risk, object *skill) 421trap_disarm (object *disarmer, object *trap, int risk, object *skill)
438{ 422{
439 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 */
440 before we kill it */
441 424
442 /* this formula awards a more reasonable amount of exp */ 425 /* this formula awards a more reasonable amount of exp */
443 trapworth = MAX (1, trap->level) * disarmer->map->difficulty * 426 trapworth = MAX (1, trap->level)
427 * disarmer->map->difficulty
444 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;
445 430
446 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)))
447 { 432 {
448 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);
449 destroy_object (trap); 434 trap->destroy ();
435
450 /* 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
451 * get exp for it. 437 * get exp for it.
452 */ 438 */
453 if (trap->owner && trap->owner->type != PLAYER && risk) 439 if (trap->owner && trap->owner->type != PLAYER && risk)
454 return trapworth; 440 return trapworth;
465 } 451 }
466 return 0; 452 return 0;
467 } 453 }
468} 454}
469 455
470
471/* 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
472 * default traps are too strong for wimpy level 1 players, and 457 * default traps are too strong for wimpy level 1 players, and
473 * unthreatening to anyone of high level 458 * unthreatening to anyone of high level
474 */ 459 */
475
476void 460void
477trap_adjust (object *trap, int difficulty) 461trap_adjust (object *trap, int difficulty)
478{ 462{
479 int i; 463 int i;
480 464

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines