1 | |
|
|
2 | /* |
1 | /* |
3 | * static char *rcsid_rune_c = |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
4 | * "$Id: rune.C,v 1.4 2006/09/10 15:59:57 root Exp $"; |
3 | * |
|
|
4 | * Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
|
|
5 | * Copyright (©) 2003 Mark Wedel & Crossfire Development Team |
|
|
6 | * Copyright (©) 1992 Frank Tore Johansen |
|
|
7 | * |
|
|
8 | * Deliantra is free software: you can redistribute it and/or modify it under |
|
|
9 | * the terms of the Affero GNU General Public License as published by the |
|
|
10 | * Free Software Foundation, either version 3 of the License, or (at your |
|
|
11 | * 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 Affero GNU General Public License |
|
|
19 | * and the GNU General Public License along with this program. If not, see |
|
|
20 | * <http://www.gnu.org/licenses/>. |
|
|
21 | * |
|
|
22 | * The authors can be reached via e-mail to <support@deliantra.net> |
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 |
46 | * dir: orientation of rune, direction rune's contained spell will |
37 | * dir: orientation of rune, direction rune's contained spell will |
47 | * be cast in, if applicable |
38 | * be cast in, if applicable |
48 | * inspell: spell object to put into the rune, can be null if doing |
39 | * spell: spell object to put into the rune |
49 | * a marking rune. |
|
|
50 | * level: level of casting of the rune |
40 | * level: level of casting of the rune |
51 | * 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 |
52 | * a rune of marking |
42 | * a rune of marking |
53 | */ |
43 | */ |
54 | |
|
|
55 | int |
44 | int |
56 | 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) |
57 | { |
46 | { |
58 | object *tmp, *rune_spell, *rune; |
47 | object *tmp, *rune_spell, *rune; |
59 | char buf[MAX_BUF]; |
48 | maptile *m; |
60 | mapstruct *m; |
|
|
61 | sint16 nx, ny; |
49 | sint16 nx, ny; |
62 | |
50 | |
63 | if (!dir) |
51 | if (!dir) |
64 | { |
|
|
65 | dir = 1; |
52 | dir = 1; |
66 | } |
|
|
67 | |
53 | |
68 | nx = op->x + freearr_x[dir]; |
54 | nx = op->x + freearr_x[dir]; |
69 | ny = op->y + freearr_y[dir]; |
55 | ny = op->y + freearr_y[dir]; |
70 | m = op->map; |
56 | m = op->map; |
71 | |
57 | |
72 | if (get_map_flags (m, &m, nx, ny, &nx, &ny)) |
58 | if (get_map_flags (m, &m, nx, ny, &nx, &ny) & (P_OUT_OF_MAP | P_SAFE | P_NO_MAGIC | P_NO_CLERIC)) |
73 | { |
59 | { |
74 | new_draw_info (NDI_UNIQUE, 0, op, "Can't make a rune there!"); |
60 | new_draw_info (NDI_UNIQUE, 0, op, "Can't make a rune there!"); |
75 | return 0; |
61 | return 0; |
76 | } |
62 | } |
|
|
63 | |
77 | for (tmp = get_map_ob (m, nx, ny); tmp != NULL; tmp = tmp->above) |
64 | for (tmp = m->at (nx, ny).bot; tmp; tmp = tmp->above) |
78 | if (tmp->type == RUNE) |
65 | if (tmp->type == RUNE) |
79 | break; |
66 | break; |
80 | |
67 | |
81 | if (tmp) |
68 | if (tmp) |
82 | { |
69 | { |
83 | new_draw_info (NDI_UNIQUE, 0, op, "You can't write a rune there."); |
70 | new_draw_info (NDI_UNIQUE, 0, op, "You can't write a rune on top of another rune."); |
84 | return 0; |
71 | return 0; |
85 | } |
72 | } |
86 | |
73 | |
87 | if (spell->other_arch) |
74 | if (spell->other_arch) |
88 | { |
75 | rune_spell = spell->other_arch->instance (); |
89 | rune_spell = arch_to_object (spell->other_arch); |
|
|
90 | } |
|
|
91 | else |
76 | else |
92 | { |
77 | { |
93 | /* Player specified spell. The player has to know the spell, so |
78 | /* Player specified spell. The player has to know the spell, so |
94 | * 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 |
95 | * use the item_matched_string for our typical matching method. |
80 | * use the item_matched_string for our typical matching method. |
… | |
… | |
102 | return 0; |
87 | return 0; |
103 | } |
88 | } |
104 | |
89 | |
105 | rune_spell = NULL; |
90 | rune_spell = NULL; |
106 | for (tmp = op->inv; tmp; tmp = tmp->below) |
91 | for (tmp = op->inv; tmp; tmp = tmp->below) |
107 | { |
|
|
108 | if (tmp->type == SPELL) |
92 | if (tmp->type == SPELL) |
109 | { |
93 | { |
110 | ms = item_matched_string (op, tmp, runename); |
94 | ms = item_matched_string (op, tmp, runename); |
111 | if (ms > bestmatch) |
95 | if (ms > bestmatch) |
112 | { |
96 | { |
113 | bestmatch = ms; |
97 | bestmatch = ms; |
114 | rune_spell = tmp; |
98 | rune_spell = tmp; |
115 | } |
99 | } |
116 | } |
100 | } |
117 | } |
101 | |
118 | if (!rune_spell) |
102 | if (!rune_spell) |
119 | { |
103 | { |
120 | 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); |
121 | return 0; |
105 | return 0; |
122 | } |
106 | } |
|
|
107 | |
123 | if (rune_spell->skill != spell->skill) |
108 | if (rune_spell->skill != spell->skill) |
124 | { |
109 | { |
125 | 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); |
126 | return 0; |
111 | return 0; |
127 | } |
112 | } |
|
|
113 | |
128 | if (caster->path_denied & spell->path_attuned) |
114 | if (caster->path_denied & spell->path_attuned && !caster->flag [FLAG_WIZCAST]) |
129 | { |
115 | { |
130 | new_draw_info_format (NDI_UNIQUE, 0, op, "%s belongs to a spell path denied to you.", &rune_spell->name); |
116 | new_draw_info_format (NDI_UNIQUE, 0, op, "%s belongs to a spell path denied to you.", &rune_spell->name); |
131 | return 0; |
117 | return 0; |
132 | } |
118 | } |
|
|
119 | |
133 | if (caster_level (caster, rune_spell) < rune_spell->level) |
120 | if (casting_level (caster, rune_spell) < rune_spell->level && !caster->flag [FLAG_WIZCAST]) |
134 | { |
|
|
135 | new_draw_info_format (NDI_UNIQUE, 0, op, "%s is beyond your ability to cast!", &rune_spell->name); |
|
|
136 | return 0; |
|
|
137 | } |
121 | { |
|
|
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); |
|
|
123 | return 0; |
|
|
124 | } |
|
|
125 | |
138 | 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) |
139 | { |
127 | { |
140 | new_draw_info (NDI_UNIQUE, 0, op, "You don't have enough mana."); |
128 | new_draw_info (NDI_UNIQUE, 0, op, "You don't have enough mana."); |
141 | return 0; |
129 | return 0; |
142 | } |
130 | } |
|
|
131 | |
143 | if (SP_level_spellpoint_cost (caster, rune_spell, SPELL_GRACE) > op->stats.grace) |
132 | if (SP_level_spellpoint_cost (caster, rune_spell, SPELL_GRACE) > op->stats.grace) |
144 | { |
133 | { |
145 | 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."); |
146 | return 0; |
135 | return 0; |
147 | } |
136 | } |
|
|
137 | |
148 | 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); |
149 | 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); |
150 | } |
140 | } |
|
|
141 | |
151 | /* 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 */ |
152 | if (rune_spell->type == RUNE) |
143 | if (rune_spell->type == RUNE) |
153 | { |
|
|
154 | rune = rune_spell; |
144 | rune = rune_spell; |
155 | } |
|
|
156 | else |
145 | else |
157 | { |
146 | { |
158 | rune = get_archetype (GENERIC_RUNE); |
147 | rune = archetype::get (GENERIC_RUNE); |
159 | 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); |
160 | rune->msg = buf; |
149 | rune->insert (rune_spell->clone ()); |
161 | tmp = get_object (); |
150 | |
162 | copy_object (rune_spell, tmp); |
|
|
163 | insert_ob_in_ob (tmp, rune); |
|
|
164 | if (spell->face != blank_face) |
151 | if (spell->face != blank_face) |
165 | rune->face = spell->face; |
152 | rune->face = spell->face; |
166 | } |
153 | } |
|
|
154 | |
167 | rune->level = caster_level (caster, spell); |
155 | rune->level = casting_level (caster, spell); |
168 | rune->stats.Cha = rune->level / 2; /* the invisibility parameter */ |
156 | 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 */ |
157 | rune->direction = dir; /* where any spell will go upon detonation */ |
173 | set_owner (rune, op); /* runes without need no owner */ |
158 | rune->set_owner (op); /* runes without need no owner */ |
174 | set_spell_skill (op, caster, spell, rune); |
159 | set_spell_skill (op, caster, spell, rune); |
175 | insert_ob_in_map (rune, m, op, 0); |
160 | |
|
|
161 | m->insert (rune, nx, ny, op); |
176 | return 1; |
162 | return 1; |
177 | |
|
|
178 | } |
163 | } |
179 | |
|
|
180 | |
|
|
181 | |
164 | |
182 | /* move_rune: peterm |
165 | /* move_rune: peterm |
183 | comments on runes: |
166 | comments on runes: |
184 | rune->level : level at which rune will cast its spell. |
167 | rune->level : level at which rune will cast its spell. |
185 | rune->hp : number of detonations before rune goes away |
168 | rune->hp : number of detonations before rune goes away |
… | |
… | |
189 | rune->attacktype: type of damage it does, if not casting spells |
172 | rune->attacktype: type of damage it does, if not casting spells |
190 | rune->other_arch: spell in the rune |
173 | rune->other_arch: spell in the rune |
191 | rune->Cha : how hidden the rune is |
174 | rune->Cha : how hidden the rune is |
192 | rune->maxhp : number of spells the rune casts |
175 | rune->maxhp : number of spells the rune casts |
193 | */ |
176 | */ |
194 | |
|
|
195 | void |
177 | void |
196 | move_rune (object *op) |
178 | move_rune (object *op) |
197 | { |
179 | { |
198 | int det = 0; |
180 | /* runes of level zero cannot detonate. */ |
199 | |
|
|
200 | if (!op->level) |
181 | if (!op->level) |
201 | { |
|
|
202 | return; |
182 | return; |
203 | } /* runes of level zero cannot detonate. */ |
183 | |
204 | det = op->invisible; |
184 | int det = op->invisible; |
|
|
185 | |
205 | if (!(rndm (0, MAX (1, (op->stats.Cha)) - 1))) |
186 | if (!(rndm (0, max (0, op->stats.Cha - 1)))) |
206 | { |
187 | { |
207 | op->invisible = 0; |
188 | op->invisible = 0; |
208 | op->speed_left -= 1; |
189 | op->speed_left -= 1; |
209 | } |
190 | } |
210 | else |
191 | else |
211 | op->invisible = 1; |
192 | op->invisible = 1; |
|
|
193 | |
212 | if (op->invisible != det) |
194 | if (op->invisible != det) |
213 | update_object (op, UP_OBJ_FACE); |
195 | update_object (op, UP_OBJ_CHANGE); |
214 | } |
196 | } |
215 | |
|
|
216 | |
197 | |
217 | /* peterm: rune_attack |
198 | /* peterm: rune_attack |
218 | * function handles those runes which detonate but do not cast spells. |
199 | * function handles those runes which detonate but do not cast spells. |
219 | */ |
200 | */ |
220 | |
201 | static void |
221 | |
|
|
222 | void |
|
|
223 | rune_attack (object *op, object *victim) |
202 | rune_attack (object *op, object *victim) |
224 | { |
203 | { |
225 | if (victim) |
204 | if (victim) |
226 | { |
205 | { |
227 | tag_t tag = victim->count; |
|
|
228 | |
|
|
229 | hit_player (victim, op->stats.dam, op, op->attacktype, 1); |
206 | hit_player (victim, op->stats.dam, op, op->attacktype, 1); |
230 | if (was_destroyed (victim, tag)) |
207 | |
|
|
208 | if (victim->destroyed ()) |
231 | return; |
209 | return; |
|
|
210 | |
232 | /* if there's a disease in the needle, put it in the player */ |
211 | /* if there's a disease in the needle, put it in the player */ |
233 | if (HAS_RANDOM_ITEMS (op)) |
212 | if (op->has_random_items ()) |
234 | create_treasure (op->randomitems, op, 0, (victim->map ? victim->map->difficulty : 1), 0); |
213 | create_treasure (op->randomitems, op, 0, (victim->map ? victim->map->difficulty : 1), 0); |
|
|
214 | |
235 | if (op->inv && op->inv->type == DISEASE) |
215 | if (op->inv && op->inv->type == DISEASE) |
236 | { |
216 | { |
237 | object *disease = op->inv; |
217 | object *disease = op->inv; |
238 | |
218 | |
239 | infect_object (victim, disease, 1); |
219 | infect_object (victim, disease, 1); |
240 | remove_ob (disease); |
220 | disease->destroy (); |
241 | free_object (disease); |
|
|
242 | } |
221 | } |
243 | } |
222 | } |
244 | else |
223 | else |
245 | hit_map (op, 0, op->attacktype, 1); |
224 | hit_map (op, 0, op->attacktype, 1); |
246 | } |
225 | } |
… | |
… | |
251 | */ |
230 | */ |
252 | void |
231 | void |
253 | spring_trap (object *trap, object *victim) |
232 | spring_trap (object *trap, object *victim) |
254 | { |
233 | { |
255 | object *env; |
234 | object *env; |
256 | tag_t trap_tag = trap->count; |
|
|
257 | rv_vector rv; |
235 | rv_vector rv; |
258 | int i; |
236 | int i; |
259 | |
237 | |
260 | /* Prevent recursion */ |
238 | /* Prevent recursion */ |
261 | if (trap->stats.hp <= 0) |
239 | if (trap->stats.hp <= 0) |
262 | return; |
240 | return; |
263 | |
241 | |
264 | if (QUERY_FLAG (trap, FLAG_IS_LINKED)) |
242 | if (trap->flag [FLAG_IS_LINKED]) |
265 | use_trigger (trap); |
243 | use_trigger (trap, victim); |
266 | |
244 | |
267 | /* 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 |
268 | * 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. |
269 | * Typical example is an arrow attacking a door. |
247 | * Typical example is an arrow attacking a door. |
270 | */ |
248 | */ |
271 | if (!QUERY_FLAG (victim, FLAG_ALIVE) && !trap->inv && !trap->other_arch) |
249 | if (!victim->flag [FLAG_ALIVE] && !trap->inv && !trap->other_arch) |
272 | return; |
250 | return; |
273 | |
251 | |
274 | trap->stats.hp--; /*decrement detcount */ |
252 | trap->stats.hp--; /*decrement detcount */ |
275 | |
253 | |
276 | if (victim && victim->type == PLAYER) |
254 | if (victim && victim->type == PLAYER) |
277 | new_draw_info (NDI_UNIQUE, 0, victim, trap->msg); |
255 | new_draw_info (NDI_UNIQUE, 0, victim, trap->msg); |
278 | |
256 | |
279 | /* 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 |
280 | * knows what hit him. |
258 | * knows what hit him. |
281 | */ |
259 | */ |
282 | env = object_get_env_recursive (trap); |
260 | env = trap->outer_env_or_self (); |
283 | |
261 | |
284 | /* 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. |
285 | * 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. |
286 | * At the same time, the trap will stick around until detonated |
264 | * At the same time, the trap will stick around until detonated |
287 | */ |
265 | */ |
288 | get_rangevector (env, victim, &rv, 0); |
266 | get_rangevector (env, victim, &rv, 0); |
289 | if (rv.distance > 1) |
267 | if (rv.distance > 1) |
290 | return; |
268 | return; |
291 | |
269 | |
|
|
270 | env->play_sound (trap->sound ? trap->sound : sound_find ("trap_spring")); |
|
|
271 | |
292 | trap_show (trap, env); |
272 | trap_show (trap, env); |
293 | |
273 | |
|
|
274 | if (victim->type == PLAYER) // only count players as enemies |
|
|
275 | trap->enemy = victim; // set the victim as the traps enemy, so that summoned |
|
|
276 | // creatures know who to attack. |
|
|
277 | |
294 | /* Only if it is a spell do we proceed here */ |
278 | /* 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)) |
279 | if ((trap->inv && trap->inv->type == SPELL) || (trap->other_arch && trap->other_arch->type == SPELL)) |
296 | { |
280 | { |
297 | |
281 | if (trap->destroyed ()) |
298 | if (was_destroyed (trap, trap_tag)) |
|
|
299 | return; |
282 | return; |
300 | |
283 | |
301 | // breaks summon golem spells, which, for inexplicable reasons, |
284 | // breaks summon golem spells, which, for inexplicable reasons, |
302 | // 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 |
303 | // direction "0" to work at all. |
286 | // direction "0" to work at all. |
304 | //if (trap->direction) |
287 | //if (trap->direction) |
305 | // rv.direction = trap->direction; |
288 | // rv.direction = trap->direction; |
306 | |
289 | |
307 | for (i = 0; i < MAX (1, trap->stats.maxhp); i++) |
290 | for (i = 0; i < max (1, trap->stats.maxhp); i++) |
308 | { |
291 | { |
309 | if (trap->inv) |
292 | if (trap->inv) |
310 | cast_spell (env, trap, trap->direction, trap->inv, NULL); |
293 | cast_spell (env, trap, trap->direction, trap->inv, NULL); |
311 | else |
294 | else |
312 | { |
295 | { |
313 | object *spell = arch_to_object (trap->other_arch); |
296 | object *spell = trap->other_arch->instance (); |
314 | |
297 | |
315 | cast_spell (env, trap, trap->direction, spell, NULL); |
298 | cast_spell (env, trap, trap->direction, spell, NULL); |
316 | free_object (spell); |
299 | spell->destroy (); |
317 | } |
300 | } |
318 | } |
301 | } |
319 | } |
302 | } |
320 | else |
303 | else |
321 | { |
304 | { |
322 | rune_attack (trap, victim); |
305 | rune_attack (trap, victim); |
323 | if (was_destroyed (trap, trap_tag)) |
306 | if (trap->destroyed ()) |
324 | return; |
307 | return; |
325 | } |
308 | } |
326 | |
309 | |
327 | if (trap->stats.hp <= 0) |
310 | if (trap->stats.hp <= 0) |
328 | { |
311 | { |
329 | trap->type = SIGN; /* make the trap impotent */ |
312 | trap->type = SIGN; /* make the trap impotent */ |
330 | 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 */ |
331 | SET_FLAG (trap, FLAG_IS_USED_UP); |
314 | trap->set_flag (FLAG_IS_USED_UP); |
332 | } |
315 | } |
333 | } |
316 | } |
334 | |
317 | |
335 | /* dispel_rune: by peterm |
318 | /* dispel_rune: by peterm |
336 | * dispels the target rune, depending on the level of the actor |
319 | * dispels the target rune, depending on the level of the actor |
… | |
… | |
341 | 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) |
342 | { |
325 | { |
343 | object *tmp, *tmp2; |
326 | object *tmp, *tmp2; |
344 | int searchflag = 1, mflags; |
327 | int searchflag = 1, mflags; |
345 | sint16 x, y; |
328 | sint16 x, y; |
346 | mapstruct *m; |
329 | maptile *m; |
347 | |
330 | |
348 | x = op->x + freearr_x[dir]; |
331 | x = op->x + freearr_x[dir]; |
349 | y = op->y + freearr_y[dir]; |
332 | y = op->y + freearr_y[dir]; |
350 | m = op->map; |
333 | m = op->map; |
351 | |
334 | |
… | |
… | |
358 | { |
341 | { |
359 | new_draw_info (NDI_UNIQUE, 0, op, "There's nothing there!"); |
342 | new_draw_info (NDI_UNIQUE, 0, op, "There's nothing there!"); |
360 | return 0; |
343 | return 0; |
361 | } |
344 | } |
362 | |
345 | |
363 | 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) |
364 | { |
347 | { |
365 | if (tmp->type == RUNE || tmp->type == TRAP) |
348 | if (tmp->type == RUNE || tmp->type == TRAP) |
366 | break; |
349 | break; |
367 | |
350 | |
368 | /* we could put a probability chance here, but since nothing happens |
351 | /* 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 |
352 | * 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. |
353 | * comparison so low level players can't erase high level players runes. |
371 | */ |
354 | */ |
372 | if (tmp->type == SIGN && !strcmp (tmp->arch->name, "rune_mark")) |
355 | if (tmp->type == SIGN && tmp->arch->archname == shstr_rune_mark) |
373 | { |
356 | { |
374 | remove_ob (tmp); |
357 | tmp->destroy (); |
375 | free_object (tmp); |
|
|
376 | 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!"); |
377 | return 1; |
359 | return 1; |
378 | } |
360 | } |
379 | |
361 | |
380 | /* now search tmp's inventory for traps |
362 | /* now search tmp's inventory for traps |
381 | * 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. |
382 | */ |
364 | */ |
383 | for (tmp2 = tmp->inv; tmp2 != NULL; tmp2 = tmp2->below) |
365 | for (tmp2 = tmp->inv; tmp2; tmp2 = tmp2->below) |
384 | { |
366 | { |
385 | if (tmp2->type == RUNE || tmp2->type == TRAP) |
367 | if (tmp2->type == RUNE || tmp2->type == TRAP) |
386 | { |
368 | { |
387 | tmp = tmp2; |
369 | tmp = tmp2; |
388 | searchflag = 0; |
370 | searchflag = 0; |
389 | break; |
371 | break; |
390 | } |
372 | } |
391 | } |
373 | } |
|
|
374 | |
392 | if (!searchflag) |
375 | if (!searchflag) |
393 | break; |
376 | break; |
394 | } |
377 | } |
395 | |
378 | |
396 | /* no rune there. */ |
379 | /* no rune there. */ |
397 | if (tmp == NULL) |
380 | if (tmp == NULL) |
398 | { |
381 | { |
399 | new_draw_info (NDI_UNIQUE, 0, op, "There's nothing there!"); |
382 | new_draw_info (NDI_UNIQUE, 0, op, "There's nothing there!"); |
400 | return 0; |
383 | return 0; |
401 | } |
384 | } |
|
|
385 | |
402 | trap_disarm (op, tmp, 0, skill); |
386 | trap_disarm (op, tmp, 0, skill); |
403 | return 1; |
387 | return 1; |
404 | |
|
|
405 | } |
388 | } |
406 | |
389 | |
407 | int |
390 | int |
408 | trap_see (object *op, object *trap) |
391 | trap_see (object *op, object *trap) |
409 | { |
392 | { |
410 | int chance; |
|
|
411 | |
|
|
412 | chance = random_roll (0, 99, op, PREFER_HIGH);; |
393 | int chance = random_roll (0, 99, op, PREFER_HIGH); |
413 | |
394 | |
414 | /* decide if we see the rune or not */ |
395 | /* decide if we see the rune or not */ |
415 | 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 |
416 | + trap->level + trap->stats.Cha - op->level) / 10.0 * 50.0)))))) |
397 | + trap->level + trap->stats.Cha - op->level) / 10.0 * 50.0)))))) |
417 | { |
398 | { |
418 | 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); |
419 | return 1; |
400 | return 1; |
420 | } |
401 | } |
|
|
402 | |
421 | return 0; |
403 | return 0; |
422 | } |
404 | } |
423 | |
405 | |
424 | int |
406 | int |
425 | trap_show (object *trap, object *where) |
407 | trap_show (object *trap, object *where) |
426 | { |
408 | { |
427 | object *tmp2; |
|
|
428 | |
|
|
429 | if (where == NULL) |
409 | if (where == NULL) |
430 | return 0; |
410 | return 0; |
431 | tmp2 = get_archetype ("runedet"); |
411 | |
432 | tmp2->face = &new_faces[GET_ANIMATION (trap, 0)]; |
412 | object *tmp = archetype::get (shstr_runedet); |
433 | tmp2->x = where->x; |
413 | tmp->face = trap->get_anim_frame (0); |
434 | tmp2->y = where->y; |
414 | tmp->insert_at (where, 0); |
435 | tmp2->map = where->map; |
415 | |
436 | insert_ob_in_map (tmp2, where->map, NULL, 0); |
|
|
437 | return 1; |
416 | return 1; |
438 | |
|
|
439 | } |
417 | } |
440 | |
|
|
441 | |
418 | |
442 | int |
419 | int |
443 | trap_disarm (object *disarmer, object *trap, int risk, object *skill) |
420 | trap_disarm (object *disarmer, object *trap, int risk, object *skill) |
444 | { |
421 | { |
445 | int trapworth; /* need to compute the experience worth of the trap |
422 | int trapworth; /* need to compute the experience worth of the trap before we kill it */ |
446 | before we kill it */ |
|
|
447 | |
423 | |
448 | /* this formula awards a more reasonable amount of exp */ |
424 | /* this formula awards a more reasonable amount of exp */ |
449 | trapworth = MAX (1, trap->level) * disarmer->map->difficulty * |
425 | trapworth = max (1, trap->level) |
|
|
426 | * disarmer->map->difficulty |
450 | sqr (MAX (trap->stats.dam, trap->inv ? trap->inv->level : 1)) / skill->level; |
427 | * sqr (max (trap->stats.dam, trap->inv ? trap->inv->level : 1)) |
|
|
428 | / skill->level; |
451 | |
429 | |
452 | 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))) |
453 | { |
431 | { |
454 | 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); |
455 | destroy_object (trap); |
433 | trap->destroy (); |
|
|
434 | |
456 | /* 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 |
457 | * get exp for it. |
436 | * get exp for it. |
458 | */ |
437 | */ |
459 | if (trap->owner && trap->owner->type != PLAYER && risk) |
438 | if (trap->owner && trap->owner->type != PLAYER && risk) |
460 | return trapworth; |
439 | return trapworth; |
… | |
… | |
462 | return 1; /* give minimal exp and say success */ |
441 | return 1; /* give minimal exp and say success */ |
463 | } |
442 | } |
464 | else |
443 | else |
465 | { |
444 | { |
466 | 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); |
467 | 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) |
468 | { |
447 | { |
469 | 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!"); |
470 | spring_trap (trap, disarmer); |
449 | spring_trap (trap, disarmer); |
471 | } |
450 | } |
472 | return 0; |
451 | return 0; |
473 | } |
452 | } |
474 | } |
453 | } |
475 | |
|
|
476 | |
454 | |
477 | /* 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 |
478 | * default traps are too strong for wimpy level 1 players, and |
456 | * default traps are too strong for wimpy level 1 players, and |
479 | * unthreatening to anyone of high level |
457 | * unthreatening to anyone of high level |
480 | */ |
458 | */ |
481 | |
|
|
482 | void |
459 | void |
483 | trap_adjust (object *trap, int difficulty) |
460 | trap_adjust (object *trap, int difficulty) |
484 | { |
461 | { |
485 | int i; |
462 | int i; |
486 | |
463 | |