forked from miki151/keeperrl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquest.cpp
65 lines (52 loc) · 1.53 KB
/
quest.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
#include "stdafx.h"
#include "quest.h"
#include "event.h"
#include "tribe.h"
#include "message_buffer.h"
using namespace std;
class KillTribeQuest : public Quest, public EventListener {
public:
KillTribeQuest(Tribe* _tribe, string msg, bool onlyImp = false)
: tribe(_tribe), message(msg), onlyImportant(onlyImp) {
EventListener::addListener(this);
}
virtual bool isFinished() const override {
for (const Creature* c : (onlyImportant ? tribe->getImportantMembers() : tribe->getMembers()))
if (!c->isDead())
return false;
return true;
}
virtual void onKillEvent(const Creature* member, const Creature* attacker) {
if (isFinished() && !notified) {
notified = true;
for (auto c : adventurers)
c->privateMessage(MessageBuffer::important("Your quest is finished."));
}
}
virtual string getMessage() const override {
return message;
}
private:
Tribe* tribe;
string message;
bool onlyImportant;
bool notified = false;
};
Quest* Quest::killTribeQuest(Tribe* tribe, string message, bool onlyImp) {
return new KillTribeQuest(tribe, message, onlyImp);
}
Quest* Quest::dragon;
Quest* Quest::castleCellar;
Quest* Quest::bandits;
Quest* Quest::goblins;
Quest* Quest::dwarves;
void Quest::addAdventurer(const Creature* c) {
adventurers.insert(c);
}
void Quest::setLocation(const Location* loc) {
CHECK(location == nullptr) << "Attempted to set quest location for a second time";
location = loc;
}
const Location* Quest::getLocation() const {
return location;
}