Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Feb 11, 2018, 10:31:46 PM (6 years ago)
Author:
landauf
Message:

[AsteroidMining_HS17] some cleanup - Field and Belt should not depend on Pawn, should not be synchronized either (server-side logic). also removed additional constructors and replaced with regular setters.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/Presentation_HS17_merge/src/modules/asteroidmining/AsteroidMinable.cc

    r11735 r11736  
    7171*/
    7272
    73 
    74 #include "../../orxonox/worldentities/pawns/Pawn.h"
    75 #include "../../orxonox/worldentities/WorldEntity.h"
    76 
    7773#include "AsteroidMinable.h"
    7874
     
    8278#include "core/GameMode.h"
    8379#include "core/XMLPort.h"
    84 #include "core/EventIncludes.h"
    85 #include "network/NetworkFunction.h"
    8680#include "util/Convert.h"
    8781#include "util/Math.h"
    8882
    89 #include "../pickup/PickupSpawner.h"
    90 #include "../pickup/Pickup.h"
    91 
    92 #include "../objects/collisionshapes/SphereCollisionShape.h"
    93 #include "../../orxonox/graphics/Model.h"
    94 
     83#include "pickup/PickupSpawner.h"
     84#include "pickup/Pickup.h"
     85
     86#include "objects/collisionshapes/SphereCollisionShape.h"
     87#include "graphics/Model.h"
    9588
    9689namespace orxonox{
     
    10295
    10396        RegisterObject(AsteroidMinable);
    104         this->context = context;
    10597
    10698        // Default Values:
    107         this->size = 10;
     99        this->size = 1;
    108100        this->dropStuff = true;
    109101        this->generateSmaller = true;
    110         this->health_ = 15*size;
    111         this->maxHealth_ = this->health_;
    112102        this->acceptsPickups_ = false;
    113103
     
    121111    }
    122112
    123     // @brief Use this constructor with care. Mainly used internally, arguments are passed directly.
    124     AsteroidMinable::AsteroidMinable(Context* c, float size, Vector3 position, bool dropStuff) : Pawn(c){
    125 
    126         RegisterObject(AsteroidMinable);
     113    AsteroidMinable::~AsteroidMinable(){
     114
     115    }
     116
     117    void AsteroidMinable::setSize(int s)
     118    {
     119        this->size = s;
     120        this->health_ = 15*size;
     121        this->maxHealth_ = this->health_;
     122    }
     123
     124    // @brief Helper method.
     125    void AsteroidMinable::putStuff(){
    127126
    128127        // The radar is able to detect whether an asteroid contains resources....
     
    136135        }
    137136
    138         this->context = c;
    139         this->size = size;
    140         this->health_ = 15*size;
    141         this->maxHealth_ = this->health_;
    142         this->acceptsPickups_ = false;
    143         this->generateSmaller = true;
    144         this->dropStuff = dropStuff;
    145 
    146         this->setPosition(position);
    147         //this->roll = rand()*5; //etwas Drehung. Richtige Variable?
    148 
    149         this->setCollisionType(WorldEntity::CollisionType::Dynamic);
    150         this->enableCollisionCallback();
    151 
    152137        // Add Model, random one of the 6 shapes
    153         Model* hull = new Model(this->context);
     138        Model* hull = new Model(this->getContext());
    154139        hull->setMeshSource("ast" + multi_cast<std::string>(1 + (int)rnd(0, 6)) + ".mesh");
    155140        hull->setScale(this->size);
     
    157142
    158143        // Collision shape
    159         SphereCollisionShape* cs = new SphereCollisionShape(this->context);
     144        SphereCollisionShape* cs = new SphereCollisionShape(this->getContext());
    160145        cs->setRadius((this->size)*2); //OFFEN: Feinabstimmung der Radien.
    161146        this->attachCollisionShape(cs);
    162147
    163         this->registerVariables();
    164 
    165148        this->initialised=true;
    166 
    167     }
    168 
    169     AsteroidMinable::~AsteroidMinable(){
    170 
    171     }
    172 
    173     // @brief Helper method.
    174     void AsteroidMinable::putStuff(){
    175 
    176         AsteroidMinable* reborn = new AsteroidMinable(this->context, this->size, this->getPosition(), this->dropStuff);
    177         reborn->setVelocity(this->getVelocity());
    178         // reborn->setAngularVelocity(this->getAngularVelocity()); // Add all other stuff, too?
    179 
    180         this->bAlive_ = false;
    181         this->destroyLater();
    182 
    183149    }
    184150
     
    188154
    189155        XMLPortParam(AsteroidMinable, "size", setSize, getSize, xmlelement, mode);
    190         XMLPortParam(AsteroidMinable, "generateSmaller", toggleShattering, doesShatter, xmlelement, mode);
    191         XMLPortParam(AsteroidMinable, "dropStuff", toggleDropStuff, doesDropStuff, xmlelement, mode);
    192 
    193     }
    194 
    195     void AsteroidMinable::XMLEventPort(Element& xmlelement, XMLPort::Mode mode){
    196 
    197         SUPER(AsteroidMinable, XMLEventPort, xmlelement, mode);
     156        XMLPortParam(AsteroidMinable, "generateSmaller", setShattering, doesShatter, xmlelement, mode);
     157        XMLPortParam(AsteroidMinable, "dropStuff", setDropStuff, doesDropStuff, xmlelement, mode);
    198158
    199159    }
     
    228188        // Pickups which can be harvested. It's munition at the moment, could be changed/extended.
    229189        if(dropStuff){
    230             PickupSpawner* thingy = new PickupSpawner(this->context);
     190            PickupSpawner* thingy = new PickupSpawner(this->getContext());
    231191
    232192            std::string tname;
     
    366326        }
    367327       
    368         AsteroidMinable* child = new AsteroidMinable(this->context, masses[fisch], this->getPosition() + pos, this->dropStuff);
     328        AsteroidMinable* child = new AsteroidMinable(this->getContext());
     329        child->setSize(masses[fisch]);
     330        child->setPosition(this->getPosition() + pos);
    369331        child->setVelocity(this->getVelocity());
    370 
     332        child->setDropStuff(this->dropStuff);
    371333    }
    372334    // orxout() << "Leaving spawnChildren() method. " << endl;
Note: See TracChangeset for help on using the changeset viewer.