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.3 by root, Sun Sep 3 00:18:42 2006 UTC vs.
Revision 1.4 by root, Sun Sep 10 15:59:57 2006 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines