1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

* refactoring

This commit is contained in:
mateuszb 2013-02-08 22:42:46 +00:00
parent 9dd60b6dbe
commit 0003d30991
7 changed files with 68 additions and 72 deletions

View File

@ -166,9 +166,9 @@ public:
bool removeObject(const CGObjectInstance * obj) OVERRIDE {return false;};
void setBlockVis(int objid, bool bv) OVERRIDE {};
void setOwner(const CGObjectInstance * obj, TPlayerColor owner) OVERRIDE {};
void setHoverName(int objid, MetaString * name) OVERRIDE {};
void setHoverName(const CGObjectInstance * obj, MetaString * name) OVERRIDE {};
void changePrimSkill(const CGHeroInstance * hero, PrimarySkill::PrimarySkill which, si64 val, bool abs=false) OVERRIDE {};
void changeSecSkill(int ID, SecondarySkill::SecondarySkill which, int val, bool abs=false) OVERRIDE {};
void changeSecSkill(const CGHeroInstance * hero, SecondarySkill::SecondarySkill which, int val, bool abs=false) OVERRIDE {};
void showBlockingDialog(BlockingDialog *iw, const CFunctionList<void(ui32)> &callback) OVERRIDE {};
ui32 showBlockingDialog(BlockingDialog *iw) OVERRIDE {return 0;}; //synchronous version of above
void showGarrisonDialog(int upobj, int hid, bool removableUnits, const boost::function<void()> &cb) OVERRIDE {};

View File

@ -1093,7 +1093,7 @@ void CGHeroInstance::initObj() //TODO: use bonus system
hs->addNewBonus(bonus);
break;
case 11://starting skill with mastery (Adrienne)
cb->changeSecSkill(id, static_cast<SecondarySkill::SecondarySkill>(spec.val), spec.additionalinfo); //simply give it and forget
cb->changeSecSkill(this, static_cast<SecondarySkill::SecondarySkill>(spec.val), spec.additionalinfo); //simply give it and forget
break;
case 12://army speed
bonus->type = Bonus::STACKS_SPEED;
@ -3459,7 +3459,7 @@ void CGMine::flagMine(TPlayerColor player) const
ms << "(%s)";
ms.addReplacement(MetaString::RES_NAMES, producedResource);
}
cb->setHoverName(id,&ms);
cb->setHoverName(this,&ms);
InfoWindow iw;
iw.soundID = soundBase::FLAGMINE;
@ -3565,7 +3565,7 @@ void CGVisitableOPW::newTurn() const
cb->setObjProperty(id, ObjProperty::VISITED, false);
MetaString ms; //set text to "not visited"
ms << std::pair<ui8,ui32>(3,ID) << " " << std::pair<ui8,ui32>(1,353);
cb->setHoverName(id,&ms);
cb->setHoverName(this,&ms);
}
}
bool CGVisitableOPW::wasVisited(TPlayerColor player) const
@ -3644,7 +3644,7 @@ void CGVisitableOPW::onHeroVisit( const CGHeroInstance * h ) const
cb->setObjProperty(id, ObjProperty::VISITED, true);
MetaString ms; //set text to "visited"
ms.addTxt(MetaString::OBJ_NAMES,ID); ms << " "; ms.addTxt(MetaString::GENERAL_TXT,352);
cb->setHoverName(id,&ms);
cb->setHoverName(this,&ms);
}
}
@ -4729,7 +4729,7 @@ void CGSeerHut::completeQuest (const CGHeroInstance * h) const //reward
cb->changePrimSkill(h, static_cast<PrimarySkill::PrimarySkill>(rID), rVal, false);
break;
case SECONDARY_SKILL:
cb->changeSecSkill(h->id, static_cast<SecondarySkill::SecondarySkill>(rID), rVal, false);
cb->changeSecSkill(h, static_cast<SecondarySkill::SecondarySkill>(rID), rVal, false);
break;
case ARTIFACT:
cb->giveHeroNewArtifact(h, VLC->arth->artifacts[rID],ArtifactPosition::FIRST_AVAILABLE);
@ -4817,7 +4817,7 @@ void CGWitchHut::onHeroVisit( const CGHeroInstance * h ) const
{
iw.components.push_back(Component(Component::SEC_SKILL, ability, 1, 0));
txt_id = 171;
cb->changeSecSkill(h->id, static_cast<SecondarySkill::SecondarySkill>(ability), 1, true);
cb->changeSecSkill(h, static_cast<SecondarySkill::SecondarySkill>(ability), 1, true);
}
iw.text.addTxt(MetaString::ADVOB_TXT,txt_id);
@ -5201,7 +5201,7 @@ void CGPandoraBox::giveContents( const CGHeroInstance *h, bool afterBattle ) con
if( (curLev && curLev < abilityLevels[i]) || (h->canLearnSkill() ))
{
cb->changeSecSkill(h->id,abilities[i],abilityLevels[i],true);
cb->changeSecSkill(h,abilities[i],abilityLevels[i],true);
}
}
@ -5577,7 +5577,7 @@ void CGScholar::onHeroVisit( const CGHeroInstance * h ) const
iw.components.push_back(Component(Component::PRIM_SKILL,bid,+1,0));
break;
case SECONDARY_SKILL:
cb->changeSecSkill(h->id,static_cast<SecondarySkill::SecondarySkill>(bid),+1);
cb->changeSecSkill(h,static_cast<SecondarySkill::SecondarySkill>(bid),+1);
iw.components.push_back(Component(Component::SEC_SKILL,bid,ssl+1,0));
break;
case SPELL:

View File

@ -142,34 +142,6 @@ bool CSpell::hasEffects() const
return !effects[0].empty();
}
namespace Spells
{
enum
{
SUMMON_BOAT=0, SCUTTLE_BOAT=1, VISIONS=2, VIEW_EARTH=3, DISGUISE=4, VIEW_AIR=5,
FLY=6, WATER_WALK=7, DIMENSION_DOOR=8, TOWN_PORTAL=9,
QUICKSAND=10, LAND_MINE=11, FORCE_FIELD=12, FIRE_WALL=13, EARTHQUAKE=14,
MAGIC_ARROW=15, ICE_BOLT=16, LIGHTNING_BOLT=17, IMPLOSION=18,
CHAIN_LIGHTNING=19, FROST_RING=20, FIREBALL=21, INFERNO=22,
METEOR_SHOWER=23, DEATH_RIPPLE=24, DESTROY_UNDEAD=25, ARMAGEDDON=26,
SHIELD=27, AIR_SHIELD=28, FIRE_SHIELD=29, PROTECTION_FROM_AIR=30,
PROTECTION_FROM_FIRE=31, PROTECTION_FROM_WATER=32,
PROTECTION_FROM_EARTH=33, ANTI_MAGIC=34, DISPEL=35, MAGIC_MIRROR=36,
CURE=37, RESURRECTION=38, ANIMATE_DEAD=39, SACRIFICE=40, BLESS=41,
CURSE=42, BLOODLUST=43, PRECISION=44, WEAKNESS=45, STONE_SKIN=46,
DISRUPTING_RAY=47, PRAYER=48, MIRTH=49, SORROW=50, FORTUNE=51,
MISFORTUNE=52, HASTE=53, SLOW=54, SLAYER=55, FRENZY=56,
TITANS_LIGHTNING_BOLT=57, COUNTERSTRIKE=58, BERSERK=59, HYPNOTIZE=60,
FORGETFULNESS=61, BLIND=62, TELEPORT=63, REMOVE_OBSTACLE=64, CLONE=65,
SUMMON_FIRE_ELEMENTAL=66, SUMMON_EARTH_ELEMENTAL=67, SUMMON_WATER_ELEMENTAL=68, SUMMON_AIR_ELEMENTAL=69,
STONE_GAZE=70, POISON=71, BIND=72, DISEASE=73, PARALYZE=74, AGE=75, DEATH_CLOUD=76, THUNDERBOLT=77,
DISPEL_HELPFUL_SPELLS=78, DEATH_STARE=79, ACID_BREATH_DEFENSE=80, ACID_BREATH_DAMAGE=81
};
}
bool DLL_LINKAGE isInScreenRange(const int3 &center, const int3 &pos); //for spells like Dimension Door
class DLL_LINKAGE CSpellHandler

View File

@ -553,6 +553,33 @@ namespace CreatureID
};
}
namespace Spells
{
enum Spells
{
SUMMON_BOAT=0, SCUTTLE_BOAT=1, VISIONS=2, VIEW_EARTH=3, DISGUISE=4, VIEW_AIR=5,
FLY=6, WATER_WALK=7, DIMENSION_DOOR=8, TOWN_PORTAL=9,
QUICKSAND=10, LAND_MINE=11, FORCE_FIELD=12, FIRE_WALL=13, EARTHQUAKE=14,
MAGIC_ARROW=15, ICE_BOLT=16, LIGHTNING_BOLT=17, IMPLOSION=18,
CHAIN_LIGHTNING=19, FROST_RING=20, FIREBALL=21, INFERNO=22,
METEOR_SHOWER=23, DEATH_RIPPLE=24, DESTROY_UNDEAD=25, ARMAGEDDON=26,
SHIELD=27, AIR_SHIELD=28, FIRE_SHIELD=29, PROTECTION_FROM_AIR=30,
PROTECTION_FROM_FIRE=31, PROTECTION_FROM_WATER=32,
PROTECTION_FROM_EARTH=33, ANTI_MAGIC=34, DISPEL=35, MAGIC_MIRROR=36,
CURE=37, RESURRECTION=38, ANIMATE_DEAD=39, SACRIFICE=40, BLESS=41,
CURSE=42, BLOODLUST=43, PRECISION=44, WEAKNESS=45, STONE_SKIN=46,
DISRUPTING_RAY=47, PRAYER=48, MIRTH=49, SORROW=50, FORTUNE=51,
MISFORTUNE=52, HASTE=53, SLOW=54, SLAYER=55, FRENZY=56,
TITANS_LIGHTNING_BOLT=57, COUNTERSTRIKE=58, BERSERK=59, HYPNOTIZE=60,
FORGETFULNESS=61, BLIND=62, TELEPORT=63, REMOVE_OBSTACLE=64, CLONE=65,
SUMMON_FIRE_ELEMENTAL=66, SUMMON_EARTH_ELEMENTAL=67, SUMMON_WATER_ELEMENTAL=68, SUMMON_AIR_ELEMENTAL=69,
STONE_GAZE=70, POISON=71, BIND=72, DISEASE=73, PARALYZE=74, AGE=75, DEATH_CLOUD=76, THUNDERBOLT=77,
DISPEL_HELPFUL_SPELLS=78, DEATH_STARE=79, ACID_BREATH_DEFENSE=80, ACID_BREATH_DAMAGE=81
};
}
// Typedef declarations
typedef si8 TFaction;
typedef si64 TExpType;

View File

@ -207,9 +207,9 @@ public:
virtual bool removeObject(const CGObjectInstance * obj)=0;
virtual void setBlockVis(int objid, bool bv)=0;
virtual void setOwner(const CGObjectInstance * objid, TPlayerColor owner)=0;
virtual void setHoverName(int objid, MetaString * name)=0;
virtual void setHoverName(const CGObjectInstance * obj, MetaString * name)=0;
virtual void changePrimSkill(const CGHeroInstance * hero, PrimarySkill::PrimarySkill which, si64 val, bool abs=false)=0;
virtual void changeSecSkill(int ID, SecondarySkill::SecondarySkill which, int val, bool abs=false)=0;
virtual void changeSecSkill(const CGHeroInstance * hero, SecondarySkill::SecondarySkill which, int val, bool abs=false)=0;
virtual void showBlockingDialog(BlockingDialog *iw, const CFunctionList<void(ui32)> &callback)=0;
virtual ui32 showBlockingDialog(BlockingDialog *iw) =0; //synchronous version of above //TODO:
virtual void showGarrisonDialog(int upobj, int hid, bool removableUnits, const boost::function<void()> &cb) =0; //cb will be called when player closes garrison window

View File

@ -195,16 +195,14 @@ void callWith(std::vector<T> args, boost::function<void(T)> fun, ui32 which)
fun(args[which]);
}
void CGameHandler::levelUpHero(int ID, SecondarySkill::SecondarySkill skill)
void CGameHandler::levelUpHero(const CGHeroInstance * hero, SecondarySkill::SecondarySkill skill)
{
changeSecSkill(ID, skill, 1, 0);
levelUpHero(ID);
changeSecSkill(hero, skill, 1, 0);
levelUpHero(hero);
}
void CGameHandler::levelUpHero(int ID)
void CGameHandler::levelUpHero(const CGHeroInstance * hero)
{
CGHeroInstance *hero = static_cast<CGHeroInstance *>(gs->map->objects[ID].get());
// required exp for at least 1 lvl-up hasn't been reached
if (hero->exp < VLC->heroh->reqExp(hero->level+1))
{
@ -226,14 +224,14 @@ void CGameHandler::levelUpHero(int ID)
}
tlog5 << "The hero gets the primary skill with the no. " << x << " with a probability of " << r << "%." << std::endl;
SetPrimSkill sps;
sps.id = ID;
sps.id = hero->id;
sps.which = static_cast<PrimarySkill::PrimarySkill>(x);
sps.abs = false;
sps.val = 1;
sendAndApply(&sps);
HeroLevelUp hlu;
hlu.heroid = ID;
hlu.heroid = hero->id;
hlu.primskill = static_cast<PrimarySkill::PrimarySkill>(x);
hlu.level = hero->level+1;
@ -280,11 +278,11 @@ void CGameHandler::levelUpHero(int ID)
sendAndApply (&hlu);
if (hlu.skills.size())
{
levelUpHero (ID, vstd::pickRandomElementOf (hlu.skills, rand));
levelUpHero (hero, vstd::pickRandomElementOf (hlu.skills, rand));
}
else //apply and send info
{
levelUpHero(ID);
levelUpHero(hero);
}
}
else
@ -294,18 +292,18 @@ void CGameHandler::levelUpHero(int ID)
boost::function<void(ui32)> callback = boost::function<void(ui32)>(boost::bind
(callWith<SecondarySkill::SecondarySkill>, hlu.skills,
boost::function<void(SecondarySkill::SecondarySkill)>(boost::bind
(&CGameHandler::levelUpHero, this, ID,_1) ), _1));
(&CGameHandler::levelUpHero, this, hero, _1) ), _1));
applyAndAsk(&hlu,hero->tempOwner,callback); //call levelUpHero when client responds
}
else if(hlu.skills.size() == 1) //apply, give only possible skill and send info
{
sendAndApply(&hlu);
levelUpHero(ID, hlu.skills.back());
levelUpHero(hero, hlu.skills.back());
}
else //apply and send info
{
sendAndApply(&hlu);
levelUpHero(ID);
levelUpHero(hero);
}
}
}
@ -472,7 +470,7 @@ void CGameHandler::changePrimSkill(const CGHeroInstance * hero, PrimarySkill::Pr
//only for exp - hero may level up
if (which == PrimarySkill::EXPERIENCE)
{
levelUpHero(hero->id);
levelUpHero(hero);
if (hero->commander && hero->commander->alive)
{
SetCommanderProperty scp;
@ -486,10 +484,10 @@ void CGameHandler::changePrimSkill(const CGHeroInstance * hero, PrimarySkill::Pr
}
}
void CGameHandler::changeSecSkill( int ID, SecondarySkill::SecondarySkill which, int val, bool abs/*=false*/ )
void CGameHandler::changeSecSkill( const CGHeroInstance * hero, SecondarySkill::SecondarySkill which, int val, bool abs/*=false*/ )
{
SetSecSkill sss;
sss.id = ID;
sss.id = hero->id;
sss.which = which;
sss.val = val;
sss.abs = abs;
@ -497,9 +495,8 @@ void CGameHandler::changeSecSkill( int ID, SecondarySkill::SecondarySkill which,
if(which == SecondarySkill::WISDOM)
{
const CGHeroInstance *h = getHero(ID);
if(h && h->visitedTown)
giveSpells(h->visitedTown, h);
if(hero && hero->visitedTown)
giveSpells(hero->visitedTown, hero);
}
}
@ -1894,9 +1891,9 @@ void CGameHandler::setOwner(const CGObjectInstance * obj, TPlayerColor owner)
}
}
void CGameHandler::setHoverName(int objid, MetaString* name)
void CGameHandler::setHoverName(const CGObjectInstance * obj, MetaString* name)
{
SetHoverName shn(objid, *name);
SetHoverName shn(obj->id, *name);
sendAndApply(&shn);
}
@ -3068,7 +3065,7 @@ bool CGameHandler::buySecSkill( const IMarket *m, const CGHeroInstance *h, Secon
sr.val = getResource(h->tempOwner, Res::GOLD) - 2000;
sendAndApply(&sr);
changeSecSkill(h->id, skill, 1, true);
changeSecSkill(h, skill, 1, true);
return true;
}
@ -5345,7 +5342,7 @@ void CGameHandler::handleAfterAttackCasting( const BattleAttack & bat )
if (staredCreatures)
{
if (bat.bsa.size() && bat.bsa[0].newAmount > 0) //TODO: death stare was not originally available for multiple-hex attacks, but...
handleSpellCasting(79, 0, gs->curB->battleGetStackByID(bat.bsa[0].stackAttacked)->position,
handleSpellCasting(Spells::DEATH_STARE, 0, gs->curB->battleGetStackByID(bat.bsa[0].stackAttacked)->position,
!attacker->attackerOwned, attacker->owner, NULL, NULL, staredCreatures, ECastingMode::AFTER_ATTACK_CASTING, attacker);
}
}
@ -5359,7 +5356,7 @@ void CGameHandler::handleAfterAttackCasting( const BattleAttack & bat )
}
if (acidDamage)
{
handleSpellCasting(81, 0, gs->curB->battleGetStackByID(bat.bsa[0].stackAttacked)->position,
handleSpellCasting(Spells::ACID_BREATH_DAMAGE, 0, gs->curB->battleGetStackByID(bat.bsa[0].stackAttacked)->position,
!attacker->attackerOwned, attacker->owner, NULL, NULL,
acidDamage * attacker->count, ECastingMode::AFTER_ATTACK_CASTING, attacker);
}
@ -5482,7 +5479,7 @@ bool CGameHandler::castSpell(const CGHeroInstance *h, int spellID, const int3 &p
COMPLAIN_RET("Destination tile doesn't exist!");
if(!h->movement)
COMPLAIN_RET("Hero needs movement points to cast Dimension Door!");
if(h->getBonusesCount(Bonus::SPELL_EFFECT, Spells::DIMENSION_DOOR) >= s->powers[schoolLevel]) //limit casts per turn
if(h->getBonusesCount(Bonus::SPELL_EFFECT, DIMENSION_DOOR) >= s->powers[schoolLevel]) //limit casts per turn
{
InfoWindow iw;
iw.player = h->tempOwner;
@ -5494,7 +5491,7 @@ bool CGameHandler::castSpell(const CGHeroInstance *h, int spellID, const int3 &p
GiveBonus gb;
gb.id = h->id;
gb.bonus = Bonus(Bonus::ONE_DAY, Bonus::NONE, Bonus::SPELL_EFFECT, 0, Spells::DIMENSION_DOOR);
gb.bonus = Bonus(Bonus::ONE_DAY, Bonus::NONE, Bonus::SPELL_EFFECT, 0, DIMENSION_DOOR);
sendAndApply(&gb);
if(!dest->isClear(curr)) //wrong dest tile
@ -5521,7 +5518,7 @@ bool CGameHandler::castSpell(const CGHeroInstance *h, int spellID, const int3 &p
GiveBonus gb;
gb.id = h->id;
gb.bonus = Bonus(Bonus::ONE_DAY, Bonus::FLYING_MOVEMENT, Bonus::SPELL_EFFECT, 0, Spells::FLY, subtype);
gb.bonus = Bonus(Bonus::ONE_DAY, Bonus::FLYING_MOVEMENT, Bonus::SPELL_EFFECT, 0, FLY, subtype);
sendAndApply(&gb);
}
break;
@ -5531,7 +5528,7 @@ bool CGameHandler::castSpell(const CGHeroInstance *h, int spellID, const int3 &p
GiveBonus gb;
gb.id = h->id;
gb.bonus = Bonus(Bonus::ONE_DAY, Bonus::WATER_WALKING, Bonus::SPELL_EFFECT, 0, Spells::WATER_WALK, subtype);
gb.bonus = Bonus(Bonus::ONE_DAY, Bonus::WATER_WALKING, Bonus::SPELL_EFFECT, 0, WATER_WALK, subtype);
sendAndApply(&gb);
}
break;

View File

@ -133,9 +133,9 @@ public:
bool removeObject(const CGObjectInstance * obj) OVERRIDE;
void setBlockVis(int objid, bool bv) OVERRIDE;
void setOwner(const CGObjectInstance * obj, TPlayerColor owner) OVERRIDE;
void setHoverName(int objid, MetaString * name) OVERRIDE;
void setHoverName(const CGObjectInstance * objid, MetaString * name) OVERRIDE;
void changePrimSkill(const CGHeroInstance * hero, PrimarySkill::PrimarySkill which, si64 val, bool abs=false) OVERRIDE;
void changeSecSkill(int ID, SecondarySkill::SecondarySkill which, int val, bool abs=false) OVERRIDE;
void changeSecSkill(const CGHeroInstance * hero, SecondarySkill::SecondarySkill which, int val, bool abs=false) OVERRIDE;
//void showInfoDialog(InfoWindow *iw) OVERRIDE;
void showBlockingDialog(BlockingDialog *iw, const CFunctionList<void(ui32)> &callback) OVERRIDE;
ui32 showBlockingDialog(BlockingDialog *iw) OVERRIDE; //synchronous version of above
@ -182,8 +182,8 @@ public:
void visitObjectOnTile(const TerrainTile &t, const CGHeroInstance * h);
bool teleportHero(si32 hid, si32 dstid, ui8 source, TPlayerColor asker = GameConstants::NEUTRAL_PLAYER);
void vistiCastleObjects (const CGTownInstance *t, const CGHeroInstance *h);
void levelUpHero(int ID, SecondarySkill::SecondarySkill skill);//handle client respond and send one more request if needed
void levelUpHero(int ID);//initial call - check if hero have remaining levelups & handle them
void levelUpHero(const CGHeroInstance * hero, SecondarySkill::SecondarySkill skill);//handle client respond and send one more request if needed
void levelUpHero(const CGHeroInstance * hero);//initial call - check if hero have remaining levelups & handle them
void levelUpCommander (const CCommanderInstance * c, int skill); //secondary skill 1 to 6, special skill : skill - 100
void levelUpCommander (const CCommanderInstance * c);
void afterBattleCallback(); // called after level-ups are finished