- Radiant is now Vista compatible (Aero must be disabled)
[xonotic/netradiant.git] / contrib / bobtoolz / funchandlers-ctf-GTK.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 #include "StdAfx.h"
21
22 #include "dialogs/dialogs-gtk.h"
23
24 #include "DEntity.h"
25 #include "DMap.h"
26
27 #include "misc.h"
28 #include "lists.h"
29 #include "funchandlers.h"
30
31 // for ctf texture changer
32 list<Str> clrList_Blue;
33 list<Str> clrList_Red;
34
35 BOOL clrLst1Loaded = FALSE;
36 BOOL clrLst2Loaded = FALSE;
37
38 // -------------
39
40 //========================//
41 //    Helper Functions    //
42 //========================//
43
44 void LoadLists()
45 {
46         char buffer[256];
47
48         if(!clrLst1Loaded)
49         {
50                 clrLst1Loaded = LoadExclusionList(GetFilename(buffer, "plugins/bt/ctf-blue.txt"), &clrList_Blue);
51                 LoadExclusionList(GetFilename(buffer, "plugins/bt/blue.txt"), &clrList_Blue);
52         }
53         if(!clrLst2Loaded)
54         {
55                 clrLst2Loaded = LoadExclusionList(GetFilename(buffer, "plugins/bt/ctf-red.txt"), &clrList_Red);
56                 LoadExclusionList(GetFilename(buffer, "plugins/bt/red.txt"), &clrList_Red);
57         }
58 }
59
60
61 //========================//
62 //     Main Functions     //
63 //========================//
64
65 void DoCTFColourChanger()
66 {
67         if(!clrLst1Loaded || !clrLst2Loaded)
68         {
69                 DoMessageBox("CTF texture lists not found, this function will terminate.", "Error", MB_OK);
70                 return;
71         }
72
73         int ret = DoCTFColourChangeBox();
74         if(ret == IDCANCEL)
75                 return;
76
77         int cnt = Min(clrList_Blue.size(), clrList_Red.size());
78         
79         list<Str>::const_iterator Texture_change;
80         list<Str>::const_iterator Texture_new;
81
82         float fDummy[2];
83
84         int eCnt = g_FuncTable.m_pfnGetEntityCount();
85
86         DMap world;
87         world.LoadAll(TRUE);
88
89         if(ret == IDYES)
90         {
91                 Texture_change =        clrList_Blue.begin();
92                 Texture_new =           clrList_Red.begin();
93         }
94         else
95         {
96                 Texture_change =        clrList_Red.begin();
97                 Texture_new =           clrList_Blue.begin();
98         }
99
100         for(int i = 0; i < cnt; i++)
101         {
102                 world.ResetTextures((*Texture_change).c_str(), fDummy, fDummy, 0, (*Texture_new).c_str(), TRUE);
103
104                 Texture_change++;
105                 Texture_new++;
106         }
107 }
108
109 void DoSwapLights()
110 {
111 /*      DMap world;
112         world.LoadAll();
113
114         for(list<DEntity*>::const_iterator loopEnt = world.entityList.begin(); loopEnt != world.entityList.end(); loopEnt++)
115         {
116                 DEntity* e = (*loopEnt);
117                 DEPair* epLightColour = e->FindEPairByKey("_color");
118                 if(epLightColour)
119                 {
120                         float r, g, b;
121                         sscanf(epLightColour->value, "%f %f %f", &r, &g, &b);
122                         sprintf(epLightColour->value, "%f %f %f", b, g, r);
123                         DMap::RebuildEntity(e);
124                 }
125         }*/
126
127         int cnt = g_FuncTable.m_pfnGetEntityCount();
128
129         for(int i = 0; i < cnt; i++)
130         {
131                 void* ent = g_FuncTable.m_pfnGetEntityHandle(i);
132
133                 for(epair_t* epList = *g_FuncTable.m_pfnGetEntityKeyValList(ent); epList; epList= epList->next)
134                 {
135                         if(!stricmp("_color", epList->key))
136                         {
137                                 float r, g, b;
138                                 sscanf(epList->value, "%f %f %f", &r, &g, &b);
139                                 sprintf(epList->value, "%f %f %f", b, g, r);
140                         }
141                 }
142         }
143 }
144
145 void DoChangeAngles()
146 {
147         int cnt = g_FuncTable.m_pfnGetEntityCount();
148
149         for(int i = 0; i < cnt; i++)
150         {
151                 void* ent = g_FuncTable.m_pfnGetEntityHandle(i);
152
153                 for(epair_t* epList = *g_FuncTable.m_pfnGetEntityKeyValList(ent); epList; epList= epList->next)
154                 {
155                         if(!stricmp("angle", epList->key))
156                         {
157                                 float angle;
158                                 sscanf(epList->value, "%f", &angle);
159                                 angle += 180;
160                                 while(angle > 360)
161                                         angle -= 360;
162
163                                 sprintf(epList->value, "%f", angle);
164                         }
165                 }
166         }
167 }
168
169 void DoSwapSpawns()
170 {
171         int cnt = g_FuncTable.m_pfnGetEntityCount();
172
173         for(int i = 0; i < cnt; i++)
174         {
175                 void* ent = g_FuncTable.m_pfnGetEntityHandle(i);
176
177                 for(epair_t* epList = *g_FuncTable.m_pfnGetEntityKeyValList(ent); epList; epList= epList->next)
178                 {
179                         if(!stricmp("classname", epList->key))
180                         {
181                                 if(!strcmp(epList->value, "team_CTF_redplayer"))
182                                         sprintf(epList->value, "team_CTF_blueplayer");
183                                 else if(!strcmp(epList->value, "team_CTF_blueplayer"))
184                                         sprintf(epList->value, "team_CTF_redplayer");
185
186                                 if(!strcmp(epList->value, "team_CTF_redspawn"))
187                                         sprintf(epList->value, "team_CTF_bluespawn");
188                                 else if(!strcmp(epList->value, "team_CTF_bluespawn"))
189                                         sprintf(epList->value, "team_CTF_redspawn");
190
191                                 if(!strcmp(epList->value, "team_CTF_redflag"))
192                                         sprintf(epList->value, "team_CTF_blueflag");
193                                 else if(!strcmp(epList->value, "team_CTF_blueflag"))
194                                         sprintf(epList->value, "team_CTF_redflag")
195                                         ;
196                                 if(!strcmp(epList->value, "team_redobelisk"))
197                                         sprintf(epList->value, "team_blueobelisk");
198                                 else if(!strcmp(epList->value, "team_blueobelisk"))
199                                         sprintf(epList->value, "team_redobelisk");
200                         }
201                 }
202         }
203 }
204
205 /*void test()
206 {
207         DMap world;
208         world.LoadAll();
209
210         for(list<DEntity*>::const_iterator ents = world.entityList.begin(); ents != world.entityList.end(); ents++)
211         {
212                 (*ents)->RemoveFromRadiant();
213         }
214 }*/