#define VCMI_DLL #include "../stdafx.h" #include "CCreatureHandler.h" #include "CLodHandler.h" #include #include #include #include #include #include #include "../lib/VCMI_Lib.h" using namespace boost::assign; extern CLodHandler * bitmaph; /* * 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 * */ static std::vector getMindSpells() { std::vector ret; ret.push_back(50); //sorrow ret.push_back(59); //berserk ret.push_back(60); //hypnotize ret.push_back(61); //forgetfulness return ret; } CCreatureHandler::CCreatureHandler() { VLC->creh = this; } int CCreature::getQuantityID(const int & quantity) { 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 5; if (quantity<1000) return 6; if (quantity<4000) return 7; return 8; } bool CCreature::isDoubleWide() const { return vstd::contains(abilities, StackFeature::DOUBLE_WIDE); } bool CCreature::isFlying() const { return vstd::contains(abilities, StackFeature::FLYING); } bool CCreature::isShooting() const { return vstd::contains(abilities, StackFeature::SHOOTER); } bool CCreature::isUndead() const { return vstd::contains(abilities, StackFeature::UNDEAD); } si32 CCreature::maxAmount(const std::vector &res) const //how many creatures can be bought { int ret = 2147483645; int resAmnt = std::min(res.size(),cost.size()); for(int i=0;igetTextFile("ZCRTRAIT.TXT"); int andame = buf.size(); int i=0; //buf iterator int hmcr=0; for(i; i mindSpells = getMindSpells(); for(int g=0; g> command; switch(command) { case '+': //add new ability { int creatureID; StackFeature nsf; si32 buf; reader >> creatureID; reader >> buf; nsf.type = buf; //it reads ui8 as byte, in file it has different format reader >> buf; nsf.value = buf; reader >> buf; nsf.subtype = buf; reader >> buf; nsf.additionalInfo = buf; nsf.source = StackFeature::CREATURE_ABILITY; nsf.duration = StackFeature::WHOLE_BATTLE; nsf.turnsRemain = 0; creatures[creatureID].abilities += nsf; break; } case '-': //remove ability { int creatureID; ui32 type; reader >> creatureID; reader >> type; StackFeature::ECombatFeatures ecf = static_cast(type); creatures[creatureID].abilities -= ecf; 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(); tlog5 << "\t\tReading config/crerefnam.txt" << std::endl; //loading reference names std::ifstream ifs("config/crerefnam.txt"); int tempi; std::string temps; for (;;) { ifs >> tempi >> temps; if (tempi>=creatures.size()) break; boost::assign::insert(nameToID)(temps,tempi); creatures[tempi].nameRef=temps; } ifs.close(); ifs.clear(); for(int i=1;i<=10;i++) levelCreatures.insert(std::pair >(i,std::vector())); tlog5 << "\t\tReading config/monsters.txt" << std::endl; ifs.open("config/monsters.txt"); { while(!ifs.eof()) { int id, lvl; ifs >> id >> lvl; if(lvl>0) { creatures[id].level = lvl; levelCreatures[lvl].push_back(&(creatures[id])); } } } ifs.close(); ifs.clear(); tlog5 << "\t\tReading config/cr_factions.txt" << std::endl; ifs.open("config/cr_factions.txt"); while(!ifs.eof()) { int id, fact; ifs >> id >> fact; creatures[id].faction = fact; } ifs.close(); ifs.clear(); tlog5 << "\t\tReading config/cr_upgrade_list.txt" << std::endl; ifs.open("config/cr_upgrade_list.txt"); while(!ifs.eof()) { int id, up; ifs >> id >> up; creatures[id].upgrades.insert(up); } ifs.close(); ifs.clear(); //loading unit animation def names tlog5 << "\t\tReading config/CREDEFS.TXT" << std::endl; std::ifstream inp("config/CREDEFS.TXT", std::ios::in | std::ios::binary); //this file is not in lod inp.seekg(0,std::ios::end); // na koniec int andame2 = inp.tellg(); // read length inp.seekg(0,std::ios::beg); // wracamy na poczatek char * bufor = new char[andame2+1]; // allocate memory inp.read((char*)bufor, andame2); // read map file to buffer inp.close(); bufor[andame2] = 0; buf = std::string(bufor); delete [] bufor; i = 0; //buf iterator hmcr = 0; for(i; i>id; if(id == -1) break; inp2>>name; idToProjectile[id] = name; inp2>>spin; idToProjectileSpin[id] = spin; } inp2.close(); //TODO: create a tidy configuration file to control fixing unit abilities /* creatures[115].abilities.push_back(makeCreatureAbility(StackFeature::DOUBLE_WIDE, 0));//water elemental should be treated as double-wide creatures[123].abilities.push_back(makeCreatureAbility(StackFeature::DOUBLE_WIDE, 0));//ice elemental should be treated as double-wide creatures[140].abilities.push_back(makeCreatureAbility(StackFeature::DOUBLE_WIDE, 0));//boar should be treated as double-wide creatures[142].abilities.push_back(makeCreatureAbility(StackFeature::DOUBLE_WIDE, 0));//nomads should be treated as double-wide creatures[46].abilities -= StackFeature::FLYING; //hell hound creatures[47].abilities -= StackFeature::FLYING; //cerberus */ creatures[52].abilities += makeCreatureAbility(StackFeature::FLYING, 0); //Efreeti creatures[53].abilities += makeCreatureAbility(StackFeature::FLYING, 0); //Efreet Sultan creatures[47].abilities += makeCreatureAbility(StackFeature::THREE_HEADED_ATTACK, 0); //cerberus creatures[87].abilities += makeCreatureAbility(StackFeature::ADDITIONAL_ATTACK, 1); //wolf raider creatures[147].abilities += makeCreatureAbility(StackFeature::NOT_ACTIVE, 0); //First Aid Tent //TODO: remove when support is added creatures[148].abilities += makeCreatureAbility(StackFeature::NOT_ACTIVE, 0); //Ammo Cart creatures[120].abilities -= StackFeature::DOUBLE_WIDE; //psychic elemental creatures[121].abilities -= StackFeature::DOUBLE_WIDE; //magic elemental creatures[0].abilities += makeCreatureAbility(StackFeature::CHARGE_IMMUNITY, 0); //pikeman immunity to Champion charge bonus creatures[1].abilities += makeCreatureAbility(StackFeature::CHARGE_IMMUNITY, 0); //halberdier immunity to Champion charge bonus creatures[4].abilities += makeCreatureAbility(StackFeature::ADDITIONAL_RETAILATION, 1); //griffins retailate twice creatures[5].abilities += makeCreatureAbility(StackFeature::UNLIMITED_RETAILATIONS, 0); //royal griffins retailate always creatures[12].abilities += makeCreatureAbility(StackFeature::HATE, 0, 54); //angels hate devils creatures[12].abilities += makeCreatureAbility(StackFeature::HATE, 0, 55); //angels hate archdevils creatures[13].abilities += makeCreatureAbility(StackFeature::HATE, 0, 54); //archangels hate devils creatures[13].abilities += makeCreatureAbility(StackFeature::HATE, 0, 55); //archangels hate arch creatures[13].abilities += makeCreatureAbility(StackFeature::SPELLCASTER, 0, 38); //archangels cast resurrection creatures[16].abilities += makeCreatureAbility(StackFeature::MAGIC_RESISTANCE, 20); //dwarf's magic resistance 20% creatures[17].abilities += makeCreatureAbility(StackFeature::MAGIC_RESISTANCE, 40); //battle dwarf's magic resistance 40% creatures[20].abilities += makeCreatureAbility(StackFeature::CHANGES_SPELL_COST_FOR_ENEMY, 2); //pegasus makes spell cost higher for enemy mage creatures[21].abilities += makeCreatureAbility(StackFeature::CHANGES_SPELL_COST_FOR_ENEMY, 2); //silver pegasus makes spell cost higher for enemy mage creatures[22].abilities += makeCreatureAbility(StackFeature::SPELL_AFTER_ATTACK, 0, 72, 100); //dendroids cast bind creatures[23].abilities += makeCreatureAbility(StackFeature::SPELL_AFTER_ATTACK, 0, 72, 100); //dendroid guards cast bind creatures[24].abilities += makeCreatureAbility(StackFeature::SPELL_RESISTANCE_AURA, 0, 55); //unicorn creatures[25].abilities += makeCreatureAbility(StackFeature::SPELL_RESISTANCE_AURA, 0, 55); //war unicorn creatures[24].abilities += makeCreatureAbility(StackFeature::SPELL_AFTER_ATTACK, 0, 62, 100); //unicorns cast blind with 20% probability creatures[25].abilities += makeCreatureAbility(StackFeature::SPELL_AFTER_ATTACK, 0, 62, 100); //war unicorns cast blind with 20% probability creatures[26].abilities += makeCreatureAbility(StackFeature::LEVEL_SPELL_IMMUNITY, 3); //green dragon's spell immunity creatures[27].abilities += makeCreatureAbility(StackFeature::LEVEL_SPELL_IMMUNITY, 4); //gold dragon's spell immunity creatures[26].abilities += makeCreatureAbility(StackFeature::TWO_HEX_ATTACK_BREATH, 0); //green dragon's breath creatures[27].abilities += makeCreatureAbility(StackFeature::TWO_HEX_ATTACK_BREATH, 0); //gold dragon's breath creatures[30].abilities += makeCreatureAbility(StackFeature::NON_LIVING, 0); //stone gargoyles are non-living creatures[31].abilities += makeCreatureAbility(StackFeature::NON_LIVING, 0); //obsidian gargoyles are non-living creatures[32].abilities += makeCreatureAbility(StackFeature::NON_LIVING, 0); //stone golems are non-living creatures[33].abilities += makeCreatureAbility(StackFeature::NON_LIVING, 0); //iron golems are non-living creatures[32].abilities += makeCreatureAbility(StackFeature::SPELL_DAMAGE_REDUCTION, 50, -1); //stone golems reduce dmg from spells creatures[33].abilities += makeCreatureAbility(StackFeature::SPELL_DAMAGE_REDUCTION, 75, -1); //iron golems reduce dmg from spells creatures[34].abilities += makeCreatureAbility(StackFeature::CHANGES_SPELL_COST_FOR_ALLY, -2); //mages reduce spell cost creatures[35].abilities += makeCreatureAbility(StackFeature::CHANGES_SPELL_COST_FOR_ALLY, -2); //archmages reduce spell cost creatures[36].abilities += makeCreatureAbility(StackFeature::HATE, 0, 52); //genies hate efreets creatures[36].abilities += makeCreatureAbility(StackFeature::HATE, 0, 53); //genies hate efreet sultans creatures[37].abilities += makeCreatureAbility(StackFeature::HATE, 0, 52); //master genies hate efreets creatures[37].abilities += makeCreatureAbility(StackFeature::HATE, 0, 53); //master genies hate efreet sultans creatures[37].abilities += makeCreatureAbility(StackFeature::RANDOM_GENIE_SPELLCASTER, 0); //master genies cast spells creatures[38].abilities += makeCreatureAbility(StackFeature::BLOCKS_RETAILATION, 0); //nagas block retailation creatures[39].abilities += makeCreatureAbility(StackFeature::BLOCKS_RETAILATION, 0); //naga queens block retailation std::vector mindSpells = getMindSpells(); for(int g=0; ggetTextFile("CRANIM.TXT"); int andame = buf.size(); int i=0; //buf iterator int hmcr=0; for(i; i