/
xTelescope.py
225 lines (190 loc) · 8.34 KB
/
xTelescope.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
# -*- coding: utf-8 -*-
""" *==LICENSE==*
CyanWorlds.com Engine - MMOG client, server and tools
Copyright (C) 2011 Cyan Worlds, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Additional permissions under GNU GPL version 3 section 7
If you modify this Program, or any covered work, by linking or
combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK,
NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent
JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK
(or a modified version of those libraries),
containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA,
PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG
JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the
licensors of this Program grant you additional
permission to convey the resulting work. Corresponding Source for a
non-source form of such a combination shall include the source code for
the parts of OpenSSL and IJG JPEG Library used as well as that of the covered
work.
You can contact Cyan Worlds, Inc. by email legal@cyan.com
or by snail mail at:
Cyan Worlds, Inc.
14617 N Newport Hwy
Mead, WA 99021
*==LICENSE==* """
"""
Module: xTelescope
Age: global
Date: April 9, 2002
Author: Mark DeForest, Bill Slease, Doug McBride
This is tha handler for the standard telescope
"""
from Plasma import *
from PlasmaTypes import *
from PlasmaKITypes import *
import PlasmaControlKeys
# define the attributes that will be entered in max
Activate = ptAttribActivator(1, "Activate Telescope",netForce=1)
Camera = ptAttribSceneobject(2,"Telescope camera")
Behavior = ptAttribBehavior(3, "Telescope behavior (multistage)",netForce=1)
Vignette = ptAttribString(4,"Vignette dialog - by Name")
# ---------
# globals
LocalAvatar = None
boolScopeOperator = 0
boolOperated = 0
Telescope = ptInputInterface()
class xTelescope(ptModifier):
"Standard telescope modifier class"
def __init__(self):
ptModifier.__init__(self)
self.id = 201
version = 4
minorVersion = 2
self.version = version
PtDebugPrint("__init__xTelescope v%d.%d" % (version,minorVersion) )
def OnFirstUpdate(self):
self.SDL.setDefault("boolOperated",(0,))
self.SDL.setDefault("OperatorID",(-1,))
self.SDL.sendToClients("boolOperated")
self.SDL.sendToClients("OperatorID")
def Load(self):
global boolScopeOperated
solo = PtIsSolo()
boolOperated = self.SDL["boolOperated"][0]
if boolOperated:
if solo:
PtDebugPrint("xTelescope.Load():\tboolOperated=%d but no one else here...correcting" % boolOperated,level=kDebugDumpLevel)
boolOperated = 0
self.SDL["boolOperated"] = (0,)
self.SDL["OperatorID"] = (-1,)
Activate.enable()
else:
Activate.disable()
PtDebugPrint("xTelescope.Load():\tboolOperated=%d, disabling telescope clickable" % boolOperated,level=kDebugDumpLevel)
def AvatarPage(self, avObj, pageIn, lastOut):
"reset scope accessibility if scope user quits or crashes"
global boolScopeOperated
if pageIn:
return
avID = PtGetClientIDFromAvatarKey(avObj.getKey())
if avID == self.SDL["OperatorID"][0]:
Activate.enable()
self.SDL["OperatorID"] = (-1,)
self.SDL["boolOperated"] = (0,)
PtDebugPrint("xTelescope.AvatarPage(): telescope operator paged out, reenabled telescope.",level=kDebugDumpLevel)
else:
return
def __del__(self):
"unload the dialog that we loaded"
PtUnloadDialog(Vignette.value)
def OnNotify(self,state,id,events):
"Activated... start telescope"
global LocalAvatar
global boolScopeOperator
PtDebugPrint("xTelescope:OnNotify state=%f id=%d events=" % (state,id),events,level=kDebugDumpLevel)
if state and id == Activate.id and PtWasLocallyNotified(self.key):
LocalAvatar = PtFindAvatar(events)
self.IStartTelescope()
# check if its an advance stage notify
for event in events:
if event[0] == kMultiStageEvent and event[1] == 0 and event[2] == kAdvanceNextStage:
if boolScopeOperator:
self.IEngageTelescope()
boolScopeOperator = 0
break
def OnGUINotify(self,id,control,event):
"Notifications from the vignette"
PtDebugPrint("GUI Notify id=%d, event=%d control=" % (id,event),control,level=kDebugDumpLevel)
if event == kDialogLoaded:
# if the dialog was just loaded then show it
control.show()
def OnControlKeyEvent(self,controlKey,activeFlag):
if controlKey == PlasmaControlKeys.kKeyExitMode:
self.IQuitTelescope()
elif controlKey == PlasmaControlKeys.kKeyMoveBackward or controlKey == PlasmaControlKeys.kKeyRotateLeft or controlKey == PlasmaControlKeys.kKeyRotateRight:
self.IQuitTelescope()
def IStartTelescope(self):
"Start the action of looking at the telescope"
global LocalAvatar
global boolScopeOperator
# disable the activator (only one in the telescope at a time)
PtSendKIMessage(kDisableKIandBB,0)
Activate.disable()
boolScopeOperator = 1 # me! I'm the operator
self.SDL["boolOperated"] = (1,)
avID = PtGetClientIDFromAvatarKey(LocalAvatar.getKey())
self.SDL["OperatorID"] = (avID,)
PtDebugPrint("xTelescope.OnNotify:\twrote SDL - scope operator id = ", avID,level=kDebugDumpLevel)
# start the behavior
Behavior.run(LocalAvatar)
def IEngageTelescope(self):
global Telescope
Telescope.pushTelescope()
"After the behavior gets our eyes in the telescope, engage ourselves with the camera"
# Disable First Person Camera
cam = ptCamera()
cam.undoFirstPerson()
cam.disableFirstPersonOverride()
# set camera to telescope
virtCam = ptCamera()
virtCam.save(Camera.sceneobject.getKey())
# show the cockpit
if Vignette.value:
PtLoadDialog(Vignette.value,self.key)
if ( PtIsDialogLoaded(Vignette.value) ):
PtShowDialog(Vignette.value)
# get control key events
PtEnableControlKeyEvents(self.key)
def IQuitTelescope(self):
"Disengage and exit the telescope mode"
global LocalAvatar
global boolScopeOperator
global Telescope
Telescope.popTelescope()
# exit every thing
if Vignette.value:
PtHideDialog(Vignette.value)
virtCam = ptCamera()
virtCam.restore(Camera.sceneobject.getKey())
PtRecenterCamera()
# exit behavior...which is in the next stage
# ... but just gotoStage the last stage by number because of a bug in the SDL send state
Behavior.gotoStage(LocalAvatar,2)
#Behavior.nextStage(LocalAvatar)
#disable the Control key events
PtDisableControlKeyEvents(self.key)
# re-enable the telescope for someone else to use
boolScopeOperator = 0
self.SDL["boolOperated"] = (0,)
self.SDL["OperatorID"] = (-1,)
#Re-enable first person camera
cam = ptCamera()
cam.enableFirstPersonOverride()
PtAtTimeCallback(self.key,3,1) # wait for player to finish exit one-shot, then reenable clickable
PtDebugPrint("xTelescope.IQuitTelescope:\tdelaying clickable reenable",level=kDebugDumpLevel)
def OnTimer(self,id):
if id==1:
Activate.enable()
PtDebugPrint("xTelescope.OnTimer:\tclickable reenabled",level=kDebugDumpLevel)
PtSendKIMessage(kEnableKIandBB,0)