Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

craft: fix crash in case recipe uses 3 ingredients #658

Merged
merged 1 commit into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions Main/Include/craft.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
#include <ctime>
#include <vector>

static constexpr int ingredient_slot_main = 0;
static constexpr int ingredient_slot_second = 1;
static constexpr int ingredient_slot_thread = 2;
static constexpr int ingredient_slots = 3;

class craft;
class humanoid;
class item;
Expand Down Expand Up @@ -172,9 +177,8 @@ class recipedata {
int iMinTurns;
bool bFailedTerminateCancel;
bool bFailedSuspend;

undoremains urMain;
undoremains urSecond;

undoremains urRemains[ingredient_slots];

/*******************************************
* save REQUIRED fields!!!
Expand Down
17 changes: 7 additions & 10 deletions Main/Source/cmdcraft.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,7 @@
bool bMustBeTailorable=false;
bool bMixRemainingLump=true;
bool bAddEquippedItemsToChoiceList=false;
bool bIsMainIngredient=true; //false if it is secondary ingredient
int iIngredientSlot=ingredient_slot_main;
};
struct recipe{
festring action;
Expand Down Expand Up @@ -1180,9 +1180,9 @@
item* lumpMixed=NULL;
if(CI.bMixRemainingLump)
lumpMixed=lumpMix(vi,lumpR,rpd.bSpendCurrentTurn);
undoremains* pur = CI.bIsMainIngredient ? &rpd.urMain : &rpd.urSecond;
undoremains* pur = &rpd.urRemains[CI.iIngredientSlot];
if(pur->ulUndoRemainsIngredientID!=0)
ABORT("craft remains undo for %s ingredient was already set!",(CI.bIsMainIngredient?"MAIN":"SECOND"));
ABORT("craft remains undo for ingredient %i was already set!", CI.iIngredientSlot + 1);
pur->ulUndoRemainsIngredientID = ToUse[i]->GetID();
pur->ulUndoRemainsLumpID = lumpMixed!=NULL ? lumpMixed->GetID() : lumpR->GetID();
pur->lUndoRemainsVolume = lRemainingVol;
Expand Down Expand Up @@ -2509,7 +2509,7 @@

ci CIS;
CIS.bMainMaterRemainsBecomeLump=true;
CIS.bIsMainIngredient=false;
CIS.iIngredientSlot=ingredient_slot_second;

// some material constraints/limitations
if(dynamic_cast<potion*>(itSpawn)!=NULL){
Expand Down Expand Up @@ -2658,7 +2658,7 @@
CISW.bMainMaterRemainsBecomeLump=true;
CISW.bMixRemainingLump = false;
CISW.iReqMatCfgMain=SPIDER_SILK;
CISW.bIsMainIngredient = false;
CISW.iIngredientSlot=ingredient_slot_thread;
if(!choseIngredients<lump>(cfestring("as sewing material"),lVolSewing,rpd,iSCfg,CISW)){ //TODO instead of <lump> should be <sewingthread> with new graphics
ADD_MESSAGE("You don't have enough sewing thread...");
rpd.SetAlreadyExplained();
Expand Down Expand Up @@ -3142,11 +3142,8 @@
static undoremains* pur;
static item *itIngredient, *itLump;
static material* matM;
for(int i=0;i<2;i++){
switch(i){
case 0: pur=&rpd.urMain;break;
case 1: pur=&rpd.urSecond;break;
}
for(int i=0;i<ingredient_slots;i++){
pur = &rpd.urRemains[i];
bkoropoff marked this conversation as resolved.
Show resolved Hide resolved
DBG6("UndoRemain:Work",i,pur->ulUndoRemainsIngredientID,pur->ulUndoRemainsLumpID,pur->lUndoRemainsVolume,rpd.dbgInfo().CStr());

if(pur->lUndoRemainsVolume==0)
Expand Down
Loading