Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/AsteroidMining_HS17/src/modules/asteroidmining/AsteroidMinable.cc @ 11547

Last change on this file since 11547 was 11547, checked in by remartin, 7 years ago
File size: 9.1 KB
Line 
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 "../../orxonox/worldentities/pawns/Pawn.h"
42#include "../../orxonox/worldentities/WorldEntity.h"
43
44#include "AsteroidMinable.h"
45
46#include <algorithm>
47
48#include "core/CoreIncludes.h"
49#include "core/GameMode.h"
50#include "core/XMLPort.h"
51#include "core/EventIncludes.h"
52#include "network/NetworkFunction.h"
53
54// #include "infos/PlayerInfo.h"
55// #include "controllers/Controller.h"
56// #include "gametypes/Gametype.h"
57// #include "graphics/ParticleSpawner.h"
58// #include "worldentities/ExplosionChunk.h"
59// #include "worldentities/ExplosionPart.h"
60
61// #include "core/object/ObjectListIterator.h"
62// #include "controllers/FormationController.h"
63
64#include "../pickup/items/HealthPickup.h"
65#include "../pickup/PickupSpawner.h"
66#include "../pickup/Pickup.h"
67#include "../objects/collisionshapes/SphereCollisionShape.h"
68#include "../../orxonox/graphics/Model.h"
69
70
71/*Veraenderungstagebuch
72- Dynamische Definition von Argumenten funktioniert nicht
73- Death-Methode -> Absturz
74
75
76
77
78*/
79
80
81
82namespace orxonox
83{
84    RegisterClass(AsteroidMinable);
85
86    AsteroidMinable::AsteroidMinable(Context* context) : Pawn(context)
87    {
88        RegisterObject(AsteroidMinable);
89        this->setRadarObjectColour(ColourValue(1.0f, 1.0f, 0.0f, 1.0f));
90        this->setRadarObjectShape(RadarViewable::Shape::Dot);
91
92        this->setCollisionType(WorldEntity::CollisionType::Dynamic);
93
94        this->generateSmaller = true;
95        //this->size = this->getSize(); // Value doesn-t get accepted. Weird.
96        this->size = 5;
97        this->context = context;
98
99
100        Model* hull = new Model(this->context);
101        // random one of the 6 shapes
102        //char meshThingy[] = "";
103        //sprintf(meshThingy, "ast%f.mesh", round(rand()*5)+1);
104        //    sprintf(str, "Value of Pi = %f", M_PI);
105        char meshThingy[] = "ast5.mesh";
106
107
108        hull->setMeshSource(meshThingy);
109        hull->setScale(size);
110        this->attach(hull);
111        //hull->setPosition(this->getPosition());
112
113        SphereCollisionShape* cs = new SphereCollisionShape(this->context);
114        cs->setRadius(size*2); //OFFEN: Feinabstimmung der Radien
115        this->attachCollisionShape(cs);
116
117
118
119        //      <Model position="0,-40,40" yaw="90" pitch="-90" roll="0" scale="4" mesh="ast6.mesh" />
120/*
121            Model* slotModel = nullptr;
122
123            for (int i = 0; i < numWeaponSlots; ++i)
124            {
125                slotPosition = weaponSlots.at(i)->getPosition();
126                slotOrientation = weaponSlots.at(i)->getOrientation();
127                slotModel = new Model(this->getContext());
128                slotModel->setMeshSource("Coordinates.mesh");
129                slotModel->setScale(3.0f);
130                slotModel->setOrientation(slotOrientation);
131                slotModel->setPosition(slotPosition);
132
133                this->attach(slotModel);
134                debugWeaponSlotModels_.push_back(slotModel);
135            }
136        }
137        else
138        {
139            // delete all debug models
140            for(Model* model : debugWeaponSlotModels_)
141            {
142                model->destroy();
143            }
144            debugWeaponSlotModels_.clear();
145        }
146*/
147
148
149
150 
151    }
152
153    AsteroidMinable::~AsteroidMinable()
154    {
155
156    }
157
158    void AsteroidMinable::XMLPort(Element& xmlelement, XMLPort::Mode mode)
159    {
160        SUPER(AsteroidMinable, XMLPort, xmlelement, mode);
161        //        XMLPortParam(PickupSpawner, "pickup", setPickupTemplateName, getPickupTemplateName, xmlelement, mode);
162        XMLPortParam(AsteroidMinable, "size", setSize, getSize, xmlelement, mode);
163
164    }
165
166    void AsteroidMinable::XMLEventPort(Element& xmlelement, XMLPort::Mode mode)
167    {
168        SUPER(AsteroidMinable, XMLEventPort, xmlelement, mode);
169
170        //XMLPortEventState(AsteroidMinable, BaseObject, "vulnerability", setVulnerable, xmlelement, mode);
171    }
172
173    void AsteroidMinable::registerVariables()
174    {
175        registerVariable(this->bAlive_,            VariableDirection::ToClient);
176        registerVariable(this->bVulnerable_,       VariableDirection::ToClient);
177        registerVariable(this->health_,            VariableDirection::ToClient);
178        registerVariable(this->maxHealth_,         VariableDirection::ToClient);
179    }
180
181    void AsteroidMinable::tick(float dt)
182    {
183        SUPER(Pawn, tick, dt);
184        if(this->health_ <=0){
185            this->death();
186        }
187
188    }
189
190    void AsteroidMinable::setSize(float s){
191        this->size = s;
192        this->health_ = 200*s;
193    }
194
195    float AsteroidMinable::getSize(){
196        return this->size;
197    }
198
199    void AsteroidMinable::death() //ueberschreiben
200    {
201
202        // pawn -> addExplosionPart
203        // this.goWithStyle()
204
205        // Spawn Pickup
206        HealthPickup* hP = new HealthPickup(context);
207        //OFFEN: Add custom pickup 'resources'
208        PickupSpawner* thingy = new PickupSpawner(context);
209        thingy->setPosition(this->getPosition());
210        thingy->createDroppedPickup(context, hP, nullptr, 10);
211
212//    /*static*/ PickupSpawner* PickupSpawner::createDroppedPickup(Context* context, Pickupable* pickup, PickupCarrier* carrier, float triggerDistance)
213   
214
215
216        if(this->generateSmaller){
217            this->spawnChildren();
218        }
219
220        // OFFEN: Sauber kapputten
221        // just copied other stuff:
222        this->setHealth(1);
223        this->bAlive_ = false;
224        this->destroyLater();
225        this->setDestroyWhenPlayerLeft(false);
226
227        // if (this->getGametype() && this->getGametype()->allowPawnDeath(this, this->lastHitOriginator_))
228        // {
229        //     // Set bAlive_ to false and wait for destroyLater() to do the destruction
230        //     this->bAlive_ = false;
231        //     this->destroyLater();
232
233        //     this->setDestroyWhenPlayerLeft(false);
234
235        // }
236    }
237
238
239void AsteroidMinable::spawnChildren(){
240    // Spawn smaller Children
241    int massRem = this->size-1; //some mass is lost
242    int num = round((massRem-1)*rand())+1; // random number of children, at least one
243    massRem = massRem-num;
244    int extra = 0;
245    for(int fisch=num; fisch>=1; fisch++){
246        // to distribute remaining mass
247        if(fisch==1){ 
248            extra = massRem;
249        }else{
250            extra = round(massRem*rand());
251            massRem = massRem-extra;
252        }
253        //Spawn this child
254        AsteroidMinable* child = new AsteroidMinable(context);
255        child->setSize(extra + 1);
256           
257        //OFFEN:Kollision der Kinder verhindern
258        //Relativ zu Elternteil automatisch?
259        //Typ position:rand()*Vektoriwas?
260        // pawn->getWorldPosition() + Vector3(30,0,-30);
261        child->setPosition(this->getPosition() + Vector3(num*5, 0, 0));
262    }
263}
264
265
266
267
268}
269
270
271
272
273
274/*
275    void DronePickup::changedUsed(void)
276    {
277        SUPER(DronePickup, changedUsed);
278
279        // If the pickup has transited to used.
280        if(this->isUsed())
281        {
282
283                Pawn* pawn = this->carrierToPawnHelper();
284                if(pawn == nullptr) // If the PickupCarrier is no Pawn, then this pickup is useless and therefore is destroyed.
285                    this->Pickupable::destroy();
286
287                //Attach to pawn
288                Drone* drone = new Drone(pawn->getContext()); // this is neccessary because the projectiles fired need a valid creator for the particlespawner (when colliding against something)
289                drone->addTemplate(this->getDroneTemplate());
290
291                Controller* controller = drone->getController();
292                DroneController* droneController = orxonox_cast<DroneController*>(controller);
293                if(droneController != nullptr)
294                {
295                    droneController->setOwner(pawn);
296                }
297
298                Vector3 spawnPosition = pawn->getWorldPosition() + Vector3(30,0,-30);
299                drone->setPosition(spawnPosition);
300
301                // The pickup has been used up.
302                this->setUsed(false);
303        }
304        else
305        {
306            // If either the pickup can only be used once or it is continuous and used up, it is destroyed upon setting it to unused.
307            if(this->isOnce() || (this->isContinuous() ))
308            {
309                this->Pickupable::destroy();
310            }
311        }
312    }
Note: See TracBrowser for help on using the repository browser.