forked from eu07/maszyna
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEvLaunch.cpp
193 lines (180 loc) · 5.57 KB
/
EvLaunch.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
/*
This Source Code Form is subject to the
terms of the Mozilla Public License, v.
2.0. If a copy of the MPL was not
distributed with this file, You can
obtain one at
http://mozilla.org/MPL/2.0/.
*/
/*
MaSzyna EU07 locomotive simulator
Copyright (C) 2001-2004 Marcin Wozniak and others
*/
#include "system.hpp"
#pragma hdrstop
#include "mtable.hpp"
#include "Timer.h"
#include "Globals.h"
#include "EvLaunch.h"
#include "Event.h"
#include "Usefull.h"
#include "MemCell.h"
#include "parser.h"
#include "Console.h"
//---------------------------------------------------------------------------
TEventLauncher::TEventLauncher()
{ // ustawienie pocz¹tkowych wartoœci dla wszystkich zmiennych
iKey = 0;
DeltaTime = -1;
UpdatedTime = 0;
fVal1 = fVal2 = 0;
szText = NULL;
iHour = iMinute = -1; // takiego czasu nigdy nie bêdzie
dRadius = 0;
Event1 = Event2 = NULL;
MemCell = NULL;
iCheckMask = 0;
}
TEventLauncher::~TEventLauncher()
{
SafeDeleteArray(szText);
}
void TEventLauncher::Init()
{
}
bool TEventLauncher::Load(cParser *parser)
{ // wczytanie wyzwalacza zdarzeñ
AnsiString str;
std::string token;
parser->getTokens();
*parser >> dRadius; // promieñ dzia³ania
if (dRadius > 0.0)
dRadius *= dRadius; // do kwadratu, pod warunkiem, ¿e nie jest ujemne
parser->getTokens(); // klawisz steruj¹cy
*parser >> token;
str = AnsiString(token.c_str());
if (str != "none")
{
if (str.Length() == 1)
iKey = VkKeyScan(str[1]); // jeden znak jest konwertowany na kod klawisza
else
iKey = str.ToIntDef(0); // a jak wiêcej, to jakby numer klawisza jest
}
parser->getTokens();
*parser >> DeltaTime;
if (DeltaTime < 0)
DeltaTime = -DeltaTime; // dla ujemnego zmieniamy na dodatni
else if (DeltaTime > 0)
{ // wartoœæ dodatnia oznacza wyzwalanie o okreœlonej godzinie
iMinute = int(DeltaTime) % 100; // minuty s¹ najm³odszymi cyframi dziesietnymi
iHour = int(DeltaTime - iMinute) / 100; // godzina to setki
DeltaTime = 0; // bez powtórzeñ
WriteLog("EventLauncher at " + IntToStr(iHour) + ":" +
IntToStr(iMinute)); // wyœwietlenie czasu
}
parser->getTokens();
*parser >> token;
asEvent1Name = AnsiString(token.c_str()); // pierwszy event
parser->getTokens();
*parser >> token;
asEvent2Name = AnsiString(token.c_str()); // drugi event
if ((asEvent2Name == "end") || (asEvent2Name == "condition"))
{ // drugiego eventu mo¿e nie byæ, bo s¹ z tym problemy, ale ciii...
str = asEvent2Name; // rozpoznane s³owo idzie do dalszego przetwarzania
asEvent2Name = "none"; // a drugiego eventu nie ma
}
else
{ // gdy s¹ dwa eventy
parser->getTokens();
*parser >> token;
str = AnsiString(token.c_str());
}
if (str == AnsiString("condition"))
{ // obs³uga wyzwalania warunkowego
parser->getTokens();
*parser >> token;
asMemCellName = AnsiString(token.c_str());
parser->getTokens();
*parser >> token;
SafeDeleteArray(szText);
szText = new char[256];
strcpy(szText, token.c_str());
if (token.compare("*") != 0) //*=nie braæ command pod uwagê
iCheckMask |= conditional_memstring;
parser->getTokens();
*parser >> token;
if (token.compare("*") != 0) //*=nie braæ wartoœci 1. pod uwagê
{
iCheckMask |= conditional_memval1;
str = AnsiString(token.c_str());
fVal1 = str.ToDouble();
}
else
fVal1 = 0;
parser->getTokens();
*parser >> token;
if (token.compare("*") != 0) //*=nie braæ wartoœci 2. pod uwagê
{
iCheckMask |= conditional_memval2;
str = AnsiString(token.c_str());
fVal2 = str.ToDouble();
}
else
fVal2 = 0;
parser->getTokens(); // s³owo zamykaj¹ce
*parser >> token;
}
return true;
};
bool TEventLauncher::Render()
{ //"renderowanie" wyzwalacza
bool bCond = false;
if (iKey != 0)
{
if (Global::bActive) // tylko jeœli okno jest aktywne
bCond = (Console::Pressed(iKey)); // czy klawisz wciœniêty
}
if (DeltaTime > 0)
{
if (UpdatedTime > DeltaTime)
{
UpdatedTime = 0; // naliczanie od nowa
bCond = true;
}
else
UpdatedTime += Timer::GetDeltaTime(); // aktualizacja naliczania czasu
}
else
{ // jeœli nie cykliczny, to sprawdziæ czas
if (GlobalTime->hh == iHour)
{
if (GlobalTime->mm == iMinute)
{ // zgodnoϾ czasu uruchomienia
if (UpdatedTime < 10)
{
UpdatedTime = 20; // czas do kolejnego wyzwolenia?
bCond = true;
}
}
}
else
UpdatedTime = 1;
}
if (bCond) // jeœli spe³niony zosta³ warunek
{
if ((iCheckMask != 0) && MemCell) // sprawdzanie warunku na komórce pamiêci
bCond = MemCell->Compare(szText, fVal1, fVal2, iCheckMask);
}
return bCond; // sprawdzanie dRadius w Ground.cpp
}
bool TEventLauncher::IsGlobal()
{ // sprawdzenie, czy jest globalnym wyzwalaczem czasu
if (DeltaTime == 0)
if (iHour >= 0)
if (iMinute >= 0)
if (dRadius < 0.0) // bez ograniczenia zasiêgu
return true;
return false;
};
//---------------------------------------------------------------------------
#pragma package(smart_init)