Update: Translations from eints
[openttd-github.git] / src / script / api / script_event.cpp
blobefdc720cf384db57e87d51826fcb1e9e16fb94d2
1 /*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD 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.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6 */
8 /** @file script_event.cpp Implementation of ScriptEvent. */
10 #include "../../stdafx.h"
11 #include "script_event_types.hpp"
13 #include <queue>
15 #include "../../safeguards.h"
17 /** The queue of events for a script. */
18 struct ScriptEventData {
19 std::queue<ScriptEvent *> stack; ///< The actual queue.
22 /* static */ void ScriptEventController::CreateEventPointer()
24 assert(ScriptObject::GetEventPointer() == nullptr);
26 ScriptObject::GetEventPointer() = new ScriptEventData();
29 /* static */ void ScriptEventController::FreeEventPointer()
31 ScriptEventData *data = (ScriptEventData *)ScriptObject::GetEventPointer();
33 /* Free all waiting events (if any) */
34 while (!data->stack.empty()) {
35 ScriptEvent *e = data->stack.front();
36 data->stack.pop();
37 e->Release();
40 /* Now kill our data pointer */
41 delete data;
44 /* static */ bool ScriptEventController::IsEventWaiting()
46 if (ScriptObject::GetEventPointer() == nullptr) ScriptEventController::CreateEventPointer();
47 ScriptEventData *data = (ScriptEventData *)ScriptObject::GetEventPointer();
49 return !data->stack.empty();
52 /* static */ ScriptEvent *ScriptEventController::GetNextEvent()
54 if (ScriptObject::GetEventPointer() == nullptr) ScriptEventController::CreateEventPointer();
55 ScriptEventData *data = (ScriptEventData *)ScriptObject::GetEventPointer();
57 if (data->stack.empty()) return nullptr;
59 ScriptEvent *e = data->stack.front();
60 data->stack.pop();
61 return e;
64 /* static */ void ScriptEventController::InsertEvent(ScriptEvent *event)
66 if (ScriptObject::GetEventPointer() == nullptr) ScriptEventController::CreateEventPointer();
67 ScriptEventData *data = (ScriptEventData *)ScriptObject::GetEventPointer();
69 event->AddRef();
70 data->stack.push(event);