Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8485 in orxonox.OLD for branches/script_engine/src/world_entities


Ignore:
Timestamp:
Jun 15, 2006, 5:33:25 PM (18 years ago)
Author:
snellen
Message:

helicopter scripted

Location:
branches/script_engine/src/world_entities
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/script_engine/src/world_entities/script_trigger.cc

    r8417 r8485  
    2020  this->toList(OM_COMMON);
    2121
     22  returnCount = 1;
     23  actionFinished = false;
    2224  doDebugDraw = false;
     25  invert = false;
    2326  scriptCalled = false;
    2427  scriptIsOk = false;
     28  triggerLasts = false;
    2529  loadParams(root);
    2630
     
    7175        .describe("True if the script shoul only be called once")
    7276        .defaultValues("");
     77    LoadParam(root, "invert", this, ScriptTrigger, setInvert)
     78        .describe("")
     79        .defaultValues("");
     80    LoadParam(root, "triggerlasts", this, ScriptTrigger, setTriggerLasts)
     81        .describe("")
     82        .defaultValues("");
    7383    LoadParam(root, "debugdraw", this, ScriptTrigger, setDebugDraw)
    7484        .describe("True if the script should only be called once")
     
    118128void ScriptTrigger::tick(float timestep)
    119129{
    120 
    121   if( this->distance(target) < radius)
     130  if(actionFinished) return;
     131
     132  if(triggerLasts && scriptCalled)
     133  {
     134    executeAction(timestep);
     135    return;
     136  }
     137 
     138 
     139  if( !invert && this->distance(target) < radius)
    122140 {
    123141  if(!callOnce)
    124142   {
    125     executeAction();
     143    executeAction(timestep);
     144    scriptCalled = true;
    126145   }
    127146  else if(callOnce && !scriptCalled)
    128147  {
    129    executeAction();
     148   executeAction(timestep);
    130149   scriptCalled = true;
    131150  }
     151 
     152 }
     153 else if( invert && this->distance(target) > radius)
     154 {
     155   if(!callOnce)
     156   {
     157     executeAction(timestep);
     158   }
     159   else if(callOnce && !scriptCalled)
     160   {
     161     executeAction(timestep);
     162     scriptCalled = true;
     163   }
     164   
    132165 }
    133166 //else
     
    137170
    138171
    139 void ScriptTrigger::executeAction()
     172void ScriptTrigger::executeAction(float timestep)
    140173{
    141174     if(scriptIsOk)
    142175     {
    143        testScriptingFramework();
    144      if(!(script->selectFunction(this->functionName,0)) )
     176       //testScriptingFramework();
     177     if(!(script->selectFunction(this->functionName,returnCount)) )
    145178       printf("Error ScriptTrigger: Selection of %s in %s failed.\n",functionName.c_str(), script->getFileName().c_str());
     179     
     180     script->pushParam( timestep, this->functionName);
     181     
    146182     if( !(script->executeFunction()) )
    147183       printf("Error ScriptTrigger: Execution of %s in %s failed.\n",functionName.c_str(), script->getFileName().c_str());
    148184     }
     185     
     186     actionFinished = script->getReturnedBool();
    149187}
    150188
  • branches/script_engine/src/world_entities/script_trigger.h

    r8408 r8485  
    2222    /// DO WORK
    2323    virtual void tick(float timestep);
    24     virtual void executeAction();
     24    virtual void executeAction(float timestep);
    2525    void testScriptingFramework();
    2626
     
    3030    void setTriggerParent(const std::string& name);
    3131    void setCallOnce(const bool call) { this->callOnce = call; }
     32    void setTriggerLasts(const bool lasts) { this->triggerLasts = lasts; }
     33    void setInvert(const bool inv) { this->invert = invert; }
    3234    void setRadius(const float radius) { if(radius>0) this->radius = radius; }
    3335    void setDelay(const float time){if(delay>0) this->delay = delay; }
    3436    void setScript(const std::string& file);
    35     void setFunction(const std::string& function){ this->functionName = function; }
     37    void setFunction(const std::string& function){ this->functionName = function;}
    3638    void setDebugDraw(const bool draw) { this->doDebugDraw = draw; }
    3739
     
    4345    WorldEntity* target;
    4446    bool         callOnce;
     47    bool         triggerLasts;
     48    bool         invert;
    4549    float        radius;
    4650    float        delay;
     
    5256    bool         scriptCalled;
    5357    bool         scriptIsOk;
     58    bool         actionFinished;
     59    int          returnCount;
    5460
    5561};
  • branches/script_engine/src/world_entities/space_ships/helicopter.h

    r8417 r8485  
    8686                        addMethod("moveUp", ExecutorLua1<Helicopter,bool>(&Helicopter::moveUp))
    8787                        ->addMethod("moveDown", ExecutorLua1<Helicopter,bool>(&Helicopter::moveDown))
     88                        ->addMethod("setAbsCoor", ExecutorLua3<PNode,float,float,float>(&PNode::setAbsCoor))
     89                        ->addMethod("getAbsCoorX", ExecutorLua0ret<PNode, float>(&PNode::getAbsCoorX))
     90                        ->addMethod("getAbsCoorY", ExecutorLua0ret<PNode, float>(&PNode::getAbsCoorY))
     91                        ->addMethod("getAbsCoorZ", ExecutorLua0ret<PNode, float>(&PNode::getAbsCoorZ))
     92                           
    8893                        );
    8994
Note: See TracChangeset for help on using the changeset viewer.