瀏覽代碼

refactor map loading, few small tweaks

alexvins 12 年之前
父節點
當前提交
b376ac8568
共有 6 個文件被更改,包括 336 次插入345 次删除
  1. 0 1
      lib/CObjectHandler.cpp
  2. 0 1
      lib/CObjectHandler.h
  3. 0 35
      lib/CSpellHandler.cpp
  4. 67 10
      lib/CSpellHandler.h
  5. 194 298
      lib/Mapping/CMapService.cpp
  6. 75 0
      lib/Mapping/CMapService.h

+ 0 - 1
lib/CObjectHandler.cpp

@@ -31,7 +31,6 @@
 #include "CBuildingHandler.h"
 #include "JsonNode.h"
 #include "Filesystem/CResourceLoader.h"
-#include "GameConstants.h"
 
 using namespace boost::assign;
 

+ 0 - 1
lib/CObjectHandler.h

@@ -478,7 +478,6 @@ public:
 	void initObj() override;
 	void onHeroVisit(const CGHeroInstance * h) const override;
 	void newTurn() const override;
-protected:
 	void setProperty(ui8 what, ui32 val) override;
 private:
 	void heroAcceptsCreatures(const CGHeroInstance *h, ui32 answer) const;

+ 0 - 35
lib/CSpellHandler.cpp

@@ -6,7 +6,6 @@
 #include "VCMI_Lib.h"
 #include "JsonNode.h"
 #include <cctype>
-#include "GameConstants.h"
 #include "BattleHex.h"
 #include "CModHandler.h"
 
@@ -251,40 +250,6 @@ CSpell::ETargetType CSpell::getTargetType() const //TODO: parse these at game la
 	return NO_TARGET;
 }
 
-bool CSpell::isPositive() const
-{
-	return positiveness == POSITIVE;
-}
-
-bool CSpell::isNegative() const
-{
-	return positiveness == NEGATIVE;
-}
-
-bool CSpell::isRisingSpell() const
-{
-	return isRising;
-}
-
-bool CSpell::isDamageSpell() const
-{
-	return isDamage;
-}
-
-bool CSpell::isMindSpell() const
-{
-	return isMind;
-}
-
-bool CSpell::isOffensiveSpell() const
-{
-	return isOffensive;
-}
-
-bool CSpell::hasEffects() const
-{
-	return !effects[0].empty();
-}
 
 
 void CSpell::getEffects(std::vector<Bonus>& lst, const int level) const

+ 67 - 10
lib/CSpellHandler.h

@@ -51,15 +51,19 @@ public:
 	si16 mainEffectAnim; //main spell effect animation, in AC format (or -1 when none)
 	ETargetType getTargetType() const;
 
-	bool isPositive() const;
-	bool isNegative() const;
-
-	bool isRisingSpell() const;
-	bool isDamageSpell() const;
-	bool isMindSpell() const;	
-	bool isOffensiveSpell() const;
-	
-	bool hasEffects() const;
+	inline bool isCombatSpell() const;
+	inline bool isAdventureSpell() const;
+	inline bool isCreatureAbility() const;
+
+	inline bool isPositive() const;
+	inline bool isNegative() const;
+
+	inline bool isRisingSpell() const;
+	inline bool isDamageSpell() const;
+	inline bool isMindSpell() const; //TODO: deprecated - remove, refactor
+	inline bool isOffensiveSpell() const;
+
+	inline bool hasEffects() const;
 	void getEffects(std::vector<Bonus> &lst, const int level) const;
 
 	bool isImmuneBy(const IBonusBearer *obj) const;
@@ -82,10 +86,63 @@ private:
 	std::vector<Bonus> effects [4];
 	std::vector<Bonus::BonusType> immunities; //any of these hrants immunity
 	std::vector<Bonus::BonusType> limiters; //all of them are required
-	
+
 
 };
 
+///CSpell inlines
+
+bool CSpell::isCombatSpell() const
+{
+	return combatSpell;
+}
+
+bool CSpell::isAdventureSpell() const
+{
+	return !combatSpell;
+}
+
+bool CSpell::isCreatureAbility() const
+{
+	return creatureAbility;
+}
+
+bool CSpell::isPositive() const
+{
+	return positiveness == POSITIVE;
+}
+
+bool CSpell::isNegative() const
+{
+	return positiveness == NEGATIVE;
+}
+
+bool CSpell::isRisingSpell() const
+{
+	return isRising;
+}
+
+bool CSpell::isDamageSpell() const
+{
+	return isDamage;
+}
+
+bool CSpell::isMindSpell() const
+{
+	return isMind;
+}
+
+bool CSpell::isOffensiveSpell() const
+{
+	return isOffensive;
+}
+
+bool CSpell::hasEffects() const
+{
+	return !effects[0].empty();
+}
+
+
 namespace Spells
 {
 	enum

文件差異過大導致無法顯示
+ 194 - 298
lib/Mapping/CMapService.cpp


+ 75 - 0
lib/Mapping/CMapService.h

@@ -24,6 +24,10 @@ class CCreatureSet;
 class CInputStream;
 class IMapLoader;
 
+#include "../vcmi_endian.h"
+#include "../int3.h"
+
+
 /**
  * The map service provides loading of VCMI/H3 map files. It can
  * be extended to save maps later as well.
@@ -312,6 +316,77 @@ private:
 	 */
 	ui8 reverse(ui8 arg);
 
+
+
+	/**
+	* Helper to read ui8 from buffer
+	*/
+	inline ui8 readUI8()
+	{
+	   return buffer[pos++];
+	}
+
+	/**
+	* Helper to read si8 from buffer
+	*/
+	inline si8 readSI8()
+	{
+	   return static_cast<si8>(buffer[pos++]);
+	}
+
+	/**
+	* Helper to read ui16 from buffer
+	*/
+	inline ui16 readUI16()
+	{
+		ui16 ret = read_le_u16(buffer+pos);
+		pos +=2;
+		return ret;
+	}
+
+	/**
+	* Helper to read ui32 from buffer
+	*/
+	inline ui32 readUI32()
+	{
+		ui32 ret = read_le_u32(buffer+pos);
+		pos +=4;
+		return ret;
+	}
+
+	/**
+	* Helper to read 8bit flag from buffer
+	*/
+	inline bool readBool()
+	{
+		return readUI8() != 0;
+	}
+
+	/**
+	* Helper to read string from buffer
+	*/
+	inline std::string readString()
+	{
+		return ::readString(buffer,pos);
+	}
+
+	/**
+	* Helper to skip unused data inbuffer
+	*/
+	inline void skip(const int count)
+	{
+		pos += count;
+	}
+
+	inline int3 readInt3()
+	{
+		int3 p;
+		p.x = readUI8();
+		p.y = readUI8();
+		p.z = readUI8();
+		return p;
+	}
+
 	/**
 	 * Init buffer / size.
 	 *

部分文件因文件數量過多而無法顯示