1 | /* |
---|
2 | * ORXONOX - the hottest 3D action shooter ever to exist |
---|
3 | * > www.orxonox.net < |
---|
4 | * |
---|
5 | * |
---|
6 | * License notice: |
---|
7 | * |
---|
8 | * This program is free software; you can redistribute it and/or |
---|
9 | * modify it under the terms of the GNU General Public License |
---|
10 | * as published by the Free Software Foundation; either version 2 |
---|
11 | * of the License, or (at your option) any later version. |
---|
12 | * |
---|
13 | * This program is distributed in the hope that it will be useful, |
---|
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
16 | * GNU General Public License for more details. |
---|
17 | * |
---|
18 | * You should have received a copy of the GNU General Public License |
---|
19 | * along with this program; if not, write to the Free Software |
---|
20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
---|
21 | * |
---|
22 | * Author: |
---|
23 | * Gani Aliguzhinov |
---|
24 | * Co-authors: |
---|
25 | * ... |
---|
26 | * |
---|
27 | */ |
---|
28 | |
---|
29 | #include "DivisionController.h" |
---|
30 | #include "infos/PlayerInfo.h" |
---|
31 | |
---|
32 | namespace orxonox |
---|
33 | { |
---|
34 | |
---|
35 | RegisterClass(DivisionController); |
---|
36 | |
---|
37 | //Leaders share the fact that they have Wingmans |
---|
38 | DivisionController::DivisionController(Context* context) : ActionpointController(context) |
---|
39 | { |
---|
40 | RegisterObject(DivisionController); |
---|
41 | this->setFormationMode(FormationMode::DIAMOND); |
---|
42 | this->target_ = 0; |
---|
43 | this->myFollower_ = 0; |
---|
44 | this->myWingman_ = 0; |
---|
45 | } |
---|
46 | |
---|
47 | DivisionController::~DivisionController() |
---|
48 | { |
---|
49 | for (size_t i = 0; i < this->actionpoints_.size(); ++i) |
---|
50 | { |
---|
51 | if(this->actionpoints_[i]) |
---|
52 | this->actionpoints_[i]->destroy(); |
---|
53 | } |
---|
54 | this->parsedActionpoints_.clear(); |
---|
55 | this->actionpoints_.clear(); |
---|
56 | } |
---|
57 | |
---|
58 | void DivisionController::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
59 | { |
---|
60 | SUPER(DivisionController, XMLPort, xmlelement, mode); |
---|
61 | |
---|
62 | } |
---|
63 | void DivisionController::tick(float dt) |
---|
64 | { |
---|
65 | if (!this->isActive()) |
---|
66 | return; |
---|
67 | |
---|
68 | SUPER(DivisionController, tick, dt); |
---|
69 | |
---|
70 | } |
---|
71 | void DivisionController::action() |
---|
72 | { |
---|
73 | if (!this || !this->getControllableEntity() || !this->isActive()) |
---|
74 | return; |
---|
75 | |
---|
76 | ActionpointController::action(); |
---|
77 | if (!this || !this->getControllableEntity()) |
---|
78 | return; |
---|
79 | if (!(this->parsedActionpoints_.empty() && this->loopActionpoints_.empty())) |
---|
80 | { |
---|
81 | if (this->myFollower_) |
---|
82 | { |
---|
83 | this->myFollower_->takeActionpoints(this->parsedActionpoints_, this->loopActionpoints_, this->bLoop_); |
---|
84 | } |
---|
85 | else if (this->myWingman_) |
---|
86 | { |
---|
87 | this->myWingman_->takeActionpoints(this->parsedActionpoints_, this->loopActionpoints_, this->bLoop_); |
---|
88 | } |
---|
89 | } |
---|
90 | |
---|
91 | |
---|
92 | } |
---|
93 | //I wanted to do it different here, but at this point I think nothing will change if I delete that method |
---|
94 | void DivisionController::stayNearProtect() |
---|
95 | { |
---|
96 | ActionpointController::stayNearProtect(); |
---|
97 | } |
---|
98 | |
---|
99 | bool DivisionController::setWingman(ActionpointController* newWingman) |
---|
100 | { |
---|
101 | if (!this->myWingman_) |
---|
102 | { |
---|
103 | this->myWingman_ = newWingman; |
---|
104 | if (!this->hasFollower()) |
---|
105 | newWingman->takeActionpoints (this->parsedActionpoints_, this->loopActionpoints_, this->bLoop_); |
---|
106 | return true; |
---|
107 | } |
---|
108 | else |
---|
109 | { |
---|
110 | return false; |
---|
111 | } |
---|
112 | } |
---|
113 | bool DivisionController::setFollower(ActionpointController* newFollower) |
---|
114 | { |
---|
115 | if (!this->myFollower_) |
---|
116 | { |
---|
117 | this->myFollower_ = newFollower; |
---|
118 | if (this->hasWingman()) |
---|
119 | { |
---|
120 | this->myWingman_->takeActionpoints (std::vector<Point>(), std::vector<Point>(), false); |
---|
121 | } |
---|
122 | |
---|
123 | newFollower->takeActionpoints (this->parsedActionpoints_, this->loopActionpoints_, this->bLoop_); |
---|
124 | |
---|
125 | return true; |
---|
126 | } |
---|
127 | else |
---|
128 | { |
---|
129 | return false; |
---|
130 | } |
---|
131 | } |
---|
132 | bool DivisionController::hasWingman() |
---|
133 | { |
---|
134 | if (this->myWingman_) |
---|
135 | return true; |
---|
136 | else |
---|
137 | return false; |
---|
138 | } |
---|
139 | bool DivisionController::hasFollower() |
---|
140 | { |
---|
141 | if (this->myFollower_) |
---|
142 | return true; |
---|
143 | |
---|
144 | return false; |
---|
145 | } |
---|
146 | |
---|
147 | } |
---|