1 | /* |
---|
2 | orxonox - the future of 3D-vertical-scrollers |
---|
3 | |
---|
4 | Copyright (C) 2004 orx |
---|
5 | |
---|
6 | This program is free software; you can redistribute it and/or modify |
---|
7 | it under the terms of the GNU General Public License as published by |
---|
8 | the Free Software Foundation; either version 2, or (at your option) |
---|
9 | any later version. |
---|
10 | |
---|
11 | ### File Specific: |
---|
12 | main-programmer: Silvan Nellen |
---|
13 | co-programmer: Benjamin Knecht |
---|
14 | */ |
---|
15 | |
---|
16 | |
---|
17 | #include "playable.h" |
---|
18 | |
---|
19 | #include "weapons/weapon_manager.h" |
---|
20 | #include "event_handler.h" |
---|
21 | #include "player.h" |
---|
22 | |
---|
23 | |
---|
24 | Playable::Playable() |
---|
25 | { |
---|
26 | this->init(); |
---|
27 | } |
---|
28 | |
---|
29 | Playable::~Playable() |
---|
30 | { |
---|
31 | delete this->weaponMan; |
---|
32 | |
---|
33 | if (this->currentPlayer) |
---|
34 | { |
---|
35 | PRINTF(2)("There is Still a Player subscribed to this Playable (%s::%s)\n", this->getClassName(), this->getName()); |
---|
36 | |
---|
37 | } |
---|
38 | } |
---|
39 | |
---|
40 | void Playable::init() |
---|
41 | { |
---|
42 | this->setClassID(CL_PLAYABLE, "Playable"); |
---|
43 | PRINTF(4)("PLAYABLE INIT\n"); |
---|
44 | this->weaponMan = new WeaponManager(this); |
---|
45 | |
---|
46 | this->currentPlayer = NULL; |
---|
47 | } |
---|
48 | |
---|
49 | /** |
---|
50 | * subscribe to all events the controllable needs |
---|
51 | */ |
---|
52 | bool Playable::subscribePlayer(Player* player) |
---|
53 | { |
---|
54 | if (this->currentPlayer != NULL) |
---|
55 | { |
---|
56 | PRINTF(1)("Already registered Player:%s to this Playable (%s:%s)\n", this->currentPlayer->getName(), this->getClassName(), this->getName()); |
---|
57 | return false; |
---|
58 | } |
---|
59 | else |
---|
60 | { |
---|
61 | this->currentPlayer = player; |
---|
62 | /*EventHandler*/ |
---|
63 | EventHandler* evh = EventHandler::getInstance(); |
---|
64 | std::list<int>::iterator ev; |
---|
65 | for (ev = this->events.begin(); ev != events.end(); ev++) |
---|
66 | evh->subscribe(player, ES_GAME, (*ev)); |
---|
67 | |
---|
68 | return true; |
---|
69 | } |
---|
70 | } |
---|
71 | |
---|
72 | /** |
---|
73 | * add an event to the event list |
---|
74 | */ |
---|
75 | void Playable::registerEvent(int eventType) |
---|
76 | { |
---|
77 | this->events.push_back(eventType); |
---|
78 | |
---|
79 | } |
---|
80 | |
---|
81 | |
---|
82 | |
---|