SpawnAreaComponent.cpp

Go to the documentation of this file.
00001 /*
00002 SagaEngine library
00003 Copyright (c) 2002-2006 Skalden Studio AS
00004 
00005 This software is provided 'as-is', without any express or implied 
00006 warranty. In no event will the authors be held liable for any 
00007 damages arising from the use of this software.
00008 
00009 Permission is granted to distribute the library under the terms of the 
00010 Q Public License version 1.0. Be sure to read and understand the license
00011 before using the library. It should be included here, or you may read it
00012 at http://www.trolltech.com/products/qt/licenses/licensing/qpl
00013 
00014 The original version of this library can be located at:
00015 http://www.sagaengine.com/
00016 
00017 Rune Myrland
00018 rune@skalden.com
00019 */
00020 
00021 
00022 #include "SpawnManager.hpp"
00023 #include "SpawnAreaComponent.hpp"
00024 #include "SpawnComponent.hpp"
00025 #include "sim/sim.hpp"
00026 #include "sim/schema/SimSchema.hpp"
00027 #include "comp/list/CompositeList.hpp"
00028 #include "util/error/Log.hpp"
00029 #include "comp/schema/CompSchema.hpp"
00030 #include "../area/Area.hpp"
00031 
00032 
00033 
00034 namespace se_core {
00035 
00036     SpawnAreaComponent
00037     ::SpawnAreaComponent(Composite* owner, const ComponentFactory* factory) 
00038             : RootChildComponent(sct_SPAWN, owner, factory), spawnPointCount_(0), spawnPoints_(0) {
00039     }
00040 
00041 
00042     SpawnAreaComponent
00043     ::~SpawnAreaComponent() {
00044     }
00045 
00046 
00047     void SpawnAreaComponent
00048     ::setActive(bool state) {
00049         if(state) {
00050             NodeComponent* c = static_cast<NodeComponent*>(CompSchema::activeRoot().component(type_));
00051             if(c) {
00052                 setParent(*c);
00053             }
00054         }
00055         else {
00056             resetParent();
00057         }
00058     }
00059 
00060 
00061     void SpawnAreaComponent
00062     ::flipSpawns(void) {
00063         // Flip new spawns into area
00064         CompositeList::Iterator it(newSpawns_);
00065         while(it.hasNext()) {
00066             // Spawned things doesn't have to be actors
00067             Composite& c = it.next();
00068 
00069             // Newly spawned things will change area on first flip.
00070             // This will call Area::addThing, inserting it into
00071             // collisionGrid_ and other structures where it belong
00072             PosComponent::Ptr(c)->flip();
00073         }
00074 
00075         // New spawn are no longer new spawns once they are flipped
00076         newSpawns_.clear();
00077     }
00078 
00079 
00080 
00081     Composite* SpawnAreaComponent
00082     ::spawn(const char* thingName, const ViewPoint& vp, PosComponent* parent) {
00083         /*
00084         if(deniedTsMask != 0 && (tsMask(terrainStyle(vp.coor_)) & deniedTsMask) != 0) {
00085             // Tried to spawn on denied terrain type
00086             LogDetail((int)(tsMask(terrainStyle(vp.coor_))));
00087             return 0;
00088         }
00089         */
00090 
00091         // Create the thing
00092         Composite* thing = SimSchema::spawnManager().create(thingName);
00093         PosComponent::Ptr sPos(thing);
00094         Assert(thing && !sPos.isNull());
00095 
00096         // Set position and direction
00097         PosComponent::Ptr aPos(*this);
00098         sPos->nextPos().setArea(*aPos, vp);
00099 
00100         if(parent) {
00101             sPos->nextPos().setParent(*parent);
00102         }
00103 
00104         // Initial index, if area type is using it
00105         sPos->nextPos().updateWorldViewPoint();
00106         Area::Ptr area(this);
00107         sPos->nextPos().setIndex( area->index(sPos->nextPos().worldCoor()) );
00108 
00109         // Add the thing to the list of new spawns
00110         newSpawns_.add(*thing);
00111 
00112         // Return the newly created thing
00113         return thing;
00114     }
00115 
00116 
00117 
00118     void SpawnAreaComponent
00119     ::setSpawnPoints(int count, const ViewPoint* const* const spawnPoints) {
00120         //AssertDetail(spawnPoints_ == 0, "Spawn points set twice: " << owner()->name());
00121 
00122         spawnPointCount_ = count;
00123         spawnPoints_ = spawnPoints;
00124     }
00125 
00126 
00127     const ViewPoint* SpawnAreaComponent
00128     ::spawnPoint(short id) const {
00129         AssertFatal(id >= 0 && id < spawnPointCount_, ": Id=" << id << " Count=" << spawnPointCount_);
00130         AssertWarning(spawnPoints_[id] != 0, "Area= " << owner()->name() << " Id=" << id);
00131         return spawnPoints_[id];
00132     }
00133 
00134 }
00135 

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

SourceForge.net Logo