Ver código fonte

- Commanders will now be properly intialized
- Commanders show in the battle

DjWarmonger 13 anos atrás
pai
commit
82f3bc8135

+ 8 - 2
config/battleStartpos.json

@@ -1,5 +1,6 @@
 {
 {
-	"battle_positions": [
+	"battle_positions":
+	[
 		{
 		{
 			"name" : "attackerLoose", // loose formation, attacker
 			"name" : "attackerLoose", // loose formation, attacker
 			"levels": [
 			"levels": [
@@ -77,5 +78,10 @@
 				[ 15, 185, 171, 1, 100, 86, 8 ]
 				[ 15, 185, 171, 1, 100, 86, 8 ]
 				]
 				]
 		}
 		}
-	]
+	],
+	"commanderPositions":
+	{
+		"field" : [88, 98], //attacker/defender
+		"creBank" : [95, 8] //not expecting defendig hero at bank, but hell knows
+	}
 }
 }

+ 23 - 0
lib/BattleState.cpp

@@ -1616,7 +1616,9 @@ BattleInfo * BattleInfo::setupBattle( int3 tile, int terrain, int terType, const
 	}
 	}
 
 
 	//reading battleStartpos
 	//reading battleStartpos
+	//TODO: parse once to some structure
 	std::vector< std::vector<int> > attackerLoose, defenderLoose, attackerTight, defenderTight, attackerCreBank, defenderCreBank;
 	std::vector< std::vector<int> > attackerLoose, defenderLoose, attackerTight, defenderTight, attackerCreBank, defenderCreBank;
+	std::vector <int> commanderField, commanderBank;
 	const JsonNode config(GameConstants::DATA_DIR + "/config/battleStartpos.json");
 	const JsonNode config(GameConstants::DATA_DIR + "/config/battleStartpos.json");
 	const JsonVector &positions = config["battle_positions"].Vector();
 	const JsonVector &positions = config["battle_positions"].Vector();
 
 
@@ -1626,6 +1628,15 @@ BattleInfo * BattleInfo::setupBattle( int3 tile, int terrain, int terType, const
 	CGH::readBattlePositions(positions[3]["levels"], defenderTight);
 	CGH::readBattlePositions(positions[3]["levels"], defenderTight);
 	CGH::readBattlePositions(positions[4]["levels"], attackerCreBank);
 	CGH::readBattlePositions(positions[4]["levels"], attackerCreBank);
 	CGH::readBattlePositions(positions[5]["levels"], defenderCreBank);
 	CGH::readBattlePositions(positions[5]["levels"], defenderCreBank);
+	
+	BOOST_FOREACH (auto position, config["commanderPositions"]["field"].Vector())
+	{
+		commanderField.push_back (position.Float());
+	}
+	BOOST_FOREACH (auto position, config["commanderPositions"]["creBank"].Vector())
+	{
+		commanderBank.push_back (position.Float());
+	}
 
 
 	//battleStartpos read
 	//battleStartpos read
 	int k = 0; //stack serial 
 	int k = 0; //stack serial 
@@ -1721,6 +1732,18 @@ BattleInfo * BattleInfo::setupBattle( int3 tile, int terrain, int terType, const
 	}
 	}
 	//war machines added
 	//war machines added
 
 
+	//adding commanders
+	for (int i = 0; i < 2; ++i)
+	{
+		if (heroes[i] && heroes[i]->commander)
+		{
+			CStack * stack = curB->generateNewStack (*heroes[i]->commander, !i, 255,
+				creatureBank ? commanderBank[i] : commanderField[i]);
+			stacks.push_back(stack);
+		}
+
+	}
+
 	if (curB->siege == 2 || curB->siege == 3)
 	if (curB->siege == 2 || curB->siege == 3)
 	{
 	{
 		// keep tower
 		// keep tower

+ 1 - 1
lib/CArtHandler.h

@@ -36,7 +36,7 @@ namespace ArtBearer
 {
 {
 	enum
 	enum
 	{
 	{
-		HERO, CREATURE//, COMMANDER
+		HERO, CREATURE, COMMANDER
 	};
 	};
 }
 }
 
 

+ 4 - 3
lib/CCreatureSet.cpp

@@ -949,20 +949,21 @@ ui8 CStackInstance::bearerType() const
 CCommanderInstance::CCommanderInstance()
 CCommanderInstance::CCommanderInstance()
 {
 {
 	init();
 	init();
+	name = "Unnamed";
 }
 }
 
 
 CCommanderInstance::CCommanderInstance (TCreature id)
 CCommanderInstance::CCommanderInstance (TCreature id)
 {
 {
 	init();
 	init();
-	CStackInstance (id, 1); //init with single unit
+	setType(id);
 	name = "Commando"; //TODO - parse them
 	name = "Commando"; //TODO - parse them
 }
 }
 
 
-void CCommanderInstance::init()
+void CCommanderInstance::init() //called only after CStackInstance::init was executed
 {
 {
 	alive = true;
 	alive = true;
 	experience = 0;
 	experience = 0;
-	count = 0;
+	count = 1;
 	type = NULL;
 	type = NULL;
 	idRand = -1;
 	idRand = -1;
 	_armyObj = NULL;
 	_armyObj = NULL;

+ 2 - 1
lib/CCreatureSet.h

@@ -83,13 +83,14 @@ public:
 	std::string name; // each Commander has different name
 	std::string name; // each Commander has different name
 	std::vector <std::pair <ui8, ui8> > secondarySkills; //ID, level
 	std::vector <std::pair <ui8, ui8> > secondarySkills; //ID, level
 	//std::vector <CArtifactInstance *> arts;
 	//std::vector <CArtifactInstance *> arts;
-	void init();
+	void init() OVERRIDE;
 	CCommanderInstance();
 	CCommanderInstance();
 	CCommanderInstance (TCreature id);
 	CCommanderInstance (TCreature id);
 	~CCommanderInstance();
 	~CCommanderInstance();
 
 
 	ui64 getPower() const {return 0;};
 	ui64 getPower() const {return 0;};
 	int getExpRank() const {return 0;};
 	int getExpRank() const {return 0;};
+	ui8 bearerType() const OVERRIDE {return ArtBearer::COMMANDER;}; //from CArtifactSet
 
 
 	template <typename Handler> void serialize(Handler &h, const int version)
 	template <typename Handler> void serialize(Handler &h, const int version)
 	{
 	{

+ 1 - 0
lib/CObjectHandler.cpp

@@ -777,6 +777,7 @@ void CGHeroInstance::initHero()
 	if (GameConstants::COMMANDERS)
 	if (GameConstants::COMMANDERS)
 	{
 	{
 		commander = new CCommanderInstance (VLC->creh->factionCommanders[type->heroType / 2]); //hopefully it returns town type
 		commander = new CCommanderInstance (VLC->creh->factionCommanders[type->heroType / 2]); //hopefully it returns town type
+		commander->setArmyObj (castToArmyObj()); //TODO: separate function for setting commanders
 	}
 	}
 
 
 	hoverName = VLC->generaltexth->allTexts[15];
 	hoverName = VLC->generaltexth->allTexts[15];

+ 1 - 1
lib/GameConstants.h

@@ -92,7 +92,7 @@ namespace GameConstants
 	//game modules
 	//game modules
 	const bool STACK_EXP = true;
 	const bool STACK_EXP = true;
 	const bool STACK_ARTIFACT = true; //now toggle for testing
 	const bool STACK_ARTIFACT = true; //now toggle for testing
-	const bool COMMANDERS = false;
+	const bool COMMANDERS = true;
 	const bool MITHRIL = false;
 	const bool MITHRIL = false;
 }
 }