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.35 by root, Mon Sep 29 10:20:49 2008 UTC vs.
Revision 1.55 by root, Mon Oct 29 23:55:55 2012 UTC

1/* 1/*
2 * This file is part of Deliantra, the Roguelike Realtime MMORPG. 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 (©) 2005,2006,2007,2008,2009,2010,2011,2012 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (©) 2003,2007 Mark Wedel & Crossfire Development Team 5 * Copyright (©) 2003 Mark Wedel & Crossfire Development Team
6 * Copyright (©) 1992,2007 Frank Tore Johansen 6 * Copyright (©) 1992 Frank Tore Johansen
7 * 7 *
8 * Deliantra is free software: you can redistribute it and/or modify 8 * Deliantra is free software: you can redistribute it and/or modify it under
9 * it under the terms of the GNU General Public License as published by 9 * the terms of the Affero GNU General Public License as published by the
10 * the Free Software Foundation, either version 3 of the License, or 10 * Free Software Foundation, either version 3 of the License, or (at your
11 * (at your option) any later version. 11 * option) any later version.
12 * 12 *
13 * 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,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details. 16 * GNU General Public License for more details.
17 * 17 *
18 * You should have received a copy of the GNU General Public License 18 * You should have received a copy of the Affero GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>. 19 * and the GNU General Public License along with this program. If not, see
20 * <http://www.gnu.org/licenses/>.
20 * 21 *
21 * The authors can be reached via e-mail to <support@deliantra.net> 22 * The authors can be reached via e-mail to <support@deliantra.net>
22 */ 23 */
23 24
24#include <global.h> 25#include <global.h>
25#include <sproto.h> 26#include <sproto.h>
33 * write_rune: 34 * write_rune:
34 * op: rune writer 35 * op: rune writer
35 * skop: skill object used for casting this rune 36 * skop: skill object used for casting this rune
36 * dir: orientation of rune, direction rune's contained spell will 37 * dir: orientation of rune, direction rune's contained spell will
37 * be cast in, if applicable 38 * be cast in, if applicable
38 * inspell: spell object to put into the rune, can be null if doing 39 * spell: spell object to put into the rune
39 * a marking rune.
40 * level: level of casting of the rune 40 * level: level of casting of the rune
41 * runename: name of the rune or message displayed by the rune for 41 * runename: name of the rune or message displayed by the rune for
42 * a rune of marking 42 * a rune of marking
43 */ 43 */
44
45int 44int
46write_rune (object *op, object *caster, object *spell, int dir, const char *runename) 45write_rune (object *op, object *caster, object *spell, int dir, const char *runename)
47{ 46{
48 object *tmp, *rune_spell, *rune; 47 object *tmp, *rune_spell, *rune;
49 char buf[MAX_BUF];
50 maptile *m; 48 maptile *m;
51 sint16 nx, ny; 49 sint16 nx, ny;
52 50
53 if (!dir) 51 if (!dir)
54 dir = 1; 52 dir = 1;
72 new_draw_info (NDI_UNIQUE, 0, op, "You can't write a rune on top of another rune."); 70 new_draw_info (NDI_UNIQUE, 0, op, "You can't write a rune on top of another rune.");
73 return 0; 71 return 0;
74 } 72 }
75 73
76 if (spell->other_arch) 74 if (spell->other_arch)
77 rune_spell = arch_to_object (spell->other_arch); 75 rune_spell = spell->other_arch->instance ();
78 else 76 else
79 { 77 {
80 /* Player specified spell. The player has to know the spell, so 78 /* Player specified spell. The player has to know the spell, so
81 * lets just look through the players inventory see if they know it 79 * lets just look through the players inventory see if they know it
82 * use the item_matched_string for our typical matching method. 80 * use the item_matched_string for our typical matching method.
101 } 99 }
102 } 100 }
103 101
104 if (!rune_spell) 102 if (!rune_spell)
105 { 103 {
106 new_draw_info_format (NDI_UNIQUE, 0, op, "You don't know any spell named %s", runename); 104 new_draw_info_format (NDI_UNIQUE, 0, op, "You don't know any spell named %s.", runename);
107 return 0; 105 return 0;
108 } 106 }
109 107
110 if (rune_spell->skill != spell->skill) 108 if (rune_spell->skill != spell->skill)
111 { 109 {
112 new_draw_info_format (NDI_UNIQUE, 0, op, "You can't cast %s with %s", &rune_spell->name, &spell->name); 110 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);
113 return 0; 111 return 0;
114 } 112 }
115 113
116 if (caster->path_denied & spell->path_attuned && !caster->flag [FLAG_WIZCAST]) 114 if (caster->path_denied & spell->path_attuned && !caster->flag [FLAG_WIZCAST])
117 { 115 {
119 return 0; 117 return 0;
120 } 118 }
121 119
122 if (casting_level (caster, rune_spell) < rune_spell->level && !caster->flag [FLAG_WIZCAST]) 120 if (casting_level (caster, rune_spell) < rune_spell->level && !caster->flag [FLAG_WIZCAST])
123 { 121 {
124 new_draw_info_format (NDI_UNIQUE, 0, op, "%s is beyond your ability to cast!", &rune_spell->name); 122 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);
125 return 0; 123 return 0;
126 } 124 }
127 125
128 if (SP_level_spellpoint_cost (caster, rune_spell, SPELL_MANA) > op->stats.sp) 126 if (SP_level_spellpoint_cost (caster, rune_spell, SPELL_MANA) > op->stats.sp)
129 { 127 {
136 new_draw_info (NDI_UNIQUE, 0, op, "You don't have enough grace."); 134 new_draw_info (NDI_UNIQUE, 0, op, "You don't have enough grace.");
137 return 0; 135 return 0;
138 } 136 }
139 137
140 op->stats.grace -= SP_level_spellpoint_cost (caster, rune_spell, SPELL_GRACE); 138 op->stats.grace -= SP_level_spellpoint_cost (caster, rune_spell, SPELL_GRACE);
141 op->stats.sp -= SP_level_spellpoint_cost (caster, rune_spell, SPELL_MANA); 139 op->stats.sp -= SP_level_spellpoint_cost (caster, rune_spell, SPELL_MANA);
142 } 140 }
143 141
144 /* already proper rune. Note this should only be the case if other_arch was set */ 142 /* already proper rune. Note this should only be the case if other_arch was set */
145 if (rune_spell->type == RUNE) 143 if (rune_spell->type == RUNE)
146 rune = rune_spell; 144 rune = rune_spell;
147 else 145 else
148 { 146 {
149 rune = get_archetype (GENERIC_RUNE); 147 rune = archetype::get (GENERIC_RUNE);
150 sprintf (buf, "You set off a rune of %s\n", &rune_spell->name); 148 rune->msg = format ("You set off a rune of %s\n", &rune_spell->name);
151 rune->msg = buf;
152 rune->insert (rune_spell->clone ()); 149 rune->insert (rune_spell->clone ());
153 150
154 if (spell->face != blank_face) 151 if (spell->face != blank_face)
155 rune->face = spell->face; 152 rune->face = spell->face;
156 } 153 }
184 if (!op->level) 181 if (!op->level)
185 return; 182 return;
186 183
187 int det = op->invisible; 184 int det = op->invisible;
188 185
189 if (!(rndm (0, MAX (1, (op->stats.Cha)) - 1))) 186 if (!(rndm (0, max (0, op->stats.Cha - 1))))
190 { 187 {
191 op->invisible = 0; 188 op->invisible = 0;
192 op->speed_left -= 1; 189 op->speed_left -= 1;
193 } 190 }
194 else 191 else
199} 196}
200 197
201/* peterm: rune_attack 198/* peterm: rune_attack
202 * function handles those runes which detonate but do not cast spells. 199 * function handles those runes which detonate but do not cast spells.
203 */ 200 */
204void 201static void
205rune_attack (object *op, object *victim) 202rune_attack (object *op, object *victim)
206{ 203{
207 if (victim) 204 if (victim)
208 { 205 {
209 hit_player (victim, op->stats.dam, op, op->attacktype, 1); 206 hit_player (victim, op->stats.dam, op, op->attacktype, 1);
218 if (op->inv && op->inv->type == DISEASE) 215 if (op->inv && op->inv->type == DISEASE)
219 { 216 {
220 object *disease = op->inv; 217 object *disease = op->inv;
221 218
222 infect_object (victim, disease, 1); 219 infect_object (victim, disease, 1);
223 disease->destroy (true); 220 disease->destroy ();
224 } 221 }
225 } 222 }
226 else 223 else
227 hit_map (op, 0, op->attacktype, 1); 224 hit_map (op, 0, op->attacktype, 1);
228} 225}
240 237
241 /* Prevent recursion */ 238 /* Prevent recursion */
242 if (trap->stats.hp <= 0) 239 if (trap->stats.hp <= 0)
243 return; 240 return;
244 241
245 if (QUERY_FLAG (trap, FLAG_IS_LINKED)) 242 if (trap->flag [FLAG_IS_LINKED])
246 use_trigger (trap); 243 use_trigger (trap, victim);
247 244
248 /* Only living objects can trigger runes that don't cast spells, as 245 /* Only living objects can trigger runes that don't cast spells, as
249 * doing direct damage to a non-living object doesn't work anyway. 246 * doing direct damage to a non-living object doesn't work anyway.
250 * Typical example is an arrow attacking a door. 247 * Typical example is an arrow attacking a door.
251 */ 248 */
252 if (!QUERY_FLAG (victim, FLAG_ALIVE) && !trap->inv && !trap->other_arch) 249 if (!victim->flag [FLAG_ALIVE] && !trap->inv && !trap->other_arch)
253 return; 250 return;
254 251
255 trap->stats.hp--; /*decrement detcount */ 252 trap->stats.hp--; /*decrement detcount */
256 253
257 if (victim && victim->type == PLAYER) 254 if (victim && victim->type == PLAYER)
258 new_draw_info (NDI_UNIQUE, 0, victim, trap->msg); 255 new_draw_info (NDI_UNIQUE, 0, victim, trap->msg);
259 256
260 /* Flash an image of the trap on the map so the poor sod 257 /* Flash an image of the trap on the map so the poor sod
261 * knows what hit him. 258 * knows what hit him.
262 */ 259 */
263 env = trap->outer_env (); 260 env = trap->outer_env_or_self ();
264 261
265 /* If the victim is not next to this trap, don't set it off. 262 /* If the victim is not next to this trap, don't set it off.
266 * players shouldn't get hit by firing arrows at a door for example. 263 * players shouldn't get hit by firing arrows at a door for example.
267 * At the same time, the trap will stick around until detonated 264 * At the same time, the trap will stick around until detonated
268 */ 265 */
288 // do not work like summon golem spells at all but still require 285 // do not work like summon golem spells at all but still require
289 // direction "0" to work at all. 286 // direction "0" to work at all.
290 //if (trap->direction) 287 //if (trap->direction)
291 // rv.direction = trap->direction; 288 // rv.direction = trap->direction;
292 289
293 for (i = 0; i < MAX (1, trap->stats.maxhp); i++) 290 for (i = 0; i < max (1, trap->stats.maxhp); i++)
294 { 291 {
295 if (trap->inv) 292 if (trap->inv)
296 cast_spell (env, trap, trap->direction, trap->inv, NULL); 293 cast_spell (env, trap, trap->direction, trap->inv, NULL);
297 else 294 else
298 { 295 {
299 object *spell = arch_to_object (trap->other_arch); 296 object *spell = trap->other_arch->instance ();
300 297
301 cast_spell (env, trap, trap->direction, spell, NULL); 298 cast_spell (env, trap, trap->direction, spell, NULL);
302 spell->destroy (true); 299 spell->destroy ();
303 } 300 }
304 } 301 }
305 } 302 }
306 else 303 else
307 { 304 {
312 309
313 if (trap->stats.hp <= 0) 310 if (trap->stats.hp <= 0)
314 { 311 {
315 trap->type = SIGN; /* make the trap impotent */ 312 trap->type = SIGN; /* make the trap impotent */
316 trap->stats.food = 20; /* make it stick around until its spells are gone */ 313 trap->stats.food = 20; /* make it stick around until its spells are gone */
317 SET_FLAG (trap, FLAG_IS_USED_UP); 314 trap->set_flag (FLAG_IS_USED_UP);
318 } 315 }
319} 316}
320 317
321/* dispel_rune: by peterm 318/* dispel_rune: by peterm
322 * dispels the target rune, depending on the level of the actor 319 * dispels the target rune, depending on the level of the actor
344 { 341 {
345 new_draw_info (NDI_UNIQUE, 0, op, "There's nothing there!"); 342 new_draw_info (NDI_UNIQUE, 0, op, "There's nothing there!");
346 return 0; 343 return 0;
347 } 344 }
348 345
349 for (tmp = GET_MAP_OB (m, x, y); tmp != NULL; tmp = tmp->above) 346 for (tmp = GET_MAP_OB (m, x, y); tmp; tmp = tmp->above)
350 { 347 {
351 if (tmp->type == RUNE || tmp->type == TRAP) 348 if (tmp->type == RUNE || tmp->type == TRAP)
352 break; 349 break;
353 350
354 /* we could put a probability chance here, but since nothing happens 351 /* we could put a probability chance here, but since nothing happens
355 * if you fail, no point on that. I suppose we could do a level 352 * if you fail, no point on that. I suppose we could do a level
356 * comparison so low level players can't erase high level players runes. 353 * comparison so low level players can't erase high level players runes.
357 */ 354 */
358 if (tmp->type == SIGN && !strcmp (tmp->arch->archname, "rune_mark")) 355 if (tmp->type == SIGN && tmp->arch->archname == shstr_rune_mark)
359 { 356 {
360 tmp->destroy (true); 357 tmp->destroy ();
361 new_draw_info (NDI_UNIQUE, 0, op, "You wipe out the rune of marking!"); 358 new_draw_info (NDI_UNIQUE, 0, op, "You wipe out the rune of marking!");
362 return 1; 359 return 1;
363 } 360 }
364 361
365 /* now search tmp's inventory for traps 362 /* now search tmp's inventory for traps
366 * This is for chests, where the rune is in the chests inventory. 363 * This is for chests, where the rune is in the chests inventory.
367 */ 364 */
368 for (tmp2 = tmp->inv; tmp2 != NULL; tmp2 = tmp2->below) 365 for (tmp2 = tmp->inv; tmp2; tmp2 = tmp2->below)
369 { 366 {
370 if (tmp2->type == RUNE || tmp2->type == TRAP) 367 if (tmp2->type == RUNE || tmp2->type == TRAP)
371 { 368 {
372 tmp = tmp2; 369 tmp = tmp2;
373 searchflag = 0; 370 searchflag = 0;
374 break; 371 break;
375 } 372 }
376 } 373 }
374
377 if (!searchflag) 375 if (!searchflag)
378 break; 376 break;
379 } 377 }
380 378
381 /* no rune there. */ 379 /* no rune there. */
390} 388}
391 389
392int 390int
393trap_see (object *op, object *trap) 391trap_see (object *op, object *trap)
394{ 392{
395 int chance;
396
397 chance = random_roll (0, 99, op, PREFER_HIGH);; 393 int chance = random_roll (0, 99, op, PREFER_HIGH);
398 394
399 /* decide if we see the rune or not */ 395 /* decide if we see the rune or not */
400 if ((trap->stats.Cha == 1) || (chance > MIN (95, MAX (5, ((int) ((float) (op->map->difficulty 396 if ((trap->stats.Cha == 1) || (chance > min (95, max (5, ((int) ((float) (op->map->difficulty
401 + trap->level + trap->stats.Cha - op->level) / 10.0 * 50.0)))))) 397 + trap->level + trap->stats.Cha - op->level) / 10.0 * 50.0))))))
402 { 398 {
403 new_draw_info_format (NDI_UNIQUE, 0, op, "You spot a %s!", &trap->name); 399 new_draw_info_format (NDI_UNIQUE, 0, op, "You spot a %s!", &trap->name);
404 return 1; 400 return 1;
405 } 401 }
411trap_show (object *trap, object *where) 407trap_show (object *trap, object *where)
412{ 408{
413 if (where == NULL) 409 if (where == NULL)
414 return 0; 410 return 0;
415 411
416 object *tmp = get_archetype ("runedet"); 412 object *tmp = archetype::get (shstr_runedet);
417 tmp->face = GET_ANIMATION (trap, 0); 413 tmp->face = trap->get_anim_frame (0);
418 tmp->insert_at (where, 0); 414 tmp->insert_at (where, 0);
419 415
420 return 1; 416 return 1;
421} 417}
422 418
424trap_disarm (object *disarmer, object *trap, int risk, object *skill) 420trap_disarm (object *disarmer, object *trap, int risk, object *skill)
425{ 421{
426 int trapworth; /* need to compute the experience worth of the trap before we kill it */ 422 int trapworth; /* need to compute the experience worth of the trap before we kill it */
427 423
428 /* this formula awards a more reasonable amount of exp */ 424 /* this formula awards a more reasonable amount of exp */
429 trapworth = MAX (1, trap->level) 425 trapworth = max (1, trap->level)
430 * disarmer->map->difficulty 426 * disarmer->map->difficulty
431 * sqr (MAX (trap->stats.dam, trap->inv ? trap->inv->level : 1)) 427 * sqr (max (trap->stats.dam, trap->inv ? trap->inv->level : 1))
432 / skill->level; 428 / skill->level;
433 429
434 if (!(random_roll (0, (MAX (2, MIN (20, trap->level - skill->level + 5 - disarmer->stats.Dex / 2)) - 1), disarmer, PREFER_LOW))) 430 if (!(random_roll (0, (max (2, min (20, trap->level - skill->level + 5 - disarmer->stats.Dex / 2)) - 1), disarmer, PREFER_LOW)))
435 { 431 {
436 new_draw_info_format (NDI_UNIQUE, 0, disarmer, "You successfully disarm the %s!", &trap->name); 432 new_draw_info_format (NDI_UNIQUE, 0, disarmer, "You successfully disarm the %s!", &trap->name);
437 trap->destroy (true); 433 trap->destroy ();
438 434
439 /* If it is your own trap, (or any players trap), don't you don't 435 /* If it is your own trap, (or any players trap), don't you don't
440 * get exp for it. 436 * get exp for it.
441 */ 437 */
442 if (trap->owner && trap->owner->type != PLAYER && risk) 438 if (trap->owner && trap->owner->type != PLAYER && risk)
445 return 1; /* give minimal exp and say success */ 441 return 1; /* give minimal exp and say success */
446 } 442 }
447 else 443 else
448 { 444 {
449 new_draw_info_format (NDI_UNIQUE, 0, disarmer, "You fail to disarm the %s.", &trap->name); 445 new_draw_info_format (NDI_UNIQUE, 0, disarmer, "You fail to disarm the %s.", &trap->name);
450 if (!(random_roll (0, (MAX (2, skill->level - trap->level + disarmer->stats.Dex / 2 - 6)) - 1, disarmer, PREFER_LOW)) && risk) 446 if (!(random_roll (0, (max (2, skill->level - trap->level + disarmer->stats.Dex / 2 - 6)) - 1, disarmer, PREFER_LOW)) && risk)
451 { 447 {
452 new_draw_info (NDI_UNIQUE, 0, disarmer, "In fact, you set it off!"); 448 new_draw_info (NDI_UNIQUE, 0, disarmer, "In fact, you set it off!");
453 spring_trap (trap, disarmer); 449 spring_trap (trap, disarmer);
454 } 450 }
455 return 0; 451 return 0;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines