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 | * Fabian 'x3n' Landau |
---|
24 | * Co-authors: |
---|
25 | * Simon Miescher |
---|
26 | * |
---|
27 | */ |
---|
28 | |
---|
29 | /* |
---|
30 | * |
---|
31 | * |
---|
32 | * An asteroid which can be destroyed. Some smaller asteroids are created and a pickup |
---|
33 | * spawns. |
---|
34 | * |
---|
35 | * |
---|
36 | * |
---|
37 | |
---|
38 | */ |
---|
39 | |
---|
40 | |
---|
41 | #include "Pawn.h" |
---|
42 | #include "AsteroidMinable.h" |
---|
43 | |
---|
44 | |
---|
45 | #include <algorithm> |
---|
46 | |
---|
47 | #include "core/CoreIncludes.h" |
---|
48 | #include "core/GameMode.h" |
---|
49 | #include "core/XMLPort.h" |
---|
50 | #include "core/EventIncludes.h" |
---|
51 | #include "network/NetworkFunction.h" |
---|
52 | |
---|
53 | #include "infos/PlayerInfo.h" |
---|
54 | #include "controllers/Controller.h" |
---|
55 | #include "gametypes/Gametype.h" |
---|
56 | #include "graphics/ParticleSpawner.h" |
---|
57 | #include "worldentities/ExplosionChunk.h" |
---|
58 | #include "worldentities/ExplosionPart.h" |
---|
59 | #include "weaponsystem/WeaponSystem.h" |
---|
60 | #include "weaponsystem/WeaponSlot.h" |
---|
61 | #include "weaponsystem/WeaponPack.h" |
---|
62 | #include "weaponsystem/WeaponSet.h" |
---|
63 | #include "weaponsystem/Munition.h" |
---|
64 | #include "sound/WorldSound.h" |
---|
65 | #include "core/object/ObjectListIterator.h" |
---|
66 | |
---|
67 | #include "controllers/FormationController.h" |
---|
68 | #include "pickup/items/HealthPickup.h" |
---|
69 | #include "pickup/PickupSpawner.h" |
---|
70 | #include "pickup/Pickup.h" |
---|
71 | |
---|
72 | namespace orxonox |
---|
73 | { |
---|
74 | RegisterClass(AsteroidMinable); |
---|
75 | |
---|
76 | AsteroidMinable::AsteroidMinable(Context* context) : Pawn(context) |
---|
77 | { |
---|
78 | RegisterObject(AsteroidMinable); |
---|
79 | this->setRadarObjectColour(ColourValue(1.0f, 1.0f, 0.0f, 1.0f)); |
---|
80 | this->setRadarObjectShape(RadarViewable::Shape::Dot); |
---|
81 | |
---|
82 | this->generateSmaller = true; |
---|
83 | this->size = 5; |
---|
84 | this->context = context; |
---|
85 | |
---|
86 | |
---|
87 | |
---|
88 | // <Model position="0,-40,40" yaw="90" pitch="-90" roll="0" scale="4" mesh="ast6.mesh" /> |
---|
89 | |
---|
90 | |
---|
91 | } |
---|
92 | |
---|
93 | AsteroidMinable::~AsteroidMinable() |
---|
94 | { |
---|
95 | |
---|
96 | } |
---|
97 | |
---|
98 | void AsteroidMinable::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
99 | { |
---|
100 | SUPER(AsteroidMinable, XMLPort, xmlelement, mode); |
---|
101 | // XMLPortParam(PickupSpawner, "pickup", setPickupTemplateName, getPickupTemplateName, xmlelement, mode); |
---|
102 | XMLPortParam(AsteroidMinable, "size", setSize,getSize, xmlelement, mode); |
---|
103 | |
---|
104 | } |
---|
105 | |
---|
106 | void AsteroidMinable::XMLEventPort(Element& xmlelement, XMLPort::Mode mode) |
---|
107 | { |
---|
108 | SUPER(AsteroidMinable, XMLEventPort, xmlelement, mode); |
---|
109 | |
---|
110 | //XMLPortEventState(AsteroidMinable, BaseObject, "vulnerability", setVulnerable, xmlelement, mode); |
---|
111 | } |
---|
112 | |
---|
113 | void AsteroidMinable::registerVariables() |
---|
114 | { |
---|
115 | registerVariable(this->bAlive_, VariableDirection::ToClient); |
---|
116 | registerVariable(this->bVulnerable_, VariableDirection::ToClient); |
---|
117 | registerVariable(this->health_, VariableDirection::ToClient); |
---|
118 | registerVariable(this->maxHealth_, VariableDirection::ToClient); |
---|
119 | } |
---|
120 | |
---|
121 | void AsteroidMinable::tick(float dt) |
---|
122 | { |
---|
123 | SUPER(Pawn, tick, dt); |
---|
124 | |
---|
125 | } |
---|
126 | |
---|
127 | void AsteroidMinable::setSize(float s){ |
---|
128 | this->size = s; |
---|
129 | this->health_ = 200*s; |
---|
130 | } |
---|
131 | |
---|
132 | float AsteroidMinable::getSize(){ |
---|
133 | return this->size; |
---|
134 | } |
---|
135 | |
---|
136 | void AsteroidMinable::death() //ueberschreiben |
---|
137 | { |
---|
138 | this->setHealth(1); |
---|
139 | |
---|
140 | |
---|
141 | |
---|
142 | // Spawn Pickup |
---|
143 | HealthPickup* hP = new HealthPickup(context); |
---|
144 | //OFFEN: Add custom pickup 'resources' |
---|
145 | PickupSpawner* thingy = new PickupSpawner(context); |
---|
146 | thingy->createDroppedPickup(context, hP, nullptr, 10); |
---|
147 | // /*static*/ PickupSpawner* PickupSpawner::createDroppedPickup(Context* context, Pickupable* pickup, PickupCarrier* carrier, float triggerDistance) |
---|
148 | |
---|
149 | |
---|
150 | |
---|
151 | if(this->generateSmaller){ |
---|
152 | this->spawnChildren(); |
---|
153 | } |
---|
154 | |
---|
155 | |
---|
156 | |
---|
157 | if (this->getGametype() && this->getGametype()->allowPawnDeath(this, this->lastHitOriginator_)) |
---|
158 | { |
---|
159 | // Set bAlive_ to false and wait for destroyLater() to do the destruction |
---|
160 | this->bAlive_ = false; |
---|
161 | this->destroyLater(); |
---|
162 | |
---|
163 | this->setDestroyWhenPlayerLeft(false); |
---|
164 | |
---|
165 | } |
---|
166 | } |
---|
167 | |
---|
168 | |
---|
169 | void AsteroidMinable::spawnChildren(){ |
---|
170 | // Spawn smaller Children |
---|
171 | int massRem = this->size-1; //some mass is lost |
---|
172 | int num = round(massRem*rand()); // random number of children |
---|
173 | massRem = massRem-num; |
---|
174 | int extra = 0; |
---|
175 | for(int fisch=num; fisch>=1; fisch++){ |
---|
176 | // to distribute remaining mass |
---|
177 | if(fisch==1){ |
---|
178 | extra = massRem; |
---|
179 | }else{ |
---|
180 | extra = round(massRem*rand()); |
---|
181 | massRem = massRem-extra; |
---|
182 | } |
---|
183 | //Spawn this child |
---|
184 | AsteroidMinable* child = new AsteroidMinable(context); |
---|
185 | child->setSize(extra + 1); |
---|
186 | |
---|
187 | //OFFEN:Kollision der Kinder verhindern |
---|
188 | //Relativ zu Elternteil automatisch? |
---|
189 | //Typ position:rand()*Vektoriwas? |
---|
190 | // pawn->getWorldPosition() + Vector3(30,0,-30); |
---|
191 | child->setPosition(this->getCarrierPosition()); |
---|
192 | } |
---|
193 | } |
---|
194 | |
---|
195 | |
---|
196 | |
---|
197 | |
---|
198 | } |
---|
199 | |
---|
200 | |
---|
201 | |
---|
202 | |
---|
203 | |
---|
204 | /* |
---|
205 | void DronePickup::changedUsed(void) |
---|
206 | { |
---|
207 | SUPER(DronePickup, changedUsed); |
---|
208 | |
---|
209 | // If the pickup has transited to used. |
---|
210 | if(this->isUsed()) |
---|
211 | { |
---|
212 | |
---|
213 | Pawn* pawn = this->carrierToPawnHelper(); |
---|
214 | if(pawn == nullptr) // If the PickupCarrier is no Pawn, then this pickup is useless and therefore is destroyed. |
---|
215 | this->Pickupable::destroy(); |
---|
216 | |
---|
217 | //Attach to pawn |
---|
218 | Drone* drone = new Drone(pawn->getContext()); // this is neccessary because the projectiles fired need a valid creator for the particlespawner (when colliding against something) |
---|
219 | drone->addTemplate(this->getDroneTemplate()); |
---|
220 | |
---|
221 | Controller* controller = drone->getController(); |
---|
222 | DroneController* droneController = orxonox_cast<DroneController*>(controller); |
---|
223 | if(droneController != nullptr) |
---|
224 | { |
---|
225 | droneController->setOwner(pawn); |
---|
226 | } |
---|
227 | |
---|
228 | Vector3 spawnPosition = pawn->getWorldPosition() + Vector3(30,0,-30); |
---|
229 | drone->setPosition(spawnPosition); |
---|
230 | |
---|
231 | // The pickup has been used up. |
---|
232 | this->setUsed(false); |
---|
233 | } |
---|
234 | else |
---|
235 | { |
---|
236 | // If either the pickup can only be used once or it is continuous and used up, it is destroyed upon setting it to unused. |
---|
237 | if(this->isOnce() || (this->isContinuous() )) |
---|
238 | { |
---|
239 | this->Pickupable::destroy(); |
---|
240 | } |
---|
241 | } |
---|
242 | } |
---|
243 | */ |
---|