diff --git a/examples/core/4square/4squareS.xml b/examples/core/4square/4squareS.xml
index af5deea8..8218fb62 100644
--- a/examples/core/4square/4squareS.xml
+++ b/examples/core/4square/4squareS.xml
@@ -3,7 +3,7 @@
-
+
@@ -108,4 +108,4 @@
-
\ No newline at end of file
+
diff --git a/examples/core/cong.xml b/examples/core/cong.xml
new file mode 100644
index 00000000..61d94970
--- /dev/null
+++ b/examples/core/cong.xml
@@ -0,0 +1,9 @@
+
+
+
diff --git a/examples/core/cong/congB.xml b/examples/core/cong/congB.xml
new file mode 100644
index 00000000..7be19ca3
--- /dev/null
+++ b/examples/core/cong/congB.xml
@@ -0,0 +1,91 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/examples/core/cong/congS.xml b/examples/core/cong/congS.xml
new file mode 100644
index 00000000..a1aadd19
--- /dev/null
+++ b/examples/core/cong/congS.xml
@@ -0,0 +1,64 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/examples/core/cong/congV.xml b/examples/core/cong/congV.xml
new file mode 100644
index 00000000..036c9088
--- /dev/null
+++ b/examples/core/cong/congV.xml
@@ -0,0 +1,16 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/examples/core/outside.xml b/examples/core/outside.xml
new file mode 100644
index 00000000..f88d23cb
--- /dev/null
+++ b/examples/core/outside.xml
@@ -0,0 +1,9 @@
+
+
+
diff --git a/examples/core/outside/outsideB.xml b/examples/core/outside/outsideB.xml
new file mode 100644
index 00000000..eafe7d6d
--- /dev/null
+++ b/examples/core/outside/outsideB.xml
@@ -0,0 +1,240 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/examples/core/outside/outsideS.xml b/examples/core/outside/outsideS.xml
new file mode 100644
index 00000000..79c28847
--- /dev/null
+++ b/examples/core/outside/outsideS.xml
@@ -0,0 +1,101 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/examples/core/outside/outsideV.xml b/examples/core/outside/outsideV.xml
new file mode 100644
index 00000000..036c9088
--- /dev/null
+++ b/examples/core/outside/outsideV.xml
@@ -0,0 +1,16 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/examples/core/predetermined.xml b/examples/core/predetermined.xml
new file mode 100644
index 00000000..cdea882a
--- /dev/null
+++ b/examples/core/predetermined.xml
@@ -0,0 +1,9 @@
+
+
+
diff --git a/examples/core/predetermined/predeterminedB.xml b/examples/core/predetermined/predeterminedB.xml
new file mode 100644
index 00000000..621cef7c
--- /dev/null
+++ b/examples/core/predetermined/predeterminedB.xml
@@ -0,0 +1,465 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/examples/core/predetermined/predeterminedS.xml b/examples/core/predetermined/predeterminedS.xml
new file mode 100644
index 00000000..3cc969a6
--- /dev/null
+++ b/examples/core/predetermined/predeterminedS.xml
@@ -0,0 +1,95 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/examples/core/predetermined/predeterminedV.xml b/examples/core/predetermined/predeterminedV.xml
new file mode 100644
index 00000000..036c9088
--- /dev/null
+++ b/examples/core/predetermined/predeterminedV.xml
@@ -0,0 +1,16 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/examples/core/random.xml b/examples/core/random.xml
new file mode 100644
index 00000000..b0b8cce5
--- /dev/null
+++ b/examples/core/random.xml
@@ -0,0 +1,10 @@
+
+
+
+
diff --git a/examples/core/random/randomB.xml b/examples/core/random/randomB.xml
new file mode 100644
index 00000000..2a5ef354
--- /dev/null
+++ b/examples/core/random/randomB.xml
@@ -0,0 +1,121 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/examples/core/random/randomS.xml b/examples/core/random/randomS.xml
new file mode 100644
index 00000000..f67baa4c
--- /dev/null
+++ b/examples/core/random/randomS.xml
@@ -0,0 +1,92 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/examples/core/random/randomV.xml b/examples/core/random/randomV.xml
new file mode 100644
index 00000000..036c9088
--- /dev/null
+++ b/examples/core/random/randomV.xml
@@ -0,0 +1,16 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/examples/core/tradeshow/tradeshow.nav b/examples/core/random/tradeshow.nav
similarity index 100%
rename from examples/core/tradeshow/tradeshow.nav
rename to examples/core/random/tradeshow.nav
diff --git a/examples/core/randomGoal/randomGoalB.xml b/examples/core/randomGoal/randomGoalB.xml
index 64bc9fd7..5b37903d 100644
--- a/examples/core/randomGoal/randomGoalB.xml
+++ b/examples/core/randomGoal/randomGoalB.xml
@@ -2,13 +2,13 @@
-
-
-
+
+
+
-
-
+
+
@@ -45,4 +45,4 @@
-
\ No newline at end of file
+
diff --git a/examples/core/randomGoal/randomGoalS.xml b/examples/core/randomGoal/randomGoalS.xml
index f6e975d8..4db6ad2e 100644
--- a/examples/core/randomGoal/randomGoalS.xml
+++ b/examples/core/randomGoal/randomGoalS.xml
@@ -31,9 +31,9 @@
@@ -43,8 +43,8 @@
-
\ No newline at end of file
+
diff --git a/projects/g++/Makefile b/projects/g++/Makefile
index edcd670c..c869fb4f 100644
--- a/projects/g++/Makefile
+++ b/projects/g++/Makefile
@@ -9,12 +9,12 @@ $(DIRS):
mkdir $@
-release:
+release: $(DIRS)
( cd build/release && cmake -DCMAKE_BUILD_TYPE=release ../.. && $(MAKE) --no-print-directory && make --no-print-directory install)
# ctags -R --language-force=c++ *.*
# ctags -eR --language-force=c++ *.*
-debug:
+debug: $(DIRS)
( cd build/debug && cmake -DCMAKE_BUILD_TYPE=debug ../.. && $(MAKE) --no-print-directory && make --no-print-directory install)
# ctags -R --language-force=c++ *.*
# ctags -eR --language-force=c++ *.*
diff --git a/src/Menge/MengeCore/Agents/PrefVelocity.cpp b/src/Menge/MengeCore/Agents/PrefVelocity.cpp
index e95b7bdb..1c507a14 100644
--- a/src/Menge/MengeCore/Agents/PrefVelocity.cpp
+++ b/src/Menge/MengeCore/Agents/PrefVelocity.cpp
@@ -3,7 +3,7 @@
License
Menge
-Copyright © and trademark ™ 2012-14 University of North Carolina at Chapel Hill.
+Copyright � and trademark � 2012-14 University of North Carolina at Chapel Hill.
All rights reserved.
Permission to use, copy, modify, and distribute this software and its documentation
@@ -89,11 +89,11 @@ namespace Menge {
_preferred = preferred;
#if _DEBUG
const float SPAN_EPS = -1.e-4f;
- #endif
assert( det( right, left ) >= SPAN_EPS );
assert( det( right, preferred )>= SPAN_EPS );
assert( det( preferred, left ) >= SPAN_EPS );
+ #endif
}
} // namespace Agents
-} // namespace Menge
\ No newline at end of file
+} // namespace Menge
diff --git a/src/Menge/MengeCore/BFSM/Actions/ActionDatabase.cpp b/src/Menge/MengeCore/BFSM/Actions/ActionDatabase.cpp
index 48d529e2..9389a17a 100644
--- a/src/Menge/MengeCore/BFSM/Actions/ActionDatabase.cpp
+++ b/src/Menge/MengeCore/BFSM/Actions/ActionDatabase.cpp
@@ -3,7 +3,7 @@
License
Menge
-Copyright © and trademark ™ 2012-14 University of North Carolina at Chapel Hill.
+Copyright � and trademark � 2012-14 University of North Carolina at Chapel Hill.
All rights reserved.
Permission to use, copy, modify, and distribute this software and its documentation
@@ -40,7 +40,7 @@ Any questions or comments should be sent to the authors {menge,geom}@cs.unc.edu
#include "Actions/ObstacleAction.h"
#include "Actions/PropertyAction.h"
#include "Actions/TeleportAction.h"
-
+#include "Actions/IncPropAction.h"
#ifndef DOXYGEN_SHOULD_SKIP_THIS
namespace Menge {
@@ -57,7 +57,8 @@ namespace Menge {
addFactory( new BFSM::OffsetPropertyActFactory() );
addFactory( new BFSM::ScalePropertyActFactory() );
addFactory( new BFSM::TeleportActFactory() );
+ addFactory( new BFSM::IncPropActFactory() );
}
} // namespace Menge
-#endif // DOXYGEN_SHOULD_SKIP_THIS
\ No newline at end of file
+#endif // DOXYGEN_SHOULD_SKIP_THIS
diff --git a/src/Menge/MengeCore/BFSM/Actions/IncPropAction.cpp b/src/Menge/MengeCore/BFSM/Actions/IncPropAction.cpp
new file mode 100644
index 00000000..e888755f
--- /dev/null
+++ b/src/Menge/MengeCore/BFSM/Actions/IncPropAction.cpp
@@ -0,0 +1,58 @@
+
+
+#include "Actions/IncPropAction.h"
+#include "BaseAgent.h"
+
+namespace Menge {
+
+ namespace BFSM {
+
+ /////////////////////////////////////////////////////////////////////
+ // Implementation of IncPropAction
+ /////////////////////////////////////////////////////////////////////
+
+ IncPropAction::IncPropAction():Action(),_increment(0.0f) {
+ }
+
+ /////////////////////////////////////////////////////////////////////
+
+ IncPropAction::~IncPropAction() {
+
+ }
+
+ /////////////////////////////////////////////////////////////////////
+
+ void IncPropAction::onEnter( Agents::BaseAgent * agent ) {
+ if(agent->_radius<20)//TODO replace with property spec from xml
+ agent->_radius = agent->_radius+this->_increment;
+ }
+
+ /////////////////////////////////////////////////////////////////////
+ // Implementation of IncPropActFactory
+ /////////////////////////////////////////////////////////////////////
+
+ IncPropActFactory::IncPropActFactory():ActionFactory() {
+ _IncrementID = _attrSet.addFloatAttribute("increment", true, 0.0f);
+ }
+
+ /////////////////////////////////////////////////////////////////////
+
+ Action * IncPropActFactory::instance() const {
+ return new IncPropAction();
+ }
+
+ /////////////////////////////////////////////////////////////////////
+
+ bool IncPropActFactory::setFromXML( Action * action, TiXmlElement * node, const std::string & behaveFldr ) const {
+ IncPropAction * IncAction = dynamic_cast< IncPropAction * >( action );
+ assert( action != 0x0 && "Trying to set Inc action properties on an incompatible object" );
+
+ if ( ! ActionFactory::setFromXML( action, node, behaveFldr ) ) return false;
+ // Override undoing the growing regardless of what was set in the XML
+ IncAction->_undoOnExit = false;
+ IncAction->_increment = _attrSet.getFloat(_IncrementID);
+ return true;
+ }
+
+ } // namespace BFSM
+} // namespace Menge
diff --git a/src/Menge/MengeCore/BFSM/Actions/IncPropAction.h b/src/Menge/MengeCore/BFSM/Actions/IncPropAction.h
new file mode 100644
index 00000000..50ba8843
--- /dev/null
+++ b/src/Menge/MengeCore/BFSM/Actions/IncPropAction.h
@@ -0,0 +1,140 @@
+
+
+/*!
+ * @file IncPropAction.h
+ * @brief Defines a BFSM action that causes agents radius to increase
+ */
+
+#ifndef __INCPROP_ACTION_H__
+#define __INCPROP_ACTION_H__
+
+#include "CoreConfig.h"
+#include "Actions/Action.h"
+#include "Actions/ActionFactory.h"
+#include "fsmCommon.h"
+
+namespace Menge {
+
+ // forward declaration
+
+ namespace Agents {
+ class BaseAgent;
+ }
+
+ namespace BFSM {
+ // forward declaration
+ class IncPropActFactory;
+
+ /*!
+ * @brief Causes the agents to grow bigger radius.
+ *
+ */
+ class MENGE_API IncPropAction : public Action {
+ public:
+ /*!
+ * @brief Constructor
+ *
+ */
+ IncPropAction();
+
+ /*!
+ * @brief Virtual destructor.
+ */
+ virtual ~IncPropAction();
+
+ /*!
+ * @brief Upon entering the state, this is called -- it is the main work
+ * of the action.
+ *
+ * @param agent The agent to act on.
+ */
+ virtual void onEnter( Agents::BaseAgent * agent );
+
+ friend class IncPropActFactory;
+ protected:
+
+ /*!
+ * @brief The work to do upon state exit.
+ *
+ * @param agent The agent to act on.
+ */
+ virtual void leaveAction( Agents::BaseAgent * agent ) {}
+
+ //variables here
+ float _increment;
+ };
+
+ /*!
+ * @brief Factory for the IncPropAction.
+ */
+ class MENGE_API IncPropActFactory : public ActionFactory {
+ public:
+ /*!
+ * @brief Constructor.
+ */
+ IncPropActFactory();
+
+ /*!
+ * @brief The name of the action.
+ *
+ * The action's name must be unique among all registered actions.
+ * Each action factory must override this function.
+ *
+ * @returns A string containing the unique action name.
+ */
+ virtual const char * name() const { return "increment_property"; }
+
+ /*!
+ * @brief A description of the action.
+ *
+ * Each action factory must override this function.
+ *
+ * @returns A string containing the action description.
+ */
+ virtual const char * description() const {
+ return "increments a property of an agent by a given step size";
+ };
+
+ protected:
+ /*!
+ * @brief Create an instance of this class's action.
+ *
+ * All ActionFactory sub-classes must override this by creating (on the heap)
+ * a new instance of its corresponding action type. The various field values
+ * of the instance will be set in a subsequent call to ActionFactory::setFromXML.
+ * The caller of this function takes ownership of the memory.
+ *
+ * @returns A pointer to a newly instantiated Action class.
+ */
+ Action * instance() const;
+
+ /*!
+ * @brief Given a pointer to an Action instance, sets the appropriate fields
+ * from the provided XML node.
+ *
+ * It is assumed that the value of the `type` attribute is this Action's type.
+ * (i.e. ActionFactory::thisFactory has already been called and returned true.)
+ * If sub-classes of ActionFactory introduce *new* Action parameters, then the
+ * sub-class should override this method but explicitly call the parent class's
+ * version.
+ *
+ * @param action A pointer to the action whose attributes are to be set.
+ * @param node The XML node containing the action attributes.
+ * @param behaveFldr The path to the behavior file. If the action references
+ * resources in the file system, it should be defined relative
+ * to the behavior file location. This is the folder containing
+ * that path.
+ * @returns A boolean reporting success (true) or failure (false).
+ */
+ virtual bool setFromXML( Action * action, TiXmlElement * node, const std::string & behaveFldr ) const;
+ size_t _IncrementID;
+ /*!
+ * @brief The identifier for the "exit_reset" boolean attribute.
+ */
+
+ };
+
+ } // namespace BFSM
+
+} //
+#endif // __TELEPORT_ACTION_H__
diff --git a/src/Menge/MengeCore/BFSM/FSM.cpp b/src/Menge/MengeCore/BFSM/FSM.cpp
index 7bcf69d5..ff3bb9bb 100644
--- a/src/Menge/MengeCore/BFSM/FSM.cpp
+++ b/src/Menge/MengeCore/BFSM/FSM.cpp
@@ -202,7 +202,7 @@ namespace Menge {
/////////////////////////////////////////////////////////////////////
- const Goal * FSM::getGoal( size_t goalSet, size_t goalID ) {
+ Goal * FSM::getGoal( size_t goalSet, size_t goalID ) {
if ( _goalSets.find( goalSet ) == _goalSets.end() ) {
return 0x0;
}
@@ -211,7 +211,7 @@ namespace Menge {
/////////////////////////////////////////////////////////////////////
- const GoalSet * FSM::getGoalSet( size_t goalSetID ) {
+ GoalSet * FSM::getGoalSet( size_t goalSetID ) {
if ( _goalSets.find( goalSetID ) == _goalSets.end() ) {
return 0x0;
}
@@ -314,4 +314,4 @@ namespace Menge {
return ctx;
}
} // namespace BFSM
-} // namespace Menge
\ No newline at end of file
+} // namespace Menge
diff --git a/src/Menge/MengeCore/BFSM/FSM.h b/src/Menge/MengeCore/BFSM/FSM.h
index fe5e0d75..fd6255ea 100644
--- a/src/Menge/MengeCore/BFSM/FSM.h
+++ b/src/Menge/MengeCore/BFSM/FSM.h
@@ -239,7 +239,7 @@ namespace Menge {
* @returns A pointer to the corresponding goal. If no such goal exists
* NULL is returned.
*/
- const Goal * getGoal( size_t goalSet, size_t goalID );
+ Goal * getGoal( size_t goalSet, size_t goalID );
/*!
* @brief Retrives the given goal set.
@@ -248,7 +248,7 @@ namespace Menge {
* @returns A pointer to the corresponding goal set. If no such goal set
* exists, NULL is returned.
*/
- const GoalSet * getGoalSet( size_t goalSetID );
+ GoalSet * getGoalSet( size_t goalSetID );
/*!
* @brief Update the fsm state by one time step
diff --git a/src/Menge/MengeCore/BFSM/GoalSelectors/GoalSelectorDatabase.cpp b/src/Menge/MengeCore/BFSM/GoalSelectors/GoalSelectorDatabase.cpp
index 41f5f1cc..8c895d94 100644
--- a/src/Menge/MengeCore/BFSM/GoalSelectors/GoalSelectorDatabase.cpp
+++ b/src/Menge/MengeCore/BFSM/GoalSelectors/GoalSelectorDatabase.cpp
@@ -3,7 +3,7 @@
License
Menge
-Copyright © and trademark ™ 2012-14 University of North Carolina at Chapel Hill.
+Copyright � and trademark � 2012-14 University of North Carolina at Chapel Hill.
All rights reserved.
Permission to use, copy, modify, and distribute this software and its documentation
@@ -48,7 +48,7 @@ Any questions or comments should be sent to the authors {menge,geom}@cs.unc.edu
#include "GoalSelectors/GoalSelectorFarthest.h"
#include "GoalSelectors/GoalSelectorFarthestNM.h"
#include "GoalSelectors/GoalSelectorShared.h"
-
+#include "GoalSelectors/GoalSelectorSecondNearest.h"
#ifndef DOXYGEN_SHOULD_SKIP_THIS
namespace Menge {
@@ -70,7 +70,8 @@ namespace Menge {
addFactory( new BFSM::NearestNMGoalSelectorFactory() );
addFactory( new BFSM::FarthestNMGoalSelectorFactory() );
addFactory( new BFSM::SharedGoalSelectorFactory() );
+ addFactory( new BFSM::SecondNearestGoalSelectorFactory() );
}
} // namespace Menge
-#endif // DOXYGEN_SHOULD_SKIP_THIS
\ No newline at end of file
+#endif // DOXYGEN_SHOULD_SKIP_THIS
diff --git a/src/Menge/MengeCore/BFSM/GoalSelectors/GoalSelectorSecondNearest.cpp b/src/Menge/MengeCore/BFSM/GoalSelectors/GoalSelectorSecondNearest.cpp
new file mode 100644
index 00000000..31e306bc
--- /dev/null
+++ b/src/Menge/MengeCore/BFSM/GoalSelectors/GoalSelectorSecondNearest.cpp
@@ -0,0 +1,46 @@
+#include "GoalSelectors/GoalSelectorSecondNearest.h"
+#include "Goals/Goal.h"
+#include "GoalSet.h"
+#include "BaseAgent.h"
+#include
+
+namespace Menge {
+
+ namespace BFSM {
+
+ /////////////////////////////////////////////////////////////////////
+ // Implementation of NearestGoalSelector
+ /////////////////////////////////////////////////////////////////////
+
+ Goal * SecondNearestGoalSelector::getGoal( const Agents::BaseAgent * agent ) const {
+ assert( agent != 0x0 && "NearestGoalGenerator requires a valid base agent!" );
+ const size_t GOAL_COUNT = _goalSet->size();
+ if ( GOAL_COUNT == 0 ) {
+ logger << Logger::ERR_MSG << "NearestGoalSelector was unable to provide a goal for agent " << agent->_id << ". There were no available goals in the goal set.";
+ return 0x0;
+ }
+ const Vector2 p = agent->_pos;
+
+ Goal * bestGoal;
+
+ bestGoal = _goalSet->getIthGoal( 0 );
+ Goal * secondBestGoal;
+
+ secondBestGoal = _goalSet->getIthGoal( 0 );
+ Vector2 disp = bestGoal->getCentroid() - p;
+ float bestDist = absSq( disp );
+ for ( size_t i = 1; i < GOAL_COUNT; ++i ) {
+ Goal * testGoal = _goalSet->getIthGoal( i );
+ disp = testGoal->getCentroid() - p;
+ float testDist = absSq( disp );
+ if ( testDist < bestDist ) {
+ bestDist = testDist;
+ secondBestGoal=bestGoal;
+ bestGoal = testGoal;
+ }
+ }
+
+ return secondBestGoal;
+ }
+ } // namespace BFSM
+} // namespace Menge
diff --git a/src/Menge/MengeCore/BFSM/GoalSelectors/GoalSelectorSecondNearest.h b/src/Menge/MengeCore/BFSM/GoalSelectors/GoalSelectorSecondNearest.h
new file mode 100644
index 00000000..69d8b727
--- /dev/null
+++ b/src/Menge/MengeCore/BFSM/GoalSelectors/GoalSelectorSecondNearest.h
@@ -0,0 +1,71 @@
+
+/*!
+ * @file GoalSelectorNearest.h
+ * @brief The definition of the nearest goal selector.
+ */
+
+#ifndef __GOAL_SELECTOR_SECOND_NEAREST_H__
+#define __GOAL_SELECTOR_SECOND_NEAREST_H__
+
+#include "CoreConfig.h"
+#include "fsmCommon.h"
+#include "GoalSelectors/GoalSelectorSet.h"
+
+namespace Menge {
+
+ namespace BFSM {
+ /*!
+ * @brief The nearest goal selector selects the goal from a goal set that
+ * is nearest to the agent in terms of Euclidian distance.
+ */
+ class MENGE_API SecondNearestGoalSelector : public SetGoalSelector {
+ public:
+ /*!
+ * @brief Interface function for acquiring per-agent goals.
+ *
+ * @param agent The agent for whom a goal is extracted.
+ * @returns A pointer to a goal.
+ * // TODO: Figure out who owns this goal.
+ */
+ virtual Goal * getGoal( const Agents::BaseAgent * agent ) const;
+ };
+
+ /*!
+ * @brief Factory for the NearestGoalSelector.
+ */
+ class MENGE_API SecondNearestGoalSelectorFactory : public SetGoalSelectorFactory {
+ public:
+ /*!
+ * @brief The name of the goal selector type.
+ *
+ * The goal selector's name must be unique among all registered goal selectors.
+ * Each goal selector factory must override this function.
+ *
+ * @returns A string containing the unique goal selector name.
+ */
+ virtual const char * name() const { return "second_nearest"; }
+
+ /*!
+ * @brief A description of the goal selector.
+ *
+ * Each goal selector factory must override this function.
+ *
+ * @returns A string containing the goal selector description.
+ */
+ virtual const char * description() const {
+ return "A goal selector. Assigns the agent the goal in the given " \
+ "goal set that is *nearest* the agent (in Euclidian distance).";
+ };
+
+ protected:
+ /*!
+ * @brief Create an instance of this class's goal selector.
+ *
+ * @returns A pointer to a newly instantiated GoalSelector class.
+ */
+ GoalSelector * instance() const { return new SecondNearestGoalSelector(); }
+ };
+ } // namespace BFSM
+} // namespace Menge
+
+#endif // __GOAL_SELECTOR_NEAREST_H__
diff --git a/src/Menge/MengeCore/BFSM/GoalSelectors/GoalSelectorSet.cpp b/src/Menge/MengeCore/BFSM/GoalSelectors/GoalSelectorSet.cpp
index f9748439..3a5addcc 100644
--- a/src/Menge/MengeCore/BFSM/GoalSelectors/GoalSelectorSet.cpp
+++ b/src/Menge/MengeCore/BFSM/GoalSelectors/GoalSelectorSet.cpp
@@ -3,7 +3,7 @@
License
Menge
-Copyright © and trademark ™ 2012-14 University of North Carolina at Chapel Hill.
+Copyright � and trademark � 2012-14 University of North Carolina at Chapel Hill.
All rights reserved.
Permission to use, copy, modify, and distribute this software and its documentation
diff --git a/src/Menge/MengeCore/BFSM/Transitions/CondFollow.cpp b/src/Menge/MengeCore/BFSM/Transitions/CondFollow.cpp
new file mode 100644
index 00000000..6997f013
--- /dev/null
+++ b/src/Menge/MengeCore/BFSM/Transitions/CondFollow.cpp
@@ -0,0 +1,108 @@
+/*
+ * CondQuad.cpp
+ *
+ * Created on: Jul 18, 2016
+ * Author: michael
+ */
+
+#include "CondFollow.h"
+
+#include "Core.h"
+#include "BaseAgent.h"
+#include
+//TODO:include file with _sim reference(get agents ability)
+#include "SimSystem.h"
+#include "SimulatorDBEntry.h"
+#include "Goals/Goal.h"
+#include "GoalSet.h"
+#include "FSM.h"
+#include "Math/Vector2.h"
+namespace Menge {
+
+ namespace BFSM {
+
+
+ ///////////////////////////////////////////////////////////////////////////
+ // Implementation of FollowTargetCondition
+ ///////////////////////////////////////////////////////////////////////////
+ FollowTargetCondition::FollowTargetCondition(): Condition(),_acceptedRadius(0.f), _followGoalSetID(-1){
+
+ }
+
+
+ ///////////////////////////////////////////////////////////////////////////
+ FollowTargetCondition::FollowTargetCondition( const FollowTargetCondition & cond ) {
+ _acceptedRadius = cond._acceptedRadius;
+ _followGoalSetID = cond._followGoalSetID;
+ }
+
+ ///////////////////////////////////////////////////////////////////////////
+
+ FollowTargetCondition::~FollowTargetCondition() {
+ //TODO:What is this for?
+ }
+
+ ///////////////////////////////////////////////////////////////////////////
+
+ void FollowTargetCondition::onEnter( Agents::BaseAgent * agent ) {
+
+ }
+
+ ///////////////////////////////////////////////////////////////////////////
+
+ void FollowTargetCondition::onLeave( Agents::BaseAgent * agent ) {
+
+ }
+
+ ///////////////////////////////////////////////////////////////////////////
+
+ bool FollowTargetCondition::conditionMet( Agents::BaseAgent * agent, const Goal * goal ) {
+ const GoalSet * gs = Menge::SimulatorDBEntry::_fsm->getGoalSet(this->_followGoalSetID);
+ if(gs == NULL)
+ {
+ logger<<"null goal set";
+ return false;
+ }
+ size_t num_goals=gs->size();
+ Menge::Math::Vector2 pos=agent->_pos;
+ for(size_t i=0;igetIthGoal(i);
+ float dist=g->squaredDistance(pos);
+ if(dist<=_acceptedRadius)
+ return true;
+ }
+
+ return false;
+ }
+
+ ///////////////////////////////////////////////////////////////////////////
+
+ Condition * FollowTargetCondition::copy() {
+ return new FollowTargetCondition( *this );
+ }
+
+ ///////////////////////////////////////////////////////////////////////////
+ // Implementation of FollowTargetCondFactory
+ /////////////////////////////////////////////////////////////////////
+ FollowTargetCondFactory::FollowTargetCondFactory() : ConditionFactory() {
+ _distanceID = _attrSet.addFloatAttribute("distance", true /*required*/, 0.0 );
+ _followGoalSetIDID = _attrSet.addIntAttribute("goalSetToFollow", true, 99 );
+
+ }
+
+ ///////////////////////////////////////////////////////////////////////////
+
+ bool FollowTargetCondFactory::setFromXML( Condition * condition, TiXmlElement * node, const std::string & behaveFldr ) const {
+ FollowTargetCondition * pCond = dynamic_cast< FollowTargetCondition * >( condition );
+ assert( pCond != 0x0 && "Trying to set the properties of a follow condition on an incompatible object" );
+
+ if ( !ConditionFactory::setFromXML( pCond, node, behaveFldr ) ) return false;
+ float d=_attrSet.getFloat( _distanceID);
+ pCond->setMinDistance( d*d);
+ pCond->setGoalsToFollow( _attrSet.getInt(_followGoalSetIDID));
+
+ return true;
+ }
+ } // namespace BFSM
+} // namespace Menge
diff --git a/src/Menge/MengeCore/BFSM/Transitions/CondFollow.h b/src/Menge/MengeCore/BFSM/Transitions/CondFollow.h
new file mode 100644
index 00000000..14b9fb0a
--- /dev/null
+++ b/src/Menge/MengeCore/BFSM/Transitions/CondFollow.h
@@ -0,0 +1,172 @@
+/*
+ * CondQuad.h
+ *
+ * Created on: Jul 18, 2016
+ * Author: michael
+ */
+
+#ifndef MENGE_MENGECORE_BFSM_TRANSITIONS_CONDFOLLOW_H_
+#define MENGE_MENGECORE_BFSM_TRANSITIONS_CONDFOLLOW_H_
+
+#include "CoreConfig.h"
+#include "Transitions/Condition.h"
+#include "Transitions/ConditionFactory.h"
+#include "fsmCommon.h"
+#include "ReadersWriterLock.h"
+#include "SimulatorInterface.h"
+
+namespace Menge {
+
+ namespace BFSM {
+
+ ///////////////////////////////////////////////////////////////////////////
+
+ /*!
+ * @brief The definition of the follow condition.
+ *
+ * The follow condition becomes active when the agent is near a target
+ * "follow" goal set. This can be used to simulate agents following a set of
+ * moving goals, e.g., quadcopters
+ */
+ class MENGE_API FollowTargetCondition : public Condition {
+ public:
+ /*!
+ * @brief Constructor.
+ */
+ FollowTargetCondition();
+ FollowTargetCondition(const FollowTargetCondition & cond);
+
+
+ /*!
+ * @brief Create a copy of this condition.
+ *
+ * It is the responsibility of the caller to delete the object.
+ *
+ * @returns: A "deep copy" of this condition - such that there is no shared
+ * objects between this and its copy.
+ */
+ virtual Condition * copy();
+
+ protected:
+ /*!
+ * @brief Constructor.
+ */
+ ~FollowTargetCondition();
+
+ public:
+ /*!
+ * @brief Called when an agent enters a state with this exiting transition.
+ *
+ * Sub-classes should use this function as the opportunity to cache any
+ * particular per-agent data.
+ *
+ * @param agent The agent who has entered the state which uses
+ * this transition.
+ */
+ virtual void onEnter( Agents::BaseAgent * agent );
+
+ /*!
+ * @brief Called when an agent exits the state with this transition.
+ *
+ * @param agent The agent who left the state.
+ */
+ virtual void onLeave( Agents::BaseAgent * agent );
+
+ /*!
+ * @brief check if agent is near a quad
+ *
+ * @param agent The agent to test the transition for.
+ * @param goal The agent's goal (although this may be ignored).
+ * @returns True if the condition has been met, false otherwise.
+ */
+ virtual bool conditionMet( Agents::BaseAgent * agent, const Goal * goal );
+ virtual void setGoalsToFollow(int id){_followGoalSetID = id;}
+ void setMinDistance( float dist ) { _acceptedRadius = dist; }
+ friend class FollowTargetCondFactory;
+ protected:
+
+ float _acceptedRadius;
+ size_t _followGoalSetID;
+
+ };
+
+ ///////////////////////////////////////////////////////////////////////////
+
+ /*!
+ * @brief The factory for creating the FollowTargetCondition
+ */
+ class MENGE_API FollowTargetCondFactory : public ConditionFactory {
+ public:
+ /*!
+ * @brief Constructor.
+ */
+ FollowTargetCondFactory();
+
+ /*!
+ * @brief The name of the action.
+ *
+ * The action's name must be unique among all registered actions.
+ * Each action factory must override this function.
+ *
+ * @returns A string containing the unique action name.
+ */
+ virtual const char * name() const { return "follow"; }
+ /*!
+ * @brief A description of the action.
+ *
+ * Each action factory must override this function.
+ *
+ * @returns A string containing the action description.
+ */
+ virtual const char * description() const {
+ return "The Quad condition. returns true if agent is within a radius of one of quadrotors";
+ }
+
+
+ protected:
+ /*!
+ * @brief Create an instance of this class's condition.
+ *
+ * All ConditionFactory sub-classes must override this by creating (on the heap)
+ * a new instance of its corresponding condition type. The various field values
+ * of the instance will be set in a subsequent call to ConditionFactory::setFromXML.
+ * The caller of this function takes ownership of the memory.
+ *
+ * @returns A pointer to a newly instantiated Action class.
+ */
+ virtual Condition * instance() const { return new FollowTargetCondition(); }
+
+ /*!
+ * @brief Given a pointer to an Condition instance, sets the appropriate fields
+ * from the provided XML node.
+ *
+ * It is assumed that the value of the `type` attribute is this Tarnsitions's type.
+ * (i.e. ConditionFactory::thisFactory has already been called and returned true.)
+ * If sub-classes of ConditionFactory introduce *new* Condition parameters, then the
+ * sub-class should override this method but explicitly call the parent class's
+ * version.
+ *
+ * @param condition A pointer to the condition whose attributes are to be set.
+ * @param node The XML node containing the condition attributes.
+ * @param behaveFldr The path to the behavior file. If the condition references
+ * resources in the file system, it should be defined relative
+ * to the behavior file location. This is the folder containing
+ * that path.
+ * @returns A boolean reporting success (true) or failure (false).
+ */
+ virtual bool setFromXML( Condition * condition, TiXmlElement * node, const std::string & behaveFldr ) const;
+
+ /*!
+ * @brief The identifier for the minimum distance.
+ */
+ size_t _distanceID;
+
+ /*!
+ * @brief The identifier for the Goal set to follow.
+ */
+ size_t _followGoalSetIDID;
+ };
+
+ } // namespace BFSM
+} // namespace Menge
+#endif //MENGE_MENGECORE_BFSM_TRANSITIONS_CONDFOLLOW_H_
diff --git a/src/Menge/MengeCore/BFSM/Transitions/CondProximity.cpp b/src/Menge/MengeCore/BFSM/Transitions/CondProximity.cpp
new file mode 100644
index 00000000..da0e2759
--- /dev/null
+++ b/src/Menge/MengeCore/BFSM/Transitions/CondProximity.cpp
@@ -0,0 +1,104 @@
+/*
+ * CondProximity.cpp
+ *
+ * Created on: Jul 18, 2016
+ * Author: michael
+ */
+
+#include "CondProximity.h"
+
+#include "Core.h"
+#include "BaseAgent.h"
+#include
+//TODO:include file with _sim reference(get agents ability)
+#include "SimSystem.h"
+#include "SimulatorDBEntry.h"
+namespace Menge {
+
+ namespace BFSM {
+
+
+ ///////////////////////////////////////////////////////////////////////////
+ // Implementation of ProximityCondition
+ ///////////////////////////////////////////////////////////////////////////
+ ProximityCondition::ProximityCondition(): Condition(),_acceptedRadius(0.f), _AgentToAvoidID(-1), _inc(0.00){
+
+ }
+
+
+ ///////////////////////////////////////////////////////////////////////////
+ ProximityCondition::ProximityCondition( const ProximityCondition & cond ) {
+ _acceptedRadius = cond._acceptedRadius;
+ _AgentToAvoidID = -1;
+ _inc = 0.00;
+ }
+
+ ///////////////////////////////////////////////////////////////////////////
+
+ ProximityCondition::~ProximityCondition() {
+ //TODO:What is this for?
+ }
+
+ ///////////////////////////////////////////////////////////////////////////
+
+ void ProximityCondition::onEnter( Agents::BaseAgent * agent ) {
+
+ }
+
+ ///////////////////////////////////////////////////////////////////////////
+
+ void ProximityCondition::onLeave( Agents::BaseAgent * agent ) {
+
+ }
+
+ ///////////////////////////////////////////////////////////////////////////
+
+ bool ProximityCondition::conditionMet( Agents::BaseAgent * agent, const Goal * goal ) {
+ const Agents::BaseAgent *avoidAgent = Menge::SimulatorDBEntry::_sim->getAgent(this->_AgentToAvoidID);
+ if(avoidAgent == NULL)
+ {
+ logger<<"null void agent";
+ return false;
+ }
+ if(_acceptedRadius>=3)
+ _inc+=0.0004;
+ if(_acceptedRadius<20)
+ _acceptedRadius += 0.2;
+ return std::sqrt(std::pow(std::abs(agent->_pos._x- avoidAgent->_pos._x),2)+std::pow(std::abs(agent->_pos._y -
+ avoidAgent->_pos._y),2))_radius+_acceptedRadius+_inc;
+
+ }
+
+ ///////////////////////////////////////////////////////////////////////////
+
+ Condition * ProximityCondition::copy() {
+ return new ProximityCondition( *this );
+ }
+
+ ///////////////////////////////////////////////////////////////////////////
+ // Implementation of ProximityCondFactory
+ /////////////////////////////////////////////////////////////////////
+ ProximityCondFactory::ProximityCondFactory() : ConditionFactory() {
+ _distanceID = _attrSet.addFloatAttribute("distance", true /*required*/, 0.0 );
+ _AgentToAvoidID = _attrSet.addIntAttribute("agentToAvoid", true, 0 );
+
+ }
+
+ ///////////////////////////////////////////////////////////////////////////
+
+ bool ProximityCondFactory::setFromXML( Condition * condition, TiXmlElement * node, const std::string & behaveFldr ) const {
+ ProximityCondition * pCond = dynamic_cast< ProximityCondition * >( condition );
+ assert( pCond != 0x0 && "Trying to set the properties of a proximity condition on an incompatible object" );
+
+ if ( !ConditionFactory::setFromXML( pCond, node, behaveFldr ) ) return false;
+
+ pCond->setMinDistance( _attrSet.getFloat( _distanceID));
+ //cycle through agents here to find disaster agent using agent to aboid in attrset, set the this_x and this_y from that thern return true
+
+ pCond->setAgentToAvoid( _attrSet.getInt(_AgentToAvoidID)) ;
+
+
+ return true;
+ }
+ } // namespace BFSM
+} // namespace Menge
diff --git a/src/Menge/MengeCore/BFSM/Transitions/CondProximity.h b/src/Menge/MengeCore/BFSM/Transitions/CondProximity.h
new file mode 100644
index 00000000..4486be5f
--- /dev/null
+++ b/src/Menge/MengeCore/BFSM/Transitions/CondProximity.h
@@ -0,0 +1,180 @@
+/*
+ * CondProximity.h
+ *
+ * Created on: Jul 18, 2016
+ * Author: michael
+ */
+
+#ifndef SRC_MENGE_MENGECORE_BFSM_TRANSITIONS_CONDPROXIMITY_H_
+#define SRC_MENGE_MENGECORE_BFSM_TRANSITIONS_CONDPROXIMITY_H_
+
+#include "CoreConfig.h"
+#include "Transitions/Condition.h"
+#include "Transitions/ConditionFactory.h"
+#include "fsmCommon.h"
+#include "ReadersWriterLock.h"
+#include "SimulatorInterface.h"
+
+namespace Menge {
+
+ namespace BFSM {
+
+ // forward declarations
+ class ProximityCondFactory;
+ ///////////////////////////////////////////////////////////////////////////
+
+ /*!
+ * @brief The definition of the proximity condition.
+ *
+ * The proximity condition becomes active when the agent is within a given
+ * distance from specified target agent.
+ */
+ class MENGE_API ProximityCondition : public Condition {
+ public:
+ /*!
+ * @brief Constructor.
+ */
+ ProximityCondition();
+ ProximityCondition(const ProximityCondition & cond);
+ /*!
+ * @brief Copy Constructor.
+ *
+ * @param cond The condition to copy from.
+ */
+ //ProximityCondition( const ProximityCondition & cond );
+
+ /*!
+ * @brief Create a copy of this condition.
+ *
+ * It is the responsibility of the caller to delete the object.
+ *
+ * @returns: A "deep copy" of this condition - such that there is no shared
+ * objects between this and its copy.
+ */
+ virtual Condition * copy();
+
+ protected:
+ /*!
+ * @brief Constructor.
+ */
+ ~ProximityCondition();
+
+ public:
+ /*!
+ * @brief Called when an agent enters a state with this exiting transition.
+ *
+ * Sub-classes should use this function as the opportunity to cache any
+ * particular per-agent data.
+ *
+ * @param agent The agent who has entered the state which uses
+ * this transition.
+ */
+ virtual void onEnter( Agents::BaseAgent * agent );
+
+ /*!
+ * @brief Called when an agent exits the state with this transition.
+ *
+ * @param agent The agent who left the state.
+ */
+ virtual void onLeave( Agents::BaseAgent * agent );
+
+ /*!
+ * @brief The AutoCondition is always met -- it is a tautology.
+ *
+ * @param agent The agent to test the transition for.
+ * @param goal The agent's goal (although this may be ignored).
+ * @returns True if the condition has been met, false otherwise.
+ */
+ virtual bool conditionMet( Agents::BaseAgent * agent, const Goal * goal );
+ virtual void setAgentToAvoid(int id){_AgentToAvoidID = id;}
+ void setMinDistance( float dist ) { _acceptedRadius = dist; }
+ friend class ProximityCondFactory;
+
+ protected:
+ //the agnet we want to avoid
+
+ int _AgentToAvoidID;
+ float _acceptedRadius;
+ float _inc;
+ };
+
+ ///////////////////////////////////////////////////////////////////////////
+
+ /*!
+ * @brief The factory for creating the ProximityCondition
+ */
+ class MENGE_API ProximityCondFactory : public ConditionFactory {
+ public:
+ /*!
+ * @brief Constructor.
+ */
+ ProximityCondFactory();
+
+ /*!
+ * @brief The name of the action.
+ *
+ * The action's name must be unique among all registered actions.
+ * Each action factory must override this function.
+ *
+ * @returns A string containing the unique action name.
+ */
+ virtual const char * name() const { return "proximity"; }
+ /*!
+ * @brief A description of the action.
+ *
+ * Each action factory must override this function.
+ *
+ * @returns A string containing the action description.
+ */
+ virtual const char * description() const {
+ return "The Proximity condition. returns true if agent is within a radius of another specified agent";
+ }
+
+
+ protected:
+ /*!
+ * @brief Create an instance of this class's condition.
+ *
+ * All ConditionFactory sub-classes must override this by creating (on the heap)
+ * a new instance of its corresponding condition type. The various field values
+ * of the instance will be set in a subsequent call to ConditionFactory::setFromXML.
+ * The caller of this function takes ownership of the memory.
+ *
+ * @returns A pointer to a newly instantiated Action class.
+ */
+ virtual Condition * instance() const { return new ProximityCondition(); }
+
+ /*!
+ * @brief Given a pointer to an Condition instance, sets the appropriate fields
+ * from the provided XML node.
+ *
+ * It is assumed that the value of the `type` attribute is this Tarnsitions's type.
+ * (i.e. ConditionFactory::thisFactory has already been called and returned true.)
+ * If sub-classes of ConditionFactory introduce *new* Condition parameters, then the
+ * sub-class should override this method but explicitly call the parent class's
+ * version.
+ *
+ * @param condition A pointer to the condition whose attributes are to be set.
+ * @param node The XML node containing the condition attributes.
+ * @param behaveFldr The path to the behavior file. If the condition references
+ * resources in the file system, it should be defined relative
+ * to the behavior file location. This is the folder containing
+ * that path.
+ * @returns A boolean reporting success (true) or failure (false).
+ */
+ virtual bool setFromXML( Condition * condition, TiXmlElement * node, const std::string & behaveFldr ) const;
+
+ /*!
+ * @brief The identifier for the minimum distance.
+ */
+ size_t _distanceID;
+
+ /*!
+ * @brief The identifier for the Agent to avoid.
+ */
+ size_t _AgentToAvoidID;
+ };
+
+ } // namespace BFSM
+} // namespace Menge
+#endif //
diff --git a/src/Menge/MengeCore/BFSM/Transitions/CondVia.cpp b/src/Menge/MengeCore/BFSM/Transitions/CondVia.cpp
new file mode 100644
index 00000000..afdb125f
--- /dev/null
+++ b/src/Menge/MengeCore/BFSM/Transitions/CondVia.cpp
@@ -0,0 +1,108 @@
+/*
+ * CondQuad.cpp
+ *
+ * Created on: Jul 18, 2016
+ * Author: michael
+ */
+
+#include "CondVia.h"
+
+#include "Core.h"
+#include "BaseAgent.h"
+#include
+//TODO:include file with _sim reference(get agents ability)
+#include "SimSystem.h"
+#include "SimulatorDBEntry.h"
+#include "Goals/Goal.h"
+#include "GoalSet.h"
+#include "FSM.h"
+#include "Math/Vector2.h"
+namespace Menge {
+
+ namespace BFSM {
+
+
+ ///////////////////////////////////////////////////////////////////////////
+ // Implementation of ViaTargetCondition
+ ///////////////////////////////////////////////////////////////////////////
+ ViaTargetCondition::ViaTargetCondition(): Condition(),_acceptedRadius(0.f), _viaGoalSetID(-1){
+
+ }
+
+
+ ///////////////////////////////////////////////////////////////////////////
+ ViaTargetCondition::ViaTargetCondition( const ViaTargetCondition & cond ) {
+ _acceptedRadius = cond._acceptedRadius;
+ _viaGoalSetID = cond._viaGoalSetID;
+ }
+
+ ///////////////////////////////////////////////////////////////////////////
+
+ ViaTargetCondition::~ViaTargetCondition() {
+ //TODO:What is this for?
+ }
+
+ ///////////////////////////////////////////////////////////////////////////
+
+ void ViaTargetCondition::onEnter( Agents::BaseAgent * agent ) {
+
+ }
+
+ ///////////////////////////////////////////////////////////////////////////
+
+ void ViaTargetCondition::onLeave( Agents::BaseAgent * agent ) {
+
+ }
+
+ ///////////////////////////////////////////////////////////////////////////
+
+ bool ViaTargetCondition::conditionMet( Agents::BaseAgent * agent, const Goal * goal ) {
+ const GoalSet * gs = Menge::SimulatorDBEntry::_fsm->getGoalSet(this->_viaGoalSetID);
+ if(gs == NULL)
+ {
+ logger<<"null goal set";
+ return false;
+ }
+ size_t num_goals=gs->size();
+ Menge::Math::Vector2 pos=agent->_pos;
+ for(size_t i=0;igetIthGoal(i);
+ float dist=g->squaredDistance(pos);
+ if(dist<=_acceptedRadius)
+ return true;
+ }
+
+ return false;
+ }
+
+ ///////////////////////////////////////////////////////////////////////////
+
+ Condition * ViaTargetCondition::copy() {
+ return new ViaTargetCondition( *this );
+ }
+
+ ///////////////////////////////////////////////////////////////////////////
+ // Implementation of ViaTargetCondFactory
+ /////////////////////////////////////////////////////////////////////
+ ViaTargetCondFactory::ViaTargetCondFactory() : ConditionFactory() {
+ _distanceID = _attrSet.addFloatAttribute("distance", true /*required*/, 0.0 );
+ _viaGoalSetIDID = _attrSet.addIntAttribute("goalsVia", true, 0 );
+
+ }
+
+ ///////////////////////////////////////////////////////////////////////////
+
+ bool ViaTargetCondFactory::setFromXML( Condition * condition, TiXmlElement * node, const std::string & behaveFldr ) const {
+ ViaTargetCondition * pCond = dynamic_cast< ViaTargetCondition * >( condition );
+ assert( pCond != 0x0 && "Trying to set the properties of a timer condition on an incompatible object" );
+
+ if ( !ConditionFactory::setFromXML( pCond, node, behaveFldr ) ) return false;
+ float d=_attrSet.getFloat( _distanceID);
+ pCond->setMinDistance(d*d);
+ pCond->setGoalsToVia( _attrSet.getInt(_viaGoalSetIDID));
+
+ return true;
+ }
+ } // namespace BFSM
+} // namespace Menge
diff --git a/src/Menge/MengeCore/BFSM/Transitions/CondVia.h b/src/Menge/MengeCore/BFSM/Transitions/CondVia.h
new file mode 100644
index 00000000..353cfd36
--- /dev/null
+++ b/src/Menge/MengeCore/BFSM/Transitions/CondVia.h
@@ -0,0 +1,170 @@
+/*
+ * CondQuad.h
+ *
+ * Created on: Jul 18, 2016
+ * Author: michael
+ */
+
+#ifndef MENGE_MENGECORE_BFSM_TRANSITIONS_CONDVIA_H_
+#define MENGE_MENGECORE_BFSM_TRANSITIONS_CONDVIA_H_
+
+#include "CoreConfig.h"
+#include "Transitions/Condition.h"
+#include "Transitions/ConditionFactory.h"
+#include "fsmCommon.h"
+#include "ReadersWriterLock.h"
+#include "SimulatorInterface.h"
+
+namespace Menge {
+
+ namespace BFSM {
+
+ ///////////////////////////////////////////////////////////////////////////
+
+ /*!
+ * @brief The definition of the via target condition.
+ *
+ * The via target condition becomes active when the agent has been near to a specified "via target" goal
+ */
+ class MENGE_API ViaTargetCondition : public Condition {
+ public:
+ /*!
+ * @brief Constructor.
+ */
+ ViaTargetCondition();
+ ViaTargetCondition(const ViaTargetCondition & cond);
+
+
+ /*!
+ * @brief Create a copy of this condition.
+ *
+ * It is the responsibility of the caller to delete the object.
+ *
+ * @returns: A "deep copy" of this condition - such that there is no shared
+ * objects between this and its copy.
+ */
+ virtual Condition * copy();
+
+ protected:
+ /*!
+ * @brief Constructor.
+ */
+ ~ViaTargetCondition();
+
+ public:
+ /*!
+ * @brief Called when an agent enters a state with this exiting transition.
+ *
+ * Sub-classes should use this function as the opportunity to cache any
+ * particular per-agent data.
+ *
+ * @param agent The agent who has entered the state which uses
+ * this transition.
+ */
+ virtual void onEnter( Agents::BaseAgent * agent );
+
+ /*!
+ * @brief Called when an agent exits the state with this transition.
+ *
+ * @param agent The agent who left the state.
+ */
+ virtual void onLeave( Agents::BaseAgent * agent );
+
+ /*!
+ * @brief check if agent is near a via goal
+ *
+ * @param agent The agent to test the transition for.
+ * @param goal The agent's goal (although this may be ignored).
+ * @returns True if the condition has been met, false otherwise.
+ */
+ virtual bool conditionMet( Agents::BaseAgent * agent, const Goal * goal );
+ virtual void setGoalsToVia(int id){_viaGoalSetID = id;}
+ void setMinDistance( float dist ) { _acceptedRadius = dist; }
+ friend class ViaTargetCondFactory;
+ protected:
+
+ float _acceptedRadius;
+ size_t _viaGoalSetID;
+
+ };
+
+ ///////////////////////////////////////////////////////////////////////////
+
+ /*!
+ * @brief The factory for creating the ViaTargetCondition
+ */
+ class MENGE_API ViaTargetCondFactory : public ConditionFactory {
+ public:
+ /*!
+ * @brief Constructor.
+ */
+ ViaTargetCondFactory();
+
+ /*!
+ * @brief The name of the action.
+ *
+ * The action's name must be unique among all registered actions.
+ * Each action factory must override this function.
+ *
+ * @returns A string containing the unique action name.
+ */
+ virtual const char * name() const { return "via"; }
+ /*!
+ * @brief A description of the action.
+ *
+ * Each action factory must override this function.
+ *
+ * @returns A string containing the action description.
+ */
+ virtual const char * description() const {
+ return "The Quad condition. returns true if agent is within a radius of one of quadrotors";
+ }
+
+
+ protected:
+ /*!
+ * @brief Create an instance of this class's condition.
+ *
+ * All ConditionFactory sub-classes must override this by creating (on the heap)
+ * a new instance of its corresponding condition type. The various field values
+ * of the instance will be set in a subsequent call to ConditionFactory::setFromXML.
+ * The caller of this function takes ownership of the memory.
+ *
+ * @returns A pointer to a newly instantiated Action class.
+ */
+ virtual Condition * instance() const { return new ViaTargetCondition(); }
+
+ /*!
+ * @brief Given a pointer to an Condition instance, sets the appropriate fields
+ * from the provided XML node.
+ *
+ * It is assumed that the value of the `type` attribute is this Tarnsitions's type.
+ * (i.e. ConditionFactory::thisFactory has already been called and returned true.)
+ * If sub-classes of ConditionFactory introduce *new* Condition parameters, then the
+ * sub-class should override this method but explicitly call the parent class's
+ * version.
+ *
+ * @param condition A pointer to the condition whose attributes are to be set.
+ * @param node The XML node containing the condition attributes.
+ * @param behaveFldr The path to the behavior file. If the condition references
+ * resources in the file system, it should be defined relative
+ * to the behavior file location. This is the folder containing
+ * that path.
+ * @returns A boolean reporting success (true) or failure (false).
+ */
+ virtual bool setFromXML( Condition * condition, TiXmlElement * node, const std::string & behaveFldr ) const;
+
+ /*!
+ * @brief The identifier for the minimum distance.
+ */
+ size_t _distanceID;
+
+ /*!
+ * @brief The identifier for the Agent to avoid.
+ */
+ size_t _viaGoalSetIDID;
+ };
+
+ } // namespace BFSM
+} // namespace Menge
+#endif // MENGE_MENGECORE_BFSM_TRANSITIONS_CONDVIA_H_
diff --git a/src/Menge/MengeCore/BFSM/Transitions/ConditionDatabase.cpp b/src/Menge/MengeCore/BFSM/Transitions/ConditionDatabase.cpp
index 6267dcca..5da467a1 100644
--- a/src/Menge/MengeCore/BFSM/Transitions/ConditionDatabase.cpp
+++ b/src/Menge/MengeCore/BFSM/Transitions/ConditionDatabase.cpp
@@ -3,7 +3,7 @@
License
Menge
-Copyright © and trademark ™ 2012-14 University of North Carolina at Chapel Hill.
+Copyright � and trademark � 2012-14 University of North Carolina at Chapel Hill.
All rights reserved.
Permission to use, copy, modify, and distribute this software and its documentation
@@ -42,7 +42,9 @@ Any questions or comments should be sent to the authors {menge,geom}@cs.unc.edu
#include "Transitions/CondSpace.h"
#include "Transitions/CondGoal.h"
#include "Transitions/CondBoolean.h"
-
+#include "Transitions/CondProximity.h"
+#include "Transitions/CondFollow.h"
+#include "Transitions/CondVia.h"
#ifndef DOXYGEN_SHOULD_SKIP_THIS
namespace Menge {
@@ -62,8 +64,11 @@ namespace Menge {
addFactory( new BFSM::AndCondFactory() );
addFactory( new BFSM::OrCondFactory() );
addFactory( new BFSM::NotCondFactory() );
+ addFactory( new BFSM::ProximityCondFactory() );
+ addFactory( new BFSM::FollowTargetCondFactory() );
+ addFactory( new BFSM::ViaTargetCondFactory() );
}
} // namespace Menge
-#endif // DOXYGEN_SHOULD_SKIP_THIS
\ No newline at end of file
+#endif // DOXYGEN_SHOULD_SKIP_THIS
diff --git a/src/Menge/MengeCore/Runtime/SimSystem.cpp b/src/Menge/MengeCore/Runtime/SimSystem.cpp
index 7352c1bf..237b8bfc 100644
--- a/src/Menge/MengeCore/Runtime/SimSystem.cpp
+++ b/src/Menge/MengeCore/Runtime/SimSystem.cpp
@@ -85,6 +85,7 @@ namespace Menge {
_isRunning = false;
} else {
for ( size_t i = 0; i <= _sim->getSubSteps(); ++i ) {
+ if(_sim->getGlobalTime()>=time) break;
try {
_isRunning = !_fsm->doStep();
} catch ( BFSM::FSMFatalException & e ) {
@@ -217,4 +218,4 @@ namespace Menge {
////////////////////////////////////////////////////////////////////////////
-} // namespace Menge
\ No newline at end of file
+} // namespace Menge
diff --git a/src/Menge/MengeCore/Runtime/SimSystem.h b/src/Menge/MengeCore/Runtime/SimSystem.h
index 3347cdd7..623d85e2 100644
--- a/src/Menge/MengeCore/Runtime/SimSystem.h
+++ b/src/Menge/MengeCore/Runtime/SimSystem.h
@@ -242,6 +242,10 @@ namespace Menge {
* @returns The number of VisAgents updated by the system.
*/
size_t getAgentCount() const;
+ const Menge::Agents::SimulatorInterface* getSimulator() const
+ {
+ return _sim;
+ }
protected:
diff --git a/src/Menge/MengeCore/Runtime/SimulatorDBEntry.cpp b/src/Menge/MengeCore/Runtime/SimulatorDBEntry.cpp
index d79199ce..f5c0c5c5 100644
--- a/src/Menge/MengeCore/Runtime/SimulatorDBEntry.cpp
+++ b/src/Menge/MengeCore/Runtime/SimulatorDBEntry.cpp
@@ -3,7 +3,7 @@
License
Menge
-Copyright © and trademark ™ 2012-14 University of North Carolina at Chapel Hill.
+Copyright � and trademark � 2012-14 University of North Carolina at Chapel Hill.
All rights reserved.
Permission to use, copy, modify, and distribute this software and its documentation
@@ -52,7 +52,8 @@ Any questions or comments should be sent to the authors {menge,geom}@cs.unc.edu
#include "MengeException.h"
namespace Menge {
-
+ Agents::SimulatorInterface * SimulatorDBEntry::_sim = 0;
+ BFSM::FSM * SimulatorDBEntry::_fsm = 0;
/////////////////////////////////////////////////////////////////////////////
// Implementation of SimulatorDBEntry
////////////////////////////////////////////////////////////////////////////
@@ -224,4 +225,4 @@ namespace Menge {
Agents::AgentInitializer * SimulatorDBEntry::getAgentInitalizer() const {
return new Agents::AgentInitializer();
}
-} // namespace Menge
\ No newline at end of file
+} // namespace Menge
diff --git a/src/Menge/MengeCore/Runtime/SimulatorDBEntry.h b/src/Menge/MengeCore/Runtime/SimulatorDBEntry.h
index 9df90226..b668c815 100644
--- a/src/Menge/MengeCore/Runtime/SimulatorDBEntry.h
+++ b/src/Menge/MengeCore/Runtime/SimulatorDBEntry.h
@@ -3,7 +3,7 @@
License
Menge
-Copyright © and trademark ™ 2012-14 University of North Carolina at Chapel Hill.
+Copyright � and trademark � 2012-14 University of North Carolina at Chapel Hill.
All rights reserved.
Permission to use, copy, modify, and distribute this software and its documentation
@@ -287,14 +287,17 @@ namespace Menge {
* @brief A pointer to the simulator. The database entry is not responsible for
* deleting it unless there is an error in initialization.
*/
- Agents::SimulatorInterface * _sim;
+
/*!
* @brief A pointer to the behavior finite state machine. The database entry is *not*
* responsible for deleting it unless there is an error in initialization.
*/
- BFSM::FSM * _fsm;
+
+ public:
+ static BFSM::FSM * _fsm;
+ static Agents::SimulatorInterface * _sim;
};
} // namespace Menge
-#endif // __SIMULATOR_DB_ENTRY_H__
\ No newline at end of file
+#endif // __SIMULATOR_DB_ENTRY_H__
diff --git a/src/Menge/include/macros.h b/src/Menge/include/macros.h
index 44071e92..0179c10b 100644
--- a/src/Menge/include/macros.h
+++ b/src/Menge/include/macros.h
@@ -21,7 +21,6 @@
#include
#include
-
//FIXME: this should be handle automatically by cmake
#define sprintf_s(buffer, buffer_size, stringbuffer, ...) (snprintf(buffer,buffer_size ,stringbuffer, __VA_ARGS__))
#define sscanf_s(buffer, buffer_size, stringbuffer, ...) (snprintf(buffer,buffer_size ,stringbuffer, __VA_ARGS__))
@@ -30,13 +29,17 @@
#ifndef DWORD
#define WINAPI
-typedef unsigned long DWORD;
+//typedef unsigned long DWORD;
+typedef uint32_t DWORD;
typedef short WCHAR;
typedef void * HANDLE;
//#define MAX_PATH PATH_MAX
-typedef unsigned char BYTE;
-typedef unsigned short WORD;
-typedef unsigned int BOOL;
+typedef uint8_t BYTE;
+//typedef unsigned char BYTE;
+//typedef unsigned short WORD;
+typedef uint16_t WORD;
+typedef int32_t BOOL;
+//typedef unsigned int BOOL;
#endif
#ifdef UNICODE