-
Notifications
You must be signed in to change notification settings - Fork 178
/
RecoveryMode.cpp
161 lines (140 loc) · 6.16 KB
/
RecoveryMode.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
/*
This source file is part of Rigs of Rods
Copyright 2005-2012 Pierre-Michel Ricordel
Copyright 2007-2012 Thomas Fischer
Copyright 2015-2020 Petr Ohlidal
For more information, see http://www.rigsofrods.org/
Rigs of Rods is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License version 3, as
published by the Free Software Foundation.
Rigs of Rods 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 Rigs of Rods. If not, see <http://www.gnu.org/licenses/>.
*/
#include "RecoveryMode.h"
#include "GameContext.h"
#include "InputEngine.h"
using namespace RoR;
void RecoveryMode::UpdateInputEvents(float dt)
{
if (App::sim_state->getEnum<SimState>() != SimState::RUNNING &&
App::GetGameContext()->GetPlayerActor() &&
App::GetGameContext()->GetPlayerActor()->ar_state != ActorState::NETWORKED_OK &&
App::GetGameContext()->GetPlayerActor()->ar_state != ActorState::LOCAL_REPLAY)
{
return;
}
if (!App::GetGameContext()->GetPlayerActor())
{
m_advanced_vehicle_repair = false;
m_advanced_vehicle_repair_timer = 0.0f;
return;
}
if (!App::GetInputEngine()->getEventBoolValue(EV_COMMON_REPAIR_TRUCK))
{
m_advanced_vehicle_repair_timer = 0.0f;
}
if (App::GetInputEngine()->getEventBoolValue(EV_COMMON_REPAIR_TRUCK) || m_advanced_vehicle_repair)
{
if (App::GetInputEngine()->getEventBoolValue(EV_COMMON_REPAIR_TRUCK))
{
m_advanced_vehicle_repair = m_advanced_vehicle_repair_timer > 1.0f;
}
Ogre::Vector3 translation = Ogre::Vector3::ZERO;
float rotation = 0.0f;
if (App::GetInputEngine()->getEventBoolValue(EV_TRUCK_ACCELERATE))
{
translation += 2.0f * Ogre::Vector3::UNIT_Y * dt;
}
else if (App::GetInputEngine()->getEventBoolValue(EV_TRUCK_BRAKE))
{
translation -= 2.0f * Ogre::Vector3::UNIT_Y * dt;
}
if (App::GetInputEngine()->getEventBoolValue(EV_TRUCK_STEER_LEFT))
{
rotation += 0.5f * dt;
}
else if (App::GetInputEngine()->getEventBoolValue(EV_TRUCK_STEER_RIGHT))
{
rotation -= 0.5f * dt;
}
if (App::GetInputEngine()->getEventBoolValue(EV_CHARACTER_FORWARD))
{
float curRot = App::GetGameContext()->GetPlayerActor()->getRotation();
translation.x += 2.0f * cos(curRot - Ogre::Math::HALF_PI) * dt;
translation.z += 2.0f * sin(curRot - Ogre::Math::HALF_PI) * dt;
}
else if (App::GetInputEngine()->getEventBoolValue(EV_CHARACTER_BACKWARDS))
{
float curRot = App::GetGameContext()->GetPlayerActor()->getRotation();
translation.x -= 2.0f * cos(curRot - Ogre::Math::HALF_PI) * dt;
translation.z -= 2.0f * sin(curRot - Ogre::Math::HALF_PI) * dt;
}
if (App::GetInputEngine()->getEventBoolValue(EV_CHARACTER_SIDESTEP_RIGHT))
{
float curRot = App::GetGameContext()->GetPlayerActor()->getRotation();
translation.x += 2.0f * cos(curRot) * dt;
translation.z += 2.0f * sin(curRot) * dt;
}
else if (App::GetInputEngine()->getEventBoolValue(EV_CHARACTER_SIDESTEP_LEFT))
{
float curRot = App::GetGameContext()->GetPlayerActor()->getRotation();
translation.x -= 2.0f * cos(curRot) * dt;
translation.z -= 2.0f * sin(curRot) * dt;
}
if (translation != Ogre::Vector3::ZERO || rotation != 0.0f)
{
float scale = App::GetInputEngine()->isKeyDown(OIS::KC_LMENU) ? 0.1f : 1.0f;
scale *= App::GetInputEngine()->isKeyDown(OIS::KC_LSHIFT) ? 3.0f : 1.0f;
scale *= App::GetInputEngine()->isKeyDown(OIS::KC_LCONTROL) ? 10.0f : 1.0f;
Ogre::Vector3 rotation_center = App::GetGameContext()->GetPlayerActor()->getRotationCenter();
rotation *= Ogre::Math::Clamp(scale, 0.1f, 10.0f);
translation *= scale;
App::GetGameContext()->GetPlayerActor()->requestRotation(rotation, rotation_center);
App::GetGameContext()->GetPlayerActor()->requestTranslation(translation);
if (App::sim_soft_reset_mode->getBool())
{
for (auto actor : App::GetGameContext()->GetPlayerActor()->getAllLinkedActors())
{
actor->requestRotation(rotation, rotation_center);
actor->requestTranslation(translation);
}
}
m_advanced_vehicle_repair_timer = 0.0f;
}
else if (App::GetInputEngine()->isKeyDownValueBounce(OIS::KC_SPACE))
{
App::GetGameContext()->GetPlayerActor()->requestAngleSnap(45);
if (App::sim_soft_reset_mode->getBool())
{
for (auto actor : App::GetGameContext()->GetPlayerActor()->getAllLinkedActors())
{
actor->requestAngleSnap(45);
}
}
}
else
{
m_advanced_vehicle_repair_timer += dt;
}
auto reset_type = ActorModifyRequest::Type::RESET_ON_SPOT;
if (App::sim_soft_reset_mode->getBool())
{
reset_type = ActorModifyRequest::Type::SOFT_RESET;
for (auto actor : App::GetGameContext()->GetPlayerActor()->getAllLinkedActors())
{
ActorModifyRequest* rq = new ActorModifyRequest;
rq->amr_actor = actor;
rq->amr_type = reset_type;
App::GetGameContext()->PushMessage(Message(MSG_SIM_MODIFY_ACTOR_REQUESTED, (void*)rq));
}
}
ActorModifyRequest* rq = new ActorModifyRequest;
rq->amr_actor = App::GetGameContext()->GetPlayerActor();
rq->amr_type = reset_type;
App::GetGameContext()->PushMessage(Message(MSG_SIM_MODIFY_ACTOR_REQUESTED, (void*)rq));
}
}