Browse Source

- blocked retreating from castle. Escape Tunnel implemented.
- fixed crash when player have no hero (like castle defence)
- minor fixes

Ivan Savenko 15 years ago
parent
commit
d732565002
6 changed files with 34 additions and 7 deletions
  1. 2 2
      CCallback.cpp
  2. 4 0
      client/CBattleInterface.cpp
  3. 8 0
      client/GUIClasses.cpp
  4. 17 2
      lib/CGameState.cpp
  5. 1 1
      lib/NetPacksLib.cpp
  6. 2 2
      server/CGameHandler.cpp

+ 2 - 2
CCallback.cpp

@@ -624,9 +624,9 @@ bool CCallback::battleCanCastSpell()
 		return false;
 		return false;
 
 
 	if(gs->curB->side1 == player)
 	if(gs->curB->side1 == player)
-		return gs->curB->castSpells[0] == 0 && gs->curB->heroes[0]->getArt(17);
+		return gs->curB->castSpells[0] == 0 && gs->curB->heroes[0] && gs->curB->heroes[0]->getArt(17);
 	else
 	else
-		return gs->curB->castSpells[1] == 0 && gs->curB->heroes[1]->getArt(17);
+		return gs->curB->castSpells[1] == 0 && gs->curB->heroes[1] && gs->curB->heroes[1]->getArt(17);
 }
 }
 
 
 bool CCallback::battleCanFlee()
 bool CCallback::battleCanFlee()

+ 4 - 0
client/CBattleInterface.cpp

@@ -1197,6 +1197,8 @@ CBattleInterface::CBattleInterface(const CCreatureSet * army1, const CCreatureSe
 	bOptions = new AdventureMapButton (CGI->generaltexth->zelp[381].first, CGI->generaltexth->zelp[381].second, boost::bind(&CBattleInterface::bOptionsf,this), 3 + pos.x, 561 + pos.y, "icm003.def", SDLK_o);
 	bOptions = new AdventureMapButton (CGI->generaltexth->zelp[381].first, CGI->generaltexth->zelp[381].second, boost::bind(&CBattleInterface::bOptionsf,this), 3 + pos.x, 561 + pos.y, "icm003.def", SDLK_o);
 	bSurrender = new AdventureMapButton (CGI->generaltexth->zelp[379].first, CGI->generaltexth->zelp[379].second, boost::bind(&CBattleInterface::bSurrenderf,this), 54 + pos.x, 561 + pos.y, "icm001.def", SDLK_s);
 	bSurrender = new AdventureMapButton (CGI->generaltexth->zelp[379].first, CGI->generaltexth->zelp[379].second, boost::bind(&CBattleInterface::bSurrenderf,this), 54 + pos.x, 561 + pos.y, "icm001.def", SDLK_s);
 	bFlee = new AdventureMapButton (CGI->generaltexth->zelp[380].first, CGI->generaltexth->zelp[380].second, boost::bind(&CBattleInterface::bFleef,this), 105 + pos.x, 561 + pos.y, "icm002.def", SDLK_r);
 	bFlee = new AdventureMapButton (CGI->generaltexth->zelp[380].first, CGI->generaltexth->zelp[380].second, boost::bind(&CBattleInterface::bFleef,this), 105 + pos.x, 561 + pos.y, "icm002.def", SDLK_r);
+	bSurrender->block(!curInt->cb->battleCanFlee());
+	bFlee->block(!curInt->cb->battleCanFlee());	
 	bAutofight  = new AdventureMapButton (CGI->generaltexth->zelp[382].first, CGI->generaltexth->zelp[382].second, boost::bind(&CBattleInterface::bAutofightf,this), 157 + pos.x, 561 + pos.y, "icm004.def", SDLK_a);
 	bAutofight  = new AdventureMapButton (CGI->generaltexth->zelp[382].first, CGI->generaltexth->zelp[382].second, boost::bind(&CBattleInterface::bAutofightf,this), 157 + pos.x, 561 + pos.y, "icm004.def", SDLK_a);
 	bSpell = new AdventureMapButton (CGI->generaltexth->zelp[385].first, CGI->generaltexth->zelp[385].second, boost::bind(&CBattleInterface::bSpellf,this), 645 + pos.x, 561 + pos.y, "icm005.def", SDLK_c);
 	bSpell = new AdventureMapButton (CGI->generaltexth->zelp[385].first, CGI->generaltexth->zelp[385].second, boost::bind(&CBattleInterface::bSpellf,this), 645 + pos.x, 561 + pos.y, "icm005.def", SDLK_c);
 	bSpell->block(true);
 	bSpell->block(true);
@@ -2915,6 +2917,8 @@ void CBattleInterface::activateStack()
 
 
 	//block cast spell button if hero doesn't have a spellbook
 	//block cast spell button if hero doesn't have a spellbook
 	bSpell->block(!curInt->cb->battleCanCastSpell());
 	bSpell->block(!curInt->cb->battleCanCastSpell());
+	bSurrender->block(!curInt->cb->battleCanFlee());
+	bFlee->block(!curInt->cb->battleCanFlee());
 
 
 	GH.fakeMouseMove();
 	GH.fakeMouseMove();
 
 

+ 8 - 0
client/GUIClasses.cpp

@@ -2161,6 +2161,14 @@ void CSplitWindow::keyPressed (const SDL_KeyboardEvent & key)
 	{
 	{
 		which = !which;
 		which = !which;
 	}
 	}
+	else if (k == SDLK_LEFT)
+	{
+		ncur--;
+	}
+	else if (k == SDLK_RIGHT)
+	{
+		ncur++;
+	}
 	else
 	else
 	{
 	{
 		int number = k - SDLK_0;
 		int number = k - SDLK_0;

+ 17 - 2
lib/CGameState.cpp

@@ -1830,8 +1830,23 @@ bool CGameState::battleCanFlee(int player)
 	if(!curB) //there is no battle
 	if(!curB) //there is no battle
 		return false;
 		return false;
 
 
-	if(curB->heroes[0]->hasBonusOfType(Bonus::ENEMY_CANT_ESCAPE) //eg. one of heroes is wearing shakles of war
-		|| curB->heroes[0]->hasBonusOfType(Bonus::ENEMY_CANT_ESCAPE))
+	if (player == curB->side1)
+	{
+		if (!curB->heroes[0])
+			return false;//current player have no hero
+	}
+	else
+	{
+		if (!curB->heroes[1])
+			return false;
+	}
+
+	if( ( curB->heroes[0] && curB->heroes[0]->hasBonusOfType(Bonus::ENEMY_CANT_ESCAPE) ) //eg. one of heroes is wearing shakles of war
+		|| ( curB->heroes[1] && curB->heroes[1]->hasBonusOfType(Bonus::ENEMY_CANT_ESCAPE)))
+		return false;
+
+	if (player == curB->side2 && curB->siege //defender in siege
+		&& !(getTown(curB->tid)->subID == 6 && vstd::contains(getTown(curB->tid)->builtBuildings, 17)))//without escape tunnel
 		return false;
 		return false;
 
 
 	return true;
 	return true;

+ 1 - 1
lib/NetPacksLib.cpp

@@ -159,7 +159,7 @@ DLL_EXPORT void FoWChange::applyGs( CGameState *gs )
 				case 53://mine
 				case 53://mine
 				case 98://town
 				case 98://town
 				case 220:
 				case 220:
-					if(vstd::contains(team->players, player)) //check owned observators
+					if(vstd::contains(team->players, gs->map->objects[i]->tempOwner)) //check owned observators
 						gs->map->objects[i]->getSightTiles(tilesRevealed);
 						gs->map->objects[i]->getSightTiles(tilesRevealed);
 					break;
 					break;
 				}
 				}

+ 2 - 2
server/CGameHandler.cpp

@@ -251,14 +251,14 @@ void CGameHandler::levelUpHero(int ID)
 		hlu.skills.push_back(s);
 		hlu.skills.push_back(s);
 		basicAndAdv.erase(s);
 		basicAndAdv.erase(s);
 	}
 	}
-	else if(hero->secSkills.size() < hero->type->heroClass->skillLimit)
+	else if(none.size() && hero->secSkills.size() < hero->type->heroClass->skillLimit)
 	{
 	{
 		hlu.skills.push_back(hero->type->heroClass->chooseSecSkill(none)); //give new skill
 		hlu.skills.push_back(hero->type->heroClass->chooseSecSkill(none)); //give new skill
 		none.erase(hlu.skills.back());
 		none.erase(hlu.skills.back());
 	}
 	}
 
 
 	//second offered skill
 	//second offered skill
-	if(hero->secSkills.size() < hero->type->heroClass->skillLimit) //hero have free skill slot
+	if(none.size() && hero->secSkills.size() < hero->type->heroClass->skillLimit) //hero have free skill slot
 	{
 	{
 		hlu.skills.push_back(hero->type->heroClass->chooseSecSkill(none)); //new skill
 		hlu.skills.push_back(hero->type->heroClass->chooseSecSkill(none)); //new skill
 	}
 	}