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.7 by root, Sun Sep 10 15:59:57 2006 UTC vs.
Revision 1.20 by root, Mon Feb 5 02:07:40 2007 UTC

1
2/* 1/*
3 * static char *rcsid_alchemy_c =
4 * "$Id: alchemy.C,v 1.7 2006/09/10 15:59:57 root Exp $";
5 */
6
7/*
8 CrossFire, A Multiplayer game for X-windows 2 * CrossFire, A Multiplayer game for X-windows
9 3 *
4 * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team
10 Copyright (C) 2002 Mark Wedel & Crossfire Development Team 5 * Copyright (C) 2002 Mark Wedel & Crossfire Development Team
11 Copyright (C) 1992 Frank Tore Johansen 6 * Copyright (C) 1992 Frank Tore Johansen
12 7 *
13 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
14 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
15 the Free Software Foundation; either version 2 of the License, or 10 * the Free Software Foundation; either version 2 of the License, or
16 (at your option) any later version. 11 * (at your option) any later version.
17 12 *
18 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,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details. 16 * GNU General Public License for more details.
22 17 *
23 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
24 along with this program; if not, write to the Free Software 19 * along with this program; if not, write to the Free Software
25 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 21 *
27 The authors can be reached via e-mail at crossfire-devel@real-time.com 22 * The authors can be reached via e-mail at <crossfire@schmorp.de>
28*/ 23 */
29 24
30/* 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 */
31 26
32#include <global.h> 27#include <global.h>
33#include <object.h> 28#include <object.h>
34#ifndef __CEXTRACT__
35# include <sproto.h> 29#include <sproto.h>
36#endif
37#include <skills.h> 30#include <skills.h>
38#include <spells.h> 31#include <spells.h>
39 32
40/** define this for some helpful debuging information */ 33/** define this for some helpful debuging information */
41#if 0 34#if 0
161 /* the caster gets an increase in ability based on thier skill lvl */ 154 /* the caster gets an increase in ability based on thier skill lvl */
162 if (rp->skill) 155 if (rp->skill)
163 { 156 {
164 skop = find_skill_by_name (caster, rp->skill); 157 skop = find_skill_by_name (caster, rp->skill);
165 if (!skop) 158 if (!skop)
166 {
167 new_draw_info (NDI_UNIQUE, 0, caster, "You do not have the proper skill for this recipe"); 159 new_draw_info (NDI_UNIQUE, 0, caster, "You do not have the proper skill for this recipe");
168 }
169 else 160 else
170 {
171 ability += (int) (skop->level * ((4.0 + cauldron->magic) / 4.0)); 161 ability += (int) (skop->level * ((4.0 + cauldron->magic) / 4.0));
172 }
173 } 162 }
174 else 163 else
175 { 164 {
176 LOG (llevDebug, "Recipe %s has NULL skill!\n", &rp->title); 165 LOG (llevDebug, "Recipe %s has NULL skill!\n", &rp->title);
177 return; 166 return;
178 } 167 }
179 168
180 if (rp->cauldron) 169 if (!rp->cauldron)
181 { 170 {
182 LOG (llevDebug, "Recipe %s has NULL cauldron!\n", &rp->title); 171 LOG (llevDebug, "Recipe %s has NULL cauldron!\n", &rp->title);
183 return; 172 return;
184 } 173 }
185 174
204 193
205 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);
206 if (attempt_shadow_alchemy && value_item > value_ingredients) 195 if (attempt_shadow_alchemy && value_item > value_ingredients)
207 { 196 {
208#ifdef ALCHEMY_DEBUG 197#ifdef ALCHEMY_DEBUG
209# ifndef WIN32
210 LOG (llevDebug, 198 LOG (llevDebug,
211 "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",
212 value_ingredients, value_item); 200 value_ingredients, value_item);
213# else
214 LOG (llevDebug,
215 "Forcing failure for shadow alchemy recipe because price of ingredients (%I64d) is less than price of result (%I64d).\n",
216 value_ingredients, value_item);
217# endif
218#endif 201#endif
219 } 202 }
220 /* roll the dice */ 203 /* roll the dice */
221 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)
222 { 205 {
223 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
224 return; 211 return;
225 } 212 }
226 } 213 }
227 } 214 }
228 } 215 }
216
229 /* if we get here, we failed!! */ 217 /* if we get here, we failed!! */
230 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));
231} 219}
232 220
233/** 221/**
244 int tval = 0, formula = 0; 232 int tval = 0, formula = 0;
245 233
246 while (tmp) 234 while (tmp)
247 { 235 {
248 tval = 0; 236 tval = 0;
249 strcpy (name, tmp->name); 237 assign (name, tmp->name);
250 if (tmp->title) 238 if (tmp->title)
251 sprintf (name, "%s %s", &tmp->name, &tmp->title); 239 sprintf (name, "%s %s", &tmp->name, &tmp->title);
252 tval = (strtoint (name) * (tmp->nrof ? tmp->nrof : 1)); 240 tval = (strtoint (name) * (tmp->nrof ? tmp->nrof : 1));
253#ifdef ALCHEMY_DEBUG 241#ifdef ALCHEMY_DEBUG
254 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);
303 291
304 /* 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 */
305 int batches = abs (nbatches); 293 int batches = abs (nbatches);
306 294
307 295
308 LOG (llevDebug, "A %s <=> %s\n", &(rp->cauldron), &(cauldron->arch->name));
309 /* is the cauldron the right type? */ 296 /* is the cauldron the right type? */
310 if (strcmp (rp->cauldron, cauldron->arch->name) != 0) 297 if (rp->cauldron != cauldron->arch->name)
311 { 298 {
312 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.");
313 return 0; 300 return 0;
314 } 301 }
315 302
321 /* code required for this recipe, search the caster */ 308 /* code required for this recipe, search the caster */
322 if (rp->keycode) 309 if (rp->keycode)
323 { 310 {
324 object *tmp; 311 object *tmp;
325 312
326 for (tmp = caster->inv; tmp != NULL; tmp = tmp->below) 313 for (tmp = caster->inv; tmp; tmp = tmp->below)
327 { 314 {
328 if (tmp->type == FORCE && tmp->slaying && !strcmp (rp->keycode, tmp->slaying)) 315 if (tmp->type == FORCE && tmp->slaying && rp->keycode == tmp->slaying)
329 break; 316 break;
330 } 317 }
318
331 if (tmp == NULL) 319 if (!tmp)
332 { /* failure--no code found */ 320 { /* failure--no code found */
333 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.");
334 return 0; 322 return 0;
335 } 323 }
336 } 324 }
353 /* new_draw_info_format(NDI_UNIQUE, 0,caster, 341 /* new_draw_info_format(NDI_UNIQUE, 0,caster,
354 "Your spell causes the %s to explode!",&cauldron->name); */ 342 "Your spell causes the %s to explode!",&cauldron->name); */
355 /* kaboom_cauldron(); */ 343 /* kaboom_cauldron(); */
356 } 344 }
357 else 345 else
358 {
359 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 ());
360 }
361 } 347 }
348
362 return item; 349 return item;
363} 350}
364 351
365 352
366 353
367/** 354/**
368 * 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
369 * 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.
370 */ 357 */
371 void 358void
372adjust_product (object *item, int lvl, int yield) 359adjust_product (object *item, int lvl, int yield)
373{ 360{
374 int nrof = 1; 361 int nrof = 1;
375 362
376 if (!yield) 363 if (!yield)
377 yield = 1; 364 yield = 1;
365
378 if (lvl <= 0) 366 if (lvl <= 0)
379 lvl = 1; /* lets avoid div by zero! */ 367 lvl = 1; /* lets avoid div by zero! */
368
380 if (item->nrof) 369 if (item->nrof)
381 { 370 {
382 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
383 if (nrof > yield) 373 if (nrof > yield)
384 nrof = yield; 374 nrof = yield;
375
385 item->nrof = nrof; 376 item->nrof = nrof;
386 } 377 }
387} 378}
388 379
389 380
457 { 448 {
458 size_t i; 449 size_t i;
459 450
460 for (i = 0; i < rp->arch_names; i++) 451 for (i = 0; i < rp->arch_names; i++)
461 { 452 {
462 if (strcmp (item->arch->name, rp->arch_name[i]) == 0) 453 if (item->arch->name == rp->arch_name[i])
463 { 454 {
464 *rp_arch_index = i; 455 *rp_arch_index = i;
465 break; 456 break;
466 } 457 }
467 } 458 }
459
468 if (i < rp->arch_names) 460 if (i < rp->arch_names)
469 break; 461 break;
470 } 462 }
471 463
472 /* 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
606 object *tmp; 598 object *tmp;
607 599
608 remove_contents (cauldron->inv, NULL); 600 remove_contents (cauldron->inv, NULL);
609 switch (rndm (0, 2)) 601 switch (rndm (0, 2))
610 { 602 {
611 case 0: 603 case 0:
612 tmp = get_archetype ("bomb"); 604 tmp = get_archetype ("bomb");
613 tmp->stats.dam = random_roll (1, level, op, PREFER_LOW); 605 tmp->stats.dam = random_roll (1, level, op, PREFER_LOW);
614 tmp->stats.hp = random_roll (1, level, op, PREFER_LOW); 606 tmp->stats.hp = random_roll (1, level, op, PREFER_LOW);
615 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);
616 break; 608 break;
617 609
618 default: 610 default:
619 tmp = get_archetype ("fireball"); 611 tmp = get_archetype ("fireball");
620 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;
621 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;
622 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);
623 break; 615 break;
624 } 616 }
625 tmp->x = cauldron->x, tmp->y = cauldron->y; 617
626 insert_ob_in_map (tmp, op->map, NULL, 0); 618 op->insert_at (cauldron);
627 return; 619 return;
628 620
629 } 621 }
630 else if (level < 60) 622 else if (level < 60)
631 { /* CREATE MONSTER */ 623 { /* CREATE MONSTER */
637 { /* MAJOR FIRE */ 629 { /* MAJOR FIRE */
638 object *fb = get_archetype (SP_MED_FIREBALL); 630 object *fb = get_archetype (SP_MED_FIREBALL);
639 631
640 remove_contents (cauldron->inv, NULL); 632 remove_contents (cauldron->inv, NULL);
641 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);
642 free_object (fb); 634 fb->destroy ();
643 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);
644 return; 636 return;
645 637
646 } 638 }
647 else if (level < 100) 639 else if (level < 100)
715 return; 707 return;
716 } 708 }
717} 709}
718 710
719 711
720/** 712/*
721 * All but object "save_item" are elimentated from 713 * All but object "save_item" are elimentated from
722 * 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
723 * 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).
724 */ 716 */
725 717
729 object *next, *tmp = first_ob; 721 object *next, *tmp = first_ob;
730 722
731 while (tmp) 723 while (tmp)
732 { 724 {
733 next = tmp->below; 725 next = tmp->below;
726
734 if (tmp == save_item) 727 if (tmp == save_item)
735 { 728 {
736 if (!(tmp = next)) 729 if (!(tmp = next))
737 break; 730 break;
738 else 731 else
739 next = next->below; 732 next = next->below;
740 } 733 }
734
741 if (tmp->inv) 735 if (tmp->inv)
742 remove_contents (tmp->inv, NULL); 736 remove_contents (tmp->inv, NULL);
743 remove_ob (tmp); 737
744 free_object (tmp); 738 tmp->destroy ();
745 tmp = next; 739 tmp = next;
746 } 740 }
747} 741}
748 742
749/** 743/**
777 * Thus the backfire is worse. Also, more ingredients 771 * Thus the backfire is worse. Also, more ingredients
778 * means we are attempting a more powerfull potion, 772 * means we are attempting a more powerfull potion,
779 * and thus the backfire will be worse. */ 773 * and thus the backfire will be worse. */
780 for (item = cauldron->inv; item; item = item->below) 774 for (item = cauldron->inv; item; item = item->below)
781 { 775 {
782 strcpy (name, item->name); 776 assign (name, item->name);
783 if (item->title) 777 if (item->title)
784 sprintf (name, "%s %s", &item->name, &item->title); 778 sprintf (name, "%s %s", &item->name, &item->title);
785 danger += (strtoint (name) / 1000) + 3; 779 danger += (strtoint (name) / 1000) + 3;
786 nrofi++; 780 nrofi++;
787 } 781 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines