forked from Source-Python-Dev-Team/Source.Python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathentities_entity.h
More file actions
491 lines (388 loc) · 12.9 KB
/
entities_entity.h
File metadata and controls
491 lines (388 loc) · 12.9 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
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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
/**
* =============================================================================
* Source Python
* Copyright (C) 2012-2015 Source Python Development Team. All rights reserved.
* =============================================================================
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, version 3.0, as published by the
* Free Software Foundation.
*
* 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/>.
*
* As a special exception, the Source Python Team gives you permission
* to link the code of this program (as well as its derivative works) to
* "Half-Life 2," the "Source Engine," and any Game MODs that run on software
* by the Valve Corporation. You must obey the GNU General Public License in
* all respects for all other code used. Additionally, the Source.Python
* Development Team grants this exception to all derivative works.
*/
#ifndef _ENTITIES_ENTITY_H
#define _ENTITIES_ENTITY_H
//-----------------------------------------------------------------------------
// Includes.
//-----------------------------------------------------------------------------
#include "boost/shared_ptr.hpp"
#include "boost/python/str.hpp"
using namespace boost::python;
#include "utilities/baseentity.h"
#include "toolframework/itoolentity.h"
// Don't remove this! It's required for the
// BOOST_PYTHON_OPAQUE_SPECIALIZED_TYPE_ID(CBaseEntity) definition.
// Otherwise you will get "undefined symbol: _ZTI11CBaseEntity".
#include "utilities/conversions.h"
//-----------------------------------------------------------------------------
// Forward declarations
//-----------------------------------------------------------------------------
class CPointer;
class IPhysicsObjectWrapper;
class CBaseEntityOutputWrapper;
//-----------------------------------------------------------------------------
// Definitions.
//-----------------------------------------------------------------------------
#define MAX_KEY_VALUE_LENGTH 1024
//-----------------------------------------------------------------------------
// External variables.
//-----------------------------------------------------------------------------
extern IServerTools* servertools;
extern CGlobalVars *gpGlobals;
//-----------------------------------------------------------------------------
// IServerUnknown extension class.
//-----------------------------------------------------------------------------
class IServerUnknownExt
{
public:
static const char* GetClassname(IServerUnknown* pUnknown);
static bool IsNetworked(IServerUnknown* pUnknown);
};
//-----------------------------------------------------------------------------
// CBaseEntity extension class.
//-----------------------------------------------------------------------------
class CBaseEntityWrapper: public IServerEntity
{
protected:
// Make sure that nobody can call the constructor/destructor
CBaseEntityWrapper() {}
~CBaseEntityWrapper() {}
public:
// We need to keep the order of these methods up-to-date and maybe we need
// to add new methods for other games.
#if defined(ENGINE_BMS)
virtual void OnNewLightSelectedFromPicker() = 0;
virtual void OnNewXogSelectedFromPicker() = 0;
#endif
virtual ServerClass* GetServerClass() = 0;
virtual int YouForgotToImplementOrDeclareServerClass() = 0;
virtual datamap_t* GetDataDescMap() = 0;
public:
static boost::shared_ptr<CBaseEntityWrapper> __init__(unsigned int uiEntityIndex);
void Initialize(object self, unsigned int uiEntityIndex);
static boost::shared_ptr<CBaseEntityWrapper> wrap(CBaseEntity* pEntity);
static CBaseEntity* create(const char* name);
static object create(object cls, const char* name);
static CBaseEntity* find(const char* name);
static object find(object cls, const char* name);
static CBaseEntity* find_or_create(const char* name);
static object find_or_create(object cls, const char* name);
CBaseEntityOutputWrapper* get_output(const char* name);
static IEntityFactory* get_factory(const char* name);
IEntityFactory* get_factory();
void remove();
bool is_marked_for_deletion();
int get_size();
void spawn();
CBaseEntity* GetThis();
bool operator==(object other);
// Datamap methods
int FindDatamapPropertyOffset(const char* name);
template<class T>
T GetDatamapProperty(const char* name)
{
return GetDatamapPropertyByOffset<T>(FindDatamapPropertyOffset(name));
}
template<class T>
T GetDatamapPropertyByOffset(int offset)
{
return *(T*) (((unsigned long) this) + offset);
}
const char* GetDatamapPropertyStringArray(const char* name)
{
return GetDatamapPropertyStringArrayByOffset(FindDatamapPropertyOffset(name));
}
const char* GetDatamapPropertyStringArrayByOffset(int offset)
{
return (const char*) (((unsigned long) this) + offset);
}
template<class T>
void SetDatamapProperty(const char* name, T value)
{
SetDatamapPropertyByOffset<T>(FindDatamapPropertyOffset(name), value);
}
template<class T>
void SetDatamapPropertyByOffset(int offset, T value)
{
*(T*) (((unsigned long) this) + offset) = value;
}
void SetDatamapPropertyStringArray(const char* name, const char* value)
{
SetDatamapPropertyStringArrayByOffset(FindDatamapPropertyOffset(name), value);
}
void SetDatamapPropertyStringArrayByOffset(int offset, const char* value)
{
strcpy((char*) (((unsigned long) this) + offset), value);
}
// Network property methods
int FindNetworkPropertyOffset(const char* name);
template<class T>
T GetNetworkProperty(const char* name)
{
return GetNetworkPropertyByOffset<T>(FindNetworkPropertyOffset(name));
}
template<class T>
T GetNetworkPropertyByOffset(int offset)
{
return *(T *) (((unsigned long) this) + offset);
}
const char* GetNetworkPropertyStringArray(const char* name)
{
return GetNetworkPropertyStringArrayByOffset(FindNetworkPropertyOffset(name));
}
const char* GetNetworkPropertyStringArrayByOffset(int offset)
{
return (const char*) (((unsigned long) this) + offset);
}
template<class T>
void SetNetworkProperty(const char* name, T value)
{
SetNetworkPropertyByOffset<T>(FindNetworkPropertyOffset(name), value);
}
template<class T>
void SetNetworkPropertyByOffset(int offset, T value)
{
*(T *) (((unsigned long) this) + offset) = value;
GetEdict()->StateChanged();
}
void SetNetworkPropertyStringArray(const char* name, const char* value)
{
SetNetworkPropertyStringArrayByOffset(FindNetworkPropertyOffset(name), value);
}
void SetNetworkPropertyStringArrayByOffset(int offset, const char* value)
{
strcpy((char*) (((unsigned long) this) + offset), value);
GetEdict()->StateChanged();
}
// Generic property getter/setter methods
template<class T>
T GetProperty(const char *name)
{
try
{
return GetNetworkProperty<T>(name);
}
catch (...)
{
if (!PyErr_ExceptionMatches(PyExc_ValueError))
throw_error_already_set();
PyErr_Clear();
return GetDatamapProperty<T>(name);
}
}
const char* GetPropertyStringArray(const char* name)
{
try
{
return GetNetworkPropertyStringArray(name);
}
catch (...)
{
if (!PyErr_ExceptionMatches(PyExc_ValueError))
throw_error_already_set();
PyErr_Clear();
return GetDatamapPropertyStringArray(name);
}
}
template<class T>
void SetProperty(const char *name, T value)
{
try
{
// Let's first lookup a networked property so we update its state, etc.
SetNetworkProperty<T>(name, value);
}
catch (...)
{
if (!PyErr_ExceptionMatches(PyExc_ValueError))
throw_error_already_set();
PyErr_Clear();
SetDatamapProperty<T>(name, value);
}
}
void SetPropertyStringArray(const char* name, const char* value)
{
try
{
// Let's first lookup a networked property so we update its state, etc.
SetNetworkPropertyStringArray(name, value);
}
catch (...)
{
if (!PyErr_ExceptionMatches(PyExc_ValueError))
throw_error_already_set();
PyErr_Clear();
SetDatamapPropertyStringArray(name, value);
}
}
// KeyValue methods
void GetKeyValueStringRaw(const char* szName, char* szOut, int iLength);
str GetKeyValueString(const char* szName);
long GetKeyValueInt(const char* szName);
double GetKeyValueFloat(const char* szName);
Vector GetKeyValueVector(const char* szName);
QAngle GetKeyValueQAngle(const char* szName);
bool GetKeyValueBool(const char* szName);
Color GetKeyValueColor(const char* szName);
void SetKeyValueColor(const char* szName, Color& color);
void SetKeyValueQAngle(const char* szName, QAngle& angles);
template<class T>
void SetKeyValue(const char* szName, T value)
{
/*
Removing this conditional/exception as it causes issues with certain entity keyvalues
*/
// if (!servertools->SetKeyValue(GetThis(), szName, value))
// BOOST_RAISE_EXCEPTION(PyExc_NameError, "\"%s\" is not a valid KeyValue for entity class \"%s\".",
// szName, GetDataDescMap()->dataClassName);
servertools->SetKeyValue(GetThis(), szName, value);
}
// Conversion methods
edict_t* GetEdict();
unsigned int GetIndex();
CPointer GetPointer();
unsigned int GetIntHandle();
IPhysicsObjectWrapper* GetPhysicsObject();
// Other methods
bool IsPlayer();
bool IsWeapon();
bool IsNetworked();
Vector GetOrigin();
void SetOrigin(Vector& vec);
Vector GetMaxs();
void SetMaxs(Vector& maxs);
Vector GetMins();
void SetMins(Vector& mins);
int GetEntityFlags();
void SetEntityFlags(int flags);
SolidType_t GetSolidType();
void SetSolidType(SolidType_t type);
unsigned short GetSolidFlags();
void SetSolidFlags(unsigned short type);
Collision_Group_t GetCollisionGroup();
void SetCollisionGroup(Collision_Group_t group);
Color GetRenderColor();
void SetRenderColor(Color& color);
float GetElasticity();
void SetElasticity(float elasticity);
int GetGroundEntity();
void SetGroundEntity(int entity);
int GetTeamIndex();
void SetTeamIndex(int team);
RenderFx_t GetRenderFx();
void SetRenderFx(RenderFx_t fx);
RenderMode_t GetRenderMode();
void SetRenderMode(RenderMode_t mode);
MoveType_t GetMoveType();
void SetMoveType(MoveType_t type);
int GetParentHandle();
void SetParentHandle(int entity);
QAngle GetAngles();
void SetAngles(QAngle& angles);
str GetTargetName();
void SetTargetName(const char* name);
int GetOwnerHandle();
void SetOwnerHandle(int entity);
Vector GetAvelocity();
void SetAvelocity(Vector& avelocity);
Vector GetBaseVelocity();
void SetBaseVelocity(Vector& base_velocity);
str GetDamageFilter();
void SetDamageFilter(const char* filter);
int GetEffects();
void SetEffects(int effects);
float GetFriction();
void SetFriction(float friction);
str GetGlobalName();
void SetGlobalName(const char* name);
float GetGravity();
void SetGravity(float gravity);
int GetHammerID();
void SetHammerID(int id);
int GetHealth();
void SetHealth(int health);
float GetLocalTime();
void SetLocalTime(float time);
int GetMaxHealth();
void SetMaxHealth(int max_health);
str GetParentName();
void SetParentName(const char* name);
float GetShadowCastDistance();
void SetShadowCastDistance(float distance);
int GetSpawnFlags();
void SetSpawnFlags(int spawn_flags);
float GetSpeed();
void SetSpeed(float speed);
str GetTarget();
void SetTarget(const char* target);
Vector GetVelocity();
void SetVelocity(Vector& velocity);
Vector GetViewOffset();
void SetViewOffset(Vector& view_offset);
unsigned char GetWaterLevel();
void SetWaterLevel(unsigned char water_level);
Color GetColor();
void SetColor(Color& color);
QAngle GetRotation();
void SetRotation(QAngle& rotation);
Vector GetEyeLocation();
void StopSound(const char* sample, int channel);
// Model stuff
MDLHandle_t get_model_handle();
studiohdr_t* get_model_header();
};
//-----------------------------------------------------------------------------
// Returns an entity pointer as a Python object.
//-----------------------------------------------------------------------------
inline object GetEntityObject(CBaseEntityWrapper *pEntity)
{
if (pEntity->IsNetworked()) {
if (pEntity->IsPlayer()) {
static object Player = import("players").attr("entity").attr("Player");
return Player(pEntity->GetIndex());
}
if (pEntity->IsWeapon()) {
static object Weapon = import("weapons").attr("entity").attr("Weapon");
return Weapon(pEntity->GetIndex());
}
static object Entity = import("entities").attr("entity").attr("Entity");
return Entity(pEntity->GetIndex());
}
return object(ptr(pEntity));
}
inline object GetEntityObject(CBaseEntity *pEntity)
{
return GetEntityObject((CBaseEntityWrapper *)pEntity);
}
inline object GetEntityObject(unsigned int uiIndex)
{
CBaseEntity *pEntity;
if (!BaseEntityFromIndex(uiIndex, pEntity)) {
return object();
}
return GetEntityObject((CBaseEntityWrapper *)pEntity);
}
#endif // _ENTITIES_ENTITY_H