StatComponent.hpp

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 #ifndef StatComponent_hpp
00023 #define StatComponent_hpp
00024 
00025 #include "Abilities.hpp"
00026 #include "Health.hpp"
00027 #include "comp/Component.hpp"
00028 #include "../sim.hpp"
00029 #include "../action/Action.hpp"
00030 #include "../action/ActionAndParameter.hpp"
00031 #include "../config/sim_config.hpp"
00032 #include "../script/sim_script.hpp"
00033 #include "../stat/sim_stat.hpp"
00034 #include "../pos/sim_pos.hpp"
00035 #include "../thing/sim_thing.hpp"
00036 #include "comp/Composite.hpp"
00037 #include "comp/Component.hpp"
00038 #include "util/type/util_type.hpp"
00039 #include "sim/stat/PropertyHashTable.hpp"
00040 
00041 namespace se_core {
00042     class _SeCoreExport StatComponent  : public Component {
00043     public:
00044         typedef ComponentPtr<StatComponent, sct_STAT> Ptr;
00045 
00046         static StatComponent* get(Composite& composite) {
00047             StatComponent* c = static_cast<StatComponent*>(composite.component(se_core::sct_STAT));
00048             return c;
00049         }
00050 
00051         static StatComponent* get(Component& component) {
00052             StatComponent* c = static_cast<StatComponent*>(component.owner()->component(se_core::sct_STAT));
00053             return c;
00054         }
00055 
00056         static const StatComponent* get(const Component& component) {
00057             const StatComponent* c = static_cast<const StatComponent*>(component.owner()->component(se_core::sct_STAT));
00058             return c;
00059         }
00060 
00061         StatComponent(Composite* owner, const ComponentFactory* factory = 0);
00062         //void setAbilities(short* abilities);
00063 
00064         coor_t walkSpeed() const;
00065         Abilities* abilities() { return &abilities_; }
00066         const Abilities* abilities() const { return &abilities_; }
00067         Health& health() { return health_; }
00068         const Health& health() const { return health_; }
00069 
00070         bool hasDefaultAction() const {
00071             return defaultAction_.hasAction();
00072         }
00073         const ActionAndParameter& defaultAction() const { 
00074             return defaultAction_; 
00075         }
00076         const Action* defaultAction(Parameter& out) const { 
00077             out = defaultAction_.parameter();
00078             return defaultAction_.action(); 
00079         }
00080         void setDefaultAction(const Action& action, const Parameter* parameter = 0) { 
00081             defaultAction_.setAction(action);
00082             if(parameter) {
00083                 defaultAction_.copyParameter(*parameter);
00084             }
00085         }
00086         void resetDefaultAction() { defaultAction_.resetAction(); }
00087 
00088 
00089         const Composite* target() const { return target_.object(); }
00090         Composite* target() { return target_.object(); }
00091         PosComponent* targetPos();
00092         const PosComponent* targetPos() const;
00093         bool hasTarget() const { return !target_.isNull(); }
00094         void setTarget(Composite* target) { target_.set(target->ref()); }
00095         void resetTarget() { target_.reset(); }
00096 
00097         const Composite* item() const { return item_.object(); }
00098         Composite* item() { return item_.object(); }
00099         PosComponent* itemPos();
00100         const PosComponent* itemPos() const;
00101         bool hasItem() const { return !item_.isNull(); }
00102         void setItem(Composite* item) { item_.set(item->ref()); }
00103         void resetItem() { item_.reset(); }
00104 
00105         void setShouldSave(bool state) { shouldSave_ = state; }
00106         bool shouldSave() { return shouldSave_; }
00107 
00108         const Property* property(const char* name) const;
00109         const Property* property(int key) const;
00110 
00111     protected:
00112         static const int MGO_COUNT = 20;
00113         static const int SV_COUNT = 20;
00114         static const int ATT_COUNT = 20;
00115 
00116         mutable short singleValues_[SV_COUNT];
00117         String attributes_[ATT_COUNT];
00118 
00119 
00120     protected:
00121         friend class StatComponentFactory;
00122         bool shouldSave_;
00123         Abilities abilities_;
00124         Health health_;
00125         const PropertyHashTable* properties_;
00126         mutable ActionAndParameter defaultAction_;
00127         Composite::RefPtr target_;
00128         Composite::RefPtr item_;
00129     };
00130 
00131 }
00132 
00133 #endif

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

SourceForge.net Logo