]> de.git.xonotic.org Git - xonotic/netradiant.git/blob - contrib/ufoaiplug/ufoai.cpp
962a2ebd4ea039a100ca129b2f5fe02ad7764d26
[xonotic/netradiant.git] / contrib / ufoaiplug / ufoai.cpp
1 /*
2    This file is part of GtkRadiant.
3
4    GtkRadiant is free software; you can redistribute it and/or modify
5    it under the terms of the GNU General Public License as published by
6    the Free Software Foundation; either version 2 of the License, or
7    (at your option) any later version.
8
9    GtkRadiant is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12    GNU General Public License for more details.
13
14    You should have received a copy of the GNU General Public License
15    along with GtkRadiant; if not, write to the Free Software
16    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17  */
18
19 #include "ufoai.h"
20 #include "ufoai_level.h"
21 #include "ufoai_gtk.h"
22 #include "ufoai_filters.h"
23
24 #include "debugging/debugging.h"
25
26 #include "iplugin.h"
27
28 #include "version.h"
29
30 #include "string/string.h"
31 #include "modulesystem/singletonmodule.h"
32
33 #include <gtk/gtk.h>
34
35 #include "ifilter.h"
36 #include "ibrush.h"
37 #include "iundo.h"       // declaration of undo system
38 #include "ientity.h"     // declaration of entity system
39 #include "iscenegraph.h" // declaration of datastructure of the map
40 #include "scenelib.h"    // declaration of datastructure of the map
41 #include "qerplugin.h"   // declaration to use other interfaces as a plugin
42 #include "ieclass.h"
43
44 #define CMD_ABOUT "About..."
45
46 class UFOAIPluginDependencies :
47         public GlobalRadiantModuleRef,  // basic class for all other module refs
48         public GlobalUndoModuleRef,     // used to say radiant that something has changed and to undo that
49         public GlobalSceneGraphModuleRef, // necessary to handle data in the mapfile (change, retrieve data)
50         public GlobalEntityModuleRef,   // to access and modify the entities
51         public GlobalEntityClassManagerModuleRef
52 {
53 public:
54 UFOAIPluginDependencies( void ) :
55         GlobalEntityModuleRef( GlobalRadiant().getRequiredGameDescriptionKeyValue( "entities" ) ),
56         GlobalEntityClassManagerModuleRef( GlobalRadiant().getRequiredGameDescriptionKeyValue( "entityclass" ) ){
57 }
58 };
59
60 namespace UFOAI
61 {
62         ui::Window g_mainwnd{ui::null};
63
64 const char* init( void* hApp, void* pMainWidget ){
65         g_mainwnd = ui::Window::from(pMainWidget);
66         return "Initializing GTKRadiant UFOAI plugin";
67 }
68 const char* getName(){
69         return PLUGIN_NAME;
70 }
71 const char* getCommandList(){
72         /*GlobalRadiant().getGameName()*/
73         return CMD_ABOUT ";-;Worldspawn reset;Worldspawn;Perform check;-;Level 1;Level 2;Level 3;Level 4;Level 5;Level 6;Level 7;Level 8;-;StepOn;ActorClip;WeaponClip;Nodraw";
74 }
75 const char* getCommandTitleList(){
76         return "";
77 }
78 void dispatch( const char* command, float* vMin, float* vMax, bool bSingleBrush ){
79         char const *message = NULL;
80         if ( string_equal( command, CMD_ABOUT ) ) {
81                 const char *label_text = 
82                         PLUGIN_NAME " " PLUGIN_VERSION " for "
83                         RADIANT_NAME " " RADIANT_VERSION "\n\n"
84                         "Written by Martin Gerhardy (tlh2000/mattn)\n"
85                         "for the UFO:AI project (http://ufoai.sf.net)\n\n"
86                         "Built against "
87                         RADIANT_NAME " " RADIANT_VERSION_STRING "\n"
88                         __DATE__;
89
90                 GlobalRadiant().m_pfnMessageBox( g_mainwnd,
91                                                                                  label_text, "About" PLUGIN_NAME,
92                                                                                  eMB_OK, eMB_ICONDEFAULT );
93         }
94         else if ( string_equal( command, "Level 1" ) ) {
95                 filter_level( CONTENTS_LEVEL1 );
96         }
97         else if ( string_equal( command, "Level 2" ) ) {
98                 filter_level( CONTENTS_LEVEL2 );
99         }
100         else if ( string_equal( command, "Level 3" ) ) {
101                 filter_level( CONTENTS_LEVEL3 );
102         }
103         else if ( string_equal( command, "Worldspawn" ) ) {
104                 assign_default_values_to_worldspawn( false, &message );
105         }
106         else if ( string_equal( command, "Worldspawn reset" ) ) {
107                 assign_default_values_to_worldspawn( true, &message );
108         }
109         else if ( string_equal( command, "Perform check" ) ) {
110                 check_map_values( &message );
111         }
112         else if ( string_equal( command, "Level 4" ) ) {
113                 filter_level( CONTENTS_LEVEL4 );
114         }
115         else if ( string_equal( command, "Level 5" ) ) {
116                 filter_level( CONTENTS_LEVEL5 );
117         }
118         else if ( string_equal( command, "Level 6" ) ) {
119                 filter_level( CONTENTS_LEVEL6 );
120         }
121         else if ( string_equal( command, "Level 7" ) ) {
122                 filter_level( CONTENTS_LEVEL7 );
123         }
124         else if ( string_equal( command, "Level 8" ) ) {
125                 filter_level( CONTENTS_LEVEL8 );
126         }
127         else if ( string_equal( command, "StepOn" ) ) {
128                 filter_stepon();
129         }
130         else if ( string_equal( command, "ActorClip" ) ) {
131                 filter_actorclip();
132         }
133         else if ( string_equal( command, "WeaponClip" ) ) {
134                 filter_weaponclip();
135         }
136         else if ( string_equal( command, "NoDraw" ) ) {
137                 filter_nodraw();
138         }
139
140         if ( message != NULL ) {
141                 GlobalRadiant().m_pfnMessageBox( g_mainwnd,
142                                                                                  message, "Note",
143                                                                                  eMB_OK, eMB_ICONDEFAULT );
144         }
145         SceneChangeNotify();
146 }
147 } // namespace
148
149
150 class UFOAIModule : public TypeSystemRef
151 {
152 _QERPluginTable m_plugin;
153 public:
154 typedef _QERPluginTable Type;
155 STRING_CONSTANT( Name, "UFO:AI" );
156
157 UFOAIModule(){
158         m_plugin.m_pfnQERPlug_Init = &UFOAI::init;
159         m_plugin.m_pfnQERPlug_GetName = &UFOAI::getName;
160         m_plugin.m_pfnQERPlug_GetCommandList = &UFOAI::getCommandList;
161         m_plugin.m_pfnQERPlug_GetCommandTitleList = &UFOAI::getCommandTitleList;
162         m_plugin.m_pfnQERPlug_Dispatch = &UFOAI::dispatch;
163 }
164 _QERPluginTable* getTable(){
165         return &m_plugin;
166 }
167 };
168
169 typedef SingletonModule<UFOAIModule, UFOAIPluginDependencies> SingletonUFOAIModule;
170
171 SingletonUFOAIModule g_UFOAIModule;
172
173
174 class UFOAIToolbarDependencies : public ModuleRef<_QERPluginTable>
175 {
176 public:
177 UFOAIToolbarDependencies() : ModuleRef<_QERPluginTable>( "UFO:AI" ){
178 }
179 };
180
181 class UFOAIToolbarModule : public TypeSystemRef
182 {
183 _QERPlugToolbarTable m_table;
184 public:
185 typedef _QERPlugToolbarTable Type;
186 STRING_CONSTANT( Name, "UFO:AI" );
187
188 UFOAIToolbarModule(){
189         if ( !strcmp( GlobalRadiant().getGameDescriptionKeyValue( "name" ), "UFO:Alien Invasion" ) ) {
190                 m_table.m_pfnToolbarButtonCount = ToolbarButtonCount;
191                 m_table.m_pfnGetToolbarButton = GetToolbarButton;
192         }
193         else
194         {
195                 m_table.m_pfnToolbarButtonCount = ToolbarNoButtons;
196                 m_table.m_pfnGetToolbarButton = GetToolbarNoButton;
197         }
198 }
199 _QERPlugToolbarTable* getTable(){
200         return &m_table;
201 }
202 };
203
204 typedef SingletonModule<UFOAIToolbarModule, UFOAIToolbarDependencies> SingletonUFOAIToolbarModule;
205
206 SingletonUFOAIToolbarModule g_UFOAIToolbarModule;
207
208
209 extern "C" void RADIANT_DLLEXPORT Radiant_RegisterModules( ModuleServer& server ){
210         initialiseModule( server );
211
212         g_UFOAIModule.selfRegister();
213         g_UFOAIToolbarModule.selfRegister();
214 }