Changeset 10607 in orxonox.OLD
- Timestamp:
- Mar 29, 2007, 5:37:25 PM (18 years ago)
- Location:
- branches/scriptimprovements/src/world_entities/script_triggers
- Files:
-
- 6 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/scriptimprovements/src/world_entities/script_triggers/script_trigger.cc
r10606 r10607 22 22 ObjectListDefinition(ScriptTrigger); 23 23 24 CREATE_SCRIPTABLE_CLASS(ScriptTrigger,25 // Coordinates26 addMethod("setAbsCoor", Executor3<PNode, lua_State*,float,float,float>(&PNode::setAbsCoor))27 ->addMethod("getAbsCoorX", Executor0ret<PNode, lua_State*, float>(&PNode::getAbsCoorX))28 ->addMethod("getAbsCoorY", Executor0ret<PNode, lua_State*, float>(&PNode::getAbsCoorY))29 ->addMethod("getAbsCoorZ", Executor0ret<PNode, lua_State*, float>(&PNode::getAbsCoorZ))30 //Properties31 ->addMethod("setName", Executor1<BaseObject, lua_State*, const std::string&>(&BaseObject::setName))32 ->addMethod("setTarget", Executor1<ScriptTrigger, lua_State*, const std::string&>(&ScriptTrigger::setTarget))33 ->addMethod("setTriggerParent", Executor1<ScriptTrigger, lua_State*, const std::string&>(&ScriptTrigger::setTriggerParent))34 ->addMethod("setTriggerRemains", Executor1<ScriptTrigger, lua_State*, bool>(&ScriptTrigger::setTriggerRemains))35 ->addMethod("setActiveOnCreation", Executor1<ScriptTrigger, lua_State*, bool>(&ScriptTrigger::setActiveOnCreation))36 ->addMethod("setInvert", Executor1<ScriptTrigger, lua_State*, bool>(&ScriptTrigger::setInvert))37 ->addMethod("setRadius", Executor1<ScriptTrigger, lua_State*, float>(&ScriptTrigger::setRadius))38 ->addMethod("setScript", Executor1<ScriptTrigger, lua_State*, const std::string&>(&ScriptTrigger::setScript))39 ->addMethod("setFunction", Executor1<ScriptTrigger, lua_State*, const std::string&>(&ScriptTrigger::setFunction))40 ->addMethod("setDebugDraw", Executor1<ScriptTrigger, lua_State*, bool>(&ScriptTrigger::setDebugDraw))41 ->addMethod("setAddToScript", Executor1<ScriptTrigger, lua_State*, bool>(&ScriptTrigger::setAddToScript))42 );24 // CREATE_SCRIPTABLE_CLASS(ScriptTrigger, 25 // // Coordinates 26 // addMethod("setAbsCoor", Executor3<PNode, lua_State*,float,float,float>(&PNode::setAbsCoor)) 27 // ->addMethod("getAbsCoorX", Executor0ret<PNode, lua_State*, float>(&PNode::getAbsCoorX)) 28 // ->addMethod("getAbsCoorY", Executor0ret<PNode, lua_State*, float>(&PNode::getAbsCoorY)) 29 // ->addMethod("getAbsCoorZ", Executor0ret<PNode, lua_State*, float>(&PNode::getAbsCoorZ)) 30 // //Properties 31 // ->addMethod("setName", Executor1<BaseObject, lua_State*, const std::string&>(&BaseObject::setName)) 32 // ->addMethod("setTarget", Executor1<ScriptTrigger, lua_State*, const std::string&>(&ScriptTrigger::setTarget)) 33 // ->addMethod("setTriggerParent", Executor1<ScriptTrigger, lua_State*, const std::string&>(&ScriptTrigger::setTriggerParent)) 34 // ->addMethod("setTriggerRemains", Executor1<ScriptTrigger, lua_State*, bool>(&ScriptTrigger::setTriggerRemains)) 35 // ->addMethod("setActiveOnCreation", Executor1<ScriptTrigger, lua_State*, bool>(&ScriptTrigger::setActiveOnCreation)) 36 // ->addMethod("setInvert", Executor1<ScriptTrigger, lua_State*, bool>(&ScriptTrigger::setInvert)) 37 // ->addMethod("setRadius", Executor1<ScriptTrigger, lua_State*, float>(&ScriptTrigger::setRadius)) 38 // ->addMethod("setScript", Executor1<ScriptTrigger, lua_State*, const std::string&>(&ScriptTrigger::setScript)) 39 // ->addMethod("setFunction", Executor1<ScriptTrigger, lua_State*, const std::string&>(&ScriptTrigger::setFunction)) 40 // ->addMethod("setDebugDraw", Executor1<ScriptTrigger, lua_State*, bool>(&ScriptTrigger::setDebugDraw)) 41 // ->addMethod("setAddToScript", Executor1<ScriptTrigger, lua_State*, bool>(&ScriptTrigger::setAddToScript)) 42 // ); 43 43 44 44 … … 53 53 this->toList(OM_COMMON); 54 54 55 radius = 10;56 55 returnCount = 1; 57 56 scriptFinished = false; 58 57 doDebugDraw = false; 59 invert = false; 58 60 59 scriptCalled = false; 61 60 scriptIsOk = false; 62 61 executionStopped = false; // true when something goes wrong and the trigger has to be stopped 63 triggerRemains = true;64 62 addToScript = false; 65 63 this->activeOnCreation = false; 66 target = NULL; 64 67 65 68 66 if(root != NULL) … … 108 106 .describe("where this script trigger should be located") 109 107 .defaultValues(""); 110 LoadParam(root, "radius", this, ScriptTrigger, setRadius)111 .describe("the fileName of the script, that should be triggered by this script trigger")112 .defaultValues(0);113 108 LoadParam(root, "delay", this, ScriptTrigger, setDelay) 114 109 .describe("the delay after which the funtion sould be triggered") 115 110 .defaultValues(0); 116 LoadParam(root, "worldentity", this, ScriptTrigger, setTarget)117 .describe("The name of the target as it is in the *.oxw file")118 .defaultValues("");119 111 LoadParam(root, "triggerparent", this, ScriptTrigger, setTriggerParent) 120 112 .describe("The name of the parent as it is in the *.oxw file") 121 113 .defaultValues(""); 122 LoadParam(root, "invert", this, ScriptTrigger, setInvert)123 .describe("")124 .defaultValues(false);125 LoadParam(root, "triggerRemains", this, ScriptTrigger, setTriggerRemains)126 .describe("")127 .defaultValues(true);128 114 LoadParam(root, "debugdraw", this, ScriptTrigger, setDebugDraw) 129 115 .describe("") … … 136 122 137 123 /** 138 * Sets the target(a world entity) of the ScriptTrigger. If the distance between the target and this trigger is smaller than the radius, the script gets triggered.139 * @param target The worldentity that the script supervises.140 */141 void ScriptTrigger::setTarget(const std::string& target)142 {143 144 WorldEntity* targetEntity = WorldEntity::objectList().getObject(target);145 if (targetEntity != NULL)146 {147 this->setTarget(targetEntity);148 }149 else150 {151 PRINTF(2)("ERROR SCRTIPTTRIGGER : Target %s for %s::%s does not Exist\n", target.c_str(), this->getClassCName(), this->getCName());152 }153 }154 155 /**156 124 * Sets the parent of the trigger. 157 * @param parent The par rent.125 * @param parent The parent. 158 126 */ 159 127 void ScriptTrigger::setTriggerParent(const std::string& parent) … … 174 142 void ScriptTrigger::tick(float timestep) 175 143 { 176 if(scriptFinished) return; 177 178 if(activeOnCreation) 179 { 180 executeAction(timestep); 181 return; 182 } 183 184 if(triggerRemains && scriptCalled) 185 { 186 executeAction(timestep); 187 return; 188 } 189 190 if( this->target != NULL) 191 { 192 if( !invert && this->distance(target) < radius) 193 { 194 //printf("Distance is %f \n", this->distance(target)); 195 executeAction(timestep); 196 scriptCalled = true; 197 return; 198 199 } 200 else if( invert && this->distance(target) > radius) 201 { 202 executeAction(timestep); 203 scriptCalled = true; 204 return; 205 } 206 } 144 207 145 } 208 146 -
branches/scriptimprovements/src/world_entities/script_triggers/script_trigger.h
r10606 r10607 33 33 34 34 /// SET MEMBER 35 void setTarget(const std::string& targetName); 36 void setTarget(WorldEntity* target) { if(target!=NULL) this->target=target; } 37 void setTriggerParent(const std::string& name); 38 void setTriggerRemains(const bool lasts) { this->triggerRemains = lasts; } 35 39 36 void setActiveOnCreation(const bool avtive) { this->activeOnCreation = avtive; } 40 void setInvert(const bool inv) { this->invert = invert; }41 37 void setDelay(float delay) { this->delay = delay; }; 42 void setRadius(const float radius) { if(radius>0) this->radius = radius; }43 38 void setScript(const std::string& file); 44 39 void setFunction(const std::string& function){ this->functionName = function;} 45 40 void setDebugDraw(const bool draw) { this->doDebugDraw = draw; } 46 41 void setAddToScript(const bool add) { this->addToScript = add; } 42 void setTriggerParent(const std::string& name); 47 43 48 44 ///DRAWING … … 51 47 private: 52 48 53 WorldEntity* target;54 bool triggerRemains;55 49 bool activeOnCreation; 56 bool invert;57 float radius;58 50 float delay; 59 51 Script* script; … … 61 53 bool doDebugDraw; 62 54 bool addToScript; 55 63 56 //for internal use 64 57 bool scriptCalled;
Note: See TracChangeset
for help on using the changeset viewer.