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.5 by root, Thu Sep 14 22:34:04 2006 UTC vs.
Revision 1.28 by root, Sun Jul 1 05:00:20 2007 UTC

1/* 1/*
2 CrossFire, A Multiplayer game for X-windows 2 * This file is part of Crossfire TRT, the Roguelike Realtime MORPG.
3 3 *
4 * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT 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 * Crossfire TRT 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 at <crossfire@schmorp.de> 21 * The authors can be reached via e-mail to <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
49int 45int
50write_rune (object *op, object *caster, object *spell, int dir, const char *runename) 46write_rune (object *op, object *caster, object *spell, int dir, const char *runename)
51{ 47{
52 object *tmp, *rune_spell, *rune; 48 object *tmp, *rune_spell, *rune;
53 char buf[MAX_BUF]; 49 char buf[MAX_BUF];
54 mapstruct *m; 50 maptile *m;
55 sint16 nx, ny; 51 sint16 nx, ny;
56 52
57 if (!dir) 53 if (!dir)
58 {
59 dir = 1; 54 dir = 1;
60 }
61 55
62 nx = op->x + freearr_x[dir]; 56 nx = op->x + freearr_x[dir];
63 ny = op->y + freearr_y[dir]; 57 ny = op->y + freearr_y[dir];
64 m = op->map; 58 m = op->map;
65 59
66 if (get_map_flags (m, &m, nx, ny, &nx, &ny)) 60 if (get_map_flags (m, &m, nx, ny, &nx, &ny) & (P_OUT_OF_MAP | P_SAFE | P_NO_MAGIC | P_NO_CLERIC))
67 { 61 {
68 new_draw_info (NDI_UNIQUE, 0, op, "Can't make a rune there!"); 62 new_draw_info (NDI_UNIQUE, 0, op, "Can't make a rune there!");
69 return 0; 63 return 0;
70 } 64 }
65
71 for (tmp = get_map_ob (m, nx, ny); tmp != NULL; tmp = tmp->above) 66 for (tmp = m->at (nx, ny).bot; tmp; tmp = tmp->above)
72 if (tmp->type == RUNE) 67 if (tmp->type == RUNE)
73 break; 68 break;
74 69
75 if (tmp) 70 if (tmp)
76 { 71 {
77 new_draw_info (NDI_UNIQUE, 0, op, "You can't write a rune there."); 72 new_draw_info (NDI_UNIQUE, 0, op, "You can't write a rune on top of another rune.");
78 return 0; 73 return 0;
79 } 74 }
80 75
81 if (spell->other_arch) 76 if (spell->other_arch)
82 {
83 rune_spell = arch_to_object (spell->other_arch); 77 rune_spell = arch_to_object (spell->other_arch);
84 }
85 else 78 else
86 { 79 {
87 /* Player specified spell. The player has to know the spell, so 80 /* Player specified spell. The player has to know the spell, so
88 * lets just look through the players inventory see if they know it 81 * lets just look through the players inventory see if they know it
89 * use the item_matched_string for our typical matching method. 82 * use the item_matched_string for our typical matching method.
96 return 0; 89 return 0;
97 } 90 }
98 91
99 rune_spell = NULL; 92 rune_spell = NULL;
100 for (tmp = op->inv; tmp; tmp = tmp->below) 93 for (tmp = op->inv; tmp; tmp = tmp->below)
101 {
102 if (tmp->type == SPELL) 94 if (tmp->type == SPELL)
103 { 95 {
104 ms = item_matched_string (op, tmp, runename); 96 ms = item_matched_string (op, tmp, runename);
105 if (ms > bestmatch) 97 if (ms > bestmatch)
106 { 98 {
107 bestmatch = ms; 99 bestmatch = ms;
108 rune_spell = tmp; 100 rune_spell = tmp;
109 } 101 }
110 } 102 }
111 } 103
112 if (!rune_spell) 104 if (!rune_spell)
113 { 105 {
114 new_draw_info_format (NDI_UNIQUE, 0, op, "You don't know any spell named %s", runename); 106 new_draw_info_format (NDI_UNIQUE, 0, op, "You don't know any spell named %s", runename);
115 return 0; 107 return 0;
116 } 108 }
109
117 if (rune_spell->skill != spell->skill) 110 if (rune_spell->skill != spell->skill)
118 { 111 {
119 new_draw_info_format (NDI_UNIQUE, 0, op, "You can't cast %s with %s", &rune_spell->name, &spell->name); 112 new_draw_info_format (NDI_UNIQUE, 0, op, "You can't cast %s with %s", &rune_spell->name, &spell->name);
120 return 0; 113 return 0;
121 } 114 }
115
122 if (caster->path_denied & spell->path_attuned) 116 if (caster->path_denied & spell->path_attuned && !caster->flag [FLAG_WIZCAST])
123 { 117 {
124 new_draw_info_format (NDI_UNIQUE, 0, op, "%s belongs to a spell path denied to you.", &rune_spell->name); 118 new_draw_info_format (NDI_UNIQUE, 0, op, "%s belongs to a spell path denied to you.", &rune_spell->name);
125 return 0; 119 return 0;
126 } 120 }
121
127 if (caster_level (caster, rune_spell) < rune_spell->level) 122 if (caster_level (caster, rune_spell) < rune_spell->level && !caster->flag [FLAG_WIZCAST])
128 { 123 {
129 new_draw_info_format (NDI_UNIQUE, 0, op, "%s is beyond your ability to cast!", &rune_spell->name); 124 new_draw_info_format (NDI_UNIQUE, 0, op, "%s is beyond your ability to cast!", &rune_spell->name);
130 return 0; 125 return 0;
131 } 126 }
127
132 if (SP_level_spellpoint_cost (caster, rune_spell, SPELL_MANA) > op->stats.sp) 128 if (SP_level_spellpoint_cost (caster, rune_spell, SPELL_MANA) > op->stats.sp)
133 { 129 {
134 new_draw_info (NDI_UNIQUE, 0, op, "You don't have enough mana."); 130 new_draw_info (NDI_UNIQUE, 0, op, "You don't have enough mana.");
135 return 0; 131 return 0;
136 } 132 }
133
137 if (SP_level_spellpoint_cost (caster, rune_spell, SPELL_GRACE) > op->stats.grace) 134 if (SP_level_spellpoint_cost (caster, rune_spell, SPELL_GRACE) > op->stats.grace)
138 { 135 {
139 new_draw_info (NDI_UNIQUE, 0, op, "You don't have enough grace."); 136 new_draw_info (NDI_UNIQUE, 0, op, "You don't have enough grace.");
140 return 0; 137 return 0;
141 } 138 }
139
142 op->stats.grace -= SP_level_spellpoint_cost (caster, rune_spell, SPELL_GRACE); 140 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); 141 op->stats.sp -= SP_level_spellpoint_cost (caster, rune_spell, SPELL_MANA);
144 } 142 }
143
145 /* already proper rune. Note this should only be the case if other_arch was set */ 144 /* already proper rune. Note this should only be the case if other_arch was set */
146 if (rune_spell->type == RUNE) 145 if (rune_spell->type == RUNE)
147 {
148 rune = rune_spell; 146 rune = rune_spell;
149 }
150 else 147 else
151 { 148 {
152 rune = get_archetype (GENERIC_RUNE); 149 rune = get_archetype (GENERIC_RUNE);
153 sprintf (buf, "You set off a rune of %s\n", &rune_spell->name); 150 sprintf (buf, "You set off a rune of %s\n", &rune_spell->name);
154 rune->msg = buf; 151 rune->msg = buf;
155 tmp = get_object (); 152 rune->insert (rune_spell->clone ());
156 copy_object (rune_spell, tmp); 153
157 insert_ob_in_ob (tmp, rune);
158 if (spell->face != blank_face) 154 if (spell->face != blank_face)
159 rune->face = spell->face; 155 rune->face = spell->face;
160 } 156 }
157
161 rune->level = caster_level (caster, spell); 158 rune->level = caster_level (caster, spell);
162 rune->stats.Cha = rune->level / 2; /* the invisibility parameter */ 159 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 */ 160 rune->direction = dir; /* where any spell will go upon detonation */
167 set_owner (rune, op); /* runes without need no owner */ 161 rune->set_owner (op); /* runes without need no owner */
168 set_spell_skill (op, caster, spell, rune); 162 set_spell_skill (op, caster, spell, rune);
169 insert_ob_in_map (rune, m, op, 0); 163
164 m->insert (rune, nx, ny, op);
170 return 1; 165 return 1;
171
172} 166}
173
174
175 167
176/* move_rune: peterm 168/* move_rune: peterm
177 comments on runes: 169 comments on runes:
178 rune->level : level at which rune will cast its spell. 170 rune->level : level at which rune will cast its spell.
179 rune->hp : number of detonations before rune goes away 171 rune->hp : number of detonations before rune goes away
183 rune->attacktype: type of damage it does, if not casting spells 175 rune->attacktype: type of damage it does, if not casting spells
184 rune->other_arch: spell in the rune 176 rune->other_arch: spell in the rune
185 rune->Cha : how hidden the rune is 177 rune->Cha : how hidden the rune is
186 rune->maxhp : number of spells the rune casts 178 rune->maxhp : number of spells the rune casts
187*/ 179*/
188
189void 180void
190move_rune (object *op) 181move_rune (object *op)
191{ 182{
192 int det = 0; 183 /* runes of level zero cannot detonate. */
193
194 if (!op->level) 184 if (!op->level)
195 {
196 return; 185 return;
197 } /* runes of level zero cannot detonate. */ 186
198 det = op->invisible; 187 int det = op->invisible;
188
199 if (!(rndm (0, MAX (1, (op->stats.Cha)) - 1))) 189 if (!(rndm (0, MAX (1, (op->stats.Cha)) - 1)))
200 { 190 {
201 op->invisible = 0; 191 op->invisible = 0;
202 op->speed_left -= 1; 192 op->speed_left -= 1;
203 } 193 }
204 else 194 else
205 op->invisible = 1; 195 op->invisible = 1;
196
206 if (op->invisible != det) 197 if (op->invisible != det)
207 update_object (op, UP_OBJ_FACE); 198 update_object (op, UP_OBJ_CHANGE);
208} 199}
209
210 200
211/* peterm: rune_attack 201/* peterm: rune_attack
212 * function handles those runes which detonate but do not cast spells. 202 * function handles those runes which detonate but do not cast spells.
213 */ 203 */
214
215
216void 204void
217rune_attack (object *op, object *victim) 205rune_attack (object *op, object *victim)
218{ 206{
219 if (victim) 207 if (victim)
220 { 208 {
221 tag_t tag = victim->count;
222
223 hit_player (victim, op->stats.dam, op, op->attacktype, 1); 209 hit_player (victim, op->stats.dam, op, op->attacktype, 1);
224 if (was_destroyed (victim, tag)) 210
211 if (victim->destroyed ())
225 return; 212 return;
213
226 /* if there's a disease in the needle, put it in the player */ 214 /* if there's a disease in the needle, put it in the player */
227 if (HAS_RANDOM_ITEMS (op)) 215 if (op->has_random_items ())
228 create_treasure (op->randomitems, op, 0, (victim->map ? victim->map->difficulty : 1), 0); 216 create_treasure (op->randomitems, op, 0, (victim->map ? victim->map->difficulty : 1), 0);
217
229 if (op->inv && op->inv->type == DISEASE) 218 if (op->inv && op->inv->type == DISEASE)
230 { 219 {
231 object *disease = op->inv; 220 object *disease = op->inv;
232 221
233 infect_object (victim, disease, 1); 222 infect_object (victim, disease, 1);
234 remove_ob (disease); 223 disease->destroy ();
235 free_object (disease);
236 } 224 }
237 } 225 }
238 else 226 else
239 hit_map (op, 0, op->attacktype, 1); 227 hit_map (op, 0, op->attacktype, 1);
240} 228}
245 */ 233 */
246void 234void
247spring_trap (object *trap, object *victim) 235spring_trap (object *trap, object *victim)
248{ 236{
249 object *env; 237 object *env;
250 tag_t trap_tag = trap->count;
251 rv_vector rv; 238 rv_vector rv;
252 int i; 239 int i;
253 240
254 /* Prevent recursion */ 241 /* Prevent recursion */
255 if (trap->stats.hp <= 0) 242 if (trap->stats.hp <= 0)
283 if (rv.distance > 1) 270 if (rv.distance > 1)
284 return; 271 return;
285 272
286 trap_show (trap, env); 273 trap_show (trap, env);
287 274
275 if (victim->type == PLAYER) // only count players as enemies
276 trap->enemy = victim; // set the victim as the traps enemy, so that summoned
277 // creatures know who to attack.
278
288 /* Only if it is a spell do we proceed here */ 279 /* 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)) 280 if ((trap->inv && trap->inv->type == SPELL) || (trap->other_arch && trap->other_arch->type == SPELL))
290 { 281 {
291 282
292 if (was_destroyed (trap, trap_tag)) 283 if (trap->destroyed ())
293 return; 284 return;
294 285
295 // breaks summon golem spells, which, for inexplicable reasons, 286 // breaks summon golem spells, which, for inexplicable reasons,
296 // do not work like summon golem spells at all but still require 287 // do not work like summon golem spells at all but still require
297 // direction "0" to work at all. 288 // direction "0" to work at all.
305 else 296 else
306 { 297 {
307 object *spell = arch_to_object (trap->other_arch); 298 object *spell = arch_to_object (trap->other_arch);
308 299
309 cast_spell (env, trap, trap->direction, spell, NULL); 300 cast_spell (env, trap, trap->direction, spell, NULL);
310 free_object (spell); 301 spell->destroy ();
311 } 302 }
312 } 303 }
313 } 304 }
314 else 305 else
315 { 306 {
316 rune_attack (trap, victim); 307 rune_attack (trap, victim);
317 if (was_destroyed (trap, trap_tag)) 308 if (trap->destroyed ())
318 return; 309 return;
319 } 310 }
320 311
321 if (trap->stats.hp <= 0) 312 if (trap->stats.hp <= 0)
322 { 313 {
335dispel_rune (object *op, object *caster, object *spell, object *skill, int dir) 326dispel_rune (object *op, object *caster, object *spell, object *skill, int dir)
336{ 327{
337 object *tmp, *tmp2; 328 object *tmp, *tmp2;
338 int searchflag = 1, mflags; 329 int searchflag = 1, mflags;
339 sint16 x, y; 330 sint16 x, y;
340 mapstruct *m; 331 maptile *m;
341 332
342 x = op->x + freearr_x[dir]; 333 x = op->x + freearr_x[dir];
343 y = op->y + freearr_y[dir]; 334 y = op->y + freearr_y[dir];
344 m = op->map; 335 m = op->map;
345 336
352 { 343 {
353 new_draw_info (NDI_UNIQUE, 0, op, "There's nothing there!"); 344 new_draw_info (NDI_UNIQUE, 0, op, "There's nothing there!");
354 return 0; 345 return 0;
355 } 346 }
356 347
357 for (tmp = get_map_ob (m, x, y); tmp != NULL; tmp = tmp->above) 348 for (tmp = GET_MAP_OB (m, x, y); tmp != NULL; tmp = tmp->above)
358 { 349 {
359 if (tmp->type == RUNE || tmp->type == TRAP) 350 if (tmp->type == RUNE || tmp->type == TRAP)
360 break; 351 break;
361 352
362 /* we could put a probability chance here, but since nothing happens 353 /* 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 354 * 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. 355 * comparison so low level players can't erase high level players runes.
365 */ 356 */
366 if (tmp->type == SIGN && !strcmp (tmp->arch->name, "rune_mark")) 357 if (tmp->type == SIGN && !strcmp (tmp->arch->archname, "rune_mark"))
367 { 358 {
368 remove_ob (tmp); 359 tmp->destroy ();
369 free_object (tmp);
370 new_draw_info (NDI_UNIQUE, 0, op, "You wipe out the rune of marking!"); 360 new_draw_info (NDI_UNIQUE, 0, op, "You wipe out the rune of marking!");
371 return 1; 361 return 1;
372 } 362 }
373 363
374 /* now search tmp's inventory for traps 364 /* now search tmp's inventory for traps
416} 406}
417 407
418int 408int
419trap_show (object *trap, object *where) 409trap_show (object *trap, object *where)
420{ 410{
421 object *tmp2;
422
423 if (where == NULL) 411 if (where == NULL)
424 return 0; 412 return 0;
413
425 tmp2 = get_archetype ("runedet"); 414 object *tmp = get_archetype ("runedet");
426 tmp2->face = &new_faces[GET_ANIMATION (trap, 0)]; 415 tmp->face = GET_ANIMATION (trap, 0);
427 tmp2->x = where->x; 416 tmp->insert_at (where, 0);
428 tmp2->y = where->y; 417
429 tmp2->map = where->map;
430 insert_ob_in_map (tmp2, where->map, NULL, 0);
431 return 1; 418 return 1;
432
433} 419}
434
435 420
436int 421int
437trap_disarm (object *disarmer, object *trap, int risk, object *skill) 422trap_disarm (object *disarmer, object *trap, int risk, object *skill)
438{ 423{
439 int trapworth; /* need to compute the experience worth of the trap 424 int trapworth; /* need to compute the experience worth of the trap
444 sqr (MAX (trap->stats.dam, trap->inv ? trap->inv->level : 1)) / skill->level; 429 sqr (MAX (trap->stats.dam, trap->inv ? trap->inv->level : 1)) / 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 (1);
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;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines