Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 10607 in orxonox.OLD


Ignore:
Timestamp:
Mar 29, 2007, 5:37:25 PM (18 years ago)
Author:
snellen
Message:

Introduced new scripttrigger: space trigger

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  
    2222ObjectListDefinition(ScriptTrigger);
    2323
    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              );
     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//              );
    4343
    4444
     
    5353  this->toList(OM_COMMON);
    5454
    55   radius = 10;
    5655  returnCount = 1;
    5756  scriptFinished = false;
    5857  doDebugDraw = false;
    59   invert = false;
     58
    6059  scriptCalled = false;
    6160  scriptIsOk = false;
    6261  executionStopped = false; // true when something goes wrong and the trigger has to be stopped
    63   triggerRemains = true;
    6462  addToScript = false;
    6563  this->activeOnCreation = false;
    66   target = NULL;
     64
    6765
    6866  if(root != NULL)
     
    108106      .describe("where this script trigger should be located")
    109107      .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);
    113108  LoadParam(root, "delay", this, ScriptTrigger, setDelay)
    114109      .describe("the delay after which the funtion sould be triggered")
    115110      .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("");
    119111  LoadParam(root, "triggerparent", this, ScriptTrigger, setTriggerParent)
    120112      .describe("The name of the parent as it is in the *.oxw file")
    121113      .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);
    128114  LoadParam(root, "debugdraw", this, ScriptTrigger, setDebugDraw)
    129115      .describe("")
     
    136122
    137123/**
    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   else
    150   {
    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 /**
    156124 * Sets the parent of the trigger.
    157  * @param parent The parrent.
     125 * @param parent The parent.
    158126 */
    159127void ScriptTrigger::setTriggerParent(const std::string& parent)
     
    174142void ScriptTrigger::tick(float timestep)
    175143{
    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
    207145}
    208146
  • branches/scriptimprovements/src/world_entities/script_triggers/script_trigger.h

    r10606 r10607  
    3333
    3434    /// 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 
    3936    void setActiveOnCreation(const bool avtive) { this->activeOnCreation = avtive; }
    40     void setInvert(const bool inv) { this->invert = invert; }
    4137    void setDelay(float delay) { this->delay = delay; };
    42     void setRadius(const float radius) { if(radius>0) this->radius = radius; }
    4338    void setScript(const std::string& file);
    4439    void setFunction(const std::string& function){ this->functionName = function;}
    4540    void setDebugDraw(const bool draw) { this->doDebugDraw = draw; }
    4641    void setAddToScript(const bool add) { this->addToScript = add; }
     42    void setTriggerParent(const std::string& name);
    4743
    4844    ///DRAWING
     
    5147  private:
    5248
    53     WorldEntity* target;
    54     bool         triggerRemains;
    5549    bool         activeOnCreation;
    56     bool         invert;
    57     float        radius;
    5850    float        delay;
    5951    Script*      script;
     
    6153    bool         doDebugDraw;
    6254    bool         addToScript;
     55   
    6356    //for internal use
    6457    bool         scriptCalled;
Note: See TracChangeset for help on using the changeset viewer.