-
Notifications
You must be signed in to change notification settings - Fork 105
/
GameLink.cpp
200 lines (151 loc) · 6.02 KB
/
GameLink.cpp
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
/*
* Copyright (C) 2006-2010 - Frictional Games
*
* This file is part of Penumbra Overture.
*
* Penumbra Overture 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.
*
* Penumbra Overture 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 Penumbra Overture. If not, see <http://www.gnu.org/licenses/>.
*/
#include "StdAfx.h"
#include "GameLink.h"
#include "Init.h"
#include "MapHandler.h"
#include "Player.h"
#include "RadioHandler.h"
#include "GlobalInit.h"
//////////////////////////////////////////////////////////////////////////
// LOADER
//////////////////////////////////////////////////////////////////////////
//-----------------------------------------------------------------------
cAreaLoader_GameLink::cAreaLoader_GameLink(const tString &asName, cInit *apInit)
: iArea3DLoader(asName)
{
mpInit = apInit;
}
cAreaLoader_GameLink::~cAreaLoader_GameLink()
{
}
//-----------------------------------------------------------------------
iEntity3D* cAreaLoader_GameLink::Load(const tString &asName, const cVector3f &avSize,
const cMatrixf &a_mtxTransform,cWorld3D *apWorld)
{
cGameLink *pLink = hplNew( cGameLink, (mpInit,asName) );
pLink->m_mtxOnLoadTransform = a_mtxTransform;
//Create physics data
iPhysicsWorld *pPhysicsWorld = apWorld->GetPhysicsWorld();
iCollideShape* pShape = pPhysicsWorld->CreateBoxShape(avSize,NULL);
std::vector<iPhysicsBody*> vBodies;
vBodies.push_back(pPhysicsWorld->CreateBody(asName,pShape));
vBodies[0]->SetCollide(false);
vBodies[0]->SetCollideCharacter(false);
vBodies[0]->SetMatrix(a_mtxTransform);
vBodies[0]->SetUserData(pLink);
pLink->SetBodies(vBodies);
mpInit->mpMapHandler->AddGameEntity(pLink);
return NULL;
}
//-----------------------------------------------------------------------
//////////////////////////////////////////////////////////////////////////
// CONSTRUCTORS
//////////////////////////////////////////////////////////////////////////
//-----------------------------------------------------------------------
cGameLink::cGameLink(cInit *apInit,const tString& asName) : iGameEntity(apInit,asName)
{
mType = eGameEntityType_Link;
}
//-----------------------------------------------------------------------
cGameLink::~cGameLink(void)
{
}
//-----------------------------------------------------------------------
//////////////////////////////////////////////////////////////////////////
// PUBLIC METHODS
//////////////////////////////////////////////////////////////////////////
//-----------------------------------------------------------------------
void cGameLink::OnPlayerPick()
{
if(mpInit->mpPlayer->GetPickedDist() <= 1.8)
{
mpInit->mpPlayer->SetCrossHairState(eCrossHairState_DoorLink);
}
}
void cGameLink::OnPlayerInteract()
{
//if(mpInit->mpRadioHandler->IsActive()) return;
if(mpInit->mpPlayer->GetPickedDist() <= 1.8 && msMapFile != "")
{
mpInit->mpMapHandler->ChangeMap(msMapFile, msMapPos, msStartSound, msStopSound, mfFadeOutTime,
mfFadeInTime,msLoadTextCat,msLoadTextEntry);
}
}
//-----------------------------------------------------------------------
//////////////////////////////////////////////////////////////////////////
// PRIVATE METHODS
//////////////////////////////////////////////////////////////////////////
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
//////////////////////////////////////////////////////////////////////////
// SAVE OBJECT STUFF
//////////////////////////////////////////////////////////////////////////
//-----------------------------------------------------------------------
kBeginSerialize(cGameLink_SaveData,iGameEntity_SaveData)
kSerializeVar(mvSize,eSerializeType_Vector3f)
kSerializeVar(msMapFile, eSerializeType_String)
kSerializeVar(msMapPos, eSerializeType_String)
kSerializeVar(msStartSound, eSerializeType_String)
kSerializeVar(msStopSound, eSerializeType_String)
kSerializeVar(mfFadeOutTime, eSerializeType_Float32)
kSerializeVar(mfFadeInTime, eSerializeType_Float32)
kSerializeVar(msLoadTextCat, eSerializeType_String)
kSerializeVar(msLoadTextEntry, eSerializeType_String)
kEndSerialize()
//-----------------------------------------------------------------------
iGameEntity* cGameLink_SaveData::CreateEntity()
{
return NULL;
}
//-----------------------------------------------------------------------
iGameEntity_SaveData* cGameLink::CreateSaveData()
{
return hplNew( cGameLink_SaveData, () );
}
//-----------------------------------------------------------------------
void cGameLink::SaveToSaveData(iGameEntity_SaveData *apSaveData)
{
__super::SaveToSaveData(apSaveData);
cGameLink_SaveData *pData = static_cast<cGameLink_SaveData*>(apSaveData);
kCopyToVar(pData,msMapFile);
kCopyToVar(pData,msMapPos);
kCopyToVar(pData,msStartSound);
kCopyToVar(pData,msStopSound);
kCopyToVar(pData,mfFadeOutTime);
kCopyToVar(pData,mfFadeInTime);
kCopyToVar(pData,msLoadTextCat);
kCopyToVar(pData,msLoadTextEntry);
pData->mvSize = mvBodies[0]->GetShape()->GetSize();
}
//-----------------------------------------------------------------------
void cGameLink::LoadFromSaveData(iGameEntity_SaveData *apSaveData)
{
__super::LoadFromSaveData(apSaveData);
cGameLink_SaveData *pData = static_cast<cGameLink_SaveData*>(apSaveData);
kCopyFromVar(pData,msMapFile);
kCopyFromVar(pData,msMapPos);
kCopyFromVar(pData,msStartSound);
kCopyFromVar(pData,msStopSound);
kCopyFromVar(pData,mfFadeOutTime);
kCopyFromVar(pData,mfFadeInTime);
kCopyFromVar(pData,msLoadTextCat);
kCopyFromVar(pData,msLoadTextEntry);
}
//-----------------------------------------------------------------------