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.28 by root, Sun Jul 1 05:00:20 2007 UTC

1
2/* 1/*
3 * static char *rcsid_rune_c = 2 * This file is part of Crossfire TRT, the Roguelike Realtime MORPG.
4 * "$Id: rune.C,v 1.4 2006/09/10 15:59:57 root Exp $"; 3 *
4 * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT team
5 * Copyright (©) 2003,2007 Mark Wedel & Crossfire Development Team
6 * Copyright (©) 1992,2007 Frank Tore Johansen
7 *
8 * Crossfire TRT 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 3 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, see <http://www.gnu.org/licenses/>.
20 *
21 * The authors can be reached via e-mail to <crossfire@schmorp.de>
5 */ 22 */
6 23
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> 24#include <global.h>
31#ifndef __CEXTRACT__
32# include <sproto.h> 25#include <sproto.h>
33#endif
34#include <spells.h> 26#include <spells.h>
35
36 27
37#ifndef sqr 28#ifndef sqr
38# define sqr(x) ((x)*(x)) 29# define sqr(x) ((x)*(x))
39#endif 30#endif
40
41 31
42/* peterm: 32/* peterm:
43 * write_rune: 33 * write_rune:
44 * op: rune writer 34 * op: rune writer
45 * skop: skill object used for casting this rune 35 * skop: skill object used for casting this rune
55int 45int
56write_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)
57{ 47{
58 object *tmp, *rune_spell, *rune; 48 object *tmp, *rune_spell, *rune;
59 char buf[MAX_BUF]; 49 char buf[MAX_BUF];
60 mapstruct *m; 50 maptile *m;
61 sint16 nx, ny; 51 sint16 nx, ny;
62 52
63 if (!dir) 53 if (!dir)
64 {
65 dir = 1; 54 dir = 1;
66 }
67 55
68 nx = op->x + freearr_x[dir]; 56 nx = op->x + freearr_x[dir];
69 ny = op->y + freearr_y[dir]; 57 ny = op->y + freearr_y[dir];
70 m = op->map; 58 m = op->map;
71 59
72 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))
73 { 61 {
74 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!");
75 return 0; 63 return 0;
76 } 64 }
65
77 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)
78 if (tmp->type == RUNE) 67 if (tmp->type == RUNE)
79 break; 68 break;
80 69
81 if (tmp) 70 if (tmp)
82 { 71 {
83 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.");
84 return 0; 73 return 0;
85 } 74 }
86 75
87 if (spell->other_arch) 76 if (spell->other_arch)
88 {
89 rune_spell = arch_to_object (spell->other_arch); 77 rune_spell = arch_to_object (spell->other_arch);
90 }
91 else 78 else
92 { 79 {
93 /* Player specified spell. The player has to know the spell, so 80 /* Player specified spell. The player has to know the spell, so
94 * 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
95 * use the item_matched_string for our typical matching method. 82 * use the item_matched_string for our typical matching method.
102 return 0; 89 return 0;
103 } 90 }
104 91
105 rune_spell = NULL; 92 rune_spell = NULL;
106 for (tmp = op->inv; tmp; tmp = tmp->below) 93 for (tmp = op->inv; tmp; tmp = tmp->below)
107 {
108 if (tmp->type == SPELL) 94 if (tmp->type == SPELL)
109 { 95 {
110 ms = item_matched_string (op, tmp, runename); 96 ms = item_matched_string (op, tmp, runename);
111 if (ms > bestmatch) 97 if (ms > bestmatch)
112 { 98 {
113 bestmatch = ms; 99 bestmatch = ms;
114 rune_spell = tmp; 100 rune_spell = tmp;
115 } 101 }
116 } 102 }
117 } 103
118 if (!rune_spell) 104 if (!rune_spell)
119 { 105 {
120 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);
121 return 0; 107 return 0;
122 } 108 }
109
123 if (rune_spell->skill != spell->skill) 110 if (rune_spell->skill != spell->skill)
124 { 111 {
125 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);
126 return 0; 113 return 0;
127 } 114 }
115
128 if (caster->path_denied & spell->path_attuned) 116 if (caster->path_denied & spell->path_attuned && !caster->flag [FLAG_WIZCAST])
129 { 117 {
130 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);
131 return 0; 119 return 0;
132 } 120 }
121
133 if (caster_level (caster, rune_spell) < rune_spell->level) 122 if (caster_level (caster, rune_spell) < rune_spell->level && !caster->flag [FLAG_WIZCAST])
134 { 123 {
135 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);
136 return 0; 125 return 0;
137 } 126 }
127
138 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)
139 { 129 {
140 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.");
141 return 0; 131 return 0;
142 } 132 }
133
143 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)
144 { 135 {
145 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.");
146 return 0; 137 return 0;
147 } 138 }
139
148 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);
149 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);
150 } 142 }
143
151 /* 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 */
152 if (rune_spell->type == RUNE) 145 if (rune_spell->type == RUNE)
153 {
154 rune = rune_spell; 146 rune = rune_spell;
155 }
156 else 147 else
157 { 148 {
158 rune = get_archetype (GENERIC_RUNE); 149 rune = get_archetype (GENERIC_RUNE);
159 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);
160 rune->msg = buf; 151 rune->msg = buf;
161 tmp = get_object (); 152 rune->insert (rune_spell->clone ());
162 copy_object (rune_spell, tmp); 153
163 insert_ob_in_ob (tmp, rune);
164 if (spell->face != blank_face) 154 if (spell->face != blank_face)
165 rune->face = spell->face; 155 rune->face = spell->face;
166 } 156 }
157
167 rune->level = caster_level (caster, spell); 158 rune->level = caster_level (caster, spell);
168 rune->stats.Cha = rune->level / 2; /* the invisibility parameter */ 159 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 */ 160 rune->direction = dir; /* where any spell will go upon detonation */
173 set_owner (rune, op); /* runes without need no owner */ 161 rune->set_owner (op); /* runes without need no owner */
174 set_spell_skill (op, caster, spell, rune); 162 set_spell_skill (op, caster, spell, rune);
175 insert_ob_in_map (rune, m, op, 0); 163
164 m->insert (rune, nx, ny, op);
176 return 1; 165 return 1;
177
178} 166}
179
180
181 167
182/* move_rune: peterm 168/* move_rune: peterm
183 comments on runes: 169 comments on runes:
184 rune->level : level at which rune will cast its spell. 170 rune->level : level at which rune will cast its spell.
185 rune->hp : number of detonations before rune goes away 171 rune->hp : number of detonations before rune goes away
189 rune->attacktype: type of damage it does, if not casting spells 175 rune->attacktype: type of damage it does, if not casting spells
190 rune->other_arch: spell in the rune 176 rune->other_arch: spell in the rune
191 rune->Cha : how hidden the rune is 177 rune->Cha : how hidden the rune is
192 rune->maxhp : number of spells the rune casts 178 rune->maxhp : number of spells the rune casts
193*/ 179*/
194
195void 180void
196move_rune (object *op) 181move_rune (object *op)
197{ 182{
198 int det = 0; 183 /* runes of level zero cannot detonate. */
199
200 if (!op->level) 184 if (!op->level)
201 {
202 return; 185 return;
203 } /* runes of level zero cannot detonate. */ 186
204 det = op->invisible; 187 int det = op->invisible;
188
205 if (!(rndm (0, MAX (1, (op->stats.Cha)) - 1))) 189 if (!(rndm (0, MAX (1, (op->stats.Cha)) - 1)))
206 { 190 {
207 op->invisible = 0; 191 op->invisible = 0;
208 op->speed_left -= 1; 192 op->speed_left -= 1;
209 } 193 }
210 else 194 else
211 op->invisible = 1; 195 op->invisible = 1;
196
212 if (op->invisible != det) 197 if (op->invisible != det)
213 update_object (op, UP_OBJ_FACE); 198 update_object (op, UP_OBJ_CHANGE);
214} 199}
215
216 200
217/* peterm: rune_attack 201/* peterm: rune_attack
218 * function handles those runes which detonate but do not cast spells. 202 * function handles those runes which detonate but do not cast spells.
219 */ 203 */
220
221
222void 204void
223rune_attack (object *op, object *victim) 205rune_attack (object *op, object *victim)
224{ 206{
225 if (victim) 207 if (victim)
226 { 208 {
227 tag_t tag = victim->count;
228
229 hit_player (victim, op->stats.dam, op, op->attacktype, 1); 209 hit_player (victim, op->stats.dam, op, op->attacktype, 1);
230 if (was_destroyed (victim, tag)) 210
211 if (victim->destroyed ())
231 return; 212 return;
213
232 /* 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 */
233 if (HAS_RANDOM_ITEMS (op)) 215 if (op->has_random_items ())
234 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
235 if (op->inv && op->inv->type == DISEASE) 218 if (op->inv && op->inv->type == DISEASE)
236 { 219 {
237 object *disease = op->inv; 220 object *disease = op->inv;
238 221
239 infect_object (victim, disease, 1); 222 infect_object (victim, disease, 1);
240 remove_ob (disease); 223 disease->destroy ();
241 free_object (disease);
242 } 224 }
243 } 225 }
244 else 226 else
245 hit_map (op, 0, op->attacktype, 1); 227 hit_map (op, 0, op->attacktype, 1);
246} 228}
251 */ 233 */
252void 234void
253spring_trap (object *trap, object *victim) 235spring_trap (object *trap, object *victim)
254{ 236{
255 object *env; 237 object *env;
256 tag_t trap_tag = trap->count;
257 rv_vector rv; 238 rv_vector rv;
258 int i; 239 int i;
259 240
260 /* Prevent recursion */ 241 /* Prevent recursion */
261 if (trap->stats.hp <= 0) 242 if (trap->stats.hp <= 0)
289 if (rv.distance > 1) 270 if (rv.distance > 1)
290 return; 271 return;
291 272
292 trap_show (trap, env); 273 trap_show (trap, env);
293 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
294 /* Only if it is a spell do we proceed here */ 279 /* 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)) 280 if ((trap->inv && trap->inv->type == SPELL) || (trap->other_arch && trap->other_arch->type == SPELL))
296 { 281 {
297 282
298 if (was_destroyed (trap, trap_tag)) 283 if (trap->destroyed ())
299 return; 284 return;
300 285
301 // breaks summon golem spells, which, for inexplicable reasons, 286 // breaks summon golem spells, which, for inexplicable reasons,
302 // 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
303 // direction "0" to work at all. 288 // direction "0" to work at all.
311 else 296 else
312 { 297 {
313 object *spell = arch_to_object (trap->other_arch); 298 object *spell = arch_to_object (trap->other_arch);
314 299
315 cast_spell (env, trap, trap->direction, spell, NULL); 300 cast_spell (env, trap, trap->direction, spell, NULL);
316 free_object (spell); 301 spell->destroy ();
317 } 302 }
318 } 303 }
319 } 304 }
320 else 305 else
321 { 306 {
322 rune_attack (trap, victim); 307 rune_attack (trap, victim);
323 if (was_destroyed (trap, trap_tag)) 308 if (trap->destroyed ())
324 return; 309 return;
325 } 310 }
326 311
327 if (trap->stats.hp <= 0) 312 if (trap->stats.hp <= 0)
328 { 313 {
341dispel_rune (object *op, object *caster, object *spell, object *skill, int dir) 326dispel_rune (object *op, object *caster, object *spell, object *skill, int dir)
342{ 327{
343 object *tmp, *tmp2; 328 object *tmp, *tmp2;
344 int searchflag = 1, mflags; 329 int searchflag = 1, mflags;
345 sint16 x, y; 330 sint16 x, y;
346 mapstruct *m; 331 maptile *m;
347 332
348 x = op->x + freearr_x[dir]; 333 x = op->x + freearr_x[dir];
349 y = op->y + freearr_y[dir]; 334 y = op->y + freearr_y[dir];
350 m = op->map; 335 m = op->map;
351 336
358 { 343 {
359 new_draw_info (NDI_UNIQUE, 0, op, "There's nothing there!"); 344 new_draw_info (NDI_UNIQUE, 0, op, "There's nothing there!");
360 return 0; 345 return 0;
361 } 346 }
362 347
363 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)
364 { 349 {
365 if (tmp->type == RUNE || tmp->type == TRAP) 350 if (tmp->type == RUNE || tmp->type == TRAP)
366 break; 351 break;
367 352
368 /* we could put a probability chance here, but since nothing happens 353 /* 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 354 * 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. 355 * comparison so low level players can't erase high level players runes.
371 */ 356 */
372 if (tmp->type == SIGN && !strcmp (tmp->arch->name, "rune_mark")) 357 if (tmp->type == SIGN && !strcmp (tmp->arch->archname, "rune_mark"))
373 { 358 {
374 remove_ob (tmp); 359 tmp->destroy ();
375 free_object (tmp);
376 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!");
377 return 1; 361 return 1;
378 } 362 }
379 363
380 /* now search tmp's inventory for traps 364 /* now search tmp's inventory for traps
422} 406}
423 407
424int 408int
425trap_show (object *trap, object *where) 409trap_show (object *trap, object *where)
426{ 410{
427 object *tmp2;
428
429 if (where == NULL) 411 if (where == NULL)
430 return 0; 412 return 0;
413
431 tmp2 = get_archetype ("runedet"); 414 object *tmp = get_archetype ("runedet");
432 tmp2->face = &new_faces[GET_ANIMATION (trap, 0)]; 415 tmp->face = GET_ANIMATION (trap, 0);
433 tmp2->x = where->x; 416 tmp->insert_at (where, 0);
434 tmp2->y = where->y; 417
435 tmp2->map = where->map;
436 insert_ob_in_map (tmp2, where->map, NULL, 0);
437 return 1; 418 return 1;
438
439} 419}
440
441 420
442int 421int
443trap_disarm (object *disarmer, object *trap, int risk, object *skill) 422trap_disarm (object *disarmer, object *trap, int risk, object *skill)
444{ 423{
445 int trapworth; /* need to compute the experience worth of the trap 424 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; 429 sqr (MAX (trap->stats.dam, trap->inv ? trap->inv->level : 1)) / skill->level;
451 430
452 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)))
453 { 432 {
454 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);
455 destroy_object (trap); 434 trap->destroy (1);
435
456 /* 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
457 * get exp for it. 437 * get exp for it.
458 */ 438 */
459 if (trap->owner && trap->owner->type != PLAYER && risk) 439 if (trap->owner && trap->owner->type != PLAYER && risk)
460 return trapworth; 440 return trapworth;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines