synched with trunk at revision 32129
[blender.git] / source / gameengine / Ketsji / KX_SteeringActuator.h
1 /**
2 * Add steering behaviors
3 *
4 *
5 * $Id$
6 *
7 * ***** BEGIN GPL LICENSE BLOCK *****
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version. The Blender
13 * Foundation also sells licenses for use in proprietary software under
14 * the Blender License.  See http://www.blender.org/BL/ for information
15 * about this.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software Foundation,
24 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 *
26 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
27 * All rights reserved.
28 *
29 * The Original Code is: all of this file.
30 *
31 * Contributor(s): none yet.
32 *
33 * ***** END GPL LICENSE BLOCK *****
34 */
35
36 #ifndef __KX_STEERINGACTUATOR
37 #define __KX_STEERINGACTUATOR
38
39 #include "SCA_IActuator.h"
40 #include "SCA_LogicManager.h"
41 #include "MT_Matrix3x3.h"
42
43 class KX_GameObject;
44 class KX_NavMeshObject;
45 struct KX_Obstacle;
46 class KX_ObstacleSimulation;
47 const int MAX_PATH_LENGTH  = 128;
48
49 class KX_SteeringActuator : public SCA_IActuator
50 {
51         Py_Header;
52
53         /** Target object */
54         KX_GameObject *m_target;
55         KX_NavMeshObject *m_navmesh;
56         int     m_mode;
57         float m_distance;
58         float m_velocity;
59         float m_acceleration;                                                                   
60         float m_turnspeed;
61         KX_ObstacleSimulation* m_simulation;
62         
63         KX_Obstacle* m_obstacle;
64         double m_updateTime;
65         bool m_isActive;
66         bool m_isSelfTerminated;
67         bool m_enableVisualization;
68         short m_facingMode;
69         bool m_normalUp;
70         float m_path[MAX_PATH_LENGTH*3];
71         int m_pathLen;
72         int m_pathUpdatePeriod;
73         double m_pathUpdateTime;
74         int m_wayPointIdx;
75         MT_Matrix3x3 m_parentlocalmat;
76         MT_Vector3 m_steerVec;
77         void HandleActorFace(MT_Vector3& velocity);
78 public:
79         enum KX_STEERINGACT_MODE
80         {
81                 KX_STEERING_NODEF = 0,
82                 KX_STEERING_SEEK,
83                 KX_STEERING_FLEE,
84                 KX_STEERING_PATHFOLLOWING,
85                 KX_STEERING_MAX
86         };
87
88         KX_SteeringActuator(class SCA_IObject* gameobj,
89                                                 int mode,
90                                                 KX_GameObject *target, 
91                                                 KX_GameObject *navmesh,
92                                                 float distance,
93                                                 float velocity, 
94                                                 float acceleration,                                                                     
95                                                 float turnspeed,
96                                                 bool  isSelfTerminated,
97                                                 int pathUpdatePeriod,
98                                                 KX_ObstacleSimulation* simulation,
99                                                 short facingmode,
100                                                 bool normalup,
101                                                 bool enableVisualization);
102         virtual ~KX_SteeringActuator();
103         virtual bool Update(double curtime, bool frame);
104
105         virtual CValue* GetReplica();
106         virtual void ProcessReplica();
107         virtual void Relink(GEN_Map<GEN_HashedPtr, void*> *obj_map);
108         virtual bool UnlinkObject(SCA_IObject* clientobj);
109         const MT_Vector3& GetSteeringVec();
110
111 #ifndef DISABLE_PYTHON
112
113         /* --------------------------------------------------------------------- */
114         /* Python interface ---------------------------------------------------- */
115         /* --------------------------------------------------------------------- */
116
117         /* These are used to get and set m_target */
118         static PyObject* pyattr_get_target(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef);
119         static int pyattr_set_target(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
120         static PyObject* pyattr_get_navmesh(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef);
121         static int pyattr_set_navmesh(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
122         static PyObject* pyattr_get_steeringVec(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef);
123         
124
125 #endif // DISABLE_PYTHON
126
127 }; /* end of class KX_SteeringActuator : public SCA_PropertyActuator */
128
129 #endif
130