Filling in branch from trunk
[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()
87 {
88         // bool result = false;  /*unused*/
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_ketsjiengine->SetNameNextGame(m_filename);
117                                 m_scene->AddDebugProperty((this)->GetParent(), exitstring);
118                         }
119                         break;
120                 }
121         case KX_GAME_QUIT:
122                 {
123                         if (m_ketsjiengine)
124                         {
125                                 STR_String exitstring = "quiting game";
126                                 m_ketsjiengine->RequestExit(KX_EXIT_REQUEST_QUIT_GAME);
127                                 m_scene->AddDebugProperty((this)->GetParent(), exitstring);
128                         }
129                         break;
130                 }
131         default:
132                 ; /* do nothing? this is an internal error !!! */
133         }
134         
135         return false;
136 }
137
138
139
140
141
142 /* ------------------------------------------------------------------------- */
143 /* Python functions                                                          */
144 /* ------------------------------------------------------------------------- */
145
146 /* Integration hooks ------------------------------------------------------- */
147 PyTypeObject KX_GameActuator::Type = {
148         PyObject_HEAD_INIT(&PyType_Type)
149                 0,
150                 "KX_GameActuator",
151                 sizeof(KX_GameActuator),
152                 0,
153                 PyDestructor,
154                 0,
155                 __getattr,
156                 __setattr,
157                 0, //&MyPyCompare,
158                 __repr,
159                 0, //&cvalue_as_number,
160                 0,
161                 0,
162                 0,
163                 0
164 };
165
166
167
168 PyParentObject KX_GameActuator::Parents[] =
169 {
170         &KX_GameActuator::Type,
171                 &SCA_IActuator::Type,
172                 &SCA_ILogicBrick::Type,
173                 &CValue::Type,
174                 NULL
175 };
176
177
178
179 PyMethodDef KX_GameActuator::Methods[] =
180 {
181         {"getFile",     (PyCFunction) KX_GameActuator::sPyGetFile, METH_VARARGS, GetFile_doc},
182         {"setFile", (PyCFunction) KX_GameActuator::sPySetFile, METH_VARARGS, SetFile_doc},
183         {NULL,NULL} //Sentinel
184 };
185
186 /* getFile */
187 char KX_GameActuator::GetFile_doc[] = 
188 "getFile()\n"
189 "get the name of the file to start.\n";
190 PyObject* KX_GameActuator::PyGetFile(PyObject* self, PyObject* args, PyObject* kwds)
191 {       
192         return PyString_FromString(m_filename);
193 }
194
195 /* setFile */
196 char KX_GameActuator::SetFile_doc[] =
197 "setFile(name)\n"
198 "set the name of the file to start.\n";
199 PyObject* KX_GameActuator::PySetFile(PyObject* self, PyObject* args, PyObject* kwds)
200 {
201         char* new_file;
202         
203         if (!PyArg_ParseTuple(args, "s", &new_file))
204         {
205                 return NULL;
206         }
207         
208         m_filename = STR_String(new_file);
209
210         Py_Return;
211
212 }
213         
214
215
216 PyObject* KX_GameActuator::_getattr(const STR_String& attr)
217 {
218         _getattr_up(SCA_IActuator);
219 }
220
221