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 ScriptComponent_hpp 00023 #define ScriptComponent_hpp 00024 00025 #include "sim_script.hpp" 00026 #include "comp/Component.hpp" 00027 #include "comp/Composite.hpp" 00028 #include "../action/ActionComponent.hpp" 00029 #include "../action/ActionFeed.hpp" 00030 #include "../action/sim_action.hpp" 00031 #include "../thing/sim_thing.hpp" 00032 #include "util/type/all.hpp" 00033 00034 namespace se_core { 00035 class _SeCoreExport ScriptComponent : public Component, public ActionFeed { 00036 public: 00037 typedef ComponentPtr<ScriptComponent, sct_SCRIPT> Ptr; 00038 00039 ScriptComponent(Composite* owner, ActionComponent* consumer); 00040 ScriptComponent(Composite* owner, const ComponentFactory* factory); 00041 00042 virtual ~ScriptComponent(); 00043 00044 static ScriptComponent* get(Composite& composite) { 00045 ScriptComponent* c = static_cast<ScriptComponent*>(composite.component(se_core::sct_SCRIPT)); 00046 return c; 00047 } 00048 00049 static ScriptComponent* get(Component& component) { 00050 ScriptComponent* c = static_cast<ScriptComponent*>(component.owner()->component(se_core::sct_SCRIPT)); 00051 return c; 00052 } 00053 00054 // 00055 // Override from ActionFeed 00056 void nextAction(const ActionComponent& performer, int channel, ActionAndParameter& out); 00057 00061 virtual void setActive(bool state); 00062 00063 00064 00070 void pushScript(const Script* s); 00071 00077 void pushScript(const char* name); 00078 00083 void popScript(); 00084 00087 inline bool hasActiveScript() const { 00088 return scriptStack_[currentScript_] != 0; 00089 } 00090 00094 inline const Script* script() const { 00095 return scriptStack_[currentScript_]; 00096 } 00097 00098 inline ScriptData* scriptData() { 00099 return scriptData_[currentScript_]; 00100 } 00101 00102 00108 void clearScripts(); 00109 00114 void nextScriptAction(short channel, ActionAndParameter& aap); 00115 00123 void setDefaultScript(const Script* s); 00124 00131 void stopScript(); 00132 00133 void touch(void* param = 0); 00134 void touchDefault(void* param = 0); 00135 00136 void feedbackEvent(const ActionComponent& source, int type); 00137 00138 protected: 00139 void cleanup(); 00140 short currentScript_; 00141 ActionComponent* consumer_; 00142 static const short SCRIPT_STACK_SIZE = 6; 00143 const Script* scriptStack_[SCRIPT_STACK_SIZE]; 00144 ScriptData* scriptData_[SCRIPT_STACK_SIZE]; 00145 }; 00146 00147 00148 } 00149 00150 #endif
Home Page | SagaEngine trunk (updated nightly) reference generated Sun Dec 2 20:06:12 2007 by Doxygen version 1.3.9.1.