瀏覽代碼

* first part shooting in battles (units cannot shoot yet)
* minor improvements

mateuszb 17 年之前
父節點
當前提交
4bd39202c2
共有 9 個文件被更改,包括 126 次插入3 次删除
  1. 26 1
      CBattleInterface.cpp
  2. 14 0
      CBattleInterface.h
  3. 9 0
      CCallback.cpp
  4. 2 0
      CCallback.h
  5. 5 1
      CGameState.cpp
  6. 0 1
      CHeroWindow.cpp
  7. 40 0
      config/cr_shots.txt
  8. 27 0
      hch/CCreatureHandler.cpp
  9. 3 0
      hch/CCreatureHandler.h

+ 26 - 1
CBattleInterface.cpp

@@ -116,7 +116,15 @@ CBattleInterface::CBattleInterface(CCreatureSet * army1, CCreatureSet * army2, C
 	{
 		bfield[it->second.position].accesible = false;
 	}
-	
+
+	//loading projectiles for units
+	for(std::map<int, CStack>::iterator g = stacks.begin(); g != stacks.end(); ++g)
+	{
+		if(g->second.creature->isShooting() && CGI->creh->idToProjectile[g->second.creature->idNumber] != std::string())
+		{
+			idToProjectile[g->second.creature->idNumber] = CGI->spriteh->giveDef(CGI->creh->idToProjectile[g->second.creature->idNumber]);
+		}
+	}
 }
 
 CBattleInterface::~CBattleInterface()
@@ -144,6 +152,9 @@ CBattleInterface::~CBattleInterface()
 
 	for(std::map< int, CCreatureAnimation * >::iterator g=creAnims.begin(); g!=creAnims.end(); ++g)
 		delete g->second;
+
+	for(std::map< int, CDefHandler * >::iterator g=idToProjectile.begin(); g!=idToProjectile.end(); ++g)
+		delete g->second;
 }
 
 void CBattleInterface::activate()
@@ -306,6 +317,7 @@ void CBattleInterface::show(SDL_Surface * to)
 		}
 	}
 	//units shown
+	projectileShowHelper(to);//showing projectiles
 }
 
 bool CBattleInterface::reverseCreature(int number, int hex, bool wideTrick)
@@ -731,6 +743,15 @@ void CBattleInterface::hexLclicked(int whichOne)
 			ba->stackNumber = activeStack;
 			givenCommand = ba;
 		}
+		else if(LOCPLINT->cb->battleGetStackByID(atCre).owner != attackingHeroInstance->tempOwner
+			&& LOCPLINT->cb->battleCanShoot(activeStack, whichOne)) //shooting
+		{
+			BattleAction * ba = new BattleAction(); //to be deleted by engine
+			ba->actionType = 7;
+			ba->destinationTile = whichOne;
+			ba->stackNumber = activeStack;
+			givenCommand = ba;
+		}
 		else if(LOCPLINT->cb->battleGetStackByID(atCre).owner != attackingHeroInstance->tempOwner) //attacking
 		{
 			BattleAction * ba = new BattleAction(); //to be deleted by engine
@@ -889,6 +910,10 @@ void CBattleInterface::printConsoleAttacked(int ID, int dmg, int killed, int IDb
 	console->addText(std::string(tabh));
 }
 
+void CBattleInterface::projectileShowHelper(SDL_Surface * to)
+{
+}
+
 void CBattleHero::show(SDL_Surface *to)
 {
 	//animation of flag

+ 14 - 0
CBattleInterface.h

@@ -1,6 +1,7 @@
 #pragma once
 #include "global.h"
 #include "CPlayerInterface.h"
+#include <list>
 
 class CCreatureSet;
 class CGHeroInstance;
@@ -79,6 +80,7 @@ private:
 	CCreatureSet * army1, * army2; //fighting armies
 	CGHeroInstance * attackingHeroInstance, * defendingHeroInstance;
 	std::map< int, CCreatureAnimation * > creAnims; //animations of creatures from fighting armies (order by BattleInfo's stacks' ID)
+	std::map< int, CDefHandler * > idToProjectile; //projectiles of creaures (creatureID, defhandler)
 	std::map< int, bool > creDir; // <creatureID, if false reverse creature's animation>
 	unsigned char animCount;
 	int activeStack; //number of active stack; -1 - no one
@@ -95,6 +97,18 @@ private:
 	void attackingShowHelper();
 	void printConsoleAttacked(int ID, int dmg, int killed, int IDby);
 
+	struct SProjectileInfo
+	{
+		int x, y; //position on the screen
+		int dx, dy; //change in position in one step
+		int step, lastStep; //to know when finish showing this projectile
+		int creID; //ID of creature that shot this projectile
+		int frameNum; //frame to display form projectile animation
+		bool spin; //if true, frameNum will be increased
+	};
+	std::list<SProjectileInfo> projectiles;
+	void projectileShowHelper(SDL_Surface * to); //prints projectiles present on the battlefield
+
 public:
 	CBattleInterface(CCreatureSet * army1, CCreatureSet * army2, CGHeroInstance *hero1, CGHeroInstance *hero2); //c-tor
 	~CBattleInterface(); //d-tor

+ 9 - 0
CCallback.cpp

@@ -838,6 +838,15 @@ bool CCallback::battleIsStackMine(int ID)
 	return false;
 }
 
+bool CCallback::battleCanShoot(int ID, int dest) //TODO: finish
+{
+	if(battleGetStackByID(ID).creature->isShooting() 
+		&& battleGetStack(dest) != -1 
+		&& battleGetStackByPos(dest).owner != battleGetStackByID(ID).owner)
+		return true;
+	return false;
+}
+
 int3 CScriptCallback::getPos(CGObjectInstance * ob)
 {
 	return ob->pos;

+ 2 - 0
CCallback.h

@@ -68,6 +68,7 @@ public:
 	//virtual bool battleMoveCreature(int ID, int dest)=0; //moves creature with id ID to dest if possible
 	virtual std::vector<int> battleGetAvailableHexes(int ID)=0; //reutrns numbers of hexes reachable by creature with id ID
 	virtual bool battleIsStackMine(int ID)=0; //returns true if stack with id ID belongs to caller
+	virtual bool battleCanShoot(int ID, int dest)=0; //returns true if unit with id ID can shoot to dest
 };
 
 struct HeroMoveDetails
@@ -140,6 +141,7 @@ public:
 	//bool battleMoveCreature(int ID, int dest); //moves creature with id ID to dest if possible
 	std::vector<int> battleGetAvailableHexes(int ID); //reutrns numbers of hexes reachable by creature with id ID
 	bool battleIsStackMine(int ID); //returns true if stack with id ID belongs to caller
+	bool battleCanShoot(int ID, int dest); //returns true if unit with id ID can shoot to dest
 	
 
 //friends

+ 5 - 1
CGameState.cpp

@@ -237,6 +237,10 @@ void CGameState::battle(CCreatureSet * army1, CCreatureSet * army2, int3 tile, C
 							battleAttackCreatureStack(ba.stackNumber, ba.destinationTile);
 							break;
 						}
+					case 7: //shoot
+						{
+							break;
+						}
 					}
 				}
 				else
@@ -345,7 +349,7 @@ bool CGameState::battleMoveCreatureStack(int ID, int dest)
 			if(curStack->attackerOwned ? (v%17)==1 : (v%17)==15)
 				accessibility[v] = false;
 	}
-	if(!accessibility[dest])
+	if(!stackAtEnd && !accessibility[dest])
 		return false;
 	int predecessor[187]; //for getting the Path
 	for(int b=0; b<187; ++b)

+ 0 - 1
CHeroWindow.cpp

@@ -43,7 +43,6 @@ CHeroWindow::CHeroWindow(int playerColor):
 	gar3button = new AdventureMapButton(CGI->generaltexth->heroscrn[24], CGI->generaltexth->heroscrn[30], boost::bind(&CHeroWindow::gar3,this), 546, 527, "hsbtns7.def", false, NULL, false);
 	gar4button = new AdventureMapButton(std::string(), CGI->generaltexth->heroscrn[32], boost::function<void()>(), 604, 527, "hsbtns9.def", false, NULL, false);
 
-	//boost::bind(&CGarrisonInt::splitClick,garInt)
 	leftArtRoll = new AdventureMapButton(std::string(), std::string(), boost::bind(&CHeroWindow::leftArtRoller,this), 379, 364, "hsbtns3.def", false, NULL, false);
 	rightArtRoll = new AdventureMapButton(std::string(), std::string(), boost::bind(&CHeroWindow::rightArtRoller,this), 632, 364, "hsbtns5.def", false, NULL, false);
 

+ 40 - 0
config/cr_shots.txt

@@ -0,0 +1,40 @@
+//here are defs with things shot by different units - don't delete this line; format: unit_ID def_name spin_projectile
+2 PLCBOWX.DEF 0
+3 PLCBOWX.DEF 0
+8 SMBALX.DEF 1
+9 SMBALX.DEF 1
+18 PELFX.DEF 0
+19 PELFX.DEF 0
+29 CPGRE.DEF 1
+34 PMAGX.DEF 1
+35 PMAGX.DEF 1
+41 SMBALX.DEF 0
+44 CPRGOGX.DEF 1
+45 CPRGOGX.DEF 1
+64 PLICH.DEF 0
+65 PLICH.DEF 0
+74 SMBALX.DEF 0
+75 SMBALX.DEF 0
+76 PMEDUSX.DEF 0
+77 PMEDUSX.DEF 0
+88 PORCHX.DEF 1
+89 PORCHX.DEF 1
+94 PCYCLBX.DEF 1
+95 PCYCLBX.DEF 1
+100 PPLIZAX.DEF 0
+101 PPLIZAX.DEF 0
+123 PICEE.DEF 0
+127 SMBALX.DEF 0
+136 SMBALX.DEF 0
+137 PLCBOWX.DEF 0
+138 PHALF.DEF 1
+145 SMBALX.DEF 0
+146 SMBALX.DEF 0
+152 SMBALX.DEF 0
+169 SMBALX.DEF 0
+170 PLCBOWX.DEF 0
+171 PLCBOWX.DEF 0
+173 CPGRE.DEF 1
+193 SMBALX.DEF 0
+196 SMBALX.DEF 0
+-1

+ 27 - 0
hch/CCreatureHandler.cpp

@@ -42,6 +42,12 @@ bool CCreature::isFlying()
 {
 	return boost::algorithm::find_first(abilityRefs, "FLYING_ARMY");
 }
+
+bool CCreature::isShooting()
+{
+	return boost::algorithm::find_first(abilityRefs, "SHOOTING_ARMY");
+}
+
 int CCreature::maxAmount(const std::vector<int> &res) const //how many creatures can be bought
 {
 	int ret = 2147483645;
@@ -437,6 +443,27 @@ void CCreatureHandler::loadCreatures()
 		creatures[s].animDefName = defName;
 	}
 	loadAnimationInfo();
+
+	//loading id to projectile mapping
+
+	std::ifstream inp2("config/cr_shots.TXT", std::ios::in | std::ios::binary); //this file is not in lod
+	char dump [200];
+	inp2.getline(dump, 200);
+	while(true)
+	{
+		int id;
+		std::string name;
+		bool spin;
+
+		inp2>>id;
+		if(id == -1)
+			break;
+		inp2>>name;
+		idToProjectile[id] = name;
+		inp2>>spin;
+		idToProjectileSpin[id] = spin;
+	}
+	inp2.close();
 }
 
 void CCreatureHandler::loadAnimationInfo()

+ 3 - 0
hch/CCreatureHandler.h

@@ -44,6 +44,7 @@ public:
 	static int getQuantityID(int quantity); //0 - a few, 1 - several, 2 - pack, 3 - lots, 4 - horde, 5 - throng, 6 - swarm, 7 - zounds, 8 - legion
 	bool isDoubleWide(); //returns true if unit is double wide on battlefield
 	bool isFlying(); //returns true if it is a flying unit
+	bool isShooting(); //returns true if unit can shoot
 	int maxAmount(const std::vector<int> &res) const; //how many creatures can be bought
 };
 
@@ -65,6 +66,8 @@ public:
 	std::vector<CCreature> creatures; //creature ID -> creature info
 	std::map<int,std::vector<CCreature*> > levelCreatures; //level -> list of creatures
 	std::map<std::string,int> nameToID;
+	std::map<int,std::string> idToProjectile;
+	std::map<int,bool> idToProjectileSpin; //if true, appropriate projectile is spinning during flight
 	void loadCreatures();
 	void loadAnimationInfo();
 	void loadUnitAnimInfo(CCreature & unit, std::string & src, int & i);