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.4 by root, Sun Sep 10 15:59:57 2006 UTC vs.
Revision 1.19 by root, Fri Feb 2 22:49:11 2007 UTC

1
2/* 1/*
3 * static char *rcsid_rune_c = 2 * CrossFire, A Multiplayer game for X-windows
4 * "$Id: rune.C,v 1.4 2006/09/10 15:59:57 root Exp $"; 3 *
4 * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team
5 * Copyright (C) 2003 Mark Wedel & Crossfire Development Team
6 * Copyright (C) 1992 Frank Tore Johansen
7 *
8 * This program is free software; you can redistribute it and/or modify
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
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
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
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 *
22 * The authors can be reached via e-mail at <crossfire@schmorp.de>
5 */ 23 */
6 24
7/*
8 CrossFire, A Multiplayer game for X-windows
9
10 Copyright (C) 2003 Mark Wedel & Crossfire Development Team
11 Copyright (C) 1992 Frank Tore Johansen
12
13 This program is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation; either version 2 of the License, or
16 (at your option) any later version.
17
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software
25 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26
27 The authors can be reached via e-mail at crossfire-devel@real-time.com
28*/
29
30#include <global.h> 25#include <global.h>
31#ifndef __CEXTRACT__
32# include <sproto.h> 26#include <sproto.h>
33#endif
34#include <spells.h> 27#include <spells.h>
35
36 28
37#ifndef sqr 29#ifndef sqr
38# define sqr(x) ((x)*(x)) 30# define sqr(x) ((x)*(x))
39#endif 31#endif
40
41 32
42/* peterm: 33/* peterm:
43 * write_rune: 34 * write_rune:
44 * op: rune writer 35 * op: rune writer
45 * skop: skill object used for casting this rune 36 * skop: skill object used for casting this rune
55int 46int
56write_rune (object *op, object *caster, object *spell, int dir, const char *runename) 47write_rune (object *op, object *caster, object *spell, int dir, const char *runename)
57{ 48{
58 object *tmp, *rune_spell, *rune; 49 object *tmp, *rune_spell, *rune;
59 char buf[MAX_BUF]; 50 char buf[MAX_BUF];
60 mapstruct *m; 51 maptile *m;
61 sint16 nx, ny; 52 sint16 nx, ny;
62 53
63 if (!dir) 54 if (!dir)
64 {
65 dir = 1; 55 dir = 1;
66 }
67 56
68 nx = op->x + freearr_x[dir]; 57 nx = op->x + freearr_x[dir];
69 ny = op->y + freearr_y[dir]; 58 ny = op->y + freearr_y[dir];
70 m = op->map; 59 m = op->map;
71 60
72 if (get_map_flags (m, &m, nx, ny, &nx, &ny)) 61 if (get_map_flags (m, &m, nx, ny, &nx, &ny) && (P_OUT_OF_MAP | P_SAFE | P_NO_MAGIC | P_NO_CLERIC))
73 { 62 {
74 new_draw_info (NDI_UNIQUE, 0, op, "Can't make a rune there!"); 63 new_draw_info (NDI_UNIQUE, 0, op, "Can't make a rune there!");
75 return 0; 64 return 0;
76 } 65 }
66
77 for (tmp = get_map_ob (m, nx, ny); tmp != NULL; tmp = tmp->above) 67 for (tmp = m->at (nx, ny).bot; tmp; tmp = tmp->above)
78 if (tmp->type == RUNE) 68 if (tmp->type == RUNE)
79 break; 69 break;
80 70
81 if (tmp) 71 if (tmp)
82 { 72 {
83 new_draw_info (NDI_UNIQUE, 0, op, "You can't write a rune there."); 73 new_draw_info (NDI_UNIQUE, 0, op, "You can't write a rune there.");
84 return 0; 74 return 0;
85 } 75 }
86 76
87 if (spell->other_arch) 77 if (spell->other_arch)
88 {
89 rune_spell = arch_to_object (spell->other_arch); 78 rune_spell = arch_to_object (spell->other_arch);
90 }
91 else 79 else
92 { 80 {
93 /* Player specified spell. The player has to know the spell, so 81 /* Player specified spell. The player has to know the spell, so
94 * lets just look through the players inventory see if they know it 82 * lets just look through the players inventory see if they know it
95 * use the item_matched_string for our typical matching method. 83 * use the item_matched_string for our typical matching method.
113 bestmatch = ms; 101 bestmatch = ms;
114 rune_spell = tmp; 102 rune_spell = tmp;
115 } 103 }
116 } 104 }
117 } 105 }
106
118 if (!rune_spell) 107 if (!rune_spell)
119 { 108 {
120 new_draw_info_format (NDI_UNIQUE, 0, op, "You don't know any spell named %s", runename); 109 new_draw_info_format (NDI_UNIQUE, 0, op, "You don't know any spell named %s", runename);
121 return 0; 110 return 0;
122 } 111 }
112
123 if (rune_spell->skill != spell->skill) 113 if (rune_spell->skill != spell->skill)
124 { 114 {
125 new_draw_info_format (NDI_UNIQUE, 0, op, "You can't cast %s with %s", &rune_spell->name, &spell->name); 115 new_draw_info_format (NDI_UNIQUE, 0, op, "You can't cast %s with %s", &rune_spell->name, &spell->name);
126 return 0; 116 return 0;
127 } 117 }
118
128 if (caster->path_denied & spell->path_attuned) 119 if (caster->path_denied & spell->path_attuned)
129 { 120 {
130 new_draw_info_format (NDI_UNIQUE, 0, op, "%s belongs to a spell path denied to you.", &rune_spell->name); 121 new_draw_info_format (NDI_UNIQUE, 0, op, "%s belongs to a spell path denied to you.", &rune_spell->name);
131 return 0; 122 return 0;
132 } 123 }
124
133 if (caster_level (caster, rune_spell) < rune_spell->level) 125 if (caster_level (caster, rune_spell) < rune_spell->level)
134 { 126 {
135 new_draw_info_format (NDI_UNIQUE, 0, op, "%s is beyond your ability to cast!", &rune_spell->name); 127 new_draw_info_format (NDI_UNIQUE, 0, op, "%s is beyond your ability to cast!", &rune_spell->name);
136 return 0; 128 return 0;
137 } 129 }
130
138 if (SP_level_spellpoint_cost (caster, rune_spell, SPELL_MANA) > op->stats.sp) 131 if (SP_level_spellpoint_cost (caster, rune_spell, SPELL_MANA) > op->stats.sp)
139 { 132 {
140 new_draw_info (NDI_UNIQUE, 0, op, "You don't have enough mana."); 133 new_draw_info (NDI_UNIQUE, 0, op, "You don't have enough mana.");
141 return 0; 134 return 0;
142 } 135 }
136
143 if (SP_level_spellpoint_cost (caster, rune_spell, SPELL_GRACE) > op->stats.grace) 137 if (SP_level_spellpoint_cost (caster, rune_spell, SPELL_GRACE) > op->stats.grace)
144 { 138 {
145 new_draw_info (NDI_UNIQUE, 0, op, "You don't have enough grace."); 139 new_draw_info (NDI_UNIQUE, 0, op, "You don't have enough grace.");
146 return 0; 140 return 0;
147 } 141 }
142
148 op->stats.grace -= SP_level_spellpoint_cost (caster, rune_spell, SPELL_GRACE); 143 op->stats.grace -= SP_level_spellpoint_cost (caster, rune_spell, SPELL_GRACE);
149 op->stats.sp -= SP_level_spellpoint_cost (caster, rune_spell, SPELL_MANA); 144 op->stats.sp -= SP_level_spellpoint_cost (caster, rune_spell, SPELL_MANA);
150 } 145 }
146
151 /* already proper rune. Note this should only be the case if other_arch was set */ 147 /* already proper rune. Note this should only be the case if other_arch was set */
152 if (rune_spell->type == RUNE) 148 if (rune_spell->type == RUNE)
153 {
154 rune = rune_spell; 149 rune = rune_spell;
155 }
156 else 150 else
157 { 151 {
158 rune = get_archetype (GENERIC_RUNE); 152 rune = get_archetype (GENERIC_RUNE);
159 sprintf (buf, "You set off a rune of %s\n", &rune_spell->name); 153 sprintf (buf, "You set off a rune of %s\n", &rune_spell->name);
160 rune->msg = buf; 154 rune->msg = buf;
161 tmp = get_object (); 155 rune->insert (rune_spell->clone ());
162 copy_object (rune_spell, tmp); 156
163 insert_ob_in_ob (tmp, rune);
164 if (spell->face != blank_face) 157 if (spell->face != blank_face)
165 rune->face = spell->face; 158 rune->face = spell->face;
166 } 159 }
160
167 rune->level = caster_level (caster, spell); 161 rune->level = caster_level (caster, spell);
168 rune->stats.Cha = rune->level / 2; /* the invisibility parameter */ 162 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 */ 163 rune->direction = dir; /* where any spell will go upon detonation */
173 set_owner (rune, op); /* runes without need no owner */ 164 rune->set_owner (op); /* runes without need no owner */
174 set_spell_skill (op, caster, spell, rune); 165 set_spell_skill (op, caster, spell, rune);
175 insert_ob_in_map (rune, m, op, 0); 166
167 m->insert (rune, nx, ny, op);
176 return 1; 168 return 1;
177
178} 169}
179
180
181 170
182/* move_rune: peterm 171/* move_rune: peterm
183 comments on runes: 172 comments on runes:
184 rune->level : level at which rune will cast its spell. 173 rune->level : level at which rune will cast its spell.
185 rune->hp : number of detonations before rune goes away 174 rune->hp : number of detonations before rune goes away
189 rune->attacktype: type of damage it does, if not casting spells 178 rune->attacktype: type of damage it does, if not casting spells
190 rune->other_arch: spell in the rune 179 rune->other_arch: spell in the rune
191 rune->Cha : how hidden the rune is 180 rune->Cha : how hidden the rune is
192 rune->maxhp : number of spells the rune casts 181 rune->maxhp : number of spells the rune casts
193*/ 182*/
194
195void 183void
196move_rune (object *op) 184move_rune (object *op)
197{ 185{
198 int det = 0; 186 /* runes of level zero cannot detonate. */
199
200 if (!op->level) 187 if (!op->level)
201 {
202 return; 188 return;
203 } /* runes of level zero cannot detonate. */ 189
204 det = op->invisible; 190 int det = op->invisible;
191
205 if (!(rndm (0, MAX (1, (op->stats.Cha)) - 1))) 192 if (!(rndm (0, MAX (1, (op->stats.Cha)) - 1)))
206 { 193 {
207 op->invisible = 0; 194 op->invisible = 0;
208 op->speed_left -= 1; 195 op->speed_left -= 1;
209 } 196 }
210 else 197 else
211 op->invisible = 1; 198 op->invisible = 1;
199
212 if (op->invisible != det) 200 if (op->invisible != det)
213 update_object (op, UP_OBJ_FACE); 201 update_object (op, UP_OBJ_FACE);
214} 202}
215 203
216 204
222void 210void
223rune_attack (object *op, object *victim) 211rune_attack (object *op, object *victim)
224{ 212{
225 if (victim) 213 if (victim)
226 { 214 {
227 tag_t tag = victim->count;
228
229 hit_player (victim, op->stats.dam, op, op->attacktype, 1); 215 hit_player (victim, op->stats.dam, op, op->attacktype, 1);
230 if (was_destroyed (victim, tag)) 216
217 if (victim->destroyed ())
231 return; 218 return;
219
232 /* if there's a disease in the needle, put it in the player */ 220 /* if there's a disease in the needle, put it in the player */
233 if (HAS_RANDOM_ITEMS (op)) 221 if (op->has_random_items ())
234 create_treasure (op->randomitems, op, 0, (victim->map ? victim->map->difficulty : 1), 0); 222 create_treasure (op->randomitems, op, 0, (victim->map ? victim->map->difficulty : 1), 0);
223
235 if (op->inv && op->inv->type == DISEASE) 224 if (op->inv && op->inv->type == DISEASE)
236 { 225 {
237 object *disease = op->inv; 226 object *disease = op->inv;
238 227
239 infect_object (victim, disease, 1); 228 infect_object (victim, disease, 1);
240 remove_ob (disease); 229 disease->destroy ();
241 free_object (disease);
242 } 230 }
243 } 231 }
244 else 232 else
245 hit_map (op, 0, op->attacktype, 1); 233 hit_map (op, 0, op->attacktype, 1);
246} 234}
251 */ 239 */
252void 240void
253spring_trap (object *trap, object *victim) 241spring_trap (object *trap, object *victim)
254{ 242{
255 object *env; 243 object *env;
256 tag_t trap_tag = trap->count;
257 rv_vector rv; 244 rv_vector rv;
258 int i; 245 int i;
259 246
260 /* Prevent recursion */ 247 /* Prevent recursion */
261 if (trap->stats.hp <= 0) 248 if (trap->stats.hp <= 0)
293 280
294 /* Only if it is a spell do we proceed here */ 281 /* Only if it is a spell do we proceed here */
295 if ((trap->inv && trap->inv->type == SPELL) || (trap->other_arch && trap->other_arch->clone.type == SPELL)) 282 if ((trap->inv && trap->inv->type == SPELL) || (trap->other_arch && trap->other_arch->clone.type == SPELL))
296 { 283 {
297 284
298 if (was_destroyed (trap, trap_tag)) 285 if (trap->destroyed ())
299 return; 286 return;
300 287
301 // breaks summon golem spells, which, for inexplicable reasons, 288 // breaks summon golem spells, which, for inexplicable reasons,
302 // do not work like summon golem spells at all but still require 289 // do not work like summon golem spells at all but still require
303 // direction "0" to work at all. 290 // direction "0" to work at all.
311 else 298 else
312 { 299 {
313 object *spell = arch_to_object (trap->other_arch); 300 object *spell = arch_to_object (trap->other_arch);
314 301
315 cast_spell (env, trap, trap->direction, spell, NULL); 302 cast_spell (env, trap, trap->direction, spell, NULL);
316 free_object (spell); 303 spell->destroy ();
317 } 304 }
318 } 305 }
319 } 306 }
320 else 307 else
321 { 308 {
322 rune_attack (trap, victim); 309 rune_attack (trap, victim);
323 if (was_destroyed (trap, trap_tag)) 310 if (trap->destroyed ())
324 return; 311 return;
325 } 312 }
326 313
327 if (trap->stats.hp <= 0) 314 if (trap->stats.hp <= 0)
328 { 315 {
341dispel_rune (object *op, object *caster, object *spell, object *skill, int dir) 328dispel_rune (object *op, object *caster, object *spell, object *skill, int dir)
342{ 329{
343 object *tmp, *tmp2; 330 object *tmp, *tmp2;
344 int searchflag = 1, mflags; 331 int searchflag = 1, mflags;
345 sint16 x, y; 332 sint16 x, y;
346 mapstruct *m; 333 maptile *m;
347 334
348 x = op->x + freearr_x[dir]; 335 x = op->x + freearr_x[dir];
349 y = op->y + freearr_y[dir]; 336 y = op->y + freearr_y[dir];
350 m = op->map; 337 m = op->map;
351 338
358 { 345 {
359 new_draw_info (NDI_UNIQUE, 0, op, "There's nothing there!"); 346 new_draw_info (NDI_UNIQUE, 0, op, "There's nothing there!");
360 return 0; 347 return 0;
361 } 348 }
362 349
363 for (tmp = get_map_ob (m, x, y); tmp != NULL; tmp = tmp->above) 350 for (tmp = GET_MAP_OB (m, x, y); tmp != NULL; tmp = tmp->above)
364 { 351 {
365 if (tmp->type == RUNE || tmp->type == TRAP) 352 if (tmp->type == RUNE || tmp->type == TRAP)
366 break; 353 break;
367 354
368 /* we could put a probability chance here, but since nothing happens 355 /* we could put a probability chance here, but since nothing happens
369 * if you fail, no point on that. I suppose we could do a level 356 * if you fail, no point on that. I suppose we could do a level
370 * comparison so low level players can't erase high level players runes. 357 * comparison so low level players can't erase high level players runes.
371 */ 358 */
372 if (tmp->type == SIGN && !strcmp (tmp->arch->name, "rune_mark")) 359 if (tmp->type == SIGN && !strcmp (tmp->arch->name, "rune_mark"))
373 { 360 {
374 remove_ob (tmp); 361 tmp->destroy ();
375 free_object (tmp);
376 new_draw_info (NDI_UNIQUE, 0, op, "You wipe out the rune of marking!"); 362 new_draw_info (NDI_UNIQUE, 0, op, "You wipe out the rune of marking!");
377 return 1; 363 return 1;
378 } 364 }
379 365
380 /* now search tmp's inventory for traps 366 /* now search tmp's inventory for traps
422} 408}
423 409
424int 410int
425trap_show (object *trap, object *where) 411trap_show (object *trap, object *where)
426{ 412{
427 object *tmp2;
428
429 if (where == NULL) 413 if (where == NULL)
430 return 0; 414 return 0;
415
431 tmp2 = get_archetype ("runedet"); 416 object *tmp = get_archetype ("runedet");
432 tmp2->face = &new_faces[GET_ANIMATION (trap, 0)]; 417 tmp->face = &new_faces[GET_ANIMATION (trap, 0)];
433 tmp2->x = where->x; 418 tmp->insert_at (where, 0);
434 tmp2->y = where->y; 419
435 tmp2->map = where->map;
436 insert_ob_in_map (tmp2, where->map, NULL, 0);
437 return 1; 420 return 1;
438
439} 421}
440
441 422
442int 423int
443trap_disarm (object *disarmer, object *trap, int risk, object *skill) 424trap_disarm (object *disarmer, object *trap, int risk, object *skill)
444{ 425{
445 int trapworth; /* need to compute the experience worth of the trap 426 int trapworth; /* need to compute the experience worth of the trap
450 sqr (MAX (trap->stats.dam, trap->inv ? trap->inv->level : 1)) / skill->level; 431 sqr (MAX (trap->stats.dam, trap->inv ? trap->inv->level : 1)) / skill->level;
451 432
452 if (!(random_roll (0, (MAX (2, MIN (20, trap->level - skill->level + 5 - disarmer->stats.Dex / 2)) - 1), disarmer, PREFER_LOW))) 433 if (!(random_roll (0, (MAX (2, MIN (20, trap->level - skill->level + 5 - disarmer->stats.Dex / 2)) - 1), disarmer, PREFER_LOW)))
453 { 434 {
454 new_draw_info_format (NDI_UNIQUE, 0, disarmer, "You successfully disarm the %s!", &trap->name); 435 new_draw_info_format (NDI_UNIQUE, 0, disarmer, "You successfully disarm the %s!", &trap->name);
455 destroy_object (trap); 436 trap->destroy (1);
437
456 /* If it is your own trap, (or any players trap), don't you don't 438 /* If it is your own trap, (or any players trap), don't you don't
457 * get exp for it. 439 * get exp for it.
458 */ 440 */
459 if (trap->owner && trap->owner->type != PLAYER && risk) 441 if (trap->owner && trap->owner->type != PLAYER && risk)
460 return trapworth; 442 return trapworth;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines