Trevor Standley 16 年之前
父節點
當前提交
f7ce452e5e
共有 1 個文件被更改,包括 4 次插入2 次删除
  1. 4 2
      lib/CGameState.cpp

+ 4 - 2
lib/CGameState.cpp

@@ -1576,10 +1576,10 @@ int CGameState::getMovementCost(const CGHeroInstance *h, int3 src, int3 dest, in
 int CGameState::canBuildStructure( const CGTownInstance *t, int ID )
 {
 	int ret = 7; //allowed by default
-
 	//checking resources
 	CBuilding * pom = VLC->buildh->buildings[t->subID][ID];
-	for(int res=0;res<7;res++) //TODO: support custom amount of resources
+	if(!pom)return 8;
+	for(int res=0;res<pom->resources.size();res++) //TODO: support custom amount of resources
 	{
 		if(pom->resources[res] > getPlayer(t->tempOwner)->resources[res])
 			ret = 6; //lack of res
@@ -1620,6 +1620,8 @@ int CGameState::canBuildStructure( const CGTownInstance *t, int ID )
 			ret = 1; //lack of water
 	}
 
+	if(t->builtBuildings.find(ID)!=t->builtBuildings.end())	//already built
+		ret = 4;
 	return ret;
 }