ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/server/rune.C
Revision: 1.14
Committed: Tue Dec 26 08:55:00 2006 UTC (17 years, 5 months ago) by root
Content type: text/plain
Branch: MAIN
Changes since 1.13: +1 -5 lines
Log Message:
replace update_ob_speed by ->set_speed

File Contents

# Content
1 /*
2 CrossFire, A Multiplayer game for X-windows
3
4 Copyright (C) 2003 Mark Wedel & Crossfire Development Team
5 Copyright (C) 1992 Frank Tore Johansen
6
7 This program 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 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 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 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20
21 The authors can be reached via e-mail at <crossfire@schmorp.de>
22 */
23
24 #include <global.h>
25 #include <sproto.h>
26 #include <spells.h>
27
28 #ifndef sqr
29 # define sqr(x) ((x)*(x))
30 #endif
31
32 /* peterm:
33 * write_rune:
34 * op: rune writer
35 * skop: skill object used for casting this rune
36 * dir: orientation of rune, direction rune's contained spell will
37 * be cast in, if applicable
38 * inspell: spell object to put into the rune, can be null if doing
39 * a marking rune.
40 * level: level of casting of the rune
41 * runename: name of the rune or message displayed by the rune for
42 * a rune of marking
43 */
44
45 int
46 write_rune (object *op, object *caster, object *spell, int dir, const char *runename)
47 {
48 object *tmp, *rune_spell, *rune;
49 char buf[MAX_BUF];
50 maptile *m;
51 sint16 nx, ny;
52
53 if (!dir)
54 dir = 1;
55
56 nx = op->x + freearr_x[dir];
57 ny = op->y + freearr_y[dir];
58 m = op->map;
59
60 if (get_map_flags (m, &m, nx, ny, &nx, &ny))
61 {
62 new_draw_info (NDI_UNIQUE, 0, op, "Can't make a rune there!");
63 return 0;
64 }
65
66 for (tmp = GET_MAP_OB (m, nx, ny); tmp != NULL; tmp = tmp->above)
67 if (tmp->type == RUNE)
68 break;
69
70 if (tmp)
71 {
72 new_draw_info (NDI_UNIQUE, 0, op, "You can't write a rune there.");
73 return 0;
74 }
75
76 if (spell->other_arch)
77 rune_spell = arch_to_object (spell->other_arch);
78 else
79 {
80 /* Player specified spell. The player has to know the spell, so
81 * lets just look through the players inventory see if they know it
82 * use the item_matched_string for our typical matching method.
83 */
84 int bestmatch = 0, ms;
85
86 if (!runename || *runename == 0)
87 {
88 new_draw_info (NDI_UNIQUE, 0, op, "Write a rune of what?");
89 return 0;
90 }
91
92 rune_spell = NULL;
93 for (tmp = op->inv; tmp; tmp = tmp->below)
94 {
95 if (tmp->type == SPELL)
96 {
97 ms = item_matched_string (op, tmp, runename);
98 if (ms > bestmatch)
99 {
100 bestmatch = ms;
101 rune_spell = tmp;
102 }
103 }
104 }
105
106 if (!rune_spell)
107 {
108 new_draw_info_format (NDI_UNIQUE, 0, op, "You don't know any spell named %s", runename);
109 return 0;
110 }
111
112 if (rune_spell->skill != spell->skill)
113 {
114 new_draw_info_format (NDI_UNIQUE, 0, op, "You can't cast %s with %s", &rune_spell->name, &spell->name);
115 return 0;
116 }
117
118 if (caster->path_denied & spell->path_attuned)
119 {
120 new_draw_info_format (NDI_UNIQUE, 0, op, "%s belongs to a spell path denied to you.", &rune_spell->name);
121 return 0;
122 }
123
124 if (caster_level (caster, rune_spell) < rune_spell->level)
125 {
126 new_draw_info_format (NDI_UNIQUE, 0, op, "%s is beyond your ability to cast!", &rune_spell->name);
127 return 0;
128 }
129
130 if (SP_level_spellpoint_cost (caster, rune_spell, SPELL_MANA) > op->stats.sp)
131 {
132 new_draw_info (NDI_UNIQUE, 0, op, "You don't have enough mana.");
133 return 0;
134 }
135
136 if (SP_level_spellpoint_cost (caster, rune_spell, SPELL_GRACE) > op->stats.grace)
137 {
138 new_draw_info (NDI_UNIQUE, 0, op, "You don't have enough grace.");
139 return 0;
140 }
141
142 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);
144 }
145
146 /* already proper rune. Note this should only be the case if other_arch was set */
147 if (rune_spell->type == RUNE)
148 {
149 rune = rune_spell;
150 }
151 else
152 {
153 rune = get_archetype (GENERIC_RUNE);
154 sprintf (buf, "You set off a rune of %s\n", &rune_spell->name);
155 rune->msg = buf;
156 tmp = rune_spell->clone ();
157 insert_ob_in_ob (tmp, rune);
158
159 if (spell->face != blank_face)
160 rune->face = spell->face;
161 }
162
163 rune->level = caster_level (caster, spell);
164 rune->stats.Cha = rune->level / 2; /* the invisibility parameter */
165 rune->x = nx;
166 rune->y = ny;
167 rune->map = m;
168 rune->direction = dir; /* where any spell will go upon detonation */
169 rune->set_owner (op); /* runes without need no owner */
170 set_spell_skill (op, caster, spell, rune);
171 insert_ob_in_map (rune, m, op, 0);
172 return 1;
173
174 }
175
176
177
178 /* move_rune: peterm
179 comments on runes:
180 rune->level : level at which rune will cast its spell.
181 rune->hp : number of detonations before rune goes away
182 rune->msg : message the rune displays when it goes off
183 rune->direction : direction it will cast a spell in
184 rune->dam : damage the rune will do if it doesn't cast spells
185 rune->attacktype: type of damage it does, if not casting spells
186 rune->other_arch: spell in the rune
187 rune->Cha : how hidden the rune is
188 rune->maxhp : number of spells the rune casts
189 */
190
191 void
192 move_rune (object *op)
193 {
194 int det = 0;
195
196 if (!op->level)
197 {
198 return;
199 } /* runes of level zero cannot detonate. */
200 det = op->invisible;
201 if (!(rndm (0, MAX (1, (op->stats.Cha)) - 1)))
202 {
203 op->invisible = 0;
204 op->speed_left -= 1;
205 }
206 else
207 op->invisible = 1;
208 if (op->invisible != det)
209 update_object (op, UP_OBJ_FACE);
210 }
211
212
213 /* peterm: rune_attack
214 * function handles those runes which detonate but do not cast spells.
215 */
216
217
218 void
219 rune_attack (object *op, object *victim)
220 {
221 if (victim)
222 {
223 hit_player (victim, op->stats.dam, op, op->attacktype, 1);
224
225 if (victim->destroyed ())
226 return;
227
228 /* if there's a disease in the needle, put it in the player */
229 if (op->has_random_items ())
230 create_treasure (op->randomitems, op, 0, (victim->map ? victim->map->difficulty : 1), 0);
231
232 if (op->inv && op->inv->type == DISEASE)
233 {
234 object *disease = op->inv;
235
236 infect_object (victim, disease, 1);
237 disease->destroy ();
238 }
239 }
240 else
241 hit_map (op, 0, op->attacktype, 1);
242 }
243
244 /* This function generalizes attacks by runes/traps. This ought to make
245 * it possible for runes to attack from the inventory,
246 * it'll spring the trap on the victim.
247 */
248 void
249 spring_trap (object *trap, object *victim)
250 {
251 object *env;
252 rv_vector rv;
253 int i;
254
255 /* Prevent recursion */
256 if (trap->stats.hp <= 0)
257 return;
258
259 if (QUERY_FLAG (trap, FLAG_IS_LINKED))
260 use_trigger (trap);
261
262 /* Only living objects can trigger runes that don't cast spells, as
263 * doing direct damage to a non-living object doesn't work anyway.
264 * Typical example is an arrow attacking a door.
265 */
266 if (!QUERY_FLAG (victim, FLAG_ALIVE) && !trap->inv && !trap->other_arch)
267 return;
268
269 trap->stats.hp--; /*decrement detcount */
270
271 if (victim && victim->type == PLAYER)
272 new_draw_info (NDI_UNIQUE, 0, victim, trap->msg);
273
274 /* Flash an image of the trap on the map so the poor sod
275 * knows what hit him.
276 */
277 env = object_get_env_recursive (trap);
278
279 /* If the victim is not next to this trap, don't set it off.
280 * players shouldn't get hit by firing arrows at a door for example.
281 * At the same time, the trap will stick around until detonated
282 */
283 get_rangevector (env, victim, &rv, 0);
284 if (rv.distance > 1)
285 return;
286
287 trap_show (trap, env);
288
289 /* Only if it is a spell do we proceed here */
290 if ((trap->inv && trap->inv->type == SPELL) || (trap->other_arch && trap->other_arch->clone.type == SPELL))
291 {
292
293 if (trap->destroyed ())
294 return;
295
296 // breaks summon golem spells, which, for inexplicable reasons,
297 // do not work like summon golem spells at all but still require
298 // direction "0" to work at all.
299 //if (trap->direction)
300 // rv.direction = trap->direction;
301
302 for (i = 0; i < MAX (1, trap->stats.maxhp); i++)
303 {
304 if (trap->inv)
305 cast_spell (env, trap, trap->direction, trap->inv, NULL);
306 else
307 {
308 object *spell = arch_to_object (trap->other_arch);
309
310 cast_spell (env, trap, trap->direction, spell, NULL);
311 spell->destroy ();
312 }
313 }
314 }
315 else
316 {
317 rune_attack (trap, victim);
318 if (trap->destroyed ())
319 return;
320 }
321
322 if (trap->stats.hp <= 0)
323 {
324 trap->type = SIGN; /* make the trap impotent */
325 trap->stats.food = 20; /* make it stick around until its spells are gone */
326 SET_FLAG (trap, FLAG_IS_USED_UP);
327 }
328 }
329
330 /* dispel_rune: by peterm
331 * dispels the target rune, depending on the level of the actor
332 * and the level of the rune risk flag, if true, means that there is
333 * a chance that the trap/rune will detonate
334 */
335 int
336 dispel_rune (object *op, object *caster, object *spell, object *skill, int dir)
337 {
338 object *tmp, *tmp2;
339 int searchflag = 1, mflags;
340 sint16 x, y;
341 maptile *m;
342
343 x = op->x + freearr_x[dir];
344 y = op->y + freearr_y[dir];
345 m = op->map;
346
347 mflags = get_map_flags (m, &m, x, y, &x, &y);
348
349 /* Should we perhaps not allow player to disable traps if a monster/
350 * player is standing on top?
351 */
352 if (mflags & P_OUT_OF_MAP)
353 {
354 new_draw_info (NDI_UNIQUE, 0, op, "There's nothing there!");
355 return 0;
356 }
357
358 for (tmp = GET_MAP_OB (m, x, y); tmp != NULL; tmp = tmp->above)
359 {
360 if (tmp->type == RUNE || tmp->type == TRAP)
361 break;
362
363 /* we could put a probability chance here, but since nothing happens
364 * if you fail, no point on that. I suppose we could do a level
365 * comparison so low level players can't erase high level players runes.
366 */
367 if (tmp->type == SIGN && !strcmp (tmp->arch->name, "rune_mark"))
368 {
369 tmp->destroy ();
370 new_draw_info (NDI_UNIQUE, 0, op, "You wipe out the rune of marking!");
371 return 1;
372 }
373
374 /* now search tmp's inventory for traps
375 * This is for chests, where the rune is in the chests inventory.
376 */
377 for (tmp2 = tmp->inv; tmp2 != NULL; tmp2 = tmp2->below)
378 {
379 if (tmp2->type == RUNE || tmp2->type == TRAP)
380 {
381 tmp = tmp2;
382 searchflag = 0;
383 break;
384 }
385 }
386 if (!searchflag)
387 break;
388 }
389
390 /* no rune there. */
391 if (tmp == NULL)
392 {
393 new_draw_info (NDI_UNIQUE, 0, op, "There's nothing there!");
394 return 0;
395 }
396 trap_disarm (op, tmp, 0, skill);
397 return 1;
398
399 }
400
401 int
402 trap_see (object *op, object *trap)
403 {
404 int chance;
405
406 chance = random_roll (0, 99, op, PREFER_HIGH);;
407
408 /* decide if we see the rune or not */
409 if ((trap->stats.Cha == 1) || (chance > MIN (95, MAX (5, ((int) ((float) (op->map->difficulty
410 + trap->level + trap->stats.Cha - op->level) / 10.0 * 50.0))))))
411 {
412 new_draw_info_format (NDI_UNIQUE, 0, op, "You spot a %s!", &trap->name);
413 return 1;
414 }
415 return 0;
416 }
417
418 int
419 trap_show (object *trap, object *where)
420 {
421 object *tmp2;
422
423 if (where == NULL)
424 return 0;
425 tmp2 = get_archetype ("runedet");
426 tmp2->face = &new_faces[GET_ANIMATION (trap, 0)];
427 tmp2->x = where->x;
428 tmp2->y = where->y;
429 tmp2->map = where->map;
430 insert_ob_in_map (tmp2, where->map, NULL, 0);
431 return 1;
432
433 }
434
435
436 int
437 trap_disarm (object *disarmer, object *trap, int risk, object *skill)
438 {
439 int trapworth; /* need to compute the experience worth of the trap
440 before we kill it */
441
442 /* this formula awards a more reasonable amount of exp */
443 trapworth = MAX (1, trap->level) * disarmer->map->difficulty *
444 sqr (MAX (trap->stats.dam, trap->inv ? trap->inv->level : 1)) / skill->level;
445
446 if (!(random_roll (0, (MAX (2, MIN (20, trap->level - skill->level + 5 - disarmer->stats.Dex / 2)) - 1), disarmer, PREFER_LOW)))
447 {
448 new_draw_info_format (NDI_UNIQUE, 0, disarmer, "You successfully disarm the %s!", &trap->name);
449 trap->destroy (1);
450
451 /* If it is your own trap, (or any players trap), don't you don't
452 * get exp for it.
453 */
454 if (trap->owner && trap->owner->type != PLAYER && risk)
455 return trapworth;
456 else
457 return 1; /* give minimal exp and say success */
458 }
459 else
460 {
461 new_draw_info_format (NDI_UNIQUE, 0, disarmer, "You fail to disarm the %s.", &trap->name);
462 if (!(random_roll (0, (MAX (2, skill->level - trap->level + disarmer->stats.Dex / 2 - 6)) - 1, disarmer, PREFER_LOW)) && risk)
463 {
464 new_draw_info (NDI_UNIQUE, 0, disarmer, "In fact, you set it off!");
465 spring_trap (trap, disarmer);
466 }
467 return 0;
468 }
469 }
470
471
472 /* traps need to be adjusted for the difficulty of the map. The
473 * default traps are too strong for wimpy level 1 players, and
474 * unthreatening to anyone of high level
475 */
476
477 void
478 trap_adjust (object *trap, int difficulty)
479 {
480 int i;
481
482 /* now we set the trap level to match the difficulty of the level
483 * the formula below will give a level from 1 to (2*difficulty) with
484 * a peak probability at difficulty
485 */
486
487 trap->level = rndm (0, difficulty - 1) + rndm (0, difficulty - 1);
488 if (trap->level < 1)
489 trap->level = 1;
490
491 /* set the hiddenness of the trap, similar formula to above */
492 trap->stats.Cha = rndm (0, 19) + rndm (0, difficulty - 1) + rndm (0, difficulty - 1);
493
494 if (!trap->other_arch && !trap->inv)
495 {
496 /* set the damage of the trap.
497 * we get 0-4 pts of damage per level of difficulty of the map in
498 * the trap
499 */
500
501 trap->stats.dam = 0;
502 for (i = 0; i < difficulty; i++)
503 trap->stats.dam += rndm (0, 4);
504
505 /* the poison trap special case */
506 if (trap->attacktype & AT_POISON)
507 {
508 trap->stats.dam = rndm (0, difficulty - 1);
509 if (trap->stats.dam < 1)
510 trap->stats.dam = 1;
511 }
512
513 /* so we get an appropriate amnt of exp for AT_DEATH traps */
514 if (trap->attacktype & AT_DEATH)
515 trap->stats.dam = 127;
516 }
517
518 }