mirror of
				https://github.com/vcmi/vcmi.git
				synced 2025-10-31 00:07:39 +02:00 
			
		
		
		
	* animation of catapult
* stacks won't be reversed when attacked by turrets
This commit is contained in:
		| @@ -295,6 +295,9 @@ bool CBattleStackAnimation::isToReverseHlp(int hexFrom, int hexTo, bool curDir) | ||||
|  | ||||
| bool CBattleStackAnimation::isToReverse(int hexFrom, int hexTo, bool curDir, bool toDoubleWide, bool toDir) | ||||
| { | ||||
| 	if(hexTo < 0) //turret | ||||
| 		return false; | ||||
|  | ||||
| 	if(toDoubleWide) | ||||
| 	{ | ||||
| 		return isToReverseHlp(hexFrom, hexTo, curDir) && | ||||
| @@ -946,7 +949,16 @@ bool CShootingAnim::init() | ||||
| 	spi.spin = CGI->creh->idToProjectileSpin[spi.creID]; | ||||
|  | ||||
| 	Point xycoord = CBattleHex::getXYUnitAnim(shooter->position, true, shooter, owner); | ||||
| 	Point destcoord = CBattleHex::getXYUnitAnim(dest, false, attackedStack, owner);  | ||||
| 	Point destcoord; | ||||
| 	if(attackedStack) | ||||
| 	{ | ||||
| 		destcoord = CBattleHex::getXYUnitAnim(dest, false, attackedStack, owner);  | ||||
| 	} | ||||
| 	else //catapult attack | ||||
| 	{ | ||||
| 		destcoord.x = -160 + 22 * ( ((dest/BFIELD_WIDTH) + 1)%2 ) + 44 * (dest % BFIELD_WIDTH); | ||||
| 		destcoord.y = -139 + 42 * (dest/BFIELD_WIDTH); | ||||
| 	} | ||||
| 	destcoord.x += 250; destcoord.y += 210; //TODO: find a better place to shoot | ||||
|  | ||||
| 	if(projectileAngle > straightAngle) //upper shot | ||||
| @@ -983,7 +995,11 @@ bool CShootingAnim::init() | ||||
| 	owner->projectiles.push_back(spi); | ||||
|  | ||||
| 	//attack aniamtion | ||||
| 	IDby = attackedStack->ID; | ||||
| 	if(attackedStack) | ||||
| 		IDby = attackedStack->ID; | ||||
| 	else | ||||
| 		IDby = -1; | ||||
|  | ||||
| 	posShiftDueToDist = 0; | ||||
| 	shooting = true; | ||||
|  | ||||
| @@ -1017,9 +1033,15 @@ void CShootingAnim::endAnim() | ||||
| 	delete this; | ||||
| } | ||||
|  | ||||
| CShootingAnim::CShootingAnim(CBattleInterface * _owner, int attacker, int _dest) | ||||
| : CBattleAttack(_owner, attacker, _dest) | ||||
| CShootingAnim::CShootingAnim(CBattleInterface * _owner, int attacker, int _dest, bool _catapult, int _catapultDmg) | ||||
| : CBattleAttack(_owner, attacker, _dest), catapultDamage(_catapultDmg), catapult(_catapult) | ||||
| { | ||||
| 	if(catapult) //catapult attack | ||||
| 	{ | ||||
| 		owner->addNewAnim( new CSpellEffectAnim(owner, "SGEXPL.DEF", | ||||
| 			-130 + 22 * ( ((dest/BFIELD_WIDTH) + 1)%2 ) + 44 * (dest % BFIELD_WIDTH), | ||||
| 			-50 + 42 * (dest/BFIELD_WIDTH) )); | ||||
| 	} | ||||
| } | ||||
|  | ||||
| //////////////////////// | ||||
| @@ -2441,6 +2463,18 @@ void CBattleInterface::stackIsShooting(int ID, int dest) | ||||
| 	addNewAnim(new CShootingAnim(this, ID, dest)); | ||||
| } | ||||
|  | ||||
| void CBattleInterface::stackIsCatapulting(const CatapultAttack & ca) | ||||
| { | ||||
| 	for(std::set< std::pair< std::pair< ui8, si16 >, ui8> >::const_iterator it = ca.attackedParts.begin(); it != ca.attackedParts.end(); ++it) | ||||
| 	{ | ||||
| 		addNewAnim(new CShootingAnim(this, ca.attacker, it->first.second, true, it->second)); | ||||
|  | ||||
| 		SDL_FreeSurface(siegeH->walls[it->first.first + 2]); | ||||
| 		siegeH->walls[it->first.first + 2] = BitmapHandler::loadBitmap( | ||||
| 			siegeH->getSiegeName(it->first.first + 2, LOCPLINT->cb->battleGetWallState(it->first.first)) ); | ||||
| 	} | ||||
| } | ||||
|  | ||||
| void CBattleInterface::battleFinished(const BattleResult& br) | ||||
| { | ||||
| 	bresult = &br; | ||||
| @@ -2960,6 +2994,9 @@ void CBattleInterface::endAction(const BattleAction* action) | ||||
| 	{ | ||||
| 		pendingAnims.push_back(std::make_pair(new CBattleMoveEnd(this, action->stackNumber, action->destinationTile), false)); | ||||
| 	} | ||||
| 	if(action->actionType == 9) //catapult | ||||
| 	{ | ||||
| 	} | ||||
| } | ||||
|  | ||||
| void CBattleInterface::hideQueue() | ||||
|   | ||||
| @@ -29,6 +29,7 @@ template <typename T> struct CondSh; | ||||
| struct SetStackEffect;; | ||||
| struct BattleAction; | ||||
| class CGTownInstance; | ||||
| struct CatapultAttack; | ||||
|  | ||||
| class CBattleInterface; | ||||
|  | ||||
| @@ -187,6 +188,7 @@ public: | ||||
|  | ||||
| 	bool checkInitialConditions(); | ||||
|  | ||||
|  | ||||
| 	CBattleAttack(CBattleInterface * _owner, int _stackID, int _dest); | ||||
| }; | ||||
|  | ||||
| @@ -202,12 +204,15 @@ public: | ||||
|  | ||||
| class CShootingAnim : public CBattleAttack | ||||
| { | ||||
| private: | ||||
| 	int catapultDamage; | ||||
| 	bool catapult; | ||||
| public: | ||||
| 	bool init(); | ||||
| 	void nextFrame(); | ||||
| 	void endAnim(); | ||||
|  | ||||
| 	CShootingAnim(CBattleInterface * _owner, int attacker, int _dest); | ||||
| 	CShootingAnim(CBattleInterface * _owner, int attacker, int _dest, bool _catapult = false, int _catapultDmg = 0); //last param only for catapult attacks | ||||
| }; | ||||
|  | ||||
| //end of battle animation handlers | ||||
| @@ -415,7 +420,7 @@ private: | ||||
|  | ||||
| 		void printPartOfWall(SDL_Surface * to, int what);//what: 1 - background wall, 2 - keep, 3 - bottom tower, 4 - bottom wall, 5 - below gate, 6 - over gate, 7 - upper wall, 8 - uppert tower, 9 - gate, 10 - gate arch, 11 - bottom static wall, 12 - upper static wall, 15 - keep creature cover, 16 - bottom turret creature cover, 17 - upper turret creature cover | ||||
|  | ||||
| 		friend class CPlayerInterface; | ||||
| 		friend class CBattleInterface; | ||||
| 	} * siegeH; | ||||
| public: | ||||
| 	std::list<std::pair<CBattleAnimation *, bool> > pendingAnims; //currently displayed animations <anim, initialized> | ||||
| @@ -475,6 +480,7 @@ public: | ||||
| 	void newRound(int number); //caled when round is ended; number is the number of round | ||||
| 	void hexLclicked(int whichOne); //hex only call-in | ||||
| 	void stackIsShooting(int ID, int dest); //called when stack with id ID is shooting to hex dest | ||||
| 	void stackIsCatapulting(const CatapultAttack & ca); //called when a stack is attacking walls | ||||
| 	void battleFinished(const BattleResult& br); //called when battle is finished - battleresult window should be printed | ||||
| 	const BattleResult * bresult; //result of a battle; if non-zero then display when all animations end | ||||
| 	void displayBattleFinished(); //displays battle result | ||||
|   | ||||
| @@ -998,12 +998,7 @@ void CPlayerInterface::battleObstaclesRemoved(const std::set<si32> & removedObst | ||||
|  | ||||
| void CPlayerInterface::battleCatapultAttacked(const CatapultAttack & ca) | ||||
| { | ||||
| 	for(std::set< std::pair<ui8, ui8> >::const_iterator it = ca.attackedParts.begin(); it != ca.attackedParts.end(); ++it) | ||||
| 	{ | ||||
| 		SDL_FreeSurface(battleInt->siegeH->walls[it->first + 2]); | ||||
| 		battleInt->siegeH->walls[it->first + 2] = BitmapHandler::loadBitmap( | ||||
| 			battleInt->siegeH->getSiegeName(it->first + 2, cb->battleGetWallState(it->first)) ); | ||||
| 	} | ||||
| 	battleInt->stackIsCatapulting(ca); | ||||
| } | ||||
|  | ||||
| void CPlayerInterface::battleStacksRemoved(const BattleStacksRemoved & bsr) | ||||
|   | ||||
| @@ -28,7 +28,7 @@ | ||||
| 136 SMBALX.DEF 0 | ||||
| 137 PLCBOWX.DEF 0 | ||||
| 138 PHALF.DEF 1 | ||||
| 145 SMBALX.DEF 0 | ||||
| 145 SMCATX.DEF 1 | ||||
| 146 SMBALX.DEF 0 | ||||
| 152 SMBALX.DEF 0 | ||||
| 169 SMBALX.DEF 0 | ||||
|   | ||||
| @@ -1028,15 +1028,15 @@ struct CatapultAttack : public CPackForClient //3015 | ||||
| 	DLL_EXPORT void applyGs(CGameState *gs); | ||||
| 	void applyCl(CClient *cl); | ||||
|  | ||||
| 	std::set< std::pair<ui8, ui8> > attackedParts; // <attackedPartOfWall, damageDealt> | ||||
| 	std::set< std::pair< std::pair< ui8, si16 >, ui8> > attackedParts; // < <attackedPartOfWall, attacked hex >, damageDealt> | ||||
| 	//attackedPartOfWall; //[0] - keep, [1] - bottom tower, [2] - bottom wall, [3] - below gate, [4] - over gate, [5] - upper wall, [6] - uppert tower, [7] - gate; | ||||
| 	//damageDealt; | ||||
|  | ||||
| 	bool byCatapult; //if true, by catapult, if false - by something else (ie. spell) | ||||
| 	int attacker; //if -1, then a spell caused this | ||||
|  | ||||
| 	template <typename Handler> void serialize(Handler &h, const int version) | ||||
| 	{ | ||||
| 		h & attackedParts & byCatapult; | ||||
| 		h & attackedParts & attacker; | ||||
| 	} | ||||
| }; | ||||
|  | ||||
|   | ||||
| @@ -1088,10 +1088,10 @@ DLL_EXPORT void CatapultAttack::applyGs( CGameState *gs ) | ||||
| { | ||||
| 	if(gs->curB && gs->curB->siege != 0) //if there is a battle and it's a siege | ||||
| 	{ | ||||
| 		for(std::set< std::pair<ui8, ui8> >::const_iterator it = attackedParts.begin(); it != attackedParts.end(); ++it) | ||||
| 		for(std::set< std::pair< std::pair< ui8, si16 >, ui8> >::const_iterator it = attackedParts.begin(); it != attackedParts.end(); ++it) | ||||
| 		{ | ||||
| 			gs->curB->si.wallState[it->first] =  | ||||
| 				std::min( gs->curB->si.wallState[it->first] + it->second, 3 ); | ||||
| 			gs->curB->si.wallState[it->first.first] =  | ||||
| 				std::min( gs->curB->si.wallState[it->first.first] + it->second, 3 ); | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
|   | ||||
| @@ -2602,8 +2602,9 @@ bool CGameHandler::makeBattleAction( BattleAction &ba ) | ||||
| 					continue; | ||||
| 				 | ||||
| 				CatapultAttack ca; //package for clients | ||||
| 				std::pair<ui8, ui8> attack; | ||||
| 				attack.first = attackedPart; | ||||
| 				std::pair< std::pair< ui8, si16 >, ui8> attack; | ||||
| 				attack.first.first = attackedPart; | ||||
| 				attack.first.second = ba.destinationTile; | ||||
| 				attack.second = 0; | ||||
|  | ||||
| 				int chanceForHit = 0; | ||||
| @@ -2672,7 +2673,7 @@ bool CGameHandler::makeBattleAction( BattleAction &ba ) | ||||
| 						sendAndApply(&bsr); | ||||
| 					} | ||||
| 				} | ||||
| 				ca.byCatapult = true; | ||||
| 				ca.attacker = ba.stackNumber; | ||||
| 				ca.attackedParts.insert(attack); | ||||
|  | ||||
| 				sendAndApply(&ca); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user