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.11 by pippijn, Mon Dec 11 19:46:46 2006 UTC vs.
Revision 1.20 by root, Mon Feb 5 02:07:40 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
233 int tval = 0, formula = 0; 232 int tval = 0, formula = 0;
234 233
235 while (tmp) 234 while (tmp)
236 { 235 {
237 tval = 0; 236 tval = 0;
238 strcpy (name, tmp->name); 237 assign (name, tmp->name);
239 if (tmp->title) 238 if (tmp->title)
240 sprintf (name, "%s %s", &tmp->name, &tmp->title); 239 sprintf (name, "%s %s", &tmp->name, &tmp->title);
241 tval = (strtoint (name) * (tmp->nrof ? tmp->nrof : 1)); 240 tval = (strtoint (name) * (tmp->nrof ? tmp->nrof : 1));
242#ifdef ALCHEMY_DEBUG 241#ifdef ALCHEMY_DEBUG
243 LOG (llevDebug, "Got ingredient %d %s(%d)\n", tmp->nrof ? tmp->nrof : 1, name, tval); 242 LOG (llevDebug, "Got ingredient %d %s(%d)\n", tmp->nrof ? tmp->nrof : 1, name, tval);
292 291
293 /* 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 */
294 int batches = abs (nbatches); 293 int batches = abs (nbatches);
295 294
296 295
297 LOG (llevDebug, "A %s <=> %s\n", &(rp->cauldron), &(cauldron->arch->name));
298 /* is the cauldron the right type? */ 296 /* is the cauldron the right type? */
299 if (strcmp (rp->cauldron, cauldron->arch->name) != 0) 297 if (rp->cauldron != cauldron->arch->name)
300 { 298 {
301 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.");
302 return 0; 300 return 0;
303 } 301 }
304 302
310 /* code required for this recipe, search the caster */ 308 /* code required for this recipe, search the caster */
311 if (rp->keycode) 309 if (rp->keycode)
312 { 310 {
313 object *tmp; 311 object *tmp;
314 312
315 for (tmp = caster->inv; tmp != NULL; tmp = tmp->below) 313 for (tmp = caster->inv; tmp; tmp = tmp->below)
316 { 314 {
317 if (tmp->type == FORCE && tmp->slaying && !strcmp (rp->keycode, tmp->slaying)) 315 if (tmp->type == FORCE && tmp->slaying && rp->keycode == tmp->slaying)
318 break; 316 break;
319 } 317 }
318
320 if (tmp == NULL) 319 if (!tmp)
321 { /* failure--no code found */ 320 { /* failure--no code found */
322 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.");
323 return 0; 322 return 0;
324 } 323 }
325 } 324 }
342 /* new_draw_info_format(NDI_UNIQUE, 0,caster, 341 /* new_draw_info_format(NDI_UNIQUE, 0,caster,
343 "Your spell causes the %s to explode!",&cauldron->name); */ 342 "Your spell causes the %s to explode!",&cauldron->name); */
344 /* kaboom_cauldron(); */ 343 /* kaboom_cauldron(); */
345 } 344 }
346 else 345 else
347 {
348 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 ());
349 }
350 } 347 }
348
351 return item; 349 return item;
352} 350}
353 351
354 352
355 353
356/** 354/**
357 * 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
358 * 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.
359 */ 357 */
360 void 358void
361adjust_product (object *item, int lvl, int yield) 359adjust_product (object *item, int lvl, int yield)
362{ 360{
363 int nrof = 1; 361 int nrof = 1;
364 362
365 if (!yield) 363 if (!yield)
366 yield = 1; 364 yield = 1;
365
367 if (lvl <= 0) 366 if (lvl <= 0)
368 lvl = 1; /* lets avoid div by zero! */ 367 lvl = 1; /* lets avoid div by zero! */
368
369 if (item->nrof) 369 if (item->nrof)
370 { 370 {
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); 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
372 if (nrof > yield) 373 if (nrof > yield)
373 nrof = yield; 374 nrof = yield;
375
374 item->nrof = nrof; 376 item->nrof = nrof;
375 } 377 }
376} 378}
377 379
378 380
446 { 448 {
447 size_t i; 449 size_t i;
448 450
449 for (i = 0; i < rp->arch_names; i++) 451 for (i = 0; i < rp->arch_names; i++)
450 { 452 {
451 if (strcmp (item->arch->name, rp->arch_name[i]) == 0) 453 if (item->arch->name == rp->arch_name[i])
452 { 454 {
453 *rp_arch_index = i; 455 *rp_arch_index = i;
454 break; 456 break;
455 } 457 }
456 } 458 }
459
457 if (i < rp->arch_names) 460 if (i < rp->arch_names)
458 break; 461 break;
459 } 462 }
460 463
461 /* failed, create a fresh object. Note no nrof>1 because that would 464 /* failed, create a fresh object. Note no nrof>1 because that would
595 object *tmp; 598 object *tmp;
596 599
597 remove_contents (cauldron->inv, NULL); 600 remove_contents (cauldron->inv, NULL);
598 switch (rndm (0, 2)) 601 switch (rndm (0, 2))
599 { 602 {
600 case 0: 603 case 0:
601 tmp = get_archetype ("bomb"); 604 tmp = get_archetype ("bomb");
602 tmp->stats.dam = random_roll (1, level, op, PREFER_LOW); 605 tmp->stats.dam = random_roll (1, level, op, PREFER_LOW);
603 tmp->stats.hp = random_roll (1, level, op, PREFER_LOW); 606 tmp->stats.hp = random_roll (1, level, op, PREFER_LOW);
604 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s creates a bomb!", &cauldron->name); 607 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s creates a bomb!", &cauldron->name);
605 break; 608 break;
606 609
607 default: 610 default:
608 tmp = get_archetype ("fireball"); 611 tmp = get_archetype ("fireball");
609 tmp->stats.dam = random_roll (1, level, op, PREFER_LOW) / 5 + 1; 612 tmp->stats.dam = random_roll (1, level, op, PREFER_LOW) / 5 + 1;
610 tmp->stats.hp = random_roll (1, level, op, PREFER_LOW) / 10 + 2; 613 tmp->stats.hp = random_roll (1, level, op, PREFER_LOW) / 10 + 2;
611 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s erupts in flame!", &cauldron->name); 614 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s erupts in flame!", &cauldron->name);
612 break; 615 break;
613 } 616 }
614 tmp->x = cauldron->x, tmp->y = cauldron->y; 617
615 insert_ob_in_map (tmp, op->map, NULL, 0); 618 op->insert_at (cauldron);
616 return; 619 return;
617 620
618 } 621 }
619 else if (level < 60) 622 else if (level < 60)
620 { /* CREATE MONSTER */ 623 { /* CREATE MONSTER */
626 { /* MAJOR FIRE */ 629 { /* MAJOR FIRE */
627 object *fb = get_archetype (SP_MED_FIREBALL); 630 object *fb = get_archetype (SP_MED_FIREBALL);
628 631
629 remove_contents (cauldron->inv, NULL); 632 remove_contents (cauldron->inv, NULL);
630 fire_arch_from_position (cauldron, cauldron, cauldron->x, cauldron->y, 0, fb); 633 fire_arch_from_position (cauldron, cauldron, cauldron->x, cauldron->y, 0, fb);
631 free_object (fb); 634 fb->destroy ();
632 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s erupts in flame!", &cauldron->name); 635 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s erupts in flame!", &cauldron->name);
633 return; 636 return;
634 637
635 } 638 }
636 else if (level < 100) 639 else if (level < 100)
704 return; 707 return;
705 } 708 }
706} 709}
707 710
708 711
709/** 712/*
710 * All but object "save_item" are elimentated from 713 * All but object "save_item" are elimentated from
711 * the container list. Note we have to becareful to remove the inventories 714 * the container list. Note we have to becareful to remove the inventories
712 * of objects in the cauldron inventory (ex icecube has stuff in it). 715 * of objects in the cauldron inventory (ex icecube has stuff in it).
713 */ 716 */
714 717
718 object *next, *tmp = first_ob; 721 object *next, *tmp = first_ob;
719 722
720 while (tmp) 723 while (tmp)
721 { 724 {
722 next = tmp->below; 725 next = tmp->below;
726
723 if (tmp == save_item) 727 if (tmp == save_item)
724 { 728 {
725 if (!(tmp = next)) 729 if (!(tmp = next))
726 break; 730 break;
727 else 731 else
728 next = next->below; 732 next = next->below;
729 } 733 }
734
730 if (tmp->inv) 735 if (tmp->inv)
731 remove_contents (tmp->inv, NULL); 736 remove_contents (tmp->inv, NULL);
732 remove_ob (tmp); 737
733 free_object (tmp); 738 tmp->destroy ();
734 tmp = next; 739 tmp = next;
735 } 740 }
736} 741}
737 742
738/** 743/**
766 * Thus the backfire is worse. Also, more ingredients 771 * Thus the backfire is worse. Also, more ingredients
767 * means we are attempting a more powerfull potion, 772 * means we are attempting a more powerfull potion,
768 * and thus the backfire will be worse. */ 773 * and thus the backfire will be worse. */
769 for (item = cauldron->inv; item; item = item->below) 774 for (item = cauldron->inv; item; item = item->below)
770 { 775 {
771 strcpy (name, item->name); 776 assign (name, item->name);
772 if (item->title) 777 if (item->title)
773 sprintf (name, "%s %s", &item->name, &item->title); 778 sprintf (name, "%s %s", &item->name, &item->title);
774 danger += (strtoint (name) / 1000) + 3; 779 danger += (strtoint (name) / 1000) + 3;
775 nrofi++; 780 nrofi++;
776 } 781 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines