about summary refs log tree commit diff
path: root/src/game
diff options
context:
space:
mode:
Diffstat (limited to 'src/game')
-rw-r--r--src/game/editor/ed_editor.cpp66
-rw-r--r--src/game/editor/ed_editor.h1
-rw-r--r--src/game/server/gamemodes/ctf.cpp2
3 files changed, 66 insertions, 3 deletions
diff --git a/src/game/editor/ed_editor.cpp b/src/game/editor/ed_editor.cpp
index 387ce104..35a0b03a 100644
--- a/src/game/editor/ed_editor.cpp
+++ b/src/game/editor/ed_editor.cpp
@@ -554,8 +554,24 @@ CQuad *CEditor::GetSelectedQuad()
 	return 0;
 }
 
-static void CallbackOpenMap(const char *pFileName, void *pUser) { if(((CEditor*)pUser)->Load(pFileName)) str_copy(((CEditor*)pUser)->m_aFileName, pFileName, 512); }
-static void CallbackAppendMap(const char *pFileName, void *pUser) { if(((CEditor*)pUser)->Append(pFileName)) ((CEditor*)pUser)->m_aFileName[0] = 0; }
+static void CallbackOpenMap(const char *pFileName, void *pUser)
+{
+	CEditor *pEditor = (CEditor*)pUser;
+	if(pEditor->Load(pFileName))
+	{
+		str_copy(pEditor->m_aFileName, pFileName, 512);
+		pEditor->SortImages();
+	}
+}
+static void CallbackAppendMap(const char *pFileName, void *pUser)
+{
+	CEditor *pEditor = (CEditor*)pUser;
+	if(pEditor->Append(pFileName))
+	{
+		pEditor->m_aFileName[0] = 0;
+		pEditor->SortImages();
+	}
+}
 static void CallbackSaveMap(const char *pFileName, void *pUser){ if(((CEditor*)pUser)->Save(pFileName)) str_copy(((CEditor*)pUser)->m_aFileName, pFileName, 512); }
 
 void CEditor::DoToolbar(CUIRect ToolBar)
@@ -1733,6 +1749,7 @@ void CEditor::ReplaceImage(const char *pFileName, void *pUser)
 	*pImg = ImgInfo;
 	ExtractName(pFileName, pImg->m_aName);
 	pImg->m_TexId = pEditor->Graphics()->LoadTextureRaw(ImgInfo.m_Width, ImgInfo.m_Height, ImgInfo.m_Format, ImgInfo.m_pData, CImageInfo::FORMAT_AUTO, 0);
+	pEditor->SortImages();
 }
 
 void CEditor::AddImage(const char *pFileName, void *pUser)
@@ -1755,6 +1772,7 @@ void CEditor::AddImage(const char *pFileName, void *pUser)
 	}
 
 	pEditor->m_Map.m_lImages.add(pImg);
+	pEditor->SortImages();
 }
 
 
@@ -1817,6 +1835,50 @@ int CEditor::PopupImage(CEditor *pEditor, CUIRect View)
 	return 0;
 }
 
+static int CompareImageName(const void *pObject1, const void *pObject2)
+{
+	CEditorImage *pImage1 = *(CEditorImage**)pObject1;
+	CEditorImage *pImage2 = *(CEditorImage**)pObject2;
+
+	return str_comp(pImage1->m_aName, pImage2->m_aName);
+}
+
+static int *gs_pSortedIndex = 0;
+static void ModifySortedIndex(int *pIndex)
+{
+	if(*pIndex > -1)
+		*pIndex = gs_pSortedIndex[*pIndex];
+}
+
+void CEditor::SortImages()
+{
+	bool Sorted = true;
+	for(int i = 1; i < m_Map.m_lImages.size(); i++)
+		if( str_comp(m_Map.m_lImages[i]->m_aName, m_Map.m_lImages[i-1]->m_aName) < 0 )
+		{
+			Sorted = false;
+			break;
+		}
+
+	if(!Sorted)
+	{
+		array<CEditorImage*> lTemp = array<CEditorImage*>(m_Map.m_lImages);
+		gs_pSortedIndex = new int[lTemp.size()];
+
+		qsort(m_Map.m_lImages.base_ptr(), m_Map.m_lImages.size(), sizeof(CEditorImage*), CompareImageName);
+
+		for(int OldIndex = 0; OldIndex < lTemp.size(); OldIndex++)
+			for(int NewIndex = 0; NewIndex < m_Map.m_lImages.size(); NewIndex++)
+				if(lTemp[OldIndex] == m_Map.m_lImages[NewIndex])
+					gs_pSortedIndex[OldIndex] = NewIndex;
+
+		m_Map.ModifyImageIndex(ModifySortedIndex);
+
+		delete [] gs_pSortedIndex;
+		gs_pSortedIndex = 0;
+	}
+}
+	
 
 void CEditor::RenderImages(CUIRect ToolBox, CUIRect ToolBar, CUIRect View)
 {
diff --git a/src/game/editor/ed_editor.h b/src/game/editor/ed_editor.h
index d027c162..a7d742a8 100644
--- a/src/game/editor/ed_editor.h
+++ b/src/game/editor/ed_editor.h
@@ -608,6 +608,7 @@ public:
 	void RenderFileDialog();
 
 	void AddFileDialogEntry(const char *pName, CUIRect *pView);
+	void SortImages();
 };
 
 // make sure to inline this function
diff --git a/src/game/server/gamemodes/ctf.cpp b/src/game/server/gamemodes/ctf.cpp
index 05eb973e..705d21ac 100644
--- a/src/game/server/gamemodes/ctf.cpp
+++ b/src/game/server/gamemodes/ctf.cpp
@@ -136,7 +136,7 @@ void CGameControllerCTF::Tick()
 		else
 		{
 			CCharacter *apCloseCCharacters[MAX_CLIENTS];
-			int Num = GameServer()->m_World.FindEntities(F->m_Pos, 32.0f, (CEntity**)apCloseCCharacters, MAX_CLIENTS, NETOBJTYPE_CHARACTER);
+			int Num = GameServer()->m_World.FindEntities(F->m_Pos, 32.0f-(float)g_CharPhysSize, (CEntity**)apCloseCCharacters, MAX_CLIENTS, NETOBJTYPE_CHARACTER);
 			for(int i = 0; i < Num; i++)
 			{
 				if(!apCloseCCharacters[i]->IsAlive() || apCloseCCharacters[i]->GetPlayer()->GetTeam() == -1 || GameServer()->Collision()->IntersectLine(F->m_Pos, apCloseCCharacters[i]->m_Pos, NULL, NULL))