]> git.xonotic.org Git - xonotic/netradiant.git/blob - contrib/bobtoolz/funchandlers-ctf-GTK.cpp
transfer from internal tree r5311 branches/1.4-gpl
[xonotic/netradiant.git] / contrib / bobtoolz / funchandlers-ctf-GTK.cpp
1 /*\r
2 BobToolz plugin for GtkRadiant\r
3 Copyright (C) 2001 Gordon Biggans\r
4 \r
5 This library is free software; you can redistribute it and/or\r
6 modify it under the terms of the GNU Lesser General Public\r
7 License as published by the Free Software Foundation; either\r
8 version 2.1 of the License, or (at your option) any later version.\r
9 \r
10 This library is distributed in the hope that it will be useful,\r
11 but WITHOUT ANY WARRANTY; without even the implied warranty of\r
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\r
13 Lesser General Public License for more details.\r
14 \r
15 You should have received a copy of the GNU Lesser General Public\r
16 License along with this library; if not, write to the Free Software\r
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\r
18 */\r
19 \r
20 #include "StdAfx.h"\r
21 \r
22 #include "dialogs/dialogs-gtk.h"\r
23 \r
24 #include "DEntity.h"\r
25 #include "DMap.h"\r
26 \r
27 #include "misc.h"\r
28 #include "lists.h"\r
29 #include "funchandlers.h"\r
30 \r
31 // for ctf texture changer\r
32 list<Str> clrList_Blue;\r
33 list<Str> clrList_Red;\r
34 \r
35 BOOL clrLst1Loaded = FALSE;\r
36 BOOL clrLst2Loaded = FALSE;\r
37 \r
38 // -------------\r
39 \r
40 //========================//\r
41 //    Helper Functions    //\r
42 //========================//\r
43 \r
44 void LoadLists()\r
45 {\r
46         char buffer[256];\r
47 \r
48         if(!clrLst1Loaded)\r
49         {\r
50                 clrLst1Loaded = LoadExclusionList(GetFilename(buffer, "plugins/bt/ctf-blue.txt"), &clrList_Blue);\r
51                 LoadExclusionList(GetFilename(buffer, "plugins/bt/blue.txt"), &clrList_Blue);\r
52         }\r
53         if(!clrLst2Loaded)\r
54         {\r
55                 clrLst2Loaded = LoadExclusionList(GetFilename(buffer, "plugins/bt/ctf-red.txt"), &clrList_Red);\r
56                 LoadExclusionList(GetFilename(buffer, "plugins/bt/red.txt"), &clrList_Red);\r
57         }\r
58 }\r
59 \r
60 \r
61 //========================//\r
62 //     Main Functions     //\r
63 //========================//\r
64 \r
65 void DoCTFColourChanger()\r
66 {\r
67         if(!clrLst1Loaded || !clrLst2Loaded)\r
68         {\r
69                 DoMessageBox("CTF texture lists not found, this function will terminate.", "Error", MB_OK);\r
70                 return;\r
71         }\r
72 \r
73         int ret = DoCTFColourChangeBox();\r
74         if(ret == IDCANCEL)\r
75                 return;\r
76 \r
77         int cnt = Min(clrList_Blue.size(), clrList_Red.size());\r
78         \r
79         list<Str>::const_iterator Texture_change;\r
80         list<Str>::const_iterator Texture_new;\r
81 \r
82         float fDummy[2];\r
83 \r
84         int eCnt = g_FuncTable.m_pfnGetEntityCount();\r
85 \r
86         DMap world;\r
87         world.LoadAll(TRUE);\r
88 \r
89         if(ret == IDYES)\r
90         {\r
91                 Texture_change =        clrList_Blue.begin();\r
92                 Texture_new =           clrList_Red.begin();\r
93         }\r
94         else\r
95         {\r
96                 Texture_change =        clrList_Red.begin();\r
97                 Texture_new =           clrList_Blue.begin();\r
98         }\r
99 \r
100         for(int i = 0; i < cnt; i++)\r
101         {\r
102                 world.ResetTextures((*Texture_change).c_str(), fDummy, fDummy, 0, (*Texture_new).c_str(), TRUE);\r
103 \r
104                 Texture_change++;\r
105                 Texture_new++;\r
106         }\r
107 }\r
108 \r
109 void DoSwapLights()\r
110 {\r
111 /*      DMap world;\r
112         world.LoadAll();\r
113 \r
114         for(list<DEntity*>::const_iterator loopEnt = world.entityList.begin(); loopEnt != world.entityList.end(); loopEnt++)\r
115         {\r
116                 DEntity* e = (*loopEnt);\r
117                 DEPair* epLightColour = e->FindEPairByKey("_color");\r
118                 if(epLightColour)\r
119                 {\r
120                         float r, g, b;\r
121                         sscanf(epLightColour->value, "%f %f %f", &r, &g, &b);\r
122                         sprintf(epLightColour->value, "%f %f %f", b, g, r);\r
123                         DMap::RebuildEntity(e);\r
124                 }\r
125         }*/\r
126 \r
127         int cnt = g_FuncTable.m_pfnGetEntityCount();\r
128 \r
129         for(int i = 0; i < cnt; i++)\r
130         {\r
131                 void* ent = g_FuncTable.m_pfnGetEntityHandle(i);\r
132 \r
133                 for(epair_t* epList = *g_FuncTable.m_pfnGetEntityKeyValList(ent); epList; epList= epList->next)\r
134                 {\r
135                         if(!stricmp("_color", epList->key))\r
136                         {\r
137                                 float r, g, b;\r
138                                 sscanf(epList->value, "%f %f %f", &r, &g, &b);\r
139                                 sprintf(epList->value, "%f %f %f", b, g, r);\r
140                         }\r
141                 }\r
142         }\r
143 }\r
144 \r
145 void DoChangeAngles()\r
146 {\r
147         int cnt = g_FuncTable.m_pfnGetEntityCount();\r
148 \r
149         for(int i = 0; i < cnt; i++)\r
150         {\r
151                 void* ent = g_FuncTable.m_pfnGetEntityHandle(i);\r
152 \r
153                 for(epair_t* epList = *g_FuncTable.m_pfnGetEntityKeyValList(ent); epList; epList= epList->next)\r
154                 {\r
155                         if(!stricmp("angle", epList->key))\r
156                         {\r
157                                 float angle;\r
158                                 sscanf(epList->value, "%f", &angle);\r
159                                 angle += 180;\r
160                                 while(angle > 360)\r
161                                         angle -= 360;\r
162 \r
163                                 sprintf(epList->value, "%f", angle);\r
164                         }\r
165                 }\r
166         }\r
167 }\r
168 \r
169 void DoSwapSpawns()\r
170 {\r
171         int cnt = g_FuncTable.m_pfnGetEntityCount();\r
172 \r
173         for(int i = 0; i < cnt; i++)\r
174         {\r
175                 void* ent = g_FuncTable.m_pfnGetEntityHandle(i);\r
176 \r
177                 for(epair_t* epList = *g_FuncTable.m_pfnGetEntityKeyValList(ent); epList; epList= epList->next)\r
178                 {\r
179                         if(!stricmp("classname", epList->key))\r
180                         {\r
181                                 if(!strcmp(epList->value, "team_CTF_redplayer"))\r
182                                         sprintf(epList->value, "team_CTF_blueplayer");\r
183                                 else if(!strcmp(epList->value, "team_CTF_blueplayer"))\r
184                                         sprintf(epList->value, "team_CTF_redplayer");\r
185 \r
186                                 if(!strcmp(epList->value, "team_CTF_redspawn"))\r
187                                         sprintf(epList->value, "team_CTF_bluespawn");\r
188                                 else if(!strcmp(epList->value, "team_CTF_bluespawn"))\r
189                                         sprintf(epList->value, "team_CTF_redspawn");\r
190 \r
191                                 if(!strcmp(epList->value, "team_CTF_redflag"))\r
192                                         sprintf(epList->value, "team_CTF_blueflag");\r
193                                 else if(!strcmp(epList->value, "team_CTF_blueflag"))\r
194                                         sprintf(epList->value, "team_CTF_redflag")\r
195                                         ;\r
196                                 if(!strcmp(epList->value, "team_redobelisk"))\r
197                                         sprintf(epList->value, "team_blueobelisk");\r
198                                 else if(!strcmp(epList->value, "team_blueobelisk"))\r
199                                         sprintf(epList->value, "team_redobelisk");\r
200                         }\r
201                 }\r
202         }\r
203 }\r
204 \r
205 /*void test()\r
206 {\r
207         DMap world;\r
208         world.LoadAll();\r
209 \r
210         for(list<DEntity*>::const_iterator ents = world.entityList.begin(); ents != world.entityList.end(); ents++)\r
211         {\r
212                 (*ents)->RemoveFromRadiant();\r
213         }\r
214 }*/\r