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,2013,2014,2015,2016 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> |
… | |
… | |
27 | |
28 | |
28 | #ifndef sqr |
29 | #ifndef sqr |
29 | # define sqr(x) ((x)*(x)) |
30 | # define sqr(x) ((x)*(x)) |
30 | #endif |
31 | #endif |
31 | |
32 | |
32 | /* peterm: |
33 | /* peterm: |
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 | * spell: spell object to put into the rune |
39 | * spell: spell object to put into the rune |
39 | * level: level of casting of the rune |
40 | * level: level of casting of the rune |
40 | * 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 |
41 | * a rune of marking |
42 | * a rune of marking |
42 | */ |
43 | */ |
43 | int |
44 | int |
44 | write_rune (object *op, object *caster, object *spell, int dir, const char *runename) |
45 | write_rune (object *op, object *caster, object *spell, int dir, const char *runename) |
45 | { |
46 | { |
46 | object *tmp, *rune_spell, *rune; |
47 | object *tmp, *rune_spell, *rune; |
… | |
… | |
69 | 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."); |
70 | return 0; |
71 | return 0; |
71 | } |
72 | } |
72 | |
73 | |
73 | if (spell->other_arch) |
74 | if (spell->other_arch) |
74 | rune_spell = arch_to_object (spell->other_arch); |
75 | rune_spell = spell->other_arch->instance (); |
75 | else |
76 | else |
76 | { |
77 | { |
77 | /* Player specified spell. The player has to know the spell, so |
78 | /* Player specified spell. The player has to know the spell, so |
78 | * 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 |
79 | * use the item_matched_string for our typical matching method. |
80 | * use the item_matched_string for our typical matching method. |
… | |
… | |
141 | /* 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 */ |
142 | if (rune_spell->type == RUNE) |
143 | if (rune_spell->type == RUNE) |
143 | rune = rune_spell; |
144 | rune = rune_spell; |
144 | else |
145 | else |
145 | { |
146 | { |
146 | rune = get_archetype (GENERIC_RUNE); |
147 | rune = archetype::get (GENERIC_RUNE); |
147 | rune->msg = format ("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); |
148 | rune->insert (rune_spell->clone ()); |
149 | rune->insert (rune_spell->clone ()); |
149 | |
150 | |
150 | if (spell->face != blank_face) |
151 | if (spell->face != blank_face) |
151 | rune->face = spell->face; |
152 | rune->face = spell->face; |
… | |
… | |
180 | if (!op->level) |
181 | if (!op->level) |
181 | return; |
182 | return; |
182 | |
183 | |
183 | int det = op->invisible; |
184 | int det = op->invisible; |
184 | |
185 | |
185 | if (!(rndm (0, MAX (1, (op->stats.Cha)) - 1))) |
186 | if (!(rndm (0, max (0, op->stats.Cha - 1)))) |
186 | { |
187 | { |
187 | op->invisible = 0; |
188 | op->invisible = 0; |
188 | op->speed_left -= 1; |
189 | op->speed_left -= 1; |
189 | } |
190 | } |
190 | else |
191 | else |
… | |
… | |
193 | if (op->invisible != det) |
194 | if (op->invisible != det) |
194 | update_object (op, UP_OBJ_CHANGE); |
195 | update_object (op, UP_OBJ_CHANGE); |
195 | } |
196 | } |
196 | |
197 | |
197 | /* peterm: rune_attack |
198 | /* peterm: rune_attack |
198 | * function handles those runes which detonate but do not cast spells. |
199 | * function handles those runes which detonate but do not cast spells. |
199 | */ |
200 | */ |
200 | void |
201 | static void |
201 | rune_attack (object *op, object *victim) |
202 | rune_attack (object *op, object *victim) |
202 | { |
203 | { |
203 | if (victim) |
204 | if (victim) |
204 | { |
205 | { |
205 | hit_player (victim, op->stats.dam, op, op->attacktype, 1); |
206 | hit_player (victim, op->stats.dam, op, op->attacktype, 1); |
… | |
… | |
222 | else |
223 | else |
223 | hit_map (op, 0, op->attacktype, 1); |
224 | hit_map (op, 0, op->attacktype, 1); |
224 | } |
225 | } |
225 | |
226 | |
226 | /* This function generalizes attacks by runes/traps. This ought to make |
227 | /* This function generalizes attacks by runes/traps. This ought to make |
227 | * it possible for runes to attack from the inventory, |
228 | * it possible for runes to attack from the inventory, |
228 | * it'll spring the trap on the victim. |
229 | * it'll spring the trap on the victim. |
229 | */ |
230 | */ |
230 | void |
231 | void |
231 | spring_trap (object *trap, object *victim) |
232 | spring_trap (object *trap, object *victim) |
232 | { |
233 | { |
… | |
… | |
236 | |
237 | |
237 | /* Prevent recursion */ |
238 | /* Prevent recursion */ |
238 | if (trap->stats.hp <= 0) |
239 | if (trap->stats.hp <= 0) |
239 | return; |
240 | return; |
240 | |
241 | |
241 | if (QUERY_FLAG (trap, FLAG_IS_LINKED)) |
242 | if (trap->flag [FLAG_IS_LINKED]) |
242 | use_trigger (trap); |
243 | use_trigger (trap, victim); |
243 | |
244 | |
244 | /* 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 |
245 | * 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. |
246 | * Typical example is an arrow attacking a door. |
247 | * Typical example is an arrow attacking a door. |
247 | */ |
248 | */ |
248 | if (!QUERY_FLAG (victim, FLAG_ALIVE) && !trap->inv && !trap->other_arch) |
249 | if (!victim->flag [FLAG_ALIVE] && !trap->inv && !trap->other_arch) |
249 | return; |
250 | return; |
250 | |
251 | |
251 | trap->stats.hp--; /*decrement detcount */ |
252 | trap->stats.hp--; /*decrement detcount */ |
252 | |
253 | |
253 | if (victim && victim->type == PLAYER) |
254 | if (victim && victim->type == PLAYER) |
254 | new_draw_info (NDI_UNIQUE, 0, victim, trap->msg); |
255 | new_draw_info (NDI_UNIQUE, 0, victim, trap->msg); |
255 | |
256 | |
256 | /* 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 |
257 | * knows what hit him. |
258 | * knows what hit him. |
258 | */ |
259 | */ |
259 | env = trap->outer_env (); |
260 | env = trap->outer_env_or_self (); |
260 | |
261 | |
261 | /* 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. |
262 | * 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. |
263 | * At the same time, the trap will stick around until detonated |
264 | * At the same time, the trap will stick around until detonated |
264 | */ |
265 | */ |
… | |
… | |
284 | // 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 |
285 | // direction "0" to work at all. |
286 | // direction "0" to work at all. |
286 | //if (trap->direction) |
287 | //if (trap->direction) |
287 | // rv.direction = trap->direction; |
288 | // rv.direction = trap->direction; |
288 | |
289 | |
289 | for (i = 0; i < MAX (1, trap->stats.maxhp); i++) |
290 | for (i = 0; i < max (1, trap->stats.maxhp); i++) |
290 | { |
291 | { |
291 | if (trap->inv) |
292 | if (trap->inv) |
292 | cast_spell (env, trap, trap->direction, trap->inv, NULL); |
293 | cast_spell (env, trap, trap->direction, trap->inv, NULL); |
293 | else |
294 | else |
294 | { |
295 | { |
295 | object *spell = arch_to_object (trap->other_arch); |
296 | object *spell = trap->other_arch->instance (); |
296 | |
297 | |
297 | cast_spell (env, trap, trap->direction, spell, NULL); |
298 | cast_spell (env, trap, trap->direction, spell, NULL); |
298 | spell->destroy (); |
299 | spell->destroy (); |
299 | } |
300 | } |
300 | } |
301 | } |
… | |
… | |
308 | |
309 | |
309 | if (trap->stats.hp <= 0) |
310 | if (trap->stats.hp <= 0) |
310 | { |
311 | { |
311 | trap->type = SIGN; /* make the trap impotent */ |
312 | trap->type = SIGN; /* make the trap impotent */ |
312 | 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 */ |
313 | SET_FLAG (trap, FLAG_IS_USED_UP); |
314 | trap->set_flag (FLAG_IS_USED_UP); |
314 | } |
315 | } |
315 | } |
316 | } |
316 | |
317 | |
317 | /* dispel_rune: by peterm |
318 | /* dispel_rune: by peterm |
318 | * dispels the target rune, depending on the level of the actor |
319 | * dispels the target rune, depending on the level of the actor |
319 | * and the level of the rune risk flag, if true, means that there is |
320 | * and the level of the rune risk flag, if true, means that there is |
320 | * a chance that the trap/rune will detonate |
321 | * a chance that the trap/rune will detonate |
321 | */ |
322 | */ |
322 | int |
323 | int |
323 | dispel_rune (object *op, object *caster, object *spell, object *skill, int dir) |
324 | dispel_rune (object *op, object *caster, object *spell, object *skill, int dir) |
324 | { |
325 | { |
325 | object *tmp, *tmp2; |
326 | object *tmp, *tmp2; |
… | |
… | |
332 | m = op->map; |
333 | m = op->map; |
333 | |
334 | |
334 | mflags = get_map_flags (m, &m, x, y, &x, &y); |
335 | mflags = get_map_flags (m, &m, x, y, &x, &y); |
335 | |
336 | |
336 | /* Should we perhaps not allow player to disable traps if a monster/ |
337 | /* Should we perhaps not allow player to disable traps if a monster/ |
337 | * player is standing on top? |
338 | * player is standing on top? |
338 | */ |
339 | */ |
339 | if (mflags & P_OUT_OF_MAP) |
340 | if (mflags & P_OUT_OF_MAP) |
340 | { |
341 | { |
341 | new_draw_info (NDI_UNIQUE, 0, op, "There's nothing there!"); |
342 | new_draw_info (NDI_UNIQUE, 0, op, "There's nothing there!"); |
342 | return 0; |
343 | return 0; |
… | |
… | |
387 | } |
388 | } |
388 | |
389 | |
389 | int |
390 | int |
390 | trap_see (object *op, object *trap) |
391 | trap_see (object *op, object *trap) |
391 | { |
392 | { |
392 | int chance; |
|
|
393 | |
|
|
394 | chance = random_roll (0, 99, op, PREFER_HIGH);; |
393 | int chance = random_roll (0, 99, op, PREFER_HIGH); |
395 | |
394 | |
396 | /* decide if we see the rune or not */ |
395 | /* decide if we see the rune or not */ |
397 | 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 |
398 | + trap->level + trap->stats.Cha - op->level) / 10.0 * 50.0)))))) |
397 | + trap->level + trap->stats.Cha - op->level) / 10.0 * 50.0)))))) |
399 | { |
398 | { |
400 | 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); |
401 | return 1; |
400 | return 1; |
402 | } |
401 | } |
… | |
… | |
408 | trap_show (object *trap, object *where) |
407 | trap_show (object *trap, object *where) |
409 | { |
408 | { |
410 | if (where == NULL) |
409 | if (where == NULL) |
411 | return 0; |
410 | return 0; |
412 | |
411 | |
413 | object *tmp = get_archetype ("runedet"); |
412 | object *tmp = archetype::get (shstr_runedet); |
414 | tmp->face = GET_ANIMATION (trap, 0); |
413 | tmp->face = trap->get_anim_frame (0); |
415 | tmp->insert_at (where, 0); |
414 | tmp->insert_at (where, 0); |
416 | |
415 | |
417 | return 1; |
416 | return 1; |
418 | } |
417 | } |
419 | |
418 | |
… | |
… | |
421 | trap_disarm (object *disarmer, object *trap, int risk, object *skill) |
420 | trap_disarm (object *disarmer, object *trap, int risk, object *skill) |
422 | { |
421 | { |
423 | 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 */ |
424 | |
423 | |
425 | /* this formula awards a more reasonable amount of exp */ |
424 | /* this formula awards a more reasonable amount of exp */ |
426 | trapworth = MAX (1, trap->level) |
425 | trapworth = max (1, trap->level) |
427 | * disarmer->map->difficulty |
426 | * disarmer->map->difficulty |
428 | * sqr (MAX (trap->stats.dam, trap->inv ? trap->inv->level : 1)) |
427 | * sqr (max (trap->stats.dam, trap->inv ? trap->inv->level : 1)) |
429 | / skill->level; |
428 | / skill->level; |
430 | |
429 | |
431 | 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))) |
432 | { |
431 | { |
433 | 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); |
434 | trap->destroy (); |
433 | trap->destroy (); |
435 | |
434 | |
436 | /* 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 |
… | |
… | |
442 | return 1; /* give minimal exp and say success */ |
441 | return 1; /* give minimal exp and say success */ |
443 | } |
442 | } |
444 | else |
443 | else |
445 | { |
444 | { |
446 | 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); |
447 | 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) |
448 | { |
447 | { |
449 | 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!"); |
450 | spring_trap (trap, disarmer); |
449 | spring_trap (trap, disarmer); |
451 | } |
450 | } |
452 | return 0; |
451 | return 0; |
453 | } |
452 | } |
454 | } |
453 | } |
455 | |
454 | |
456 | /* traps need to be adjusted for the difficulty of the map. The |
455 | /* traps need to be adjusted for the difficulty of the map. The |
457 | * default traps are too strong for wimpy level 1 players, and |
456 | * default traps are too strong for wimpy level 1 players, and |
458 | * unthreatening to anyone of high level |
457 | * unthreatening to anyone of high level |
459 | */ |
458 | */ |
460 | void |
459 | void |
461 | trap_adjust (object *trap, int difficulty) |
460 | trap_adjust (object *trap, int difficulty) |
462 | { |
461 | { |
463 | int i; |
462 | int i; |
464 | |
463 | |
465 | /* now we set the trap level to match the difficulty of the level |
464 | /* now we set the trap level to match the difficulty of the level |
466 | * the formula below will give a level from 1 to (2*difficulty) with |
465 | * the formula below will give a level from 1 to (2*difficulty) with |
467 | * a peak probability at difficulty |
466 | * a peak probability at difficulty |
468 | */ |
467 | */ |
469 | |
468 | |
470 | trap->level = rndm (0, difficulty - 1) + rndm (0, difficulty - 1); |
469 | trap->level = rndm (0, difficulty - 1) + rndm (0, difficulty - 1); |
471 | if (trap->level < 1) |
470 | if (trap->level < 1) |
472 | trap->level = 1; |
471 | trap->level = 1; |