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