Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8171 in orxonox.OLD for branches


Ignore:
Timestamp:
Jun 6, 2006, 9:18:31 AM (18 years ago)
Author:
snellen
Message:

scripttrigger implemented. todo: make loadParam work

Location:
branches/script_engine/src/lib/script_engine
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/script_engine/src/lib/script_engine/script_manager.cc

    r8170 r8171  
    1818}
    1919
    20 ScriptManager* ScriptManager::getInstance()
    21 {
    22 
    23   if (!ScriptManager::singletonRef)
    24     ScriptManager::singletonRef = new ScriptManager();
    25   return ScriptManager::singletonRef;
    26 
    27 }
    2820
    2921void ScriptManager::loadParams(const TiXmlElement* root)
     
    8476    LOAD_PARAM_START_CYCLE(script, object);
    8577    {
    86       LoadParam_CYCLE(object, "object", this, ScriptManager, addObjectToScript)
    87           .describe("The name of an object that is needed by a script");
     78     // LoadParam_CYCLE(object, "object", this, ScriptManager, addObjectToScript)
     79       //   .describe("The name of an object that is needed by a script");
    8880    }
    8981    LOAD_PARAM_END_CYCLE(object);
     
    9688  }
    9789
     90
     91}
     92
     93
     94Script* ScriptManager::getScriptByFile(std::string& file)
     95{
     96
     97  for(std::list<LuaScript>::iterator it = scriptList.begin(); it != scriptList.end(); it++ )
     98  {
     99    if( (*it).name.compare(file) == 0)
     100    {
     101      return &((*it).script);
     102    }
     103  }
     104  return NULL;
    98105
    99106}
  • branches/script_engine/src/lib/script_engine/script_manager.h

    r8170 r8171  
    2525   ~ScriptManager();
    2626
    27   inline static ScriptManager* getInstance();
     27  inline static ScriptManager* getInstance(){if (!ScriptManager::singletonRef)ScriptManager::singletonRef = new ScriptManager();return ScriptManager::singletonRef;}
    2828
    2929  virtual void loadParams(const TiXmlElement* root);
     
    3333
    3434  void initScripts(); // initializes all scripts
     35  Script* getScriptByFile(std::string& file);
    3536
    3637 private:
  • branches/script_engine/src/lib/script_engine/script_trigger.cc

    r8170 r8171  
     1#include "script_trigger.h"
     2
     3
     4ScriptTrigger::ScriptTrigger()
     5{
     6 scriptCalled = false;
     7}
     8
     9ScriptTrigger::~ScriptTrigger()
     10{
     11
     12}
     13
     14void ScriptTrigger::loadParams(const TiXmlElement* root)
     15{
     16   /* LoadParam(root, "file", this, ScriptTrigger, setScript)
     17        .describe("the fileName of the script, that should be triggered by this script trigger")
     18        .defaultValues("");
     19    LoadParam(root, "function", this, ScriptTrigger, setFunction)
     20        .describe("the function of the script, that should be triggered by this script trigger")
     21        .defaultValues("");
     22    LoadParam(root, "abs-coor", this, ScriptTrigger, setAbsCoord)
     23        .describe("the fileName of the script, that should be triggered by this script trigger")
     24        .defaultValues("");
     25    LoadParam(root, "radius", this, ScriptTrigger, setRadius)
     26        .describe("the fileName of the script, that should be triggered by this script trigger")
     27        .defaultValues("");
     28    */
     29}
     30
     31
     32
     33void ScriptTrigger::tick(float timestep)
     34{
     35
     36 if((this->getAbsDirV()-target->getAbsDirV()).len() < radius)
     37 {
     38  if(!callOnce)
     39   {
     40    executeAction();
     41   }
     42  else if(callOnce && !scriptCalled)
     43  {
     44   executeAction();
     45   scriptCalled = true;
     46  }
     47 }
     48
     49}
     50
     51
     52
     53void ScriptTrigger::executeAction()
     54{
     55     ScriptManager* scriptManager = ScriptManager::getInstance();
     56     Script* script = scriptManager->getScriptByFile(this->scriptFile);
     57     if(!(script->selectFunction(this->functionName,0)) )
     58       printf("Error: Selection of %s in %s failed.\n",functionName.c_str(), scriptFile.c_str());
     59     if( !(script->executeFunction()) )
     60       printf("Execution of %s in %s failed\n",functionName.c_str(),scriptFile.c_str());
     61}
  • branches/script_engine/src/lib/script_engine/script_trigger.h

    r8170 r8171  
    22#define _SCRIPT_TRIGGER_H
    33
     4#include <string>
     5
    46#include "world_entity.h"
    57#include "loading/load_param.h"
     8#include "vector.h"
     9#include "script_manager.h"
    610
    711class ScriptTrigger : public WorldEntity
     
    1216
    1317    virtual void loadParams(const TiXmlElement* root);
    14     virtual voit tick(float timestep);
     18    virtual void tick(float timestep);
     19    virtual void executeAction();
     20
     21    void setTarget(WorldEntity* target){ if(target!=NULL) this->target=target;}
     22    void setCallOnce(bool call){this->callOnce = call;}
     23    void setRadius(float radius){if(radius>0) this->radius = radius;}
     24    void setScript(std::string& script){this->scriptFile = script;}
     25    void setFunction(std::string& function){this->functionName = function;}
    1526
    1627  private:
Note: See TracChangeset for help on using the changeset viewer.