Last of the config.h mods...
[blender.git] / source / gameengine / Ketsji / KX_GameActuator.cpp
1 /**
2 * global game stuff
3 *
4 * $Id$
5 *
6  * ***** BEGIN GPL/BL DUAL 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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, 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/BL DUAL LICENSE BLOCK *****
33 */
34
35 #include "SCA_IActuator.h"
36 #include "KX_GameActuator.h"
37 //#include <iostream>
38 #include "KX_Scene.h"
39 #include "KX_KetsjiEngine.h"
40
41 #ifdef HAVE_CONFIG_H
42 #include <config.h>
43 #endif
44
45 /* ------------------------------------------------------------------------- */
46 /* Native functions                                                          */
47 /* ------------------------------------------------------------------------- */
48
49 KX_GameActuator::KX_GameActuator(SCA_IObject *gameobj, 
50                                                                    int mode,
51                                                                    const STR_String& filename,
52                                                                    const STR_String& loadinganimationname,
53                                                                    KX_Scene* scene,
54                                                                    KX_KetsjiEngine* ketsjiengine,
55                                                                    PyTypeObject* T)
56                                                                    : SCA_IActuator(gameobj, T)
57 {
58         m_mode = mode;
59         m_filename = filename;
60         m_loadinganimationname = loadinganimationname;
61         m_scene = scene;
62         m_ketsjiengine = ketsjiengine;
63 } /* End of constructor */
64
65
66
67 KX_GameActuator::~KX_GameActuator()
68
69         // there's nothing to be done here, really....
70 } /* end of destructor */
71
72
73
74 CValue* KX_GameActuator::GetReplica()
75 {
76         KX_GameActuator* replica = new KX_GameActuator(*this);
77         replica->ProcessReplica();
78         // this will copy properties and so on...
79         CValue::AddDataToReplica(replica);
80         
81         return replica;
82 }
83
84
85
86 bool KX_GameActuator::Update(double curtime, double deltatime)
87 {
88         bool result = false;    
89         bool bNegativeEvent = IsNegativeEvent();
90         RemoveAllEvents();
91
92         if (bNegativeEvent)
93                 return false; // do nothing on negative events
94
95         switch (m_mode)
96         {
97         case KX_GAME_LOAD:
98         case KX_GAME_START:
99                 {
100                         if (m_ketsjiengine)
101                         {
102                                 STR_String exitstring = "start other game";
103                                 m_ketsjiengine->RequestExit(KX_EXIT_REQUEST_START_OTHER_GAME);
104                                 m_ketsjiengine->SetNameNextGame(m_filename);
105                                 m_scene->AddDebugProperty((this)->GetParent(), exitstring);
106                         }
107
108                         break;
109                 }
110         case KX_GAME_RESTART:
111                 {
112                         if (m_ketsjiengine)
113                         {
114                                 STR_String exitstring = "restarting game";
115                                 m_ketsjiengine->RequestExit(KX_EXIT_REQUEST_RESTART_GAME);
116                                 m_scene->AddDebugProperty((this)->GetParent(), exitstring);
117                         }
118                         break;
119                 }
120         case KX_GAME_QUIT:
121                 {
122                         if (m_ketsjiengine)
123                         {
124                                 STR_String exitstring = "quiting game";
125                                 m_ketsjiengine->RequestExit(KX_EXIT_REQUEST_QUIT_GAME);
126                                 m_scene->AddDebugProperty((this)->GetParent(), exitstring);
127                         }
128                         break;
129                 }
130         default:
131                 ; /* do nothing? this is an internal error !!! */
132         }
133         
134         return false;
135 }
136
137
138
139
140
141 /* ------------------------------------------------------------------------- */
142 /* Python functions                                                          */
143 /* ------------------------------------------------------------------------- */
144
145 /* Integration hooks ------------------------------------------------------- */
146 PyTypeObject KX_GameActuator::Type = {
147         PyObject_HEAD_INIT(&PyType_Type)
148                 0,
149                 "KX_SceneActuator",
150                 sizeof(KX_GameActuator),
151                 0,
152                 PyDestructor,
153                 0,
154                 __getattr,
155                 __setattr,
156                 0, //&MyPyCompare,
157                 __repr,
158                 0, //&cvalue_as_number,
159                 0,
160                 0,
161                 0,
162                 0
163 };
164
165
166
167 PyParentObject KX_GameActuator::Parents[] =
168 {
169         &KX_GameActuator::Type,
170                 &SCA_IActuator::Type,
171                 &SCA_ILogicBrick::Type,
172                 &CValue::Type,
173                 NULL
174 };
175
176
177
178 PyMethodDef KX_GameActuator::Methods[] =
179 {
180         {NULL,NULL} //Sentinel
181 };
182
183
184
185 PyObject* KX_GameActuator::_getattr(char* attr)
186 {
187         _getattr_up(SCA_IActuator);
188 }
189
190