-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathComputer.cpp
151 lines (135 loc) · 4.08 KB
/
Computer.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
#include "Computer.h"
#include "CWeapon.h"
Computer::Computer()
{
mActMagic=false;
mFov=90;
allowVirtualDisplay=true;
notice=true;
mNearLua="";
}
Computer::~Computer()
{
}
void Computer::init(SceneNode* cComp,int type,String fileName)
{
//global::getSingleton().getRoot()->addFrameListener(this);
mComp=cComp;
Vector3 size=cComp->getScale();
mWorld = global::getSingleton().getWorld();
OgreNewt::Collision* col = new OgreNewt::CollisionPrimitives::TreeCollision(mWorld,cComp,true);
bod = new OgreNewt::Body( mWorld, col );
bod->attachToNode( cComp );
bod->setName(cComp->getName());
bod->setPositionOrientation( cComp->getPosition(), cComp->getOrientation() );
pLuaState = global::getSingleton().getLuaState();
luaFlName=fileName;
delete col;
}
void Computer::init(SceneNode* cComp,int type,String fileName,String dispMatName)
{
//global::getSingleton().getRoot()->addFrameListener(this);
mDispMatName=dispMatName;
mComp=cComp;
Vector3 size=cComp->getScale();
mWorld = global::getSingleton().getWorld();
OgreNewt::Collision* col = new OgreNewt::CollisionPrimitives::TreeCollision(mWorld,cComp,true);
bod = new OgreNewt::Body( mWorld, col );
bod->attachToNode( cComp );
bod->setName(cComp->getName());
bod->setPositionOrientation( cComp->getPosition(), cComp->getOrientation() );
pLuaState = global::getSingleton().getLuaState();
luaFlName=fileName;
delete col;
}
void Computer::power()
{
if (!Display::getSingleton().isVisible())
{
mFov=global::getSingleton().getPlayer()->getFOV();
LogManager::getSingleton().logMessage("Computer: player FOV is:");
LogManager::getSingleton().logMessage(StringConverter::toString(mFov));
MagicManager::getSingleton().activateMagic(true);
LogManager::getSingleton().logMessage("Computer turned on!");
Display::getSingleton().curcomputer=this;
Display::getSingleton().setAllowVirtualDisplay(allowVirtualDisplay);
Display::getSingleton().show();
global::getSingleton().computer_mode=true;
CWeapon::getSingleton().hide_all();
global::getSingleton().getPlayer()->freeze();
RunLuaScript(pLuaState, luaFlName.c_str());
HUD::getSingleton().Hide();
}
}
void Computer::logoff()
{
if (Display::getSingleton().isVisible())
{
LogManager::getSingleton().logMessage("Computer turned off!");
MagicManager::getSingleton().activateMagic(false);
LogManager::getSingleton().logMessage("Computer turned off2!");
Display::getSingleton().hide();
if (!(msLua==""))
{
RunLuaScript(pLuaState, msLua.c_str());
}
RunLuaScript(pLuaState, "run3/lua/resetcomp.lua");
global::getSingleton().computer_mode=false;
LogManager::getSingleton().logMessage("Computer: last FOV is. Reverting changes.");
LogManager::getSingleton().logMessage(StringConverter::toString(mFov));
global::getSingleton().getPlayer()->unfreeze2();
global::getSingleton().getPlayer()->changeFOV(mFov);
HUD::getSingleton().Show();
}
}
void Computer::explode()
{
//explosions are not implemented
}
void Computer::reset()
{
RunLuaScript(pLuaState, "run3/lua/resetcomp.lua");
RunLuaScript(pLuaState, luaFlName.c_str());
}
bool Computer::frameStarted(const Ogre::FrameEvent &evt)
{
if (bod->getUsing()) //user pressed "E" near the computer
{
power();
}
if (notice)
{
Vector3 dist = global::getSingleton().getPlayer()->get_location()-mComp->getPosition();
//LogManager::getSingleton().logMessage(StringConverter::toString(dist.length()));
if (dist.length()<200.0f)
{
LogManager::getSingleton().logMessage("Computer: near.");
if (!mNearLua.empty())
{
RunLuaScript(pLuaState, mNearLua.c_str());
}
notice=false;
}
}
/*if (!bod->getUsing()) //user pressed "E" near the computer
{
hide();
}*/
return true;
}
void Computer::del()
{
//global::getSingleton().getRoot()->removeFrameListener(this);
delete bod;
Ogre::MovableObject* aEnt = mComp->getAttachedObject(0);
if (global::getSingleton().getSceneManager()->hasEntity(aEnt->getName()))
{
mComp->detachAllObjects();
global::getSingleton().getSceneManager()->destroySceneNode(mComp);
global::getSingleton().getSceneManager()->destroyEntity(aEnt->getName());
}
}
bool Computer::frameEnded(const Ogre::FrameEvent &evt)
{
return true;
}