ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/server/alchemy.C
(Generate patch)

Comparing deliantra/server/server/alchemy.C (file contents):
Revision 1.9 by root, Fri Sep 15 23:11:57 2006 UTC vs.
Revision 1.18 by pippijn, Mon Jan 15 21:06:19 2007 UTC

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) 2002 Mark Wedel & Crossfire Development Team 5 * Copyright (C) 2002 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/* March 96 - Laid down original code. -b.t. thomas@astro.psu.edu */ 25/* March 96 - Laid down original code. -b.t. thomas@astro.psu.edu */
25 26
26#include <global.h> 27#include <global.h>
27#include <object.h> 28#include <object.h>
28#ifndef __CEXTRACT__
29# include <sproto.h> 29#include <sproto.h>
30#endif
31#include <skills.h> 30#include <skills.h>
32#include <spells.h> 31#include <spells.h>
33 32
34/** define this for some helpful debuging information */ 33/** define this for some helpful debuging information */
35#if 0 34#if 0
194 193
195 value_item = query_cost (item, NULL, F_TRUE | F_IDENTIFIED | F_NOT_CURSED); 194 value_item = query_cost (item, NULL, F_TRUE | F_IDENTIFIED | F_NOT_CURSED);
196 if (attempt_shadow_alchemy && value_item > value_ingredients) 195 if (attempt_shadow_alchemy && value_item > value_ingredients)
197 { 196 {
198#ifdef ALCHEMY_DEBUG 197#ifdef ALCHEMY_DEBUG
199# ifndef WIN32
200 LOG (llevDebug, 198 LOG (llevDebug,
201 "Forcing failure for shadow alchemy recipe because price of ingredients (%llu) is less than price of result (%llu).\n", 199 "Forcing failure for shadow alchemy recipe because price of ingredients (%llu) is less than price of result (%llu).\n",
202 value_ingredients, value_item); 200 value_ingredients, value_item);
203# else
204 LOG (llevDebug,
205 "Forcing failure for shadow alchemy recipe because price of ingredients (%I64d) is less than price of result (%I64d).\n",
206 value_ingredients, value_item);
207# endif
208#endif 201#endif
209 } 202 }
210 /* roll the dice */ 203 /* roll the dice */
211 else if ((float) (random_roll (0, 101, caster, PREFER_LOW)) <= 100.0 * success_chance) 204 else if ((float) (random_roll (0, 101, caster, PREFER_LOW)) <= 100.0 * success_chance)
212 { 205 {
213 change_exp (caster, rp->exp, rp->skill, SK_EXP_NONE); 206 change_exp (caster, rp->exp, rp->skill, SK_EXP_NONE);
207
208 // let alchemy consume some time, so that exploits are less easy
209 caster->speed_left -= 1.0;
210
214 return; 211 return;
215 } 212 }
216 } 213 }
217 } 214 }
218 } 215 }
216
219 /* if we get here, we failed!! */ 217 /* if we get here, we failed!! */
220 alchemy_failure_effect (caster, cauldron, rp, calc_alch_danger (caster, cauldron, rp)); 218 alchemy_failure_effect (caster, cauldron, rp, calc_alch_danger (caster, cauldron, rp));
221} 219}
222 220
223/** 221/**
293 291
294 /* this should be passed to this fctn, not effiecent cpu use this way */ 292 /* this should be passed to this fctn, not effiecent cpu use this way */
295 int batches = abs (nbatches); 293 int batches = abs (nbatches);
296 294
297 295
298 LOG (llevDebug, "A %s <=> %s\n", &(rp->cauldron), &(cauldron->arch->name));
299 /* is the cauldron the right type? */ 296 /* is the cauldron the right type? */
300 if (strcmp (rp->cauldron, cauldron->arch->name) != 0) 297 if (strcmp (rp->cauldron, cauldron->arch->name) != 0)
301 { 298 {
302 new_draw_info (NDI_UNIQUE, 0, caster, "You are not using the proper" " facilities for this formula."); 299 new_draw_info (NDI_UNIQUE, 0, caster, "You are not using the proper" " facilities for this formula.");
303 return 0; 300 return 0;
311 /* code required for this recipe, search the caster */ 308 /* code required for this recipe, search the caster */
312 if (rp->keycode) 309 if (rp->keycode)
313 { 310 {
314 object *tmp; 311 object *tmp;
315 312
316 for (tmp = caster->inv; tmp != NULL; tmp = tmp->below) 313 for (tmp = caster->inv; tmp; tmp = tmp->below)
317 { 314 {
318 if (tmp->type == FORCE && tmp->slaying && !strcmp (rp->keycode, tmp->slaying)) 315 if (tmp->type == FORCE && tmp->slaying && !strcmp (rp->keycode, tmp->slaying))
319 break; 316 break;
320 } 317 }
318
321 if (tmp == NULL) 319 if (!tmp)
322 { /* failure--no code found */ 320 { /* failure--no code found */
323 new_draw_info (NDI_UNIQUE, 0, caster, "You know the ingredients," " but not the technique. Go learn how to do this recipe."); 321 new_draw_info (NDI_UNIQUE, 0, caster, "You know the ingredients," " but not the technique. Go learn how to do this recipe.");
324 return 0; 322 return 0;
325 } 323 }
326 } 324 }
343 /* new_draw_info_format(NDI_UNIQUE, 0,caster, 341 /* new_draw_info_format(NDI_UNIQUE, 0,caster,
344 "Your spell causes the %s to explode!",&cauldron->name); */ 342 "Your spell causes the %s to explode!",&cauldron->name); */
345 /* kaboom_cauldron(); */ 343 /* kaboom_cauldron(); */
346 } 344 }
347 else 345 else
348 {
349 new_draw_info_format (NDI_UNIQUE, 0, caster, "The %s %s.", &cauldron->name, cauldron_sound ()); 346 new_draw_info_format (NDI_UNIQUE, 0, caster, "The %s %s.", &cauldron->name, cauldron_sound ());
350 }
351 } 347 }
348
352 return item; 349 return item;
353} 350}
354 351
355 352
356 353
357/** 354/**
358 * We adjust the nrof, exp and level of the final product, based 355 * We adjust the nrof, exp and level of the final product, based
359 * on the item's default parameters, and the relevant caster skill level. 356 * on the item's default parameters, and the relevant caster skill level.
360 */ 357 */
361 void 358void
362adjust_product (object *item, int lvl, int yield) 359adjust_product (object *item, int lvl, int yield)
363{ 360{
364 int nrof = 1; 361 int nrof = 1;
365 362
366 if (!yield) 363 if (!yield)
367 yield = 1; 364 yield = 1;
365
368 if (lvl <= 0) 366 if (lvl <= 0)
369 lvl = 1; /* lets avoid div by zero! */ 367 lvl = 1; /* lets avoid div by zero! */
368
370 if (item->nrof) 369 if (item->nrof)
371 { 370 {
372 nrof = (int) ((1.0 - 1.0 / (lvl / 10.0 + 1.0)) * (rndm (0, yield - 1) + rndm (0, yield - 1) + rndm (0, yield - 1)) + 1); 371 nrof = (int) ((1.0 - 1.0 / (lvl / 10.0 + 1.0)) * (rndm (0, yield - 1) + rndm (0, yield - 1) + rndm (0, yield - 1)) + 1);
372
373 if (nrof > yield) 373 if (nrof > yield)
374 nrof = yield; 374 nrof = yield;
375
375 item->nrof = nrof; 376 item->nrof = nrof;
376 } 377 }
377} 378}
378 379
379 380
596 object *tmp; 597 object *tmp;
597 598
598 remove_contents (cauldron->inv, NULL); 599 remove_contents (cauldron->inv, NULL);
599 switch (rndm (0, 2)) 600 switch (rndm (0, 2))
600 { 601 {
601 case 0: 602 case 0:
602 tmp = get_archetype ("bomb"); 603 tmp = get_archetype ("bomb");
603 tmp->stats.dam = random_roll (1, level, op, PREFER_LOW); 604 tmp->stats.dam = random_roll (1, level, op, PREFER_LOW);
604 tmp->stats.hp = random_roll (1, level, op, PREFER_LOW); 605 tmp->stats.hp = random_roll (1, level, op, PREFER_LOW);
605 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s creates a bomb!", &cauldron->name); 606 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s creates a bomb!", &cauldron->name);
606 break; 607 break;
607 608
608 default: 609 default:
609 tmp = get_archetype ("fireball"); 610 tmp = get_archetype ("fireball");
610 tmp->stats.dam = random_roll (1, level, op, PREFER_LOW) / 5 + 1; 611 tmp->stats.dam = random_roll (1, level, op, PREFER_LOW) / 5 + 1;
611 tmp->stats.hp = random_roll (1, level, op, PREFER_LOW) / 10 + 2; 612 tmp->stats.hp = random_roll (1, level, op, PREFER_LOW) / 10 + 2;
612 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s erupts in flame!", &cauldron->name); 613 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s erupts in flame!", &cauldron->name);
613 break; 614 break;
614 } 615 }
615 tmp->x = cauldron->x, tmp->y = cauldron->y; 616
616 insert_ob_in_map (tmp, op->map, NULL, 0); 617 op->insert_at (cauldron);
617 return; 618 return;
618 619
619 } 620 }
620 else if (level < 60) 621 else if (level < 60)
621 { /* CREATE MONSTER */ 622 { /* CREATE MONSTER */
627 { /* MAJOR FIRE */ 628 { /* MAJOR FIRE */
628 object *fb = get_archetype (SP_MED_FIREBALL); 629 object *fb = get_archetype (SP_MED_FIREBALL);
629 630
630 remove_contents (cauldron->inv, NULL); 631 remove_contents (cauldron->inv, NULL);
631 fire_arch_from_position (cauldron, cauldron, cauldron->x, cauldron->y, 0, fb); 632 fire_arch_from_position (cauldron, cauldron, cauldron->x, cauldron->y, 0, fb);
632 free_object (fb); 633 fb->destroy ();
633 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s erupts in flame!", &cauldron->name); 634 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s erupts in flame!", &cauldron->name);
634 return; 635 return;
635 636
636 } 637 }
637 else if (level < 100) 638 else if (level < 100)
705 return; 706 return;
706 } 707 }
707} 708}
708 709
709 710
710/** 711/*
711 * All but object "save_item" are elimentated from 712 * All but object "save_item" are elimentated from
712 * the container list. Note we have to becareful to remove the inventories 713 * the container list. Note we have to becareful to remove the inventories
713 * of objects in the cauldron inventory (ex icecube has stuff in it). 714 * of objects in the cauldron inventory (ex icecube has stuff in it).
714 */ 715 */
715 716
719 object *next, *tmp = first_ob; 720 object *next, *tmp = first_ob;
720 721
721 while (tmp) 722 while (tmp)
722 { 723 {
723 next = tmp->below; 724 next = tmp->below;
725
724 if (tmp == save_item) 726 if (tmp == save_item)
725 { 727 {
726 if (!(tmp = next)) 728 if (!(tmp = next))
727 break; 729 break;
728 else 730 else
729 next = next->below; 731 next = next->below;
730 } 732 }
733
731 if (tmp->inv) 734 if (tmp->inv)
732 remove_contents (tmp->inv, NULL); 735 remove_contents (tmp->inv, NULL);
733 remove_ob (tmp); 736
734 free_object (tmp); 737 tmp->destroy ();
735 tmp = next; 738 tmp = next;
736 } 739 }
737} 740}
738 741
739/** 742/**

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines