]> de.git.xonotic.org Git - xonotic/netradiant.git/blob - contrib/ufoaiplug/ufoai.cpp
Merge remote-tracking branch 'ttimo/master'
[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 #define PLUGIN_VERSION "0.4"
36
37 #include "ifilter.h"
38 #include "ibrush.h"
39 #include "iundo.h"       // declaration of undo system
40 #include "ientity.h"     // declaration of entity system
41 #include "iscenegraph.h" // declaration of datastructure of the map
42 #include "scenelib.h"    // declaration of datastructure of the map
43 #include "qerplugin.h"   // declaration to use other interfaces as a plugin
44 #include "ieclass.h"
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 GtkWindow* g_mainwnd;
63
64 const char* init( void* hApp, void* pMainWidget ){
65         g_mainwnd = GTK_WINDOW( pMainWidget );
66         return "Initializing GTKRadiant UFOAI plugin";
67 }
68 const char* getName(){
69         return "UFO:AI";
70 }
71 const char* getCommandList(){
72         /*GlobalRadiant().getGameName()*/
73         return "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 *message = NULL;
80         if ( string_equal( command, "About" ) ) {
81                 GlobalRadiant().m_pfnMessageBox( GTK_WIDGET( g_mainwnd ),
82                                                                                  "UFO:AI Plugin (http://ufoai.sf.net)\nBuild: " __DATE__ "\nRadiant version: " RADIANT_VERSION "\nPlugin version: " PLUGIN_VERSION "\nAuthor: Martin Gerhardy (tlh2000/mattn)\n", "About",
83                                                                                  eMB_OK, eMB_ICONDEFAULT );
84         }
85         else if ( string_equal( command, "Level 1" ) ) {
86                 filter_level( CONTENTS_LEVEL1 );
87         }
88         else if ( string_equal( command, "Level 2" ) ) {
89                 filter_level( CONTENTS_LEVEL2 );
90         }
91         else if ( string_equal( command, "Level 3" ) ) {
92                 filter_level( CONTENTS_LEVEL3 );
93         }
94         else if ( string_equal( command, "Worldspawn" ) ) {
95                 assign_default_values_to_worldspawn( false, &message );
96         }
97         else if ( string_equal( command, "Worldspawn reset" ) ) {
98                 assign_default_values_to_worldspawn( true, &message );
99         }
100         else if ( string_equal( command, "Perform check" ) ) {
101                 check_map_values( &message );
102         }
103         else if ( string_equal( command, "Level 4" ) ) {
104                 filter_level( CONTENTS_LEVEL4 );
105         }
106         else if ( string_equal( command, "Level 5" ) ) {
107                 filter_level( CONTENTS_LEVEL5 );
108         }
109         else if ( string_equal( command, "Level 6" ) ) {
110                 filter_level( CONTENTS_LEVEL6 );
111         }
112         else if ( string_equal( command, "Level 7" ) ) {
113                 filter_level( CONTENTS_LEVEL7 );
114         }
115         else if ( string_equal( command, "Level 8" ) ) {
116                 filter_level( CONTENTS_LEVEL8 );
117         }
118         else if ( string_equal( command, "StepOn" ) ) {
119                 filter_stepon();
120         }
121         else if ( string_equal( command, "ActorClip" ) ) {
122                 filter_actorclip();
123         }
124         else if ( string_equal( command, "WeaponClip" ) ) {
125                 filter_weaponclip();
126         }
127         else if ( string_equal( command, "NoDraw" ) ) {
128                 filter_nodraw();
129         }
130
131         if ( message != NULL ) {
132                 GlobalRadiant().m_pfnMessageBox( GTK_WIDGET( g_mainwnd ),
133                                                                                  message, "Note",
134                                                                                  eMB_OK, eMB_ICONDEFAULT );
135         }
136         SceneChangeNotify();
137 }
138 } // namespace
139
140
141 class UFOAIModule : public TypeSystemRef
142 {
143 _QERPluginTable m_plugin;
144 public:
145 typedef _QERPluginTable Type;
146 STRING_CONSTANT( Name, "UFO:AI" );
147
148 UFOAIModule(){
149         m_plugin.m_pfnQERPlug_Init = &UFOAI::init;
150         m_plugin.m_pfnQERPlug_GetName = &UFOAI::getName;
151         m_plugin.m_pfnQERPlug_GetCommandList = &UFOAI::getCommandList;
152         m_plugin.m_pfnQERPlug_GetCommandTitleList = &UFOAI::getCommandTitleList;
153         m_plugin.m_pfnQERPlug_Dispatch = &UFOAI::dispatch;
154 }
155 _QERPluginTable* getTable(){
156         return &m_plugin;
157 }
158 };
159
160 typedef SingletonModule<UFOAIModule, UFOAIPluginDependencies> SingletonUFOAIModule;
161
162 SingletonUFOAIModule g_UFOAIModule;
163
164
165 class UFOAIToolbarDependencies : public ModuleRef<_QERPluginTable>
166 {
167 public:
168 UFOAIToolbarDependencies() : ModuleRef<_QERPluginTable>( "UFO:AI" ){
169 }
170 };
171
172 class UFOAIToolbarModule : public TypeSystemRef
173 {
174 _QERPlugToolbarTable m_table;
175 public:
176 typedef _QERPlugToolbarTable Type;
177 STRING_CONSTANT( Name, "UFO:AI" );
178
179 UFOAIToolbarModule(){
180         if ( !strcmp( GlobalRadiant().getGameDescriptionKeyValue( "name" ), "UFO:Alien Invasion" ) ) {
181                 m_table.m_pfnToolbarButtonCount = ToolbarButtonCount;
182                 m_table.m_pfnGetToolbarButton = GetToolbarButton;
183         }
184         else
185         {
186                 m_table.m_pfnToolbarButtonCount = ToolbarNoButtons;
187                 m_table.m_pfnGetToolbarButton = GetToolbarNoButton;
188         }
189 }
190 _QERPlugToolbarTable* getTable(){
191         return &m_table;
192 }
193 };
194
195 typedef SingletonModule<UFOAIToolbarModule, UFOAIToolbarDependencies> SingletonUFOAIToolbarModule;
196
197 SingletonUFOAIToolbarModule g_UFOAIToolbarModule;
198
199
200 extern "C" void RADIANT_DLLEXPORT Radiant_RegisterModules( ModuleServer& server ){
201         initialiseModule( server );
202
203         g_UFOAIModule.selfRegister();
204         g_UFOAIToolbarModule.selfRegister();
205 }