2011-12-14 00:23:17 +03:00
|
|
|
#include "StdInc.h"
|
2010-02-08 16:39:19 +02:00
|
|
|
#include "CCampaignHandler.h"
|
2011-12-14 00:23:17 +03:00
|
|
|
|
2012-08-01 15:02:54 +03:00
|
|
|
#include "Filesystem/CResourceLoader.h"
|
|
|
|
#include "Filesystem/CCompressedStream.h"
|
2010-02-12 17:04:01 +02:00
|
|
|
#include "../lib/VCMI_Lib.h"
|
2011-10-08 04:23:46 +03:00
|
|
|
#include "../lib/vcmi_endian.h"
|
2010-02-12 17:04:01 +02:00
|
|
|
#include "CGeneralTextHandler.h"
|
2011-12-14 00:23:17 +03:00
|
|
|
#include "StartInfo.h"
|
2010-08-28 17:52:20 +03:00
|
|
|
#include "CArtHandler.h" //for hero crossover
|
|
|
|
#include "CObjectHandler.h" //for hero crossover
|
|
|
|
#include "CHeroHandler.h"
|
2010-02-08 16:39:19 +02:00
|
|
|
|
|
|
|
namespace fs = boost::filesystem;
|
|
|
|
|
2010-02-09 15:48:14 +02:00
|
|
|
/*
|
|
|
|
* CCampaignHandler.cpp, part of VCMI engine
|
|
|
|
*
|
|
|
|
* Authors: listed in file AUTHORS in main folder
|
|
|
|
*
|
|
|
|
* License: GNU General Public License v2.0 or later
|
|
|
|
* Full text of license available in license.txt file, in main folder
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2010-02-08 16:39:19 +02:00
|
|
|
|
2012-08-01 15:02:54 +03:00
|
|
|
CCampaignHeader CCampaignHandler::getHeader( const std::string & name)
|
2010-02-08 16:39:19 +02:00
|
|
|
{
|
2012-08-02 14:03:26 +03:00
|
|
|
std::vector<ui8> cmpgn = getFile(name, true)[0];
|
2010-02-08 16:39:19 +02:00
|
|
|
|
2010-02-09 15:48:14 +02:00
|
|
|
int it = 0;//iterator for reading
|
2012-08-02 14:03:26 +03:00
|
|
|
CCampaignHeader ret = readHeaderFromMemory(cmpgn.data(), it);
|
2010-02-18 14:34:44 +02:00
|
|
|
ret.filename = name;
|
2010-02-11 16:12:22 +02:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-09-21 20:59:54 +03:00
|
|
|
unique_ptr<CCampaign> CCampaignHandler::getCampaign( const std::string & name )
|
2010-02-11 16:12:22 +02:00
|
|
|
{
|
2012-09-21 20:59:54 +03:00
|
|
|
auto ret = make_unique<CCampaign>();
|
2010-02-11 16:12:22 +02:00
|
|
|
|
2012-08-02 14:03:26 +03:00
|
|
|
std::vector<std::vector<ui8>> file = getFile(name, false);
|
2010-02-11 16:12:22 +02:00
|
|
|
|
|
|
|
int it = 0; //iterator for reading
|
2012-08-02 14:03:26 +03:00
|
|
|
ret->header = readHeaderFromMemory(file[0].data(), it);
|
2010-02-18 14:34:44 +02:00
|
|
|
ret->header.filename = name;
|
2010-02-11 16:12:22 +02:00
|
|
|
|
2010-02-12 17:04:01 +02:00
|
|
|
int howManyScenarios = VLC->generaltexth->campaignRegionNames[ret->header.mapVersion].size();
|
|
|
|
for(int g=0; g<howManyScenarios; ++g)
|
|
|
|
{
|
2012-08-02 14:03:26 +03:00
|
|
|
CCampaignScenario sc = readScenarioFromMemory(file[0].data(), it, ret->header.version, ret->header.mapVersion);
|
2010-02-12 17:04:01 +02:00
|
|
|
ret->scenarios.push_back(sc);
|
|
|
|
}
|
|
|
|
|
2010-07-30 14:29:42 +03:00
|
|
|
int scenarioID = 0;
|
2010-02-16 19:28:56 +02:00
|
|
|
|
2012-08-02 14:03:26 +03:00
|
|
|
//first entry is campaign header. start loop from 1
|
2012-09-23 17:32:49 +03:00
|
|
|
for (int g=1; g<file.size() && scenarioID<howManyScenarios; ++g)
|
2010-02-12 17:04:01 +02:00
|
|
|
{
|
2010-07-30 14:29:42 +03:00
|
|
|
while(!ret->scenarios[scenarioID].isNotVoid()) //skip void scenarios
|
|
|
|
{
|
|
|
|
scenarioID++;
|
|
|
|
}
|
2012-09-21 20:59:54 +03:00
|
|
|
|
2012-09-23 17:32:49 +03:00
|
|
|
//set map piece appropriately, convert vector to string
|
|
|
|
ret->mapPieces[scenarioID].assign(reinterpret_cast< const char* >(file[g].data()), file[g].size());
|
2012-09-21 20:59:54 +03:00
|
|
|
scenarioID++;
|
2010-02-12 17:04:01 +02:00
|
|
|
}
|
2010-02-08 16:39:19 +02:00
|
|
|
|
2010-02-11 16:12:22 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-12-14 00:23:17 +03:00
|
|
|
CCampaignHeader CCampaignHandler::readHeaderFromMemory( const ui8 *buffer, int & outIt )
|
2010-02-11 16:12:22 +02:00
|
|
|
{
|
|
|
|
CCampaignHeader ret;
|
2011-10-08 04:23:46 +03:00
|
|
|
ret.version = read_le_u32(buffer + outIt); outIt+=4;
|
2011-11-25 22:41:23 +03:00
|
|
|
ret.mapVersion = buffer[outIt++]; //1 byte only
|
2010-02-15 14:12:21 +02:00
|
|
|
ret.mapVersion -= 1; //change range of it from [1, 20] to [0, 19]
|
2010-02-11 16:12:22 +02:00
|
|
|
ret.name = readString(buffer, outIt);
|
|
|
|
ret.description = readString(buffer, outIt);
|
2011-11-27 16:14:20 +03:00
|
|
|
if (ret.version > CampaignVersion::RoE)
|
|
|
|
ret.difficultyChoosenByPlayer = readChar(buffer, outIt);
|
|
|
|
else
|
|
|
|
ret.difficultyChoosenByPlayer = 0;
|
2010-02-11 16:12:22 +02:00
|
|
|
ret.music = readChar(buffer, outIt);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-12-14 00:23:17 +03:00
|
|
|
CCampaignScenario CCampaignHandler::readScenarioFromMemory( const ui8 *buffer, int & outIt, int version, int mapVersion )
|
2010-02-11 16:12:22 +02:00
|
|
|
{
|
|
|
|
struct HLP
|
|
|
|
{
|
|
|
|
//reads prolog/epilog info from memory
|
2011-12-14 00:23:17 +03:00
|
|
|
static CCampaignScenario::SScenarioPrologEpilog prologEpilogReader( const ui8 *buffer, int & outIt )
|
2010-02-11 16:12:22 +02:00
|
|
|
{
|
|
|
|
CCampaignScenario::SScenarioPrologEpilog ret;
|
|
|
|
ret.hasPrologEpilog = buffer[outIt++];
|
|
|
|
if(ret.hasPrologEpilog)
|
|
|
|
{
|
|
|
|
ret.prologVideo = buffer[outIt++];
|
|
|
|
ret.prologMusic = buffer[outIt++];
|
|
|
|
ret.prologText = readString(buffer, outIt);
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
CCampaignScenario ret;
|
2010-02-16 19:28:56 +02:00
|
|
|
ret.conquered = false;
|
2010-02-11 16:12:22 +02:00
|
|
|
ret.mapName = readString(buffer, outIt);
|
2011-10-08 04:23:46 +03:00
|
|
|
ret.packedMapSize = read_le_u32(buffer + outIt); outIt += 4;
|
2010-02-15 15:28:33 +02:00
|
|
|
if(mapVersion == 18)//unholy alliance
|
2010-02-16 19:28:56 +02:00
|
|
|
{
|
2012-01-19 17:33:22 +03:00
|
|
|
ret.loadPreconditionRegions(read_le_u16(buffer + outIt)); outIt += 2;
|
2010-02-16 19:28:56 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-01-19 17:33:22 +03:00
|
|
|
ret.loadPreconditionRegions(buffer[outIt++]);
|
2010-02-16 19:28:56 +02:00
|
|
|
}
|
2010-02-11 16:12:22 +02:00
|
|
|
ret.regionColor = buffer[outIt++];
|
|
|
|
ret.difficulty = buffer[outIt++];
|
|
|
|
ret.regionText = readString(buffer, outIt);
|
|
|
|
ret.prolog = HLP::prologEpilogReader(buffer, outIt);
|
|
|
|
ret.epilog = HLP::prologEpilogReader(buffer, outIt);
|
|
|
|
|
2010-02-15 14:12:21 +02:00
|
|
|
ret.travelOptions = readScenarioTravelFromMemory(buffer, outIt, version);
|
2010-02-11 16:12:22 +02:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-01-19 17:33:22 +03:00
|
|
|
void CCampaignScenario::loadPreconditionRegions(ui32 regions)
|
|
|
|
{
|
|
|
|
for (int i=0; i<32; i++) //for each bit in region. h3c however can only hold up to 16
|
|
|
|
{
|
|
|
|
if ( (1 << i) & regions)
|
|
|
|
preconditionRegions.insert(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-14 00:23:17 +03:00
|
|
|
CScenarioTravel CCampaignHandler::readScenarioTravelFromMemory( const ui8 * buffer, int & outIt , int version )
|
2010-02-11 16:12:22 +02:00
|
|
|
{
|
|
|
|
CScenarioTravel ret;
|
|
|
|
|
|
|
|
ret.whatHeroKeeps = buffer[outIt++];
|
|
|
|
memcpy(ret.monstersKeptByHero, buffer+outIt, ARRAY_COUNT(ret.monstersKeptByHero));
|
|
|
|
outIt += ARRAY_COUNT(ret.monstersKeptByHero);
|
2010-02-15 14:12:21 +02:00
|
|
|
int artifBytes;
|
2011-11-27 16:14:20 +03:00
|
|
|
if (version < CampaignVersion::SoD)
|
2010-02-15 14:12:21 +02:00
|
|
|
{
|
|
|
|
artifBytes = 17;
|
|
|
|
ret.artifsKeptByHero[17] = 0;
|
|
|
|
}
|
2011-11-27 16:14:20 +03:00
|
|
|
else
|
2010-02-15 14:12:21 +02:00
|
|
|
{
|
|
|
|
artifBytes = 18;
|
|
|
|
}
|
|
|
|
memcpy(ret.artifsKeptByHero, buffer+outIt, artifBytes);
|
|
|
|
outIt += artifBytes;
|
2010-02-11 16:12:22 +02:00
|
|
|
|
|
|
|
ret.startOptions = buffer[outIt++];
|
|
|
|
|
|
|
|
switch(ret.startOptions)
|
|
|
|
{
|
2010-02-16 19:28:56 +02:00
|
|
|
case 0:
|
|
|
|
//no bonuses. Seems to be OK
|
|
|
|
break;
|
2010-02-11 16:12:22 +02:00
|
|
|
case 1: //reading of bonuses player can choose
|
|
|
|
{
|
|
|
|
ret.playerColor = buffer[outIt++];
|
|
|
|
ui8 numOfBonuses = buffer[outIt++];
|
|
|
|
for (int g=0; g<numOfBonuses; ++g)
|
|
|
|
{
|
|
|
|
CScenarioTravel::STravelBonus bonus;
|
|
|
|
bonus.type = buffer[outIt++];
|
2010-07-31 16:55:05 +03:00
|
|
|
//hero: FFFD means 'most powerful' and FFFE means 'generated'
|
2010-02-11 16:12:22 +02:00
|
|
|
switch(bonus.type)
|
|
|
|
{
|
2012-09-22 18:16:45 +03:00
|
|
|
case CScenarioTravel::STravelBonus::SPELL:
|
2010-02-11 16:12:22 +02:00
|
|
|
{
|
2011-10-08 04:23:46 +03:00
|
|
|
bonus.info1 = read_le_u16(buffer + outIt); outIt += 2; //hero
|
2010-02-11 16:12:22 +02:00
|
|
|
bonus.info2 = buffer[outIt++]; //spell ID
|
|
|
|
break;
|
|
|
|
}
|
2012-09-22 18:16:45 +03:00
|
|
|
case CScenarioTravel::STravelBonus::MONSTER:
|
2010-02-11 16:12:22 +02:00
|
|
|
{
|
2011-10-08 04:23:46 +03:00
|
|
|
bonus.info1 = read_le_u16(buffer + outIt); outIt += 2; //hero
|
|
|
|
bonus.info2 = read_le_u16(buffer + outIt); outIt += 2; //monster type
|
|
|
|
bonus.info3 = read_le_u16(buffer + outIt); outIt += 2; //monster count
|
2010-02-11 16:12:22 +02:00
|
|
|
break;
|
|
|
|
}
|
2012-09-22 18:16:45 +03:00
|
|
|
case CScenarioTravel::STravelBonus::BUILDING:
|
2010-02-11 16:12:22 +02:00
|
|
|
{
|
2010-02-12 17:04:01 +02:00
|
|
|
bonus.info1 = buffer[outIt++]; //building ID (0 - town hall, 1 - city hall, 2 - capitol, etc)
|
2010-02-11 16:12:22 +02:00
|
|
|
break;
|
|
|
|
}
|
2012-09-22 18:16:45 +03:00
|
|
|
case CScenarioTravel::STravelBonus::ARTIFACT:
|
2010-02-11 16:12:22 +02:00
|
|
|
{
|
2011-10-08 04:23:46 +03:00
|
|
|
bonus.info1 = read_le_u16(buffer + outIt); outIt += 2; //hero
|
|
|
|
bonus.info2 = read_le_u16(buffer + outIt); outIt += 2; //artifact ID
|
2010-02-11 16:12:22 +02:00
|
|
|
break;
|
|
|
|
}
|
2012-09-22 18:16:45 +03:00
|
|
|
case CScenarioTravel::STravelBonus::SPELL_SCROLL:
|
2010-02-11 16:12:22 +02:00
|
|
|
{
|
2011-10-08 04:23:46 +03:00
|
|
|
bonus.info1 = read_le_u16(buffer + outIt); outIt += 2; //hero
|
2010-02-15 14:12:21 +02:00
|
|
|
bonus.info2 = buffer[outIt++]; //spell ID
|
2010-02-11 16:12:22 +02:00
|
|
|
break;
|
|
|
|
}
|
2012-09-22 18:16:45 +03:00
|
|
|
case CScenarioTravel::STravelBonus::PRIMARY_SKILL:
|
2010-02-11 16:12:22 +02:00
|
|
|
{
|
2011-10-08 04:23:46 +03:00
|
|
|
bonus.info1 = read_le_u16(buffer + outIt); outIt += 2; //hero
|
|
|
|
bonus.info2 = read_le_u32(buffer + outIt); outIt += 4; //bonuses (4 bytes for 4 skills)
|
2010-02-11 16:12:22 +02:00
|
|
|
break;
|
|
|
|
}
|
2012-09-22 18:16:45 +03:00
|
|
|
case CScenarioTravel::STravelBonus::SECONDARY_SKILL:
|
2010-02-11 16:12:22 +02:00
|
|
|
{
|
2011-10-08 04:23:46 +03:00
|
|
|
bonus.info1 = read_le_u16(buffer + outIt); outIt += 2; //hero
|
2010-02-11 16:12:22 +02:00
|
|
|
bonus.info2 = buffer[outIt++]; //skill ID
|
|
|
|
bonus.info3 = buffer[outIt++]; //skill level
|
|
|
|
break;
|
|
|
|
}
|
2012-09-22 18:16:45 +03:00
|
|
|
case CScenarioTravel::STravelBonus::RESOURCE:
|
2010-02-11 16:12:22 +02:00
|
|
|
{
|
|
|
|
bonus.info1 = buffer[outIt++]; //type
|
|
|
|
//FD - wood+ore
|
|
|
|
//FE - mercury+sulfur+crystal+gem
|
2011-10-08 04:23:46 +03:00
|
|
|
bonus.info2 = read_le_u32(buffer + outIt); outIt += 4; //count
|
2010-02-11 16:12:22 +02:00
|
|
|
break;
|
|
|
|
}
|
2012-09-22 20:23:28 +03:00
|
|
|
default:
|
|
|
|
tlog1<<"Corrupted h3c file"<<std::endl;
|
|
|
|
break;
|
2010-02-11 16:12:22 +02:00
|
|
|
}
|
|
|
|
ret.bonusesToChoose.push_back(bonus);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 2: //reading of players (colors / scenarios ?) player can choose
|
|
|
|
{
|
|
|
|
ui8 numOfBonuses = buffer[outIt++];
|
|
|
|
for (int g=0; g<numOfBonuses; ++g)
|
|
|
|
{
|
|
|
|
CScenarioTravel::STravelBonus bonus;
|
2012-09-22 18:16:45 +03:00
|
|
|
bonus.type = CScenarioTravel::STravelBonus::PLAYER_PREV_SCENARIO;
|
2010-02-11 16:12:22 +02:00
|
|
|
bonus.info1 = buffer[outIt++]; //player color
|
|
|
|
bonus.info2 = buffer[outIt++]; //from what scenario
|
|
|
|
|
|
|
|
ret.bonusesToChoose.push_back(bonus);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 3: //heroes player can choose between
|
|
|
|
{
|
|
|
|
ui8 numOfBonuses = buffer[outIt++];
|
|
|
|
for (int g=0; g<numOfBonuses; ++g)
|
|
|
|
{
|
|
|
|
CScenarioTravel::STravelBonus bonus;
|
2012-09-22 18:16:45 +03:00
|
|
|
bonus.type = CScenarioTravel::STravelBonus::HERO;
|
2010-02-11 16:12:22 +02:00
|
|
|
bonus.info1 = buffer[outIt++]; //player color
|
2011-10-08 04:23:46 +03:00
|
|
|
bonus.info2 = read_le_u16(buffer + outIt); outIt += 2; //hero, FF FF - random
|
2010-02-11 16:12:22 +02:00
|
|
|
|
|
|
|
ret.bonusesToChoose.push_back(bonus);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
tlog1<<"Corrupted h3c file"<<std::endl;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-02-08 16:39:19 +02:00
|
|
|
return ret;
|
2010-02-12 17:04:01 +02:00
|
|
|
}
|
|
|
|
|
2012-08-02 14:03:26 +03:00
|
|
|
std::vector< std::vector<ui8> > CCampaignHandler::getFile(const std::string & name, bool headerOnly)
|
2010-02-12 17:04:01 +02:00
|
|
|
{
|
2012-08-02 14:03:26 +03:00
|
|
|
CCompressedStream stream(std::move(CResourceHandler::get()->load(ResourceID(name, EResType::CAMPAIGN))), true);
|
2010-02-12 17:04:01 +02:00
|
|
|
|
2012-08-02 14:03:26 +03:00
|
|
|
std::vector< std::vector<ui8> > ret;
|
|
|
|
do
|
2010-02-12 17:04:01 +02:00
|
|
|
{
|
2012-08-02 14:03:26 +03:00
|
|
|
std::vector<ui8> block(stream.getSize());
|
|
|
|
stream.read(block.data(), block.size());
|
|
|
|
ret.push_back(block);
|
2010-02-12 17:04:01 +02:00
|
|
|
}
|
2012-08-02 14:03:26 +03:00
|
|
|
while (!headerOnly && stream.getNextBlock());
|
2010-02-16 19:28:56 +02:00
|
|
|
|
2012-08-02 14:03:26 +03:00
|
|
|
return ret;
|
2010-02-18 16:09:16 +02:00
|
|
|
}
|
|
|
|
|
2010-02-16 19:28:56 +02:00
|
|
|
bool CCampaign::conquerable( int whichScenario ) const
|
|
|
|
{
|
2010-07-30 14:29:42 +03:00
|
|
|
//check for void scenraio
|
|
|
|
if (!scenarios[whichScenario].isNotVoid())
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-02-16 19:28:56 +02:00
|
|
|
if (scenarios[whichScenario].conquered)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
//check preconditioned regions
|
|
|
|
for (int g=0; g<scenarios.size(); ++g)
|
|
|
|
{
|
2012-01-19 17:33:22 +03:00
|
|
|
if( vstd::contains(scenarios[whichScenario].preconditionRegions, g) && !scenarios[g].conquered)
|
2010-02-16 19:28:56 +02:00
|
|
|
return false; //prerequisite does not met
|
|
|
|
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2010-05-08 21:56:38 +03:00
|
|
|
|
|
|
|
CCampaign::CCampaign()
|
|
|
|
{
|
|
|
|
|
2010-07-30 14:29:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CCampaignScenario::isNotVoid() const
|
|
|
|
{
|
|
|
|
return mapName.size() > 0;
|
|
|
|
}
|
2010-07-31 16:55:05 +03:00
|
|
|
|
2010-08-28 17:52:20 +03:00
|
|
|
void CCampaignScenario::prepareCrossoverHeroes( std::vector<CGHeroInstance *> heroes )
|
|
|
|
{
|
|
|
|
crossoverHeroes = heroes;
|
2010-09-04 17:49:15 +03:00
|
|
|
|
2010-08-28 17:52:20 +03:00
|
|
|
|
|
|
|
if (!(travelOptions.whatHeroKeeps & 1))
|
|
|
|
{
|
|
|
|
//trimming experience
|
|
|
|
BOOST_FOREACH(CGHeroInstance * cgh, crossoverHeroes)
|
|
|
|
{
|
|
|
|
cgh->initExp();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!(travelOptions.whatHeroKeeps & 2))
|
|
|
|
{
|
|
|
|
//trimming prim skills
|
|
|
|
BOOST_FOREACH(CGHeroInstance * cgh, crossoverHeroes)
|
|
|
|
{
|
|
|
|
#define RESET_PRIM_SKILL(NAME, VALNAME) \
|
2012-09-20 19:55:21 +03:00
|
|
|
cgh->getBonusLocalFirst(Selector::type(Bonus::PRIMARY_SKILL) && \
|
2010-08-28 17:52:20 +03:00
|
|
|
Selector::subtype(PrimarySkill::NAME) && \
|
|
|
|
Selector::sourceType(Bonus::HERO_BASE_SKILL) )->val = cgh->type->heroClass->VALNAME;
|
|
|
|
|
|
|
|
RESET_PRIM_SKILL(ATTACK, initialAttack);
|
|
|
|
RESET_PRIM_SKILL(DEFENSE, initialDefence);
|
|
|
|
RESET_PRIM_SKILL(SPELL_POWER, initialPower);
|
|
|
|
RESET_PRIM_SKILL(KNOWLEDGE, initialKnowledge);
|
|
|
|
#undef RESET_PRIM_SKILL
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!(travelOptions.whatHeroKeeps & 4))
|
|
|
|
{
|
|
|
|
//trimming sec skills
|
|
|
|
BOOST_FOREACH(CGHeroInstance * cgh, crossoverHeroes)
|
|
|
|
{
|
|
|
|
cgh->secSkills = cgh->type->secSkillsInit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!(travelOptions.whatHeroKeeps & 8))
|
|
|
|
{
|
|
|
|
//trimming spells
|
|
|
|
BOOST_FOREACH(CGHeroInstance * cgh, crossoverHeroes)
|
|
|
|
{
|
|
|
|
cgh->spells.clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!(travelOptions.whatHeroKeeps & 16))
|
|
|
|
{
|
|
|
|
//trimming artifacts
|
2012-01-19 17:33:22 +03:00
|
|
|
BOOST_FOREACH(CGHeroInstance * hero, crossoverHeroes)
|
2010-08-28 17:52:20 +03:00
|
|
|
{
|
2012-01-19 17:33:22 +03:00
|
|
|
size_t totalArts = GameConstants::BACKPACK_START + hero->artifactsInBackpack.size();
|
|
|
|
for (size_t i=0; i<totalArts; i++ )
|
2010-08-28 17:52:20 +03:00
|
|
|
{
|
2012-01-19 17:33:22 +03:00
|
|
|
const ArtSlotInfo *info = hero->getSlot(i);
|
|
|
|
if (!info)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
const CArtifactInstance *art = info->artifact;
|
|
|
|
if (!art)//FIXME: check spellbook and catapult behaviour
|
|
|
|
continue;
|
|
|
|
|
|
|
|
int id = art->artType->id;
|
|
|
|
assert( 8*18 > id );//number of arts that fits into h3m format
|
|
|
|
bool takeable = travelOptions.artifsKeptByHero[id / 8] & ( 1 << (id%8) );
|
|
|
|
|
|
|
|
if (takeable)
|
|
|
|
hero->eraseArtSlot(i);
|
2010-08-28 17:52:20 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//trimming creatures
|
|
|
|
BOOST_FOREACH(CGHeroInstance * cgh, crossoverHeroes)
|
|
|
|
{
|
2010-12-06 01:10:02 +02:00
|
|
|
for (TSlots::const_iterator j = cgh->Slots().begin(); j != cgh->Slots().end(); j++)
|
2010-08-28 17:52:20 +03:00
|
|
|
{
|
2010-12-06 01:10:02 +02:00
|
|
|
if (!(travelOptions.monstersKeptByHero[j->first / 8] & (1 << (j->first%8)) ))
|
2010-08-28 17:52:20 +03:00
|
|
|
{
|
2010-12-06 01:10:02 +02:00
|
|
|
cgh->eraseStack(j->first);
|
|
|
|
j = cgh->Slots().begin();
|
2010-08-28 17:52:20 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-31 16:55:05 +03:00
|
|
|
bool CScenarioTravel::STravelBonus::isBonusForHero() const
|
|
|
|
{
|
2012-09-22 18:16:45 +03:00
|
|
|
return type == SPELL || type == MONSTER || type == ARTIFACT || type == SPELL_SCROLL || type == PRIMARY_SKILL
|
|
|
|
|| type == SECONDARY_SKILL;
|
2010-07-31 16:55:05 +03:00
|
|
|
}
|
2010-08-04 14:18:13 +03:00
|
|
|
|
2012-09-21 20:59:54 +03:00
|
|
|
// void CCampaignState::initNewCampaign( const StartInfo &si )
|
|
|
|
// {
|
|
|
|
// assert(si.mode == StartInfo::CAMPAIGN);
|
|
|
|
// campaignName = si.mapname;
|
|
|
|
// currentMap = si.campState->currentMap;
|
|
|
|
//
|
|
|
|
// camp = CCampaignHandler::getCampaign(campaignName);
|
|
|
|
// for (ui8 i = 0; i < camp->mapPieces.size(); i++)
|
|
|
|
// mapsRemaining.push_back(i);
|
|
|
|
// }
|
2010-08-20 16:34:39 +03:00
|
|
|
|
2010-08-28 17:52:20 +03:00
|
|
|
void CCampaignState::mapConquered( const std::vector<CGHeroInstance*> & heroes )
|
2010-08-20 16:34:39 +03:00
|
|
|
{
|
2010-08-28 17:52:20 +03:00
|
|
|
camp->scenarios[currentMap].prepareCrossoverHeroes(heroes);
|
2010-08-20 16:34:39 +03:00
|
|
|
mapsConquered.push_back(currentMap);
|
|
|
|
mapsRemaining -= currentMap;
|
|
|
|
camp->scenarios[currentMap].conquered = true;
|
2011-10-08 04:23:46 +03:00
|
|
|
}
|
2012-09-21 20:59:54 +03:00
|
|
|
|
|
|
|
CScenarioTravel::STravelBonus CCampaignState::getBonusForCurrentMap() const
|
|
|
|
{
|
|
|
|
assert(chosenCampaignBonuses.count(currentMap));
|
|
|
|
return getCurrentScenario().travelOptions.bonusesToChoose[currentBonusID()];
|
|
|
|
}
|
|
|
|
|
|
|
|
const CCampaignScenario & CCampaignState::getCurrentScenario() const
|
|
|
|
{
|
|
|
|
return camp->scenarios[currentMap];
|
|
|
|
}
|
|
|
|
|
|
|
|
ui8 CCampaignState::currentBonusID() const
|
|
|
|
{
|
|
|
|
return chosenCampaignBonuses[currentMap];
|
|
|
|
}
|
2012-09-22 18:16:45 +03:00
|
|
|
|
|
|
|
CCampaignState::CCampaignState()
|
|
|
|
{}
|
|
|
|
|
|
|
|
CCampaignState::CCampaignState( unique_ptr<CCampaign> _camp ) : camp(std::move(_camp))
|
|
|
|
{
|
|
|
|
for(int i = 0; i < camp->scenarios.size(); i++)
|
|
|
|
{
|
|
|
|
mapsRemaining.push_back(i);
|
|
|
|
}
|
|
|
|
}
|