2008-06-13 00:08:04 +03:00
|
|
|
#define VCMI_DLL
|
2008-01-09 19:21:31 +02:00
|
|
|
#include "../stdafx.h"
|
2007-06-08 22:56:35 +03:00
|
|
|
#include "CCreatureHandler.h"
|
2007-08-29 15:18:31 +03:00
|
|
|
#include "CLodHandler.h"
|
2007-10-15 23:59:17 +03:00
|
|
|
#include <sstream>
|
2008-08-30 00:41:32 +03:00
|
|
|
#include <boost/assign/std/set.hpp>
|
2007-10-15 23:59:17 +03:00
|
|
|
#include <boost/assign/std/vector.hpp>
|
2010-05-02 21:20:26 +03:00
|
|
|
#include <boost/assign/std/list.hpp>
|
2009-07-07 06:34:23 +03:00
|
|
|
#include <boost/assign/list_of.hpp>
|
2007-10-15 23:59:17 +03:00
|
|
|
#include <boost/algorithm/string.hpp>
|
2008-04-14 21:24:46 +03:00
|
|
|
#include <boost/algorithm/string/find.hpp>
|
2007-10-15 23:59:17 +03:00
|
|
|
#include <boost/algorithm/string/replace.hpp>
|
2008-06-17 20:48:32 +03:00
|
|
|
#include "../lib/VCMI_Lib.h"
|
2010-08-24 17:26:57 +03:00
|
|
|
#include "../lib/CGameState.h"
|
2011-02-06 10:32:05 +02:00
|
|
|
#include <boost/foreach.hpp>
|
2011-02-10 15:12:53 +02:00
|
|
|
#include <boost/lexical_cast.hpp>
|
2011-08-21 00:53:03 +03:00
|
|
|
#include "../lib/JsonNode.h"
|
2009-04-15 17:03:31 +03:00
|
|
|
|
2008-08-30 00:41:32 +03:00
|
|
|
using namespace boost::assign;
|
2008-06-13 00:08:04 +03:00
|
|
|
extern CLodHandler * bitmaph;
|
2009-04-15 17:03:31 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* CCreatureHandler.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
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2009-05-24 01:57:39 +03:00
|
|
|
static std::vector<int> getMindSpells()
|
2009-05-14 20:26:55 +03:00
|
|
|
{
|
|
|
|
std::vector<int> ret;
|
|
|
|
ret.push_back(50); //sorrow
|
|
|
|
ret.push_back(59); //berserk
|
|
|
|
ret.push_back(60); //hypnotize
|
|
|
|
ret.push_back(61); //forgetfulness
|
2009-08-24 20:40:20 +03:00
|
|
|
ret.push_back(62); //blind
|
2009-05-14 20:26:55 +03:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-06-17 20:48:32 +03:00
|
|
|
CCreatureHandler::CCreatureHandler()
|
|
|
|
{
|
|
|
|
VLC->creh = this;
|
2009-08-24 20:40:20 +03:00
|
|
|
|
|
|
|
// Set the faction alignments to the defaults:
|
|
|
|
// Good: Castle, Rampart, Tower // Evil: Inferno, Necropolis, Dungeon
|
|
|
|
// Neutral: Stronghold, Fortess, Conflux
|
|
|
|
factionAlignments += 1, 1, 1, -1, -1, -1, 0, 0, 0;
|
2010-08-29 10:49:04 +03:00
|
|
|
doubledCreatures += 4, 14, 20, 28, 42, 44, 60, 70, 72, 85, 86, 100, 104; //according to Strategija
|
2011-02-10 15:12:53 +02:00
|
|
|
|
2011-07-13 21:39:02 +03:00
|
|
|
allCreatures.setDescription("All creatures");
|
|
|
|
creaturesOfLevel[0].setDescription("Creatures of unnormalized tier");
|
2011-02-10 15:12:53 +02:00
|
|
|
for(int i = 1; i < ARRAY_COUNT(creaturesOfLevel); i++)
|
2011-07-13 21:39:02 +03:00
|
|
|
creaturesOfLevel[i].setDescription("Creatures of tier " + boost::lexical_cast<std::string>(i));
|
2008-06-17 20:48:32 +03:00
|
|
|
}
|
2009-08-24 20:40:20 +03:00
|
|
|
|
2008-09-24 19:25:14 +03:00
|
|
|
int CCreature::getQuantityID(const int & quantity)
|
2008-02-25 01:06:27 +02:00
|
|
|
{
|
|
|
|
if (quantity<5)
|
|
|
|
return 0;
|
|
|
|
if (quantity<10)
|
|
|
|
return 1;
|
|
|
|
if (quantity<20)
|
|
|
|
return 2;
|
|
|
|
if (quantity<50)
|
|
|
|
return 3;
|
|
|
|
if (quantity<100)
|
|
|
|
return 4;
|
|
|
|
if (quantity<250)
|
|
|
|
return 5;
|
|
|
|
if (quantity<500)
|
|
|
|
return 6;
|
2011-08-25 18:24:37 +03:00
|
|
|
if (quantity<1000)
|
2008-02-25 01:06:27 +02:00
|
|
|
return 7;
|
|
|
|
return 8;
|
|
|
|
}
|
|
|
|
|
2011-08-27 05:15:58 +03:00
|
|
|
int CCreature::estimateCreatureCount(unsigned int countID)
|
2011-08-25 18:24:37 +03:00
|
|
|
{
|
2011-08-27 05:15:58 +03:00
|
|
|
static const int creature_count[] = { 3, 8, 15, 35, 75, 175, 375, 750, 2500 };
|
|
|
|
|
|
|
|
if (countID > 8)
|
2011-08-25 18:24:37 +03:00
|
|
|
assert("Wrong countID!");
|
2011-08-27 05:15:58 +03:00
|
|
|
|
|
|
|
return creature_count[countID];
|
2011-08-25 18:24:37 +03:00
|
|
|
}
|
|
|
|
|
2008-09-24 19:25:14 +03:00
|
|
|
bool CCreature::isDoubleWide() const
|
2008-04-14 21:24:46 +03:00
|
|
|
{
|
2010-05-02 21:20:26 +03:00
|
|
|
return doubleWide;
|
2008-04-14 21:24:46 +03:00
|
|
|
}
|
|
|
|
|
2008-09-24 19:25:14 +03:00
|
|
|
bool CCreature::isFlying() const
|
2008-04-14 21:24:46 +03:00
|
|
|
{
|
2010-11-19 00:06:56 +02:00
|
|
|
return hasBonusOfType(Bonus::FLYING);
|
2008-04-14 21:24:46 +03:00
|
|
|
}
|
2009-05-08 19:55:04 +03:00
|
|
|
|
2008-09-24 19:25:14 +03:00
|
|
|
bool CCreature::isShooting() const
|
2008-08-02 18:08:03 +03:00
|
|
|
{
|
2010-11-19 00:06:56 +02:00
|
|
|
return hasBonusOfType(Bonus::SHOOTER);
|
2008-08-02 18:08:03 +03:00
|
|
|
}
|
2009-05-08 19:55:04 +03:00
|
|
|
|
2009-04-16 17:01:27 +03:00
|
|
|
bool CCreature::isUndead() const
|
|
|
|
{
|
2010-11-19 00:06:56 +02:00
|
|
|
return hasBonusOfType(Bonus::UNDEAD);
|
2009-04-16 17:01:27 +03:00
|
|
|
}
|
2009-05-08 19:55:04 +03:00
|
|
|
|
2009-08-24 20:40:20 +03:00
|
|
|
/**
|
|
|
|
* Determines if the creature is of a good alignment.
|
|
|
|
* @return true if the creture is good, false otherwise.
|
|
|
|
*/
|
|
|
|
bool CCreature::isGood () const
|
|
|
|
{
|
|
|
|
return VLC->creh->isGood(faction);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determines if the creature is of an evil alignment.
|
|
|
|
* @return true if the creature is evil, false otherwise.
|
|
|
|
*/
|
|
|
|
bool CCreature::isEvil () const
|
|
|
|
{
|
|
|
|
return VLC->creh->isEvil(faction);
|
|
|
|
}
|
|
|
|
|
2008-08-01 14:21:15 +03:00
|
|
|
si32 CCreature::maxAmount(const std::vector<si32> &res) const //how many creatures can be bought
|
2008-05-12 08:46:04 +03:00
|
|
|
{
|
|
|
|
int ret = 2147483645;
|
|
|
|
int resAmnt = std::min(res.size(),cost.size());
|
|
|
|
for(int i=0;i<resAmnt;i++)
|
|
|
|
if(cost[i])
|
2008-08-01 14:21:15 +03:00
|
|
|
ret = std::min(ret,(int)(res[i]/cost[i]));
|
2008-05-12 08:46:04 +03:00
|
|
|
return ret;
|
|
|
|
}
|
2008-04-14 21:24:46 +03:00
|
|
|
|
2010-05-02 21:20:26 +03:00
|
|
|
CCreature::CCreature()
|
|
|
|
{
|
|
|
|
doubleWide = false;
|
2011-07-13 21:39:02 +03:00
|
|
|
setNodeType(CBonusSystemNode::CREATURE);
|
2010-05-02 21:20:26 +03:00
|
|
|
}
|
|
|
|
void CCreature::addBonus(int val, int type, int subtype /*= -1*/)
|
|
|
|
{
|
2010-11-20 02:03:31 +02:00
|
|
|
Bonus *added = new Bonus(Bonus::PERMANENT, type, Bonus::CREATURE_ABILITY, val, idNumber, subtype, Bonus::BASE_NUMBER);
|
2010-11-19 00:06:56 +02:00
|
|
|
addNewBonus(added);
|
2010-05-02 21:20:26 +03:00
|
|
|
}
|
2010-11-13 22:26:15 +02:00
|
|
|
// void CCreature::getParents(TCNodes &out, const CBonusSystemNode *root /*= NULL*/) const
|
|
|
|
// {
|
|
|
|
// out.insert (VLC->creh->globalEffects);
|
|
|
|
// }
|
2010-07-12 13:20:25 +03:00
|
|
|
bool CCreature::isMyUpgrade(const CCreature *anotherCre) const
|
|
|
|
{
|
|
|
|
//TODO upgrade of upgrade?
|
|
|
|
return vstd::contains(upgrades, anotherCre->idNumber);
|
|
|
|
}
|
|
|
|
|
2010-11-27 22:17:28 +02:00
|
|
|
bool CCreature::valid() const
|
|
|
|
{
|
|
|
|
return this == VLC->creh->creatures[idNumber];
|
|
|
|
}
|
|
|
|
|
2010-12-29 23:04:22 +02:00
|
|
|
std::string CCreature::nodeName() const
|
|
|
|
{
|
2011-02-10 15:12:53 +02:00
|
|
|
return "\"" + namePl + "\"";
|
2010-12-29 23:04:22 +02:00
|
|
|
}
|
|
|
|
|
2009-06-28 17:57:00 +03:00
|
|
|
int readNumber(int & befi, int & i, int andame, std::string & buf) //helper function for void CCreatureHandler::loadCreatures() and loadUnitAnimInfo()
|
2009-06-28 16:49:39 +03:00
|
|
|
{
|
|
|
|
befi=i;
|
2010-10-25 22:37:21 +03:00
|
|
|
for(; i<andame; ++i)
|
2009-06-28 16:49:39 +03:00
|
|
|
{
|
|
|
|
if(buf[i]=='\t')
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
std::string tmp = buf.substr(befi, i-befi);
|
|
|
|
int ret = atoi(buf.substr(befi, i-befi).c_str());
|
|
|
|
++i;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-06-28 17:57:00 +03:00
|
|
|
float readFloat(int & befi, int & i, int andame, std::string & buf) //helper function for void CCreatureHandler::loadUnitAnimInfo()
|
|
|
|
{
|
|
|
|
befi=i;
|
2010-10-25 22:37:21 +03:00
|
|
|
for(; i<andame; ++i)
|
2009-06-28 17:57:00 +03:00
|
|
|
{
|
|
|
|
if(buf[i]=='\t')
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
std::string tmp = buf.substr(befi, i-befi);
|
|
|
|
float ret = atof(buf.substr(befi, i-befi).c_str());
|
|
|
|
++i;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-08-24 20:40:20 +03:00
|
|
|
/**
|
|
|
|
* Determines if a faction is good.
|
|
|
|
* @param ID of the faction.
|
|
|
|
* @return true if the faction is good, false otherwise.
|
|
|
|
*/
|
|
|
|
bool CCreatureHandler::isGood (si8 faction) const
|
|
|
|
{
|
|
|
|
return faction != -1 && factionAlignments[faction] == 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determines if a faction is evil.
|
|
|
|
* @param ID of the faction.
|
|
|
|
* @return true if the faction is evil, false otherwise.
|
|
|
|
*/
|
|
|
|
bool CCreatureHandler::isEvil (si8 faction) const
|
|
|
|
{
|
|
|
|
return faction != -1 && factionAlignments[faction] == -1;
|
|
|
|
}
|
|
|
|
|
2007-06-08 22:56:35 +03:00
|
|
|
void CCreatureHandler::loadCreatures()
|
|
|
|
{
|
2008-09-01 03:25:36 +03:00
|
|
|
notUsedMonsters += 122,124,126,128,145,146,147,148,149,160,161,162,163,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191;
|
2009-06-28 16:49:39 +03:00
|
|
|
tlog5 << "\t\tReading config/cr_abils.txt and ZCRTRAIT.TXT" << std::endl;
|
|
|
|
|
|
|
|
bool useCreAbilsFromZCRTRAIT = true;
|
|
|
|
|
|
|
|
////////////reading cr_abils.txt ///////////////////
|
2009-10-04 05:02:45 +03:00
|
|
|
std::ifstream abils(DATA_DIR "/config/cr_abils.txt", std::ios::in | std::ios::binary); //this file is not in lod
|
2009-06-28 16:49:39 +03:00
|
|
|
const int MAX_LINE_SIZE = 1000;
|
|
|
|
char abilLine[MAX_LINE_SIZE+1];
|
|
|
|
for(int i=0; i<5; ++i) //removing 5 comment lines
|
|
|
|
{
|
|
|
|
abils.getline(abilLine, MAX_LINE_SIZE);
|
|
|
|
}
|
|
|
|
//reading first line (determining if we should use creature abilities from ZCRTRAIT.TXT)
|
|
|
|
abils.getline(abilLine, MAX_LINE_SIZE);
|
|
|
|
useCreAbilsFromZCRTRAIT = atoi(abilLine);
|
|
|
|
|
|
|
|
////////////reading ZCRTRAIT.TXT ///////////////////
|
2008-06-12 09:45:51 +03:00
|
|
|
std::string buf = bitmaph->getTextFile("ZCRTRAIT.TXT");
|
2007-07-16 17:42:44 +03:00
|
|
|
int andame = buf.size();
|
2007-06-10 21:04:15 +03:00
|
|
|
int i=0; //buf iterator
|
|
|
|
int hmcr=0;
|
2010-10-25 22:37:21 +03:00
|
|
|
for(; i<andame; ++i)
|
2007-06-08 22:56:35 +03:00
|
|
|
{
|
2007-06-10 21:04:15 +03:00
|
|
|
if(buf[i]=='\r')
|
|
|
|
++hmcr;
|
|
|
|
if(hmcr==2)
|
|
|
|
break;
|
2007-06-08 22:56:35 +03:00
|
|
|
}
|
2007-06-10 21:04:15 +03:00
|
|
|
i+=2;
|
|
|
|
|
|
|
|
while(i<buf.size())
|
2007-06-08 22:56:35 +03:00
|
|
|
{
|
2010-05-02 21:20:26 +03:00
|
|
|
CCreature &ncre = *new CCreature;
|
|
|
|
ncre.idNumber = creatures.size();
|
2008-04-04 20:30:53 +03:00
|
|
|
ncre.cost.resize(RESOURCE_QUANTITY);
|
2008-02-05 05:56:45 +02:00
|
|
|
ncre.level=0;
|
2009-04-26 02:31:39 +03:00
|
|
|
|
2007-06-10 21:04:15 +03:00
|
|
|
int befi=i;
|
2010-10-25 22:37:21 +03:00
|
|
|
for(; i<andame; ++i)
|
2007-06-08 22:56:35 +03:00
|
|
|
{
|
2007-06-10 21:04:15 +03:00
|
|
|
if(buf[i]=='\t')
|
|
|
|
break;
|
2007-06-08 22:56:35 +03:00
|
|
|
}
|
2007-06-10 21:04:15 +03:00
|
|
|
ncre.nameSing = buf.substr(befi, i-befi);
|
|
|
|
++i;
|
2007-06-08 22:56:35 +03:00
|
|
|
|
2007-06-10 21:04:15 +03:00
|
|
|
befi=i;
|
2010-10-25 22:37:21 +03:00
|
|
|
for(; i<andame; ++i)
|
2007-06-08 22:56:35 +03:00
|
|
|
{
|
2007-06-10 21:04:15 +03:00
|
|
|
if(buf[i]=='\t')
|
|
|
|
break;
|
2007-06-08 22:56:35 +03:00
|
|
|
}
|
2007-06-10 21:04:15 +03:00
|
|
|
ncre.namePl = buf.substr(befi, i-befi);
|
|
|
|
++i;
|
2007-06-08 22:56:35 +03:00
|
|
|
|
2009-06-28 16:49:39 +03:00
|
|
|
for(int v=0; v<7; ++v)
|
2007-06-08 22:56:35 +03:00
|
|
|
{
|
2009-06-28 16:49:39 +03:00
|
|
|
ncre.cost[v] = readNumber(befi, i, andame, buf);
|
2007-06-08 22:56:35 +03:00
|
|
|
}
|
2009-06-28 16:49:39 +03:00
|
|
|
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);
|
2010-05-02 21:20:26 +03:00
|
|
|
|
2009-06-28 16:49:39 +03:00
|
|
|
ncre.hitPoints = readNumber(befi, i, andame, buf);
|
2010-05-02 21:20:26 +03:00
|
|
|
ncre.addBonus(ncre.hitPoints, Bonus::STACK_HEALTH);
|
2009-06-28 16:49:39 +03:00
|
|
|
ncre.speed = readNumber(befi, i, andame, buf);
|
2010-05-02 21:20:26 +03:00
|
|
|
ncre.addBonus(ncre.speed, Bonus::STACKS_SPEED);
|
2009-06-28 16:49:39 +03:00
|
|
|
ncre.attack = readNumber(befi, i, andame, buf);
|
2010-05-02 21:20:26 +03:00
|
|
|
ncre.addBonus(ncre.attack, Bonus::PRIMARY_SKILL, PrimarySkill::ATTACK);
|
2009-06-28 16:49:39 +03:00
|
|
|
ncre.defence = readNumber(befi, i, andame, buf);
|
2010-05-02 21:20:26 +03:00
|
|
|
ncre.addBonus(ncre.defence, Bonus::PRIMARY_SKILL, PrimarySkill::DEFENSE);
|
2010-08-30 21:06:17 +03:00
|
|
|
ncre.damageMin = readNumber(befi, i, andame, buf); //not used anymore?
|
|
|
|
ncre.addBonus(ncre.damageMin, Bonus::CREATURE_DAMAGE, 1);
|
2009-06-28 16:49:39 +03:00
|
|
|
ncre.damageMax = readNumber(befi, i, andame, buf);
|
2010-08-30 21:06:17 +03:00
|
|
|
ncre.addBonus(ncre.damageMax, Bonus::CREATURE_DAMAGE, 2);
|
2010-05-02 21:20:26 +03:00
|
|
|
|
2009-06-28 16:49:39 +03:00
|
|
|
ncre.shots = readNumber(befi, i, andame, buf);
|
2011-04-12 11:59:18 +03:00
|
|
|
ncre.addBonus(ncre.shots, Bonus::SHOTS);
|
2009-06-28 16:49:39 +03:00
|
|
|
ncre.spells = readNumber(befi, i, andame, buf);
|
|
|
|
ncre.ammMin = readNumber(befi, i, andame, buf);
|
|
|
|
ncre.ammMax = readNumber(befi, i, andame, buf);
|
2007-06-08 22:56:35 +03:00
|
|
|
|
2007-06-10 21:04:15 +03:00
|
|
|
befi=i;
|
2010-10-25 22:37:21 +03:00
|
|
|
for(; i<andame; ++i)
|
2007-06-08 22:56:35 +03:00
|
|
|
{
|
2007-06-10 21:04:15 +03:00
|
|
|
if(buf[i]=='\t')
|
|
|
|
break;
|
2007-06-08 22:56:35 +03:00
|
|
|
}
|
2007-06-10 21:04:15 +03:00
|
|
|
ncre.abilityText = buf.substr(befi, i-befi);
|
|
|
|
++i;
|
2007-06-08 22:56:35 +03:00
|
|
|
|
2007-06-10 21:04:15 +03:00
|
|
|
befi=i;
|
2010-10-25 22:37:21 +03:00
|
|
|
for(; i<andame; ++i)
|
2007-06-08 22:56:35 +03:00
|
|
|
{
|
2007-06-10 21:04:15 +03:00
|
|
|
if(buf[i]=='\r')
|
|
|
|
break;
|
2007-06-08 22:56:35 +03:00
|
|
|
}
|
2007-06-10 21:04:15 +03:00
|
|
|
ncre.abilityRefs = buf.substr(befi, i-befi);
|
|
|
|
i+=2;
|
2009-06-28 16:49:39 +03:00
|
|
|
if(useCreAbilsFromZCRTRAIT)
|
|
|
|
{ //adding abilities from ZCRTRAIT.TXT
|
|
|
|
if(boost::algorithm::find_first(ncre.abilityRefs, "DOUBLE_WIDE"))
|
2010-05-02 21:20:26 +03:00
|
|
|
ncre.doubleWide = true;
|
2009-06-28 16:49:39 +03:00
|
|
|
if(boost::algorithm::find_first(ncre.abilityRefs, "FLYING_ARMY"))
|
2010-05-02 21:20:26 +03:00
|
|
|
ncre.addBonus(0, Bonus::FLYING);
|
2009-06-28 16:49:39 +03:00
|
|
|
if(boost::algorithm::find_first(ncre.abilityRefs, "SHOOTING_ARMY"))
|
2010-05-02 21:20:26 +03:00
|
|
|
ncre.addBonus(0, Bonus::SHOOTER);
|
2009-06-28 16:49:39 +03:00
|
|
|
if(boost::algorithm::find_first(ncre.abilityRefs, "SIEGE_WEAPON"))
|
2010-05-02 21:20:26 +03:00
|
|
|
ncre.addBonus(0, Bonus::SIEGE_WEAPON);
|
2009-06-28 16:49:39 +03:00
|
|
|
if(boost::algorithm::find_first(ncre.abilityRefs, "const_two_attacks"))
|
2010-05-02 21:20:26 +03:00
|
|
|
ncre.addBonus(1, Bonus::ADDITIONAL_ATTACK);
|
2009-06-28 16:49:39 +03:00
|
|
|
if(boost::algorithm::find_first(ncre.abilityRefs, "const_free_attack"))
|
2010-05-02 21:20:26 +03:00
|
|
|
ncre.addBonus(0, Bonus::BLOCKS_RETALIATION);
|
2009-06-28 16:49:39 +03:00
|
|
|
if(boost::algorithm::find_first(ncre.abilityRefs, "IS_UNDEAD"))
|
2010-05-02 21:20:26 +03:00
|
|
|
ncre.addBonus(0, Bonus::UNDEAD);
|
2009-06-28 16:49:39 +03:00
|
|
|
if(boost::algorithm::find_first(ncre.abilityRefs, "const_no_melee_penalty"))
|
2010-05-02 21:20:26 +03:00
|
|
|
ncre.addBonus(0, Bonus::NO_MELEE_PENALTY);
|
2009-06-28 16:49:39 +03:00
|
|
|
if(boost::algorithm::find_first(ncre.abilityRefs, "const_jousting"))
|
2010-05-02 21:20:26 +03:00
|
|
|
ncre.addBonus(0, Bonus::JOUSTING);
|
2009-06-28 16:49:39 +03:00
|
|
|
if(boost::algorithm::find_first(ncre.abilityRefs, "const_raises_morale"))
|
2010-05-02 21:20:26 +03:00
|
|
|
{
|
|
|
|
ncre.addBonus(+1, Bonus::MORALE);;
|
2011-07-13 21:39:02 +03:00
|
|
|
ncre.getBonusList().back()->addPropagator(new CPropagatorNodeType(CBonusSystemNode::HERO));
|
2010-05-02 21:20:26 +03:00
|
|
|
}
|
2009-06-28 16:49:39 +03:00
|
|
|
if(boost::algorithm::find_first(ncre.abilityRefs, "const_lowers_morale"))
|
2010-05-02 21:20:26 +03:00
|
|
|
{
|
|
|
|
ncre.addBonus(-1, Bonus::MORALE);;
|
2011-07-13 21:39:02 +03:00
|
|
|
ncre.getBonusList().back()->effectRange = Bonus::ONLY_ENEMY_ARMY;
|
2010-05-02 21:20:26 +03:00
|
|
|
}
|
2009-06-28 16:49:39 +03:00
|
|
|
if(boost::algorithm::find_first(ncre.abilityRefs, "KING_1"))
|
2010-05-02 21:20:26 +03:00
|
|
|
ncre.addBonus(0, Bonus::KING1);
|
2009-06-28 16:49:39 +03:00
|
|
|
if(boost::algorithm::find_first(ncre.abilityRefs, "KING_2"))
|
2010-05-02 21:20:26 +03:00
|
|
|
ncre.addBonus(0, Bonus::KING2);
|
2009-06-28 16:49:39 +03:00
|
|
|
if(boost::algorithm::find_first(ncre.abilityRefs, "KING_3"))
|
2010-05-02 21:20:26 +03:00
|
|
|
ncre.addBonus(0, Bonus::KING3);
|
2009-06-28 16:49:39 +03:00
|
|
|
if(boost::algorithm::find_first(ncre.abilityRefs, "const_no_wall_penalty"))
|
2010-05-02 21:20:26 +03:00
|
|
|
ncre.addBonus(0, Bonus::NO_WALL_PENALTY);
|
2009-06-28 16:49:39 +03:00
|
|
|
if(boost::algorithm::find_first(ncre.abilityRefs, "CATAPULT"))
|
2010-05-02 21:20:26 +03:00
|
|
|
ncre.addBonus(0, Bonus::CATAPULT);
|
2009-06-28 16:49:39 +03:00
|
|
|
if(boost::algorithm::find_first(ncre.abilityRefs, "MULTI_HEADED"))
|
2010-05-02 21:20:26 +03:00
|
|
|
ncre.addBonus(0, Bonus::ATTACKS_ALL_ADJACENT);
|
|
|
|
|
2009-06-28 16:49:39 +03:00
|
|
|
if(boost::algorithm::find_first(ncre.abilityRefs, "IMMUNE_TO_MIND_SPELLS"))
|
2009-05-15 15:07:55 +03:00
|
|
|
{
|
2009-06-28 16:49:39 +03:00
|
|
|
std::vector<int> mindSpells = getMindSpells();
|
|
|
|
for(int g=0; g<mindSpells.size(); ++g)
|
2010-05-02 21:20:26 +03:00
|
|
|
ncre.addBonus(0, Bonus::SPELL_IMMUNITY, mindSpells[g]); //giants are immune to mind spells
|
2009-05-15 15:07:55 +03:00
|
|
|
}
|
2009-06-28 16:49:39 +03:00
|
|
|
if(boost::algorithm::find_first(ncre.abilityRefs, "IMMUNE_TO_FIRE_SPELLS"))
|
2010-05-02 21:20:26 +03:00
|
|
|
ncre.addBonus(0, Bonus::FIRE_IMMUNITY);
|
2009-06-28 16:49:39 +03:00
|
|
|
if(boost::algorithm::find_first(ncre.abilityRefs, "HAS_EXTENDED_ATTACK"))
|
2010-05-02 21:20:26 +03:00
|
|
|
ncre.addBonus(0, Bonus::TWO_HEX_ATTACK_BREATH);;
|
2009-05-15 15:07:55 +03:00
|
|
|
}
|
2009-05-13 23:40:23 +03:00
|
|
|
|
2007-06-13 23:17:48 +03:00
|
|
|
if(ncre.nameSing!=std::string("") && ncre.namePl!=std::string(""))
|
|
|
|
{
|
|
|
|
ncre.idNumber = creatures.size();
|
2010-05-02 21:20:26 +03:00
|
|
|
creatures.push_back(&ncre);
|
2007-06-13 23:17:48 +03:00
|
|
|
}
|
2007-06-08 22:56:35 +03:00
|
|
|
}
|
2010-07-12 13:20:25 +03:00
|
|
|
|
2009-06-28 16:49:39 +03:00
|
|
|
////second part of reading cr_abils.txt////
|
|
|
|
bool contReading = true;
|
|
|
|
while(contReading) //main reading loop
|
|
|
|
{
|
|
|
|
abils.getline(abilLine, MAX_LINE_SIZE);
|
|
|
|
std::istringstream reader(abilLine);
|
|
|
|
char command;
|
|
|
|
reader >> command;
|
|
|
|
switch(command)
|
|
|
|
{
|
|
|
|
case '+': //add new ability
|
|
|
|
{
|
|
|
|
int creatureID;
|
2010-11-20 02:03:31 +02:00
|
|
|
Bonus *nsf = new Bonus();
|
2009-06-28 16:49:39 +03:00
|
|
|
si32 buf;
|
2009-07-07 06:34:23 +03:00
|
|
|
std::string type;
|
|
|
|
|
2009-06-28 16:49:39 +03:00
|
|
|
reader >> creatureID;
|
2009-07-07 06:34:23 +03:00
|
|
|
reader >> type;
|
2010-05-02 21:20:26 +03:00
|
|
|
|
2010-07-12 13:20:25 +03:00
|
|
|
std::map<std::string, int>::const_iterator it = bonusNameMap.find(type);
|
2010-05-02 21:20:26 +03:00
|
|
|
CCreature *cre = creatures[creatureID];
|
|
|
|
|
2010-07-12 13:20:25 +03:00
|
|
|
if (it == bonusNameMap.end())
|
2010-05-02 21:20:26 +03:00
|
|
|
{
|
|
|
|
if(type == "DOUBLE_WIDE")
|
|
|
|
cre->doubleWide = true;
|
|
|
|
else if(type == "ENEMY_MORALE_DECREASING")
|
|
|
|
{
|
2010-11-19 00:06:56 +02:00
|
|
|
cre->addBonus(-1, Bonus::MORALE);
|
2011-07-13 21:39:02 +03:00
|
|
|
cre->getBonusList().back()->effectRange = Bonus::ONLY_ENEMY_ARMY;
|
2010-05-02 21:20:26 +03:00
|
|
|
}
|
|
|
|
else if(type == "ENEMY_LUCK_DECREASING")
|
|
|
|
{
|
2010-11-19 00:06:56 +02:00
|
|
|
cre->addBonus(-1, Bonus::LUCK);
|
2011-07-13 21:39:02 +03:00
|
|
|
cre->getBonusList().back()->effectRange = Bonus::ONLY_ENEMY_ARMY;
|
2010-05-02 21:20:26 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
tlog1 << "Error: invalid type " << type << " in cr_abils.txt" << std::endl;
|
2009-07-07 06:34:23 +03:00
|
|
|
break;
|
|
|
|
}
|
2010-11-20 02:03:31 +02:00
|
|
|
nsf->type = it->second;
|
|
|
|
|
|
|
|
reader >> buf; nsf->val = buf;
|
|
|
|
reader >> buf; nsf->subtype = buf;
|
|
|
|
reader >> buf; nsf->additionalInfo = buf;
|
|
|
|
nsf->source = Bonus::CREATURE_ABILITY;
|
2011-02-20 20:32:39 +02:00
|
|
|
nsf->sid = cre->idNumber;
|
2011-03-06 14:12:22 +02:00
|
|
|
//nsf->duration = Bonus::ONE_BATTLE; //what the?
|
|
|
|
nsf->duration = Bonus::PERMANENT;
|
2010-11-20 02:03:31 +02:00
|
|
|
nsf->turnsRemain = 0;
|
2009-06-28 16:49:39 +03:00
|
|
|
|
2010-11-19 00:06:56 +02:00
|
|
|
cre->addNewBonus(nsf);
|
2009-06-28 16:49:39 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case '-': //remove ability
|
|
|
|
{
|
|
|
|
int creatureID;
|
2009-08-05 15:46:08 +03:00
|
|
|
std::string type;
|
2009-06-28 16:49:39 +03:00
|
|
|
reader >> creatureID;
|
|
|
|
reader >> type;
|
2010-07-12 13:20:25 +03:00
|
|
|
std::map<std::string, int>::const_iterator it = bonusNameMap.find(type);
|
|
|
|
if (it == bonusNameMap.end())
|
2009-08-05 15:46:08 +03:00
|
|
|
{
|
2010-05-02 21:20:26 +03:00
|
|
|
if(type == "DOUBLE_WIDE")
|
|
|
|
creatures[creatureID]->doubleWide = false;
|
|
|
|
else
|
|
|
|
tlog1 << "Error: invalid type " << type << " in cr_abils.txt" << std::endl;
|
2009-08-05 15:46:08 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
int typeNo = it->second;
|
|
|
|
|
2010-05-02 21:20:26 +03:00
|
|
|
Bonus::BonusType ecf = static_cast<Bonus::BonusType>(typeNo);
|
2009-06-28 16:49:39 +03:00
|
|
|
|
2010-11-19 00:06:56 +02:00
|
|
|
Bonus *b = creatures[creatureID]->getBonus(Selector::type(ecf));
|
|
|
|
creatures[creatureID]->removeBonus(b);
|
2009-06-28 16:49:39 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case '0': //end reading
|
|
|
|
{
|
|
|
|
contReading = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: //invalid command
|
|
|
|
{
|
|
|
|
tlog1 << "Parse error in file config/cr_abils.txt" << std::endl;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
abils.close();
|
|
|
|
|
2011-08-21 00:53:03 +03:00
|
|
|
// loading creatures properties
|
|
|
|
tlog5 << "\t\tReading config/creatures.json" << std::endl;
|
|
|
|
const JsonNode config(DATA_DIR "/config/creatures.json");
|
|
|
|
const JsonVector &creatures_vec = config["creatures"].Vector();
|
2008-11-01 00:41:22 +02:00
|
|
|
|
2011-08-21 00:53:03 +03:00
|
|
|
for (JsonVector::const_iterator it = creatures_vec.begin(); it!=creatures_vec.end(); ++it) {
|
|
|
|
const JsonNode &creature = *it;
|
|
|
|
int creatureID = creature["id"].Float();
|
2011-08-30 09:19:07 +03:00
|
|
|
const JsonNode *value;
|
2011-02-10 15:12:53 +02:00
|
|
|
|
2011-08-21 00:53:03 +03:00
|
|
|
/* A creature can have several names. */
|
|
|
|
const JsonVector &names_vec = creature["name"].Vector();
|
|
|
|
for (JsonVector::const_iterator it = names_vec.begin(); it!=names_vec.end(); ++it) {
|
|
|
|
const std::string name = (*it).String();
|
2011-02-22 11:47:25 +02:00
|
|
|
|
2011-08-21 00:53:03 +03:00
|
|
|
boost::assign::insert(nameToID)(name, creatureID);
|
|
|
|
}
|
2011-02-10 15:12:53 +02:00
|
|
|
|
2011-08-21 00:53:03 +03:00
|
|
|
// Set various creature properties
|
|
|
|
CCreature *c = creatures[creatureID];
|
|
|
|
c->level = creature["level"].Float();
|
|
|
|
c->faction = creature["faction"].Float();
|
|
|
|
c->animDefName = creature["defname"].String();
|
2008-04-04 20:30:53 +03:00
|
|
|
|
2011-08-30 09:19:07 +03:00
|
|
|
value = &creature["upgrade"];
|
|
|
|
if (!value->isNull())
|
|
|
|
c->upgrades.insert(value->Float());
|
2007-10-17 01:39:11 +03:00
|
|
|
|
2011-08-30 09:19:07 +03:00
|
|
|
value = &creature["projectile_defname"];
|
|
|
|
if (!value->isNull()) {
|
|
|
|
idToProjectile[creatureID] = value->String();
|
|
|
|
|
|
|
|
value = &creature["projectile_spin"];
|
|
|
|
idToProjectileSpin[creatureID] = value->Bool();
|
|
|
|
}
|
|
|
|
|
|
|
|
value = &creature["turret_shooter"];
|
|
|
|
if (!value->isNull() && value->Bool())
|
2011-08-21 00:53:03 +03:00
|
|
|
factionToTurretCreature[c->faction] = creatureID;
|
2008-08-02 18:08:03 +03:00
|
|
|
}
|
2009-09-05 17:10:26 +03:00
|
|
|
|
2011-08-21 00:53:03 +03:00
|
|
|
buildBonusTreeForTiers();
|
|
|
|
loadAnimationInfo();
|
2011-02-02 20:49:48 +02:00
|
|
|
|
|
|
|
//reading creature ability names
|
2011-08-21 01:31:59 +03:00
|
|
|
const JsonNode config2(DATA_DIR "/config/bonusnames.json");
|
|
|
|
const JsonVector &bonuses_vec = config2["bonuses"].Vector();
|
|
|
|
|
|
|
|
for (JsonVector::const_iterator it = bonuses_vec.begin(); it!=bonuses_vec.end(); ++it) {
|
|
|
|
const JsonNode &bonus = *it;
|
|
|
|
std::map<std::string,int>::const_iterator it_map;
|
|
|
|
std::string bonusID = bonus["id"].String();
|
|
|
|
|
|
|
|
it_map = bonusNameMap.find(bonusID);
|
|
|
|
if (it_map != bonusNameMap.end()) {
|
|
|
|
stackBonuses[it_map->second] = std::pair<std::string, std::string>(bonus["name"].String(), bonus["description"].String());
|
|
|
|
} else
|
|
|
|
tlog2 << "Bonus " << bonusID << " not recognized, ignoring\n";
|
2011-02-02 20:49:48 +02:00
|
|
|
}
|
2011-08-21 01:31:59 +03:00
|
|
|
|
2011-06-18 13:58:46 +03:00
|
|
|
//handle magic resistance secondary skill premy, potentialy may be buggy
|
|
|
|
std::map<TBonusType, std::pair<std::string, std::string> >::iterator it = stackBonuses.find(Bonus::MAGIC_RESISTANCE);
|
|
|
|
stackBonuses[Bonus::SECONDARY_SKILL_PREMY] = std::pair<std::string, std::string>(it->second.first, it->second.second);
|
2011-02-03 14:58:46 +02:00
|
|
|
|
|
|
|
if (STACK_EXP) //reading default stack experience bonuses
|
|
|
|
{
|
|
|
|
buf = bitmaph->getTextFile("CREXPBON.TXT");
|
2011-02-06 10:32:05 +02:00
|
|
|
int it = 0;
|
|
|
|
si32 creid = -1;
|
2011-02-11 10:20:26 +02:00
|
|
|
Bonus b; //prototype with some default properties
|
2011-02-03 14:58:46 +02:00
|
|
|
b.source = Bonus::STACK_EXPERIENCE;
|
2011-02-13 15:16:41 +02:00
|
|
|
b.duration = Bonus::PERMANENT;
|
2011-02-11 10:20:26 +02:00
|
|
|
b.valType = Bonus::ADDITIVE_VALUE;
|
2011-02-13 15:16:41 +02:00
|
|
|
b.effectRange = Bonus::NO_LIMIT;
|
2011-02-08 13:34:34 +02:00
|
|
|
b.additionalInfo = 0;
|
2011-02-14 23:08:29 +02:00
|
|
|
b.turnsRemain = 0;
|
2011-02-11 10:20:26 +02:00
|
|
|
BonusList bl;
|
2011-08-21 01:31:59 +03:00
|
|
|
std::string dump2;
|
2011-02-03 14:58:46 +02:00
|
|
|
|
|
|
|
loadToIt (dump2, buf, it, 3); //ignore first line
|
|
|
|
loadToIt (dump2, buf, it, 4); //ignore index
|
2011-02-11 10:20:26 +02:00
|
|
|
|
|
|
|
loadStackExp(b, bl, buf, it);
|
|
|
|
BOOST_FOREACH(Bonus * b, bl)
|
|
|
|
addBonusForAllCreatures(b); //health bonus is common for all
|
|
|
|
|
2011-02-13 15:16:41 +02:00
|
|
|
loadToIt (dump2, buf, it, 3); //crop comment
|
2011-02-13 21:46:16 +02:00
|
|
|
for (i = 1; i < 7; ++i)
|
2011-02-03 14:58:46 +02:00
|
|
|
{
|
|
|
|
for (int j = 0; j < 4; ++j) //four modifiers common for tiers
|
|
|
|
{
|
|
|
|
loadToIt (dump2, buf, it, 4); //ignore index
|
2011-02-11 10:20:26 +02:00
|
|
|
bl.clear();
|
|
|
|
loadStackExp(b, bl, buf, it);
|
|
|
|
BOOST_FOREACH(Bonus * b, bl)
|
|
|
|
addBonusForTier(i, b);
|
2011-02-03 14:58:46 +02:00
|
|
|
loadToIt (dump2, buf, it, 3); //crop comment
|
|
|
|
}
|
|
|
|
}
|
2011-02-13 21:46:16 +02:00
|
|
|
for (int j = 0; j < 4; ++j) //tier 7
|
|
|
|
{
|
|
|
|
loadToIt (dump2, buf, it, 4); //ignore index
|
|
|
|
bl.clear();
|
|
|
|
loadStackExp(b, bl, buf, it);
|
|
|
|
BOOST_FOREACH(Bonus * b, bl)
|
|
|
|
{
|
|
|
|
addBonusForTier(7, b);
|
|
|
|
creaturesOfLevel[0].addNewBonus(b); //bonuses from level 7 are given to high-level creatures
|
|
|
|
}
|
|
|
|
loadToIt (dump2, buf, it, 3); //crop comment
|
|
|
|
}
|
2011-02-03 14:58:46 +02:00
|
|
|
do //parse everything that's left
|
|
|
|
{
|
|
|
|
loadToIt(creid, buf, it, 4); //get index
|
2011-02-20 20:32:39 +02:00
|
|
|
b.sid = creid; //id = this particular creature ID
|
2011-07-13 21:39:02 +03:00
|
|
|
loadStackExp(b, creatures[creid]->getBonusList(), buf, it); //add directly to CCreature Node
|
2011-02-03 14:58:46 +02:00
|
|
|
loadToIt (dump2, buf, it, 3); //crop comment
|
2011-02-06 10:32:05 +02:00
|
|
|
} while (it < buf.size());
|
|
|
|
|
2011-02-11 10:20:26 +02:00
|
|
|
//Calculate rank exp values, formula appears complicated bu no parsing needed
|
|
|
|
expRanks.resize(8);
|
|
|
|
int dif = 0;
|
|
|
|
it = 8000; //ignore name of this variable
|
|
|
|
expRanks[0].push_back(it);
|
|
|
|
for (int j = 1; j < 10; ++j) //used for tiers 8-10, and all other probably
|
|
|
|
{
|
2011-02-12 18:21:48 +02:00
|
|
|
expRanks[0].push_back(expRanks[0][j-1] + it + dif);
|
2011-02-11 10:20:26 +02:00
|
|
|
dif += it/5;
|
|
|
|
}
|
2011-02-12 18:21:48 +02:00
|
|
|
for (i = 1; i < 8; ++i)
|
2011-02-11 10:20:26 +02:00
|
|
|
{
|
|
|
|
dif = 0;
|
|
|
|
it = 1000 * i;
|
|
|
|
expRanks[i].push_back(it);
|
|
|
|
for (int j = 1; j < 10; ++j)
|
|
|
|
{
|
2011-02-12 18:21:48 +02:00
|
|
|
expRanks[i].push_back(expRanks[i][j-1] + it + dif);
|
2011-02-11 10:20:26 +02:00
|
|
|
dif += it/5;
|
|
|
|
}
|
|
|
|
}
|
2011-02-10 15:12:53 +02:00
|
|
|
|
2011-02-12 18:21:48 +02:00
|
|
|
buf = bitmaph->getTextFile("CREXPMOD.TXT"); //could be hardcoded though, lots of useless info
|
|
|
|
it = 0;
|
|
|
|
loadToIt (dump2, buf, it, 3); //ignore first line
|
|
|
|
|
|
|
|
maxExpPerBattle.resize(8);
|
|
|
|
si32 val;
|
|
|
|
for (i = 1; i < 8; ++i)
|
|
|
|
{
|
2011-02-13 15:16:41 +02:00
|
|
|
loadToIt (dump2, buf, it, 4); //index
|
2011-02-12 18:21:48 +02:00
|
|
|
loadToIt (dump2, buf, it, 4); //float multiplier -> hardcoded
|
|
|
|
loadToIt (dump2, buf, it, 4); //ignore upgrade mod? ->hardcoded
|
|
|
|
loadToIt (dump2, buf, it, 4); //already calculated
|
|
|
|
loadToIt (val, buf, it, 4);
|
|
|
|
maxExpPerBattle[i] = (ui32)val;
|
|
|
|
loadToIt (val, buf, it, 4); //11th level
|
|
|
|
val += (si32)expRanks[i].back();
|
|
|
|
expRanks[i].push_back((ui32)val);
|
|
|
|
loadToIt (dump2, buf, it, 3); //crop comment
|
|
|
|
}
|
|
|
|
//skeleton gets exp penalty
|
|
|
|
creatures[56].get()->addBonus(-50, Bonus::EXP_MULTIPLIER, -1);
|
|
|
|
creatures[57].get()->addBonus(-50, Bonus::EXP_MULTIPLIER, -1);
|
|
|
|
//exp for tier >7, rank 11
|
2011-02-13 21:46:16 +02:00
|
|
|
expRanks[0].push_back(147000);
|
2011-02-12 18:21:48 +02:00
|
|
|
expAfterUpgrade = 75; //percent
|
2011-02-13 21:46:16 +02:00
|
|
|
maxExpPerBattle[0] = maxExpPerBattle[7];
|
2011-02-12 18:21:48 +02:00
|
|
|
|
2011-02-11 10:20:26 +02:00
|
|
|
}//end of Stack Experience
|
2011-02-10 15:12:53 +02:00
|
|
|
//experiment - add 100 to attack for creatures of tier 1
|
|
|
|
// Bonus *b = new Bonus(Bonus::PERMANENT, Bonus::PRIMARY_SKILL, Bonus::OTHER, +100, 0, 0);
|
|
|
|
// addBonusForTier(1, b);
|
2007-10-15 23:59:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void CCreatureHandler::loadAnimationInfo()
|
|
|
|
{
|
2008-06-12 09:45:51 +03:00
|
|
|
std::string buf = bitmaph->getTextFile("CRANIM.TXT");
|
2008-03-05 19:01:41 +02:00
|
|
|
int andame = buf.size();
|
|
|
|
int i=0; //buf iterator
|
|
|
|
int hmcr=0;
|
2010-10-25 22:37:21 +03:00
|
|
|
for(; i<andame; ++i)
|
2008-03-05 19:01:41 +02:00
|
|
|
{
|
|
|
|
if(buf[i]=='\r')
|
|
|
|
++hmcr;
|
|
|
|
if(hmcr==2)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
i+=2;
|
2008-11-01 00:41:22 +02:00
|
|
|
for(int dd=0; dd<creatures.size(); ++dd)
|
2008-03-05 19:01:41 +02:00
|
|
|
{
|
2008-11-01 00:41:22 +02:00
|
|
|
//tlog5 << "\t\t\tReading animation info for creature " << dd << std::endl;
|
2010-05-02 21:20:26 +03:00
|
|
|
loadUnitAnimInfo(*creatures[dd], buf, i);
|
2008-03-05 19:01:41 +02:00
|
|
|
}
|
2007-06-18 13:49:06 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCreatureHandler::loadUnitAnimInfo(CCreature & unit, std::string & src, int & i)
|
|
|
|
{
|
|
|
|
int befi=i;
|
2009-06-28 17:57:00 +03:00
|
|
|
|
|
|
|
unit.timeBetweenFidgets = readFloat(befi, i, src.size(), src);
|
2007-06-18 13:49:06 +03:00
|
|
|
|
|
|
|
while(unit.timeBetweenFidgets == 0.0)
|
|
|
|
{
|
2010-10-25 22:37:21 +03:00
|
|
|
for(; i<src.size(); ++i)
|
2007-06-18 13:49:06 +03:00
|
|
|
{
|
|
|
|
if(src[i]=='\r')
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
i+=2;
|
|
|
|
|
2009-06-28 17:57:00 +03:00
|
|
|
unit.timeBetweenFidgets = readFloat(befi, i, src.size(), src);
|
2007-06-18 13:49:06 +03:00
|
|
|
}
|
|
|
|
|
2009-06-28 17:57:00 +03:00
|
|
|
unit.walkAnimationTime = readFloat(befi, i, src.size(), src);
|
|
|
|
unit.attackAnimationTime = readFloat(befi, i, src.size(), src);
|
|
|
|
unit.flightAnimationDistance = readFloat(befi, i, src.size(), src);
|
2007-06-18 13:49:06 +03:00
|
|
|
///////////////////////
|
|
|
|
|
2009-06-28 17:57:00 +03:00
|
|
|
unit.upperRightMissleOffsetX = readNumber(befi, i, src.size(), src);
|
|
|
|
unit.upperRightMissleOffsetY = readNumber(befi, i, src.size(), src);
|
|
|
|
unit.rightMissleOffsetX = readNumber(befi, i, src.size(), src);
|
|
|
|
unit.rightMissleOffsetY = readNumber(befi, i, src.size(), src);
|
|
|
|
unit.lowerRightMissleOffsetX = readNumber(befi, i, src.size(), src);
|
|
|
|
unit.lowerRightMissleOffsetY = readNumber(befi, i, src.size(), src);
|
2007-06-18 13:49:06 +03:00
|
|
|
|
|
|
|
///////////////////////
|
|
|
|
|
|
|
|
for(int jjj=0; jjj<12; ++jjj)
|
|
|
|
{
|
2009-06-28 17:57:00 +03:00
|
|
|
unit.missleFrameAngles[jjj] = readFloat(befi, i, src.size(), src);
|
2007-06-18 13:49:06 +03:00
|
|
|
}
|
|
|
|
|
2009-06-28 17:57:00 +03:00
|
|
|
unit.troopCountLocationOffset= readNumber(befi, i, src.size(), src);
|
|
|
|
unit.attackClimaxFrame = readNumber(befi, i, src.size(), src);
|
2007-06-18 13:49:06 +03:00
|
|
|
|
2010-10-25 22:37:21 +03:00
|
|
|
for(; i<src.size(); ++i)
|
2007-06-18 13:49:06 +03:00
|
|
|
{
|
|
|
|
if(src[i]=='\r')
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
i+=2;
|
2008-08-02 18:08:03 +03:00
|
|
|
}
|
2009-01-11 00:08:18 +02:00
|
|
|
|
2011-02-11 10:20:26 +02:00
|
|
|
void CCreatureHandler::loadStackExp(Bonus & b, BonusList & bl, std::string & src, int & it) //help function for parsing CREXPBON.txt
|
2011-02-13 21:46:16 +02:00
|
|
|
{
|
2011-02-03 14:58:46 +02:00
|
|
|
std::string buf, mod;
|
2011-02-11 10:20:26 +02:00
|
|
|
bool enable = false; //some bonuses are activated with values 2 or 1
|
2011-02-03 14:58:46 +02:00
|
|
|
loadToIt(buf, src, it, 4);
|
|
|
|
loadToIt(mod, src, it, 4);
|
2011-02-11 10:20:26 +02:00
|
|
|
|
2011-02-03 14:58:46 +02:00
|
|
|
switch (buf[0])
|
|
|
|
{
|
2011-02-06 10:32:05 +02:00
|
|
|
case 'H':
|
|
|
|
b.type = Bonus::STACK_HEALTH;
|
2011-02-11 10:20:26 +02:00
|
|
|
b.valType = Bonus::PERCENT_TO_BASE;
|
2011-02-06 10:32:05 +02:00
|
|
|
break;
|
|
|
|
case 'A':
|
|
|
|
b.type = Bonus::PRIMARY_SKILL;
|
|
|
|
b.subtype = PrimarySkill::ATTACK;
|
|
|
|
break;
|
|
|
|
case 'D':
|
|
|
|
b.type = Bonus::PRIMARY_SKILL;
|
|
|
|
b.subtype = PrimarySkill::DEFENSE;
|
|
|
|
break;
|
|
|
|
case 'M': //Max damage
|
|
|
|
b.type = Bonus::CREATURE_DAMAGE;
|
|
|
|
b.subtype = 2;
|
|
|
|
break;
|
|
|
|
case 'm': //Min damage
|
|
|
|
b.type = Bonus::CREATURE_DAMAGE;
|
|
|
|
b.subtype = 1;
|
|
|
|
break;
|
2011-02-08 13:34:34 +02:00
|
|
|
case 'S':
|
2011-02-13 21:46:16 +02:00
|
|
|
b.type = Bonus::STACKS_SPEED; break;
|
2011-04-12 11:59:18 +03:00
|
|
|
case 'O':
|
|
|
|
b.type = Bonus::SHOTS; break;
|
2011-02-08 13:34:34 +02:00
|
|
|
|
|
|
|
case 'b':
|
|
|
|
b.type = Bonus::ENEMY_DEFENCE_REDUCTION; break;
|
|
|
|
case 'C':
|
|
|
|
b.type = Bonus::CHANGES_SPELL_COST_FOR_ALLY; break;
|
2011-07-16 19:40:38 +03:00
|
|
|
case 'd':
|
|
|
|
b.type = Bonus::DEFENSIVE_STANCE; break;
|
2011-02-08 13:34:34 +02:00
|
|
|
case 'e':
|
|
|
|
b.type = Bonus::DOUBLE_DAMAGE_CHANCE; break;
|
2011-04-23 20:10:54 +03:00
|
|
|
case 'E':
|
|
|
|
b.type = Bonus::DEATH_STARE;
|
|
|
|
b.subtype = 0; //Gorgon
|
|
|
|
break;
|
2011-02-08 13:34:34 +02:00
|
|
|
case 'g':
|
2011-03-08 09:40:14 +02:00
|
|
|
b.type = Bonus::SPELL_DAMAGE_REDUCTION;
|
|
|
|
b.subtype = -1; //all magic schools
|
|
|
|
break;
|
2011-05-15 09:37:57 +03:00
|
|
|
case 'P':
|
|
|
|
b.type = Bonus::CASTS; break;
|
2011-02-09 16:58:15 +02:00
|
|
|
case 'R':
|
|
|
|
b.type = Bonus::ADDITIONAL_RETALIATION; break;
|
2011-05-13 20:51:12 +03:00
|
|
|
case 'W':
|
|
|
|
b.type = Bonus::MAGIC_RESISTANCE;
|
2011-05-15 09:37:57 +03:00
|
|
|
b.subtype = 0; //otherwise creature window goes crazy
|
2011-05-13 20:51:12 +03:00
|
|
|
break;
|
2011-02-08 13:34:34 +02:00
|
|
|
|
|
|
|
case 'f': //on-off skill
|
2011-02-11 10:20:26 +02:00
|
|
|
enable = true; //sometimes format is: 2 -> 0, 1 -> 1
|
2011-02-08 13:34:34 +02:00
|
|
|
switch (mod[0])
|
|
|
|
{
|
|
|
|
case 'A':
|
|
|
|
b.type = Bonus::ATTACKS_ALL_ADJACENT; break;
|
|
|
|
case 'b':
|
|
|
|
b.type = Bonus::RETURN_AFTER_STRIKE; break;
|
|
|
|
case 'B':
|
|
|
|
b.type = Bonus::TWO_HEX_ATTACK_BREATH; break;
|
|
|
|
case 'c':
|
|
|
|
b.type = Bonus::JOUSTING; break;
|
|
|
|
case 'D':
|
|
|
|
b.type = Bonus::ADDITIONAL_ATTACK; break;
|
|
|
|
case 'f':
|
|
|
|
b.type = Bonus::FEARLESS; break;
|
|
|
|
case 'F':
|
|
|
|
b.type = Bonus::FLYING; break;
|
|
|
|
case 'm':
|
|
|
|
b.type = Bonus::SELF_MORALE; break;
|
|
|
|
case 'M':
|
|
|
|
b.type = Bonus::NO_MORALE; break;
|
|
|
|
case 'p': //Mind spells
|
|
|
|
case 'P':
|
|
|
|
{
|
2011-02-11 10:20:26 +02:00
|
|
|
loadMindImmunity(b, bl, src, it);
|
2011-02-08 13:34:34 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
return;
|
2011-07-10 12:03:46 +03:00
|
|
|
case 'r':
|
|
|
|
b.type = Bonus::REBIRTH; //on/off? makes sense?
|
|
|
|
b.subtype = 0;
|
|
|
|
b.val = 20; //arbitrary value
|
2011-02-08 13:34:34 +02:00
|
|
|
break;
|
|
|
|
case 'R':
|
|
|
|
b.type = Bonus::BLOCKS_RETALIATION; break;
|
|
|
|
case 's':
|
|
|
|
b.type = Bonus::FREE_SHOOTING; break;
|
|
|
|
case 'u':
|
|
|
|
b.type = Bonus::SPELL_RESISTANCE_AURA; break;
|
|
|
|
case 'U':
|
|
|
|
b.type = Bonus::UNDEAD; break;
|
|
|
|
default:
|
|
|
|
tlog3 << "Not parsed bonus " << buf << mod << "\n";
|
2011-02-14 23:08:29 +02:00
|
|
|
return;
|
2011-02-08 13:34:34 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2011-02-09 16:58:15 +02:00
|
|
|
case 'w': //specific spell immunities, enabled/disabled
|
2011-02-11 10:20:26 +02:00
|
|
|
enable = true;
|
2011-02-09 16:58:15 +02:00
|
|
|
switch (mod[0])
|
|
|
|
{
|
|
|
|
case 'B': //Blind
|
|
|
|
b.type = Bonus::SPELL_IMMUNITY;
|
|
|
|
b.subtype = 74;
|
|
|
|
break;
|
|
|
|
case 'H': //Hypnotize
|
|
|
|
b.type = Bonus::SPELL_IMMUNITY;
|
|
|
|
b.subtype = 60;
|
|
|
|
break;
|
|
|
|
case 'I': //Implosion
|
|
|
|
b.type = Bonus::SPELL_IMMUNITY;
|
|
|
|
b.subtype = 18;
|
|
|
|
break;
|
|
|
|
case 'K': //Berserk
|
|
|
|
b.type = Bonus::SPELL_IMMUNITY;
|
|
|
|
b.subtype = 59;
|
|
|
|
break;
|
|
|
|
case 'M': //Meteor Shower
|
|
|
|
b.type = Bonus::SPELL_IMMUNITY;
|
|
|
|
b.subtype = 23;
|
|
|
|
break;
|
2011-05-28 08:34:40 +03:00
|
|
|
case 'N': //dispell beneficial spells
|
|
|
|
b.type = Bonus::SPELL_IMMUNITY;
|
|
|
|
b.subtype = 78;
|
|
|
|
break;
|
2011-02-09 16:58:15 +02:00
|
|
|
case 'R': //Armageddon
|
|
|
|
b.type = Bonus::SPELL_IMMUNITY;
|
|
|
|
b.subtype = 26;
|
|
|
|
break;
|
|
|
|
case 'S': //Slow
|
|
|
|
b.type = Bonus::SPELL_IMMUNITY;
|
|
|
|
b.subtype = 54;
|
|
|
|
break;
|
2011-02-13 21:46:16 +02:00
|
|
|
case '6':
|
2011-02-09 16:58:15 +02:00
|
|
|
case '7':
|
|
|
|
case '8':
|
|
|
|
case '9':
|
2011-05-21 10:07:07 +03:00
|
|
|
b.type = Bonus::LEVEL_SPELL_IMMUNITY;
|
2011-02-09 16:58:15 +02:00
|
|
|
b.val = std::atoi(mod.c_str()) - 5;
|
|
|
|
break;
|
|
|
|
case ':':
|
|
|
|
b.type = Bonus::LEVEL_SPELL_IMMUNITY;
|
|
|
|
b.val = SPELL_LEVELS; //in case someone adds higher level spells?
|
|
|
|
break;
|
2011-05-13 20:51:12 +03:00
|
|
|
case 'F':
|
|
|
|
b.type = Bonus::FIRE_IMMUNITY;
|
|
|
|
b.subtype = 1; //not positive
|
|
|
|
break;
|
|
|
|
case 'O':
|
|
|
|
b.type = Bonus::FIRE_IMMUNITY;
|
|
|
|
b.subtype = 2; //only direct damage
|
|
|
|
break;
|
|
|
|
case 'f':
|
|
|
|
b.type = Bonus::FIRE_IMMUNITY;
|
|
|
|
b.subtype = 0; //all
|
|
|
|
break;
|
|
|
|
case 'C':
|
|
|
|
b.type = Bonus::WATER_IMMUNITY;
|
|
|
|
b.subtype = 1; //not positive
|
|
|
|
break;
|
|
|
|
case 'W':
|
|
|
|
b.type = Bonus::WATER_IMMUNITY;
|
|
|
|
b.subtype = 2; //only direct damage
|
|
|
|
break;
|
|
|
|
case 'w':
|
|
|
|
b.type = Bonus::WATER_IMMUNITY;
|
|
|
|
b.subtype = 0; //all
|
|
|
|
break;
|
|
|
|
case 'E':
|
|
|
|
b.type = Bonus::EARTH_IMMUNITY;
|
|
|
|
b.subtype = 2; //only direct damage
|
|
|
|
break;
|
|
|
|
case 'e':
|
|
|
|
b.type = Bonus::EARTH_IMMUNITY;
|
|
|
|
b.subtype = 0; //all
|
|
|
|
break;
|
|
|
|
case 'A':
|
|
|
|
b.type = Bonus::AIR_IMMUNITY;
|
|
|
|
b.subtype = 2; //only direct damage
|
|
|
|
break;
|
|
|
|
case 'a':
|
|
|
|
b.type = Bonus::AIR_IMMUNITY;
|
|
|
|
b.subtype = 0; //all
|
|
|
|
break;
|
|
|
|
case 'D':
|
|
|
|
b.type = Bonus::DIRECT_DAMAGE_IMMUNITY;
|
|
|
|
break;
|
|
|
|
case '0':
|
|
|
|
b.type = Bonus::RECEPTIVE;
|
|
|
|
break;
|
2011-02-09 16:58:15 +02:00
|
|
|
default:
|
|
|
|
tlog3 << "Not parsed bonus " << buf << mod << "\n";
|
2011-02-14 23:08:29 +02:00
|
|
|
return;
|
2011-02-09 16:58:15 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2011-02-08 13:34:34 +02:00
|
|
|
case 'i':
|
2011-02-11 10:20:26 +02:00
|
|
|
enable = true;
|
2011-02-08 13:34:34 +02:00
|
|
|
b.type = Bonus::NO_DISTANCE_PENALTY;
|
|
|
|
break;
|
|
|
|
case 'o':
|
2011-02-11 10:20:26 +02:00
|
|
|
enable = true;
|
2011-02-08 13:34:34 +02:00
|
|
|
b.type = Bonus::NO_OBSTACLES_PENALTY;
|
|
|
|
break;
|
2011-02-09 16:58:15 +02:00
|
|
|
|
|
|
|
case 'a':
|
2011-04-25 12:03:13 +03:00
|
|
|
case 'c': //some special abilities are threated as spells, work in progress
|
2011-02-09 16:58:15 +02:00
|
|
|
b.type = Bonus::SPELL_AFTER_ATTACK;
|
|
|
|
b.subtype = stringToNumber(mod);
|
|
|
|
break;
|
|
|
|
case 'h':
|
|
|
|
b.type= Bonus::HATE;
|
|
|
|
b.subtype = stringToNumber(mod);
|
|
|
|
break;
|
2011-07-16 09:42:44 +03:00
|
|
|
case 'p':
|
|
|
|
b.type = Bonus::SPELL_BEFORE_ATTACK;
|
|
|
|
b.subtype = stringToNumber(mod);
|
|
|
|
b.additionalInfo = 3; //always expert?
|
|
|
|
break;
|
2011-02-08 13:34:34 +02:00
|
|
|
default:
|
|
|
|
tlog3 << "Not parsed bonus " << buf << mod << "\n";
|
2011-02-14 23:08:29 +02:00
|
|
|
return;
|
2011-02-08 13:34:34 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
switch (mod[0])
|
|
|
|
{
|
|
|
|
case '+':
|
|
|
|
case '=': //should we allow percent values to stack or pick highest?
|
2011-02-11 10:20:26 +02:00
|
|
|
b.valType = Bonus::ADDITIVE_VALUE;
|
2011-02-08 13:34:34 +02:00
|
|
|
break;
|
2011-02-03 14:58:46 +02:00
|
|
|
}
|
2011-02-11 10:20:26 +02:00
|
|
|
|
|
|
|
//limiters, range
|
|
|
|
si32 lastVal, curVal, lastLev = 0;
|
|
|
|
|
|
|
|
if (enable) //0 and 2 means non-active, 1 - active
|
2011-02-03 14:58:46 +02:00
|
|
|
{
|
2011-07-10 12:03:46 +03:00
|
|
|
if (b.type != Bonus::REBIRTH)
|
|
|
|
b.val = 0; //on-off ability, no value specified
|
2011-02-11 10:20:26 +02:00
|
|
|
loadToIt (curVal, src, it, 4); // 0 level is never active
|
|
|
|
for (int i = 1; i < 11; ++i)
|
|
|
|
{
|
|
|
|
loadToIt (curVal, src, it, 4);
|
|
|
|
if (curVal == 1)
|
|
|
|
{
|
2011-02-12 18:12:48 +02:00
|
|
|
b.limiter.reset (new RankRangeLimiter(i));
|
2011-02-11 10:20:26 +02:00
|
|
|
bl.push_back(new Bonus(b));
|
|
|
|
break; //never turned off it seems
|
|
|
|
}
|
|
|
|
}
|
2011-02-03 14:58:46 +02:00
|
|
|
}
|
2011-02-11 10:20:26 +02:00
|
|
|
else
|
2011-02-08 13:34:34 +02:00
|
|
|
{
|
2011-02-11 10:20:26 +02:00
|
|
|
loadToIt (lastVal, src, it, 4); //basic value, not particularly useful but existent
|
|
|
|
for (int i = 1; i < 11; ++i)
|
2011-02-08 13:34:34 +02:00
|
|
|
{
|
2011-02-11 10:20:26 +02:00
|
|
|
loadToIt (curVal, src, it, 4);
|
2011-03-06 14:12:22 +02:00
|
|
|
if (b.type == Bonus::HATE)
|
|
|
|
curVal *= 10; //odd fix
|
2011-02-13 15:16:41 +02:00
|
|
|
if (curVal > lastVal) //threshold, add new bonus
|
2011-02-11 10:20:26 +02:00
|
|
|
{
|
2011-02-13 15:16:41 +02:00
|
|
|
b.val = curVal - lastVal;
|
|
|
|
lastVal = curVal;
|
2011-02-12 18:12:48 +02:00
|
|
|
b.limiter.reset (new RankRangeLimiter(i));
|
2011-02-11 10:20:26 +02:00
|
|
|
bl.push_back(new Bonus(b));
|
|
|
|
lastLev = i; //start new range from here, i = previous rank
|
|
|
|
}
|
|
|
|
else if (curVal < lastVal)
|
|
|
|
{
|
|
|
|
b.val = lastVal;
|
|
|
|
b.limiter.reset (new RankRangeLimiter(lastLev, i));
|
|
|
|
}
|
2011-02-08 13:34:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-11 10:20:26 +02:00
|
|
|
void CCreatureHandler::loadMindImmunity(Bonus & b, BonusList & bl, std::string & src, int & it)
|
2011-02-08 13:34:34 +02:00
|
|
|
{
|
2011-02-20 20:32:39 +02:00
|
|
|
CCreature * cre = creatures[b.sid]; //odd workaround
|
2011-02-08 13:34:34 +02:00
|
|
|
|
|
|
|
b.type = Bonus::SPELL_IMMUNITY;
|
|
|
|
b.val = Bonus::BASE_NUMBER;
|
2011-05-04 05:38:58 +03:00
|
|
|
si32 curVal;
|
2011-02-08 13:34:34 +02:00
|
|
|
|
2011-02-17 11:06:24 +02:00
|
|
|
b.val = 0; //on-off ability, no value specified
|
|
|
|
loadToIt (curVal, src, it, 4); // 0 level is never active
|
|
|
|
for (int i = 1; i < 11; ++i)
|
2011-02-08 13:34:34 +02:00
|
|
|
{
|
2011-02-17 11:06:24 +02:00
|
|
|
loadToIt (curVal, src, it, 4);
|
|
|
|
if (curVal == 1)
|
|
|
|
{
|
|
|
|
b.limiter.reset (new RankRangeLimiter(i));
|
|
|
|
break; //only one limiter here
|
|
|
|
}
|
2011-02-08 13:34:34 +02:00
|
|
|
}
|
2011-02-17 11:06:24 +02:00
|
|
|
|
|
|
|
std::vector<int> mindSpells = getMindSpells(); //multiplicate spells
|
2011-02-08 13:34:34 +02:00
|
|
|
for (int g=0; g < mindSpells.size(); ++g)
|
|
|
|
{
|
|
|
|
b.subtype = mindSpells[g];
|
2011-07-13 21:39:02 +03:00
|
|
|
cre->getBonusList().push_back(new Bonus(b));
|
2011-02-08 13:34:34 +02:00
|
|
|
}
|
2011-02-03 14:58:46 +02:00
|
|
|
}
|
|
|
|
|
2011-02-09 16:58:15 +02:00
|
|
|
int CCreatureHandler::stringToNumber(std::string & s)
|
|
|
|
{
|
|
|
|
boost::algorithm::replace_first(s,"#",""); //drop hash character
|
|
|
|
return std::atoi(s.c_str());
|
|
|
|
}
|
|
|
|
|
2009-01-11 00:08:18 +02:00
|
|
|
CCreatureHandler::~CCreatureHandler()
|
|
|
|
{
|
2009-05-24 01:57:39 +03:00
|
|
|
}
|
2010-07-24 00:05:49 +03:00
|
|
|
|
2011-02-10 15:12:53 +02:00
|
|
|
static int retreiveRandNum(const boost::function<int()> &randGen)
|
|
|
|
{
|
|
|
|
if(randGen)
|
|
|
|
return randGen();
|
|
|
|
else
|
|
|
|
return rand();
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T> const T & pickRandomElementOf(const std::vector<T> &v, const boost::function<int()> &randGen)
|
|
|
|
{
|
|
|
|
return v[retreiveRandNum(randGen) % v.size()];
|
|
|
|
}
|
|
|
|
|
|
|
|
int CCreatureHandler::pickRandomMonster(const boost::function<int()> &randGen, int tier) const
|
2010-07-24 00:05:49 +03:00
|
|
|
{
|
|
|
|
int r = 0;
|
2011-02-10 15:12:53 +02:00
|
|
|
if(tier == -1) //pick any allowed creature
|
2010-07-24 00:05:49 +03:00
|
|
|
{
|
2011-02-10 15:12:53 +02:00
|
|
|
do
|
|
|
|
{
|
2011-04-07 19:44:24 +03:00
|
|
|
r = pickRandomElementOf(creatures, randGen)->idNumber;
|
2011-02-10 15:12:53 +02:00
|
|
|
} while (vstd::contains(VLC->creh->notUsedMonsters,r));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
assert(iswith(tier, 1, 7));
|
|
|
|
std::vector<int> allowed;
|
2011-07-13 21:39:02 +03:00
|
|
|
BOOST_FOREACH(const CBonusSystemNode *b, creaturesOfLevel[tier].getChildrenNodes())
|
2011-02-10 15:12:53 +02:00
|
|
|
{
|
2011-07-13 21:39:02 +03:00
|
|
|
assert(b->getNodeType() == CBonusSystemNode::CREATURE);
|
2011-02-10 15:12:53 +02:00
|
|
|
int creid = static_cast<const CCreature*>(b)->idNumber;
|
|
|
|
if(!vstd::contains(notUsedMonsters, creid))
|
2010-07-24 00:05:49 +03:00
|
|
|
|
2011-02-10 15:12:53 +02:00
|
|
|
allowed.push_back(creid);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!allowed.size())
|
|
|
|
{
|
|
|
|
tlog2 << "Cannot pick a random creature of tier " << tier << "!\n";
|
|
|
|
return 0;
|
|
|
|
}
|
2010-07-24 00:05:49 +03:00
|
|
|
|
2011-02-10 15:12:53 +02:00
|
|
|
return pickRandomElementOf(allowed, randGen);
|
|
|
|
}
|
2010-07-24 00:05:49 +03:00
|
|
|
return r;
|
2011-02-10 15:12:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CCreatureHandler::addBonusForTier(int tier, Bonus *b)
|
|
|
|
{
|
|
|
|
assert(iswith(tier, 1, 7));
|
|
|
|
creaturesOfLevel[tier].addNewBonus(b);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCreatureHandler::addBonusForAllCreatures(Bonus *b)
|
|
|
|
{
|
|
|
|
allCreatures.addNewBonus(b);
|
2011-02-22 11:47:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CCreatureHandler::buildBonusTreeForTiers()
|
|
|
|
{
|
|
|
|
BOOST_FOREACH(CCreature *c, creatures)
|
|
|
|
{
|
|
|
|
if(isbetw(c->level, 0, ARRAY_COUNT(creaturesOfLevel)))
|
|
|
|
c->attachTo(&creaturesOfLevel[c->level]);
|
|
|
|
else
|
|
|
|
c->attachTo(&creaturesOfLevel[0]);
|
|
|
|
}
|
|
|
|
BOOST_FOREACH(CBonusSystemNode &b, creaturesOfLevel)
|
|
|
|
b.attachTo(&allCreatures);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCreatureHandler::deserializationFix()
|
|
|
|
{
|
|
|
|
buildBonusTreeForTiers();
|
2011-05-04 05:38:58 +03:00
|
|
|
}
|