1 | /* |
1 | /* |
2 | CrossFire, A Multiplayer game for X-windows |
2 | * CrossFire, A Multiplayer game for X-windows |
3 | |
3 | * |
|
|
4 | * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team |
4 | Copyright (C) 2003 Mark Wedel & Crossfire Development Team |
5 | * Copyright (C) 2003 Mark Wedel & Crossfire Development Team |
5 | Copyright (C) 1992 Frank Tore Johansen |
6 | * Copyright (C) 1992 Frank Tore Johansen |
6 | |
7 | * |
7 | This program is free software; you can redistribute it and/or modify |
8 | * This program is free software; you can redistribute it and/or modify |
8 | it under the terms of the GNU General Public License as published by |
9 | * it under the terms of the GNU General Public License as published by |
9 | the Free Software Foundation; either version 2 of the License, or |
10 | * the Free Software Foundation; either version 2 of the License, or |
10 | (at your option) any later version. |
11 | * (at your option) any later version. |
11 | |
12 | * |
12 | 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, |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | GNU General Public License for more details. |
16 | * GNU General Public License for more details. |
16 | |
17 | * |
17 | You should have received a copy of the GNU General Public License |
18 | * You should have received a copy of the GNU General Public License |
18 | along with this program; if not, write to the Free Software |
19 | * along with this program; if not, write to the Free Software |
19 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
20 | |
21 | * |
21 | The authors can be reached via e-mail at <crossfire@schmorp.de> |
22 | * The authors can be reached via e-mail at <crossfire@schmorp.de> |
22 | */ |
23 | */ |
23 | |
24 | |
24 | #include <global.h> |
25 | #include <global.h> |
25 | #ifndef __CEXTRACT__ |
|
|
26 | # include <sproto.h> |
26 | #include <sproto.h> |
27 | #endif |
|
|
28 | #include <spells.h> |
27 | #include <spells.h> |
29 | |
|
|
30 | |
28 | |
31 | #ifndef sqr |
29 | #ifndef sqr |
32 | # define sqr(x) ((x)*(x)) |
30 | # define sqr(x) ((x)*(x)) |
33 | #endif |
31 | #endif |
34 | |
|
|
35 | |
32 | |
36 | /* peterm: |
33 | /* peterm: |
37 | * write_rune: |
34 | * write_rune: |
38 | * op: rune writer |
35 | * op: rune writer |
39 | * skop: skill object used for casting this rune |
36 | * skop: skill object used for casting this rune |
… | |
… | |
53 | char buf[MAX_BUF]; |
50 | char buf[MAX_BUF]; |
54 | maptile *m; |
51 | maptile *m; |
55 | sint16 nx, ny; |
52 | sint16 nx, ny; |
56 | |
53 | |
57 | if (!dir) |
54 | if (!dir) |
58 | { |
|
|
59 | dir = 1; |
55 | dir = 1; |
60 | } |
|
|
61 | |
56 | |
62 | nx = op->x + freearr_x[dir]; |
57 | nx = op->x + freearr_x[dir]; |
63 | ny = op->y + freearr_y[dir]; |
58 | ny = op->y + freearr_y[dir]; |
64 | m = op->map; |
59 | m = op->map; |
65 | |
60 | |
66 | if (get_map_flags (m, &m, nx, ny, &nx, &ny)) |
61 | if (get_map_flags (m, &m, nx, ny, &nx, &ny) && (P_OUT_OF_MAP | P_SAFE | P_NO_MAGIC | P_NO_CLERIC)) |
67 | { |
62 | { |
68 | new_draw_info (NDI_UNIQUE, 0, op, "Can't make a rune there!"); |
63 | new_draw_info (NDI_UNIQUE, 0, op, "Can't make a rune there!"); |
69 | return 0; |
64 | return 0; |
70 | } |
65 | } |
|
|
66 | |
71 | for (tmp = get_map_ob (m, nx, ny); tmp != NULL; tmp = tmp->above) |
67 | for (tmp = m->at (nx, ny).bot; tmp; tmp = tmp->above) |
72 | if (tmp->type == RUNE) |
68 | if (tmp->type == RUNE) |
73 | break; |
69 | break; |
74 | |
70 | |
75 | if (tmp) |
71 | if (tmp) |
76 | { |
72 | { |
77 | new_draw_info (NDI_UNIQUE, 0, op, "You can't write a rune there."); |
73 | new_draw_info (NDI_UNIQUE, 0, op, "You can't write a rune there."); |
78 | return 0; |
74 | return 0; |
79 | } |
75 | } |
80 | |
76 | |
81 | if (spell->other_arch) |
77 | if (spell->other_arch) |
82 | { |
|
|
83 | rune_spell = arch_to_object (spell->other_arch); |
78 | rune_spell = arch_to_object (spell->other_arch); |
84 | } |
|
|
85 | else |
79 | else |
86 | { |
80 | { |
87 | /* Player specified spell. The player has to know the spell, so |
81 | /* Player specified spell. The player has to know the spell, so |
88 | * lets just look through the players inventory see if they know it |
82 | * lets just look through the players inventory see if they know it |
89 | * use the item_matched_string for our typical matching method. |
83 | * use the item_matched_string for our typical matching method. |
… | |
… | |
107 | bestmatch = ms; |
101 | bestmatch = ms; |
108 | rune_spell = tmp; |
102 | rune_spell = tmp; |
109 | } |
103 | } |
110 | } |
104 | } |
111 | } |
105 | } |
|
|
106 | |
112 | if (!rune_spell) |
107 | if (!rune_spell) |
113 | { |
108 | { |
114 | new_draw_info_format (NDI_UNIQUE, 0, op, "You don't know any spell named %s", runename); |
109 | new_draw_info_format (NDI_UNIQUE, 0, op, "You don't know any spell named %s", runename); |
115 | return 0; |
110 | return 0; |
116 | } |
111 | } |
|
|
112 | |
117 | if (rune_spell->skill != spell->skill) |
113 | if (rune_spell->skill != spell->skill) |
118 | { |
114 | { |
119 | new_draw_info_format (NDI_UNIQUE, 0, op, "You can't cast %s with %s", &rune_spell->name, &spell->name); |
115 | new_draw_info_format (NDI_UNIQUE, 0, op, "You can't cast %s with %s", &rune_spell->name, &spell->name); |
120 | return 0; |
116 | return 0; |
121 | } |
117 | } |
|
|
118 | |
122 | if (caster->path_denied & spell->path_attuned) |
119 | if (caster->path_denied & spell->path_attuned) |
123 | { |
120 | { |
124 | new_draw_info_format (NDI_UNIQUE, 0, op, "%s belongs to a spell path denied to you.", &rune_spell->name); |
121 | new_draw_info_format (NDI_UNIQUE, 0, op, "%s belongs to a spell path denied to you.", &rune_spell->name); |
125 | return 0; |
122 | return 0; |
126 | } |
123 | } |
|
|
124 | |
127 | if (caster_level (caster, rune_spell) < rune_spell->level) |
125 | if (caster_level (caster, rune_spell) < rune_spell->level) |
128 | { |
126 | { |
129 | new_draw_info_format (NDI_UNIQUE, 0, op, "%s is beyond your ability to cast!", &rune_spell->name); |
127 | new_draw_info_format (NDI_UNIQUE, 0, op, "%s is beyond your ability to cast!", &rune_spell->name); |
130 | return 0; |
128 | return 0; |
131 | } |
129 | } |
|
|
130 | |
132 | if (SP_level_spellpoint_cost (caster, rune_spell, SPELL_MANA) > op->stats.sp) |
131 | if (SP_level_spellpoint_cost (caster, rune_spell, SPELL_MANA) > op->stats.sp) |
133 | { |
132 | { |
134 | new_draw_info (NDI_UNIQUE, 0, op, "You don't have enough mana."); |
133 | new_draw_info (NDI_UNIQUE, 0, op, "You don't have enough mana."); |
135 | return 0; |
134 | return 0; |
136 | } |
135 | } |
|
|
136 | |
137 | if (SP_level_spellpoint_cost (caster, rune_spell, SPELL_GRACE) > op->stats.grace) |
137 | if (SP_level_spellpoint_cost (caster, rune_spell, SPELL_GRACE) > op->stats.grace) |
138 | { |
138 | { |
139 | new_draw_info (NDI_UNIQUE, 0, op, "You don't have enough grace."); |
139 | new_draw_info (NDI_UNIQUE, 0, op, "You don't have enough grace."); |
140 | return 0; |
140 | return 0; |
141 | } |
141 | } |
|
|
142 | |
142 | op->stats.grace -= SP_level_spellpoint_cost (caster, rune_spell, SPELL_GRACE); |
143 | op->stats.grace -= SP_level_spellpoint_cost (caster, rune_spell, SPELL_GRACE); |
143 | op->stats.sp -= SP_level_spellpoint_cost (caster, rune_spell, SPELL_MANA); |
144 | op->stats.sp -= SP_level_spellpoint_cost (caster, rune_spell, SPELL_MANA); |
144 | } |
145 | } |
|
|
146 | |
145 | /* already proper rune. Note this should only be the case if other_arch was set */ |
147 | /* already proper rune. Note this should only be the case if other_arch was set */ |
146 | if (rune_spell->type == RUNE) |
148 | if (rune_spell->type == RUNE) |
147 | { |
|
|
148 | rune = rune_spell; |
149 | rune = rune_spell; |
149 | } |
|
|
150 | else |
150 | else |
151 | { |
151 | { |
152 | rune = get_archetype (GENERIC_RUNE); |
152 | rune = get_archetype (GENERIC_RUNE); |
153 | sprintf (buf, "You set off a rune of %s\n", &rune_spell->name); |
153 | sprintf (buf, "You set off a rune of %s\n", &rune_spell->name); |
154 | rune->msg = buf; |
154 | rune->msg = buf; |
155 | tmp = get_object (); |
155 | rune->insert (rune_spell->clone ()); |
156 | copy_object (rune_spell, tmp); |
156 | |
157 | insert_ob_in_ob (tmp, rune); |
|
|
158 | if (spell->face != blank_face) |
157 | if (spell->face != blank_face) |
159 | rune->face = spell->face; |
158 | rune->face = spell->face; |
160 | } |
159 | } |
|
|
160 | |
161 | rune->level = caster_level (caster, spell); |
161 | rune->level = caster_level (caster, spell); |
162 | rune->stats.Cha = rune->level / 2; /* the invisibility parameter */ |
162 | rune->stats.Cha = rune->level / 2; /* the invisibility parameter */ |
163 | rune->x = nx; |
|
|
164 | rune->y = ny; |
|
|
165 | rune->map = m; |
|
|
166 | rune->direction = dir; /* where any spell will go upon detonation */ |
163 | rune->direction = dir; /* where any spell will go upon detonation */ |
167 | set_owner (rune, op); /* runes without need no owner */ |
164 | rune->set_owner (op); /* runes without need no owner */ |
168 | set_spell_skill (op, caster, spell, rune); |
165 | set_spell_skill (op, caster, spell, rune); |
169 | insert_ob_in_map (rune, m, op, 0); |
166 | |
|
|
167 | m->insert (rune, nx, ny, op); |
170 | return 1; |
168 | return 1; |
171 | |
|
|
172 | } |
169 | } |
173 | |
|
|
174 | |
|
|
175 | |
170 | |
176 | /* move_rune: peterm |
171 | /* move_rune: peterm |
177 | comments on runes: |
172 | comments on runes: |
178 | rune->level : level at which rune will cast its spell. |
173 | rune->level : level at which rune will cast its spell. |
179 | rune->hp : number of detonations before rune goes away |
174 | rune->hp : number of detonations before rune goes away |
… | |
… | |
183 | rune->attacktype: type of damage it does, if not casting spells |
178 | rune->attacktype: type of damage it does, if not casting spells |
184 | rune->other_arch: spell in the rune |
179 | rune->other_arch: spell in the rune |
185 | rune->Cha : how hidden the rune is |
180 | rune->Cha : how hidden the rune is |
186 | rune->maxhp : number of spells the rune casts |
181 | rune->maxhp : number of spells the rune casts |
187 | */ |
182 | */ |
188 | |
|
|
189 | void |
183 | void |
190 | move_rune (object *op) |
184 | move_rune (object *op) |
191 | { |
185 | { |
192 | int det = 0; |
186 | /* runes of level zero cannot detonate. */ |
193 | |
|
|
194 | if (!op->level) |
187 | if (!op->level) |
195 | { |
|
|
196 | return; |
188 | return; |
197 | } /* runes of level zero cannot detonate. */ |
189 | |
198 | det = op->invisible; |
190 | int det = op->invisible; |
|
|
191 | |
199 | if (!(rndm (0, MAX (1, (op->stats.Cha)) - 1))) |
192 | if (!(rndm (0, MAX (1, (op->stats.Cha)) - 1))) |
200 | { |
193 | { |
201 | op->invisible = 0; |
194 | op->invisible = 0; |
202 | op->speed_left -= 1; |
195 | op->speed_left -= 1; |
203 | } |
196 | } |
204 | else |
197 | else |
205 | op->invisible = 1; |
198 | op->invisible = 1; |
|
|
199 | |
206 | if (op->invisible != det) |
200 | if (op->invisible != det) |
207 | update_object (op, UP_OBJ_FACE); |
201 | update_object (op, UP_OBJ_FACE); |
208 | } |
202 | } |
209 | |
203 | |
210 | |
204 | |
… | |
… | |
222 | |
216 | |
223 | if (victim->destroyed ()) |
217 | if (victim->destroyed ()) |
224 | return; |
218 | return; |
225 | |
219 | |
226 | /* if there's a disease in the needle, put it in the player */ |
220 | /* if there's a disease in the needle, put it in the player */ |
227 | if (HAS_RANDOM_ITEMS (op)) |
221 | if (op->has_random_items ()) |
228 | create_treasure (op->randomitems, op, 0, (victim->map ? victim->map->difficulty : 1), 0); |
222 | create_treasure (op->randomitems, op, 0, (victim->map ? victim->map->difficulty : 1), 0); |
229 | |
223 | |
230 | if (op->inv && op->inv->type == DISEASE) |
224 | if (op->inv && op->inv->type == DISEASE) |
231 | { |
225 | { |
232 | object *disease = op->inv; |
226 | object *disease = op->inv; |
233 | |
227 | |
234 | infect_object (victim, disease, 1); |
228 | infect_object (victim, disease, 1); |
235 | disease->remove (); |
|
|
236 | disease->destroy (0); |
229 | disease->destroy (); |
237 | } |
230 | } |
238 | } |
231 | } |
239 | else |
232 | else |
240 | hit_map (op, 0, op->attacktype, 1); |
233 | hit_map (op, 0, op->attacktype, 1); |
241 | } |
234 | } |
… | |
… | |
305 | else |
298 | else |
306 | { |
299 | { |
307 | object *spell = arch_to_object (trap->other_arch); |
300 | object *spell = arch_to_object (trap->other_arch); |
308 | |
301 | |
309 | cast_spell (env, trap, trap->direction, spell, NULL); |
302 | cast_spell (env, trap, trap->direction, spell, NULL); |
310 | spell->destroy (0); |
303 | spell->destroy (); |
311 | } |
304 | } |
312 | } |
305 | } |
313 | } |
306 | } |
314 | else |
307 | else |
315 | { |
308 | { |
… | |
… | |
352 | { |
345 | { |
353 | new_draw_info (NDI_UNIQUE, 0, op, "There's nothing there!"); |
346 | new_draw_info (NDI_UNIQUE, 0, op, "There's nothing there!"); |
354 | return 0; |
347 | return 0; |
355 | } |
348 | } |
356 | |
349 | |
357 | for (tmp = get_map_ob (m, x, y); tmp != NULL; tmp = tmp->above) |
350 | for (tmp = GET_MAP_OB (m, x, y); tmp != NULL; tmp = tmp->above) |
358 | { |
351 | { |
359 | if (tmp->type == RUNE || tmp->type == TRAP) |
352 | if (tmp->type == RUNE || tmp->type == TRAP) |
360 | break; |
353 | break; |
361 | |
354 | |
362 | /* we could put a probability chance here, but since nothing happens |
355 | /* we could put a probability chance here, but since nothing happens |
363 | * if you fail, no point on that. I suppose we could do a level |
356 | * if you fail, no point on that. I suppose we could do a level |
364 | * comparison so low level players can't erase high level players runes. |
357 | * comparison so low level players can't erase high level players runes. |
365 | */ |
358 | */ |
366 | if (tmp->type == SIGN && !strcmp (tmp->arch->name, "rune_mark")) |
359 | if (tmp->type == SIGN && !strcmp (tmp->arch->name, "rune_mark")) |
367 | { |
360 | { |
368 | tmp->remove (); |
|
|
369 | tmp->destroy (0); |
361 | tmp->destroy (); |
370 | new_draw_info (NDI_UNIQUE, 0, op, "You wipe out the rune of marking!"); |
362 | new_draw_info (NDI_UNIQUE, 0, op, "You wipe out the rune of marking!"); |
371 | return 1; |
363 | return 1; |
372 | } |
364 | } |
373 | |
365 | |
374 | /* now search tmp's inventory for traps |
366 | /* now search tmp's inventory for traps |
… | |
… | |
416 | } |
408 | } |
417 | |
409 | |
418 | int |
410 | int |
419 | trap_show (object *trap, object *where) |
411 | trap_show (object *trap, object *where) |
420 | { |
412 | { |
421 | object *tmp2; |
|
|
422 | |
|
|
423 | if (where == NULL) |
413 | if (where == NULL) |
424 | return 0; |
414 | return 0; |
|
|
415 | |
425 | tmp2 = get_archetype ("runedet"); |
416 | object *tmp = get_archetype ("runedet"); |
426 | tmp2->face = &new_faces[GET_ANIMATION (trap, 0)]; |
417 | tmp->face = &new_faces[GET_ANIMATION (trap, 0)]; |
427 | tmp2->x = where->x; |
418 | tmp->insert_at (where, 0); |
428 | tmp2->y = where->y; |
419 | |
429 | tmp2->map = where->map; |
|
|
430 | insert_ob_in_map (tmp2, where->map, NULL, 0); |
|
|
431 | return 1; |
420 | return 1; |
432 | |
|
|
433 | } |
421 | } |
434 | |
|
|
435 | |
422 | |
436 | int |
423 | int |
437 | trap_disarm (object *disarmer, object *trap, int risk, object *skill) |
424 | trap_disarm (object *disarmer, object *trap, int risk, object *skill) |
438 | { |
425 | { |
439 | int trapworth; /* need to compute the experience worth of the trap |
426 | int trapworth; /* need to compute the experience worth of the trap |
… | |
… | |
444 | sqr (MAX (trap->stats.dam, trap->inv ? trap->inv->level : 1)) / skill->level; |
431 | sqr (MAX (trap->stats.dam, trap->inv ? trap->inv->level : 1)) / skill->level; |
445 | |
432 | |
446 | if (!(random_roll (0, (MAX (2, MIN (20, trap->level - skill->level + 5 - disarmer->stats.Dex / 2)) - 1), disarmer, PREFER_LOW))) |
433 | if (!(random_roll (0, (MAX (2, MIN (20, trap->level - skill->level + 5 - disarmer->stats.Dex / 2)) - 1), disarmer, PREFER_LOW))) |
447 | { |
434 | { |
448 | new_draw_info_format (NDI_UNIQUE, 0, disarmer, "You successfully disarm the %s!", &trap->name); |
435 | new_draw_info_format (NDI_UNIQUE, 0, disarmer, "You successfully disarm the %s!", &trap->name); |
449 | destroy_object (trap); |
436 | trap->destroy (1); |
|
|
437 | |
450 | /* If it is your own trap, (or any players trap), don't you don't |
438 | /* If it is your own trap, (or any players trap), don't you don't |
451 | * get exp for it. |
439 | * get exp for it. |
452 | */ |
440 | */ |
453 | if (trap->owner && trap->owner->type != PLAYER && risk) |
441 | if (trap->owner && trap->owner->type != PLAYER && risk) |
454 | return trapworth; |
442 | return trapworth; |