summaryrefslogtreecommitdiffstats
path: root/src/CraftingRecipes.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/CraftingRecipes.cpp87
1 files changed, 86 insertions, 1 deletions
diff --git a/src/CraftingRecipes.cpp b/src/CraftingRecipes.cpp
index fb1a10cca..868182394 100644
--- a/src/CraftingRecipes.cpp
+++ b/src/CraftingRecipes.cpp
@@ -1,4 +1,4 @@
-
+
// CraftingRecipes.cpp
// Interfaces to the cCraftingRecipes class representing the storage of crafting recipes
@@ -762,9 +762,94 @@ cCraftingRecipes::cRecipe * cCraftingRecipes::MatchRecipe(const cItem * a_Crafti
Recipe->m_Ingredients.push_back(*itrS);
}
Recipe->m_Ingredients.insert(Recipe->m_Ingredients.end(), MatchedSlots.begin(), MatchedSlots.end());
+
+ // We use Recipe instead of a_Recipe because we want the wildcard ingredients' slot numbers as well, which was just added previously
+ HandleFireworks(a_CraftingGrid, Recipe.get(), a_GridStride, a_OffsetX, a_OffsetY);
+
return Recipe.release();
}
+
+void cCraftingRecipes::HandleFireworks(const cItem * a_CraftingGrid, cCraftingRecipes::cRecipe * a_Recipe, int a_GridStride, int a_OffsetX, int a_OffsetY)
+{
+ // TODO: add support for more than one dye in the recipe
+ // A manual and temporary solution (listing everything) is in crafting.txt for fade colours, but a programmatic solutions needs to be done for everything else
+
+ if (a_Recipe->m_Result.m_ItemType == E_ITEM_FIREWORK_ROCKET)
+ {
+ for (cRecipeSlots::const_iterator itr = a_Recipe->m_Ingredients.begin(); itr != a_Recipe->m_Ingredients.end(); ++itr)
+ {
+ switch (itr->m_Item.m_ItemType)
+ {
+ case E_ITEM_FIREWORK_STAR:
+ {
+ // Result was a rocket, found a star - copy star data to rocket data
+ int GridID = (itr->x + a_OffsetX) + a_GridStride * (itr->y + a_OffsetY);
+ a_Recipe->m_Result.m_FireworkItem.CopyFrom(a_CraftingGrid[GridID].m_FireworkItem);
+ break;
+ }
+ case E_ITEM_GUNPOWDER:
+ {
+ // Gunpowder - increase flight time
+ a_Recipe->m_Result.m_FireworkItem.m_FlightTimeInTicks += 20;
+ break;
+ }
+ case E_ITEM_PAPER: break;
+ default: LOG("Unexpected item in firework rocket a_Recipe, was the crafting file fireworks section changed?"); break;
+ }
+ }
+ }
+ else if (a_Recipe->m_Result.m_ItemType == E_ITEM_FIREWORK_STAR)
+ {
+ std::vector<int> DyeColours;
+ bool FoundStar = false;
+
+ for (cRecipeSlots::const_iterator itr = a_Recipe->m_Ingredients.begin(); itr != a_Recipe->m_Ingredients.end(); ++itr)
+ {
+ switch (itr->m_Item.m_ItemType)
+ {
+ case E_ITEM_FIREWORK_STAR:
+ {
+ // Result was star, found another star - probably adding fade colours, but copy data over anyhow
+ FoundStar = true;
+ int GridID = (itr->x + a_OffsetX) + a_GridStride * (itr->y + a_OffsetY);
+ a_Recipe->m_Result.m_FireworkItem.CopyFrom(a_CraftingGrid[GridID].m_FireworkItem);
+ break;
+ }
+ case E_ITEM_DYE:
+ {
+ int GridID = (itr->x + a_OffsetX) + a_GridStride * (itr->y + a_OffsetY);
+ DyeColours.push_back(cFireworkItem::GetVanillaColourCodeFromDye(a_CraftingGrid[GridID].m_ItemDamage));
+ break;
+ }
+ case E_ITEM_GUNPOWDER: break;
+ case E_ITEM_DIAMOND: a_Recipe->m_Result.m_FireworkItem.m_HasTrail = true; break;
+ case E_ITEM_GLOWSTONE_DUST: a_Recipe->m_Result.m_FireworkItem.m_HasFlicker = true; break;
+
+ case E_ITEM_FIRE_CHARGE: a_Recipe->m_Result.m_FireworkItem.m_Type = 1; break;
+ case E_ITEM_GOLD_NUGGET: a_Recipe->m_Result.m_FireworkItem.m_Type = 2; break;
+ case E_ITEM_FEATHER: a_Recipe->m_Result.m_FireworkItem.m_Type = 4; break;
+ case E_ITEM_HEAD: a_Recipe->m_Result.m_FireworkItem.m_Type = 3; break;
+ default: LOG("Unexpected item in firework star a_Recipe, was the crafting file fireworks section changed?"); break; // ermahgerd BARD ardmins
+ }
+ }
+
+ if (FoundStar && (!DyeColours.empty()))
+ {
+ // Found a star and a dye? Fade colours.
+ a_Recipe->m_Result.m_FireworkItem.m_FadeColours = DyeColours;
+ }
+ else if (!DyeColours.empty())
+ {
+ // Only dye? Normal colours.
+ a_Recipe->m_Result.m_FireworkItem.m_Colours = DyeColours;
+ }
+ }
+}
+
+
+
+