… | |
… | |
416 | * @param rp_arch_index pointer to return value; set to arch index for recipe; |
416 | * @param rp_arch_index pointer to return value; set to arch index for recipe; |
417 | * set to zero if not using a transmution formula |
417 | * set to zero if not using a transmution formula |
418 | */ |
418 | */ |
419 | |
419 | |
420 | object * |
420 | object * |
421 | find_transmution_ob (object *first_ingred, recipe *rp, size_t * rp_arch_index, int create_item) |
421 | find_transmution_ob (object *first_ingred, recipe *rp, size_t *rp_arch_index, int create_item) |
422 | { |
422 | { |
423 | object *item = NULL; |
423 | object *prod_item = 0; |
424 | |
424 | bool found = false; |
425 | *rp_arch_index = 0; |
425 | *rp_arch_index = 0; |
426 | |
426 | |
427 | if (rp->transmute) /* look for matching ingredient/prod archs */ |
427 | if (rp->transmute) /* look for matching ingredient/prod archs */ |
428 | for (item = first_ingred; item; item = item->below) |
428 | for (object *item = first_ingred; item; item = item->below) |
429 | { |
429 | { |
430 | int i; |
|
|
431 | |
|
|
432 | for (int i = 0; i < rp->arch_names; i++) |
430 | for (int i = 0; i < rp->arch_names; i++) |
433 | //TODO: should be a shstr comparison |
431 | //TODO: should be a shstr comparison |
434 | if (&item->arch->archname == rp->arch_name[i]) |
432 | if (&item->arch->archname == rp->arch_name[i]) |
435 | { |
433 | { |
436 | *rp_arch_index = i; |
434 | *rp_arch_index = i; |
|
|
435 | prod_item = item; |
437 | break; |
436 | break; |
438 | } |
437 | } |
439 | |
438 | |
440 | if (i < rp->arch_names) |
439 | if (prod_item) |
441 | break; |
440 | break; |
442 | } |
441 | } |
443 | |
442 | |
444 | /* failed, create a fresh object. Note no nrof>1 because that would |
443 | /* failed, create a fresh object. Note no nrof>1 because that would |
445 | * allow players to create massive amounts of artifacts easily */ |
444 | * allow players to create massive amounts of artifacts easily */ |
446 | if (create_item && (!item || item->nrof > 1)) |
445 | if (create_item && (!prod_item || prod_item->nrof > 1)) |
447 | { |
446 | { |
448 | *rp_arch_index = rndm (rp->arch_names); |
447 | *rp_arch_index = rndm (rp->arch_names); |
449 | item = get_archetype (rp->arch_name[*rp_arch_index]); |
448 | prod_item = get_archetype (rp->arch_name[*rp_arch_index]); |
450 | } |
449 | } |
451 | |
450 | |
452 | #ifdef ALCHEMY_DEBUG |
451 | #ifdef ALCHEMY_DEBUG |
453 | LOG (llevDebug, "recipe calls for%stransmution.\n", rp->transmute ? " " : " no "); |
452 | LOG (llevDebug, "recipe calls for%stransmution.\n", rp->transmute ? " " : " no "); |
454 | if (item != NULL) |
453 | if (prod_item != NULL) |
455 | { |
454 | { |
456 | LOG (llevDebug, " find_transmutable_ob(): returns arch %s(sp:%d)\n", item->arch->name, item->stats.sp); |
455 | LOG (llevDebug, " find_transmutable_ob(): returns arch %s(sp:%d)\n", |
|
|
456 | prod_item->arch->name, prod_item->stats.sp); |
457 | } |
457 | } |
458 | #endif |
458 | #endif |
459 | |
459 | |
460 | return item; |
460 | return prod_item; |
461 | } |
461 | } |
462 | |
462 | |
463 | |
463 | |
464 | /**
|
464 | /**
|
465 | * Ouch. We didnt get the formula we wanted. |
465 | * Ouch. We didnt get the formula we wanted. |