Debian Codegraph @

contrib/bobtoolz/funchandlers-ctf-GTK.cpp

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