Rigs of Rods 2023.09
Soft-body Physics Simulation
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Loading...
Searching...
No Matches
RepairMode.cpp
Go to the documentation of this file.
1/*
2 This source file is part of Rigs of Rods
3 Copyright 2005-2012 Pierre-Michel Ricordel
4 Copyright 2007-2012 Thomas Fischer
5 Copyright 2015-2020 Petr Ohlidal
6
7 For more information, see http://www.rigsofrods.org/
8
9 Rigs of Rods is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License version 3, as
11 published by the Free Software Foundation.
12
13 Rigs of Rods is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with Rigs of Rods. If not, see <http://www.gnu.org/licenses/>.
20*/
21
22#include "RepairMode.h"
23
24#include "Actor.h"
25#include "GameContext.h"
26#include "InputEngine.h"
27
28using namespace RoR;
29
31{
32 if (App::sim_state->getEnum<SimState>() != SimState::RUNNING &&
33 App::GetGameContext()->GetPlayerActor() &&
34 App::GetGameContext()->GetPlayerActor()->ar_state != ActorState::NETWORKED_OK &&
35 App::GetGameContext()->GetPlayerActor()->ar_state != ActorState::LOCAL_REPLAY)
36 {
37 return;
38 }
39
40 if (!App::GetGameContext()->GetPlayerActor())
41 {
45 return;
46 }
47
48 if (App::GetInputEngine()->getEventBoolValue(EV_COMMON_LIVE_REPAIR_MODE))
49 {
51 // Hack to bypass the timer - because EV_COMMON_REPAIR_TRUCK (default Backspace) may not be 'EXPL' so the below condition may execute.
53 }
54
55 // Update LiveRepair timer
58 {
59 if (App::sim_live_repair_interval->getFloat() > 0)
61 }
62 else
63 {
65 }
66
67 // Handle repair controls
69 {
70 Ogre::Vector3 translation = Ogre::Vector3::ZERO;
71 float rotation = 0.0f;
72
73 if (App::GetInputEngine()->getEventBoolValue(EV_TRUCK_ACCELERATE))
74 {
75 translation += 2.0f * Ogre::Vector3::UNIT_Y * dt;
76 }
77 else if (App::GetInputEngine()->getEventBoolValue(EV_TRUCK_BRAKE))
78 {
79 translation -= 2.0f * Ogre::Vector3::UNIT_Y * dt;
80 }
81 if (App::GetInputEngine()->getEventBoolValue(EV_TRUCK_STEER_LEFT))
82 {
83 rotation += 0.5f * dt;
84 }
85 else if (App::GetInputEngine()->getEventBoolValue(EV_TRUCK_STEER_RIGHT))
86 {
87 rotation -= 0.5f * dt;
88 }
89 if (App::GetInputEngine()->getEventBoolValue(EV_CHARACTER_FORWARD))
90 {
91 float curRot = App::GetGameContext()->GetPlayerActor()->getRotation();
92 translation.x += 2.0f * cos(curRot - Ogre::Math::HALF_PI) * dt;
93 translation.z += 2.0f * sin(curRot - Ogre::Math::HALF_PI) * dt;
94 }
95 else if (App::GetInputEngine()->getEventBoolValue(EV_CHARACTER_BACKWARDS))
96 {
97 float curRot = App::GetGameContext()->GetPlayerActor()->getRotation();
98 translation.x -= 2.0f * cos(curRot - Ogre::Math::HALF_PI) * dt;
99 translation.z -= 2.0f * sin(curRot - Ogre::Math::HALF_PI) * dt;
100 }
101 if (App::GetInputEngine()->getEventBoolValue(EV_CHARACTER_SIDESTEP_RIGHT))
102 {
103 float curRot = App::GetGameContext()->GetPlayerActor()->getRotation();
104 translation.x += 2.0f * cos(curRot) * dt;
105 translation.z += 2.0f * sin(curRot) * dt;
106 }
107 else if (App::GetInputEngine()->getEventBoolValue(EV_CHARACTER_SIDESTEP_LEFT))
108 {
109 float curRot = App::GetGameContext()->GetPlayerActor()->getRotation();
110 translation.x -= 2.0f * cos(curRot) * dt;
111 translation.z -= 2.0f * sin(curRot) * dt;
112 }
113
114 if (translation != Ogre::Vector3::ZERO || rotation != 0.0f)
115 {
116 float scale = App::GetInputEngine()->isKeyDown(OIS::KC_LMENU) ? 0.1f : 1.0f;
117 scale *= App::GetInputEngine()->isKeyDown(OIS::KC_LSHIFT) ? 3.0f : 1.0f;
118 scale *= App::GetInputEngine()->isKeyDown(OIS::KC_LCONTROL) ? 10.0f : 1.0f;
119
120 Ogre::Vector3 rotation_center = App::GetGameContext()->GetPlayerActor()->getRotationCenter();
121
122 rotation *= Ogre::Math::Clamp(scale, 0.1f, 10.0f);
123 translation *= scale;
124
125 App::GetGameContext()->GetPlayerActor()->requestRotation(rotation, rotation_center);
127
128 if (App::sim_soft_reset_mode->getBool())
129 {
131 {
132 actor->requestRotation(rotation, rotation_center);
133 actor->requestTranslation(translation);
134 }
135 }
136
137 m_live_repair_timer = 0.0f;
138 }
139 else if (App::GetInputEngine()->isKeyDownValueBounce(OIS::KC_SPACE))
140 {
142 if (App::sim_soft_reset_mode->getBool())
143 {
145 {
146 actor->requestAngleSnap(45);
147 }
148 }
149 }
150 else
151 {
153 }
154
156 if (App::sim_soft_reset_mode->getBool())
157 {
160 {
162 rq->amr_actor = actor->ar_instance_id;
163 rq->amr_type = reset_type;
165 }
166 }
167
170 rq->amr_type = reset_type;
172 }
173}
Game state manager and message-queue provider.
Handles controller inputs from player.
Actor feat - interactive recovery and repair mode.
void requestAngleSnap(int division)
Definition Actor.h:121
float getRotation()
Definition Actor.cpp:355
Ogre::Vector3 getRotationCenter()
Definition Actor.cpp:1550
void requestRotation(float rotation, Ogre::Vector3 center)
Definition Actor.h:120
ActorInstanceID_t ar_instance_id
Static attr; session-unique ID.
Definition Actor.h:429
void requestTranslation(Ogre::Vector3 translation)
Definition Actor.h:122
ActorPtrVec ar_linked_actors
BEWARE: Includes indirect links, see DetermineLinkedActors(); Other actors linked using 'hooks/ties/r...
Definition Actor.h:519
float getFloat() const
Definition CVar.h:96
const ActorPtr & GetPlayerActor()
void PushMessage(Message m)
Doesn't guarantee order! Use ChainMessage() if order matters.
bool isKeyDown(OIS::KeyCode mod)
Asks OIS directly.
bool getEventBoolValue(int eventID)
bool isKeyDownValueBounce(OIS::KeyCode mod, float time=0.2f)
bool m_live_repair_active
Definition RepairMode.h:48
float m_live_repair_timer
Definition RepairMode.h:49
void UpdateInputEvents(float dt)
bool m_quick_repair_active
Definition RepairMode.h:47
@ EV_TRUCK_ACCELERATE
accelerate the truck
@ EV_CHARACTER_SIDESTEP_LEFT
sidestep to the left
@ EV_CHARACTER_FORWARD
step forward with the character
@ EV_TRUCK_STEER_LEFT
steer left
@ EV_COMMON_REPAIR_TRUCK
repair truck to original condition
@ EV_TRUCK_BRAKE
brake
@ EV_TRUCK_STEER_RIGHT
steer right
@ EV_CHARACTER_SIDESTEP_RIGHT
sidestep to the right
@ EV_COMMON_LIVE_REPAIR_MODE
toggles live repair and recovery mode, controlled by keyboard
@ EV_CHARACTER_BACKWARDS
step backwards with the character
@ MSG_SIM_MODIFY_ACTOR_REQUESTED
Payload = RoR::ActorModifyRequest* (owner)
@ NETWORKED_OK
not simulated (remote) actor
CVar * sim_state
InputEngine * GetInputEngine()
GameContext * GetGameContext()
CVar * sim_soft_reset_mode
CVar * sim_live_repair_interval
Hold EV_COMMON_REPAIR_TRUCK to enter LiveRepair mode. 0 or negative interval disables.
ActorInstanceID_t amr_actor
Definition SimData.h:875
Unified game event system - all requests and state changes are reported using a message.
Definition GameContext.h:52