1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-28 08:48:48 +02:00

Refactoring

This commit is contained in:
AlexVinS 2015-02-06 15:41:26 +03:00
parent 666d7a4f45
commit 36cdb2968b
8 changed files with 111 additions and 81 deletions

View File

@ -439,11 +439,15 @@ CInfoBoxPopup::CInfoBoxPopup(Point position, const CGGarrison * garr):
CIntObject * CRClickPopup::createInfoWin(Point position, const CGObjectInstance * specific) //specific=0 => draws info about selected town/hero CIntObject * CRClickPopup::createInfoWin(Point position, const CGObjectInstance * specific) //specific=0 => draws info about selected town/hero
{ {
if(!specific) if(nullptr == specific)
specific = adventureInt->selection; specific = adventureInt->selection;
assert(specific); if(nullptr == specific)
{
logGlobal->error("createInfoWin: no object to describe");
return nullptr;
}
switch(specific->ID) switch(specific->ID)
{ {
case Obj::HERO: case Obj::HERO:

View File

@ -525,6 +525,11 @@
"icon": "zvs/Lib1.res/E_RETAIL1" "icon": "zvs/Lib1.res/E_RETAIL1"
} }
}, },
"VISIONS":
{
"hidden": true
},
"WATER_IMMUNITY": "WATER_IMMUNITY":
{ {
"graphics": "graphics":

View File

@ -17,7 +17,7 @@
}, },
"scuttleBoat" : { "scuttleBoat" : {
"index" : 1, "index" : 1,
"targetType": "LOCATION", "targetType": "NO_TARGET",
"sounds": { "sounds": {
"cast": "SCUTBOAT" "cast": "SCUTBOAT"
@ -40,7 +40,30 @@
}, },
"levels" : { "levels" : {
"base":{ "base":{
"range" : "X" "range" : "0",
"effects" : {
"visionsMonsters" : {
"type" : "VISIONS",
"subtype" : 0,
"duration" : "ONE_DAY",
"val" : 1,
"valueType" : "INDEPENDENT_MAX"
}
}
},
"advanced":{
"effects" : {
"visionsMonsters" : {
"val" : 2
}
}
},
"expert":{
"effects" : {
"visionsMonsters" : {
"val" : 3
}
}
} }
}, },
"flags" : { "flags" : {
@ -104,7 +127,29 @@
}, },
"levels" : { "levels" : {
"base":{ "base":{
"range" : "X" "range" : "0",
"effects" : {
"fly" : {
"type" : "FLYING_MOVEMENT",
"subtype" : 2,
"duration" : "ONE_DAY",
"val" : 0 //in fact unused
}
}
},
"advanced":{
"effects" : {
"fly" : {
"subtype" : 1
}
}
},
"expert":{
"effects" : {
"fly" : {
"subtype" : 1
}
}
} }
}, },
"flags" : { "flags" : {
@ -120,7 +165,29 @@
}, },
"levels" : { "levels" : {
"base":{ "base":{
"range" : "X" "range" : "0",
"effects" : {
"waterWalk" : {
"type" : "WATER_WALKING",
"subtype" : 2,
"duration" : "ONE_DAY",
"val" : 0 //in fact unused
}
}
},
"advanced":{
"effects" : {
"waterWalk" : {
"subtype" : 1
}
}
},
"expert":{
"effects" : {
"waterWalk" : {
"subtype" : 1
}
}
} }
}, },
"flags" : { "flags" : {

View File

@ -19,37 +19,6 @@
#include "../CGameState.h" #include "../CGameState.h"
#include "../CGameInfoCallback.h" #include "../CGameInfoCallback.h"
///AdventureBonusingMechanics
bool AdventureBonusingMechanics::applyAdventureEffects(const SpellCastEnvironment * env, AdventureSpellCastParameters & parameters) const
{
const int schoolLevel = parameters.caster->getSpellSchoolLevel(owner);
const int subtype = spellLevelToSubtype(schoolLevel);
GiveBonus gb;
gb.id = parameters.caster->id.getNum();
gb.bonus = Bonus(Bonus::ONE_DAY, bonusTypeID, Bonus::SPELL_EFFECT, 0, owner->id, subtype);
env->sendAndApply(&gb);
return true;
}
int FlyMechanics::spellLevelToSubtype(const int schoolLevel) const
{
return schoolLevel >= 2 ? 1 : 2; //adv or expert
}
int VisionsMechanics::spellLevelToSubtype(const int schoolLevel) const
{
//0,1 schoolLevel => 0 subtype
//2 schoolLevel => 1 subtype
//3 schoolLevel => 2 subtype
int result = schoolLevel - 1;
vstd::amin(result, 0);
vstd::amax(result, 2);
return result; //adv or expert
}
///SummonBoatMechanics ///SummonBoatMechanics
bool SummonBoatMechanics::applyAdventureEffects(const SpellCastEnvironment * env, AdventureSpellCastParameters & parameters) const bool SummonBoatMechanics::applyAdventureEffects(const SpellCastEnvironment * env, AdventureSpellCastParameters & parameters) const
{ {

View File

@ -13,37 +13,6 @@
#include "CDefaultSpellMechanics.h" #include "CDefaultSpellMechanics.h"
//todo: make configurable
class AdventureBonusingMechanics: public DefaultSpellMechanics
{
public:
AdventureBonusingMechanics(CSpell * s, Bonus::BonusType _bonusTypeID): DefaultSpellMechanics(s), bonusTypeID(_bonusTypeID){};
protected:
bool applyAdventureEffects(const SpellCastEnvironment * env, AdventureSpellCastParameters & parameters) const override;
virtual int spellLevelToSubtype(const int schoolLevel) const = 0;
private:
Bonus::BonusType bonusTypeID;
};
//FLY & WATER_WALK
class FlyMechanics: public AdventureBonusingMechanics
{
public:
FlyMechanics(CSpell * s, Bonus::BonusType _bonusTypeID): AdventureBonusingMechanics(s, _bonusTypeID){};
protected:
int spellLevelToSubtype(const int schoolLevel) const override;
};
//VISIONS & DISGUISE
class VisionsMechanics: public AdventureBonusingMechanics
{
public:
VisionsMechanics(CSpell * s, Bonus::BonusType _bonusTypeID): AdventureBonusingMechanics(s, _bonusTypeID){};
protected:
int spellLevelToSubtype(const int schoolLevel) const override;
};
class SummonBoatMechanics: public DefaultSpellMechanics class SummonBoatMechanics: public DefaultSpellMechanics
{ {
public: public:

View File

@ -191,9 +191,30 @@ bool DefaultSpellMechanics::adventureCast(const SpellCastEnvironment * env, Adve
bool DefaultSpellMechanics::applyAdventureEffects(const SpellCastEnvironment * env, AdventureSpellCastParameters & parameters) const bool DefaultSpellMechanics::applyAdventureEffects(const SpellCastEnvironment * env, AdventureSpellCastParameters & parameters) const
{ {
//There is no generic algorithm of adventure cast if(owner->hasEffects())
env->complain("Unimplemented adventure spell"); {
return false; const int schoolLevel = parameters.caster->getSpellSchoolLevel(owner);
std::vector<Bonus> bonuses;
owner->getEffects(bonuses, schoolLevel);
for(Bonus b : bonuses)
{
GiveBonus gb;
gb.id = parameters.caster->id.getNum();
gb.bonus = b;
env->sendAndApply(&gb);
}
return true;
}
else
{
//There is no generic algorithm of adventure cast
env->complain("Unimplemented adventure spell");
return false;
}
} }

View File

@ -358,8 +358,6 @@ const std::string& CSpell::getCastSound() const
return castSound; return castSound;
} }
si32 CSpell::getCost(const int skillLevel) const si32 CSpell::getCost(const int skillLevel) const
{ {
return getLevelInfo(skillLevel).cost; return getLevelInfo(skillLevel).cost;

View File

@ -69,19 +69,16 @@ ISpellMechanics * ISpellMechanics::createMechanics(CSpell * s)
case SpellID::DIMENSION_DOOR: case SpellID::DIMENSION_DOOR:
return new DimensionDoorMechanics(s); return new DimensionDoorMechanics(s);
case SpellID::FLY: case SpellID::FLY:
return new FlyMechanics(s, Bonus::FLYING_MOVEMENT); //temporary
case SpellID::WATER_WALK: case SpellID::WATER_WALK:
return new FlyMechanics(s, Bonus::WATER_WALKING); //temporary case SpellID::VISIONS:
case SpellID::DISGUISE:
return new DefaultSpellMechanics(s); //implemented using bonus system
case SpellID::TOWN_PORTAL: case SpellID::TOWN_PORTAL:
return new TownPortalMechanics(s); return new TownPortalMechanics(s);
case SpellID::VIEW_EARTH: case SpellID::VIEW_EARTH:
return new ViewEarthMechanics(s); return new ViewEarthMechanics(s);
case SpellID::VIEW_AIR: case SpellID::VIEW_AIR:
return new ViewAirMechanics(s); return new ViewAirMechanics(s);
case SpellID::VISIONS:
return new VisionsMechanics(s, Bonus::VISIONS); //temporary
case SpellID::DISGUISE:
return new VisionsMechanics(s, Bonus::DISGUISED); //temporary
default: default:
if(s->isRisingSpell()) if(s->isRisingSpell())
return new SpecialRisingSpellMechanics(s); return new SpecialRisingSpellMechanics(s);