forked from ValveSoftware/source-sdk-2013
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathentities.py
More file actions
151 lines (132 loc) · 4.73 KB
/
Copy pathentities.py
File metadata and controls
151 lines (132 loc) · 4.73 KB
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
from _entitiesmisc import *
from _entities import *
from core.fields import SetupClassFields, SetupInputMethods
# Lists of all entity classes
if isclient:
list_ents = [
C_BaseEntity,
C_BaseAnimating,
C_BaseAnimatingOverlay,
C_BaseFlex,
C_BaseCombatCharacter,
C_BaseGrenade,
C_BasePlayer,
C_BaseCombatWeapon,
]
# List of aliases
CBaseEntity = C_BaseEntity
CBaseAnimating = C_BaseAnimating
CBaseAnimatingOverlay = C_BaseAnimatingOverlay
CBaseFlex = C_BaseFlex
CBaseCombatCharacter = C_BaseCombatCharacter
CBaseGrenade = C_BaseGrenade
CBasePlayer = C_BasePlayer
CBaseCombatWeapon = C_BaseCombatWeapon
# Server only, add an alias anyway (for convenience)
CPointEntity = CBaseEntity
# Client sub
entlist = None
else:
list_ents = [
CBaseEntity,
CBaseAnimating,
CBaseAnimatingOverlay,
CBaseFlex,
CBaseCombatCharacter,
CBaseGrenade,
CBasePlayer,
CPointEntity,
CServerOnlyEntity,
CServerOnlyPointEntity,
CLogicalEntity,
CFuncBrush,
CBaseToggle,
CBaseTrigger,
# TODO CTriggerMultiple,
CBaseCombatWeapon,
# TODO CBaseFilter,
]
# Friendly aliases
eventqueue = g_EventQueue if isserver else None
@classmethod
def InitEntityClass(cls):
""" Entity Class initializer, could be seen as a metaclass.
It is called when the class is created and when a new map is loaded.
Used for one time initializations per map.
"""
SetupClassFields(cls)
SetupInputMethods(cls)
# Bind the following methods to each entity class
for cls in list_ents:
# InitEntityClass: Called on level initialization and on the first time the entity factory is initialized.
cls.InitEntityClass = InitEntityClass
clstoclstype = {
'CBaseEntity' : ('@PointClass', ['Targetname', 'Origin']),
'CFuncBrush' : ('@SolidClass', ['Targetname', 'Parentname', 'Origin', 'RenderFields', 'Global', 'Inputfilter', 'EnableDisable', 'Shadow']),
'CBaseTrigger' : ('@SolidClass', ['Targetname', 'Parentname', 'Origin', 'RenderFields', 'Global', 'Inputfilter', 'EnableDisable', 'Shadow']),
'CBaseFilter' : ('@FilterClass', ['BaseFilter']),
}
def DetermineClsType(cls):
if cls.__name__ in clstoclstype:
return clstoclstype[cls.__name__]
for basecls in cls.__bases__:
rs = DetermineClsType(basecls)
if rs:
return rs
return None
def networked(cls):
""" Makes the class networked, which can serve as a base for entities which don't need to be
networked. """
if 'networkinst' not in cls.__dict__:
networkname = '%s.__%s' % (cls.__module__, cls.__name__)
cls.networkinst = NetworkedClass(networkname, cls)
return cls
def entity( clsname,
networked=False,
helpstring='',
clstype='',
entityextraproperties='',
base=[],
studio='',
iconsprite='',
cylinder=[],
color='',
size='',
cppproperties='',
nofgdentry=False):
""" Decorator for turning a class into an entity.
The class entity must be derived from CBaseEntity. """
def wrapcls(cls):
# FIXME: This creates a circular reference between the class and factory/network instance
# Although new factories will remove the old factories, it does not clean up nicely yet.
factoryname = 'factory__%s' % (clsname)
factory = EntityFactory(clsname, cls)
factory.entityname = clsname
factory.clstype = clstype
factory.entityextraproperties = entityextraproperties
factory.cppproperties = cppproperties
factory.helpstring = helpstring
factory.nofgdentry = nofgdentry
factory.fgdbase = base
factory.fgdstudio = studio
factory.fgdiconsprite = iconsprite
factory.fgdcylinder = cylinder
factory.fgdcolor = color
factory.fgdsize = size
setattr(cls, factoryname, factory)
if not factory.clstype:
info = DetermineClsType(cls)
if info:
factory.clstype = info[0]
else:
info = None
if not factory.fgdbase:
if info:
factory.fgdbase = info[1]
if networked and 'networkinst' not in cls.__dict__:
networkname = '%s.__%s' % (cls.__module__, cls.__name__)
cls.networkinst = NetworkedClass(networkname, cls)
# Initialize the class so the fields are setup
cls.InitEntityClass()
return cls
return wrapcls