2
* Copyright (C) 2002-4 by the Widelands Development Team
4
* This program is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU General Public License
6
* as published by the Free Software Foundation; either version 2
7
* of the License, or (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20
#include "trigger_time.h"
22
#include "filesystem.h"
25
static const int TRIGGER_VERSION = 1;
30
Trigger_Time::Trigger_Time(void) {
32
m_wait_time=60; // defaults to one minute
33
set_name("Time Trigger");
35
set_is_one_time_trigger(true);
38
Trigger_Time::~Trigger_Time(void) {
42
* File Read, File Write
44
void Trigger_Time::Read(FileRead* fr, Editor_Game_Base* ) {
45
int version=fr->Unsigned16();
46
if(version <= TRIGGER_VERSION) {
47
set_name(fr->CString());
48
set_is_one_time_trigger(fr->Unsigned8());
49
m_wait_time=fr->Unsigned32();
52
throw wexception("Time Trigger with unknown/unhandled version %i in map!\n", version);
55
void Trigger_Time::Write(FileWrite* fw) {
56
// First of all the id
57
fw->Unsigned16(get_id());
60
fw->Unsigned16(TRIGGER_VERSION);
63
fw->Data(get_name(), strlen(get_name()));
66
// triggers only once?
67
fw->Unsigned8(is_one_time_trigger());
70
fw->Unsigned32(m_wait_time);
76
* check if trigger conditions are done
78
void Trigger_Time::check_set_conditions(Game* game) {
79
if(((game->get_gametime()-m_last_start_time)/1000) < m_wait_time) return;
81
// Time has come. Set us
86
* Reset this trigger. This is only valid for non one timers
88
void Trigger_Time::reset_trigger(Game* game) {
89
assert(!is_one_time_trigger());
91
// save new start time
92
// NOTE: if it took a while for an event to note us,
93
// this time the trigger wasn't counting
94
m_last_start_time=game->get_gametime();