Browse Source

Style tweaks.

AlexVinS 9 years ago
parent
commit
cd5c0b3297

+ 2 - 2
lib/CGameState.cpp

@@ -1798,7 +1798,7 @@ void CGameState::initTowns()
 
 		for(ui32 z=0; z<vti->obligatorySpells.size();z++)
 		{
-			CSpell *s = vti->obligatorySpells[z].toSpell();
+			auto s = vti->obligatorySpells[z].toSpell();
 			vti->spells[s->level-1].push_back(s->id);
 			vti->possibleSpells -= s->id;
 		}
@@ -1826,7 +1826,7 @@ void CGameState::initTowns()
 			if(sel<0)
 				sel=0;
 
-			CSpell *s = vti->possibleSpells[sel].toSpell();
+			auto s = vti->possibleSpells[sel].toSpell();
 			vti->spells[s->level-1].push_back(s->id);
 			vti->possibleSpells -= s->id;
 		}

+ 1 - 1
lib/CTownHandler.cpp

@@ -605,7 +605,7 @@ void CTownHandler::loadTown(CTown &town, const JsonNode & source)
 
 		VLC->modh->identifiers.requestIdentifier(node.second.meta, "spell", node.first, [=, &town](si32 spellID)
 		{
-			SpellID(spellID).toSpell()->probabilities[town.faction->index] = chance;
+			VLC->spellh->objects.at(spellID)->probabilities[town.faction->index] = chance;
 		});
 	}
 

+ 5 - 5
lib/GameConstants.cpp

@@ -31,17 +31,17 @@ const PlayerColor PlayerColor::NEUTRAL = PlayerColor(255);
 const PlayerColor PlayerColor::PLAYER_LIMIT = PlayerColor(PLAYER_LIMIT_I);
 const TeamID TeamID::NO_TEAM = TeamID(255);
 
-CArtifact * ArtifactID::toArtifact() const
+const CArtifact * ArtifactID::toArtifact() const
 {
-	return VLC->arth->artifacts[*this];
+	return VLC->arth->artifacts.at(*this);
 }
 
-CCreature * CreatureID::toCreature() const
+const CCreature * CreatureID::toCreature() const
 {
-	return VLC->creh->creatures[*this];
+	return VLC->creh->creatures.at(*this);
 }
 
-CSpell * SpellID::toSpell() const
+const CSpell * SpellID::toSpell() const
 {
 	if(num < 0 || num >= VLC->spellh->objects.size())
 	{

+ 3 - 4
lib/GameConstants.h

@@ -961,7 +961,7 @@ public:
 	ArtifactID(EArtifactID _num = NONE) : num(_num)
 	{}
 
-	DLL_LINKAGE CArtifact * toArtifact() const;
+	DLL_LINKAGE const CArtifact * toArtifact() const;
 
 	ID_LIKE_CLASS_COMMON(ArtifactID, EArtifactID)
 
@@ -1006,7 +1006,7 @@ public:
 	CreatureID(ECreatureID _num = NONE) : num(_num)
 	{}
 
-	DLL_LINKAGE CCreature * toCreature() const;
+	DLL_LINKAGE const CCreature * toCreature() const;
 
 	ID_LIKE_CLASS_COMMON(CreatureID, ECreatureID)
 
@@ -1049,8 +1049,7 @@ public:
 	SpellID(ESpellID _num = NONE) : num(_num)
 	{}
 
-	//TODO: should this be const?
-	DLL_LINKAGE CSpell * toSpell() const;
+	DLL_LINKAGE const CSpell * toSpell() const;
 
 	ID_LIKE_CLASS_COMMON(SpellID, ESpellID)
 

+ 2 - 2
lib/spells/BattleSpellMechanics.cpp

@@ -196,8 +196,8 @@ bool CureMechanics::dispellSelector(const Bonus * b)
 {
 	if(b->source == Bonus::SPELL_EFFECT)
 	{
-		CSpell * sp = SpellID(b->sid).toSpell();
-		return sp->isNegative();
+		const CSpell * sp = SpellID(b->sid).toSpell();
+		return sp && sp->isNegative();
 	}
 	return false; //not a spell effect
 }

+ 2 - 2
lib/spells/CreatureSpellMechanics.cpp

@@ -99,8 +99,8 @@ bool DispellHelpfulMechanics::positiveSpellEffects(const Bonus *b)
 {
 	if(b->source == Bonus::SPELL_EFFECT)
 	{
-		CSpell *sp = SpellID(b->sid).toSpell();
-		return sp->isPositive();
+		const CSpell * sp = SpellID(b->sid).toSpell();
+		return sp && sp->isPositive();
 	}
 	return false; //not a spell effect
 }

+ 2 - 3
server/CGameHandler.cpp

@@ -4426,14 +4426,13 @@ bool CGameHandler::makeCustomAction( BattleAction &ba )
 			const CGHeroInstance *h = gs->curB->battleGetFightingHero(ba.side);
 			COMPLAIN_RET_FALSE_IF((!h), "Wrong caster!");
 
-			if(ba.additionalInfo < 0 || ba.additionalInfo >= VLC->spellh->objects.size())
+			const CSpell * s = SpellID(ba.additionalInfo).toSpell();
+			if(!s)
 			{
 				logGlobal->error("Wrong spell id (%d)!", ba.additionalInfo);
 				return false;
 			}
 
-			const CSpell * s = SpellID(ba.additionalInfo).toSpell();
-
 			BattleSpellCastParameters parameters(gs->curB, h, s);
 			parameters.aimToHex(ba.destinationTile);//todo: allow multiple destinations
 			parameters.mode = ECastingMode::HERO_CASTING;