use const for readonly strings and set some functions to static
[blender.git] / source / gameengine / Converter / KX_ConvertActuators.cpp
index 8fc224f..f4b1737 100644 (file)
@@ -1,6 +1,4 @@
 /*
-* $Id$
-*
  * ***** BEGIN GPL LICENSE BLOCK *****
  *
  * This program is free software; you can redistribute it and/or
@@ -25,8 +23,8 @@
  * Contributor(s): none yet.
  *
  * ***** END GPL LICENSE BLOCK *****
-* Convert Blender actuators for use in the GameEngine
-*/
+ * Convert Blender actuators for use in the GameEngine
+ */
 
 /** \file gameengine/Converter/KX_ConvertActuators.cpp
  *  \ingroup bgeconv
@@ -72,6 +70,7 @@
 #include "KX_SCA_ReplaceMeshActuator.h"
 #include "KX_ParentActuator.h"
 #include "KX_SCA_DynamicActuator.h"
+#include "KX_SteeringActuator.h"
 
 #include "KX_Scene.h"
 #include "KX_KetsjiEngine.h"
 #include "BL_ActionActuator.h"
 #include "BL_ShapeActionActuator.h"
 #include "BL_ArmatureActuator.h"
+#include "RNA_access.h"
 #include "BL_Action.h"
 /* end of blender include block */
 
@@ -111,7 +111,7 @@ KX_BLENDERTRUNC needed to round 'almost' zero values to zero, else velocities et
 
 #define KX_BLENDERTRUNC(x)  (( x < 0.0001 && x > -0.0001 )  ? 0.0 : x)
 
-void BL_ConvertActuators(char* maggiename,
+void BL_ConvertActuators(const char* maggiename,
                                                 struct Object* blenderobject,
                                                 KX_GameObject* gameobj,
                                                 SCA_LogicManager* logicmgr,
@@ -413,14 +413,21 @@ void BL_ConvertActuators(char* maggiename,
                                                // if sound shall be 3D but isn't mono, we have to make it mono!
                                                if(is3d)
                                                {
-                                                       AUD_Reference<AUD_IReader> reader = snd_sound->createReader();
-                                                       if(reader->getSpecs().channels != AUD_CHANNELS_MONO)
+                                                       try
+                                                       {
+                                                               AUD_Reference<AUD_IReader> reader = snd_sound->createReader();
+                                                               if(reader->getSpecs().channels != AUD_CHANNELS_MONO)
+                                                               {
+                                                                       AUD_DeviceSpecs specs;
+                                                                       specs.channels = AUD_CHANNELS_MONO;
+                                                                       specs.rate = AUD_RATE_INVALID;
+                                                                       specs.format = AUD_FORMAT_INVALID;
+                                                                       snd_sound = new AUD_ChannelMapperFactory(snd_sound, specs);
+                                                               }
+                                                       }
+                                                       catch(AUD_Exception&)
                                                        {
-                                                               AUD_DeviceSpecs specs;
-                                                               specs.channels = AUD_CHANNELS_MONO;
-                                                               specs.rate = AUD_RATE_INVALID;
-                                                               specs.format = AUD_FORMAT_INVALID;
-                                                               snd_sound = new AUD_ChannelMapperFactory(snd_sound, specs);
+                                                               // sound cannot be played... ignore
                                                        }
                                                }
                                        }
@@ -1057,6 +1064,45 @@ void BL_ConvertActuators(char* maggiename,
                                baseact = tmparmact;
                                break;
                        }
+               case ACT_STEERING:
+                       {
+                               bSteeringActuator *stAct = (bSteeringActuator *) bact->data;
+                               KX_GameObject *navmeshob = NULL;
+                               if (stAct->navmesh)
+                               {
+                                       PointerRNA settings_ptr;
+                                       RNA_pointer_create((ID *)stAct->navmesh, &RNA_GameObjectSettings, stAct->navmesh, &settings_ptr);
+                                       if (RNA_enum_get(&settings_ptr, "physics_type") == OB_BODY_TYPE_NAVMESH)
+                                               navmeshob = converter->FindGameObject(stAct->navmesh);
+                               }
+                               KX_GameObject *targetob = converter->FindGameObject(stAct->target);
+
+                               int mode = KX_SteeringActuator::KX_STEERING_NODEF;
+                               switch(stAct->type)
+                               {
+                               case ACT_STEERING_SEEK:
+                                       mode = KX_SteeringActuator::KX_STEERING_SEEK;
+                                       break;
+                               case ACT_STEERING_FLEE:
+                                       mode = KX_SteeringActuator::KX_STEERING_FLEE;
+                                       break;
+                               case ACT_STEERING_PATHFOLLOWING:
+                                       mode = KX_SteeringActuator::KX_STEERING_PATHFOLLOWING;
+                                       break;
+                               }
+
+                               bool selfTerminated = (stAct->flag & ACT_STEERING_SELFTERMINATED) !=0;
+                               bool enableVisualization = (stAct->flag & ACT_STEERING_ENABLEVISUALIZATION) !=0;
+                               short facingMode = (stAct->flag & ACT_STEERING_AUTOMATICFACING) ? stAct->facingaxis : 0;
+                               bool normalup = (stAct->flag & ACT_STEERING_NORMALUP) !=0;
+                               KX_SteeringActuator *tmpstact
+                                       = new KX_SteeringActuator(gameobj, mode, targetob, navmeshob,stAct->dist, 
+                                       stAct->velocity, stAct->acceleration, stAct->turnspeed, 
+                                       selfTerminated, stAct->updateTime,
+                                       scene->GetObstacleSimulation(), facingMode, normalup, enableVisualization);
+                               baseact = tmpstact;
+                               break;
+                       }
                default:
                        ; /* generate some error */
                }