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