Changeset 2227
- Timestamp:
- Nov 19, 2008, 4:06:51 PM (16 years ago)
- Location:
- code/branches/pickups2/src/orxonox
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/pickups2/src/orxonox/CMakeLists.txt
r2106 r2227 67 67 objects/worldentities/ParticleEmitter.cc 68 68 objects/worldentities/ParticleSpawner.cc 69 objects/pickup/PickupSpawner.cc 69 70 # objects/worldentities/Backlight.cc 71 72 objects/pickup/Item.cc 73 objects/pickup/Turbo.cc 70 74 71 75 objects/quest/AddQuest.cc -
code/branches/pickups2/src/orxonox/objects/pickup/Item.cc
r2202 r2227 1 /* has to be added to player 2 multimap<std::string, Item*> Equipment;*/ 3 4 #include "Item.h" 5 #include "core/CoreIncludes.h" 6 #include "core/XMLPort.h" 7 #include "util/String.h" 8 #include "objects/worldentities/pawns/Pawn.h" 9 10 namespace orxonox 11 { 12 Item::Item(BaseObject* creator) : BaseObject(creator) 13 { 14 RegisterObject(Item); 15 16 this->playerBaseClass_ = 0; 17 } 18 19 Item::~Item() 20 { 21 } 22 void Item::XMLPort(Element& xmlelement, XMLPort::Mode mode) 23 { 24 SUPER(Item, XMLPort, xmlelement, mode); 25 26 XMLPortParam(Item, "playerclass", setPlayerBaseClassName, getPlayerBaseClassName, xmlelement, mode); 27 } 28 29 void Item::addTo (Pawn* player) 30 { 31 //player->Equipment.insert ( std::pair<std::string, Item*>(this->itemname,this) ); 32 } 33 34 void Item::setPlayerBaseClassName(const std::string& name) 35 { 36 this->playerBaseClass_ = ClassByString(name); 37 } 38 39 const std::string& Item::getPlayerBaseClassName() const 40 { 41 if (this->playerBaseClass_) 42 return this->playerBaseClass_->getName(); 43 else 44 return BLANKSTRING; 45 } 46 } -
code/branches/pickups2/src/orxonox/objects/pickup/Item.h
r2202 r2227 1 #ifndef _Item_H__ 2 #define _Item_H__ 3 4 #include "core/BaseObject.h" 5 #include "OrxonoxPrereqs.h" 6 1 7 namespace orxonox 2 8 { 3 class _OrxonoxExport Item 9 class _OrxonoxExport Item : public BaseObject 4 10 { 5 11 public: 6 virtual bool pickedUp(Pawn* player); 7 virtual bool dropped(Pawn* player); //erst bei festen Items 12 Item( BaseObject* creator); 13 virtual ~Item(); 14 15 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 16 17 virtual bool pickedUp(Pawn* player) { return true; } 18 virtual bool dropped(Pawn* player) { return true; } //erst bei festen Items 8 19 void addTo(Pawn* player); 9 void removeFrom(Pawn* player); 10 string getPlayerBaseClass(); 11 Item( BaseObject* creator); 12 ~Item(); 20 21 inline void setPlayerBaseClass(Identifier* identifier) 22 { this->playerBaseClass_ = identifier; } 23 inline Identifier* getPlayerBaseClass() const 24 { return this->playerBaseClass_; } 13 25 14 26 private: 15 Identifier* PlayerBaseClass; //class(...) 16 17 18 } 27 void setPlayerBaseClassName(const std::string& name); 28 const std::string& getPlayerBaseClassName() const; 29 30 Identifier* playerBaseClass_; //class(...) 31 }; 19 32 } 20 33 34 #endif /* _Item_H__ */ -
code/branches/pickups2/src/orxonox/objects/pickup/PickupSpawner.cc
r2202 r2227 1 1 #include "PickupSpawner.h" 2 #include "Item.h" 3 #include "objects/worldentities/pawns/Pawn.h" 4 #include "objects/worldentities/triggers/DistanceTrigger.h" 2 5 #include "core/CoreIncludes.h" 6 #include "core/XMLPort.h" 3 7 #include "core/Template.h" 4 8 … … 12 16 13 17 this->template_ = 0; 18 this->distance_ = 50; 19 } 20 21 PickupSpawner::~PickupSpawner() 22 { 23 } 24 25 void PickupSpawner::XMLPort(Element& xmlelement, XMLPort::Mode mode) 26 { 27 SUPER(PickupSpawner, XMLPort, xmlelement, mode); 28 29 XMLPortParam(PickupSpawner, "item", setItemTemplate, getItemTemplate, xmlelement, mode); 30 XMLPortParam(PickupSpawner, "distance", setDistance, getDistance, xmlelement, mode).defaultValues(50.0f); 31 } 32 33 void PickupSpawner::tick(float dt) 34 { 35 if (this->isActive()) 36 { 37 for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it != ObjectList<Pawn>::end(); ++it) 38 { 39 Vector3 distanceVec = it->getWorldPosition() - this->getWorldPosition(); 40 if (distanceVec.length() < this->distance_) 41 this->triggering(*it); 42 } 43 } 14 44 } 15 45 … … 20 50 } 21 51 22 void PickupSpawner::processEvent(Event& event) 23 { 24 SUPER(PickupSpawner, processEvent, event); 25 26 SetSubclassEvent(PickupSpawner, "pickup", triggering, event, DistanceTrigger); 27 } 28 29 void activateSpawner(bool active) 52 void PickupSpawner::triggering(Pawn* player) 53 { 54 if (this->isActive() && this->template_ && this->template_->getBaseclassIdentifier()) 30 55 { 31 if active=true 32 this->isActive =true; 33 else 34 this->isActive = false; 35 } 36 37 void triggering(bool active, DistanceTrigger* trigger) 38 { 39 if (active= true && this->template_ && this->template_->getBaseclassIdentifier()) 40 { 41 Pawn* player = trigger->getPlayer(); // getPlayer muss noch implementiert werden 42 if(player->isA(itemtemplate_->getPlayerBaseClass())) 56 COUT(0) << "activated" << std::endl; 57 //if(player->isA(itemtemplate_->getPlayerBaseClass())) 43 58 { 44 BaseObject* newobject = this->template_->getBaseclassIdentifier()->fabricate( );59 BaseObject* newobject = this->template_->getBaseclassIdentifier()->fabricate(this); 45 60 Item* newitem = dynamic_cast<Item*>(newobject); 46 61 if (newitem) 47 newitem->addTemplate(this->itemtemplate_); 48 newitem->pickedUp(player); 62 { 63 newitem->addTemplate(this->itemtemplate_); 64 if (newitem->pickedUp(player)== true) 65 this->setActive(false); 66 else 67 delete newobject; 49 68 } 50 else51 delete newobject;52 activateSpawner(false);69 } 70 //else 71 // delete newobject; 53 72 } 54 73 } -
code/branches/pickups2/src/orxonox/objects/pickup/PickupSpawner.h
r2202 r2227 1 #ifndef _PickupSpawner_H__ 2 #define _PickupSpawner_H__ 1 3 4 #include "OrxonoxPrereqs.h" 5 6 #include "objects/worldentities/PositionableEntity.h" 7 #include "objects/Tickable.h" 2 8 3 9 namespace orxonox 4 10 { 5 class _OrxonoxExport PickupSpawner : public PositionableEnity11 class _OrxonoxExport PickupSpawner : public PositionableEntity, public Tickable 6 12 { 7 13 public: … … 9 15 virtual ~PickupSpawner(); 10 16 17 virtual void tick(float dt); 18 11 19 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 12 virtual void processEvent(Event& event); 13 virtual void changedActivity(); 14 virtual void triggering(bool active, DistanceTrigger* trigger); // Wenn ein Spieler in die Naehe kommt 15 void activateSpawner(bool active); 20 virtual void triggering(Pawn* trigger); // Wenn ein Spieler in die Naehe kommt 16 21 17 22 void setItemTemplate(const std::string& itemtemplate); 18 inline const s dt::string& getItemTemplate() const23 inline const std::string& getItemTemplate() const 19 24 { return this->itemtemplate_; } 25 26 inline void setDistance(float distance) 27 { this->distance_ = distance; } 28 inline float getDistance() const 29 { return this->distance_; } 20 30 21 31 private: 22 32 std::string itemtemplate_; 23 33 Template* template_; 24 bool isActive; 25 } 26 27 34 float distance_; 35 }; 36 } 37 38 #endif /* _PickupSpawner_H__ */ 28 39 29 40 … … 43 54 44 55 45 } -
code/branches/pickups2/src/orxonox/objects/pickup/ShipEquipmentClasses.h
r2136 r2227 23 23 { 24 24 public: 25 void AddItem(Shipitem* toAddItem);25 /*void AddItem(Shipitem* toAddItem); 26 26 void RemoveItem(Shipitem* toRemoveItem); 27 27 bool CheckifValid(Shipitem* toBeChecked); 28 28 bool CheckifSpace(); 29 29 void SwitchItem(Permanent* toSwitchItem); 30 string GetNameofPermanent (subItemTypePermanent NametoGet); //holt den Namen des getragenen Items im jeweiligen Slot.30 string GetNameofPermanent (subItemTypePermanent NametoGet);*/ //holt den Namen des getragenen Items im jeweiligen Slot. 31 31 32 32 private: 33 multimap<std::string, ShipItem*> Equipment;34 multimap<std::string, ShipItem*> Usable;35 multimap<std::string, ShipItem*> Trunk;33 multimap<std::string, Item*> Equipment; 34 multimap<std::string, Item*> Usable; 35 multimap<std::string, Item*> Trunk; 36 36 }; 37 37 } -
code/branches/pickups2/src/orxonox/objects/pickup/Turbo.cc
r2202 r2227 1 #include "Turbo.h" 2 3 #include "objects/worldentities/pawns/SpaceShip.h" 1 4 #include "core/Executor.h" 5 #include "core/CoreIncludes.h" 6 #include "core/XMLPort.h" 2 7 3 8 namespace orxonox 4 9 { 10 5 11 6 bool pickedUp(Pawn* player) 12 CreateFactory(Turbo); 13 14 Turbo::Turbo(BaseObject* creator) : Item(creator) 7 15 { 8 if(player-> isA(playerBaseClass)) 16 RegisterObject(Turbo); 17 18 this->boost_ = 0; 19 this->duration_ = 0; 20 this->accboost_ = 1; 21 } 22 23 Turbo::~Turbo() 24 { 25 } 26 27 void Turbo::XMLPort(Element& xmlelement, XMLPort::Mode mode) 28 { 29 SUPER(Turbo, XMLPort, xmlelement, mode); 30 31 XMLPortParam(Turbo, "boost", setBoost, getBoost, xmlelement, mode); 32 XMLPortParam(Turbo, "duration", setDuration, getDuration, xmlelement, mode); 33 XMLPortParam(Turbo, "accboost", setAccBoost, getAccBoost, xmlelement, mode); 34 } 35 36 bool Turbo::pickedUp(Pawn* player) 37 { 38 if(player-> isA(this->getPlayerBaseClass())) 9 39 { 10 Spaceship* ship = dynamic_cast <SpaceShip*>(player); 11 setSpeedBoost(this->boost, this->duration, Spaceship* ship) 40 SpaceShip* ship = dynamic_cast <SpaceShip*>(player); 41 this->setSpeedBoost(ship); 42 if(duration_==0) 43 addTo(player); 12 44 return true; 13 45 } … … 17 49 18 50 19 void unsetSpeedBoost(int boost, Spaceship* ship)51 void Turbo::unsetSpeedBoost(SpaceShip* ship) 20 52 { 21 ship->setMaxSpeed( ship->getMaxSpeed() - boost); 22 ship->setTransAcc( ship->getTransAcc()/ACCBOOST); 53 ship->setMaxSpeed( ship->getMaxSpeed() - this->boost_); 54 ship->setTransAcc( ship->getTransAcc()/this->accboost_); 55 COUT(3)<<"PickUp Timer expired"<<std::endl; 23 56 } 24 57 25 void setSpeedBoost(float boost, float duration, Spaceship* ship)58 void Turbo::setSpeedBoost(SpaceShip* ship) 26 59 { 27 const float ACCBOOST =1.5 28 ship->setMaxSpeed( ship->getMaxSpeed() + boost); 29 ship->setTransAcc( ship->getTransAcc()*ACCBOOST); 30 31 turbotimer_.setTimer(duration, false, this, createExecutor(createFunctor(&Turbo::unsetSpeedBoost))) 60 ship->setMaxSpeed( ship->getMaxSpeed() + this->boost_); 61 ship->setTransAcc( ship->getTransAcc()*this->accboost_); 62 if( this->duration_ != 0) 63 { 64 ExecutorMember<Turbo>* executor = createExecutor(createFunctor(&Turbo::unsetSpeedBoost)); 65 executor->setDefaultValues(ship); 66 turbotimer_.setTimer(this->duration_, false, this, executor); 67 } 32 68 33 69 } 34 70 bool Turbo::dropped(Pawn* player) 71 { 72 if (this->duration_ == 0) 73 { 74 //player->Equipment.erase ( std::pair<std::string, Item*>(this->itemname,this) ); 75 SpaceShip* ship = dynamic_cast <SpaceShip*>(player); 76 this->unsetSpeedBoost(ship); 77 } 78 return true; 79 } 35 80 36 81 } 82 /*<Template baseclass="Turbo" name=turboitem> 83 <Turbo playerclass="SpaceShip" boost=150 duration=10 accboost=10 /> 84 </Template> 85 86 <PickupSpawner item=turboitem> 87 <attached> 88 <Billboard material="Examples/Flare" scale=0.2 colour="0.0, 0.0, 1.0, 1.0" /> 89 </attached> 90 </PickupSpawner>*/ 91 37 92 38 93 39 94 40 95 41 -
code/branches/pickups2/src/orxonox/objects/pickup/Turbo.h
r2202 r2227 1 #ifndef _Turbo_H__ 2 #define _Turbo_H__ 3 1 4 #include "tools/Timer.h" 5 #include "Item.h" 6 #include "OrxonoxPrereqs.h" 2 7 3 8 namespace orxonox 4 9 { 5 class _OrxonoxExport Turbo : public Item10 class _OrxonoxExport Turbo : public Item 6 11 { 7 12 8 13 public: 9 void setSpeedBoost(int boost, float duration, Spaceship* ship) 10 void unsetSpeedBoost(int boost, Spaceship* ship) 14 Turbo(BaseObject* creator); 15 virtual ~Turbo(); 16 17 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 18 19 virtual bool pickedUp(Pawn* player); 20 virtual bool dropped(Pawn* player); //erst bei festen Items 21 22 void setSpeedBoost(SpaceShip* ship); 23 void unsetSpeedBoost(SpaceShip* ship); 24 25 inline void setBoost(float boost) 26 { this->boost_ = boost; } 27 inline float getBoost() const 28 { return this->boost_; } 29 30 inline void setDuration(float duration) 31 { this->duration_ = duration; } 32 inline float getDuration() const 33 { return this->duration_; } 34 35 36 inline void setAccBoost(float accboost) 37 { this->accboost_ = accboost; } 38 inline float getAccBoost() const 39 { return this->accboost_; } 40 11 41 private: 12 42 Timer<Turbo> turbotimer_; 13 float boost; 14 float duration; 15 } 43 float boost_; 44 float duration_; 45 float accboost_; 46 }; 16 47 } 48 49 #endif /* _Turbo_H__ */
Note: See TracChangeset
for help on using the changeset viewer.