1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-27 22:49:25 +02:00

* a bit more work on campaigns; hero crossover still buggy

This commit is contained in:
mateuszb
2013-02-06 10:16:44 +00:00
parent 1ef205e5f1
commit 3958364884
10 changed files with 100 additions and 32 deletions

View File

@@ -215,7 +215,7 @@ void CHeroWindow::update(const CGHeroInstance * hero, bool redrawNeeded /*= fals
//primary skills support //primary skills support
for(size_t g=0; g<primSkillAreas.size(); ++g) for(size_t g=0; g<primSkillAreas.size(); ++g)
{ {
primSkillAreas[g]->bonusValue = heroWArt.getPrimSkillLevel(g); primSkillAreas[g]->bonusValue = heroWArt.getPrimSkillLevel(static_cast<PrimarySkill::PrimarySkill>(g));
} }
//secondary skills support //secondary skills support

View File

@@ -316,7 +316,7 @@ si64 InfoBoxHeroData::getValue()
switch(type) switch(type)
{ {
case HERO_PRIMARY_SKILL: case HERO_PRIMARY_SKILL:
return hero->getPrimSkillLevel(index); return hero->getPrimSkillLevel(static_cast<PrimarySkill::PrimarySkill>(index));
case HERO_MANA: case HERO_MANA:
return hero->mana; return hero->mana;
case HERO_EXPERIENCE: case HERO_EXPERIENCE:

View File

@@ -5041,9 +5041,9 @@ void CExchangeWindow::prepareBackground()
{ {
CHeroWithMaybePickedArtifact heroWArt = CHeroWithMaybePickedArtifact(this, heroInst[b]); CHeroWithMaybePickedArtifact heroWArt = CHeroWithMaybePickedArtifact(this, heroInst[b]);
//printing primary skills' amounts //printing primary skills' amounts
for(int m=0; m<4; ++m) for(int m=0; m<GameConstants::PRIMARY_SKILLS; ++m)
new CLabel(352 + 93 * b, 35 + 36 * m, FONT_SMALL, CENTER, Colors::WHITE, new CLabel(352 + 93 * b, 35 + 36 * m, FONT_SMALL, CENTER, Colors::WHITE,
boost::lexical_cast<std::string>(heroWArt.getPrimSkillLevel(m))); boost::lexical_cast<std::string>(heroWArt.getPrimSkillLevel(static_cast<PrimarySkill::PrimarySkill>(m))));
//printing secondary skills //printing secondary skills
for(int m=0; m<heroInst[b]->secSkills.size(); ++m) for(int m=0; m<heroInst[b]->secSkills.size(); ++m)

View File

@@ -161,7 +161,7 @@ void MetaString::getLocalString(const std::pair<ui8,ui32> &txt, std::string &dst
else if(type == MINE_EVNTS) else if(type == MINE_EVNTS)
{ {
dst = VLC->generaltexth->mines[ser].second; dst = VLC->generaltexth->mines[ser].second;
} }
else if(type == SPELL_NAME) else if(type == SPELL_NAME)
{ {
dst = VLC->spellh->spells[ser]->name; dst = VLC->spellh->spells[ser]->name;
@@ -1092,14 +1092,16 @@ void CGameState::init(StartInfo * si)
/*************************replace hero placeholders*****************************/ /*************************replace hero placeholders*****************************/
tlog4 << "\tReplacing hero placeholders"; tlog4 << "\tReplacing hero placeholders";
std::vector<std::tuple<CGHeroInstance*, int> > campHeroReplacements; //instance, id in vector
if (scenarioOps->campState) if (scenarioOps->campState)
{ {
auto replaceHero = [&](int objId, CGHeroInstance * ghi) auto replaceHero = [&](int objId, CGHeroInstance * ghi)
{ {
ghi->tempOwner = getHumanPlayerInfo()[0]->color; campHeroReplacements.push_back(std::make_tuple(ghi, objId));
ghi->id = objId; // ghi->tempOwner = getHumanPlayerInfo()[0]->color;
gs->map->objects[objId] = ghi; // ghi->id = objId;
gs->map->heroes.push_back(ghi); // gs->map->objects[objId] = ghi;
// gs->map->heroes.push_back(ghi);
}; };
auto campaign = scenarioOps->campState; auto campaign = scenarioOps->campState;
@@ -1248,28 +1250,91 @@ void CGameState::init(StartInfo * si)
continue; continue;
} }
CGHeroInstance * vhi = map->heroes[i]; CGHeroInstance * vhi = map->heroes[i];
if(vhi->sex == 0xff) //campaign heroes already come initialized -- I hope this will skip them vhi->initHero();
players.find(vhi->getOwner())->second.heroes.push_back(vhi);
hids.erase(vhi->subID);
}
BOOST_FOREACH(auto obj, campHeroReplacements)
{
CGHeroInstance * hero = new CGHeroInstance(),
* oldHero = std::get<0>(obj);
hero->initHero(oldHero->subID);
hero->id = std::get<1>(obj);
map->objects[hero->id] = hero;
map->heroes.push_back(hero);
const auto & travelOptions = scenarioOps->campState->getCurrentScenario().travelOptions;
if (travelOptions.whatHeroKeeps & 1)
{ {
vhi->initHero(); //giving exp
players.find(vhi->getOwner())->second.heroes.push_back(vhi); hero->exp = oldHero->exp;
hids.erase(vhi->subID); }
if (travelOptions.whatHeroKeeps & 2)
{
//giving prim skills
for(int g=0; g<GameConstants::PRIMARY_SKILLS; ++g)
{
hero->getBonusLocalFirst(Selector::type(Bonus::PRIMARY_SKILL) &&
Selector::subtype(g) && Selector::sourceType(Bonus::HERO_BASE_SKILL) )->val
= oldHero->getBonusLocalFirst(Selector::type(Bonus::PRIMARY_SKILL) &&
Selector::subtype(g) && Selector::sourceType(Bonus::HERO_BASE_SKILL) )->val;
}
}
if (travelOptions.whatHeroKeeps & 4)
{
//giving sec skills
hero->secSkills = oldHero->secSkills;
}
if (travelOptions.whatHeroKeeps & 8)
{
//giving spells
hero->spells = oldHero->spells;
}
if (travelOptions.whatHeroKeeps & 16)
{
//giving artifacts
size_t totalArts = GameConstants::BACKPACK_START + oldHero->artifactsInBackpack.size();
for (size_t i=0; i<totalArts; i++ )
{
const ArtSlotInfo *info = oldHero->getSlot(i);
if (!info)
continue;
const CArtifactInstance *art = info->artifact;
if (!art)//FIXME: check spellbook and catapult behaviour
continue;
int id = art->artType->id;
assert( 8*18 > id );//number of arts that fits into h3m format
bool takeable = travelOptions.artifsKeptByHero[id / 8] & ( 1 << (id%8) );
if (takeable)
hero->setNewArtSlot(i, const_cast<CArtifactInstance*>(oldHero->getSlot(i)->artifact.get()), false);
}
}
//giving creatures
if(!oldHero->stacks.empty())
{
hero->stacks = oldHero->stacks;
} }
} }
for (ui32 i=0; i<map->objects.size();i++) //prisons BOOST_FOREACH(auto obj, map->objects) //prisons
{ {
if (map->objects[i] && map->objects[i]->ID == Obj::PRISON) if(obj && obj->ID == Obj::PRISON)
hids.erase(map->objects[i]->subID); hids.erase(obj->subID);
} }
for(ui32 i=0; i<map->predefinedHeroes.size(); i++) BOOST_FOREACH(auto ph, map->predefinedHeroes)
{ {
if(!vstd::contains(hids,map->predefinedHeroes[i]->subID)) if(!vstd::contains(hids, ph->subID))
continue; continue;
map->predefinedHeroes[i]->initHero(); ph->initHero();
hpool.heroesPool[map->predefinedHeroes[i]->subID] = map->predefinedHeroes[i]; hpool.heroesPool[ph->subID] = ph;
hpool.pavailable[map->predefinedHeroes[i]->subID] = 0xff; hpool.pavailable[ph->subID] = 0xff;
hids.erase(map->predefinedHeroes[i]->subID); hids.erase(ph->subID);
} }
BOOST_FOREACH(int hid, hids) //all not used allowed heroes go with default state into the pool BOOST_FOREACH(int hid, hids) //all not used allowed heroes go with default state into the pool
@@ -2796,7 +2861,7 @@ void InfoAboutHero::initFromHero(const CGHeroInstance *h, bool detailed)
for (int i = 0; i < GameConstants::PRIMARY_SKILLS ; i++) for (int i = 0; i < GameConstants::PRIMARY_SKILLS ; i++)
{ {
details->primskills[i] = h->getPrimSkillLevel(i); details->primskills[i] = h->getPrimSkillLevel(static_cast<PrimarySkill::PrimarySkill>(i));
} }
} }
} }

View File

@@ -1286,7 +1286,7 @@ void CGHeroInstance::setPropertyDer( ui8 what, ui32 val )
double CGHeroInstance::getHeroStrength() const double CGHeroInstance::getHeroStrength() const
{ {
return sqrt((1.0 + 0.05*getPrimSkillLevel(0)) * (1.0 + 0.05*getPrimSkillLevel(1))); return sqrt((1.0 + 0.05*getPrimSkillLevel(PrimarySkill::ATTACK)) * (1.0 + 0.05*getPrimSkillLevel(PrimarySkill::DEFENSE)));
} }
ui64 CGHeroInstance::getTotalStrength() const ui64 CGHeroInstance::getTotalStrength() const
@@ -4115,9 +4115,9 @@ bool CQuest::checkQuest (const CGHeroInstance * h) const
return true; return true;
return false; return false;
case MISSION_PRIMARY_STAT: case MISSION_PRIMARY_STAT:
for (int i = 0; i < 4; ++i) for (int i = 0; i < GameConstants::PRIMARY_SKILLS; ++i)
{ {
if (h->getPrimSkillLevel(i) < m2stats[i]) if (h->getPrimSkillLevel(static_cast<PrimarySkill::PrimarySkill>(i)) < m2stats[i])
return false; return false;
} }
return true; return true;

View File

@@ -466,7 +466,7 @@ si32 IBonusBearer::manaLimit() const
/ 10.0); / 10.0);
} }
int IBonusBearer::getPrimSkillLevel(int id) const int IBonusBearer::getPrimSkillLevel(PrimarySkill::PrimarySkill id) const
{ {
int ret = 0; int ret = 0;
if(id == PrimarySkill::ATTACK) if(id == PrimarySkill::ATTACK)

View File

@@ -541,7 +541,7 @@ public:
ui8 howManyEffectsSet(ui16 id) const; //returns amount of effects with given id set for this stack ui8 howManyEffectsSet(ui16 id) const; //returns amount of effects with given id set for this stack
si32 manaLimit() const; //maximum mana value for this hero (basically 10*knowledge) si32 manaLimit() const; //maximum mana value for this hero (basically 10*knowledge)
int getPrimSkillLevel(int id) const; //0-attack, 1-defence, 2-spell power, 3-knowledge int getPrimSkillLevel(PrimarySkill::PrimarySkill id) const;
const TBonusListPtr getSpellBonuses() const; const TBonusListPtr getSpellBonuses() const;
}; };

View File

@@ -330,14 +330,16 @@ int CGameInfoCallback::estimateSpellDamage(const CSpell * sp, const CGHeroInstan
if(!gs->curB) //no battle if(!gs->curB) //no battle
{ {
if (hero) //but we see hero's spellbook if (hero) //but we see hero's spellbook
return gs->curB->calculateSpellDmg(sp, hero, NULL, hero->getSpellSchoolLevel(sp), hero->getPrimSkillLevel(2)); return gs->curB->calculateSpellDmg(
sp, hero, NULL, hero->getSpellSchoolLevel(sp), hero->getPrimSkillLevel(PrimarySkill::SPELL_POWER));
else else
return 0; //mage guild return 0; //mage guild
} }
//gs->getHero(gs->currentPlayer) //gs->getHero(gs->currentPlayer)
//const CGHeroInstance * ourHero = gs->curB->heroes[0]->tempOwner == player ? gs->curB->heroes[0] : gs->curB->heroes[1]; //const CGHeroInstance * ourHero = gs->curB->heroes[0]->tempOwner == player ? gs->curB->heroes[0] : gs->curB->heroes[1];
const CGHeroInstance * ourHero = hero; const CGHeroInstance * ourHero = hero;
return gs->curB->calculateSpellDmg(sp, ourHero, NULL, ourHero->getSpellSchoolLevel(sp), ourHero->getPrimSkillLevel(2)); return gs->curB->calculateSpellDmg(
sp, ourHero, NULL, ourHero->getSpellSchoolLevel(sp), ourHero->getPrimSkillLevel(PrimarySkill::SPELL_POWER));
} }
void CGameInfoCallback::getThievesGuildInfo(SThievesGuildInfo & thi, const CGObjectInstance * obj) void CGameInfoCallback::getThievesGuildInfo(SThievesGuildInfo & thi, const CGObjectInstance * obj)

View File

@@ -381,7 +381,7 @@ void CCampaignScenario::prepareCrossoverHeroes( std::vector<CGHeroInstance *> he
assert( 8*18 > id );//number of arts that fits into h3m format assert( 8*18 > id );//number of arts that fits into h3m format
bool takeable = travelOptions.artifsKeptByHero[id / 8] & ( 1 << (id%8) ); bool takeable = travelOptions.artifsKeptByHero[id / 8] & ( 1 << (id%8) );
if (takeable) if (!takeable)
hero->eraseArtSlot(i); hero->eraseArtSlot(i);
} }
} }

View File

@@ -4455,7 +4455,8 @@ bool CGameHandler::makeCustomAction( BattleAction &ba )
StartAction start_action(ba); StartAction start_action(ba);
sendAndApply(&start_action); //start spell casting sendAndApply(&start_action); //start spell casting
handleSpellCasting (ba.additionalInfo, skill, ba.destinationTile, ba.side, h->tempOwner, h, secondHero, h->getPrimSkillLevel(2), handleSpellCasting (ba.additionalInfo, skill, ba.destinationTile, ba.side, h->tempOwner,
h, secondHero, h->getPrimSkillLevel(PrimarySkill::SPELL_POWER),
ECastingMode::HERO_CASTING, NULL, ba.selectedStack); ECastingMode::HERO_CASTING, NULL, ba.selectedStack);
sendAndApply(&end_action); sendAndApply(&end_action);