forked from LemonHaze420/DCMoHo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcannon.cpp
More file actions
98 lines (73 loc) · 1.9 KB
/
Copy pathcannon.cpp
File metadata and controls
98 lines (73 loc) · 1.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
#include "Common.h"
#include "Globals.h"
#include "Cannon.h"
//******************************************************************************************
#define CANNON_GROUND_SPEED_MAX GINT(0, 52428)
#define CANNON_GROUND_SPEED_MIN GINT(0, 10000)
void CCannon::Init(CInitThing *i)
{
SUPERTYPE::Init(i);
StickToGround();
mTimer = 0;
GET_OID;
GET_TARGET;
}
//******************************************************************************************
#if TARGET == PC
void CCannon::WriteData(CInitThing &i)
{
SUPERTYPE::WriteData(i);
WRITE_OID;
WRITE_TARGET;
}
#endif
//******************************************************************************************
GVector CCannon::CalcVelocity()
{
ASSERT(mTarget); // shouldn't ever be NULL
GVector v;
v = (mTarget->GetPos() - mPos);
GINT speed = v.MagnitudeXY() / 64;
if (speed > CANNON_GROUND_SPEED_MAX) speed = CANNON_GROUND_SPEED_MAX;
if (speed < CANNON_GROUND_SPEED_MIN) speed = CANNON_GROUND_SPEED_MIN;
v.Normalise();
v *= speed;
v.Z = -WORLD.Gravity() * (mTarget->GetPos() - mPos).MagnitudeXY() / speed / 2;
return v;
}
//******************************************************************************************
void CCannon::Process()
{
mPos.Z = MAP.GetMapHeightDifference(mPos) ;
mTimer ++;
if ((mTimer > 100) && (mTarget))
{
SINT oid;
if ((mOID != OID_NONE) && (mOID != OID_INVALID))
oid = mOID;
else
oid = OID_CCannonBall;
CThing *t = SpawnThing(oid);
if (t)
{
CInitThing i;
i.mPos = mPos + GetRenderThingEmitter(0);
i.mVelocity = CalcVelocity();
t->Init(&i);
}
mTimer = 0;
}
}
//******************************************************************************************
#ifdef LINK_EDITOR
void CCannon::DeclareSpawnees()
{
SUPERTYPE::DeclareSpawnees();
SINT oid;
if ((mOID != OID_NONE) && (mOID != OID_INVALID))
oid = mOID;
else
oid = OID_CCannonBall;
WORLD.AccumulateOIDResources(oid);
}
#endif