1 /***************************************************************************
2                   event.h  -  Base class for ingame events
3                              -------------------
4     begin                : Thu Apr 8 2004
5     copyright            : (C) 2004 by Daroth-U
6     email                : daroth-u@ifrance.com
7  ***************************************************************************/
8 
9 /***************************************************************************
10  *                                                                         *
11  *   This program is free software; you can redistribute it and/or modify  *
12  *   it under the terms of the GNU General Public License as published by  *
13  *   the Free Software Foundation; either version 2 of the License, or     *
14  *   (at your option) any later version.                                   *
15  *                                                                         *
16  ***************************************************************************/
17 
18 #ifndef EVENT_H
19 #define EVENT_H
20 #pragma once
21 
22 #include "../date.h"
23 
24 
25 /**
26   *@author Daroth-U
27   */
28 
29 class Date;
30 class Creature;
31 
32 /// A scheduled ingame event (hunger, thirst, potion expires etc.)
33 class Event  {
34 
35 private:
36 	Date eventDate;
37 	Date timeOut;
38 	long nbExecutionsToDo;
39 	long nbExecutions;
40 
41 	// For debug purpose
42 	static int globalId;
43 	int eventId;  // unique
44 	bool cancelEvent;
45 
46 public:
47 
48 
49 	enum {
50 		INFINITE_EXECUTIONS = -1
51 	};
52 
53 	// This event will occur nbExecutionsTD time every tmOut from currentDate.
54 	Event( Date currentDate, Date tmOut, long nbExecutionsToDo );
55 
56 	// This event will occur only one time at the given date
57 	Event( Date eventDate );
58 
59 	Event();
60 	virtual ~Event();
61 
62 	//virtual void execute()=0;
execute()63 	virtual void execute() {
64 		std::cout << "Event.cpp : execute function should'nt be called by event base class!" << std::endl;
65 	}
66 
67 	// this is called before the event is deleted (It's only called once.)
executeBeforeDelete()68 	virtual void executeBeforeDelete() { }
69 
getNbExecutionsToDo()70 	inline long getNbExecutionsToDo() {
71 		return nbExecutionsToDo;
72 	}
getNbExecutions()73 	inline long getNbExecutions()     {
74 		return nbExecutions;
75 	}
getEventId()76 	inline int getEventId()           {
77 		return eventId;
78 	}
increaseNbExecutions()79 	inline void increaseNbExecutions() {
80 		nbExecutions ++ ;
81 	}
setNbExecutionsToDo(int nb)82 	inline void setNbExecutionsToDo( int nb ) {
83 		if ( nb >= -1 ) nbExecutionsToDo = nb; else nbExecutions = 0;
84 	}
isCancelEventSet()85 	inline bool isCancelEventSet() {
86 		return cancelEvent;
87 	}
88 
89 
getEventDate()90 	Date getEventDate() {
91 		return eventDate;
92 	}
getTimeOut()93 	Date getTimeOut()   {
94 		return timeOut;
95 	}
setEventDate(Date d)96 	void setEventDate( Date d ) {
97 		eventDate = d;
98 	}
99 	void scheduleDeleteEvent();
100 
101 	// does this event reference this creature?
doesReferenceCreature(Creature * creature)102 	virtual inline bool doesReferenceCreature( Creature *creature ) {
103 		return false;
104 	};
105 
106 	virtual const char *getName() = 0;
107 
getCreature()108 	virtual Creature *getCreature() {
109 		return NULL;
110 	}
111 
112 
113 };
114 
115 #endif
116