Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8711 in orxonox.OLD for trunk/src/world_entities


Ignore:
Timestamp:
Jun 22, 2006, 1:09:20 PM (19 years ago)
Author:
bensch
Message:

merged the script_engine back here

Location:
trunk/src/world_entities
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/world_entities/script_trigger.cc

    r8408 r8711  
    1 //for testing
    2 #include "luaincl.h"
     1/*
     2   orxonox - the future of 3D-vertical-scrollers
     3
     4   Copyright (C) 2004 orx
     5
     6   This program is free software; you can redistribute it and/or modify
     7   it under the terms of the GNU General Public License as published by
     8   the Free Software Foundation; either version 2, or (at your option)
     9   any later version.
     10
     11### File Specific:
     12   main-programmer: Silvan Nellen
     13   co-programmer: ...
     14*/
     15
    316
    417#include "script_trigger.h"
     
    2033  this->toList(OM_COMMON);
    2134
     35  returnCount = 1;
     36  actionFinished = false;
    2237  doDebugDraw = false;
     38  invert = false;
    2339  scriptCalled = false;
    2440  scriptIsOk = false;
     41  triggerLasts = false;
    2542  loadParams(root);
    2643
     
    7188        .describe("True if the script shoul only be called once")
    7289        .defaultValues("");
     90    LoadParam(root, "invert", this, ScriptTrigger, setInvert)
     91        .describe("")
     92        .defaultValues("");
     93    LoadParam(root, "triggerlasts", this, ScriptTrigger, setTriggerLasts)
     94        .describe("")
     95        .defaultValues("");
    7396    LoadParam(root, "debugdraw", this, ScriptTrigger, setDebugDraw)
    7497        .describe("True if the script should only be called once")
     
    118141void ScriptTrigger::tick(float timestep)
    119142{
    120 
    121   if( this->distance(target) < radius)
     143  if(actionFinished) return;
     144
     145  if(triggerLasts && scriptCalled)
     146  {
     147    executeAction(timestep);
     148    return;
     149  }
     150 
     151  if( !invert && this->distance(target) < radius)
    122152 {
    123153  if(!callOnce)
    124154   {
    125     executeAction();
     155    executeAction(timestep);
     156    scriptCalled = true;
    126157   }
    127158  else if(callOnce && !scriptCalled)
    128159  {
    129    executeAction();
     160   executeAction(timestep);
    130161   scriptCalled = true;
    131162  }
     163 
     164 }
     165 else if( invert && this->distance(target) > radius)
     166 {
     167   if(!callOnce)
     168   {
     169     executeAction(timestep);
     170   }
     171   else if(callOnce && !scriptCalled)
     172   {
     173     executeAction(timestep);
     174     scriptCalled = true;
     175   }
     176   
    132177 }
    133178 //else
     
    137182
    138183
    139 void ScriptTrigger::executeAction()
     184void ScriptTrigger::executeAction(float timestep)
    140185{
    141186     if(scriptIsOk)
    142187     {
    143        testScriptingFramework();
    144      /*if(!(script->selectFunction(this->functionName,0)) )
     188       //testScriptingFramework();
     189     if(!(script->selectFunction(this->functionName,returnCount)) )
    145190       printf("Error ScriptTrigger: Selection of %s in %s failed.\n",functionName.c_str(), script->getFileName().c_str());
     191     
     192     script->pushParam( timestep, this->functionName);
     193     
    146194     if( !(script->executeFunction()) )
    147        printf("Error ScriptTrigger: Execution of %s in %s failed.\n",functionName.c_str(), script->getFileName().c_str());*/
     195       printf("Error ScriptTrigger: Execution of %s in %s failed.\n",functionName.c_str(), script->getFileName().c_str());
     196     
     197     actionFinished = script->getReturnedBool();
    148198     }
     199     
     200     
    149201}
    150202
     
    165217}
    166218
    167 
     219/*
    168220 void ScriptTrigger::testScriptingFramework()
    169221 {
     
    208260   printf("-------------------------- top of the stack:%i\n",lua_gettop(script->getLuaState()));
    209261
    210  }
     262}*/
  • trunk/src/world_entities/script_trigger.h

    r8408 r8711  
     1/*!
     2 * @file scrip_trigger.h
     3 *  triggeres a script
     4 */
     5
    16#ifndef _SCRIPT_TRIGGER_H
    27#define _SCRIPT_TRIGGER_H
     
    2227    /// DO WORK
    2328    virtual void tick(float timestep);
    24     virtual void executeAction();
     29    virtual void executeAction(float timestep);
    2530    void testScriptingFramework();
    2631
     
    3035    void setTriggerParent(const std::string& name);
    3136    void setCallOnce(const bool call) { this->callOnce = call; }
     37    void setTriggerLasts(const bool lasts) { this->triggerLasts = lasts; }
     38    void setInvert(const bool inv) { this->invert = invert; }
    3239    void setRadius(const float radius) { if(radius>0) this->radius = radius; }
    3340    void setDelay(const float time){if(delay>0) this->delay = delay; }
    3441    void setScript(const std::string& file);
    35     void setFunction(const std::string& function){ this->functionName = function; }
     42    void setFunction(const std::string& function){ this->functionName = function;}
    3643    void setDebugDraw(const bool draw) { this->doDebugDraw = draw; }
    3744
     
    4350    WorldEntity* target;
    4451    bool         callOnce;
     52    bool         triggerLasts;
     53    bool         invert;
    4554    float        radius;
    4655    float        delay;
     
    5261    bool         scriptCalled;
    5362    bool         scriptIsOk;
     63    bool         actionFinished;
     64    int          returnCount;        //TODO: set return count correctly
    5465
    5566};
  • trunk/src/world_entities/space_ships/helicopter.h

    r8408 r8711  
    1212#include "sound_buffer.h"
    1313#include "sound_source.h"
     14
     15#include "script_class.h"
    1416
    1517class Helicopter : public Playable
     
    3840    virtual void process(const Event &event);
    3941   
    40     virtual void moveUp(bool move){bUp = move;};
     42    virtual void moveUp(bool move){bAscend = move;};
     43    virtual void moveDown(bool move){bDescend = move;};
    4144
    4245
     
    8083};
    8184
    82 //CREATE_SCRIPTABLE_CLASS(Helicopter, CL_HELICOPTER,
    83                        // addMethod("moveUp", ExecutorLua1<Object,bool>(&Helicopter::moveUp))
    84                        // );
     85CREATE_SCRIPTABLE_CLASS(Helicopter, CL_HELICOPTER,
     86                        addMethod("moveUp", ExecutorLua1<Helicopter,bool>(&Helicopter::moveUp))
     87                        ->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                           
     93                        );
    8594
    8695
Note: See TracChangeset for help on using the changeset viewer.