git-svn-id: svn://svn.icculus.org/gtkradiant/GtkRadiant/trunk@132 8a3a26a2-13c4-0310-b231-cf6edde360e5
This commit is contained in:
namespace 2007-01-05 22:00:16 +00:00
parent 211ab65196
commit 854c35ae49
20 changed files with 1320 additions and 0 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 774 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 198 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 198 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 198 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 198 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 198 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 198 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 198 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 198 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 774 B

227
contrib/ufoai/ufoai.cpp Normal file
View file

@ -0,0 +1,227 @@
/*
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();
}

7
contrib/ufoai/ufoai.def Normal file
View file

@ -0,0 +1,7 @@
; sample.def : Declares the module parameters for the DLL.
LIBRARY "UFOAI"
EXPORTS
; Explicit exports can go here
Radiant_RegisterModules @1

22
contrib/ufoai/ufoai.h Normal file
View file

@ -0,0 +1,22 @@
/*
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

199
contrib/ufoai/ufoai.vcproj Normal file
View file

@ -0,0 +1,199 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="7.10"
Name="ufoai"
ProjectGUID="{46B36F0C-5E17-458E-AE6F-AECE52F66EDE}"
Keyword="Win32Proj">
<Platforms>
<Platform
Name="Win32"/>
</Platforms>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="Debug"
IntermediateDirectory="Debug"
ConfigurationType="2"
CharacterSet="2">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="..\..\include;..\..\libs;&quot;..\..\..\STLPort-4.6/stlport&quot;;&quot;..\..\..\gtk2-2.4\include\gtk-2.0&quot;;&quot;..\..\..\gtk2-2.4\include\glib-2.0&quot;;&quot;..\..\..\gtk2-2.4\lib\glib-2.0\include&quot;;&quot;..\..\..\gtk2-2.4\include\pango-1.0&quot;;&quot;..\..\..\gtk2-2.4\lib\gtk-2.0\include&quot;;&quot;..\..\..\gtk2-2.4\include\atk-1.0&quot;"
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;UFOAI_EXPORTS"
StringPooling="TRUE"
MinimalRebuild="TRUE"
ExceptionHandling="FALSE"
BasicRuntimeChecks="0"
RuntimeLibrary="3"
BufferSecurityCheck="FALSE"
ForceConformanceInForLoopScope="TRUE"
UsePrecompiledHeader="0"
BrowseInformation="0"
WarningLevel="3"
Detect64BitPortabilityProblems="TRUE"
DebugInformationFormat="3"
DisableSpecificWarnings="4610;4510;4512;4505;4100;4127"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="gtk-win32-2.0.lib gobject-2.0.lib"
OutputFile="$(OutDir)/ufoai.dll"
LinkIncremental="1"
SuppressStartupBanner="TRUE"
AdditionalLibraryDirectories=""
IgnoreDefaultLibraryNames="msvcprtd.lib"
ModuleDefinitionFile="$(ProjectName).def"
GenerateDebugInformation="TRUE"
ProgramDatabaseFile="$(OutDir)/$(ProjectName).pdb"
SubSystem="2"
ImportLibrary="$(OutDir)/ufoai.lib"
TargetMachine="1"/>
<Tool
Name="VCMIDLTool"/>
<Tool
Name="VCPostBuildEventTool"
CommandLine="copy &quot;$(TargetPath)&quot; &quot;$(SolutionDir)install\plugins&quot;"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCXMLDataGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
<Tool
Name="VCManagedWrapperGeneratorTool"/>
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="Release"
IntermediateDirectory="Release"
ConfigurationType="2"
CharacterSet="2"
WholeProgramOptimization="TRUE">
<Tool
Name="VCCLCompilerTool"
GlobalOptimizations="TRUE"
InlineFunctionExpansion="2"
EnableIntrinsicFunctions="TRUE"
FavorSizeOrSpeed="1"
OptimizeForWindowsApplication="FALSE"
AdditionalIncludeDirectories="..\..\include;..\..\libs;&quot;..\..\..\STLPort-4.6/stlport&quot;;&quot;..\..\..\gtk2-2.4\include\gtk-2.0&quot;;&quot;..\..\..\gtk2-2.4\include\glib-2.0&quot;;&quot;..\..\..\gtk2-2.4\lib\glib-2.0\include&quot;;&quot;..\..\..\gtk2-2.4\include\pango-1.0&quot;;&quot;..\..\..\gtk2-2.4\lib\gtk-2.0\include&quot;;&quot;..\..\..\gtk2-2.4\include\atk-1.0&quot;"
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;UFOAI_EXPORTS"
StringPooling="TRUE"
ExceptionHandling="FALSE"
RuntimeLibrary="2"
BufferSecurityCheck="FALSE"
ForceConformanceInForLoopScope="TRUE"
UsePrecompiledHeader="0"
WarningLevel="4"
Detect64BitPortabilityProblems="TRUE"
DebugInformationFormat="3"
DisableSpecificWarnings="4610;4510;4512;4505;4100;4127"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="gtk-win32-2.0.lib gobject-2.0.lib"
OutputFile="$(OutDir)/ufoai.dll"
LinkIncremental="1"
SuppressStartupBanner="TRUE"
AdditionalLibraryDirectories=""
IgnoreDefaultLibraryNames="msvcprt.lib"
ModuleDefinitionFile="$(ProjectName).def"
GenerateDebugInformation="TRUE"
ProgramDatabaseFile="$(OutDir)/$(ProjectName).pdb"
SubSystem="2"
OptimizeReferences="2"
EnableCOMDATFolding="2"
ImportLibrary="$(OutDir)/ufoai.lib"
TargetMachine="1"
FixedBaseAddress="0"/>
<Tool
Name="VCMIDLTool"/>
<Tool
Name="VCPostBuildEventTool"
CommandLine="copy &quot;$(TargetPath)&quot; &quot;$(SolutionDir)install\plugins&quot;"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCXMLDataGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
<Tool
Name="VCManagedWrapperGeneratorTool"/>
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="src"
Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx"
UniqueIdentifier="{22F2852C-8177-45D5-94D0-C5255C199F7F}">
<File
RelativePath=".\ufoai.cpp">
</File>
<File
RelativePath=".\ufoai.h">
</File>
<File
RelativePath=".\ufoai_filters.cpp">
</File>
<File
RelativePath=".\ufoai_filters.h">
</File>
<File
RelativePath=".\ufoai_gtk.cpp">
</File>
<File
RelativePath=".\ufoai_gtk.h">
</File>
<File
RelativePath=".\ufoai_level.cpp">
</File>
<File
RelativePath=".\ufoai_level.h">
</File>
</Filter>
<File
RelativePath=".\ufoai.def">
<FileConfiguration
Name="Debug|Win32">
<Tool
Name="VCCustomBuildTool"
CommandLine="python &quot;$(SolutionDir)touch.py&quot; &quot;$(TargetPath)&quot;
"
AdditionalDependencies="&quot;$(SolutionDir)install\plugins\$(TargetFileName)&quot;"
Outputs="&quot;$(TargetPath)&quot;"/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32">
<Tool
Name="VCCustomBuildTool"
CommandLine="python &quot;$(SolutionDir)touch.py&quot; &quot;$(TargetPath)&quot;
"
AdditionalDependencies="&quot;$(SolutionDir)install\plugins\$(TargetFileName)&quot;"
Outputs="&quot;$(TargetPath)&quot;"/>
</FileConfiguration>
</File>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

View file

@ -0,0 +1,292 @@
/*
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
}

View file

@ -0,0 +1,38 @@
/*
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

181
contrib/ufoai/ufoai_gtk.cpp Normal file
View file

@ -0,0 +1,181 @@
/*
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];
}

28
contrib/ufoai/ufoai_gtk.h Normal file
View file

@ -0,0 +1,28 @@
/*
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

View file

@ -0,0 +1,300 @@
/*
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;
}

View file

@ -0,0 +1,26 @@
/*
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