Sfoglia il codice sorgente

Stack artifact backup.
Still doesn't serialize properly, though.

DjWarmonger 13 anni fa
parent
commit
9e5fcc3152

+ 10 - 1
client/CCreatureWindow.cpp

@@ -19,6 +19,7 @@
 #include "../lib/CGameState.h"
 #include "../lib/CGameState.h"
 #include "../lib/BattleState.h"
 #include "../lib/BattleState.h"
 #include "../lib/CSpellHandler.h"
 #include "../lib/CSpellHandler.h"
+#include "../lib/CArtHandler.h"
 
 
 #include "UIFramework/CGuiHandler.h"
 #include "UIFramework/CGuiHandler.h"
 #include "UIFramework/CIntObjectClasses.h"
 #include "UIFramework/CIntObjectClasses.h"
@@ -26,6 +27,7 @@
 using namespace CSDL_Ext;
 using namespace CSDL_Ext;
 
 
 class CBonusItem;
 class CBonusItem;
+class CCreatureArtifactInstance;
 
 
 /*
 /*
  * CCreatureWindow.cpp, part of VCMI engine
  * CCreatureWindow.cpp, part of VCMI engine
@@ -260,7 +262,7 @@ void CCreatureWindow::init(const CStackInstance *Stack, const CBonusSystemNode *
 				if (heroOwner)
 				if (heroOwner)
 					passArtToHero = new CAdventureMapButton(std::string(), std::string(), boost::bind (&CCreatureWindow::scrollArt, this, 0), 437, 148, "OVBUTN1.DEF", SDLK_HOME);
 					passArtToHero = new CAdventureMapButton(std::string(), std::string(), boost::bind (&CCreatureWindow::scrollArt, this, 0), 437, 148, "OVBUTN1.DEF", SDLK_HOME);
 			}
 			}
-			if (ConstTransitivePtr<CArtifactInstance> art = stack->activeArtifact.artifact)
+			if (const CArtifactInstance * art = stack->getArt(GameConstants::CREATURE_ART))
 				blitAt(graphics->artDefs->ourImages[art->id].bitmap, 466, 161, *bitmap);
 				blitAt(graphics->artDefs->ourImages[art->id].bitmap, 466, 161, *bitmap);
 		}
 		}
 		else
 		else
@@ -393,6 +395,13 @@ void CCreatureWindow::sliderMoved(int newpos)
 
 
 void CCreatureWindow::scrollArt(int dir)
 void CCreatureWindow::scrollArt(int dir)
 {
 {
+	//TODO: get next artifact
+	creatureArtifact = const_cast<CArtifactInstance*>(stack->getArt(GameConstants::CREATURE_ART));
+}
+
+void CCreatureWindow::passArtifactToHero()
+{
+	creatureArtifact->artType;
 }
 }
 
 
 void CCreatureWindow::clickRight(tribool down, bool previousState)
 void CCreatureWindow::clickRight(tribool down, bool previousState)

+ 9 - 9
client/CCreatureWindow.h

@@ -18,6 +18,7 @@ struct Bonus;
 class CCreature;
 class CCreature;
 class CStackInstance;
 class CStackInstance;
 class CStack;
 class CStack;
+class CCreatureArtifactInstance;
 class CAdventureMapButton;
 class CAdventureMapButton;
 class CBonusItem;
 class CBonusItem;
 class CGHeroInstance;
 class CGHeroInstance;
@@ -29,12 +30,11 @@ struct UpgradeInfo;
 class CPicture;
 class CPicture;
 class CCreaturePic;
 class CCreaturePic;
 class LRClickableAreaWTextComp;
 class LRClickableAreaWTextComp;
-class CArtPlace;
 class CSlider;
 class CSlider;
 class CLabel;
 class CLabel;
 class CAnimImage;
 class CAnimImage;
 
 
-// Classical creature window
+// New creature window
 class CCreatureWindow : public CIntObject
 class CCreatureWindow : public CIntObject
 {
 {
 public:
 public:
@@ -48,6 +48,7 @@ public:
 	const CStackInstance *stack;
 	const CStackInstance *stack;
 	const CBonusSystemNode *stackNode;
 	const CBonusSystemNode *stackNode;
 	const CGHeroInstance *heroOwner;
 	const CGHeroInstance *heroOwner;
+	CArtifactInstance *creatureArtifact; //currently worn artifact
 	std::vector<CComponent*> upgResCost; //cost of upgrade (if not possible then empty)
 	std::vector<CComponent*> upgResCost; //cost of upgrade (if not possible then empty)
 	std::vector<CBonusItem*> bonusItems;
 	std::vector<CBonusItem*> bonusItems;
 	std::vector<LRClickableAreaWText*> spellEffects;
 	std::vector<LRClickableAreaWText*> spellEffects;
@@ -56,7 +57,6 @@ public:
 	CCreaturePic *anim; //related creature's animation
 	CCreaturePic *anim; //related creature's animation
 	MoraleLuckBox *luck, *morale;
 	MoraleLuckBox *luck, *morale;
 	LRClickableAreaWTextComp * expArea; //displays exp details
 	LRClickableAreaWTextComp * expArea; //displays exp details
-	CArtPlace *creatureArtifact;
 	CSlider * slider; //Abilities
 	CSlider * slider; //Abilities
 	CAdventureMapButton *dismiss, *upgrade, *ok;
 	CAdventureMapButton *dismiss, *upgrade, *ok;
 	CAdventureMapButton * leftArtRoll, * rightArtRoll; //artifact selection
 	CAdventureMapButton * leftArtRoll, * rightArtRoll; //artifact selection
@@ -69,19 +69,19 @@ public:
 	CCreatureWindow (const CStackInstance &stack, int Type); //pop-up c-tor
 	CCreatureWindow (const CStackInstance &stack, int Type); //pop-up c-tor
 	CCreatureWindow(const CStackInstance &st, int Type, boost::function<void()> Upg, boost::function<void()> Dsm, UpgradeInfo *ui); //full garrison window
 	CCreatureWindow(const CStackInstance &st, int Type, boost::function<void()> Upg, boost::function<void()> Dsm, UpgradeInfo *ui); //full garrison window
 	CCreatureWindow(int Cid, int Type, int creatureCount); //c-tor
 	CCreatureWindow(int Cid, int Type, int creatureCount); //c-tor
+
 	void init(const CStackInstance *stack, const CBonusSystemNode *stackNode, const CGHeroInstance *heroOwner);
 	void init(const CStackInstance *stack, const CBonusSystemNode *stackNode, const CGHeroInstance *heroOwner);
 	void showAll(SDL_Surface * to);
 	void showAll(SDL_Surface * to);
 	void show(SDL_Surface * to);
 	void show(SDL_Surface * to);
 	void printLine(int nr, const std::string &text, int baseVal, int val=-1, bool range=false);
 	void printLine(int nr, const std::string &text, int baseVal, int val=-1, bool range=false);
-	void recreateSkillList(int pos);
-	~CCreatureWindow(); //d-tor
-	//void activate();
-	//void deactivate();
 	void close();
 	void close();
 	void clickRight(tribool down, bool previousState); //call-in
 	void clickRight(tribool down, bool previousState); //call-in
 	void sliderMoved(int newpos);
 	void sliderMoved(int newpos);
-	//void keyPressed (const SDL_KeyboardEvent & key); //call-in
+	~CCreatureWindow(); //d-tor
+
+	void recreateSkillList(int pos);
 	void scrollArt(int dir);
 	void scrollArt(int dir);
+	void passArtifactToHero();
 };
 };
 
 
 class CBonusItem : public LRClickableAreaWTextComp //responsible for displaying creature skill, active or not
 class CBonusItem : public LRClickableAreaWTextComp //responsible for displaying creature skill, active or not
@@ -99,7 +99,7 @@ public:
 	void showAll (SDL_Surface * to);
 	void showAll (SDL_Surface * to);
 };
 };
 
 
-/// New Creature info window
+/// original creature info window
 class CCreInfoWindow : public CIntObject
 class CCreInfoWindow : public CIntObject
 {
 {
 public:
 public:

+ 9 - 0
lib/CArtHandler.cpp

@@ -738,6 +738,15 @@ void CArtHandler::addBonuses()
 	giveArtBonus(140, Bonus::GENERATE_RESOURCE, +4, Res::SULFUR);
 	giveArtBonus(140, Bonus::GENERATE_RESOURCE, +4, Res::SULFUR);
 	giveArtBonus(140, Bonus::GENERATE_RESOURCE, +4, Res::CRYSTAL);
 	giveArtBonus(140, Bonus::GENERATE_RESOURCE, +4, Res::CRYSTAL);
 	giveArtBonus(140, Bonus::GENERATE_RESOURCE, +4, Res::GEMS);
 	giveArtBonus(140, Bonus::GENERATE_RESOURCE, +4, Res::GEMS);
+
+	//Stack artifact test
+	if (GameConstants::STACK_ARTIFACT)
+	{
+		giveArtBonus(141, Bonus::STACK_HEALTH, +400, -1, Bonus::PERCENT_TO_BASE); //Magic Wans
+		giveArtBonus(142, Bonus::STACK_HEALTH, +400, -1, Bonus::PERCENT_TO_BASE); //Tower Arrow
+		giveArtBonus(143, Bonus::STACK_HEALTH, +400, -1, Bonus::PERCENT_TO_BASE); //Monster's Power
+		giveArtBonus(156, Bonus::STACK_HEALTH, +2); //Warlord's banner
+	}
 }
 }
 
 
 void CArtHandler::clear()
 void CArtHandler::clear()

+ 2 - 2
lib/CArtHandler.h

@@ -171,7 +171,7 @@ public:
 	template <typename Handler> void serialize(Handler &h, const int version)
 	template <typename Handler> void serialize(Handler &h, const int version)
 	{
 	{
 		h & static_cast<CArtifactInstance&>(*this);
 		h & static_cast<CArtifactInstance&>(*this);
-		BONUS_TREE_DESERIALIZATION_FIX
+		//BONUS_TREE_DESERIALIZATION_FIX
 	}
 	}
 };
 };
 
 
@@ -329,7 +329,7 @@ class DLL_LINKAGE CCreatureArtifactSet : public IArtifactSetBase
 { ///creature artifacts
 { ///creature artifacts
 public:
 public:
 	std::vector<ArtSlotInfo> artifactsInBackpack; //artifacts carried by creature - 4 max (according to WoG)
 	std::vector<ArtSlotInfo> artifactsInBackpack; //artifacts carried by creature - 4 max (according to WoG)
-	ArtSlotInfo activeArtifact; //position 0 - Arts::CREATURE_ART
+	ArtSlotInfo activeArtifact; //position 0 - GameConstants::CREATURE_ART
 
 
 	ArtSlotInfo &retreiveNewArtSlot(ui16 slot);
 	ArtSlotInfo &retreiveNewArtSlot(ui16 slot);
 	void eraseArtSlot(ui16 slot);
 	void eraseArtSlot(ui16 slot);

+ 3 - 0
lib/CCreatureSet.cpp

@@ -930,6 +930,9 @@ void CStackInstance::deserializationFix()
 	const CArmedInstance *armyBackup = _armyObj;
 	const CArmedInstance *armyBackup = _armyObj;
 	_armyObj = NULL;
 	_armyObj = NULL;
 	setArmyObj(armyBackup);
 	setArmyObj(armyBackup);
+
+	if(activeArtifact.artifact)
+		attachTo(activeArtifact.artifact);
 }
 }
 
 
 int CStackInstance::getCreatureID() const
 int CStackInstance::getCreatureID() const

+ 2 - 0
lib/NetPacks.h

@@ -851,6 +851,8 @@ struct ArtifactLocation
 	ArtifactLocation()
 	ArtifactLocation()
 	{
 	{
 		slot = -1;
 		slot = -1;
+		stack = NULL;
+		hero = NULL;
 	}
 	}
 	ArtifactLocation(const CGHeroInstance *Hero, TArtPos Slot)
 	ArtifactLocation(const CGHeroInstance *Hero, TArtPos Slot)
 	{
 	{

+ 1 - 0
lib/NetPacksLib.cpp

@@ -564,6 +564,7 @@ DLL_LINKAGE const ArtSlotInfo *ArtifactLocation::getSlot() const
 		return hero->getSlot(slot);
 		return hero->getSlot(slot);
 	if (stack)
 	if (stack)
 		return stack->getSlot(slot);
 		return stack->getSlot(slot);
+	return NULL;
 }
 }
 
 
 DLL_LINKAGE void ChangeStackCount::applyGs( CGameState *gs )
 DLL_LINKAGE void ChangeStackCount::applyGs( CGameState *gs )

+ 1 - 0
lib/RegisterTypes.h

@@ -95,6 +95,7 @@ void registerTypes1(Serializer &s)
 	s.template registerType<CArtifactInstance>();
 	s.template registerType<CArtifactInstance>();
 	s.template registerType<CCombinedArtifactInstance>();
 	s.template registerType<CCombinedArtifactInstance>();
 	s.template registerType<CCreatureArtifactInstance>();
 	s.template registerType<CCreatureArtifactInstance>();
+	//s.template registerType<ArtSlotInfo>();
 	//s.template registerType<ArtifactLocation>();
 	//s.template registerType<ArtifactLocation>();
 	//s.template registerType<StackLocation>();
 	//s.template registerType<StackLocation>();
 }
 }