/
xAgeSDLVarSet.py
145 lines (117 loc) · 6.67 KB
/
xAgeSDLVarSet.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
# -*- 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: xAgeSDLVarSet.py
Age: Global
Date: March, 2003
Author: Adam Van Ornum
"""
from Plasma import *
from PlasmaTypes import *
# define the attributes that will be entered in max
# NOTE: The state value tuples string should be a string of value pairs
# where the pairs are enclosed by parentheses and values separated by a comma.
# The pairs must not be separated by a comma or any character other than a space.
# Mixing spaces in anywhere is fine because they will just be removed.
# Example string: (0,0)(1,1)(2,0)
# The first value is a state, and the second value is the value to set in that particular state.
stringSDLVarName = ptAttribString(1,"Age SDL Variable")
stringSDLVarToSet = ptAttribString(2,"SDL Variable To Set")
stringStartStates = ptAttribString(3,"State value tuples")
stringTag = ptAttribString(4, "Extra info to pass along")
intDefault = ptAttribInt(5,"Default setting",0)
class xAgeSDLVarSet(ptResponder):
def __init__(self):
ptModifier.__init__(self)
self.id = 5303
version = 2
self.version = version
self.enabledStateDict = {}
PtDebugPrint("__init__xAgeSDLVarSet v.", version)
def OnFirstUpdate(self):
if not stringSDLVarName.value:
PtDebugPrint("ERROR: xAgeSDLVarSet.OnFirstUpdate():\tERROR: missing SDL var name in max file")
pass
def OnServerInitComplete(self):
ageSDL = PtGetAgeSDL()
ageSDL.setFlags(stringSDLVarToSet.value,1,1)
ageSDL.sendToClients(stringSDLVarToSet.value)
PtDebugPrint("DEBUG: xAgeSDLVarSet.OnServerInitComplete:\tOn %s" % stringSDLVarName.value)
# Parse out the state, value pairs and add them to the dictionary
try:
str = stringStartStates.value.replace(" ","")
tuples = str.split(")(")
tuples[0] = tuples[0][1:]
tuples[-1] = tuples[-1][:-1]
for tup in tuples:
vals = tup.split(",")
self.enabledStateDict[int(vals[0])] = int(vals[1])
except:
PtDebugPrint("ERROR: xAgeSDLVarSet.OnServerInitComplete():\tERROR: couldn't process start state list")
pass
PtDebugPrint("DEBUG: xAgeSDLVarSet.OnServerInitComplete:\tSetting notify on %s" % stringSDLVarName.value)
ageSDL.setNotify(self.key,stringSDLVarName.value,0.0)
try:
SDLvalue = ageSDL[stringSDLVarName.value][0]
except:
PtDebugPrint("ERROR: xAgeSDLVarSet.OnServerInitComplete():\tERROR: age sdl read failed, SDLvalue = %d by default. stringSDLVarName = %s" % (intDefault.value,stringSDLVarName.value))
SDLvalue = intDefault.value
PtDebugPrint("DEBUG: xAgeSDLVarSet.OnServerInitComplete:\tCurrent SDL value = %d" % SDLvalue)
# Check if the current SDL value represents a state in the dictionary and set the other SDL value to the value in the dictionary (yay for values!)
if int(SDLvalue) in self.enabledStateDict:
ageSDL[stringSDLVarToSet.value] = (self.enabledStateDict[int(SDLvalue)],)
if stringSDLVarToSet:
ageSDL.setTagString(stringSDLVarToSet.value,stringTag.value)
PtDebugPrint("DEBUG: xAgeSDLVarSet.OnServerInitComplete:\t%s setting %s to %d" % (stringSDLVarName.value, stringSDLVarToSet.value, self.enabledStateDict[int(SDLvalue)]))
# If the value is not in the dictionary then just set the state to 0
#else:
# ageSDL[stringSDLVarToSet.value] = (0,)
# PtDebugPrint("xAgeSDLVarSet.OnServerInitComplete:\t%s setting %s to 0" % (stringSDLVarName.value, stringSDLVarToSet.value))
def OnSDLNotify(self,VARname,SDLname,PlayerID,tag):
if VARname != stringSDLVarName.value:
return
ageSDL = PtGetAgeSDL()
PtDebugPrint("DEBUG: xAgeSDLVarSet.OnSDLNotify received: %s" % VARname)
SDLvalue = ageSDL[stringSDLVarName.value][0]
# Check if the current SDL value represents a state in the dictionary and set the other SDL value to the value in the dictionary (yay for values!)
if int(SDLvalue) in self.enabledStateDict:
ageSDL[stringSDLVarToSet.value] = (self.enabledStateDict[int(SDLvalue)],)
if stringSDLVarToSet:
ageSDL.setTagString(stringSDLVarToSet.value,stringTag.value)
PtDebugPrint("DEBUG: xAgeSDLVarSet.OnServerInitComplete:\t%s setting %s to %d, tag string: %s" % (stringSDLVarName.value, stringSDLVarToSet.value, self.enabledStateDict[int(SDLvalue)], stringTag.value))
# If the value is not in the dictionary then just set the state to 0
#else:
# ageSDL[stringSDLVarToSet.value] = (0,)
# PtDebugPrint("xAgeSDLVarSet.OnServerInitComplete:\t%s setting %s to 0" % (stringSDLVarName.value, stringSDLVarToSet.value))