mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +02:00
parent
7759ed017e
commit
15a7f43e11
@ -241,7 +241,7 @@ struct AttackPossibility
|
||||
};
|
||||
|
||||
template<typename Key, typename Val>
|
||||
const Val &getValOr(const std::map<Key, Val> &Map, const Key &key, const Key &defaultValue)
|
||||
const Val &getValOr(const std::map<Key, Val> &Map, const Key &key, const Val &defaultValue)
|
||||
{
|
||||
auto i = Map.find(key);
|
||||
if(i != Map.end())
|
||||
@ -279,8 +279,8 @@ struct PotentialTargets
|
||||
GenerateAttackInfo = [&](bool shooting, BattleHex hex) -> AttackPossibility
|
||||
{
|
||||
auto bai = BattleAttackInfo(attacker, enemy, shooting);
|
||||
bai.attackerBonuses = getValOr(state.bonusesOfStacks, bai.attacker, bai.attacker);
|
||||
bai.defenderBonuses = getValOr(state.bonusesOfStacks, bai.defender, bai.defender);
|
||||
bai.attackerBonuses = getValOr(state.bonusesOfStacks, bai.attacker, static_cast<const IBonusBearer *>(bai.attacker));
|
||||
bai.defenderBonuses = getValOr(state.bonusesOfStacks, bai.defender, static_cast<const IBonusBearer *>(bai.defender));
|
||||
|
||||
AttackPossibility ap = {enemy, hex, bai, 0, 0};
|
||||
if(hex.isValid())
|
||||
|
@ -788,7 +788,7 @@ void CInfoBar::CVisibleInfo::loadGameStatus()
|
||||
}
|
||||
}
|
||||
|
||||
void CInfoBar::CVisibleInfo::loadComponent(const Component compToDisplay, std::string message)
|
||||
void CInfoBar::CVisibleInfo::loadComponent(const Component & compToDisplay, std::string message)
|
||||
{
|
||||
assert(children.empty()); // visible info should be re-created to change type
|
||||
|
||||
@ -889,7 +889,7 @@ void CInfoBar::showDate()
|
||||
redraw();
|
||||
}
|
||||
|
||||
void CInfoBar::showComponent(const Component comp, std::string message)
|
||||
void CInfoBar::showComponent(const Component & comp, std::string message)
|
||||
{
|
||||
reset(COMPONENT);
|
||||
visibleInfo->loadComponent(comp, message);
|
||||
|
@ -263,7 +263,7 @@ class CInfoBar : public CIntObject
|
||||
void loadDay();
|
||||
void loadEnemyTurn(int player);
|
||||
void loadGameStatus();
|
||||
void loadComponent(const Component comp, std::string message);
|
||||
void loadComponent(const Component &comp, std::string message);
|
||||
|
||||
//can be called multiple times
|
||||
void updateEnemyTurn(double progress);
|
||||
@ -295,7 +295,7 @@ public:
|
||||
void showDate();
|
||||
|
||||
/// show component for 3 seconds. Used to display picked up resources
|
||||
void showComponent(const Component comp, std::string message);
|
||||
void showComponent(const Component & comp, std::string message);
|
||||
|
||||
/// print enemy turn progress
|
||||
void startEnemyTurn(ui8 color);
|
||||
|
@ -118,7 +118,7 @@ SettingsListener::~SettingsListener()
|
||||
parent.listeners.erase(this);
|
||||
}
|
||||
|
||||
void SettingsListener::nodeInvalidated(const std::vector<std::string> changedPath)
|
||||
void SettingsListener::nodeInvalidated(const std::vector<std::string> &changedPath)
|
||||
{
|
||||
if (!callback)
|
||||
return;
|
||||
|
@ -68,7 +68,7 @@ class SettingsListener
|
||||
SettingsListener(SettingsStorage &_parent, const std::vector<std::string> &_path);
|
||||
|
||||
// Executes callback if changedpath begins with path
|
||||
void nodeInvalidated(const std::vector<std::string> changedPath);
|
||||
void nodeInvalidated(const std::vector<std::string> & changedPath);
|
||||
|
||||
public:
|
||||
SettingsListener(const SettingsListener &sl);
|
||||
|
@ -471,7 +471,6 @@ void CCreatureWindow::recreateSkillList(int Pos)
|
||||
|
||||
int n = 0, i = 0, j = 0;
|
||||
int numSkills = std::min ((bonusRows + Pos) << 1, (int)bonusItems.size());
|
||||
std::string gfxName;
|
||||
for (n = 0; n < Pos << 1; ++n)
|
||||
{
|
||||
bonusItems[n]->visible = false;
|
||||
|
@ -372,8 +372,8 @@ void CHeroWindow::showAll(SDL_Surface * to)
|
||||
//secondary skills
|
||||
for(size_t v=0; v<std::min(secSkillAreas.size(), curHero->secSkills.size()); ++v)
|
||||
{
|
||||
printAtLoc(CGI->generaltexth->levels[curHero->secSkills[v].second-1], v%2 ? 212 : 68, 280 + 48 * (v/2), FONT_SMALL, Colors::Cornsilk, to);
|
||||
printAtLoc(CGI->generaltexth->skillName[curHero->secSkills[v].first], v%2 ? 212 : 68, 300 + 48 * (v/2), FONT_SMALL, Colors::Cornsilk, to);
|
||||
printAtLoc(CGI->generaltexth->levels[curHero->secSkills[v].second-1], (v%2) ? 212 : 68, 280 + 48 * (v/2), FONT_SMALL, Colors::Cornsilk, to);
|
||||
printAtLoc(CGI->generaltexth->skillName[curHero->secSkills[v].first], (v%2) ? 212 : 68, 300 + 48 * (v/2), FONT_SMALL, Colors::Cornsilk, to);
|
||||
}
|
||||
|
||||
//printing special ability
|
||||
|
@ -151,7 +151,7 @@ void updateStartInfo(std::string filename, StartInfo & sInfo, const CMapHeader *
|
||||
const PlayerInfo &pinfo = mapHeader->players[i];
|
||||
|
||||
//neither computer nor human can play - no player
|
||||
if (!(pinfo.canComputerPlay || pinfo.canComputerPlay))
|
||||
if (!(pinfo.canHumanPlay || pinfo.canComputerPlay))
|
||||
continue;
|
||||
|
||||
PlayerSettings &pset = sInfo.playerInfos[i];
|
||||
@ -1048,8 +1048,8 @@ void SelectionTab::parseMaps(const std::vector<ResourceID> &files, int start, in
|
||||
{
|
||||
try
|
||||
{
|
||||
CCompressedStream stream(std::move(CResourceHandler::get()->load(files[start])), true);
|
||||
int read = stream.read(mapBuffer, 1500);
|
||||
TInputStreamPtr stream(Mapa::getMapStream(files[start].getName()));
|
||||
int read = stream->read(mapBuffer, 1500);
|
||||
|
||||
if(read < 50 || !mapBuffer[4])
|
||||
throw std::runtime_error("corrupted map file");
|
||||
|
@ -317,7 +317,7 @@ bool CSmackPlayer::open( std::string name )
|
||||
|
||||
void CSmackPlayer::show( int x, int y, SDL_Surface *dst, bool update)
|
||||
{
|
||||
int w = data->width, h = data->height;
|
||||
int w = data->width;
|
||||
int stripe = (-w*2) & (~3);
|
||||
|
||||
//put frame to the buffer
|
||||
|
@ -5093,8 +5093,8 @@ void CTransformerWindow::CItem::update()
|
||||
icon->setFrame(parent->army->getCreature(id)->idNumber + 2);
|
||||
}
|
||||
|
||||
CTransformerWindow::CItem::CItem(CTransformerWindow * _parent, int _size, int _id):
|
||||
id(_id), size(_size), parent(_parent)
|
||||
CTransformerWindow::CItem::CItem(CTransformerWindow * parent, int size, int id):
|
||||
id(id), size(size), parent(parent)
|
||||
{
|
||||
OBJ_CONSTRUCTION_CAPTURING_ALL;
|
||||
addUsedEvents(LCLICK);
|
||||
|
@ -1062,7 +1062,7 @@ public:
|
||||
void move();
|
||||
void clickLeft(tribool down, bool previousState);
|
||||
void update();
|
||||
CItem(CTransformerWindow * _parent, int _size, int _id);
|
||||
CItem(CTransformerWindow * parent, int size, int id);
|
||||
};
|
||||
|
||||
const CArmedInstance *army;//object with army for transforming (hero or town)
|
||||
|
@ -228,8 +228,7 @@ void Graphics::loadHeroAnims()
|
||||
std::ostringstream nm;
|
||||
nm << "AH" << std::setw(2) << std::setfill('0') << i << "_.DEF";
|
||||
loadHeroAnim(nm.str(), rotations, &Graphics::heroAnims);
|
||||
std::string name = nm.str();
|
||||
}
|
||||
}
|
||||
|
||||
loadHeroAnim("AB01_.DEF", rotations, &Graphics::boatAnims);
|
||||
loadHeroAnim("AB02_.DEF", rotations, &Graphics::boatAnims);
|
||||
|
@ -434,12 +434,12 @@ void CAdventureMapButton::setPlayerColor(int player)
|
||||
image->playerColored(player);
|
||||
}
|
||||
|
||||
void CAdventureMapButton::showAll(SDL_Surface * to)
|
||||
void CAdventureMapButton::show(SDL_Surface * to)
|
||||
{
|
||||
CIntObject::showAll(to);
|
||||
CIntObject::show(to);
|
||||
|
||||
if (borderEnabled && borderColor.unused == 0)
|
||||
CSDL_Ext::drawBorder(to, pos.x - 1, pos.y - 1, pos.w + 2, pos.h + 2, int3(borderColor.r, borderColor.g, borderColor.b));
|
||||
CSDL_Ext::drawBorder(to, pos.x, pos.y, pos.w, pos.h, int3(borderColor.r, borderColor.g, borderColor.b));
|
||||
}
|
||||
|
||||
void CHighlightableButton::select(bool on)
|
||||
@ -1761,14 +1761,14 @@ void CWindowObject::updateShadow()
|
||||
|
||||
void CWindowObject::setShadow(bool on)
|
||||
{
|
||||
vstd::clear_pointer(shadow);
|
||||
|
||||
//size of shadow
|
||||
static const int size = 8;
|
||||
|
||||
if (on == bool(shadow))
|
||||
return;
|
||||
|
||||
vstd::clear_pointer(shadow);
|
||||
|
||||
//object too small to cast shadow
|
||||
if (pos.h <= size || pos.w <= size)
|
||||
return;
|
||||
|
@ -148,7 +148,7 @@ public:
|
||||
void setIndex(size_t index, bool playerColoredButton=false);
|
||||
void setImage(CAnimation* anim, bool playerColoredButton=false, int animFlags=0);
|
||||
void setPlayerColor(int player);
|
||||
void showAll(SDL_Surface * to);
|
||||
void show(SDL_Surface * to);
|
||||
};
|
||||
|
||||
/// A button which can be selected/deselected
|
||||
|
@ -250,86 +250,51 @@ void CCreatureHandler::loadCreatures()
|
||||
tlog5 << "\t\tReading config/cr_abils.json and ZCRTRAIT.TXT" << std::endl;
|
||||
|
||||
////////////reading ZCRTRAIT.TXT ///////////////////
|
||||
auto textFile = CResourceHandler::get()->loadData(ResourceID("DATA/ZCRTRAIT.TXT"));
|
||||
std::string buf((char*)textFile.first.get(), textFile.second);
|
||||
int andame = buf.size();
|
||||
int i=0; //buf iterator
|
||||
int hmcr=0;
|
||||
for(; i<andame; ++i)
|
||||
{
|
||||
if(buf[i]=='\r')
|
||||
++hmcr;
|
||||
if(hmcr==2)
|
||||
break;
|
||||
}
|
||||
i+=2;
|
||||
CLegacyConfigParser parser("DATA/ZCRTRAIT.TXT");
|
||||
|
||||
while(i<buf.size())
|
||||
parser.endLine(); // header
|
||||
parser.endLine();
|
||||
|
||||
do
|
||||
{
|
||||
//loop till non-empty line
|
||||
while (parser.isNextEntryEmpty())
|
||||
parser.endLine();
|
||||
|
||||
CCreature &ncre = *new CCreature;
|
||||
ncre.idNumber = creatures.size();
|
||||
ncre.cost.resize(GameConstants::RESOURCE_QUANTITY);
|
||||
ncre.level=0;
|
||||
ncre.iconIndex = ncre.idNumber + 2; // +2 for empty\selection images
|
||||
|
||||
int befi=i;
|
||||
for(; i<andame; ++i)
|
||||
{
|
||||
if(buf[i]=='\t')
|
||||
break;
|
||||
}
|
||||
ncre.nameSing = buf.substr(befi, i-befi);
|
||||
++i;
|
||||
|
||||
befi=i;
|
||||
for(; i<andame; ++i)
|
||||
{
|
||||
if(buf[i]=='\t')
|
||||
break;
|
||||
}
|
||||
ncre.namePl = buf.substr(befi, i-befi);
|
||||
++i;
|
||||
ncre.nameSing = parser.readString();
|
||||
ncre.namePl = parser.readString();
|
||||
|
||||
for(int v=0; v<7; ++v)
|
||||
{
|
||||
ncre.cost[v] = readNumber(befi, i, andame, buf);
|
||||
ncre.cost[v] = parser.readNumber();
|
||||
}
|
||||
ncre.fightValue = readNumber(befi, i, andame, buf);
|
||||
ncre.AIValue = readNumber(befi, i, andame, buf);
|
||||
ncre.growth = readNumber(befi, i, andame, buf);
|
||||
ncre.hordeGrowth = readNumber(befi, i, andame, buf);
|
||||
ncre.fightValue = parser.readNumber();
|
||||
ncre.AIValue = parser.readNumber();
|
||||
ncre.growth = parser.readNumber();
|
||||
ncre.hordeGrowth = parser.readNumber();
|
||||
|
||||
ncre.addBonus(readNumber(befi, i, andame, buf), Bonus::STACK_HEALTH);
|
||||
ncre.addBonus(readNumber(befi, i, andame, buf), Bonus::STACKS_SPEED);
|
||||
ncre.addBonus(readNumber(befi, i, andame, buf), Bonus::PRIMARY_SKILL, PrimarySkill::ATTACK);
|
||||
ncre.addBonus(readNumber(befi, i, andame, buf), Bonus::PRIMARY_SKILL, PrimarySkill::DEFENSE);
|
||||
ncre.addBonus(readNumber(befi, i, andame, buf), Bonus::CREATURE_DAMAGE, 1);
|
||||
ncre.addBonus(readNumber(befi, i, andame, buf), Bonus::CREATURE_DAMAGE, 2);
|
||||
ncre.addBonus(readNumber(befi, i, andame, buf), Bonus::SHOTS);
|
||||
ncre.addBonus(parser.readNumber(), Bonus::STACK_HEALTH);
|
||||
ncre.addBonus(parser.readNumber(), Bonus::STACKS_SPEED);
|
||||
ncre.addBonus(parser.readNumber(), Bonus::PRIMARY_SKILL, PrimarySkill::ATTACK);
|
||||
ncre.addBonus(parser.readNumber(), Bonus::PRIMARY_SKILL, PrimarySkill::DEFENSE);
|
||||
ncre.addBonus(parser.readNumber(), Bonus::CREATURE_DAMAGE, 1);
|
||||
ncre.addBonus(parser.readNumber(), Bonus::CREATURE_DAMAGE, 2);
|
||||
ncre.addBonus(parser.readNumber(), Bonus::SHOTS);
|
||||
|
||||
//spells - not used?
|
||||
readNumber(befi, i, andame, buf);
|
||||
ncre.ammMin = readNumber(befi, i, andame, buf);
|
||||
ncre.ammMax = readNumber(befi, i, andame, buf);
|
||||
parser.readNumber();
|
||||
ncre.ammMin = parser.readNumber();
|
||||
ncre.ammMax = parser.readNumber();
|
||||
|
||||
befi=i;
|
||||
for(; i<andame; ++i)
|
||||
{
|
||||
if(buf[i]=='\t')
|
||||
break;
|
||||
}
|
||||
ncre.abilityText = buf.substr(befi, i-befi);
|
||||
++i;
|
||||
ncre.abilityText = parser.readString();
|
||||
ncre.abilityRefs = parser.readString();
|
||||
|
||||
befi=i;
|
||||
for(; i<andame; ++i)
|
||||
{
|
||||
if(buf[i]=='\r')
|
||||
break;
|
||||
}
|
||||
ncre.abilityRefs = buf.substr(befi, i-befi);
|
||||
i+=2;
|
||||
if(true)
|
||||
{ //adding abilities from ZCRTRAIT.TXT
|
||||
if(boost::algorithm::find_first(ncre.abilityRefs, "DOUBLE_WIDE"))
|
||||
ncre.doubleWide = true;
|
||||
@ -379,13 +344,9 @@ void CCreatureHandler::loadCreatures()
|
||||
if(boost::algorithm::find_first(ncre.abilityRefs, "HAS_EXTENDED_ATTACK"))
|
||||
ncre.addBonus(0, Bonus::TWO_HEX_ATTACK_BREATH);;
|
||||
}
|
||||
|
||||
if(ncre.nameSing!=std::string("") && ncre.namePl!=std::string(""))
|
||||
{
|
||||
ncre.idNumber = creatures.size();
|
||||
creatures.push_back(&ncre);
|
||||
}
|
||||
creatures.push_back(&ncre);
|
||||
}
|
||||
while (parser.endLine());
|
||||
|
||||
// loading creatures properties
|
||||
tlog5 << "\t\tReading config/creatures.json" << std::endl;
|
||||
@ -493,7 +454,7 @@ void CCreatureHandler::loadCreatures()
|
||||
addBonusForAllCreatures(b); //health bonus is common for all
|
||||
parser.endLine();
|
||||
|
||||
for (i = 1; i < 7; ++i)
|
||||
for (int i = 1; i < 7; ++i)
|
||||
{
|
||||
for (int j = 0; j < 4; ++j) //four modifiers common for tiers
|
||||
{
|
||||
@ -534,7 +495,7 @@ void CCreatureHandler::loadCreatures()
|
||||
expRanks[0].push_back(expRanks[0][j-1] + it + dif);
|
||||
dif += it/5;
|
||||
}
|
||||
for (i = 1; i < 8; ++i)
|
||||
for (int i = 1; i < 8; ++i)
|
||||
{
|
||||
dif = 0;
|
||||
it = 1000 * i;
|
||||
@ -551,7 +512,7 @@ void CCreatureHandler::loadCreatures()
|
||||
expBonParser.endLine(); //header
|
||||
|
||||
maxExpPerBattle.resize(8);
|
||||
for (i = 1; i < 8; ++i)
|
||||
for (int i = 1; i < 8; ++i)
|
||||
{
|
||||
expBonParser.readString(); //index
|
||||
expBonParser.readString(); //float multiplier -> hardcoded
|
||||
@ -585,7 +546,7 @@ void CCreatureHandler::loadCreatures()
|
||||
commanderLevelPremy.push_back(ParseBonus (bonus.Vector()));
|
||||
}
|
||||
|
||||
i = 0;
|
||||
int i = 0;
|
||||
BOOST_FOREACH (auto skill, config3["skillLevels"].Vector())
|
||||
{
|
||||
skillLevels.push_back (std::vector<ui8>());
|
||||
|
@ -387,7 +387,7 @@ CGHeroInstance * CGameState::HeroesPool::pickHeroFor(bool native, TPlayerColor p
|
||||
{
|
||||
CGHeroInstance *ret = NULL;
|
||||
|
||||
if(player<0 || player>=GameConstants::PLAYER_LIMIT)
|
||||
if(player>=GameConstants::PLAYER_LIMIT)
|
||||
{
|
||||
tlog1 << "Cannot pick hero for " << town->Name() << ". Wrong owner!\n";
|
||||
return NULL;
|
||||
|
@ -477,7 +477,7 @@ struct DLL_LINKAGE QuestInfo //universal interface for human and AI
|
||||
QuestInfo (const CQuest * Quest, const CGObjectInstance * Obj, int3 Tile) :
|
||||
quest (Quest), obj (Obj), tile (Tile){};
|
||||
|
||||
bool operator== (const QuestInfo qi) const
|
||||
bool operator== (const QuestInfo & qi) const
|
||||
{
|
||||
return (quest == qi.quest && obj == qi.obj);
|
||||
}
|
||||
|
@ -118,7 +118,11 @@ float CLegacyConfigParser::readNumber()
|
||||
|
||||
bool CLegacyConfigParser::isNextEntryEmpty()
|
||||
{
|
||||
return curr >= end || *curr == '\n' || *curr == '\r' || *curr == '\t';
|
||||
char * nextSymbol = curr;
|
||||
while (nextSymbol < end && *nextSymbol == ' ')
|
||||
nextSymbol++; //find next meaningfull symbol
|
||||
|
||||
return nextSymbol >= end || *nextSymbol == '\n' || *nextSymbol == '\r' || *nextSymbol == '\t';
|
||||
}
|
||||
|
||||
bool CLegacyConfigParser::endLine()
|
||||
|
@ -168,7 +168,7 @@ CCreature * CModHandler::loadCreature (const JsonNode &node)
|
||||
auto bonus = ParseBonus (exp["bonus"]);
|
||||
bonus->duration = Bonus::PERMANENT;
|
||||
const JsonVector &values = exp["values"].Vector();
|
||||
int lowerLimit = 1, upperLimit = 255;
|
||||
int lowerLimit = 1;//, upperLimit = 255;
|
||||
if (values[0].getType() == JsonNode::JsonType::DATA_BOOL)
|
||||
{
|
||||
BOOST_FOREACH (const JsonNode &val, values)
|
||||
|
@ -1500,7 +1500,6 @@ int CGHeroInstance::movementPointsAfterEmbark(int MPsBefore, int basicCost, bool
|
||||
|
||||
CGHeroInstance::ECanDig CGHeroInstance::diggingStatus() const
|
||||
{
|
||||
std::string hlp;
|
||||
if(movement < maxMovePoints(true))
|
||||
return LACK_OF_MOVEMENT;
|
||||
else if(cb->getTile(getPosition(false))->tertype == TerrainTile::water)
|
||||
@ -2328,11 +2327,11 @@ void CGTownInstance::recreateBuildingsBonuses()
|
||||
addBonusIfBuilt(EBuilding::FOUNTAIN_OF_FORTUNE, Bonus::LUCK, +2); //fountain of fortune
|
||||
addBonusIfBuilt(EBuilding::GRAIL, Bonus::LUCK, +2, make_shared<CPropagatorNodeType>(PLAYER)); //guardian spirit
|
||||
}
|
||||
else if(subID == ETownType::RAMPART) //tower
|
||||
else if(subID == ETownType::TOWER) //tower
|
||||
{
|
||||
addBonusIfBuilt(EBuilding::GRAIL, Bonus::PRIMARY_SKILL, +15, PrimarySkill::KNOWLEDGE); //grail
|
||||
}
|
||||
else if(subID == ETownType::TOWER) //Inferno
|
||||
else if(subID == ETownType::INFERNO) //Inferno
|
||||
{
|
||||
addBonusIfBuilt(EBuilding::STORMCLOUDS, Bonus::PRIMARY_SKILL, +2, PrimarySkill::SPELL_POWER); //Brimstone Clouds
|
||||
}
|
||||
|
@ -55,15 +55,15 @@ namespace SRSLPraserHelpers
|
||||
switch(direction)
|
||||
{
|
||||
case 0: //top left
|
||||
return std::make_pair(y%2 ? x-1 : x, y-1);
|
||||
return std::make_pair((y%2) ? x-1 : x, y-1);
|
||||
case 1: //top right
|
||||
return std::make_pair(y%2 ? x : x+1, y-1);
|
||||
return std::make_pair((y%2) ? x : x+1, y-1);
|
||||
case 2: //right
|
||||
return std::make_pair(x+1, y);
|
||||
case 3: //right bottom
|
||||
return std::make_pair(y%2 ? x : x+1, y+1);
|
||||
return std::make_pair((y%2) ? x : x+1, y+1);
|
||||
case 4: //left bottom
|
||||
return std::make_pair(y%2 ? x-1 : x, y+1);
|
||||
return std::make_pair((y%2) ? x-1 : x, y+1);
|
||||
case 5: //left
|
||||
return std::make_pair(x-1, y);
|
||||
default:
|
||||
|
@ -285,7 +285,7 @@ void CTownHandler::loadTown(CTown &town, const JsonNode & source)
|
||||
|
||||
BOOST_FOREACH(const JsonNode &list, source["creatures"].Vector())
|
||||
{
|
||||
std::vector<si32> level;
|
||||
std::vector<TCreature> level;
|
||||
BOOST_FOREACH(const JsonNode &node, list.Vector())
|
||||
{
|
||||
level.push_back(node.Float());
|
||||
|
@ -3,7 +3,7 @@
|
||||
#include "ConstTransitivePtr.h"
|
||||
#include "ResourceSet.h"
|
||||
#include "int3.h"
|
||||
//#include "GameConstants.h"
|
||||
#include "GameConstants.h"
|
||||
|
||||
/*
|
||||
* CTownHandler.h, part of VCMI engine
|
||||
@ -29,7 +29,8 @@ class DLL_LINKAGE CBuilding
|
||||
std::string description;
|
||||
|
||||
public:
|
||||
si32 tid, bid; //town ID and structure ID
|
||||
TFaction tid;
|
||||
si32 bid; //town ID and structure ID
|
||||
TResources resources;
|
||||
|
||||
std::set<BuildingType> requirements; /// set of required buildings, includes upgradeOf;
|
||||
@ -88,11 +89,11 @@ class DLL_LINKAGE CTown
|
||||
std::vector<std::string> names; //names of the town instances
|
||||
|
||||
public:
|
||||
ui32 typeID;//also works as factionID
|
||||
TFaction typeID;//also works as factionID
|
||||
|
||||
/// level -> list of creatures on this tier
|
||||
// TODO: replace with pointers to CCreature
|
||||
std::vector<std::vector<si32> > creatures;
|
||||
std::vector<std::vector<TCreature> > creatures;
|
||||
|
||||
bmap<int, ConstTransitivePtr<CBuilding> > buildings;
|
||||
|
||||
@ -155,7 +156,7 @@ class CFaction
|
||||
{
|
||||
public:
|
||||
std::string name; //reference name, usually lower case
|
||||
ui32 factionID;
|
||||
TFaction factionID;
|
||||
|
||||
ui32 nativeTerrain;
|
||||
|
||||
@ -194,8 +195,8 @@ class DLL_LINKAGE CTownHandler
|
||||
void loadLegacyData(JsonNode & dest);
|
||||
|
||||
public:
|
||||
std::map<ui32, CTown> towns;
|
||||
std::map<ui32, CFaction> factions;
|
||||
std::map<TFaction, CTown> towns;
|
||||
std::map<TFaction, CFaction> factions;
|
||||
|
||||
CTownHandler(); //c-tor, set pointer in VLC to this
|
||||
|
||||
|
@ -68,75 +68,19 @@ public:
|
||||
si64 read(ui8 * data, si64 size);
|
||||
|
||||
/**
|
||||
* Reads a unsigned 8 bit integer. Advances the read pointer by one byte.
|
||||
* Reads integer of various size. Advances the read pointer.
|
||||
*
|
||||
* @return a unsigned 8 bit integer.
|
||||
* @return a read integer.
|
||||
*
|
||||
* @throws std::runtime_error if the end of the stream was reached unexpectedly
|
||||
*/
|
||||
ui8 readUInt8();
|
||||
|
||||
/**
|
||||
* Reads a signed 8 bit integer. Advances the read pointer by one byte.
|
||||
*
|
||||
* @return a signed 8 bit integer.
|
||||
*
|
||||
* @throws std::runtime_error if the end of the stream was reached unexpectedly
|
||||
*/
|
||||
si8 readInt8();
|
||||
|
||||
/**
|
||||
* Reads a unsigned 16 bit integer. Advances the read pointer by two bytes.
|
||||
*
|
||||
* @return a unsigned 16 bit integer.
|
||||
*
|
||||
* @throws std::runtime_error if the end of the stream was reached unexpectedly
|
||||
*/
|
||||
ui16 readUInt16();
|
||||
|
||||
/**
|
||||
* Reads a signed 16 bit integer. Advances the read pointer by two bytes.
|
||||
*
|
||||
* @return a signed 16 bit integer.
|
||||
*
|
||||
* @throws std::runtime_error if the end of the stream was reached unexpectedly
|
||||
*/
|
||||
si16 readInt16();
|
||||
|
||||
/**
|
||||
* Reads a unsigned 32 bit integer. Advances the read pointer by four bytes.
|
||||
*
|
||||
* @return a unsigned 32 bit integer.
|
||||
*
|
||||
* @throws std::runtime_error if the end of the stream was reached unexpectedly
|
||||
*/
|
||||
ui32 readUInt32();
|
||||
|
||||
/**
|
||||
* Reads a signed 32 bit integer. Advances the read pointer by four bytes.
|
||||
*
|
||||
* @return a signed 32 bit integer.
|
||||
*
|
||||
* @throws std::runtime_error if the end of the stream was reached unexpectedly
|
||||
*/
|
||||
si32 readInt32();
|
||||
|
||||
/**
|
||||
* Reads a unsigned 64 bit integer. Advances the read pointer by eight bytes.
|
||||
*
|
||||
* @return a unsigned 64 bit integer.
|
||||
*
|
||||
* @throws std::runtime_error if the end of the stream was reached unexpectedly
|
||||
*/
|
||||
ui64 readUInt64();
|
||||
|
||||
/**
|
||||
* Reads a signed 64 bit integer. Advances the read pointer by eight bytes.
|
||||
*
|
||||
* @return a signed 64 bit integer.
|
||||
*
|
||||
* @throws std::runtime_error if the end of the stream was reached unexpectedly
|
||||
*/
|
||||
si64 readInt64();
|
||||
|
||||
private:
|
||||
|
@ -336,7 +336,7 @@ void CResourceHandler::initialize()
|
||||
recurseInDir("ALL/MODS", 2); // look for mods. Depth 2 is required for now but won't cause issues if no mods present
|
||||
}
|
||||
|
||||
void CResourceHandler::loadDirectory(const std::string mountPoint, const JsonNode & config)
|
||||
void CResourceHandler::loadDirectory(const std::string &mountPoint, const JsonNode & config)
|
||||
{
|
||||
std::string URI = config["path"].String();
|
||||
bool writeable = config["writeable"].Bool();
|
||||
@ -354,7 +354,7 @@ void CResourceHandler::loadDirectory(const std::string mountPoint, const JsonNod
|
||||
}
|
||||
}
|
||||
|
||||
void CResourceHandler::loadArchive(const std::string mountPoint, const JsonNode & config, EResType::Type archiveType)
|
||||
void CResourceHandler::loadArchive(const std::string &mountPoint, const JsonNode & config, EResType::Type archiveType)
|
||||
{
|
||||
std::string URI = config["path"].String();
|
||||
std::string filename = initialLoader->getResourceName(ResourceID(URI, archiveType));
|
||||
@ -363,7 +363,7 @@ void CResourceHandler::loadArchive(const std::string mountPoint, const JsonNode
|
||||
shared_ptr<ISimpleResourceLoader>(new CLodArchiveLoader(filename)), false);
|
||||
}
|
||||
|
||||
void CResourceHandler::loadFileSystem(const std::string fsConfigURI)
|
||||
void CResourceHandler::loadFileSystem(const std::string &fsConfigURI)
|
||||
{
|
||||
auto fsConfigData = initialLoader->loadData(ResourceID(fsConfigURI, EResType::TEXT));
|
||||
|
||||
|
@ -376,9 +376,9 @@ public:
|
||||
/**
|
||||
* Will load all filesystem data from Json data at this path (config/filesystem.json)
|
||||
*/
|
||||
static void loadFileSystem(const std::string fsConfigURI);
|
||||
static void loadDirectory(const std::string mountPoint, const JsonNode & config);
|
||||
static void loadArchive(const std::string mountPoint, const JsonNode & config, EResType::Type archiveType);
|
||||
static void loadFileSystem(const std::string & fsConfigURI);
|
||||
static void loadDirectory(const std::string & mountPoint, const JsonNode & config);
|
||||
static void loadArchive(const std::string & mountPoint, const JsonNode & config, EResType::Type archiveType);
|
||||
|
||||
/**
|
||||
* Experimental. Checks all subfolders of MODS directory for presence of ERA-style mods
|
||||
|
@ -221,7 +221,7 @@ struct PackageApplied : public CPackForClient //94
|
||||
|
||||
struct SystemMessage : public CPackForClient //95
|
||||
{
|
||||
SystemMessage(const std::string Text) : text(Text){type = 95;};
|
||||
SystemMessage(const std::string & Text) : text(Text){type = 95;};
|
||||
SystemMessage(){type = 95;};
|
||||
void applyCl(CClient *cl);
|
||||
|
||||
|
@ -187,7 +187,7 @@ DLL_LINKAGE void SetAvailableHeroes::applyGs( CGameState *gs )
|
||||
|
||||
for (int i = 0; i < GameConstants::AVAILABLE_HEROES_PER_PLAYER; i++)
|
||||
{
|
||||
CGHeroInstance *h = (hid[i]>=0 ? (CGHeroInstance*)gs->hpool.heroesPool[hid[i]] : NULL);
|
||||
CGHeroInstance *h = (hid[i]>=0 ? gs->hpool.heroesPool[hid[i]].get() : nullptr);
|
||||
if(h && army[i])
|
||||
h->setToArmy(army[i]);
|
||||
p->availableHeroes.push_back(h);
|
||||
|
32
lib/map.cpp
32
lib/map.cpp
@ -1,6 +1,7 @@
|
||||
#include "StdInc.h"
|
||||
#include "map.h"
|
||||
|
||||
#include "Filesystem/CBinaryReader.h"
|
||||
#include "Filesystem/CResourceLoader.h"
|
||||
#include "Filesystem/CCompressedStream.h"
|
||||
#include "CObjectHandler.h"
|
||||
@ -498,18 +499,41 @@ void Mapa::addBlockVisTiles(CGObjectInstance * obj)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TInputStreamPtr Mapa::getMapStream(std::string URI)
|
||||
{
|
||||
TInputStreamPtr file = CResourceHandler::get()->load(ResourceID(URI, EResType::MAP));
|
||||
|
||||
CBinaryReader reader(*file.get());
|
||||
|
||||
ui32 header = reader.readUInt32();
|
||||
file->seek(0); //reset file
|
||||
|
||||
switch (header)
|
||||
{
|
||||
case 0x00088B1F: // gzip header magic number, reversed for LE
|
||||
return TInputStreamPtr(new CCompressedStream(std::move(file), true));
|
||||
case CMapHeader::WoG :
|
||||
case CMapHeader::AB :
|
||||
case CMapHeader::RoE :
|
||||
case CMapHeader::SoD :
|
||||
return file;
|
||||
default :
|
||||
return TInputStreamPtr();
|
||||
}
|
||||
}
|
||||
|
||||
Mapa::Mapa(std::string filename)
|
||||
:grailPos(-1, -1, -1), grailRadious(0)
|
||||
{
|
||||
tlog0<<"Opening map file: "<<filename<<"\t "<<std::flush;
|
||||
|
||||
std::unique_ptr<CInputStream> decompressed(new CCompressedStream(
|
||||
std::move(CResourceHandler::get()->load(ResourceID(filename, EResType::MAP))), true));
|
||||
TInputStreamPtr file = getMapStream(filename);
|
||||
|
||||
//load file and decompress
|
||||
size_t mapSize = decompressed->getSize();
|
||||
size_t mapSize = file->getSize();
|
||||
std::unique_ptr<ui8[]> data(new ui8 [mapSize] );
|
||||
decompressed->read(data.get(), mapSize);
|
||||
file->read(data.get(), mapSize);
|
||||
|
||||
tlog0<<"done."<<std::endl;
|
||||
|
||||
|
@ -32,6 +32,9 @@ class CGTownInstance;
|
||||
class IModableArt;
|
||||
class IQuestObject;
|
||||
|
||||
class CInputStream;
|
||||
typedef std::unique_ptr<CInputStream> TInputStreamPtr;
|
||||
|
||||
/// Struct which describes a single terrain tile
|
||||
struct DLL_LINKAGE TerrainTile
|
||||
{
|
||||
@ -349,6 +352,8 @@ struct DLL_LINKAGE Mapa : public CMapHeader
|
||||
bool isInTheMap(const int3 &pos) const;
|
||||
bool isWaterTile(const int3 &pos) const; //out-of-pos safe
|
||||
|
||||
static TInputStreamPtr getMapStream(std::string URI);
|
||||
|
||||
template <typename Handler> void serialize(Handler &h, const int formatVersion)
|
||||
{
|
||||
h & static_cast<CMapHeader&>(*this);
|
||||
|
@ -43,7 +43,7 @@
|
||||
#ifndef _MSC_VER
|
||||
#include <boost/thread/xtime.hpp>
|
||||
#endif
|
||||
#include <boost/random/linear_congruential.hpp>
|
||||
#include <boost/random/binomial_distribution.hpp>
|
||||
#include <boost/range/algorithm/random_shuffle.hpp>
|
||||
extern bool end2;
|
||||
#ifdef min
|
||||
@ -5297,18 +5297,18 @@ void CGameHandler::handleAfterAttackCasting( const BattleAttack & bat )
|
||||
if (attacker->hasBonusOfType(Bonus::DEATH_STARE)) // spell id 79
|
||||
{
|
||||
// mechanics of Death Stare as in H3:
|
||||
// each gorgon have 10% chance to kill (counted separately in H3) -> poisson distribution
|
||||
// maximum amount that can be killed is (1 + gorgons / 5 ), rounded up
|
||||
// each gorgon have 10% chance to kill (counted separately in H3) -> binomial distribution
|
||||
// maximum amount that can be killed is ( gorgons_count / 10 ), rounded up
|
||||
|
||||
int staredCreatures = 0;
|
||||
double mean = double(attacker->count * attacker->valOfBonuses(Bonus::DEATH_STARE, 0)) / 100;
|
||||
double chanceToKill = double(attacker->count * attacker->valOfBonuses(Bonus::DEATH_STARE, 0)) / 100;
|
||||
vstd::amin(chanceToKill, 1); //cap at 100%
|
||||
|
||||
boost::poisson_distribution<> p(mean);
|
||||
boost::binomial_distribution<> distr(attacker->count, chanceToKill);
|
||||
boost::mt19937 rng(rand());
|
||||
boost::variate_generator<boost::mt19937&, boost::poisson_distribution<> > dice (rng, p);
|
||||
staredCreatures += dice();
|
||||
boost::variate_generator<boost::mt19937&, boost::binomial_distribution<> > dice (rng, distr);
|
||||
int staredCreatures = dice();
|
||||
|
||||
int maxToKill = 1 + (attacker->count + 4) / 5;
|
||||
int maxToKill = (attacker->count * chanceToKill + 99) / 100;
|
||||
vstd::amin(staredCreatures, maxToKill);
|
||||
|
||||
staredCreatures += attacker->type->level * attacker->valOfBonuses(Bonus::DEATH_STARE, 1);
|
||||
|
Loading…
Reference in New Issue
Block a user