--- /dev/null
+/*
+This file is part of GtkRadiant.
+
+GtkRadiant is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+GtkRadiant is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GtkRadiant; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+
+#include "ufoai.h"
+#include "ufoai_level.h"
+#include "ufoai_gtk.h"
+#include "ufoai_filters.h"
+
+#include "debugging/debugging.h"
+
+#include "iplugin.h"
+
+#include "version.h"
+
+#include "string/string.h"
+#include "modulesystem/singletonmodule.h"
+
+#include <gtk/gtk.h>
+
+#define PLUGIN_VERSION "0.1"
+
+#include "ifilter.h"
+#include "ibrush.h"
+#include "iundo.h" // declaration of undo system
+#include "ientity.h" // declaration of entity system
+#include "iscenegraph.h" // declaration of datastructure of the map
+#include "scenelib.h" // declaration of datastructure of the map
+#include "qerplugin.h" // declaration to use other interfaces as a plugin
+#include "ieclass.h"
+
+class UFOAIPluginDependencies :
+ public GlobalRadiantModuleRef, // basic class for all other module refs
+ public GlobalUndoModuleRef, // used to say radiant that something has changed and to undo that
+ public GlobalSceneGraphModuleRef, // necessary to handle data in the mapfile (change, retrieve data)
+ public GlobalEntityModuleRef, // to access and modify the entities
+ public GlobalEntityClassManagerModuleRef
+{
+public:
+ UFOAIPluginDependencies(void) :
+ GlobalEntityModuleRef(GlobalRadiant().getRequiredGameDescriptionKeyValue("entities")),
+ GlobalEntityClassManagerModuleRef(GlobalRadiant().getRequiredGameDescriptionKeyValue("entityclass"))
+ {
+ }
+};
+
+namespace UFOAI
+{
+ GtkWindow* g_mainwnd;
+
+ const char* init(void* hApp, void* pMainWidget)
+ {
+ g_mainwnd = GTK_WINDOW(pMainWidget);
+ return "Initializing GTKRadiant UFOAI plugin";
+ }
+ const char* getName()
+ {
+ return "UFO:AI";
+ }
+ const char* getCommandList()
+ {
+ /*GlobalRadiant().getGameName()*/
+ return "About;-;Worldspawn reset (day);Worldspawn reset (night);Worldspawn (day);Worldspawn (night);Perform check;-;Level 1;Level 2;Level 3;Level 4;Level 5;Level 6;Level 7;Level 8;-;StepOn;ActorClip";
+ }
+ const char* getCommandTitleList()
+ {
+ return "";
+ }
+ void dispatch(const char* command, float* vMin, float* vMax, bool bSingleBrush)
+ {
+ char *message = NULL;
+ if(string_equal(command, "About"))
+ {
+ GlobalRadiant().m_pfnMessageBox(GTK_WIDGET(g_mainwnd),
+ "UFO:AI Plugin (http://www.ufoai.net)\nBuild: " __DATE__ "\nRadiant version: " RADIANT_VERSION "\nPlugin version: " PLUGIN_VERSION "\n", "About",
+ eMB_OK, eMB_ICONDEFAULT);
+ }
+ else if(string_equal(command, "Level 1"))
+ {
+ filter_level(CONTENTS_LEVEL1);
+ }
+ else if(string_equal(command, "Level 2"))
+ {
+ filter_level(CONTENTS_LEVEL2);
+ }
+ else if(string_equal(command, "Level 3"))
+ {
+ filter_level(CONTENTS_LEVEL3);
+ }
+ else if(string_equal(command, "Worldspawn (day)"))
+ {
+ assign_default_values_to_worldspawn(false, true, &message);
+ }
+ else if(string_equal(command, "Worldspawn (night)"))
+ {
+ assign_default_values_to_worldspawn(false, false, &message);
+ }
+ else if(string_equal(command, "Worldspawn reset (day)"))
+ {
+ assign_default_values_to_worldspawn(true, true, &message);
+ }
+ else if(string_equal(command, "Worldspawn reset (night)"))
+ {
+ assign_default_values_to_worldspawn(true, false, &message);
+ }
+ else if(string_equal(command, "Perform check"))
+ {
+ check_map_values(&message);
+ }
+ else if(string_equal(command, "Level 4"))
+ {
+ filter_level(CONTENTS_LEVEL4);
+ }
+ else if(string_equal(command, "Level 5"))
+ {
+ filter_level(CONTENTS_LEVEL5);
+ }
+ else if(string_equal(command, "Level 6"))
+ {
+ filter_level(CONTENTS_LEVEL6);
+ }
+ else if(string_equal(command, "Level 7"))
+ {
+ filter_level(CONTENTS_LEVEL7);
+ }
+ else if(string_equal(command, "Level 8"))
+ {
+ filter_level(CONTENTS_LEVEL8);
+ }
+ else if(string_equal(command, "StepOn"))
+ {
+ filter_stepon();
+ }
+ else if(string_equal(command, "ActorClip"))
+ {
+ filter_actorclip();
+ }
+
+ if (message != NULL)
+ {
+ GlobalRadiant().m_pfnMessageBox(GTK_WIDGET(g_mainwnd),
+ message, "Note",
+ eMB_OK, eMB_ICONDEFAULT);
+ }
+ SceneChangeNotify();
+ }
+} // namespace
+
+
+class UFOAIModule : public TypeSystemRef
+{
+ _QERPluginTable m_plugin;
+public:
+ typedef _QERPluginTable Type;
+ STRING_CONSTANT(Name, "UFO:AI");
+
+ UFOAIModule()
+ {
+ m_plugin.m_pfnQERPlug_Init = &UFOAI::init;
+ m_plugin.m_pfnQERPlug_GetName = &UFOAI::getName;
+ m_plugin.m_pfnQERPlug_GetCommandList = &UFOAI::getCommandList;
+ m_plugin.m_pfnQERPlug_GetCommandTitleList = &UFOAI::getCommandTitleList;
+ m_plugin.m_pfnQERPlug_Dispatch = &UFOAI::dispatch;
+ }
+ _QERPluginTable* getTable()
+ {
+ return &m_plugin;
+ }
+};
+
+typedef SingletonModule<UFOAIModule, UFOAIPluginDependencies> SingletonUFOAIModule;
+
+SingletonUFOAIModule g_UFOAIModule;
+
+
+class UFOAIToolbarDependencies : public ModuleRef<_QERPluginTable>
+{
+public:
+ UFOAIToolbarDependencies() : ModuleRef<_QERPluginTable>("UFO:AI")
+ {
+ }
+};
+
+class UFOAIToolbarModule : public TypeSystemRef
+{
+ _QERPlugToolbarTable m_table;
+public:
+ typedef _QERPlugToolbarTable Type;
+ STRING_CONSTANT(Name, "UFO:AI");
+
+ UFOAIToolbarModule()
+ {
+ m_table.m_pfnToolbarButtonCount = ToolbarButtonCount;
+ m_table.m_pfnGetToolbarButton = GetToolbarButton;
+ }
+ _QERPlugToolbarTable* getTable()
+ {
+ return &m_table;
+ }
+};
+
+typedef SingletonModule<UFOAIToolbarModule, UFOAIToolbarDependencies> SingletonUFOAIToolbarModule;
+
+SingletonUFOAIToolbarModule g_UFOAIToolbarModule;
+
+
+extern "C" void RADIANT_DLLEXPORT Radiant_RegisterModules(ModuleServer& server)
+{
+ initialiseModule(server);
+
+ g_UFOAIModule.selfRegister();
+ g_UFOAIToolbarModule.selfRegister();
+}
--- /dev/null
+; sample.def : Declares the module parameters for the DLL.
+
+LIBRARY "UFOAI"
+
+EXPORTS
+ ; Explicit exports can go here
+ Radiant_RegisterModules @1
--- /dev/null
+/*
+This file is part of GtkRadiant.
+
+GtkRadiant is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+GtkRadiant is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GtkRadiant; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+
+#if !defined(INCLUDED_UFOAI_H)
+#define INCLUDED_UFOAI_H
+
+#endif
--- /dev/null
+<?xml version="1.0" encoding="Windows-1252"?>\r
+<VisualStudioProject\r
+ ProjectType="Visual C++"\r
+ Version="7.10"\r
+ Name="ufoai"\r
+ ProjectGUID="{46B36F0C-5E17-458E-AE6F-AECE52F66EDE}"\r
+ Keyword="Win32Proj">\r
+ <Platforms>\r
+ <Platform\r
+ Name="Win32"/>\r
+ </Platforms>\r
+ <Configurations>\r
+ <Configuration\r
+ Name="Debug|Win32"\r
+ OutputDirectory="Debug"\r
+ IntermediateDirectory="Debug"\r
+ ConfigurationType="2"\r
+ CharacterSet="2">\r
+ <Tool\r
+ Name="VCCLCompilerTool"\r
+ Optimization="0"\r
+ AdditionalIncludeDirectories="..\..\include;..\..\libs;"..\..\..\STLPort-4.6/stlport";"..\..\..\gtk2-2.4\include\gtk-2.0";"..\..\..\gtk2-2.4\include\glib-2.0";"..\..\..\gtk2-2.4\lib\glib-2.0\include";"..\..\..\gtk2-2.4\include\pango-1.0";"..\..\..\gtk2-2.4\lib\gtk-2.0\include";"..\..\..\gtk2-2.4\include\atk-1.0""\r
+ PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;UFOAI_EXPORTS"\r
+ StringPooling="TRUE"\r
+ MinimalRebuild="TRUE"\r
+ ExceptionHandling="FALSE"\r
+ BasicRuntimeChecks="0"\r
+ RuntimeLibrary="3"\r
+ BufferSecurityCheck="FALSE"\r
+ ForceConformanceInForLoopScope="TRUE"\r
+ UsePrecompiledHeader="0"\r
+ BrowseInformation="0"\r
+ WarningLevel="3"\r
+ Detect64BitPortabilityProblems="TRUE"\r
+ DebugInformationFormat="3"\r
+ DisableSpecificWarnings="4610;4510;4512;4505;4100;4127"/>\r
+ <Tool\r
+ Name="VCCustomBuildTool"/>\r
+ <Tool\r
+ Name="VCLinkerTool"\r
+ AdditionalDependencies="gtk-win32-2.0.lib gobject-2.0.lib"\r
+ OutputFile="$(OutDir)/ufoai.dll"\r
+ LinkIncremental="1"\r
+ SuppressStartupBanner="TRUE"\r
+ AdditionalLibraryDirectories=""\r
+ IgnoreDefaultLibraryNames="msvcprtd.lib"\r
+ ModuleDefinitionFile="$(ProjectName).def"\r
+ GenerateDebugInformation="TRUE"\r
+ ProgramDatabaseFile="$(OutDir)/$(ProjectName).pdb"\r
+ SubSystem="2"\r
+ ImportLibrary="$(OutDir)/ufoai.lib"\r
+ TargetMachine="1"/>\r
+ <Tool\r
+ Name="VCMIDLTool"/>\r
+ <Tool\r
+ Name="VCPostBuildEventTool"\r
+ CommandLine="copy "$(TargetPath)" "$(SolutionDir)install\plugins""/>\r
+ <Tool\r
+ Name="VCPreBuildEventTool"/>\r
+ <Tool\r
+ Name="VCPreLinkEventTool"/>\r
+ <Tool\r
+ Name="VCResourceCompilerTool"/>\r
+ <Tool\r
+ Name="VCWebServiceProxyGeneratorTool"/>\r
+ <Tool\r
+ Name="VCXMLDataGeneratorTool"/>\r
+ <Tool\r
+ Name="VCWebDeploymentTool"/>\r
+ <Tool\r
+ Name="VCManagedWrapperGeneratorTool"/>\r
+ <Tool\r
+ Name="VCAuxiliaryManagedWrapperGeneratorTool"/>\r
+ </Configuration>\r
+ <Configuration\r
+ Name="Release|Win32"\r
+ OutputDirectory="Release"\r
+ IntermediateDirectory="Release"\r
+ ConfigurationType="2"\r
+ CharacterSet="2"\r
+ WholeProgramOptimization="TRUE">\r
+ <Tool\r
+ Name="VCCLCompilerTool"\r
+ GlobalOptimizations="TRUE"\r
+ InlineFunctionExpansion="2"\r
+ EnableIntrinsicFunctions="TRUE"\r
+ FavorSizeOrSpeed="1"\r
+ OptimizeForWindowsApplication="FALSE"\r
+ AdditionalIncludeDirectories="..\..\include;..\..\libs;"..\..\..\STLPort-4.6/stlport";"..\..\..\gtk2-2.4\include\gtk-2.0";"..\..\..\gtk2-2.4\include\glib-2.0";"..\..\..\gtk2-2.4\lib\glib-2.0\include";"..\..\..\gtk2-2.4\include\pango-1.0";"..\..\..\gtk2-2.4\lib\gtk-2.0\include";"..\..\..\gtk2-2.4\include\atk-1.0""\r
+ PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;UFOAI_EXPORTS"\r
+ StringPooling="TRUE"\r
+ ExceptionHandling="FALSE"\r
+ RuntimeLibrary="2"\r
+ BufferSecurityCheck="FALSE"\r
+ ForceConformanceInForLoopScope="TRUE"\r
+ UsePrecompiledHeader="0"\r
+ WarningLevel="4"\r
+ Detect64BitPortabilityProblems="TRUE"\r
+ DebugInformationFormat="3"\r
+ DisableSpecificWarnings="4610;4510;4512;4505;4100;4127"/>\r
+ <Tool\r
+ Name="VCCustomBuildTool"/>\r
+ <Tool\r
+ Name="VCLinkerTool"\r
+ AdditionalDependencies="gtk-win32-2.0.lib gobject-2.0.lib"\r
+ OutputFile="$(OutDir)/ufoai.dll"\r
+ LinkIncremental="1"\r
+ SuppressStartupBanner="TRUE"\r
+ AdditionalLibraryDirectories=""\r
+ IgnoreDefaultLibraryNames="msvcprt.lib"\r
+ ModuleDefinitionFile="$(ProjectName).def"\r
+ GenerateDebugInformation="TRUE"\r
+ ProgramDatabaseFile="$(OutDir)/$(ProjectName).pdb"\r
+ SubSystem="2"\r
+ OptimizeReferences="2"\r
+ EnableCOMDATFolding="2"\r
+ ImportLibrary="$(OutDir)/ufoai.lib"\r
+ TargetMachine="1"\r
+ FixedBaseAddress="0"/>\r
+ <Tool\r
+ Name="VCMIDLTool"/>\r
+ <Tool\r
+ Name="VCPostBuildEventTool"\r
+ CommandLine="copy "$(TargetPath)" "$(SolutionDir)install\plugins""/>\r
+ <Tool\r
+ Name="VCPreBuildEventTool"/>\r
+ <Tool\r
+ Name="VCPreLinkEventTool"/>\r
+ <Tool\r
+ Name="VCResourceCompilerTool"/>\r
+ <Tool\r
+ Name="VCWebServiceProxyGeneratorTool"/>\r
+ <Tool\r
+ Name="VCXMLDataGeneratorTool"/>\r
+ <Tool\r
+ Name="VCWebDeploymentTool"/>\r
+ <Tool\r
+ Name="VCManagedWrapperGeneratorTool"/>\r
+ <Tool\r
+ Name="VCAuxiliaryManagedWrapperGeneratorTool"/>\r
+ </Configuration>\r
+ </Configurations>\r
+ <References>\r
+ </References>\r
+ <Files>\r
+ <Filter\r
+ Name="src"\r
+ Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx"\r
+ UniqueIdentifier="{22F2852C-8177-45D5-94D0-C5255C199F7F}">\r
+ <File\r
+ RelativePath=".\ufoai.cpp">\r
+ </File>\r
+ <File\r
+ RelativePath=".\ufoai.h">\r
+ </File>\r
+ <File\r
+ RelativePath=".\ufoai_filters.cpp">\r
+ </File>\r
+ <File\r
+ RelativePath=".\ufoai_filters.h">\r
+ </File>\r
+ <File\r
+ RelativePath=".\ufoai_gtk.cpp">\r
+ </File>\r
+ <File\r
+ RelativePath=".\ufoai_gtk.h">\r
+ </File>\r
+ <File\r
+ RelativePath=".\ufoai_level.cpp">\r
+ </File>\r
+ <File\r
+ RelativePath=".\ufoai_level.h">\r
+ </File>\r
+ </Filter>\r
+ <File\r
+ RelativePath=".\ufoai.def">\r
+ <FileConfiguration\r
+ Name="Debug|Win32">\r
+ <Tool\r
+ Name="VCCustomBuildTool"\r
+ CommandLine="python "$(SolutionDir)touch.py" "$(TargetPath)"\r
+"\r
+ AdditionalDependencies=""$(SolutionDir)install\plugins\$(TargetFileName)""\r
+ Outputs=""$(TargetPath)""/>\r
+ </FileConfiguration>\r
+ <FileConfiguration\r
+ Name="Release|Win32">\r
+ <Tool\r
+ Name="VCCustomBuildTool"\r
+ CommandLine="python "$(SolutionDir)touch.py" "$(TargetPath)"\r
+"\r
+ AdditionalDependencies=""$(SolutionDir)install\plugins\$(TargetFileName)""\r
+ Outputs=""$(TargetPath)""/>\r
+ </FileConfiguration>\r
+ </File>\r
+ </Files>\r
+ <Globals>\r
+ </Globals>\r
+</VisualStudioProject>\r
--- /dev/null
+/*
+This file is part of GtkRadiant.
+
+GtkRadiant is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+GtkRadiant is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GtkRadiant; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+
+#include "ufoai_filters.h"
+
+#include "ibrush.h"
+#include "ientity.h"
+#include "iscenegraph.h"
+
+// believe me, i'm sorry
+#include "../../radiant/brush.h"
+
+#include "generic/callback.h"
+
+#include <list>
+
+bool actorclip_active = false;
+bool stepon_active = false;
+int level_active = 0;
+
+// TODO: This should be added to ibrush.h
+// like already done for Node_getEntity in ientity.h
+// FIXME: Doesn't belong here
+inline Brush* Node_getBrush(scene::Node& node)
+{
+ return NodeTypeCast<Brush>::cast(node);
+}
+
+void hide_node(scene::Node& node, bool hide)
+{
+ hide
+ ? node.enable(scene::Node::eHidden)
+ : node.disable(scene::Node::eHidden);
+}
+
+typedef std::list<Entity*> entitylist_t;
+
+class EntityFindByName : public scene::Graph::Walker
+{
+ const char* m_name;
+ entitylist_t& m_entitylist;
+ /* this starts at 1 << level */
+ int m_flag;
+ int m_hide;
+public:
+ EntityFindByName(const char* name, entitylist_t& entitylist, int flag, bool hide)
+ : m_name(name), m_entitylist(entitylist), m_flag(flag), m_hide(hide)
+ {
+ }
+ bool pre(const scene::Path& path, scene::Instance& instance) const
+ {
+ int spawnflagsInt;
+ Entity* entity = Node_getEntity(path.top());
+ if (entity != 0)
+ {
+ if (string_equal(m_name, entity->getKeyValue("classname")))
+ {
+ const char *spawnflags = entity->getKeyValue("spawnflags");
+ globalOutputStream() << "spawnflags for " << m_name << ": " << spawnflags << ".\n";
+
+ if (!string_empty(spawnflags)) {
+ spawnflagsInt = atoi(spawnflags);
+ if (!(spawnflagsInt & m_flag))
+ {
+ hide_node(path.top(), m_hide); // hide/unhide
+ m_entitylist.push_back(entity);
+ }
+ }
+ else
+ {
+ globalOutputStream() << "UFO:AI: Warning: no spawnflags for " << m_name << ".\n";
+ }
+ }
+ }
+ return true;
+ }
+};
+
+class ForEachFace : public BrushVisitor
+{
+ Brush &m_brush;
+public:
+ mutable int m_contentFlagsVis;
+ mutable int m_surfaceFlagsVis;
+
+ ForEachFace(Brush& brush)
+ : m_brush(brush)
+ {
+ m_contentFlagsVis = -1;
+ m_surfaceFlagsVis = -1;
+ }
+
+ void visit(Face& face) const
+ {
+#if _DEBUG
+ if (m_surfaceFlagsVis < 0)
+ m_surfaceFlagsVis = face.getShader().m_flags.m_surfaceFlags;
+ else if (m_surfaceFlagsVis >= 0 && m_surfaceFlagsVis != face.getShader().m_flags.m_surfaceFlags)
+ globalOutputStream() << "Faces with different surfaceflags at brush\n";
+ if (m_contentFlagsVis < 0)
+ m_contentFlagsVis = face.getShader().m_flags.m_contentFlags;
+ else if (m_contentFlagsVis >= 0 && m_contentFlagsVis != face.getShader().m_flags.m_contentFlags)
+ globalOutputStream() << "Faces with different contentflags at brush\n";
+#else
+ m_surfaceFlagsVis = face.getShader().m_flags.m_surfaceFlags;
+ m_contentFlagsVis = face.getShader().m_flags.m_contentFlags;
+#endif
+ }
+};
+
+typedef std::list<Brush*> brushlist_t;
+
+class BrushGetLevel : public scene::Graph::Walker
+{
+ brushlist_t& m_brushlist;
+ int m_flag;
+ bool m_content; // if true - use m_contentFlags - otherwise m_surfaceFlags
+ mutable bool m_notset;
+ mutable bool m_hide;
+public:
+ BrushGetLevel(brushlist_t& brushlist, int flag, bool content, bool notset, bool hide)
+ : m_brushlist(brushlist), m_flag(flag), m_content(content), m_notset(notset), m_hide(hide)
+ {
+ }
+ bool pre(const scene::Path& path, scene::Instance& instance) const
+ {
+ Brush* brush = Node_getBrush(path.top());
+ if (brush != 0)
+ {
+ ForEachFace faces(*brush);
+ brush->forEachFace(faces);
+ // contentflags?
+ if (m_content)
+ {
+ // are any flags set?
+ if (faces.m_contentFlagsVis > 0)
+ {
+ // flag should not be set
+ if (m_notset && (!(faces.m_contentFlagsVis & m_flag)))
+ {
+ hide_node(path.top(), m_hide);
+ m_brushlist.push_back(brush);
+ }
+ // check whether flag is set
+ else if (!m_notset && ((faces.m_contentFlagsVis & m_flag)))
+ {
+ hide_node(path.top(), m_hide);
+ m_brushlist.push_back(brush);
+ }
+ }
+ }
+ // surfaceflags?
+ else
+ {
+ // are any flags set?
+ if (faces.m_surfaceFlagsVis > 0)
+ {
+ // flag should not be set
+ if (m_notset && (!(faces.m_surfaceFlagsVis & m_flag)))
+ {
+ hide_node(path.top(), m_hide);
+ m_brushlist.push_back(brush);
+ }
+ // check whether flag is set
+ else if (!m_notset && ((faces.m_surfaceFlagsVis & m_flag)))
+ {
+ hide_node(path.top(), m_hide);
+ m_brushlist.push_back(brush);
+ }
+ }
+ }
+
+ }
+ return true;
+ }
+};
+
+/**
+ * @brief Activates the level filter for the given level
+ * @param[in] level Which level to show?
+ * @todo Entities
+ */
+void filter_level(int flag)
+{
+ int level;
+ brushlist_t brushes;
+ entitylist_t entities;
+
+ level = (flag >> 8);
+
+ if (level_active)
+ {
+ GlobalSceneGraph().traverse(BrushGetLevel(brushes, (level_active << 8), true, true, false));
+ GlobalSceneGraph().traverse(EntityFindByName("func_breakable", entities, level_active, false));
+ GlobalSceneGraph().traverse(EntityFindByName("misc_model", entities, level_active, false));
+ entities.erase(entities.begin(), entities.end());
+ brushes.erase(brushes.begin(), brushes.end());
+ if (level_active == level)
+ {
+ level_active = 0;
+ // just disabĺe level filter
+ return;
+ }
+ }
+ level_active = level;
+ globalOutputStream() << "UFO:AI: level_active: " << level_active << ", flag: " << flag << ".\n";
+
+ // first all brushes
+ GlobalSceneGraph().traverse(BrushGetLevel(brushes, flag, true, true, true));
+
+ // now all entities
+ GlobalSceneGraph().traverse(EntityFindByName("func_breakable", entities, level, true));
+ GlobalSceneGraph().traverse(EntityFindByName("misc_model", entities, level, true));
+
+#ifdef _DEBUG
+ if (brushes.empty())
+ {
+ globalOutputStream() << "UFO:AI: No brushes.\n";
+ }
+ else
+ {
+ globalOutputStream() << "UFO:AI: Found " << Unsigned(brushes.size()) << " brushes.\n";
+ }
+
+ // now let's filter all entities like misc_model and func_breakable that have the spawnflags set
+ if (entities.empty())
+ {
+ globalOutputStream() << "UFO:AI: No entities.\n";
+ }
+ else
+ {
+ globalOutputStream() << "UFO:AI: Found " << Unsigned(entities.size()) << " entities.\n";
+ }
+#endif
+}
+
+void filter_stepon (void)
+{
+ if (stepon_active) {
+ stepon_active = false;
+ } else {
+ stepon_active = true;
+ }
+ brushlist_t brushes;
+ GlobalSceneGraph().traverse(BrushGetLevel(brushes, CONTENTS_STEPON, true, false, stepon_active));
+
+ if (brushes.empty())
+ {
+ globalOutputStream() << "UFO:AI: No brushes.\n";
+ }
+ else
+ {
+ globalOutputStream() << "UFO:AI: Hiding " << Unsigned(brushes.size()) << " stepon brushes.\n";
+ }
+}
+
+void filter_actorclip (void)
+{
+ if (actorclip_active) {
+ actorclip_active = false;
+ } else {
+ actorclip_active = true;
+ }
+ brushlist_t brushes;
+ GlobalSceneGraph().traverse(BrushGetLevel(brushes, CONTENTS_ACTORCLIP, true, false, actorclip_active));
+
+#ifdef _DEBUG
+ if (brushes.empty())
+ {
+ globalOutputStream() << "UFO:AI: No brushes.\n";
+ }
+ else
+ {
+ globalOutputStream() << "UFO:AI: Hiding " << Unsigned(brushes.size()) << " actorclip brushes.\n";
+ }
+#endif
+}
--- /dev/null
+/*
+This file is part of GtkRadiant.
+
+GtkRadiant is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+GtkRadiant is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GtkRadiant; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+
+#if !defined(INCLUDED_FILTERS_H)
+#define INCLUDED_FILTERS_H
+
+void filter_level(int flag);
+void filter_stepon(void);
+void filter_actorclip(void);
+
+#define CONTENTS_LEVEL8 0x8000
+#define CONTENTS_LEVEL7 0x4000
+#define CONTENTS_LEVEL6 0x2000
+#define CONTENTS_LEVEL5 0x1000
+#define CONTENTS_LEVEL4 0x0800
+#define CONTENTS_LEVEL3 0x0400
+#define CONTENTS_LEVEL2 0x0200
+#define CONTENTS_LEVEL1 0x0100
+#define CONTENTS_ACTORCLIP 0x10000
+
+#define CONTENTS_STEPON 0x40000000
+
+#endif
--- /dev/null
+/*
+This file is part of GtkRadiant.
+
+GtkRadiant is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+GtkRadiant is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GtkRadiant; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+
+#include "ufoai_gtk.h"
+#include "ufoai_filters.h"
+
+#include "itoolbar.h"
+#include "iscenegraph.h"
+
+#include <gtk/gtk.h>
+
+/**
+ * GTK callback functions
+ */
+
+class UFOAIGtk
+{
+ GtkWindow* m_gtk_window;
+public:
+ UFOAIGtk(void* gtk_window) : m_gtk_window((GtkWindow*)gtk_window)
+ {
+ }
+};
+
+/**
+ * @brief If you return FALSE in the "delete_event" signal handler,
+ * GTK will emit the "destroy" signal. Returning TRUE means
+ * you don't want the window to be destroyed.
+ * This is useful for popping up 'are you sure you want to quit?'
+ * type dialogs.
+ */
+static gboolean delete_event(GtkWidget *widget, GdkEvent *event, gpointer data)
+{
+ return FALSE;
+}
+
+/**
+ * @brief destroy widget if destroy signal is passed to widget
+ */
+static void destroy(GtkWidget *widget, gpointer data)
+{
+ gtk_widget_destroy(widget);
+}
+
+/**
+ * @brief function for close button to destroy the toplevel widget
+ */
+static void close_window(GtkWidget *widget, gpointer data)
+{
+ gtk_widget_destroy(gtk_widget_get_toplevel(widget));
+}
+
+/* =============================== */
+
+#define NUM_TOOLBARBUTTONS 10
+
+/**
+ * @brief
+ */
+std::size_t ToolbarButtonCount(void)
+{
+ return NUM_TOOLBARBUTTONS;
+}
+
+/**
+ * @brief
+ */
+class CUFOAIToolbarButton : public IToolbarButton
+{
+public:
+ virtual const char* getImage() const
+ {
+ switch( mIndex )
+ {
+ case 0: return "ufoai_level1.bmp";
+ case 1: return "ufoai_level2.bmp";
+ case 2: return "ufoai_level3.bmp";
+ case 3: return "ufoai_level4.bmp";
+ case 4: return "ufoai_level5.bmp";
+ case 5: return "ufoai_level6.bmp";
+ case 6: return "ufoai_level7.bmp";
+ case 7: return "ufoai_level8.bmp";
+ case 8: return "ufoai_stepon.bmp";
+ case 9: return "ufoai_actorclip.bmp";
+ }
+ return NULL;
+ }
+ virtual EType getType() const
+ {
+ switch( mIndex )
+ {
+/* case 3: return eButton;*/
+ case 8: return eToggleButton;
+ case 9: return eToggleButton;
+ default: return eButton;
+ }
+ }
+ virtual const char* getText() const
+ {
+ switch( mIndex )
+ {
+ case 0: return "Level 1";
+ case 1: return "Level 2";
+ case 2: return "Level 3";
+ case 3: return "Level 4";
+ case 4: return "Level 5";
+ case 5: return "Level 6";
+ case 6: return "Level 7";
+ case 7: return "Level 8";
+ case 8: return "Stepon";
+ case 9: return "Actorclip";
+ }
+ return NULL;
+ }
+ virtual const char* getTooltip() const
+ {
+ switch( mIndex )
+ {
+ case 0: return "Show only level 1";
+ case 1: return "Show only level 2";
+ case 2: return "Show only level 3";
+ case 3: return "Show only level 4";
+ case 4: return "Show only level 5";
+ case 5: return "Show only level 6";
+ case 6: return "Show only level 7";
+ case 7: return "Show only level 8";
+ case 8: return "Hide stepon brushes";
+ case 9: return "Hide actorclip brushes";
+ }
+ return NULL;
+ }
+
+ virtual void activate() const
+ {
+ switch( mIndex )
+ {
+ case 0: filter_level(CONTENTS_LEVEL1); break;
+ case 1: filter_level(CONTENTS_LEVEL2); break;
+ case 2: filter_level(CONTENTS_LEVEL3); break;
+ case 3: filter_level(CONTENTS_LEVEL4); break;
+ case 4: filter_level(CONTENTS_LEVEL5); break;
+ case 5: filter_level(CONTENTS_LEVEL6); break;
+ case 6: filter_level(CONTENTS_LEVEL7); break;
+ case 7: filter_level(CONTENTS_LEVEL8); break;
+ case 8: filter_stepon(); break;
+ case 9: filter_actorclip(); break;
+ }
+ SceneChangeNotify();
+ }
+
+ std::size_t mIndex;
+};
+
+/**
+ * @brief
+ */
+CUFOAIToolbarButton g_ufoaiToolbarButtons[NUM_TOOLBARBUTTONS];
+
+/**
+ * @brief
+ */
+const IToolbarButton* GetToolbarButton(std::size_t index)
+{
+ g_ufoaiToolbarButtons[index].mIndex = index;
+ return &g_ufoaiToolbarButtons[index];
+}
--- /dev/null
+/*
+This file is part of GtkRadiant.
+
+GtkRadiant is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+GtkRadiant is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GtkRadiant; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+
+#if !defined(INCLUDED_UFOAI_GTK_H)
+#define INCLUDED_UFOAI_GTK_H
+
+#include "itoolbar.h"
+#include <gtk/gtk.h>
+
+const IToolbarButton* GetToolbarButton(std::size_t index);
+std::size_t ToolbarButtonCount(void);
+
+#endif
--- /dev/null
+/*
+This file is part of GtkRadiant.
+
+GtkRadiant is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+GtkRadiant is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GtkRadiant; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+
+#include "ufoai_level.h"
+#include "ufoai_filters.h"
+
+#include "ibrush.h"
+#include "ientity.h"
+#include "iscenegraph.h"
+
+#include "string/string.h"
+#include <list>
+
+class Level;
+
+/**
+ * @brief find entities by class
+ * @note from radiant/map.cpp
+ */
+class EntityFindByClassname : public scene::Graph::Walker
+{
+ const char* m_name;
+ Entity*& m_entity;
+public:
+ EntityFindByClassname(const char* name, Entity*& entity) : m_name(name), m_entity(entity)
+ {
+ m_entity = 0;
+ }
+ bool pre(const scene::Path& path, scene::Instance& instance) const
+ {
+ if(m_entity == 0)
+ {
+ Entity* entity = Node_getEntity(path.top());
+ if(entity != 0 && string_equal(m_name, entity->getKeyValue("classname")))
+ {
+ m_entity = entity;
+ }
+ }
+ return true;
+ }
+};
+
+/**
+ * @brief
+ */
+Entity* Scene_FindEntityByClass(const char* name)
+{
+ Entity* entity = NULL;
+ GlobalSceneGraph().traverse(EntityFindByClassname(name, entity));
+ return entity;
+}
+
+/**
+ * @brief finds start positions
+ */
+class EntityFindTeams : public scene::Graph::Walker
+{
+ const char *m_classname;
+ int *m_count;
+ int *m_team;
+
+public:
+ EntityFindTeams(const char *classname, int *count, int *team) : m_classname(classname), m_count(count), m_team(team)
+ {
+ }
+ bool pre(const scene::Path& path, scene::Instance& instance) const
+ {
+ const char *str;
+ Entity* entity = Node_getEntity(path.top());
+ if(entity != 0 && string_equal(m_classname, entity->getKeyValue("classname")))
+ {
+ if (m_count)
+ (*m_count)++;
+ // now get the highest teamnum
+ if (m_team)
+ {
+ str = entity->getKeyValue("team");
+ if (!string_empty(str))
+ {
+ if (atoi(str) > *m_team)
+ (*m_team) = atoi(str);
+ }
+ }
+ }
+ return true;
+ }
+};
+
+/**
+ * @brief
+ */
+void get_team_count (const char *classname, int *count, int *team)
+{
+ GlobalSceneGraph().traverse(EntityFindTeams(classname, count, team));
+ globalOutputStream() << "UFO:AI: classname: " << classname << ": #" << (*count) << "\n";
+}
+
+/**
+ * @brief Some default values to worldspawn like maxlevel, maxteams and so on
+ */
+void assign_default_values_to_worldspawn (bool override, bool day, char **returnMsg)
+{
+ static char message[1024];
+ Entity* worldspawn;
+ int teams = 0;
+ int count = 0;
+ char str[64];
+
+ worldspawn = Scene_FindEntityByClass("worldspawn");
+ if (!worldspawn)
+ {
+ globalOutputStream() << "UFO:AI: Could not find worldspawn.\n";
+ *returnMsg = "Could not find worldspawn";
+ return;
+ }
+
+ *message = '\0';
+ *str = '\0';
+
+ get_team_count("info_player_start", &count, &teams);
+
+ // TODO: Get highest brush - a level has 64 units
+ worldspawn->setKeyValue("maxlevel", "5");
+
+ if (string_empty(worldspawn->getKeyValue("maxteams"))
+ || atoi(worldspawn->getKeyValue("maxteams")) != teams)
+ {
+ snprintf(str, sizeof(str) - 1, "%i", teams);
+ worldspawn->setKeyValue("maxteams", str);
+ strncat(message, "Worldspawn: Set maxteams to ", sizeof(message) - 1);
+ strncat(message, str, sizeof(message) - 1);
+ strncat(message, "\n", sizeof(message) - 1);
+ }
+
+ if (day)
+ {
+ if (override)
+ {
+ worldspawn->setKeyValue("light", "160");
+ worldspawn->setKeyValue("_color", "1 0.8 0.8");
+ worldspawn->setKeyValue("angles", "30 210");
+ worldspawn->setKeyValue("ambient", "0.4 0.4 0.4");
+ }
+ else
+ {
+ if (string_empty(worldspawn->getKeyValue("light")))
+ {
+ worldspawn->setKeyValue("light", "160");
+ snprintf(&message[strlen(message)], sizeof(message) - 1 - strlen(message), "Set ambient to: %s", worldspawn->getKeyValue("ambient"));
+ }
+ if (string_empty(worldspawn->getKeyValue("_color")))
+ {
+ worldspawn->setKeyValue("_color", "1 0.8 0.8");
+ snprintf(&message[strlen(message)], sizeof(message) - 1 - strlen(message), "Set ambient to: %s", worldspawn->getKeyValue("ambient"));
+ }
+ if (string_empty(worldspawn->getKeyValue("angles")))
+ {
+ worldspawn->setKeyValue("angles", "30 210");
+ snprintf(&message[strlen(message)], sizeof(message) - 1 - strlen(message), "Set ambient to: %s", worldspawn->getKeyValue("ambient"));
+ }
+ if (string_empty(worldspawn->getKeyValue("ambient")))
+ {
+ worldspawn->setKeyValue("ambient", "0.4 0.4 0.4");
+ snprintf(&message[strlen(message)], sizeof(message) - 1 - strlen(message), "Set ambient to: %s", worldspawn->getKeyValue("ambient"));
+ }
+ }
+ }
+ else
+ {
+ if (override)
+ {
+ worldspawn->setKeyValue("light", "60");
+ worldspawn->setKeyValue("_color", "0.8 0.8 1");
+ worldspawn->setKeyValue("angles", "15 60");
+ worldspawn->setKeyValue("ambient", "0.25 0.25 0.275");
+ }
+ else
+ {
+ if (string_empty(worldspawn->getKeyValue("light")))
+ {
+ worldspawn->setKeyValue("light", "60");
+ snprintf(&message[strlen(message)], sizeof(message) - 1 - strlen(message), "Set ambient to: %s", worldspawn->getKeyValue("ambient"));
+ }
+ if (string_empty(worldspawn->getKeyValue("_color")))
+ {
+ worldspawn->setKeyValue("_color", "0.8 0.8 1");
+ snprintf(&message[strlen(message)], sizeof(message) - 1 - strlen(message), "Set ambient to: %s", worldspawn->getKeyValue("ambient"));
+ }
+ if (string_empty(worldspawn->getKeyValue("angles")))
+ {
+ worldspawn->setKeyValue("angles", "15 60");
+ snprintf(&message[strlen(message)], sizeof(message) - 1 - strlen(message), "Set ambient to: %s", worldspawn->getKeyValue("ambient"));
+ }
+ if (string_empty(worldspawn->getKeyValue("ambient")))
+ {
+ worldspawn->setKeyValue("ambient", "0.25 0.25 0.275");
+ snprintf(&message[strlen(message)], sizeof(message) - 1 - strlen(message), "Set ambient to: %s", worldspawn->getKeyValue("ambient"));
+ }
+ }
+ }
+
+ if (override)
+ {
+ snprintf(&message[strlen(message)], sizeof(message) - 1 - strlen(message),
+ "Set light to: %s\n"
+ "Set _color to: %s\n"
+ "Set angles to: %s\n"
+ "Set ambient to: %s\n",
+ worldspawn->getKeyValue("light"),
+ worldspawn->getKeyValue("_color"),
+ worldspawn->getKeyValue("angles"),
+ worldspawn->getKeyValue("ambient")
+ );
+ }
+
+ // no errors - no warnings
+ if (!strlen(message))
+ return;
+
+ *returnMsg = message;
+}
+
+/**
+ * @brief Will check e.g. the map entities for valid values
+ * @todo: Check whether all misc_model and func_breakable have spawnflags
+ * @todo: check for maxlevel
+ */
+void check_map_values (char **returnMsg)
+{
+ static char message[1024];
+ int count = 0;
+ int teams = 0;
+ Entity* worldspawn;
+ char str[64];
+
+ worldspawn = Scene_FindEntityByClass("worldspawn");
+ if (!worldspawn)
+ {
+ globalOutputStream() << "UFO:AI: Could not find worldspawn.\n";
+ *returnMsg = "Could not find worldspawn";
+ return;
+ }
+
+ *message = '\0';
+ *str = '\0';
+
+ // multiplayer start positions
+ get_team_count("info_player_start", &count, &teams);
+ if (!count)
+ strncat(message, "No multiplayer start positions (info_player_start)\n", sizeof(message) - 1);
+ else if (string_empty(worldspawn->getKeyValue("maxteams")))
+ {
+ snprintf(message, sizeof(message) - 1, "Worldspawn: No maxteams defined (#info_player_start) (set to: %i)\n", teams);
+ snprintf(str, sizeof(str) - 1, "%i", teams);
+ worldspawn->setKeyValue("maxteams", str);
+ }
+ else if (teams != atoi(worldspawn->getKeyValue("maxteams")))
+ snprintf(message, sizeof(message) - 1, "Worldspawn: Settings for maxteams (%s) doesn't match team count (%i)\n", worldspawn->getKeyValue("maxteams"), teams);
+
+ // singleplayer map?
+ count = 0;
+ get_team_count("info_human_start", &count, NULL);
+ if (!count)
+ strncat(message, "No singleplayer start positions (info_human_start)\n", sizeof(message) - 1);
+
+ // search for civilians
+ count = 0;
+ get_team_count("info_civilian_start", &count, NULL);
+ if (!count)
+ strncat(message, "No civilian start positions (info_civilian_start)\n", sizeof(message) - 1);
+
+ // check maxlevel
+ if (string_empty(worldspawn->getKeyValue("maxlevel")))
+ strncat(message, "Worldspawn: No maxlevel defined\n", sizeof(message) - 1);
+ else if (atoi(worldspawn->getKeyValue("maxlevel")) > 8)
+ {
+ strncat(message, "Worldspawn: Highest maxlevel is 8\n", sizeof(message) - 1);
+ worldspawn->setKeyValue("maxlevel", "8");
+ }
+ // no errors - no warnings
+ if (!strlen(message))
+ return;
+
+ *returnMsg = message;
+}
--- /dev/null
+/*
+This file is part of GtkRadiant.
+
+GtkRadiant is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+GtkRadiant is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GtkRadiant; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+
+#if !defined(INCLUDED_UFOAI_LEVEL_H)
+#define INCLUDED_UFOAI_LEVEL_H
+
+void assign_default_values_to_worldspawn (bool override, bool day, char **returnMsg);
+void check_map_values (char **returnMsg);
+void get_team_count (const char *classname, int *count, int *team);
+
+#endif