SimpleActorFactory.cpp

Go to the documentation of this file.
00001 #include "SimpleActorFactory.hpp"
00002 #include "sim/thing/Actor.hpp"
00003 #include "sim/script/Script.hpp"
00004 #include "comp/comp.hpp"
00005 
00006 using namespace se_core;
00007 
00008 namespace se_basic {
00009 
00010     SimpleActorFactory
00011     ::SimpleActorFactory(String* name)
00012             : CompositeFactory(st_ACTOR, name)
00013             , isPickable_(false)
00014             , isCollideable_(false)
00015             , physics_(0)
00016             , collide_(0)
00017             , defaultAction_(0)
00018             , substance_(0)
00019             , spawnPointCount_(0)
00020             , spawnPoints_(0) {
00021         anim_[0].setWeight(1);
00022     }
00023 
00024 
00025     SimpleActorFactory
00026     ::~SimpleActorFactory() {
00027         for(int i = 0; i < spawnPointCount_; ++i) {
00028             delete spawnPoints_[ i ];
00029         }
00030         delete defaultAction_;
00031         delete[] spawnPoints_;
00032     }
00033 
00034 
00035     Composite* SimpleActorFactory
00036     ::create() const {
00037         Composite* c = new Composite(this);
00038         c->setTag(tag_);
00039         Actor* a = static_cast<Actor*>(actorFactory_.create(c));
00040 
00041         if(isCollideable_ || collide_) {
00042             CollisionComponent* cc = static_cast<CollisionComponent*>(collisionFactory_.create(c));
00043             cc->setCollide(collide_);
00044             cc->setCollideable(isCollideable_);
00045             cc->setSubstance(substance_);
00046             cc->setDoObstructView(substance_ == 2 && bounds_.maxY_ > 5 * COOR_RES);
00047         }
00048 
00049         //a->setPickable(isPickable_);
00050         a->setDefaultPhysics(physics_);
00051         a->nextPos().setBounds(bounds_);
00052         SpawnComponent::Ptr spawn(*c);
00053         if(spawnPointCount_)
00054             spawn->setSpawnPoints(spawnPointCount_, spawnPoints_);
00055 
00056 
00057         PhysicsComponent* pPhysics = PhysicsComponent::get(*c);
00058         pPhysics->nextMove() = move_;
00059 
00060         StatComponent* pStats = StatComponent::get(*c);
00061         pStats->abilities()->setBases(&abilities_);
00062         if(defaultAction_ && defaultAction_->hasAction()) {
00063             pStats->setDefaultAction(*defaultAction_->action(), &defaultAction_->parameter());
00064         }
00065 
00066         PosComponent::Ptr pPos(*c);
00067         for(int i = 0; i < Pos::MAX_ANIMS; ++i) {
00068             pPos->nextPos().anim(i).setAnim( anim_[i] );
00069         }
00070 
00071         createGenericComponents(c);
00072         createComponents(c);
00073 
00074         return c;
00075     }
00076 
00077 
00078     void SimpleActorFactory
00079     ::setBounds(const BoundingBox& b) {
00080         bounds_ = b;
00081     }
00082 
00083 
00084     void SimpleActorFactory
00085     ::setPickable(bool isPickable) {
00086         isPickable_ = isPickable;
00087     }
00088 
00089 
00090     void SimpleActorFactory
00091     ::setCollideable(bool isCollideable) {
00092         isCollideable_ = isCollideable;
00093     }
00094 
00095 
00096     void SimpleActorFactory
00097     ::setPhysics(const char* name) {
00098         physics_ = Physics::lookup(name);
00099     }
00100 
00101 
00102     void SimpleActorFactory
00103     ::setDefaultAction(const char* name) {
00104         defaultAction_ = new ActionAndParameter();
00105         defaultAction_->setAction(*Action::lookup(name));
00106     }
00107 
00108 
00109     void SimpleActorFactory
00110     ::setCollide(const char* name) {
00111         collide_ = ThingCollide::lookup(name);
00112     }
00113 
00114     void SimpleActorFactory
00115     ::setSubstance(int s) {
00116         substance_ = s;
00117     }
00118 
00119 
00120 
00121     void SimpleActorFactory
00122     ::setSpawnPoints(int count, ViewPoint* const* spawnPoints) {
00123         if(count == 0 && spawnPoints_ != 0)
00124             return;
00125         spawnPoints_ = new ViewPoint*[ count ];
00126 
00127         spawnPointCount_ = count;
00128         for(int i = 0; i < spawnPointCount_; ++i) {
00129             spawnPoints_[ i ] = spawnPoints[ i ];
00130         }
00131     }
00132 
00133     void SimpleActorFactory
00134     ::setMass(scale_t m) {
00135         move_.mass_ = m * SCALE_RES;
00136     }
00137 
00138 
00139     void SimpleActorFactory
00140     ::setFriction(float linear, float angular, float bounceDecay) {
00141         move_.linearFriction_ = linear * SCALE_STEP;
00142         move_.angularFriction_ = angular * SCALE_STEP;
00143         move_.bounceMaintain_ = 1 - bounceDecay;
00144     }
00145 
00146 
00147     void SimpleActorFactory
00148     ::setAnim(int id, int movementMode, float pos, float speed) {
00149         Assert(id >= 0 && id < Pos::MAX_ANIMS);
00150         anim_[id].setMovementMode(id);
00151         anim_[id].setStartPos(pos);
00152         anim_[id].resetPos();
00153         anim_[id].setSpeed(speed);
00154     }
00155 }

Home Page | SagaEngine trunk (updated nightly) reference generated Sun Dec 2 20:06:03 2007 by Doxygen version 1.3.9.1.

SourceForge.net Logo