]> de.git.xonotic.org Git - xonotic/netradiant.git/blob - contrib/bobtoolz/DMap.cpp
* applied patch by StefanV (from mailinglist) that fixes an error in config.py (broke...
[xonotic/netradiant.git] / contrib / bobtoolz / DMap.cpp
1 /*
2 BobToolz plugin for GtkRadiant
3 Copyright (C) 2001 Gordon Biggans
4
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.
9
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.
14
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
18 */
19
20 // DMap.cpp: implementation of the DMap class.
21 //
22 //////////////////////////////////////////////////////////////////////
23
24 #include "StdAfx.h"
25 #include "DMap.h"
26
27
28 //////////////////////////////////////////////////////////////////////
29 // Construction/Destruction
30 //////////////////////////////////////////////////////////////////////
31
32 DMap::DMap()
33 {
34         m_nNextEntity = 1;
35         AddEntity("worldspawn", 0);
36 }
37
38 DMap::~DMap()
39 {
40         ClearEntities();
41 }
42
43 DEntity* DMap::AddEntity(const char *classname, int ID)
44 {
45         DEntity* newEntity;
46         if(ID == -1)
47                 newEntity = new DEntity(classname, m_nNextEntity++);
48         else
49                 newEntity = new DEntity(classname, ID);
50
51         entityList.push_back(newEntity);
52
53         return newEntity;
54 }
55
56 void DMap::ClearEntities()
57 {
58         m_nNextEntity = 1;
59
60         for(list<DEntity *>::const_iterator deadEntity=entityList.begin(); deadEntity!=entityList.end(); deadEntity++)
61                 delete *deadEntity;
62
63         entityList.clear();
64 }
65
66 DEntity* DMap::GetEntityForID(int ID)
67 {
68         DEntity* findEntity = NULL;
69
70         for(list<DEntity *>::const_iterator chkEntity=entityList.begin(); chkEntity!=entityList.end(); chkEntity++)
71         {
72                 if((*chkEntity)->m_nID == ID)
73                 {
74                         findEntity = (*chkEntity);
75                         break;
76                 }
77         }
78
79         if(!findEntity)
80                 findEntity = AddEntity("worldspawn", ID);
81
82         return findEntity;
83 }
84
85
86 DEntity* DMap::GetWorldSpawn()
87 {
88         return GetEntityForID(0);
89 }
90
91 void DMap::BuildInRadiant(bool bAllowDestruction)
92 {
93         for(list<DEntity *>::const_iterator buildEntity=entityList.begin(); buildEntity!=entityList.end(); buildEntity++)
94                 (*buildEntity)->BuildInRadiant(bAllowDestruction);
95 }
96
97 void DMap::LoadAll(bool bLoadPatches)
98 {
99         ClearEntities();
100
101         g_FuncTable.m_pfnDeselectAllBrushes();
102
103         int count = g_FuncTable.m_pfnGetEntityCount();
104
105         for(int i = 0; i < count; i++)
106         {
107                 DEntity* loadEntity;
108
109                 if(i == 0)
110                         loadEntity = GetWorldSpawn();
111                 else
112                         loadEntity = AddEntity("", m_nNextEntity++);
113
114                 if(!loadEntity->LoadFromEntity(i, bLoadPatches))
115                 {
116                         delete loadEntity;
117                         entityList.pop_back();
118                 }
119         }
120 }
121
122 int DMap::FixBrushes(bool rebuild)
123 {
124         int count = 0;
125         for(list<DEntity *>::const_iterator fixEntity=entityList.begin(); fixEntity!=entityList.end(); fixEntity++)
126         {
127                 int cnt;
128
129                 if(!stricmp("worldspawn", (*fixEntity)->m_Classname))
130                         cnt = (*fixEntity)->FixBrushes(rebuild);
131                 else
132                 {
133                         cnt = (*fixEntity)->FixBrushes(FALSE);
134
135                         if(cnt && rebuild)
136                                 RebuildEntity(*fixEntity);
137                 }
138
139                 count += cnt;
140         }
141
142         return count;
143 }
144
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)
147 {
148         for(list<DEntity *>::const_iterator texEntity=entityList.begin(); texEntity!=entityList.end(); texEntity++)
149         {
150                 if(!stricmp("worldspawn", (*texEntity)->m_Classname))
151                         (*texEntity)->ResetTextures(textureName,        fScale,       fShift,       rotation, newTextureName,
152                                   bResetTextureName,  bResetScale,  bResetShift,  bResetRotation, TRUE);
153                 else
154                 {
155                         if((*texEntity)->ResetTextures( textureName,        fScale,       fShift,       rotation, newTextureName,
156                                       bResetTextureName,  bResetScale,  bResetShift,  bResetRotation, FALSE))
157                                 RebuildEntity(*texEntity);
158                 }
159         }
160 }
161
162 void DMap::RebuildEntity(DEntity *ent)
163 {
164         ent->RemoveFromRadiant();
165         ent->BuildInRadiant(FALSE);
166 }