Patch to change license to GPL only, from GSR.
[blender.git] / source / gameengine / Ketsji / KX_GameActuator.cpp
1 /**
2 * global game stuff
3 *
4 * $Id$
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.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software Foundation,
20  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
21  *
22  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
23  * All rights reserved.
24  *
25  * The Original Code is: all of this file.
26  *
27  * Contributor(s): none yet.
28  *
29  * ***** END GPL LICENSE BLOCK *****
30 */
31
32 #include "SCA_IActuator.h"
33 #include "KX_GameActuator.h"
34 //#include <iostream>
35 #include "KX_Scene.h"
36 #include "KX_KetsjiEngine.h"
37
38 #ifdef HAVE_CONFIG_H
39 #include <config.h>
40 #endif
41
42 /* ------------------------------------------------------------------------- */
43 /* Native functions                                                          */
44 /* ------------------------------------------------------------------------- */
45
46 KX_GameActuator::KX_GameActuator(SCA_IObject *gameobj, 
47                                                                    int mode,
48                                                                    const STR_String& filename,
49                                                                    const STR_String& loadinganimationname,
50                                                                    KX_Scene* scene,
51                                                                    KX_KetsjiEngine* ketsjiengine,
52                                                                    PyTypeObject* T)
53                                                                    : SCA_IActuator(gameobj, T)
54 {
55         m_mode = mode;
56         m_filename = filename;
57         m_loadinganimationname = loadinganimationname;
58         m_scene = scene;
59         m_ketsjiengine = ketsjiengine;
60 } /* End of constructor */
61
62
63
64 KX_GameActuator::~KX_GameActuator()
65
66         // there's nothing to be done here, really....
67 } /* end of destructor */
68
69
70
71 CValue* KX_GameActuator::GetReplica()
72 {
73         KX_GameActuator* replica = new KX_GameActuator(*this);
74         replica->ProcessReplica();
75         // this will copy properties and so on...
76         CValue::AddDataToReplica(replica);
77         
78         return replica;
79 }
80
81
82
83 bool KX_GameActuator::Update()
84 {
85         // bool result = false;  /*unused*/
86         bool bNegativeEvent = IsNegativeEvent();
87         RemoveAllEvents();
88
89         if (bNegativeEvent)
90                 return false; // do nothing on negative events
91
92         switch (m_mode)
93         {
94         case KX_GAME_LOAD:
95         case KX_GAME_START:
96                 {
97                         if (m_ketsjiengine)
98                         {
99                                 STR_String exitstring = "start other game";
100                                 m_ketsjiengine->RequestExit(KX_EXIT_REQUEST_START_OTHER_GAME);
101                                 m_ketsjiengine->SetNameNextGame(m_filename);
102                                 m_scene->AddDebugProperty((this)->GetParent(), exitstring);
103                         }
104
105                         break;
106                 }
107         case KX_GAME_RESTART:
108                 {
109                         if (m_ketsjiengine)
110                         {
111                                 STR_String exitstring = "restarting game";
112                                 m_ketsjiengine->RequestExit(KX_EXIT_REQUEST_RESTART_GAME);
113                                 m_ketsjiengine->SetNameNextGame(m_filename);
114                                 m_scene->AddDebugProperty((this)->GetParent(), exitstring);
115                         }
116                         break;
117                 }
118         case KX_GAME_QUIT:
119                 {
120                         if (m_ketsjiengine)
121                         {
122                                 STR_String exitstring = "quiting game";
123                                 m_ketsjiengine->RequestExit(KX_EXIT_REQUEST_QUIT_GAME);
124                                 m_scene->AddDebugProperty((this)->GetParent(), exitstring);
125                         }
126                         break;
127                 }
128         default:
129                 ; /* do nothing? this is an internal error !!! */
130         }
131         
132         return false;
133 }
134
135
136
137
138
139 /* ------------------------------------------------------------------------- */
140 /* Python functions                                                          */
141 /* ------------------------------------------------------------------------- */
142
143 /* Integration hooks ------------------------------------------------------- */
144 PyTypeObject KX_GameActuator::Type = {
145         PyObject_HEAD_INIT(&PyType_Type)
146                 0,
147                 "KX_GameActuator",
148                 sizeof(KX_GameActuator),
149                 0,
150                 PyDestructor,
151                 0,
152                 __getattr,
153                 __setattr,
154                 0, //&MyPyCompare,
155                 __repr,
156                 0, //&cvalue_as_number,
157                 0,
158                 0,
159                 0,
160                 0
161 };
162
163
164
165 PyParentObject KX_GameActuator::Parents[] =
166 {
167         &KX_GameActuator::Type,
168                 &SCA_IActuator::Type,
169                 &SCA_ILogicBrick::Type,
170                 &CValue::Type,
171                 NULL
172 };
173
174
175
176 PyMethodDef KX_GameActuator::Methods[] =
177 {
178         {"getFile",     (PyCFunction) KX_GameActuator::sPyGetFile, METH_VARARGS, GetFile_doc},
179         {"setFile", (PyCFunction) KX_GameActuator::sPySetFile, METH_VARARGS, SetFile_doc},
180         {NULL,NULL} //Sentinel
181 };
182
183 /* getFile */
184 char KX_GameActuator::GetFile_doc[] = 
185 "getFile()\n"
186 "get the name of the file to start.\n";
187 PyObject* KX_GameActuator::PyGetFile(PyObject* self, PyObject* args, PyObject* kwds)
188 {       
189         return PyString_FromString(m_filename);
190 }
191
192 /* setFile */
193 char KX_GameActuator::SetFile_doc[] =
194 "setFile(name)\n"
195 "set the name of the file to start.\n";
196 PyObject* KX_GameActuator::PySetFile(PyObject* self, PyObject* args, PyObject* kwds)
197 {
198         char* new_file;
199         
200         if (!PyArg_ParseTuple(args, "s", &new_file))
201         {
202                 return NULL;
203         }
204         
205         m_filename = STR_String(new_file);
206
207         Py_Return;
208
209 }
210         
211
212
213 PyObject* KX_GameActuator::_getattr(const STR_String& attr)
214 {
215         _getattr_up(SCA_IActuator);
216 }
217
218