2 BobToolz plugin for GtkRadiant
3 Copyright (C) 2001 Gordon Biggans
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // DMap.cpp: implementation of the DMap class.
22 //////////////////////////////////////////////////////////////////////
28 //////////////////////////////////////////////////////////////////////
29 // Construction/Destruction
30 //////////////////////////////////////////////////////////////////////
35 AddEntity("worldspawn", 0);
43 DEntity* DMap::AddEntity(char *classname, int ID)
47 newEntity = new DEntity(classname, m_nNextEntity++);
49 newEntity = new DEntity(classname, ID);
51 entityList.push_back(newEntity);
56 void DMap::ClearEntities()
60 for(list<DEntity *>::const_iterator deadEntity=entityList.begin(); deadEntity!=entityList.end(); deadEntity++)
66 DEntity* DMap::GetEntityForID(int ID)
68 DEntity* findEntity = NULL;
70 for(list<DEntity *>::const_iterator chkEntity=entityList.begin(); chkEntity!=entityList.end(); chkEntity++)
72 if((*chkEntity)->m_nID == ID)
74 findEntity = (*chkEntity);
80 findEntity = AddEntity("worldspawn", ID);
86 DEntity* DMap::GetWorldSpawn()
88 return GetEntityForID(0);
91 void DMap::BuildInRadiant(bool bAllowDestruction)
93 for(list<DEntity *>::const_iterator buildEntity=entityList.begin(); buildEntity!=entityList.end(); buildEntity++)
94 (*buildEntity)->BuildInRadiant(bAllowDestruction);
97 void DMap::LoadAll(bool bLoadPatches)
101 g_FuncTable.m_pfnDeselectAllBrushes();
103 int count = g_FuncTable.m_pfnGetEntityCount();
105 for(int i = 0; i < count; i++)
110 loadEntity = GetWorldSpawn();
112 loadEntity = AddEntity("", m_nNextEntity++);
114 if(!loadEntity->LoadFromEntity(i, bLoadPatches))
117 entityList.pop_back();
122 int DMap::FixBrushes(bool rebuild)
125 for(list<DEntity *>::const_iterator fixEntity=entityList.begin(); fixEntity!=entityList.end(); fixEntity++)
129 if(!stricmp("worldspawn", (*fixEntity)->m_Classname))
130 cnt = (*fixEntity)->FixBrushes(rebuild);
133 cnt = (*fixEntity)->FixBrushes(FALSE);
136 RebuildEntity(*fixEntity);
145 void DMap::ResetTextures( const char* textureName, float fScale[2], float fShift[2], int rotation, const char* newTextureName,
146 int bResetTextureName, int bResetScale[2], int bResetShift[2], int bResetRotation)
148 for(list<DEntity *>::const_iterator texEntity=entityList.begin(); texEntity!=entityList.end(); texEntity++)
150 if(!stricmp("worldspawn", (*texEntity)->m_Classname))
151 (*texEntity)->ResetTextures(textureName, fScale, fShift, rotation, newTextureName,
152 bResetTextureName, bResetScale, bResetShift, bResetRotation, TRUE);
155 if((*texEntity)->ResetTextures( textureName, fScale, fShift, rotation, newTextureName,
156 bResetTextureName, bResetScale, bResetShift, bResetRotation, FALSE))
157 RebuildEntity(*texEntity);
162 void DMap::RebuildEntity(DEntity *ent)
164 ent->RemoveFromRadiant();
165 ent->BuildInRadiant(FALSE);