Beispiel #1
0
BOOL RevealRoom(Room2* pRoom2, BOOL revealPresets) {
	bool bAdded = false;
	bool bInit = false;

	DWORD dwLevelNo = D2CLIENT_GetPlayerUnit()->pPath->pRoom1->pRoom2->pLevel->dwLevelNo;

	CriticalRoom room;
	room.EnterSection();
	//Make sure we have the room.
	if (!pRoom2)
		return false;

	UnitAny* player = D2CLIENT_GetPlayerUnit();
	//Check if we have Room1(Needed in order to reveal)
	if (!(pRoom2 && pRoom2->pLevel && pRoom2->pRoom1)) {
		D2COMMON_AddRoomData(pRoom2->pLevel->pMisc->pAct, pRoom2->pLevel->dwLevelNo, pRoom2->dwPosX, pRoom2->dwPosY, NULL);
		bAdded = true;
	}
	if (!(pRoom2 && pRoom2->pRoom1)){// second check added to see if we DID indeed init the room!
		return false;
	}

	//If we are somewhere other then the given area, init automap layer to be drawn to.
	if(!(pRoom2 && pRoom2->pLevel && pRoom2->pLevel->dwLevelNo && player->pPath && player->pPath->pRoom1 && player->pPath->pRoom1->pRoom2 && player->pPath->pRoom1->pRoom2->pLevel && player->pPath->pRoom1->pRoom2->pLevel->dwLevelNo == pRoom2->pLevel->dwLevelNo)){
		InitAutomapLayer(pRoom2->pLevel->dwLevelNo);
		bInit = true;
	}

	//Reveal this room!
	D2CLIENT_RevealAutomapRoom(pRoom2->pRoom1, TRUE, (*p_D2CLIENT_AutomapLayer));

	if(revealPresets)
		DrawPresets(pRoom2);

	//Remove room data if we have added.
	if(bAdded)
		D2COMMON_RemoveRoomData(pRoom2->pLevel->pMisc->pAct, pRoom2->pLevel->dwLevelNo, pRoom2->dwPosX, pRoom2->dwPosY, NULL);
	
	if(bInit)
		InitAutomapLayer(dwLevelNo);
	
	return true;
}
Beispiel #2
0
INT CCollisionMap::GetLevelExits(LPLevelExit* lpLevel)
{
	POINT ptExitPoints[0x40][2];
	INT nTotalPoints = 0, nCurrentExit = 0;
	INT nMaxExits = 0x40;
	UnitAny* Me = D2CLIENT_GetPlayerUnit();
	CriticalRoom myRoom;
	myRoom.EnterSection();

	for(INT i = 0; i < m_map.GetCX(); i++)
	{
		if(!(m_map[i][0] % 2))
		{
			ptExitPoints[nTotalPoints][0].x = i;
			ptExitPoints[nTotalPoints][0].y = 0;

			for(i++; i < m_map.GetCX(); i++)
			{
				if(m_map[i][0] % 2)
				{
					ptExitPoints[nTotalPoints][1].x = i - 1;
					ptExitPoints[nTotalPoints][1].y = 0;
					break;
				}
			}

			nTotalPoints++;
			break;
		}
	}

	for(INT i = 0; i < m_map.GetCX(); i++)
	{
		if(!(m_map[i][m_map.GetCY() - 1] % 2))
		{
			ptExitPoints[nTotalPoints][0].x = i;
			ptExitPoints[nTotalPoints][0].y = m_map.GetCY() - 1;

			for(i++; i < m_map.GetCX(); i++)
			{
				if((m_map[i][m_map.GetCY() - 1] % 2))
				{
					ptExitPoints[nTotalPoints][1].x = i - 1;
					ptExitPoints[nTotalPoints][1].y = m_map.GetCY() - 1;
					break;
				}
			}

			nTotalPoints++;
			break;
		}
	}

	for(INT i = 0; i < m_map.GetCY(); i++)
	{
		if(!(m_map[0][i] % 2))
		{
			ptExitPoints[nTotalPoints][0].x = 0;
			ptExitPoints[nTotalPoints][0].y = i;

			for(i++; i < m_map.GetCY(); i++)
			{
				if((m_map[0][i] % 2))
				{
					ptExitPoints[nTotalPoints][1].x = 0;
					ptExitPoints[nTotalPoints][1].y = i - 1;
					break;
				}
			}

			nTotalPoints++;
			break;
		}
	}

	for(INT i = 0; i < m_map.GetCY(); i++)
	{
		if(!(m_map[m_map.GetCX() - 1][i] % 2))
		{
			ptExitPoints[nTotalPoints][0].x = m_map.GetCX() - 1;
			ptExitPoints[nTotalPoints][0].y = i;

			for(i++; i < m_map.GetCY(); i++)
			{
				if((m_map[m_map.GetCX() - 1][i] % 2))
				{
					ptExitPoints[nTotalPoints][1].x = m_map.GetCX() - 1;
					ptExitPoints[nTotalPoints][1].y = i - 1;
					break;
				}
			}

			nTotalPoints++;
			break;
		}
	}

	LPPOINT ptCenters = new POINT[nTotalPoints];
	for(INT i = 0; i < nTotalPoints; i++)
	{
		INT nXDiff = ptExitPoints[i][1].x - ptExitPoints[i][0].x;
		INT nYDiff = ptExitPoints[i][1].y - ptExitPoints[i][0].y;
		INT nXCenter = 0, nYCenter = 0;

		if(nXDiff > 0)
		{
			if(nXDiff % 2)
				nXCenter = ptExitPoints[i][0].x + ((nXDiff - (nXDiff % 2)) / 2);
			else
				nXCenter = ptExitPoints[i][0].x + (nXDiff / 2);
		}

		if(nYDiff > 0)
		{
			if(nYDiff % 2)
				nYCenter = ptExitPoints[i][0].y + ((nYDiff - (nYDiff % 2)) / 2);
			else
				nYCenter = ptExitPoints[i][0].y + (nYDiff / 2);
		}

		ptCenters[i].x = nXCenter ? nXCenter : ptExitPoints[i][0].x;
		ptCenters[i].y = nYCenter ? nYCenter : ptExitPoints[i][0].y;
	}

	

	for(Room2* pRoom = GetLevel(dwLevelId)->pRoom2First; pRoom; pRoom = pRoom->pRoom2Next)
	{
		Room2* *pNear = pRoom->pRoom2Near;
		for(DWORD i = 0; i < pRoom->dwRoomsNear; i++)
		{
			if(pNear[i]->pLevel->dwLevelNo != dwLevelId)
			{
				INT nRoomX = pRoom->dwPosX * 5;
				INT nRoomY = pRoom->dwPosY * 5;

				for(INT j = 0; j < nTotalPoints; j++)
				{
					if((ptCenters[j].x + m_ptLevelOrigin.x) >= (WORD)nRoomX && (ptCenters[j].x + m_ptLevelOrigin.x) <= (WORD)(nRoomX + (pRoom->dwSizeX * 5)))
					{
						if((ptCenters[j].y + m_ptLevelOrigin.y) >= (WORD)nRoomY && (ptCenters[j].y + m_ptLevelOrigin.y) <= (WORD)(nRoomY + (pRoom->dwSizeY * 5)))
						{
							if(nCurrentExit >= nMaxExits)
							{
//								LeaveCriticalSection(&CriticalSection);
								return FALSE;
							}
							
							lpLevel[nCurrentExit] = new LevelExit;
							lpLevel[nCurrentExit]->dwTargetLevel = pNear[i]->pLevel->dwLevelNo;
							lpLevel[nCurrentExit]->ptPos.x = ptCenters[j].x + m_ptLevelOrigin.x;
							lpLevel[nCurrentExit]->ptPos.y = ptCenters[j].y + m_ptLevelOrigin.y;
							lpLevel[nCurrentExit]->dwType = EXIT_LEVEL;
							lpLevel[nCurrentExit]->dwId = 0;
							nCurrentExit++;
						}
					}
				}

				break;
			}
		}

		BOOL bAdded = FALSE;

		if(!pRoom->pRoom1)
		{
			D2COMMON_AddRoomData(Me->pAct, pRoom->pLevel->dwLevelNo, pRoom->dwPosX, pRoom->dwPosY, Me->pPath->pRoom1);
			bAdded = TRUE;
		}
			
			for(PresetUnit* pUnit = pRoom->pPreset; pUnit; pUnit = pUnit->pPresetNext)
			{

				if(nCurrentExit >= nMaxExits)
				{
					if(bAdded)
						D2COMMON_RemoveRoomData(Me->pAct, pRoom->pLevel->dwLevelNo, pRoom->dwPosX, pRoom->dwPosY, Me->pPath->pRoom1);
//					LeaveCriticalSection(&CriticalSection);
					return FALSE;
				}

				if(pUnit->dwType == UNIT_TILE)
				{
					DWORD dwTargetLevel = GetTileLevelNo(pRoom, pUnit->dwTxtFileNo);
					
					if(dwTargetLevel)
					{
						BOOL bExists = FALSE;

						for(INT i = 0; i < nCurrentExit; i++)
							{
								if(((DWORD)lpLevel[i]->ptPos.x == (pRoom->dwPosX * 5) + pUnit->dwPosX) && 
									((DWORD)lpLevel[i]->ptPos.y == (pRoom->dwPosY * 5) + pUnit->dwPosY))
									bExists = TRUE;
							}

						if(!bExists)
						{
							lpLevel[nCurrentExit] = new LevelExit;
							lpLevel[nCurrentExit]->dwTargetLevel = dwTargetLevel;
							lpLevel[nCurrentExit]->ptPos.x = (pRoom->dwPosX * 5) + pUnit->dwPosX;
							lpLevel[nCurrentExit]->ptPos.y = (pRoom->dwPosY * 5) + pUnit->dwPosY;
							lpLevel[nCurrentExit]->dwType = EXIT_TILE;
							lpLevel[nCurrentExit]->dwId = pUnit->dwTxtFileNo;
							nCurrentExit++;
						}
					}
				}
			}

		if(bAdded)
			D2COMMON_RemoveRoomData(Me->pAct, pRoom->pLevel->dwLevelNo, pRoom->dwPosX, pRoom->dwPosY, Me->pPath->pRoom1);
	}

//	LeaveCriticalSection(&CriticalSection);

	return nCurrentExit;
}