1 | /* |
1 | /* |
2 | * static char *rcsid_rune_c = |
2 | * This file is part of Crossfire TRT, the Roguelike Realtime MORPG. |
3 | * "$Id: rune.C,v 1.2 2006/08/29 08:01:38 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> |
4 | */ |
22 | */ |
5 | |
23 | |
6 | /* |
|
|
7 | CrossFire, A Multiplayer game for X-windows |
|
|
8 | |
|
|
9 | Copyright (C) 2003 Mark Wedel & Crossfire Development Team |
|
|
10 | Copyright (C) 1992 Frank Tore Johansen |
|
|
11 | |
|
|
12 | This program is free software; you can redistribute it and/or modify |
|
|
13 | it under the terms of the GNU General Public License as published by |
|
|
14 | the Free Software Foundation; either version 2 of the License, or |
|
|
15 | (at your option) any later version. |
|
|
16 | |
|
|
17 | This program is distributed in the hope that it will be useful, |
|
|
18 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
|
19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
|
20 | GNU General Public License for more details. |
|
|
21 | |
|
|
22 | You should have received a copy of the GNU General Public License |
|
|
23 | along with this program; if not, write to the Free Software |
|
|
24 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
|
|
25 | |
|
|
26 | The authors can be reached via e-mail at crossfire-devel@real-time.com |
|
|
27 | */ |
|
|
28 | |
|
|
29 | #include <global.h> |
24 | #include <global.h> |
30 | #ifndef __CEXTRACT__ |
|
|
31 | #include <sproto.h> |
25 | #include <sproto.h> |
|
|
26 | #include <spells.h> |
|
|
27 | |
|
|
28 | #ifndef sqr |
|
|
29 | # define sqr(x) ((x)*(x)) |
32 | #endif |
30 | #endif |
33 | #include <spells.h> |
|
|
34 | |
|
|
35 | |
|
|
36 | #ifndef sqr |
|
|
37 | #define sqr(x) ((x)*(x)) |
|
|
38 | #endif |
|
|
39 | |
|
|
40 | |
31 | |
41 | /* peterm: |
32 | /* peterm: |
42 | * write_rune: |
33 | * write_rune: |
43 | * op: rune writer |
34 | * op: rune writer |
44 | * skop: skill object used for casting this rune |
35 | * skop: skill object used for casting this rune |
… | |
… | |
49 | * level: level of casting of the rune |
40 | * level: level of casting of the rune |
50 | * 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 |
51 | * a rune of marking |
42 | * a rune of marking |
52 | */ |
43 | */ |
53 | |
44 | |
|
|
45 | int |
54 | int write_rune(object *op,object *caster, object *spell, int dir, const char *runename) { |
46 | write_rune (object *op, object *caster, object *spell, int dir, const char *runename) |
|
|
47 | { |
55 | object *tmp, *rune_spell, *rune; |
48 | object *tmp, *rune_spell, *rune; |
56 | char buf[MAX_BUF]; |
49 | char buf[MAX_BUF]; |
57 | mapstruct *m; |
50 | maptile *m; |
58 | sint16 nx,ny; |
51 | sint16 nx, ny; |
59 | |
52 | |
60 | if(!dir) { |
53 | if (!dir) |
61 | dir=1; |
54 | dir = 1; |
62 | } |
|
|
63 | |
55 | |
64 | nx=op->x+freearr_x[dir]; |
56 | nx = op->x + freearr_x[dir]; |
65 | ny=op->y+freearr_y[dir]; |
57 | ny = op->y + freearr_y[dir]; |
66 | m = op->map; |
58 | m = op->map; |
67 | |
59 | |
68 | 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)) |
|
|
61 | { |
69 | 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!"); |
70 | return 0; |
|
|
71 | } |
|
|
72 | for(tmp=get_map_ob(m,nx,ny);tmp!=NULL;tmp=tmp->above) |
|
|
73 | if(tmp->type==RUNE) break; |
|
|
74 | |
|
|
75 | if(tmp){ |
|
|
76 | new_draw_info(NDI_UNIQUE, 0,op,"You can't write a rune there."); |
|
|
77 | return 0; |
63 | return 0; |
78 | } |
64 | } |
79 | |
65 | |
|
|
66 | for (tmp = m->at (nx, ny).bot; tmp; tmp = tmp->above) |
|
|
67 | if (tmp->type == RUNE) |
|
|
68 | break; |
|
|
69 | |
|
|
70 | if (tmp) |
|
|
71 | { |
|
|
72 | new_draw_info (NDI_UNIQUE, 0, op, "You can't write a rune on top of another rune."); |
|
|
73 | return 0; |
|
|
74 | } |
|
|
75 | |
80 | if (spell->other_arch) { |
76 | if (spell->other_arch) |
81 | rune_spell = arch_to_object(spell->other_arch); |
77 | rune_spell = arch_to_object (spell->other_arch); |
82 | } else { |
78 | else |
|
|
79 | { |
83 | /* Player specified spell. The player has to know the spell, so |
80 | /* Player specified spell. The player has to know the spell, so |
84 | * 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 |
85 | * use the item_matched_string for our typical matching method. |
82 | * use the item_matched_string for our typical matching method. |
86 | */ |
83 | */ |
87 | int bestmatch = 0, ms; |
84 | int bestmatch = 0, ms; |
88 | |
85 | |
89 | if (!runename || *runename == 0) { |
86 | if (!runename || *runename == 0) |
|
|
87 | { |
90 | new_draw_info(NDI_UNIQUE, 0, op, "Write a rune of what?"); |
88 | new_draw_info (NDI_UNIQUE, 0, op, "Write a rune of what?"); |
91 | return 0; |
89 | return 0; |
92 | } |
90 | } |
93 | |
91 | |
94 | rune_spell=NULL; |
92 | rune_spell = NULL; |
95 | for (tmp=op->inv; tmp; tmp=tmp->below) { |
93 | for (tmp = op->inv; tmp; tmp = tmp->below) |
96 | if (tmp->type == SPELL) { |
94 | if (tmp->type == SPELL) |
|
|
95 | { |
97 | ms = item_matched_string(op, tmp, runename); |
96 | ms = item_matched_string (op, tmp, runename); |
98 | if (ms > bestmatch) { |
97 | if (ms > bestmatch) |
|
|
98 | { |
99 | bestmatch = ms; |
99 | bestmatch = ms; |
100 | rune_spell = tmp; |
100 | rune_spell = tmp; |
101 | } |
101 | } |
102 | } |
102 | } |
103 | } |
103 | |
104 | if (!rune_spell) { |
104 | if (!rune_spell) |
|
|
105 | { |
105 | new_draw_info_format(NDI_UNIQUE, 0, op, "You don't know any spell named %s", |
106 | new_draw_info_format (NDI_UNIQUE, 0, op, "You don't know any spell named %s", runename); |
106 | runename); |
|
|
107 | return 0; |
107 | return 0; |
108 | } |
108 | } |
|
|
109 | |
109 | if (rune_spell->skill != spell->skill) { |
110 | if (rune_spell->skill != spell->skill) |
|
|
111 | { |
110 | new_draw_info_format(NDI_UNIQUE, 0, op, "You can't cast %s with %s", |
112 | new_draw_info_format (NDI_UNIQUE, 0, op, "You can't cast %s with %s", &rune_spell->name, &spell->name); |
111 | rune_spell->name, spell->name); |
|
|
112 | return 0; |
113 | return 0; |
|
|
114 | } |
|
|
115 | |
|
|
116 | if (caster->path_denied & spell->path_attuned && !caster->flag [FLAG_WIZCAST]) |
113 | } |
117 | { |
114 | if (caster->path_denied & spell->path_attuned) { |
|
|
115 | new_draw_info_format(NDI_UNIQUE, 0,op, "%s belongs to a spell path denied to you.", |
118 | new_draw_info_format (NDI_UNIQUE, 0, op, "%s belongs to a spell path denied to you.", &rune_spell->name); |
116 | rune_spell->name); |
|
|
117 | return 0; |
119 | return 0; |
|
|
120 | } |
|
|
121 | |
|
|
122 | if (caster_level (caster, rune_spell) < rune_spell->level && !caster->flag [FLAG_WIZCAST]) |
118 | } |
123 | { |
119 | if (caster_level(caster, rune_spell) < rune_spell->level) { |
|
|
120 | new_draw_info_format(NDI_UNIQUE, 0,op, "%s is beyond your ability to cast!", |
124 | new_draw_info_format (NDI_UNIQUE, 0, op, "%s is beyond your ability to cast!", &rune_spell->name); |
121 | rune_spell->name); |
|
|
122 | return 0; |
125 | return 0; |
123 | } |
126 | } |
|
|
127 | |
124 | 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) |
|
|
129 | { |
125 | 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."); |
126 | return 0; |
131 | return 0; |
127 | } |
132 | } |
|
|
133 | |
128 | 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) |
|
|
135 | { |
129 | 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."); |
130 | return 0; |
137 | return 0; |
131 | } |
138 | } |
|
|
139 | |
132 | 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); |
133 | 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); |
134 | } |
142 | } |
|
|
143 | |
135 | /* 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 */ |
136 | if (rune_spell->type == RUNE) { |
145 | if (rune_spell->type == RUNE) |
137 | rune = rune_spell; |
146 | rune = rune_spell; |
138 | } else { |
147 | else |
|
|
148 | { |
139 | rune = get_archetype(GENERIC_RUNE); |
149 | rune = get_archetype (GENERIC_RUNE); |
140 | 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); |
141 | rune->msg=add_string(buf); |
151 | rune->msg = buf; |
142 | tmp = get_object(); |
152 | rune->insert (rune_spell->clone ()); |
143 | copy_object(rune_spell, tmp); |
153 | |
144 | insert_ob_in_ob(tmp, rune); |
|
|
145 | if (spell->face != blank_face) |
154 | if (spell->face != blank_face) |
146 | rune->face = spell->face; |
155 | rune->face = spell->face; |
147 | } |
156 | } |
|
|
157 | |
148 | rune->level = caster_level(caster, spell); |
158 | rune->level = caster_level (caster, spell); |
149 | rune->stats.Cha = rune->level/2; /* the invisibility parameter */ |
159 | rune->stats.Cha = rune->level / 2; /* the invisibility parameter */ |
150 | rune->x=nx; |
|
|
151 | rune->y=ny; |
|
|
152 | rune->map = m; |
|
|
153 | rune->direction=dir; /* where any spell will go upon detonation */ |
160 | rune->direction = dir; /* where any spell will go upon detonation */ |
154 | set_owner(rune,op); /* runes without need no owner */ |
161 | rune->set_owner (op); /* runes without need no owner */ |
155 | set_spell_skill(op, caster, spell, rune); |
162 | set_spell_skill (op, caster, spell, rune); |
156 | insert_ob_in_map(rune,m,op,0); |
163 | |
|
|
164 | m->insert (rune, nx, ny, op); |
157 | return 1; |
165 | return 1; |
158 | |
|
|
159 | } |
166 | } |
160 | |
|
|
161 | |
|
|
162 | |
167 | |
163 | /* move_rune: peterm |
168 | /* move_rune: peterm |
164 | comments on runes: |
169 | comments on runes: |
165 | rune->level : level at which rune will cast its spell. |
170 | rune->level : level at which rune will cast its spell. |
166 | rune->hp : number of detonations before rune goes away |
171 | rune->hp : number of detonations before rune goes away |
… | |
… | |
170 | rune->attacktype: type of damage it does, if not casting spells |
175 | rune->attacktype: type of damage it does, if not casting spells |
171 | rune->other_arch: spell in the rune |
176 | rune->other_arch: spell in the rune |
172 | rune->Cha : how hidden the rune is |
177 | rune->Cha : how hidden the rune is |
173 | rune->maxhp : number of spells the rune casts |
178 | rune->maxhp : number of spells the rune casts |
174 | */ |
179 | */ |
175 | |
180 | void |
176 | void move_rune(object *op) { |
181 | move_rune (object *op) |
177 | int det=0; |
182 | { |
178 | if(!op->level) {return;} /* runes of level zero cannot detonate. */ |
183 | /* runes of level zero cannot detonate. */ |
|
|
184 | if (!op->level) |
|
|
185 | return; |
|
|
186 | |
179 | det=op->invisible; |
187 | int det = op->invisible; |
|
|
188 | |
180 | if(!(rndm(0, MAX(1,(op->stats.Cha))-1))) { |
189 | if (!(rndm (0, MAX (1, (op->stats.Cha)) - 1))) |
|
|
190 | { |
181 | op->invisible=0; |
191 | op->invisible = 0; |
182 | op->speed_left-=1; |
192 | op->speed_left -= 1; |
183 | } |
193 | } |
184 | else |
194 | else |
185 | op->invisible=1; |
195 | op->invisible = 1; |
|
|
196 | |
186 | if(op->invisible!=det) |
197 | if (op->invisible != det) |
187 | update_object(op,UP_OBJ_FACE); |
198 | update_object (op, UP_OBJ_CHANGE); |
188 | } |
199 | } |
189 | |
|
|
190 | |
200 | |
191 | /* peterm: rune_attack |
201 | /* peterm: rune_attack |
192 | * function handles those runes which detonate but do not cast spells. |
202 | * function handles those runes which detonate but do not cast spells. |
193 | */ |
203 | */ |
194 | |
204 | void |
195 | |
|
|
196 | void rune_attack(object *op,object *victim) |
205 | rune_attack (object *op, object *victim) |
197 | { |
206 | { |
198 | if(victim) { |
207 | if (victim) |
199 | tag_t tag = victim->count; |
208 | { |
200 | hit_player(victim,op->stats.dam,op,op->attacktype,1); |
209 | hit_player (victim, op->stats.dam, op, op->attacktype, 1); |
201 | if (was_destroyed (victim, tag)) |
210 | |
|
|
211 | if (victim->destroyed ()) |
202 | return; |
212 | return; |
|
|
213 | |
203 | /* 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 */ |
204 | if(HAS_RANDOM_ITEMS(op)) create_treasure(op->randomitems,op,0, |
215 | if (op->has_random_items ()) |
205 | (victim->map?victim->map->difficulty:1),0); |
216 | create_treasure (op->randomitems, op, 0, (victim->map ? victim->map->difficulty : 1), 0); |
|
|
217 | |
206 | if(op->inv && op->inv->type == DISEASE) { |
218 | if (op->inv && op->inv->type == DISEASE) |
|
|
219 | { |
207 | object *disease=op->inv; |
220 | object *disease = op->inv; |
|
|
221 | |
208 | infect_object(victim, disease, 1); |
222 | infect_object (victim, disease, 1); |
209 | remove_ob(disease); |
223 | disease->destroy (); |
210 | free_object(disease); |
|
|
211 | } |
224 | } |
212 | } |
225 | } |
|
|
226 | else |
213 | else hit_map(op,0,op->attacktype,1); |
227 | hit_map (op, 0, op->attacktype, 1); |
214 | } |
228 | } |
215 | |
229 | |
216 | /* This function generalizes attacks by runes/traps. This ought to make |
230 | /* This function generalizes attacks by runes/traps. This ought to make |
217 | * it possible for runes to attack from the inventory, |
231 | * it possible for runes to attack from the inventory, |
218 | * it'll spring the trap on the victim. |
232 | * it'll spring the trap on the victim. |
219 | */ |
233 | */ |
|
|
234 | void |
220 | void spring_trap(object *trap,object *victim) |
235 | spring_trap (object *trap, object *victim) |
221 | { |
236 | { |
222 | object *env; |
237 | object *env; |
223 | tag_t trap_tag = trap->count; |
|
|
224 | rv_vector rv; |
238 | rv_vector rv; |
225 | int i; |
239 | int i; |
226 | |
240 | |
227 | /* Prevent recursion */ |
241 | /* Prevent recursion */ |
228 | if (trap->stats.hp <= 0) |
242 | if (trap->stats.hp <= 0) |
|
|
243 | return; |
|
|
244 | |
|
|
245 | if (QUERY_FLAG (trap, FLAG_IS_LINKED)) |
|
|
246 | use_trigger (trap); |
|
|
247 | |
|
|
248 | /* 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. |
|
|
250 | * Typical example is an arrow attacking a door. |
|
|
251 | */ |
|
|
252 | if (!QUERY_FLAG (victim, FLAG_ALIVE) && !trap->inv && !trap->other_arch) |
|
|
253 | return; |
|
|
254 | |
|
|
255 | trap->stats.hp--; /*decrement detcount */ |
|
|
256 | |
|
|
257 | if (victim && victim->type == PLAYER) |
|
|
258 | new_draw_info (NDI_UNIQUE, 0, victim, trap->msg); |
|
|
259 | |
|
|
260 | /* Flash an image of the trap on the map so the poor sod |
|
|
261 | * knows what hit him. |
|
|
262 | */ |
|
|
263 | env = object_get_env_recursive (trap); |
|
|
264 | |
|
|
265 | /* 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. |
|
|
267 | * At the same time, the trap will stick around until detonated |
|
|
268 | */ |
|
|
269 | get_rangevector (env, victim, &rv, 0); |
|
|
270 | if (rv.distance > 1) |
|
|
271 | return; |
|
|
272 | |
|
|
273 | trap_show (trap, env); |
|
|
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 | |
|
|
279 | /* Only if it is a spell do we proceed here */ |
|
|
280 | if ((trap->inv && trap->inv->type == SPELL) || (trap->other_arch && trap->other_arch->type == SPELL)) |
|
|
281 | { |
|
|
282 | |
|
|
283 | if (trap->destroyed ()) |
229 | return; |
284 | return; |
230 | |
285 | |
231 | if (QUERY_FLAG(trap,FLAG_IS_LINKED)) |
286 | // breaks summon golem spells, which, for inexplicable reasons, |
232 | use_trigger(trap); |
287 | // do not work like summon golem spells at all but still require |
|
|
288 | // direction "0" to work at all. |
|
|
289 | //if (trap->direction) |
|
|
290 | // rv.direction = trap->direction; |
233 | |
291 | |
234 | /* Only living objects can trigger runes that don't cast spells, as |
292 | for (i = 0; i < MAX (1, trap->stats.maxhp); i++) |
235 | * doing direct damage to a non-living object doesn't work anyway. |
293 | { |
236 | * Typical example is an arrow attacking a door. |
294 | if (trap->inv) |
237 | */ |
295 | cast_spell (env, trap, trap->direction, trap->inv, NULL); |
238 | if ( ! QUERY_FLAG (victim, FLAG_ALIVE) && !trap->inv && !trap->other_arch) |
296 | else |
|
|
297 | { |
|
|
298 | object *spell = arch_to_object (trap->other_arch); |
|
|
299 | |
|
|
300 | cast_spell (env, trap, trap->direction, spell, NULL); |
|
|
301 | spell->destroy (); |
|
|
302 | } |
|
|
303 | } |
|
|
304 | } |
|
|
305 | else |
|
|
306 | { |
|
|
307 | rune_attack (trap, victim); |
|
|
308 | if (trap->destroyed ()) |
239 | return; |
309 | return; |
240 | |
|
|
241 | trap->stats.hp--; /*decrement detcount */ |
|
|
242 | |
|
|
243 | if(victim && victim->type==PLAYER) |
|
|
244 | new_draw_info(NDI_UNIQUE, 0,victim,trap->msg); |
|
|
245 | |
|
|
246 | /* Flash an image of the trap on the map so the poor sod |
|
|
247 | * knows what hit him. |
|
|
248 | */ |
|
|
249 | env = object_get_env_recursive(trap); |
|
|
250 | |
|
|
251 | /* If the victim is not next to this trap, don't set it off. |
|
|
252 | * players shouldn't get hit by firing arrows at a door for example. |
|
|
253 | * At the same time, the trap will stick around until detonated |
|
|
254 | */ |
|
|
255 | get_rangevector(env, victim, &rv, 0); |
|
|
256 | if (rv.distance > 1) return; |
|
|
257 | |
|
|
258 | trap_show(trap,env); |
|
|
259 | |
|
|
260 | /* Only if it is a spell do we proceed here */ |
|
|
261 | if ((trap->inv && trap->inv->type == SPELL) || |
|
|
262 | (trap->other_arch && trap->other_arch->clone.type == SPELL)) { |
|
|
263 | |
|
|
264 | if (was_destroyed (trap, trap_tag)) |
|
|
265 | return; |
|
|
266 | |
|
|
267 | // breaks summon golem spells, which, for inexplicable reasons, |
|
|
268 | // do not work like summon golem spells at all but still require |
|
|
269 | // direction "0" to work at all. |
|
|
270 | //if (trap->direction) |
|
|
271 | // rv.direction = trap->direction; |
|
|
272 | |
|
|
273 | for(i = 0; i < MAX(1, trap->stats.maxhp); i++) { |
|
|
274 | if (trap->inv) |
|
|
275 | cast_spell(env,trap,trap->direction,trap->inv,NULL); |
|
|
276 | else { |
|
|
277 | object *spell = arch_to_object(trap->other_arch); |
|
|
278 | cast_spell(env,trap,trap->direction,spell,NULL); |
|
|
279 | free_object(spell); |
|
|
280 | } |
|
|
281 | } |
|
|
282 | } else { |
|
|
283 | rune_attack(trap,victim); |
|
|
284 | if (was_destroyed (trap, trap_tag)) |
|
|
285 | return; |
|
|
286 | } |
310 | } |
287 | |
311 | |
288 | if (trap->stats.hp <= 0) { |
312 | if (trap->stats.hp <= 0) |
|
|
313 | { |
289 | trap->type=SIGN; /* make the trap impotent */ |
314 | trap->type = SIGN; /* make the trap impotent */ |
290 | trap->stats.food=20; /* make it stick around until its spells are gone */ |
315 | trap->stats.food = 20; /* make it stick around until its spells are gone */ |
291 | SET_FLAG(trap,FLAG_IS_USED_UP); |
316 | SET_FLAG (trap, FLAG_IS_USED_UP); |
292 | } |
317 | } |
293 | } |
318 | } |
294 | |
319 | |
295 | /* dispel_rune: by peterm |
320 | /* dispel_rune: by peterm |
296 | * dispels the target rune, depending on the level of the actor |
321 | * dispels the target rune, depending on the level of the actor |
297 | * and the level of the rune risk flag, if true, means that there is |
322 | * and the level of the rune risk flag, if true, means that there is |
298 | * a chance that the trap/rune will detonate |
323 | * a chance that the trap/rune will detonate |
299 | */ |
324 | */ |
|
|
325 | int |
300 | int dispel_rune(object *op,object *caster, object *spell, object *skill, int dir) |
326 | dispel_rune (object *op, object *caster, object *spell, object *skill, int dir) |
301 | { |
327 | { |
302 | object *tmp,*tmp2; |
328 | object *tmp, *tmp2; |
303 | int searchflag = 1, mflags; |
329 | int searchflag = 1, mflags; |
304 | sint16 x,y; |
330 | sint16 x, y; |
305 | mapstruct *m; |
331 | maptile *m; |
306 | |
332 | |
307 | x = op->x+freearr_x[dir]; |
333 | x = op->x + freearr_x[dir]; |
308 | y = op->y+freearr_y[dir]; |
334 | y = op->y + freearr_y[dir]; |
309 | m = op->map; |
335 | m = op->map; |
310 | |
336 | |
311 | mflags = get_map_flags(m, &m, x, y, &x, &y); |
337 | mflags = get_map_flags (m, &m, x, y, &x, &y); |
312 | |
338 | |
313 | /* Should we perhaps not allow player to disable traps if a monster/ |
339 | /* Should we perhaps not allow player to disable traps if a monster/ |
314 | * player is standing on top? |
340 | * player is standing on top? |
315 | */ |
341 | */ |
316 | if (mflags & P_OUT_OF_MAP) { |
342 | if (mflags & P_OUT_OF_MAP) |
|
|
343 | { |
317 | new_draw_info(NDI_UNIQUE, 0,op,"There's nothing there!"); |
344 | new_draw_info (NDI_UNIQUE, 0, op, "There's nothing there!"); |
318 | return 0; |
345 | return 0; |
|
|
346 | } |
|
|
347 | |
|
|
348 | for (tmp = GET_MAP_OB (m, x, y); tmp != NULL; tmp = tmp->above) |
319 | } |
349 | { |
320 | |
|
|
321 | for(tmp=get_map_ob(m,x, y); tmp!=NULL; tmp=tmp->above) { |
|
|
322 | if(tmp->type==RUNE || tmp->type==TRAP) break; |
350 | if (tmp->type == RUNE || tmp->type == TRAP) |
|
|
351 | break; |
323 | |
352 | |
324 | /* we could put a probability chance here, but since nothing happens |
353 | /* we could put a probability chance here, but since nothing happens |
325 | * 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 |
326 | * 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. |
327 | */ |
356 | */ |
328 | if (tmp->type == SIGN && !strcmp(tmp->arch->name,"rune_mark")) { |
357 | if (tmp->type == SIGN && !strcmp (tmp->arch->archname, "rune_mark")) |
329 | remove_ob(tmp); |
358 | { |
330 | free_object(tmp); |
359 | tmp->destroy (); |
331 | 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!"); |
332 | return 1; |
361 | return 1; |
333 | } |
362 | } |
334 | |
363 | |
335 | /* now search tmp's inventory for traps |
364 | /* now search tmp's inventory for traps |
336 | * This is for chests, where the rune is in the chests inventory. |
365 | * This is for chests, where the rune is in the chests inventory. |
337 | */ |
366 | */ |
338 | for(tmp2=tmp->inv;tmp2!=NULL;tmp2=tmp2->below) { |
367 | for (tmp2 = tmp->inv; tmp2 != NULL; tmp2 = tmp2->below) |
|
|
368 | { |
339 | if(tmp2->type==RUNE || tmp2->type==TRAP) { |
369 | if (tmp2->type == RUNE || tmp2->type == TRAP) |
|
|
370 | { |
340 | tmp=tmp2; |
371 | tmp = tmp2; |
341 | searchflag=0; |
372 | searchflag = 0; |
342 | break; |
373 | break; |
343 | } |
374 | } |
344 | } |
375 | } |
345 | if(!searchflag) break; |
376 | if (!searchflag) |
|
|
377 | break; |
346 | } |
378 | } |
347 | |
379 | |
348 | /* no rune there. */ |
380 | /* no rune there. */ |
349 | if(tmp==NULL) { |
381 | if (tmp == NULL) |
|
|
382 | { |
350 | new_draw_info(NDI_UNIQUE, 0,op,"There's nothing there!"); |
383 | new_draw_info (NDI_UNIQUE, 0, op, "There's nothing there!"); |
351 | return 0; |
384 | return 0; |
352 | } |
385 | } |
353 | trap_disarm(op,tmp,0, skill); |
386 | trap_disarm (op, tmp, 0, skill); |
354 | return 1; |
387 | return 1; |
355 | |
|
|
356 | } |
|
|
357 | |
388 | |
|
|
389 | } |
|
|
390 | |
|
|
391 | int |
358 | int trap_see(object *op,object *trap) { |
392 | trap_see (object *op, object *trap) |
|
|
393 | { |
359 | int chance; |
394 | int chance; |
360 | |
395 | |
361 | chance = random_roll(0, 99, op, PREFER_HIGH);; |
396 | chance = random_roll (0, 99, op, PREFER_HIGH);; |
362 | |
397 | |
363 | /* decide if we see the rune or not */ |
398 | /* decide if we see the rune or not */ |
364 | if((trap->stats.Cha==1) || (chance > MIN(95,MAX(5,((int)((float) (op->map->difficulty |
399 | if ((trap->stats.Cha == 1) || (chance > MIN (95, MAX (5, ((int) ((float) (op->map->difficulty |
365 | + trap->level + trap->stats.Cha-op->level)/10.0 * 50.0)))))) { |
400 | + trap->level + trap->stats.Cha - op->level) / 10.0 * 50.0)))))) |
|
|
401 | { |
366 | new_draw_info_format(NDI_UNIQUE, 0,op,"You spot a %s!",trap->name); |
402 | new_draw_info_format (NDI_UNIQUE, 0, op, "You spot a %s!", &trap->name); |
367 | return 1; |
403 | return 1; |
368 | } |
404 | } |
|
|
405 | return 0; |
|
|
406 | } |
|
|
407 | |
|
|
408 | int |
|
|
409 | trap_show (object *trap, object *where) |
|
|
410 | { |
|
|
411 | if (where == NULL) |
369 | return 0; |
412 | return 0; |
370 | } |
|
|
371 | |
413 | |
372 | int trap_show(object *trap, object *where) { |
|
|
373 | object *tmp2; |
|
|
374 | |
|
|
375 | if(where==NULL) return 0; |
|
|
376 | tmp2=get_archetype("runedet"); |
414 | object *tmp = get_archetype ("runedet"); |
377 | tmp2->face=&new_faces[GET_ANIMATION(trap, 0)]; |
415 | tmp->face = GET_ANIMATION (trap, 0); |
378 | tmp2->x=where->x;tmp2->y=where->y;tmp2->map=where->map; |
416 | tmp->insert_at (where, 0); |
379 | insert_ob_in_map(tmp2,where->map,NULL,0); |
417 | |
380 | return 1; |
418 | return 1; |
381 | |
|
|
382 | } |
419 | } |
383 | |
420 | |
384 | |
421 | int |
385 | int trap_disarm(object *disarmer, object *trap, int risk, object *skill) { |
422 | trap_disarm (object *disarmer, object *trap, int risk, object *skill) |
|
|
423 | { |
386 | int trapworth; /* need to compute the experience worth of the trap |
424 | int trapworth; /* need to compute the experience worth of the trap |
387 | before we kill it */ |
425 | before we kill it */ |
388 | |
426 | |
389 | /* this formula awards a more reasonable amount of exp */ |
427 | /* this formula awards a more reasonable amount of exp */ |
390 | trapworth = MAX(1,trap->level) * disarmer->map->difficulty * |
428 | trapworth = MAX (1, trap->level) * disarmer->map->difficulty * |
391 | sqr(MAX(trap->stats.dam,trap->inv?trap->inv->level:1)) / |
429 | sqr (MAX (trap->stats.dam, trap->inv ? trap->inv->level : 1)) / skill->level; |
392 | skill->level; |
|
|
393 | |
430 | |
394 | if(!(random_roll(0, (MAX(2, MIN(20,trap->level-skill->level |
431 | if (!(random_roll (0, (MAX (2, MIN (20, trap->level - skill->level + 5 - disarmer->stats.Dex / 2)) - 1), disarmer, PREFER_LOW))) |
395 | +5 - disarmer->stats.Dex/2))-1), disarmer, PREFER_LOW))) |
432 | { |
396 | { |
433 | new_draw_info_format (NDI_UNIQUE, 0, disarmer, "You successfully disarm the %s!", &trap->name); |
397 | new_draw_info_format(NDI_UNIQUE, 0,disarmer, |
434 | trap->destroy (1); |
398 | "You successfully disarm the %s!",trap->name); |
435 | |
399 | destroy_object(trap); |
|
|
400 | /* 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 |
401 | * get exp for it. |
437 | * get exp for it. |
402 | */ |
438 | */ |
403 | if (trap->owner && trap->owner->type!=PLAYER && risk) |
439 | if (trap->owner && trap->owner->type != PLAYER && risk) |
404 | return trapworth; |
440 | return trapworth; |
405 | else return 1; /* give minimal exp and say success */ |
|
|
406 | } |
|
|
407 | else |
441 | else |
|
|
442 | return 1; /* give minimal exp and say success */ |
|
|
443 | } |
|
|
444 | else |
|
|
445 | { |
|
|
446 | 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) |
408 | { |
448 | { |
409 | new_draw_info_format(NDI_UNIQUE, 0,disarmer, |
|
|
410 | "You fail to disarm the %s.",trap->name); |
|
|
411 | if(! (random_roll(0, (MAX(2,skill->level-trap->level |
|
|
412 | + disarmer->stats.Dex/2-6))-1, disarmer, PREFER_LOW)) &&risk) { |
|
|
413 | new_draw_info(NDI_UNIQUE, 0,disarmer,"In fact, you set it off!"); |
449 | new_draw_info (NDI_UNIQUE, 0, disarmer, "In fact, you set it off!"); |
414 | spring_trap(trap,disarmer); |
450 | spring_trap (trap, disarmer); |
415 | } |
451 | } |
416 | return 0; |
452 | return 0; |
417 | } |
453 | } |
418 | } |
454 | } |
419 | |
455 | |
420 | |
456 | |
421 | /* traps need to be adjusted for the difficulty of the map. The |
457 | /* traps need to be adjusted for the difficulty of the map. The |
422 | * default traps are too strong for wimpy level 1 players, and |
458 | * default traps are too strong for wimpy level 1 players, and |
423 | * unthreatening to anyone of high level |
459 | * unthreatening to anyone of high level |
424 | */ |
460 | */ |
425 | |
461 | |
|
|
462 | void |
426 | void trap_adjust(object *trap, int difficulty) { |
463 | trap_adjust (object *trap, int difficulty) |
|
|
464 | { |
427 | int i; |
465 | int i; |
428 | |
466 | |
429 | /* now we set the trap level to match the difficulty of the level |
467 | /* now we set the trap level to match the difficulty of the level |
430 | * the formula below will give a level from 1 to (2*difficulty) with |
468 | * the formula below will give a level from 1 to (2*difficulty) with |
431 | * a peak probability at difficulty |
469 | * a peak probability at difficulty |
432 | */ |
470 | */ |
433 | |
471 | |
434 | trap->level = rndm(0, difficulty-1) + rndm(0, difficulty-1); |
472 | trap->level = rndm (0, difficulty - 1) + rndm (0, difficulty - 1); |
435 | if(trap->level < 1) |
473 | if (trap->level < 1) |
436 | trap->level = 1; |
474 | trap->level = 1; |
437 | |
475 | |
438 | /* set the hiddenness of the trap, similar formula to above */ |
476 | /* set the hiddenness of the trap, similar formula to above */ |
439 | trap->stats.Cha = rndm(0, 19) + rndm(0, difficulty-1) + rndm(0, difficulty-1); |
477 | trap->stats.Cha = rndm (0, 19) + rndm (0, difficulty - 1) + rndm (0, difficulty - 1); |
440 | |
478 | |
441 | if (!trap->other_arch && !trap->inv) { |
479 | if (!trap->other_arch && !trap->inv) |
|
|
480 | { |
442 | /* set the damage of the trap. |
481 | /* set the damage of the trap. |
443 | * we get 0-4 pts of damage per level of difficulty of the map in |
482 | * we get 0-4 pts of damage per level of difficulty of the map in |
444 | * the trap |
483 | * the trap |
445 | */ |
484 | */ |
446 | |
485 | |
447 | trap->stats.dam = 0; |
486 | trap->stats.dam = 0; |
448 | for(i=0;i<difficulty;i++) |
487 | for (i = 0; i < difficulty; i++) |
449 | trap->stats.dam+=rndm(0, 4); |
488 | trap->stats.dam += rndm (0, 4); |
450 | |
489 | |
451 | /* the poison trap special case */ |
490 | /* the poison trap special case */ |
452 | if(trap->attacktype & AT_POISON) { |
491 | if (trap->attacktype & AT_POISON) |
|
|
492 | { |
453 | trap->stats.dam = rndm(0, difficulty-1); |
493 | trap->stats.dam = rndm (0, difficulty - 1); |
454 | if(trap->stats.dam < 1) |
494 | if (trap->stats.dam < 1) |
455 | trap->stats.dam = 1; |
495 | trap->stats.dam = 1; |
456 | } |
496 | } |
457 | |
497 | |
458 | /* so we get an appropriate amnt of exp for AT_DEATH traps */ |
498 | /* so we get an appropriate amnt of exp for AT_DEATH traps */ |
459 | if(trap->attacktype & AT_DEATH) trap->stats.dam = 127; |
499 | if (trap->attacktype & AT_DEATH) |
|
|
500 | trap->stats.dam = 127; |
460 | } |
501 | } |
461 | |
502 | |
462 | } |
503 | } |
463 | |
|
|