mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-26 22:57:00 +02:00
* reading ZCRBANK.TXT config file
* fixed off by one error reported here: http://antypika.aplus.pl/vcmi/forum/viewtopic.php?p=3324&sid=ee179a979bdc27add85c21c72161f539#3324
This commit is contained in:
parent
8458a03e85
commit
de886abc0e
@ -76,6 +76,7 @@
|
||||
74 Beholder
|
||||
75 EvilEye
|
||||
76 Medusa
|
||||
76 Medusae
|
||||
77 MedusaQueen
|
||||
78 Minotaur
|
||||
79 MinotaurKing
|
||||
|
@ -21,6 +21,7 @@
|
||||
#include "../lib/NetPacks.h"
|
||||
#include "../StartInfo.h"
|
||||
#include "../lib/map.h"
|
||||
#include <sstream>
|
||||
using namespace boost::assign;
|
||||
|
||||
/*
|
||||
@ -74,6 +75,46 @@ bool CPlayersVisited::hasVisited( ui8 player ) const
|
||||
return vstd::contains(players,player);
|
||||
}
|
||||
|
||||
static void readCreatures(std::istream & is, BankConfig & bc, bool guards) //helper function for void CObjectHandler::loadObjects()
|
||||
{
|
||||
const int MAX_BUF = 5000;
|
||||
char buffer[MAX_BUF + 1];
|
||||
std::pair<si16, si32> guardInfo = std::make_pair(0, 0);
|
||||
std::string creName;
|
||||
|
||||
is >> guardInfo.first;
|
||||
//one getline just does not work... probably a kind of left whitespace
|
||||
is.getline(buffer, MAX_BUF, '\t');
|
||||
is.getline(buffer, MAX_BUF, '\t');
|
||||
creName = buffer;
|
||||
|
||||
if( std::string(buffer) == "None" ) //no creature to be added
|
||||
return;
|
||||
|
||||
//look for the best creature that is described by given name
|
||||
if( vstd::contains(VLC->creh->nameToID, creName) )
|
||||
{
|
||||
guardInfo.second = VLC->creh->nameToID[creName];
|
||||
}
|
||||
else
|
||||
{
|
||||
for(int g=0; g<VLC->creh->creatures.size(); ++g)
|
||||
{
|
||||
if(VLC->creh->creatures[g].namePl == creName
|
||||
|| VLC->creh->creatures[g].nameRef == creName
|
||||
|| VLC->creh->creatures[g].nameSing == creName)
|
||||
{
|
||||
guardInfo.second = VLC->creh->creatures[g].idNumber;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(guards)
|
||||
bc.guards.push_back(guardInfo);
|
||||
else //given creatures
|
||||
bc.creatures.push_back(guardInfo);
|
||||
}
|
||||
|
||||
void CObjectHandler::loadObjects()
|
||||
{
|
||||
{
|
||||
@ -93,11 +134,64 @@ void CObjectHandler::loadObjects()
|
||||
tlog5 << "\t\tDone loading objects!\n";
|
||||
}
|
||||
|
||||
int i = 0;
|
||||
std::string banksConfig = bitmaph->getTextFile("ZCRBANK.TXT");
|
||||
|
||||
//TODO: parse to banksInfo
|
||||
std::istringstream istr(banksConfig);
|
||||
const int MAX_BUF = 5000;
|
||||
char buffer[MAX_BUF + 1];
|
||||
|
||||
//omitting unnecessary lines
|
||||
istr.getline(buffer, MAX_BUF);
|
||||
istr.getline(buffer, MAX_BUF);
|
||||
|
||||
for(int g=0; g<21; ++g) //TODO: remove hardcoded value
|
||||
{
|
||||
//reading name - TODO: use it if necessary
|
||||
istr.getline(buffer, MAX_BUF, '\t');
|
||||
|
||||
for(int i=0; i<4; ++i) //reading levels
|
||||
{
|
||||
BankConfig bc;
|
||||
std::string buf;
|
||||
char dump;
|
||||
//bc.level is of type char and thus we cannot read directly to it; same for some othre variables
|
||||
istr >> buf;
|
||||
bc.level = atoi(buf.c_str());
|
||||
|
||||
istr >> buf;
|
||||
bc.chance = atoi(buf.c_str());
|
||||
|
||||
readCreatures(istr, bc, true);
|
||||
istr >> buf;
|
||||
bc.upgradeChance = atoi(buf.c_str());
|
||||
|
||||
for(int b=0; b<3; ++b)
|
||||
readCreatures(istr, bc, true);
|
||||
|
||||
istr >> bc.combatValue;
|
||||
bc.resources.resize(RESOURCE_QUANTITY);
|
||||
for(int h=0; h<7; ++h)
|
||||
{
|
||||
istr >> bc.resources[h];
|
||||
}
|
||||
readCreatures(istr, bc, false);
|
||||
|
||||
bc.artifacts.resize(4);
|
||||
for(int b=0; b<4; ++b)
|
||||
{
|
||||
istr >> bc.artifacts[b];
|
||||
}
|
||||
|
||||
istr >> bc.value;
|
||||
istr >> bc.rewardDifficulty;
|
||||
istr >> buf;
|
||||
bc.easiest = atoi(buf.c_str());
|
||||
|
||||
banksInfo[g].push_back(bc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int CGObjectInstance::getOwner() const
|
||||
{
|
||||
//if (state)
|
||||
@ -3698,17 +3792,20 @@ void CBank::endBattle (const CGHeroInstance *h, const BattleResult *result) cons
|
||||
}
|
||||
iw.text.addTxt (MetaString::ADVOB_TXT, textID);
|
||||
iw.player = cb->getCurrentPlayer();
|
||||
for (std::map<ui8, si32>::iterator it = bc->resources.begin(); it != bc->resources.end(); it++)
|
||||
//grant resources
|
||||
for (int it = 0; it < bc->resources.size(); ++it)
|
||||
{
|
||||
iw.components.push_back (Component (Component::RESOURCE, it->first, it->second, 0));
|
||||
cb->giveResource (cb->getCurrentPlayer(), it->first, it->second);
|
||||
iw.components.push_back (Component (Component::RESOURCE, it, bc->resources[it], 0));
|
||||
cb->giveResource (cb->getCurrentPlayer(), it, bc->resources[it]);
|
||||
}
|
||||
//grant artifacts
|
||||
for (std::vector<si32>::const_iterator it = artifacts.begin(); it != artifacts.end(); it++)
|
||||
{
|
||||
iw.components.push_back (Component (Component::ARTIFACT, *it, 0, 0));
|
||||
iw.text.addReplacement (MetaString::ART_NAMES, *it);
|
||||
cb->giveHeroArtifact (*it, cb->getSelectedHero() ,-2);
|
||||
}
|
||||
//grant creatures
|
||||
CCreatureSet ourArmy;
|
||||
for (std::vector< std::pair <ui16, ui32> >::const_iterator it = bc->creatures.begin(); it != bc->creatures.end(); it++)
|
||||
{
|
||||
|
@ -900,26 +900,26 @@ public:
|
||||
h & players;
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
struct BankConfig
|
||||
{
|
||||
BankConfig() {chance = upgradeChance = combatValue = value = rewardDifficulty = easiest = 0; };
|
||||
//std::string name;
|
||||
ui8 chance;
|
||||
ui8 upgradeChance;
|
||||
std::vector< std::pair <ui16, ui32> > guards;
|
||||
ui32 combatValue;
|
||||
std::map<ui8, si32> resources;
|
||||
std::vector< std::pair <ui16, ui32> > creatures;
|
||||
std::map<ui8, ui16> artifacts;
|
||||
ui32 value;
|
||||
ui32 rewardDifficulty; //?
|
||||
ui16 easiest; //?
|
||||
BankConfig() {level = chance = upgradeChance = combatValue = value = rewardDifficulty = easiest = 0; };
|
||||
ui8 level; //1 - 4, how hard the battle will be
|
||||
ui8 chance; //chance for this level being chosen
|
||||
ui8 upgradeChance; //chance for creatures to be in upgraded versions
|
||||
std::vector< std::pair <ui16, ui32> > guards; //creature ID -> amount
|
||||
ui32 combatValue; //how hard are guards of this level
|
||||
std::vector<si32> resources; //resources given in case of victory
|
||||
std::vector< std::pair <ui16, ui32> > creatures; //creatures granted in case of victory
|
||||
std::vector<ui16> artifacts; //number of artifacts given in case of victory [0] -> treasure, [1] -> minor [2] -> major [3] -> relic
|
||||
ui32 value; //overall value of given things
|
||||
ui32 rewardDifficulty; //proportion of reward value to difficulty of guards; how profitable is this creature Bank config
|
||||
ui16 easiest; //?!?
|
||||
|
||||
template <typename Handler> void serialize(Handler &h, const int version)
|
||||
{
|
||||
h & chance & upgradeChance & guards & combatValue & resources & creatures & artifacts
|
||||
h & level & chance & upgradeChance & guards & combatValue & resources & creatures & artifacts
|
||||
& value & rewardDifficulty & easiest;
|
||||
}
|
||||
};
|
||||
|
@ -378,6 +378,10 @@ std::vector<int> BattleInfo::getAccessibility(int stackID, bool addOccupiable)
|
||||
std::vector<int> rem;
|
||||
for(int b=0; b<BFIELD_SIZE; ++b)
|
||||
{
|
||||
//don't take into account most left and most right columns of hexes
|
||||
if( b % BFIELD_WIDTH == 0 || b % BFIELD_WIDTH == BFIELD_WIDTH - 1 )
|
||||
continue;
|
||||
|
||||
if( ac[b] && !(s->attackerOwned ? ac[b-1] : ac[b+1]) )
|
||||
{
|
||||
rem.push_back(b);
|
||||
|
Loading…
Reference in New Issue
Block a user