mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-03-22 15:05:03 +01:00
ai alert mode
This commit is contained in:
76
Driver.cpp
76
Driver.cpp
@@ -4045,6 +4045,20 @@ bool TController::PutCommand( std::string NewCommand, double NewValue1, double N
|
||||
return true;
|
||||
}
|
||||
|
||||
if (NewCommand == "SetSignal") {
|
||||
TSignals signal = (TSignals)std::round(NewValue1);
|
||||
|
||||
mvOccupied->iLights[0] = 0;
|
||||
mvOccupied->iLights[1] = 0;
|
||||
mvOccupied->WarningSignal = 0;
|
||||
|
||||
for (int i = Signal_START; i <= Signal_MAX; i++)
|
||||
iDrivigFlags &= ~(1 << i);
|
||||
|
||||
if (NewValue2 > 0.5)
|
||||
iDrivigFlags |= 1 << (uint32_t)signal;
|
||||
}
|
||||
|
||||
return false; // nierozpoznana - wysłać bezpośrednio do pojazdu
|
||||
};
|
||||
|
||||
@@ -4413,18 +4427,56 @@ TController::UpdateSituation(double dt) {
|
||||
}
|
||||
}
|
||||
|
||||
// horn control
|
||||
if( fWarningDuration > 0.0 ) {
|
||||
// jeśli pozostało coś do wytrąbienia trąbienie trwa nadal
|
||||
fWarningDuration -= dt;
|
||||
if( fWarningDuration < 0.05 )
|
||||
mvOccupied->WarningSignal = 0; // a tu się kończy
|
||||
}
|
||||
if( mvOccupied->Vel >= 5.0 ) {
|
||||
// jesli jedzie, można odblokować trąbienie, bo się wtedy nie włączy
|
||||
iDrivigFlags &= ~moveStartHornDone; // zatrąbi dopiero jak następnym razem stanie
|
||||
iDrivigFlags |= moveStartHorn; // i trąbić przed następnym ruszeniem
|
||||
}
|
||||
if (iDrivigFlags & (1 << Signal_A1)) {
|
||||
if (fWarningDuration < 2.0)
|
||||
mvOccupied->WarningSignal = 1;
|
||||
else if (fWarningDuration < 2.5)
|
||||
mvOccupied->WarningSignal = 0;
|
||||
else if (fWarningDuration < 3.0)
|
||||
mvOccupied->WarningSignal = 1;
|
||||
else if (fWarningDuration < 3.5)
|
||||
mvOccupied->WarningSignal = 0;
|
||||
else if (fWarningDuration < 4.0)
|
||||
mvOccupied->WarningSignal = 1;
|
||||
else if (fWarningDuration < 4.5)
|
||||
mvOccupied->WarningSignal = 0;
|
||||
else if (fWarningDuration < 5.0)
|
||||
mvOccupied->WarningSignal = 1;
|
||||
else if (fWarningDuration < 7.0)
|
||||
mvOccupied->WarningSignal = 0;
|
||||
else
|
||||
fWarningDuration = 0.0;
|
||||
|
||||
if (std::fmod(fWarningDuration, 1.0) < 0.5) {
|
||||
mvOccupied->iLights[0] = headlight_right | headlight_left;
|
||||
mvOccupied->iLights[1] = headlight_right | headlight_left;
|
||||
}
|
||||
else {
|
||||
mvOccupied->iLights[0] = 0;
|
||||
mvOccupied->iLights[1] = 0;
|
||||
}
|
||||
|
||||
fWarningDuration += dt;
|
||||
}
|
||||
else if (iDrivigFlags & (1 << Signal_Pc6)) {
|
||||
mvOccupied->WarningSignal = 0;
|
||||
mvOccupied->iLights[0] = redmarker_right | redmarker_left | headlight_upper;
|
||||
mvOccupied->iLights[1] = redmarker_right | redmarker_left | headlight_upper;
|
||||
}
|
||||
else {
|
||||
// horn control
|
||||
if( fWarningDuration > 0.0 ) {
|
||||
// jeśli pozostało coś do wytrąbienia trąbienie trwa nadal
|
||||
fWarningDuration -= dt;
|
||||
if( fWarningDuration < 0.05 )
|
||||
mvOccupied->WarningSignal = 0; // a tu się kończy
|
||||
}
|
||||
if( mvOccupied->Vel >= 5.0 ) {
|
||||
// jesli jedzie, można odblokować trąbienie, bo się wtedy nie włączy
|
||||
iDrivigFlags &= ~moveStartHornDone; // zatrąbi dopiero jak następnym razem stanie
|
||||
iDrivigFlags |= moveStartHorn; // i trąbić przed następnym ruszeniem
|
||||
}
|
||||
}
|
||||
|
||||
if( ( true == TestFlag( iDrivigFlags, moveStartHornNow ) )
|
||||
&& ( true == Ready )
|
||||
|
||||
11
Driver.h
11
Driver.h
@@ -30,7 +30,16 @@ enum TOrders
|
||||
Obey_train = 1 << 7, // tryb pociągowy
|
||||
Bank = 1 << 8, // assist mode
|
||||
// others
|
||||
Jump_to_first_order = 1 << 9 // zapęlenie do pierwszej pozycji (po co?)
|
||||
Jump_to_first_order = 1 << 9, // zapęlenie do pierwszej pozycji (po co?)
|
||||
};
|
||||
|
||||
// TSignals is shifted into TMovementStatus
|
||||
enum TSignals
|
||||
{
|
||||
Signal_START = 30,
|
||||
Signal_Pc6 = 30,
|
||||
Signal_A1 = 31,
|
||||
Signal_MAX = 31
|
||||
};
|
||||
|
||||
enum TMovementStatus
|
||||
|
||||
@@ -253,7 +253,10 @@ commanddescription_sequence Commands_descriptions = {
|
||||
{ "trainsetmove", command_target::simulation, command_mode::oneoff },
|
||||
{ "consistteleport", command_target::simulation, command_mode::oneoff },
|
||||
{ "pullalarmchain", command_target::simulation, command_mode::oneoff },
|
||||
{ "notifyquit", command_target::simulation, command_mode::oneoff },
|
||||
{ "sendaicommand", command_target::simulation, command_mode::oneoff },
|
||||
{ "spawntrainset", command_target::simulation, command_mode::oneoff },
|
||||
{ "destroytrainset", command_target::simulation, command_mode::oneoff },
|
||||
{ "quitsimulation", command_target::simulation, command_mode::oneoff },
|
||||
};
|
||||
|
||||
} // simulation
|
||||
|
||||
@@ -247,6 +247,9 @@ enum class user_command {
|
||||
dynamicmove,
|
||||
consistteleport,
|
||||
pullalarmchain,
|
||||
sendaicommand,
|
||||
spawntrainset,
|
||||
destroytrainset,
|
||||
|
||||
quitsimulation,
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ http://mozilla.org/MPL/2.0/.
|
||||
#include "scene.h"
|
||||
#include "Train.h"
|
||||
#include "application.h"
|
||||
#include "Driver.h"
|
||||
|
||||
namespace simulation {
|
||||
|
||||
@@ -263,12 +264,30 @@ void state_manager::process_commands() {
|
||||
}
|
||||
}
|
||||
|
||||
if (commanddata.command == user_command::spawntrainset) {
|
||||
|
||||
}
|
||||
|
||||
if (commanddata.command == user_command::pullalarmchain) {
|
||||
TDynamicObject *vehicle = simulation::Vehicles.find(commanddata.payload);
|
||||
if (vehicle)
|
||||
vehicle->MoverParameters->AlarmChainSwitch(true);
|
||||
}
|
||||
|
||||
if (commanddata.command == user_command::sendaicommand) {
|
||||
std::istringstream ss(commanddata.payload);
|
||||
|
||||
std::string vehicle_name;
|
||||
std::string command;
|
||||
std::getline(ss, vehicle_name, '%');
|
||||
std::getline(ss, command, '%');
|
||||
|
||||
TDynamicObject *vehicle = simulation::Vehicles.find(vehicle_name);
|
||||
glm::dvec3 location = commanddata.location;
|
||||
if (vehicle && vehicle->Mechanik)
|
||||
vehicle->Mechanik->PutCommand(command, commanddata.param1, commanddata.param2, &location);
|
||||
}
|
||||
|
||||
if (commanddata.command == user_command::quitsimulation) {
|
||||
Application.queue_quit();
|
||||
}
|
||||
|
||||
@@ -317,6 +317,10 @@ void ui::handle_map_object_click(ui_panel &parent, std::shared_ptr<map::map_obje
|
||||
{
|
||||
parent.register_popup(std::make_unique<obstacle_remove_window>(parent, std::move(obstacle)));
|
||||
}
|
||||
else if (auto obstacle = std::dynamic_pointer_cast<map::vehicle>(obj))
|
||||
{
|
||||
parent.register_popup(std::make_unique<vehicle_click_window>(parent, std::move(obstacle)));
|
||||
}
|
||||
}
|
||||
|
||||
void ui::handle_map_object_hover(std::shared_ptr<map::map_object> &obj)
|
||||
@@ -538,3 +542,29 @@ void ui::obstacle_remove_window::render_content()
|
||||
ImGui::CloseCurrentPopup();
|
||||
}
|
||||
}
|
||||
|
||||
ui::vehicle_click_window::vehicle_click_window(ui_panel &panel, std::shared_ptr<map::vehicle> &&obstacle)
|
||||
: popup(panel), m_obstacle(obstacle) { }
|
||||
|
||||
void ui::vehicle_click_window::render_content()
|
||||
{
|
||||
std::string name = m_obstacle->name + "%" + "SetSignal";
|
||||
|
||||
if (ImGui::Button(u8"wyłącz")) {
|
||||
m_relay.post(user_command::sendaicommand, 0.0, 0.0, GLFW_PRESS, 0, glm::vec3(), &name);
|
||||
|
||||
ImGui::CloseCurrentPopup();
|
||||
}
|
||||
if (ImGui::Button(u8"Pc6")) {
|
||||
std::string name = m_obstacle->name + "%" + "SetSignal";
|
||||
m_relay.post(user_command::sendaicommand, Signal_Pc6, 1.0, GLFW_PRESS, 0, glm::vec3(), &name);
|
||||
|
||||
ImGui::CloseCurrentPopup();
|
||||
}
|
||||
if (ImGui::Button(u8"A1")) {
|
||||
std::string name = m_obstacle->name + "%" + "SetSignal";
|
||||
m_relay.post(user_command::sendaicommand, Signal_A1, 1.0, GLFW_PRESS, 0, glm::vec3(), &name);
|
||||
|
||||
ImGui::CloseCurrentPopup();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,6 +65,17 @@ class obstacle_remove_window : public popup
|
||||
virtual void render_content() override;
|
||||
};
|
||||
|
||||
class vehicle_click_window : public popup
|
||||
{
|
||||
std::shared_ptr<map::vehicle> m_obstacle;
|
||||
command_relay m_relay;
|
||||
|
||||
public:
|
||||
vehicle_click_window(ui_panel &panel, std::shared_ptr<map::vehicle> &&obstacle);
|
||||
|
||||
virtual void render_content() override;
|
||||
};
|
||||
|
||||
class map_panel : public ui_panel
|
||||
{
|
||||
std::unique_ptr<gl::program> m_track_shader;
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#include "stdafx.h"
|
||||
#include "widgets/map_objects.h"
|
||||
#include "simulation.h"
|
||||
#include "DynObj.h"
|
||||
|
||||
map::objects map::Objects;
|
||||
|
||||
@@ -27,5 +29,28 @@ map::sorted_object_list map::objects::find_in_range(glm::vec3 from, float distan
|
||||
}
|
||||
}
|
||||
|
||||
for (TDynamicObject *dynobj : simulation::Vehicles.sequence()) {
|
||||
if (!dynobj->Controller || dynobj->Prev())
|
||||
continue;
|
||||
|
||||
glm::vec3 entry_location = dynobj->GetPosition();
|
||||
glm::vec3 search_point = from;
|
||||
|
||||
if (glm::isnan(from.y))
|
||||
{
|
||||
entry_location.y = 0.0f;
|
||||
search_point.y = 0.0f;
|
||||
}
|
||||
|
||||
float dist = glm::distance2(entry_location, search_point);
|
||||
if (dist < max_distance2)
|
||||
{
|
||||
auto entry = std::make_shared<map::vehicle>();
|
||||
entry->dynobj = dynobj;
|
||||
entry->name = dynobj->name();
|
||||
items.emplace(dist, std::move(entry));
|
||||
}
|
||||
}
|
||||
|
||||
return items;
|
||||
}
|
||||
|
||||
@@ -59,6 +59,12 @@ struct obstacle : public map_object
|
||||
}
|
||||
};
|
||||
|
||||
// vehicle wrapper for map display
|
||||
struct vehicle : public map_object
|
||||
{
|
||||
TDynamicObject *dynobj = nullptr;
|
||||
};
|
||||
|
||||
struct objects
|
||||
{
|
||||
std::vector<std::shared_ptr<map_object>> entries;
|
||||
|
||||
Reference in New Issue
Block a user