浏览代码

Fixes for previous rev.

Michał W. Urbańczyk 12 年之前
父节点
当前提交
827d7b8681
共有 3 个文件被更改,包括 34 次插入15 次删除
  1. 28 9
      lib/Connection.h
  2. 2 2
      lib/GameConstants.cpp
  3. 4 4
      lib/GameConstants.h

+ 28 - 9
lib/Connection.h

@@ -368,10 +368,11 @@ public:
 	{
 	/*	if(id < 0)
 			return NULL;*/
+		si32 idAsNumber = idToNumber(id);
 
 		assert(oInfo.vector);
-		assert(oInfo.vector->size() > id);
-		return const_cast<T*>((*oInfo.vector)[id].get());
+		assert(oInfo.vector->size() > idAsNumber);
+		return const_cast<T*>((*oInfo.vector)[idAsNumber].get());
 	}
 
 	template <typename T, typename U>
@@ -431,12 +432,30 @@ struct VectorizedIDType
 		//else if
 		mpl::eval_if<boost::is_same<CCreature,U>,
 		mpl::identity<CreatureID>,
+		//else if
+		mpl::eval_if<boost::is_same<CArtifactInstance,U>,
+		mpl::identity<ArtifactInstanceID>,
+		//else if
+		mpl::eval_if<boost::is_base_of<CGObjectInstance,U>,
+		mpl::identity<ObjectInstanceID>,
 		//else
 		mpl::identity<si32>
-		>
-		>::type type;
+		> > > >::type type;
 };
 
+
+template<typename T>
+si32 idToNumber(const T &t, typename boost::enable_if<boost::is_convertible<T,si32> >::type * dummy = 0)
+{
+	return t;
+}
+
+template<typename T>
+si32 idToNumber(const BaseForID<T> &t)
+{
+	return t.getNum();
+}
+
 template <typename Handler>
 struct VariantVisitorSaver : boost::static_visitor<>
 {
@@ -586,9 +605,9 @@ public:
 			typedef typename VectorizedIDType<TObjectType>::type IDType;
  			if(const auto *info = getVectorisedTypeInfo<VType, IDType>())
  			{
-				si32 id = getIdFromVectorItem<VType>(*info, data);
+				IDType id = getIdFromVectorItem<VType>(*info, data);
 				*this << id;
-				if(id != -1) //vector id is enough
+				if(id != IDType(-1)) //vector id is enough
  					return;
  			}
  		}
@@ -961,11 +980,11 @@ public:
 			typedef typename VectorizedIDType<TObjectType>::type IDType;
 			if(const auto *info = getVectorisedTypeInfo<VType, IDType>())
 			{
-				si32 id;
+				IDType id;
 				*this >> id;
-				if(id != -1)
+				if(id != IDType(-1))
 				{
-					data = static_cast<T>(getVectorItemFromId<VType, IDType>(*info, IDType(id)));
+					data = static_cast<T>(getVectorItemFromId<VType, IDType>(*info, id));
 					return;
 				}
 			}

+ 2 - 2
lib/GameConstants.cpp

@@ -89,5 +89,5 @@ CSpell * SpellID::toSpell() const
 	return VLC->spellh->spells[*this];
 }
 
-template std::ostream & operator << <ArtifactInstanceID>(std::ostream & os, BaseForID<ArtifactInstanceID> id);
-template std::ostream & operator << <ObjectInstanceID>(std::ostream & os, BaseForID<ObjectInstanceID> id);
+//template std::ostream & operator << <ArtifactInstanceID>(std::ostream & os, BaseForID<ArtifactInstanceID> id);
+//template std::ostream & operator << <ObjectInstanceID>(std::ostream & os, BaseForID<ObjectInstanceID> id);

+ 4 - 4
lib/GameConstants.h

@@ -223,10 +223,10 @@ class ObjectInstanceID : public BaseForID<ObjectInstanceID>
 	friend class CNonConstInfoCallback;
 };
 
-#ifndef INSTANTIATE_BASE_FOR_ID_HERE
-extern template std::ostream & operator << <ArtifactInstanceID>(std::ostream & os, BaseForID<ArtifactInstanceID> id);
-extern template std::ostream & operator << <ObjectInstanceID>(std::ostream & os, BaseForID<ObjectInstanceID> id);
-#endif
+// #ifndef INSTANTIATE_BASE_FOR_ID_HERE
+// extern template std::ostream & operator << <ArtifactInstanceID>(std::ostream & os, BaseForID<ArtifactInstanceID> id);
+// extern template std::ostream & operator << <ObjectInstanceID>(std::ostream & os, BaseForID<ObjectInstanceID> id);
+// #endif
 
 // Enum declarations
 namespace PrimarySkill