Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/world_entities/environments/mover.diff @ 10696

Last change on this file since 10696 was 10696, checked in by snellen, 17 years ago

added all the new mover classes

File size: 80.8 KB
  • mover_trigger_list.cc

     
     1/*
     2   orxonox - the future of 3D-vertical-scrollers
     3
     4   Copyright (C) 2007 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: Fabian 'x3n' Landau
     13   co-programmer:
     14*/
     15
     16#include "mover_trigger_list.h"
     17#include "debug.h"
     18
     19
     20MoverTriggerList::MoverTriggerList()
     21{
     22    PRINTF(0)("10_1 MoverTriggerList %p created\n", this);
     23    this->first = 0;
     24    PRINTF(0)("10_2 first element: %p\n", this->first);
     25}
     26
     27MoverTriggerList::~MoverTriggerList()
     28{
     29    PRINTF(0)("13_1 MoverTriggerList %p destroyed\n", this);
     30    MoverTriggerListElement *temp1 = this->first;
     31    MoverTriggerListElement *temp2;
     32    while (temp1 != 0)
     33    {
     34        temp2 = temp1->next;
     35        delete temp1;
     36        temp1 = temp2;
     37    }
     38}
     39
     40void MoverTriggerList::addTrigger(MoverTrigger *trigger)
     41{
     42    PRINTF(0)("11_1 added trigger %p to list %p\n", trigger, this);
     43    if (trigger)
     44    {
     45        if (this->first == 0)
     46        {
     47            PRINTF(0)("11_2\n");
     48            this->first = new MoverTriggerListElement(trigger);
     49        }
     50        else
     51        {
     52            PRINTF(0)("11_3\n");
     53            MoverTriggerListElement *temp = this->first;
     54            while (temp->next != 0)
     55                temp = temp->next;
     56
     57            temp->next = new MoverTriggerListElement(trigger);
     58            PRINTF(0)("11_4\n");
     59        }
     60    }
     61    PRINTF(0)("11_5\n");
     62}
     63
     64bool MoverTriggerList::isTriggered()
     65{
     66//    PRINTF(0)("16_1\n");
     67    if (this->first == 0)
     68    {
     69//        PRINTF(0)("16_2\n");
     70        return true;
     71    }
     72    else
     73    {
     74//        PRINTF(0)("16_3\n");
     75        bool isTriggered = false;
     76        MoverTriggerListElement *temp = this->first;
     77
     78        while (temp != 0)
     79        {
     80            if (temp->trigger->isTriggered())
     81            {
     82                isTriggered = true;
     83            }
     84            else
     85            {
     86                if (temp->trigger->isObligatory())
     87                    return false;
     88            }
     89                   
     90            temp = temp->next;
     91        }
     92
     93//        PRINTF(0)("16_4\n");
     94        return isTriggered;
     95    }
     96}
     97
     98void MoverTriggerList::setBaseCoor(Vector baseCoor)
     99{
     100//    PRINTF(0)("12_1 set base coor in %p\n", this);
     101//    PRINTF(0)("12_2 first element: %p\n", this->first);
     102    MoverTriggerListElement *temp = this->first;
     103    while (temp != 0)
     104    {
     105//        PRINTF(0)("12_3\n");
     106        temp->trigger->setBaseCoor(baseCoor);
     107        temp = temp->next;
     108    }
     109//    PRINTF(0)("12_4\n");
     110}
     111
     112
     113////////////////////////////////////////////////////////
     114
     115
     116MoverTriggerListElement::MoverTriggerListElement(MoverTrigger *trigger)
     117{
     118    this->trigger = trigger;
     119    this->next = 0;
     120}
     121
     122MoverTriggerListElement::~MoverTriggerListElement()
     123{
     124    if (this->trigger)
     125        delete this->trigger;
     126}
  • mover_trigger_pointer_list.cc

     
     1/*
     2   orxonox - the future of 3D-vertical-scrollers
     3
     4   Copyright (C) 2007 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: Fabian 'x3n' Landau
     13   co-programmer:
     14*/
     15
     16#include "mover_trigger_pointer_list.h"
     17#include "debug.h"
     18
     19
     20MoverTriggerPointerList::MoverTriggerPointerList()
     21{
     22    this->first = 0;
     23}
     24
     25MoverTriggerPointerList::~MoverTriggerPointerList()
     26{
     27    MoverTriggerPointerListElement *temp1 = this->first;
     28    MoverTriggerPointerListElement *temp2;
     29    while (temp1 != 0)
     30    {
     31        temp2 = temp1->next;
     32        delete temp1;
     33        temp1 = temp2;
     34    }
     35}
     36
     37void MoverTriggerPointerList::addTrigger(MoverTrigger *trigger)
     38{
     39    if (trigger)
     40    {
     41        if (this->first == 0)
     42        {
     43            this->first = new MoverTriggerPointerListElement(trigger);
     44        }
     45        else
     46        {
     47            MoverTriggerPointerListElement *temp = this->first;
     48            while (temp->next != 0)
     49                temp = temp->next;
     50
     51            temp->next = new MoverTriggerPointerListElement(trigger);
     52        }
     53    }
     54}
     55
     56bool MoverTriggerPointerList::isTriggered()
     57{
     58    if (this->first == 0)
     59    {
     60        return false;
     61    }
     62    else
     63    {
     64        bool isTriggered = false;
     65        MoverTriggerPointerListElement *temp = this->first;
     66
     67        while (temp != 0)
     68        {
     69            if (temp->trigger->isTriggered())
     70            {
     71                isTriggered = true;
     72            }
     73            else
     74            {
     75                if (temp->trigger->isObligatory())
     76                    return false;
     77            }
     78                   
     79            temp = temp->next;
     80        }
     81
     82        return isTriggered;
     83    }
     84}
     85
     86////////////////////////////////////////////////////////
     87
     88
     89MoverTriggerPointerListElement::MoverTriggerPointerListElement(MoverTrigger *trigger)
     90{
     91    this->trigger = trigger;
     92    this->next = 0;
     93}
     94
     95MoverTriggerPointerListElement::~MoverTriggerPointerListElement()
     96{
     97}
  • mover_trigger_event.h

     
     1/*!
     2 * @file mover_trigger_event.h
     3 *  Gets triggered when a specific event occurs.
     4 */
     5
     6#ifndef _MOVER_TRIGGER_EVENT_H
     7#define _MOVER_TRIGGER_EVENT_H
     8
     9#include "mover_trigger.h"
     10
     11
     12class EventTrigger : public MoverTrigger
     13{
     14    ObjectListDeclaration(EventTrigger);
     15
     16    public:
     17        EventTrigger(const TiXmlElement* root = NULL);
     18        virtual ~EventTrigger();
     19        virtual void loadParams(const TiXmlElement* root);
     20        void setEvent(const std::string& eventName) { this->eventName = eventName; }
     21
     22    private:
     23        virtual bool checkIsTriggered();
     24        std::string                 eventName;
     25        MoverTriggerPointerList     *eventTriggers;
     26        bool                        bIsChecking;
     27};
     28
     29
     30#endif
     31
  • mover_trigger_key.cc

     
     1/*
     2   orxonox - the future of 3D-vertical-scrollers
     3
     4   Copyright (C) 2007 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: Fabian 'x3n' Landau
     13   co-programmer:
     14*/
     15
     16#include "util/loading/load_param.h"
     17#include "util/loading/factory.h"
     18#include "mover_trigger_key.h"
     19
     20ObjectListDefinition(KeyTrigger);
     21CREATE_FACTORY(KeyTrigger);
     22
     23
     24KeyTrigger::KeyTrigger(const TiXmlElement* root)
     25{
     26    this->registerObject(this, KeyTrigger::_objectList);
     27    this->toList(OM_ENVIRON);
     28    this->keyName = "";
     29
     30    if (root != NULL)
     31        this->loadParams(root);
     32
     33    this->init_post_params();
     34}
     35
     36void KeyTrigger::loadParams(const TiXmlElement* root)
     37{
     38    MoverTrigger::loadParams(root);
     39
     40    LoadParam(root, "key", this, KeyTrigger, setKey)
     41        .describe("The key that releases the trigger")
     42        .defaultValues("");
     43}
     44
     45bool KeyTrigger::checkIsTriggered()
     46{
     47    /* TODO */
     48    return false;
     49}
  • mover_trigger_delay_list.cc

     
     1/*
     2   orxonox - the future of 3D-vertical-scrollers
     3
     4   Copyright (C) 2007 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: Fabian 'x3n' Landau
     13   co-programmer:
     14*/
     15
     16#include "mover_trigger_list.h"
     17
     18
     19MoverTriggerDelayList::MoverTriggerDelayList()
     20{
     21    this->first = 0;
     22}
     23
     24MoverTriggerDelayList::~MoverTriggerDelayList()
     25{
     26    while (this->first)
     27        this->deleteFirstState();
     28}
     29
     30void MoverTriggerDelayList::addState(bool state, bool oldState, float time)
     31{
     32    if (this->first == 0)
     33        this->first = new MoverTriggerDelayListElement(state, oldState, time);
     34    else
     35    {
     36        MoverTriggerDelayListElement *temp = this->first;
     37        while (temp->next != 0)
     38            temp = temp->next;
     39           
     40        temp->next = new MoverTriggerDelayListElement(state, oldState, time);
     41    }
     42}
     43
     44void MoverTriggerDelayList::deleteFirstState()
     45{
     46    if (this->first != 0)
     47    {
     48        MoverTriggerDelayListElement *temp = this->first->next;
     49        delete this->first;
     50        this->first = temp;
     51    }
     52}
     53
     54MoverTriggerDelayListElement *MoverTriggerDelayList::getFirstState()
     55{
     56    return this->first;
     57}
     58
     59MoverTriggerDelayListElement *MoverTriggerDelayList::getLastState()
     60{
     61    MoverTriggerDelayListElement *temp = this->first;
     62    while (temp != 0)
     63    {
     64        if (temp->next == 0)
     65            return temp;
     66           
     67        temp = temp->next;
     68    }
     69           
     70    return 0;
     71}
     72
     73bool MoverTriggerDelayList::isEmpty()
     74{
     75    return (this->first == 0);
     76}
     77
     78////////////////////////////////////////////////////////
     79
     80
     81MoverTriggerDelayListElement::MoverTriggerDelayListElement(bool state, bool oldState, float time)
     82{
     83    this->state = state;
     84    this->oldState = oldState;
     85    this->time = time;
     86    this->next = 0;
     87}
     88
     89MoverTriggerDelayListElement::~MoverTriggerDelayListElement()
     90{
     91}
  • mover_trigger_key.h

     
     1/*!
     2 * @file mover_trigger_key.h
     3 *  Gets triggered when player presses a key.
     4 */
     5
     6#ifndef _MOVER_TRIGGER_KEY_H
     7#define _MOVER_TRIGGER_KEY_H
     8
     9#include "mover_trigger.h"
     10
     11
     12class KeyTrigger : public MoverTrigger
     13{
     14    ObjectListDeclaration(KeyTrigger);
     15
     16    public:
     17        KeyTrigger(const TiXmlElement* root = NULL);
     18        virtual void loadParams(const TiXmlElement* root);
     19        void setKey(const std::string& keyName) { this->keyName = keyName; }
     20
     21    private:
     22        virtual bool checkIsTriggered();
     23        std::string keyName;
     24};
     25
     26
     27#endif
     28
  • mover_trigger_intervisibility.h

     
     1/*!
     2 * @file mover_trigger_intervisibility.h
     3 *  Gets triggered when the trigger "sees" the player.
     4 */
     5
     6#ifndef _MOVER_TRIGGER_INTERVISIBILITY_H
     7#define _MOVER_TRIGGER_INTERVISIBILITY_H
     8
     9#include "mover_trigger.h"
     10
     11
     12class IntervisibilityTrigger : public MoverTrigger
     13{
     14    ObjectListDeclaration(IntervisibilityTrigger);
     15
     16    public:
     17        IntervisibilityTrigger(const TiXmlElement* root = NULL);
     18        virtual void loadParams(const TiXmlElement* root);
     19        void setOnlyHumans(bool onlyHumans = true) { this->onlyHumans = onlyHumans; }
     20        void setOnlyNPCs(bool onlyNPCs = true) { this->onlyNPCs = onlyNPCs; }
     21
     22    private:
     23        virtual bool checkIsTriggered();
     24        bool onlyHumans;
     25        bool onlyNPCs;
     26};
     27
     28
     29#endif
     30
  • mover_station_list.h

     
     1/*!
     2 * @file mover_station_list.h
     3 *  A list to store and handle several stations.
     4 */
     5
     6#ifndef _MOVER_STATION_LIST_H
     7#define _MOVER_STATION_LIST_H
     8
     9#include "mover_station.h"
     10#include "sound_buffer.h"
     11
     12
     13class MoverStationListElement
     14{
     15    public:
     16        MoverStationListElement(MoverStation *station);
     17        ~MoverStationListElement();
     18
     19        MoverStation *station;
     20        MoverStationListElement *next;
     21        MoverStationListElement *prev;
     22};
     23
     24
     25class MoverStationList
     26{
     27    public:
     28        MoverStationList();
     29        ~MoverStationList();
     30
     31        void addStation(MoverStation *station);
     32        MoverStation *getNextStation(MoverStation *station);
     33        Vector getTotalRelCoor(MoverStation *station);
     34        Vector getTotalRelDir(MoverStation *station);
     35        bool isOpen(MoverStation *station);
     36        bool isClosed(MoverStation *station);
     37        bool changeDirection(bool bReopen, bool bRelocse, bool bIsTriggered);
     38
     39        Vector getRelTargetCoor(MoverStation *station);
     40        Vector getRelTargetDir(MoverStation *station);
     41        float getDelay(MoverStation *station) { return station->delay; }
     42        float getStayOpenTime(MoverStation *station) { return station->stayOpenTime; }
     43        float getMovingTime(MoverStation *station) { return station->movingTime; }
     44        Vector getVelocity(MoverStation *station);
     45        Vector getRotation(MoverStation *station);
     46        OrxSound::SoundBuffer getStartingSound(MoverStation *station);
     47        OrxSound::SoundBuffer getMovingSound(MoverStation *station);
     48        OrxSound::SoundBuffer getEndingSound(MoverStation *station);
     49
     50    private:
     51        MoverStation *getStation(int rank);
     52       
     53        MoverStationListElement *first;
     54        MoverStationListElement *last;
     55        bool goForward;
     56};
     57
     58
     59#endif
  • mover_trigger_mapstart.h

     
     1/*!
     2 * @file mover_trigger_mapstart.h
     3 *  Gets triggered when the map starts.
     4 */
     5
     6#ifndef _MOVER_TRIGGER_MAPSTART_H
     7#define _MOVER_TRIGGER_MAPSTART_H
     8
     9#include "mover_trigger.h"
     10
     11
     12class MapstartTrigger : public MoverTrigger
     13{
     14    ObjectListDeclaration(MapstartTrigger);
     15
     16    public:
     17        MapstartTrigger(const TiXmlElement* root = NULL);
     18        virtual void loadParams(const TiXmlElement* root);
     19
     20    private:
     21        virtual bool checkIsTriggered();
     22        bool bInit;
     23};
     24
     25
     26#endif
     27
  • mover.cc

     
     1/*
     2   orxonox - the future of 3D-vertical-scrollers
     3
     4   Copyright (C) 2007 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: Fabian 'x3n' Landau
     13   co-programmer:
     14*/
     15
     16#include "sound/resource_sound_buffer.h"
     17#include "sound_engine.h"
     18#include "util/loading/load_param_xml.h"
     19#include "util/loading/load_param.h"
     20#include "util/loading/factory.h"
     21#include "mover.h"
     22
     23#define CLOSED 0
     24#define OPEN 1
     25#define MOVE 2
     26#define WAIT 3
     27#define NEXT 4
     28#define DELAY 5
     29#define STAY 6
     30
     31ObjectListDefinition(Mover);
     32CREATE_FACTORY(Mover);
     33
     34
     35Mover::Mover(const TiXmlElement* root)
     36{
     37    PRINTF(0)("1_1 Mover %p created\n", this);
     38    this->registerObject(this, Mover::_objectList);
     39    this->toList(OM_ENVIRON);
     40
     41    this->bLoop = false;
     42    this->bRepeat = false;
     43    this->bWaitAfterEachStation = false;
     44    this->bOnlyMoveWhileTriggered = false;
     45    this->bAttachTrigger = false;
     46    this->bReopen = false;
     47    this->bReclose = false;
     48   
     49    this->triggers = 0;
     50    this->stations = 0;
     51
     52    this->repeats = 0;
     53    this->state = CLOSED;
     54    this->station = 0;
     55    this->repeatsToGo = 0;
     56    this->time = 0;
     57   
     58    this->originCoor = Vector(0, 0, 0);
     59    this->originDir = Vector(0, 0, 0);
     60
     61    this->soundSource_starting.setSourceNode(this);
     62    this->soundSource_moving.setSourceNode(this);
     63    this->soundSource_ending.setSourceNode(this);
     64
     65    PRINTF(0)("1_2\n");
     66    if (root != NULL)
     67        this->loadParams(root);
     68       
     69    this->updateNode(0.001);
     70       
     71    this->originCoor = this->getAbsCoor();
     72    this->originDir = this->getAbsDir().getRotation();
     73
     74    PRINTF(0)("1_3\n");
     75    if (this->stations)
     76        this->station = this->stations->getNextStation(0);
     77    PRINTF(0)("1_4\n");
     78    if (this->triggers)
     79        this->triggers->setBaseCoor(this->getAbsCoor());
     80    PRINTF(0)("1_5\n");
     81}
     82
     83Mover::~Mover()
     84{
     85    if (this->triggers)
     86        delete this->triggers;
     87    if (this->stations)
     88        delete this->stations;
     89   
     90    if (this->soundSource_starting.isPlaying())
     91        this->soundSource_starting.stop();
     92    if (this->soundSource_moving.isPlaying())
     93        this->soundSource_moving.stop();
     94    if (this->soundSource_ending.isPlaying())
     95        this->soundSource_ending.stop();
     96}
     97
     98void Mover::loadParams(const TiXmlElement* root)
     99{
     100    PRINTF(0)("2_1\n");
     101    WorldEntity::loadParams(root);
     102
     103    LoadParam(root, "bLoop", this, Mover, setLoop)
     104        .describe("After getting triggered, the mover loops forever.")
     105        .defaultValues(false);
     106    LoadParam(root, "bRepeat", this, Mover, setRepeat)
     107        .describe("After getting triggered, the mover moves n times.")
     108        .defaultValues(1);
     109    LoadParam(root, "bWaitAfterEachStation", this, Mover, setWaitAfterEachStation)
     110        .describe("After each station, the mover waits until he gets triggered.")
     111        .defaultValues(false);
     112    LoadParam(root, "bOnlyMoveWhileTriggered", this, Mover, setOnlyMoveWhileTriggered)
     113        .describe("The mover stops as soon as he gets untriggered.")
     114        .defaultValues(false);
     115    LoadParam(root, "bAttachTrigger", this, Mover, setAttachTrigger)
     116        .describe("The trigger follows the mover.")
     117        .defaultValues(false);
     118    LoadParam(root, "bReopen", this, Mover, setReopen)
     119        .describe("Stops closing and reopens the mover when he gets triggered again.")
     120        .defaultValues(false);
     121    LoadParam(root, "bReclose", this, Mover, setReclose)
     122        .describe("Stops opening and recloses the mover when he gets untriggered.")
     123        .defaultValues(false);
     124    PRINTF(0)("2_2\n");
     125    LoadParamXML(root, "triggers", this, Mover, setTriggers)
     126        .describe("Adds a trigger that releases the mover.");
     127    PRINTF(0)("2_3\n");
     128    LoadParamXML(root, "stations", this, Mover, setStations)
     129        .describe("Adds a station to the movers stations-list.");
     130    PRINTF(0)("2_4\n");
     131}
     132
     133void Mover::setTriggers(const TiXmlElement* root)
     134{
     135    PRINTF(0)("3_1\n");
     136    this->triggers = new MoverTriggerList();
     137    const TiXmlElement* element = root->FirstChildElement();
     138   
     139    PRINTF(0)("3_2\n");
     140    while (element != NULL)
     141    {
     142        PRINTF(0)("3_3\n");
     143//        PRINTF(0)("TiXmlElement Value:   %s\n", element->Value());
     144        BaseObject *newObj = Factory::fabricate(element);
     145//        PRINTF(0)("BaseObject ClassName: %s\n", newObj->getClassCName());
     146//        MoverTrigger *newTrigger = ((MoverTrigger*)(&newObj));
     147        MoverTrigger *newTrigger = (dynamic_cast< MoverTrigger *> ( newObj ));
     148        this->triggers->addTrigger(newTrigger);
     149//        this->triggers->addTrigger(MoverTrigger::createTrigger(element));
     150        PRINTF(0)("3_4\n");
     151        element = element->NextSiblingElement();
     152        PRINTF(0)("3_5\n");
     153    }
     154    PRINTF(0)("3_6\n");
     155}
     156
     157void Mover::setStations(const TiXmlElement* root)
     158{
     159    PRINTF(0)("4_1\n");
     160    this->stations = new MoverStationList();
     161    const TiXmlElement* element = root->FirstChildElement();
     162
     163    PRINTF(0)("4_2\n");
     164    while (element != NULL)
     165    {
     166        PRINTF(0)("4_3\n");
     167        this->stations->addStation(new MoverStation(element));
     168        element = element->NextSiblingElement();
     169    }
     170    PRINTF(0)("4_4\n");
     171}
     172
     173void Mover::tick(float dt)
     174{
     175//    PRINTF(0)("15_1 mover state of mover %p is %i, triggerlist is %p\n", this, this->state, this->triggers);
     176    if (this->state == DELAY || this->state == MOVE || this->state == STAY)
     177        this->time += dt;
     178
     179    if (this->state == NEXT)
     180        this->changeState(this->next());
     181       
     182    if (this->state == WAIT)
     183        this->changeState(this->wait());
     184       
     185    if (this->state == CLOSED)
     186        this->changeState(this->closed());
     187
     188    if (this->state == OPEN)
     189        this->changeState(this->open());
     190
     191    if (this->state == DELAY)
     192        this->changeState(this->delay());
     193
     194    if (this->state == MOVE)
     195        this->changeState(this->move(dt));
     196
     197    if (this->state == STAY)
     198        this->changeState(this->stay());
     199}
     200
     201void Mover::changeState(int state)
     202{
     203    if (this->state == state)
     204        return;
     205       
     206    this->state = state;
     207   
     208    if (this->state == DELAY || this->state == STAY)
     209        this->time = 0;
     210}
     211
     212int Mover::closed()
     213{
     214    if (this->triggers && this->triggers->isTriggered())
     215    {
     216        if (this->bRepeat)
     217            this->repeatsToGo = this->repeats;
     218           
     219        return DELAY;
     220    }
     221
     222    return CLOSED;
     223}
     224
     225int Mover::open()
     226{
     227    if (this->triggers && !this->triggers->isTriggered())
     228    {
     229        return DELAY;
     230    }
     231
     232    return OPEN;
     233}
     234
     235int Mover::wait()
     236{
     237    if (this->triggers && this->triggers->isTriggered())
     238    {
     239        this->soundSource_moving.play(this->stations->getMovingSound(this->station), OrxSound::SoundEngine::getInstance()->getEffectsVolume(), 0.5, true);
     240        return MOVE;
     241    }
     242
     243    return WAIT;
     244}
     245
     246int Mover::next()
     247{
     248    bool isOpen = false;
     249    bool isClosed = false;
     250    if (this->stations)
     251    {
     252        isOpen = this->stations->isOpen(station);
     253        isClosed = this->stations->isClosed(station);
     254        this->station = this->stations->getNextStation(this->station);
     255    }
     256
     257    if (isClosed && this->bRepeat)
     258        this->repeatsToGo--;
     259       
     260    if (isClosed && (!this->bLoop && this->repeatsToGo <= 0))
     261        return CLOSED;
     262
     263    if (isOpen && (!this->bLoop && this->repeatsToGo <= 0))
     264        return OPEN;
     265
     266    if (this->bWaitAfterEachStation)
     267        return WAIT;
     268
     269    if ((this->bLoop || this->repeats > 0) || (!isOpen && !isClosed))
     270        return DELAY;
     271       
     272    return NEXT;
     273}
     274
     275int Mover::delay()
     276{
     277    if (!this->stations || (this->time < this->stations->getDelay(this->station)))
     278        return DELAY;
     279
     280    if (this->stations->getStartingSound(this->station).loaded())
     281        this->soundSource_starting.play(this->stations->getStartingSound(this->station), OrxSound::SoundEngine::getInstance()->getEffectsVolume(), 0.5);
     282    if (this->stations->getMovingSound(this->station).loaded())
     283        this->soundSource_moving.play(this->stations->getMovingSound(this->station), OrxSound::SoundEngine::getInstance()->getEffectsVolume(), 0.5, true);
     284
     285    this->time = 0;
     286   
     287    return MOVE;
     288}
     289
     290int Mover::move(float dt)
     291{
     292    if (this->stations)
     293    {
     294        this->setAbsCoor(this->originCoor + this->stations->getVelocity(this->station) * this->time);
     295        this->setAbsDir(VtoQ(this->originDir + this->stations->getRotation(this->station) * this->time));
     296    }
     297   
     298    if (this->bAttachTrigger && this->triggers)
     299        this->triggers->setBaseCoor(this->getAbsCoor());
     300
     301    if (!this->bLoop && this->repeatsToGo <= 0)
     302    {
     303        if (this->stations && this->triggers && this->stations->changeDirection(this->bReopen, this->bReclose, this->triggers->isTriggered()))
     304        {
     305            this->time = this->stations->getMovingTime(this->station) - this->time;
     306            this->originCoor = this->originCoor - this->stations->getRelTargetCoor(this->station);
     307            this->originDir = this->originDir - this->stations->getRelTargetDir(this->station);
     308        }
     309    }
     310
     311    if (/*this->reachedStationsTarget(dt) || */(this->stations && (this->time >= 1.0 * this->stations->getMovingTime(this->station))))
     312//    if (this->stations && (this->time >= this->stations->getMovingTime(this->station)))
     313    {
     314        this->setAbsCoor(this->originCoor + this->stations->getRelTargetCoor(this->station));
     315        this->setAbsDir(VtoQ(this->originDir + this->stations->getRelTargetDir(this->station)));
     316
     317        if (this->stations->getEndingSound(this->station).loaded())
     318            this->soundSource_ending.play(this->stations->getEndingSound(this->station), OrxSound::SoundEngine::getInstance()->getEffectsVolume(), 0.5);
     319        this->soundSource_moving.stop();
     320
     321        this->originCoor = this->originCoor + this->stations->getRelTargetCoor(this->station);
     322        this->originDir = this->originDir + this->stations->getRelTargetDir(this->station);
     323       
     324        return STAY;
     325    }
     326       
     327    if (this->triggers && this->bOnlyMoveWhileTriggered && (!this->triggers->isTriggered()))
     328    {
     329        this->soundSource_moving.stop();
     330        return WAIT;
     331    }
     332
     333    return MOVE;
     334}
     335
     336int Mover::stay()
     337{
     338    if (!this->stations || (this->time < this->stations->getStayOpenTime(this->station)))
     339        return STAY;
     340
     341    return NEXT;
     342}
     343
     344bool Mover::reachedStationsTarget(float dt)
     345{
     346    if (this->stations)
     347        if ((this->getAbsCoor() - (this->originCoor + this->stations->getRelTargetCoor(this->station))).len() <= 1.2 * (this->stations->getVelocity(this->station) * dt).len())
     348            if ((this->getAbsDir().getRotation() - (this->originDir + this->stations->getRelTargetDir(this->station))).len() <= 1.2 * (this->stations->getRotation(this->station) * dt).len())
     349                return true;
     350
     351    return false;
     352}
     353
  • mover_trigger_approach.cc

     
     1/*
     2   orxonox - the future of 3D-vertical-scrollers
     3
     4   Copyright (C) 2007 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: Fabian 'x3n' Landau
     13   co-programmer:
     14*/
     15
     16#include "util/loading/load_param.h"
     17#include "util/loading/factory.h"
     18#include "mover_trigger_approach.h"
     19#include "debug.h"
     20
     21ObjectListDefinition(ApproachTrigger);
     22CREATE_FACTORY(ApproachTrigger);
     23
     24
     25ApproachTrigger::ApproachTrigger(const TiXmlElement* root)
     26{
     27    PRINTF(0)("13_1 ApproachTrigger %p created\n", this);
     28    this->registerObject(this, ApproachTrigger::_objectList);
     29    this->toList(OM_ENVIRON);
     30
     31    this->onlyHumans = false;
     32    this->onlyNPCs =  false;
     33    this->radius = 0;
     34    this->distanceX = 0;
     35    this->distanceY = 0;
     36    this->distanceZ = 0;
     37
     38    if (root != NULL)
     39        this->loadParams(root);
     40
     41    this->init_post_params();
     42}
     43
     44void ApproachTrigger::loadParams(const TiXmlElement* root)
     45{
     46    PRINTF(0)("13_2 ApproachTrigger loadParams\n", this);
     47    MoverTrigger::loadParams(root);
     48
     49    LoadParam(root, "radius", this, ApproachTrigger, setRadius)
     50        .describe("The radius wherein the player releases the trigger.")
     51        .defaultValues(0);
     52    LoadParam(root, "distance", this, ApproachTrigger, setDistance)
     53        .describe("The distance of all axes wherein the player releases the trigger.")
     54        .defaultValues(0, 0, 0);
     55    LoadParam(root, "onlyHumans", this, ApproachTrigger, setOnlyHumans)
     56        .describe("Only human players can release the trigger.")
     57        .defaultValues(false);
     58    LoadParam(root, "onlyNPCs", this, ApproachTrigger, setOnlyNPCs)
     59        .describe("Only NPCs can release the trigger.")
     60        .defaultValues(false);
     61}
     62
     63#include "playable.h"
     64#include "../npcs/generic_npc.h"
     65
     66bool ApproachTrigger::checkIsTriggered()
     67{
     68    WorldEntity* entity;
     69    float distance;
     70
     71    // for all players
     72    if (!this->onlyNPCs)
     73    {
     74        for (ObjectList<Playable>::const_iterator it = Playable::objectList().begin();
     75            it != Playable::objectList().end();
     76            ++it)
     77        {
     78            entity = (*it);
     79            distance = (this->getAbsCoor() - entity->getAbsCoor()).len();
     80            if (distance <= this->radius
     81                || (fabs(this->getAbsCoor().x - entity->getAbsCoor().x) <= this->distanceX
     82                    && fabs(this->getAbsCoor().y - entity->getAbsCoor().y) <= this->distanceY
     83                    && fabs(this->getAbsCoor().z - entity->getAbsCoor().z) <= this->distanceZ))
     84                return true;
     85        }
     86    }
     87
     88    // for all npcs
     89    if (!this->onlyHumans)
     90    {
     91        for (ObjectList<GenericNPC>::const_iterator it = GenericNPC::objectList().begin();
     92            it != GenericNPC::objectList().end();
     93            ++it)
     94        {
     95            entity = (*it);
     96            distance = (this->getAbsCoor() - entity->getAbsCoor()).len();
     97            if (distance <= this->radius
     98                || (fabs(this->getAbsCoor().x - entity->getAbsCoor().x) <= this->distanceX
     99                    && fabs(this->getAbsCoor().y - entity->getAbsCoor().y) <= this->distanceY
     100                    && fabs(this->getAbsCoor().z - entity->getAbsCoor().z) <= this->distanceZ))
     101                return true;
     102        }
     103    }
     104   
     105    return false;
     106}
  • mover_station.cc

     
     1/*
     2   orxonox - the future of 3D-vertical-scrollers
     3
     4   Copyright (C) 2007 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: Fabian 'x3n' Landau
     13   co-programmer:
     14*/
     15
     16#include "util/loading/load_param.h"
     17#include "util/loading/factory.h"
     18#include "mover_station.h"
     19#include "debug.h"
     20
     21ObjectListDefinition(MoverStation);
     22CREATE_FACTORY(MoverStation);
     23
     24
     25MoverStation::MoverStation(const TiXmlElement* root)
     26{
     27    PRINTF(0)("MoverStation %p erzeugt\n", this);
     28    this->rank = 0;
     29    this->relTargetCoor = Vector(0, 0, 0);
     30    this->relTargetDir = Vector(0, 0, 0);
     31    this->delay = 0;
     32    this->movingTime = 0;
     33    this->stayOpenTime = 0;
     34    this->bAccelerate = false;
     35    this->bDecelerate = false;
     36    this->jumpToRank = 0;
     37    this->bJumpToRank = false;
     38    this->moveToRank = 0;
     39    this->bMoveToRank = false;
     40    this->bIsOpen = false;
     41    this->bIsClosed = false;;
     42
     43    if (root != NULL)
     44        this->loadParams(root);
     45}
     46
     47MoverStation::~MoverStation()
     48{
     49}
     50
     51void MoverStation::loadParams(const TiXmlElement* root)
     52{
     53    WorldEntity::loadParams(root);
     54
     55    LoadParam(root, "rank", this, MoverStation, setRank)
     56        .describe("The rank of the station in the stationlist of the mover.")
     57        .defaultValues(0);
     58    LoadParam(root, "rel-target-coor", this, MoverStation, setRelTargetCoor)
     59        .describe("The relative coordinates of the stations target.")
     60        .defaultValues(0, 0, 0);
     61    LoadParam(root, "rel-target-dir", this, MoverStation, setRelTargetDir)
     62        .describe("The relative direction of the stations target in all axes (roll/pitch/yaw).")
     63        .defaultValues(0, 0, 0);
     64    LoadParam(root, "delay", this, MoverStation, setDelay)
     65        .describe("The amount of time the mover waits, before he starts moving.")
     66        .defaultValues(0);
     67    LoadParam(root, "moving-time", this, MoverStation, setMovingTime)
     68        .describe("The amount of time the mover needs to move.")
     69        .defaultValues(0);
     70    LoadParam(root, "stay-open-time", this, MoverStation, setStayOpenTime)
     71        .describe("The amount of time the mover waits when he reached the target.")
     72        .defaultValues(0);
     73    LoadParam(root, "bAccelerate", this, MoverStation, setAccelerate)
     74        .describe("If true, the mover starts slowly and increases his speed.");
     75    LoadParam(root, "bDecelerate", this, MoverStation, setDecelerate)
     76        .describe("If true, the mover starts fast and decreases his speed.");
     77    LoadParam(root, "jump-to-rank", this, MoverStation, setJumpToRank)
     78        .describe("The rank of the station the mover should jump to, after reaching the target.")
     79        .defaultValues(0);
     80    LoadParam(root, "move-to-rank", this, MoverStation, setMoveToRank)
     81        .describe("The rank of the station the mover should move to (instead of rel-target-coor).")
     82        .defaultValues(0);
     83    LoadParam(root, "bOpen", this, MoverStation, setOpen)
     84        .describe("If true, the mover changes to state 'open' after reaching this station.");
     85    LoadParam(root, "bClosed", this, MoverStation, setClosed)
     86        .describe("If true, the mover changes to state 'closed' after reaching this station.");
     87    LoadParam(root, "opening-sound", this, MoverStation, setOpeningSoundFile)
     88        .describe("Sets the file of the opening sound source");
     89    LoadParam(root, "opened-sound", this, MoverStation, setOpenedSoundFile)
     90        .describe("Sets the file of the opened sound source");
     91    LoadParam(root, "moving-sound", this, MoverStation, setMovingSoundFile)
     92        .describe("Sets the file of the moving sound source");
     93    LoadParam(root, "closing-sound", this, MoverStation, setClosingSoundFile)
     94        .describe("Sets the file of the closing sound source");
     95    LoadParam(root, "closed-sound", this, MoverStation, setClosedSoundFile)
     96        .describe("Sets the file of the closed sound source");
     97       
     98    if (this->bMoveToRank)
     99    {
     100        this->relTargetCoor = Vector(0, 0, 0);
     101        this->relTargetDir = Vector(0, 0, 0);
     102    }
     103}
  • mover_station.h

     
     1/*!
     2 * @file mover_station.h
     3 *  A station for a mover.
     4 */
     5
     6#ifndef _MOVER_STATION_H
     7#define _MOVER_STATION_H
     8
     9#include "world_entity.h"
     10#include "sound_buffer.h"
     11#include "sound/resource_sound_buffer.h"
     12
     13
     14class MoverStation : public WorldEntity
     15{
     16    friend class MoverStationList;
     17
     18    ObjectListDeclaration(MoverStation);
     19
     20    public:
     21        MoverStation(const TiXmlElement* root = NULL);
     22        virtual ~MoverStation();
     23
     24        virtual void loadParams(const TiXmlElement* root);
     25
     26        void setRank(int id) { this->rank = id; }
     27        void setRelTargetCoor(float x = 0, float y = 0, float z = 0) { this->relTargetCoor = Vector(x, y, z); }
     28        void setRelTargetDir(float wx = 0, float wy = 0, float wz = 0) { this->relTargetDir = Vector(wx, wy, wz); }
     29        void setDelay(float t) { this->delay = t; }
     30        void setMovingTime(float t) { this->movingTime = t; }
     31        void setStayOpenTime(float t) { this->stayOpenTime = t; }
     32        void setAccelerate() { this->bAccelerate = true; }
     33        void setDecelerate() { this->bDecelerate = true; }
     34        void setJumpToRank(int rank) { this->jumpToRank = rank; this->bJumpToRank = true; }
     35        void setMoveToRank(int rank) { this->moveToRank = rank; this->bMoveToRank = true; }
     36        void setOpen() { this->bIsOpen = true; }
     37        void setClosed() { this->bIsClosed = true; }
     38        void setOpeningSoundFile(const std::string& fileName) { this->soundBuffer_opening = OrxSound::ResourceSoundBuffer(fileName); }
     39        void setOpenedSoundFile(const std::string& fileName) { this->soundBuffer_opened = OrxSound::ResourceSoundBuffer(fileName); }
     40        void setMovingSoundFile(const std::string& fileName) { this->soundBuffer_moving = OrxSound::ResourceSoundBuffer(fileName); }
     41        void setClosingSoundFile(const std::string& fileName) { this->soundBuffer_closing = OrxSound::ResourceSoundBuffer(fileName); }
     42        void setClosedSoundFile(const std::string& fileName) { this->soundBuffer_closed = OrxSound::ResourceSoundBuffer(fileName); }
     43
     44    private:
     45        int                     rank;
     46        Vector                  relTargetCoor;
     47        Vector                  relTargetDir;
     48        float                   delay;
     49        float                   movingTime;
     50        float                   stayOpenTime;
     51        bool                    bAccelerate;
     52        bool                    bDecelerate;
     53        int                     jumpToRank;
     54        bool                    bJumpToRank;
     55        int                     moveToRank;
     56        bool                    bMoveToRank;
     57        bool                    bIsOpen;
     58        bool                    bIsClosed;
     59        OrxSound::SoundBuffer   soundBuffer_opening;
     60        OrxSound::SoundBuffer   soundBuffer_opened;
     61        OrxSound::SoundBuffer   soundBuffer_moving;
     62        OrxSound::SoundBuffer   soundBuffer_closing;
     63        OrxSound::SoundBuffer   soundBuffer_closed;
     64};
     65
     66
     67#endif
  • mover_trigger_event_list.cc

     
     1/*
     2   orxonox - the future of 3D-vertical-scrollers
     3
     4   Copyright (C) 2007 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: Fabian 'x3n' Landau
     13   co-programmer:
     14*/
     15
     16#include "mover_trigger_event_list.h"
     17#include "debug.h"
     18/*
     19MoverTriggerEventList *listPointer = 0;
     20
     21MoverTriggerEventList::getListPointer()
     22{
     23    if (!this->listPointer)
     24        this->listPointer = new MoverTriggerEventList();
     25       
     26    return this->listPointer;
     27}
     28*/
     29MoverTriggerEventList::MoverTriggerEventList()
     30{
     31    this->first = 0;
     32}
     33
     34
     35MoverTriggerEventList::~MoverTriggerEventList()
     36{
     37    while (this->first != 0)
     38    {
     39        this->removeTrigger(this->first->trigger);
     40    }
     41}
     42
     43void MoverTriggerEventList::addTrigger(MoverTrigger *trigger)
     44{
     45    if (trigger)
     46    {
     47        if (!this->first)
     48            this->first = new MoverTriggerEventListElement(trigger);
     49        else
     50        {
     51            MoverTriggerEventListElement *temp = this->first;
     52            while (temp->next != 0)
     53                temp = temp->next;
     54
     55            temp->next = new MoverTriggerEventListElement(trigger);
     56        }
     57    }
     58}
     59
     60void MoverTriggerEventList::removeTrigger(MoverTrigger *trigger)
     61{
     62    if (trigger)
     63    {
     64        if (this->first != 0)
     65        {
     66            if (this->first->trigger == trigger)
     67            {
     68                MoverTriggerEventListElement *temp = this->first->next;
     69
     70                delete this->first;
     71                this->first = temp;
     72            }
     73            else
     74            {
     75                MoverTriggerEventListElement *temp = this->first;
     76
     77                while (temp != 0)
     78                {
     79                    if (temp->next && (temp->next->trigger == trigger))
     80                    {
     81                        MoverTriggerEventListElement *temp2 = temp->next->next;
     82                        delete temp->next;
     83                        temp->next = temp2;
     84                    }
     85
     86                    temp = temp->next;
     87                }
     88            }
     89        }
     90    }
     91}
     92
     93bool MoverTriggerEventList::isEmpty()
     94{
     95    return (this->first == 0);
     96}
     97
     98bool MoverTriggerEventList::isTriggered(const std::string& triggerName)
     99{
     100    MoverTriggerEventListElement *temp = this->first;
     101    bool isTriggered = false;
     102   
     103    while (temp != 0)
     104    {
     105        if (temp->trigger && (temp->trigger->getName() == triggerName))
     106        {
     107            if (temp->trigger->isTriggered())
     108            {
     109                isTriggered = true;
     110            }
     111            else
     112            {
     113                if (temp->trigger->isObligatory())
     114                    return false;
     115            }
     116        }
     117       
     118        temp = temp->next;
     119    }
     120   
     121    return isTriggered;
     122}
     123
     124MoverTriggerPointerList *MoverTriggerEventList::getPointerList(const std::string& triggerName)
     125{
     126    MoverTriggerPointerList *list = new MoverTriggerPointerList();
     127    MoverTriggerEventListElement *temp = this->first;
     128
     129    while (temp != 0)
     130    {
     131        if (temp->trigger && (temp->trigger->getName() == triggerName))
     132            list->addTrigger(temp->trigger);
     133
     134        temp = temp->next;
     135    }
     136   
     137    return list;
     138}
     139
     140
     141////////////////////////////////////////////////////////
     142
     143
     144MoverTriggerEventListElement::MoverTriggerEventListElement(MoverTrigger *trigger)
     145{
     146    this->trigger = trigger;
     147    this->next = 0;
     148}
     149
     150MoverTriggerEventListElement::~MoverTriggerEventListElement()
     151{
     152}
  • mover_trigger_list.h

     
     1/*!
     2 * @file mover_trigger_list.h
     3 *  A list to store and handle several triggers.
     4 */
     5
     6#ifndef _MOVER_TRIGGER_LIST_H
     7#define _MOVER_TRIGGER_LIST_H
     8
     9#include "mover_trigger.h"
     10
     11
     12class MoverTrigger;
     13
     14class MoverTriggerListElement
     15{
     16    public:
     17        MoverTriggerListElement(MoverTrigger *trigger);
     18        ~MoverTriggerListElement();
     19       
     20        MoverTrigger *trigger;
     21        MoverTriggerListElement *next;
     22};
     23
     24
     25class MoverTriggerList
     26{
     27    public:
     28        MoverTriggerList();
     29        ~MoverTriggerList();
     30
     31        void addTrigger(MoverTrigger *trigger);
     32        bool isTriggered();
     33        void setBaseCoor(Vector baseCoor);
     34
     35    private:
     36        MoverTriggerListElement *first;
     37};
     38
     39
     40#endif
  • mover_trigger_pointer_list.h

     
     1/*!
     2 * @file mover_trigger_pointer_list.h
     3 *  A list to store and handle several trigger pointers.
     4 */
     5
     6#ifndef _MOVER_TRIGGER_POINTER_LIST_H
     7#define _MOVER_TRIGGER_POINTER_LIST_H
     8
     9#include "mover_trigger.h"
     10
     11
     12class MoverTrigger;
     13
     14class MoverTriggerPointerListElement
     15{
     16    public:
     17        MoverTriggerPointerListElement(MoverTrigger *trigger);
     18        ~MoverTriggerPointerListElement();
     19       
     20        MoverTrigger *trigger;
     21        MoverTriggerPointerListElement *next;
     22};
     23
     24
     25class MoverTriggerPointerList
     26{
     27    public:
     28        MoverTriggerPointerList();
     29        ~MoverTriggerPointerList();
     30
     31        void addTrigger(MoverTrigger *trigger);
     32        bool isTriggered();
     33
     34    private:
     35        MoverTriggerPointerListElement *first;
     36};
     37
     38
     39#endif
  • mover_trigger_event_list.h

     
     1/*!
     2 * @file mover_trigger_event_list.h
     3 *  A List to handle several events, caused by mover triggers.
     4 */
     5
     6#ifndef _MOVER_TRIGGER_EVENT_LIST_H
     7#define _MOVER_TRIGGER_EVENT_LIST_H
     8
     9#include "mover_trigger.h"
     10#include "mover_trigger_pointer_list.h"
     11
     12
     13class MoverTrigger;
     14class MoverTriggerPointerList;
     15
     16class MoverTriggerEventListElement
     17{
     18    public:
     19        MoverTriggerEventListElement(MoverTrigger *trigger);
     20        ~MoverTriggerEventListElement();
     21
     22        MoverTrigger *trigger;
     23        MoverTriggerEventListElement *next;
     24};
     25
     26
     27class MoverTriggerEventList
     28{
     29    public:
     30//        static MoverTriggerEventList *getListPointer();
     31       
     32        void addTrigger(MoverTrigger *trigger);
     33        void removeTrigger(MoverTrigger *trigger);
     34        bool isEmpty();
     35        bool isTriggered(const std::string& triggerName);
     36        MoverTriggerPointerList *getPointerList(const std::string& triggerName);
     37
     38//    protected:
     39        MoverTriggerEventList();
     40        ~MoverTriggerEventList();
     41
     42    private:
     43        MoverTriggerEventListElement *first;
     44//        static MoverTriggerEventList *listPointer;
     45};
     46
     47
     48#endif
  • mover_trigger.cc

     
     1/*
     2   orxonox - the future of 3D-vertical-scrollers
     3
     4   Copyright (C) 2007 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: Fabian 'x3n' Landau
     13   co-programmer:
     14*/
     15
     16#include "util/loading/load_param_xml.h"
     17#include "util/loading/load_param.h"
     18#include "util/loading/factory.h"
     19#include "mover_trigger.h"
     20#include "mover_trigger_approach.h"
     21#include "mover_trigger_mapstart.h"
     22#include "mover_trigger_key.h"
     23#include "mover_trigger_event.h"
     24#include "mover_trigger_intervisibility.h"
     25#include <string.h>
     26
     27MoverTriggerEventList *MoverTrigger::events = 0;
     28
     29ObjectListDefinition(MoverTrigger);
     30CREATE_FACTORY(MoverTrigger);
     31
     32
     33MoverTrigger::MoverTrigger(const TiXmlElement* root)
     34{
     35    PRINTF(0)("5_1 MoverTrigger %p created\n", this);
     36    this->registerObject(this, MoverTrigger::_objectList);
     37    this->toList(OM_ENVIRON);
     38
     39    PRINTF(0)("5_2\n");
     40    this->init_prae_params();
     41    PRINTF(0)("5_3\n");
     42
     43    if (root != NULL)
     44        this->loadParams(root);
     45
     46    PRINTF(0)("5_4\n");
     47    this->init_post_params();
     48    PRINTF(0)("5_5\n");
     49}
     50
     51MoverTrigger::~MoverTrigger()
     52{
     53    PRINTF(0)("14_1 MoverTrigger %p destroyed\n", this);
     54    if (this->triggers)
     55        delete this->triggers;
     56       
     57    PRINTF(0)("14_2\n");
     58    if (this->delaylist)
     59        delete this->delaylist;
     60   
     61    PRINTF(0)("14_3\n");
     62    if (MoverTrigger::events)
     63    {
     64        PRINTF(0)("14_4\n");
     65        MoverTrigger::events->removeTrigger(this);
     66        if (MoverTrigger::events->isEmpty())
     67        {
     68            PRINTF(0)("14_5\n");
     69            delete MoverTrigger::events;
     70            MoverTrigger::events = 0;
     71        }
     72    }
     73    PRINTF(0)("14_6\n");
     74}
     75
     76void MoverTrigger::init_prae_params()
     77{
     78    PRINTF(0)("6_1\n");
     79    this->bIsTriggered = false;
     80    this->delay = 0;
     81    this->bIsWaitingForDelay = false;
     82    this->relCoor = Vector(0, 0, 0);
     83    this->bStayTriggered = false;
     84    this->bTriggerOnceOnly = false;
     85    this->bInvert = false;
     86    this->bSwitch = false;
     87    this->bObligatory = false;
     88    this->bFirstRelease = true;
     89    this->oldState = false;
     90    this->time = 0;
     91   
     92    this->triggers = 0;
     93    this->delaylist = 0;
     94   
     95//    if (!this->delaylist)
     96        this->delaylist = new MoverTriggerDelayList();
     97
     98//    if (!this->triggers)
     99        this->triggers = new MoverTriggerList();
     100
     101    PRINTF(0)("6_2\n");
     102
     103    if (!MoverTrigger::events)
     104        MoverTrigger::events = new MoverTriggerEventList();
     105       
     106    PRINTF(0)("6_3\n");
     107}
     108
     109void MoverTrigger::init_post_params()
     110{
     111    PRINTF(0)("6_4\n");
     112    this->updateNode(0.001);
     113    this->setBaseCoor(this->getAbsCoor());
     114
     115//    PRINTF(0)("6_5 MoverTrigger abs-coor: %f, %f, %f\n", this->getAbsCoor().x, this->getAbsCoor().y, this->getAbsCoor().z);
     116
     117    PRINTF(0)("6_5\n");
     118    if (this->getName() != "")
     119        MoverTrigger::events->addTrigger(this);
     120       
     121    PRINTF(0)("6_6\n");
     122}
     123
     124void MoverTrigger::loadParams(const TiXmlElement* root)
     125{
     126    PRINTF(0)("7_1 MoverTrigger loadParams for trigger %p\n", this);
     127    WorldEntity::loadParams(root);
     128
     129    LoadParam(root, "rel-coor", this, MoverTrigger, setRelCoor)
     130        .describe("The relative position to the mover.")
     131        .defaultValues(0, 0, 0);
     132    LoadParam(root, "delay", this, MoverTrigger, setDelay)
     133        .describe("The delay of the trigger.")
     134        .defaultValues(0);
     135    LoadParam(root, "bStayTriggered", this, MoverTrigger, setStayTriggered)
     136        .describe("If the trigger gets released, he stays triggered forever.")
     137        .defaultValues(false);
     138    LoadParam(root, "bTriggerOnceOnly", this, MoverTrigger, setTriggerOnceOnly)
     139        .describe("The trigger can only be released once.")
     140        .defaultValues(false);
     141    LoadParam(root, "bInvert", this, MoverTrigger, setInvert)
     142        .describe("Inverts the state of the trigger.")
     143        .defaultValues(false);
     144    LoadParam(root, "bSwitch", this, MoverTrigger, setSwitch)
     145        .describe("Each time the trigger gets triggered again, he switches his state.")
     146        .defaultValues(false);
     147    LoadParam(root, "bObligatory", this, MoverTrigger, setObligatory)
     148        .describe("A obligatory trigger MUST be triggered to create an event.")
     149        .defaultValues(false);
     150    LoadParamXML(root, "triggers", this, MoverTrigger, setTriggers)
     151        .describe("Adds a trigger that triggers the trigger.");
     152}
     153
     154void MoverTrigger::setBaseCoor(Vector baseCoor)
     155{
     156//    PRINTF(0)("13_1\n");
     157    this->setAbsCoor(baseCoor + this->relCoor);
     158//    PRINTF(0)("13_2\n");
     159    if (this->triggers)
     160        this->triggers->setBaseCoor(baseCoor);
     161//    PRINTF(0)("13_3\n");
     162}
     163
     164void MoverTrigger::setTriggers(const TiXmlElement* root)
     165{
     166    PRINTF(0)("8_1\n");
     167    if (!this->triggers)
     168        this->triggers = new MoverTriggerList();
     169       
     170    const TiXmlElement* element = root->FirstChildElement();
     171
     172    PRINTF(0)("8_2\n");
     173    while (element != NULL)
     174    {
     175        PRINTF(0)("8_3\n");
     176        BaseObject *newObj = Factory::fabricate(element);
     177//        MoverTrigger *newTrigger = ((MoverTrigger*)(&newObj));
     178        MoverTrigger *newTrigger = (dynamic_cast< MoverTrigger *> ( newObj ));
     179        this->triggers->addTrigger(newTrigger);
     180//        this->triggers->addTrigger(MoverTrigger::createTrigger(element));
     181        PRINTF(0)("8_4\n");
     182        element = element->NextSiblingElement();
     183    }
     184    PRINTF(0)("8_5\n");
     185}
     186/*
     187MoverTrigger *MoverTrigger::createTrigger(const TiXmlElement* root)
     188{
     189    PRINTF(0)("9_1\n");
     190    PRINTF(0)("root->Value(): %s\n", root->Value());
     191    if (strcmp(root->Value(), "MoverTrigger") == 0)
     192    {
     193        PRINTF(0)("9_2\n");
     194        return new MoverTrigger(root);
     195    }
     196    else if (strcmp(root->Value(), "ApproachTrigger") == 0)
     197    {
     198        PRINTF(0)("9_3\n");
     199        return new ApproachTrigger(root);
     200    }
     201    else if (strcmp(root->Value(), "MapstartTrigger") == 0)
     202        return new MapstartTrigger(root);
     203    else if (strcmp(root->Value(), "EventTrigger") == 0)
     204        return new EventTrigger(root);
     205    else if (strcmp(root->Value(), "KeyTrigger") == 0)
     206        return new KeyTrigger(root);
     207    else if (strcmp(root->Value(), "IntervisibilityTrigger") == 0)
     208        return new IntervisibilityTrigger(root);
     209    else
     210    {
     211        PRINTF(0)("9_4\n");
     212        return new MoverTrigger(root);
     213    }
     214}
     215*/
     216void MoverTrigger::tick(float dt)
     217{
     218    this->time += dt;
     219   
     220    if (this->delaylist && this->delaylist->isEmpty())
     221        this->time = 0;
     222}
     223
     224bool MoverTrigger::isTriggered()
     225{
     226//    PRINTF(0)("17_1\n");
     227    if (!this->bIsTriggered && this->bTriggerOnceOnly && !this->bFirstRelease)
     228        return this->bInvert; // yes this makes sense... just think about it ;)
     229
     230//    PRINTF(0)("17_2\n");
     231    if (!this->bStayTriggered || !this->bIsTriggered)
     232    {
     233//        PRINTF(0)("17_3\n");
     234        if (this->triggers && this->delaylist)
     235        {
     236//            PRINTF(0)("17_4\n");
     237            if (this->triggers->isTriggered())
     238            {
     239//                PRINTF(0)("17_5\n");
     240                bool tempIsTriggered = this->checkIsTriggered();
     241                if (this->delaylist->isEmpty())
     242                {
     243                    if (!this->bSwitch)
     244                    {
     245                        if (tempIsTriggered != this->bIsTriggered)
     246                            this->delaylist->addState(tempIsTriggered, this->oldState, this->time + this->delay);
     247                    }
     248                    else
     249                    {
     250                        if (tempIsTriggered != this->oldState)
     251                            this->delaylist->addState(tempIsTriggered, this->oldState, this->time + this->delay);
     252                    }
     253                }
     254                else
     255                {
     256                    if (!this->bSwitch)
     257                    {
     258                        if (tempIsTriggered != this->delaylist->getLastState()->state)
     259                            this->delaylist->addState(tempIsTriggered, this->oldState, this->time + this->delay);
     260                    }
     261                    else
     262                    {
     263                        if (tempIsTriggered != this->delaylist->getLastState()->oldState)
     264                            this->delaylist->addState(tempIsTriggered, this->oldState, this->time + this->delay);
     265                    }
     266                }
     267            }
     268
     269//            PRINTF(0)("17_6\n");
     270            while (!this->delaylist->isEmpty())
     271            {
     272                MoverTriggerDelayListElement *element = this->delaylist->getFirstState();
     273
     274                if (element && (this->time >= element->time))
     275                {
     276                    if (!this->bSwitch)
     277                    {
     278                        this->bIsTriggered = element->state;
     279                    }
     280                    else
     281                    {
     282                        if (element->state && !this->oldState)
     283                            this->bIsTriggered = !this->bIsTriggered;
     284
     285                        this->oldState = element->state;
     286                    }
     287
     288                    this->delaylist->deleteFirstState();
     289
     290                    if (this->delaylist->isEmpty())
     291                    {
     292                        this->time = 0;
     293                        break;
     294                    }
     295                   
     296                    continue;
     297                }
     298               
     299                break;
     300            }
     301        }
     302        else
     303            this->bIsTriggered = false;
     304    }
     305
     306//    PRINTF(0)("17_7\n");
     307    if (this->bIsTriggered && this->bTriggerOnceOnly && this->bFirstRelease)
     308        this->bFirstRelease = false;
     309
     310//    PRINTF(0)("17_8\n");
     311    if (this->bInvert)
     312        return (!this->bIsTriggered);
     313    else
     314        return this->bIsTriggered;
     315}
     316
     317bool MoverTrigger::isObligatory()
     318{
     319    return this->bObligatory;
     320}
     321
     322bool MoverTrigger::checkIsTriggered()
     323{
     324    return true;
     325}
     326
     327
  • mover_trigger_event.cc

     
     1/*
     2   orxonox - the future of 3D-vertical-scrollers
     3
     4   Copyright (C) 2007 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: Fabian 'x3n' Landau
     13   co-programmer:
     14*/
     15
     16#include "util/loading/load_param.h"
     17#include "util/loading/factory.h"
     18#include "mover_trigger_event.h"
     19#include "debug.h"
     20
     21ObjectListDefinition(EventTrigger);
     22CREATE_FACTORY(EventTrigger);
     23
     24
     25EventTrigger::EventTrigger(const TiXmlElement* root)
     26{
     27    PRINTF(0)("15_1 EventTrigger %p created\n", this);
     28    this->registerObject(this, EventTrigger::_objectList);
     29    this->toList(OM_ENVIRON);
     30
     31    this->eventName = "";
     32    this->eventTriggers = 0;
     33    this->bIsChecking = false;
     34   
     35    if (root != NULL)
     36        this->loadParams(root);
     37
     38    this->init_post_params();
     39}
     40
     41EventTrigger::~EventTrigger()
     42{
     43    delete this->eventTriggers;
     44}
     45
     46void EventTrigger::loadParams(const TiXmlElement* root)
     47{
     48    MoverTrigger::loadParams(root);
     49
     50    LoadParam(root, "event", this, EventTrigger, setEvent)
     51        .describe("The event that releases the trigger")
     52        .defaultValues("");
     53}
     54
     55bool EventTrigger::checkIsTriggered()
     56{
     57    if (this->bIsChecking)
     58        return this->bIsTriggered; // to avoid event-loops
     59       
     60    if (!this->eventTriggers)
     61    {
     62        if (MoverTrigger::events)
     63            this->eventTriggers = MoverTrigger::events->getPointerList(this->eventName);
     64
     65        if (!this->eventTriggers)
     66            this->eventTriggers = new MoverTriggerPointerList();
     67    }
     68
     69    this->bIsChecking = true;
     70    bool isTriggered = this->eventTriggers->isTriggered();
     71    this->bIsChecking = false;
     72   
     73    return isTriggered;
     74}
     75
  • mover_trigger.h

     
     1/*!
     2 * @file mover_trigger.h
     3 *  Base-class for all mover triggers and container for an independent triggerlist.
     4 */
     5
     6#ifndef _MOVER_TRIGGER_H
     7#define _MOVER_TRIGGER_H
     8
     9#include "world_entity.h"
     10#include "mover_trigger_list.h"
     11#include "mover_trigger_event_list.h"
     12#include "mover_trigger_delay_list.h"
     13
     14
     15class MoverTriggerList;
     16class MoverTriggerEventList;
     17
     18class MoverTrigger : public WorldEntity
     19{
     20    ObjectListDeclaration(MoverTrigger);
     21   
     22    public:
     23        MoverTrigger(const TiXmlElement* root = NULL);
     24        virtual ~MoverTrigger();
     25
     26        virtual void loadParams(const TiXmlElement* root);
     27        virtual void tick(float dt);
     28       
     29        void setRelCoor(float x, float y, float z) { this->relCoor = Vector(x, y, z); }
     30        void updateCoordinates(Vector baseCoor);
     31        void setDelay(float delay) { this->delay = delay; }
     32        void setStayTriggered(bool bStayTriggered = true) { this->bStayTriggered = bStayTriggered; }
     33        void setTriggerOnceOnly(bool bTriggerOnceOnly = true) { this->bTriggerOnceOnly = bTriggerOnceOnly; }
     34        void setInvert(bool bInvert = true) { this->bInvert = bInvert; }
     35        void setSwitch(bool bSwitch = true) { this->bSwitch = bSwitch; }
     36        void setObligatory(bool bObligatory = true) { this->bObligatory = bObligatory; }
     37        void setTriggers(const TiXmlElement* root);
     38        void setBaseCoor(Vector baseCoor);
     39
     40        bool isTriggered();
     41        bool isObligatory();
     42        static MoverTriggerEventList *events;
     43        std::string getName() { return this->objectName; }
     44        static MoverTrigger *createTrigger(const TiXmlElement* root);
     45
     46    protected:
     47        void init_post_params();
     48
     49        bool                    bIsTriggered;
     50
     51    private:
     52        void init_prae_params();
     53        virtual bool checkIsTriggered();
     54       
     55        Vector                  relCoor;
     56        float                   delay;
     57        bool                    bIsWaitingForDelay;
     58        bool                    bStayTriggered;
     59        bool                    bTriggerOnceOnly;
     60        bool                    bInvert;
     61        bool                    bSwitch;
     62        bool                    bObligatory;
     63        float                   time;
     64        bool                    bFirstRelease;
     65        bool                    oldState;
     66
     67        MoverTriggerList        *triggers;
     68        MoverTriggerDelayList   *delaylist;
     69};
     70
     71
     72#endif
     73
  • mover_station_list.cc

     
     1/*
     2   orxonox - the future of 3D-vertical-scrollers
     3
     4   Copyright (C) 2007 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: Fabian 'x3n' Landau
     13   co-programmer:
     14*/
     15
     16#include "mover_station_list.h"
     17#include "debug.h"
     18
     19
     20MoverStationList::MoverStationList()
     21{
     22    this->first = 0;
     23    this->last = 0;
     24    this->goForward = true;
     25}
     26
     27MoverStationList::~MoverStationList()
     28{
     29    MoverStationListElement *temp1 = this->first;
     30    MoverStationListElement *temp2;
     31    while (temp1 != 0)
     32    {
     33        temp2 = temp1->next;
     34        delete temp1;
     35        temp1 = temp2;
     36    }
     37}
     38
     39void MoverStationList::addStation(MoverStation *station)
     40{
     41    PRINTF(0)("Füge MoverStation %p hinzu\n", station);
     42    if (this->first == 0)
     43    {
     44        this->first = new MoverStationListElement(station);
     45        this->last = this->first;
     46        return;
     47    }
     48    else
     49    {
     50        if (this->first->station->rank > station->rank)
     51        {
     52            MoverStationListElement *temp = this->first;
     53            this->first = new MoverStationListElement(station);
     54            this->first->next = temp;
     55            this->first->next->prev = this->first;
     56            return;
     57        }
     58        else
     59        {
     60            MoverStationListElement *temp1 = this->first;
     61            MoverStationListElement *temp2;
     62            while (temp1->next != 0)
     63            {
     64                if (temp1->next->station->rank > station->rank)
     65                {
     66                    temp2 = temp1->next;
     67                    temp1->next = new MoverStationListElement(station);
     68                    temp1->next->prev = temp1;
     69                    temp1->next->next = temp2;
     70                    temp1->next->next->prev = temp1->next;
     71                       
     72                    return;
     73                }
     74               
     75                temp1 = temp1->next;
     76            }
     77           
     78            temp1->next = new MoverStationListElement(station);
     79            temp1->next->prev = last;
     80            last = temp1->next;
     81        }
     82    }
     83}
     84
     85MoverStation *MoverStationList::getNextStation(MoverStation *station)
     86{
     87    if (this->goForward)
     88    {
     89        if (station)
     90        {
     91            MoverStationListElement *temp;
     92            if (station->bJumpToRank)
     93            {
     94                temp = this->first;
     95                while (temp != 0)
     96                {
     97                    if (temp->station->rank == station->jumpToRank)
     98                        return temp->station;
     99
     100                    temp = temp->next;
     101                }
     102            } // no "else" here - if jumpToRank wasn't found, we return the following station (as usual)
     103
     104            if (station->bMoveToRank)
     105            {
     106                temp = this->first;
     107                while (temp != 0)
     108                {
     109                    if (temp->station->rank == station->moveToRank)
     110                        return temp->station;
     111
     112                    temp = temp->next;
     113                }
     114            } // no "else" here - if moveToRank wasn't found, we return the following station (as usual)
     115
     116            temp = this->first;
     117            while (temp != 0)
     118            {
     119                if (temp->station == station)
     120                {
     121                    if (temp->next)
     122                    {
     123                        return temp->next->station;
     124                    }
     125                    else
     126                    {
     127                        this->goForward = false;
     128                        return this->last->station;
     129                    }
     130                }
     131                temp = temp->next;
     132            }
     133            return 0;
     134        }
     135        else
     136        {
     137            if (this->first)
     138                return this->first->station;
     139            else
     140                return 0;
     141        }
     142    }
     143    else
     144    {
     145        if (station)
     146        {
     147            MoverStationListElement *temp;
     148            if (station->bJumpToRank)
     149            {
     150                temp = this->last;
     151                while (temp != 0)
     152                {
     153                    if (temp->station->rank == station->jumpToRank)
     154                        return temp->station;
     155
     156                    temp = temp->prev;
     157                }
     158            } // no "else" here - if jumpToRank wasn't found, we return the following station (as usual)
     159
     160            if (station->bMoveToRank)
     161            {
     162                temp = this->last;
     163                while (temp != 0)
     164                {
     165                    if (temp->station->rank == station->moveToRank)
     166                        return temp->station;
     167
     168                    temp = temp->prev;
     169                }
     170            } // no "else" here - if moveToRank wasn't found, we return the following station (as usual)
     171
     172            temp = this->last;
     173            while (temp != 0)
     174            {
     175                if (temp->station == station)
     176                {
     177                    if (temp->prev)
     178                    {
     179                        return temp->prev->station;
     180                    }
     181                    else
     182                    {
     183                        this->goForward = true;
     184                        return this->first->station;
     185                    }
     186                }
     187                temp = temp->prev;
     188            }
     189            return 0;
     190        }
     191        else
     192        {
     193            if (this->last)
     194                return this->last->station;
     195            else
     196                return 0;
     197        }
     198    }
     199}
     200
     201Vector MoverStationList::getTotalRelCoor(MoverStation *station)
     202{
     203    MoverStationListElement *temp = this->first;
     204    Vector totalRelCoor = Vector(0, 0, 0);
     205
     206    if (station)
     207    {
     208        if (this->goForward)
     209        {
     210            while (temp != 0)
     211            {
     212                totalRelCoor += temp->station->relTargetCoor;
     213                if (temp->station == station)
     214                    break;
     215
     216                temp = temp->next;
     217            }
     218        }
     219        else
     220        {
     221            if (temp)
     222            {
     223                while (temp->next != 0)
     224                {
     225                    totalRelCoor += temp->next->station->relTargetCoor;
     226                    if (temp->next->station == station)
     227                        break;
     228
     229                    temp = temp->next;
     230                }
     231            }
     232        }
     233    }
     234
     235    return totalRelCoor;
     236}
     237
     238Vector MoverStationList::getTotalRelDir(MoverStation *station)
     239{
     240    MoverStationListElement *temp = this->first;
     241    Vector totalRelDir = Vector(0, 0, 0);
     242   
     243    if (station)
     244    {
     245        if (this->goForward)
     246        {
     247            while (temp != 0)
     248            {
     249                totalRelDir += temp->station->relTargetDir;
     250                if (temp->station == station)
     251                    break;
     252
     253                temp = temp->next;
     254            }
     255        }
     256        else
     257        {
     258            if (temp)
     259            {
     260                while (temp->next != 0)
     261                {
     262                    totalRelDir += temp->next->station->relTargetDir;
     263                    if (temp->next->station == station)
     264                        break;
     265
     266                    temp = temp->next;
     267                }
     268            }
     269        }
     270    }
     271
     272    return totalRelDir;
     273}
     274
     275bool MoverStationList::isOpen(MoverStation *station)
     276{
     277    if (station)
     278        if ((this->goForward && this->last && this->last->station == station) || station->bIsOpen)
     279            return true;
     280       
     281    return false;
     282}
     283
     284bool MoverStationList::isClosed(MoverStation *station)
     285{
     286    if (station)
     287        if ((!this->goForward && this->first && this->first->station == station) || station->bIsClosed)
     288            return true;
     289       
     290    return false;
     291}
     292
     293bool MoverStationList::changeDirection(bool bReopen, bool bReclose, bool bIsTriggered)
     294{
     295    if (this->goForward && bReclose && !bIsTriggered)
     296    {
     297        this->goForward = false;
     298        return true;
     299    }
     300   
     301    if (!this->goForward && bReopen && bIsTriggered)
     302    {
     303        this->goForward = true;
     304        return true;
     305    }
     306   
     307    return false;
     308}
     309
     310Vector MoverStationList::getRelTargetCoor(MoverStation *station)
     311{
     312    if (station)
     313    {
     314        if (!station->bMoveToRank)
     315        {
     316            if (this->goForward)
     317                return station->relTargetCoor;
     318            else
     319                return station->relTargetCoor * -1;
     320        }
     321        else
     322        {
     323            MoverStation *moveToStation = this->getStation(station->moveToRank);
     324
     325            if (moveToStation != 0)
     326            {
     327                if (this->goForward)
     328                    return (this->getTotalRelCoor(station) - this->getTotalRelCoor(moveToStation)) * -1;
     329                else
     330                    return (this->getTotalRelCoor(station) - this->getTotalRelCoor(moveToStation));
     331            }
     332        }
     333    }
     334   
     335    return Vector(0, 0, 0);
     336}
     337
     338Vector MoverStationList::getRelTargetDir(MoverStation *station)
     339{
     340    if (station)
     341    {
     342        if (!station->bMoveToRank)
     343        {
     344            if (this->goForward)
     345                return station->relTargetDir;
     346            else
     347                return station->relTargetDir * -1;
     348        }
     349        else
     350        {
     351            MoverStation *moveToStation = this->getStation(station->moveToRank);
     352
     353            if (moveToStation != 0)
     354            {
     355                if (this->goForward)
     356                    return (station->relTargetDir - this->getTotalRelDir(moveToStation)) * -1;
     357                else
     358                    return station->relTargetDir - this->getTotalRelDir(moveToStation);
     359            }
     360        }
     361    }
     362   
     363    return Vector(0, 0, 0);
     364}
     365
     366Vector MoverStationList::getVelocity(MoverStation *station)
     367{
     368    if (station)
     369        if (station->movingTime != 0)
     370            return this->getRelTargetCoor(station) / station->movingTime;
     371
     372    return Vector(0, 0, 0);
     373}
     374
     375Vector MoverStationList::getRotation(MoverStation *station)
     376{
     377    if (station)
     378        if (station->movingTime != 0)
     379            return this->getRelTargetDir(station) / station->movingTime;
     380
     381    return Vector(0, 0, 0);
     382}
     383
     384OrxSound::SoundBuffer MoverStationList::getStartingSound(MoverStation *station)
     385{
     386    if (station)
     387    {
     388        if (this->goForward)
     389            return station->soundBuffer_opening;
     390        else
     391            return station->soundBuffer_closing;
     392    }
     393
     394    return OrxSound::ResourceSoundBuffer("");
     395}
     396
     397OrxSound::SoundBuffer MoverStationList::getEndingSound(MoverStation *station)
     398{
     399    if (station)
     400    {
     401        if (this->goForward)
     402            return station->soundBuffer_opened;
     403        else
     404            return station->soundBuffer_closed;
     405    }
     406
     407    return OrxSound::ResourceSoundBuffer("");
     408}
     409
     410OrxSound::SoundBuffer MoverStationList::getMovingSound(MoverStation *station)
     411{
     412    if (station)
     413        return station->soundBuffer_moving;
     414
     415    return OrxSound::ResourceSoundBuffer("");
     416}
     417
     418MoverStation *MoverStationList::getStation(int rank)
     419{
     420    MoverStationListElement *temp;
     421
     422    temp = this->first;
     423    while (temp != 0)
     424    {
     425        if (temp->station->rank == rank)
     426            return temp->station;
     427
     428        temp = temp->next;
     429    }
     430   
     431    return 0;
     432}
     433
     434////////////////////////////////////////////////////////
     435
     436
     437MoverStationListElement::MoverStationListElement(MoverStation *station)
     438{
     439    this->station = station;
     440    this->next = 0;
     441    this->prev = 0;
     442}
     443
     444MoverStationListElement::~MoverStationListElement()
     445{
     446    delete this->station;
     447}
  • mover_trigger_intervisibility.cc

     
     1/*
     2   orxonox - the future of 3D-vertical-scrollers
     3
     4   Copyright (C) 2007 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: Fabian 'x3n' Landau
     13   co-programmer:
     14*/
     15
     16#include "util/loading/load_param.h"
     17#include "util/loading/factory.h"
     18#include "mover_trigger_intervisibility.h"
     19
     20ObjectListDefinition(IntervisibilityTrigger);
     21CREATE_FACTORY(IntervisibilityTrigger);
     22
     23
     24IntervisibilityTrigger::IntervisibilityTrigger(const TiXmlElement* root)
     25{
     26    this->registerObject(this, IntervisibilityTrigger::_objectList);
     27    this->toList(OM_ENVIRON);
     28
     29    this->onlyHumans = false;
     30    this->onlyNPCs =  false;
     31
     32    if (root != NULL)
     33        this->loadParams(root);
     34
     35    this->init_post_params();
     36}
     37
     38void IntervisibilityTrigger::loadParams(const TiXmlElement* root)
     39{
     40    MoverTrigger::loadParams(root);
     41
     42    LoadParam(root, "onlyHumans", this, IntervisibilityTrigger, setOnlyHumans)
     43        .describe("Only human players can release the trigger.")
     44        .defaultValues(false);
     45    LoadParam(root, "onlyNPCs", this, IntervisibilityTrigger, setOnlyNPCs)
     46        .describe("Only NPCs can release the trigger.")
     47        .defaultValues(false);
     48}
     49
     50bool IntervisibilityTrigger::checkIsTriggered()
     51{
     52    /* TODO */
     53    return false;
     54}
  • mover_trigger_delay_list.h

     
     1/*!
     2 * @file mover_trigger_delay_list.h
     3 *  A list to delay trigger-state-changes.
     4 */
     5
     6#ifndef _MOVER_TRIGGER_DELAY_LIST_H
     7#define _MOVER_TRIGGER_DELAY_LIST_H
     8
     9
     10class MoverTriggerDelayListElement
     11{
     12    public:
     13        MoverTriggerDelayListElement(bool state, bool oldState, float time);
     14        ~MoverTriggerDelayListElement();
     15       
     16        bool state;
     17        bool oldState;
     18        float time;
     19        MoverTriggerDelayListElement *next;
     20};
     21
     22
     23class MoverTriggerDelayList
     24{
     25    public:
     26        MoverTriggerDelayList();
     27        ~MoverTriggerDelayList();
     28
     29        void addState(bool state, bool oldState, float time);
     30        void deleteFirstState();
     31        MoverTriggerDelayListElement *getFirstState();
     32        MoverTriggerDelayListElement *getLastState();
     33        bool isEmpty();
     34
     35    private:
     36        MoverTriggerDelayListElement *first;
     37};
     38
     39
     40#endif
  • mover_trigger_mapstart.cc

     
     1/*
     2   orxonox - the future of 3D-vertical-scrollers
     3
     4   Copyright (C) 2007 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: Fabian 'x3n' Landau
     13   co-programmer:
     14*/
     15
     16#include "util/loading/load_param.h"
     17#include "util/loading/factory.h"
     18#include "mover_trigger_mapstart.h"
     19#include "debug.h"
     20
     21ObjectListDefinition(MapstartTrigger);
     22CREATE_FACTORY(MapstartTrigger);
     23
     24
     25MapstartTrigger::MapstartTrigger(const TiXmlElement* root)
     26{
     27    PRINTF(0)("13_1 MapstartTrigger %p created\n", this);
     28    this->registerObject(this, MapstartTrigger::_objectList);
     29    this->toList(OM_ENVIRON);
     30
     31    this->bInit = true;
     32
     33    if (root != NULL)
     34        this->loadParams(root);
     35
     36    this->init_post_params();
     37}
     38
     39void MapstartTrigger::loadParams(const TiXmlElement* root)
     40{
     41    MoverTrigger::loadParams(root);
     42}
     43
     44bool MapstartTrigger::checkIsTriggered()
     45{
     46    if (this->bInit)
     47    {
     48        this->bInit = false;
     49        return true;
     50    }
     51   
     52    return false;
     53}
  • mover.h

     
     1/*!
     2 * @file mover.h
     3 *  A mover is an object that moves along scripted paths, released by scripted events.
     4 */
     5
     6#ifndef _MOVER_H
     7#define _MOVER_H
     8
     9#include "world_entity.h"
     10#include "mover_trigger.h"
     11#include "mover_station.h"
     12#include "mover_trigger_list.h"
     13#include "mover_station_list.h"
     14#include "sound_source.h"
     15
     16
     17class Mover : public WorldEntity
     18{
     19    ObjectListDeclaration(Mover);
     20
     21    public:
     22        Mover(const TiXmlElement* root = NULL);
     23        virtual ~Mover();
     24
     25        virtual void loadParams(const TiXmlElement* root);
     26        virtual void tick(float dt);
     27
     28        void setLoop(bool bLoop = true) { this->bLoop = bLoop; }
     29        void setRepeat(int n) { this->bRepeat = true; this->repeats = n; }
     30        void setWaitAfterEachStation(bool bWaitAfterEachStation = true) { this->bWaitAfterEachStation = bWaitAfterEachStation; }
     31        void setOnlyMoveWhileTriggered(bool bOnlyMoveWhileTriggered = true) { this->bOnlyMoveWhileTriggered = bOnlyMoveWhileTriggered; }
     32        void setAttachTrigger(bool bAttachTrigger = true) { this->bAttachTrigger = bAttachTrigger; }
     33        void setTriggers(const TiXmlElement* root);
     34        void setStations(const TiXmlElement* root);
     35        void setReopen(bool bReopen = true) { this->bReopen = bReopen; }
     36        void setReclose(bool bReclose = true) { this->bReclose = bReclose; }
     37
     38    private:
     39        void changeState(int state);
     40        int closed();
     41        int open();
     42        int move(float dt);
     43        int wait();
     44        int next();
     45        int delay();
     46        int stay();
     47        bool reachedStationsTarget(float dt);
     48        Quaternion VtoQ(Vector v) { return Quaternion(v.x, v.y, v.z); }
     49        Vector QtoV(Quaternion Q) { return Vector(); }
     50
     51        bool                        bLoop;
     52        bool                        bRepeat;
     53        int                         repeats;
     54        bool                        bWaitAfterEachStation;
     55        bool                        bOnlyMoveWhileTriggered;
     56        bool                        bAttachTrigger;
     57        bool                        bReopen;
     58        bool                        bReclose;
     59       
     60        MoverTriggerList            *triggers;
     61        MoverStationList            *stations;
     62       
     63        int                         state;
     64        MoverStation                *station;
     65        float                       time;
     66        int                         repeatsToGo;
     67        Vector                      originCoor;
     68        Vector                      originDir;
     69
     70        OrxSound::SoundSource       soundSource_starting;
     71        OrxSound::SoundSource       soundSource_moving;
     72        OrxSound::SoundSource       soundSource_ending;
     73};
     74
     75
     76#endif
  • mover_trigger_approach.h

     
     1/*!
     2 * @file mover_trigger_approach.h
     3 *  Gets triggered when a player enters a radius or a box.
     4 */
     5
     6#ifndef _MOVER_TRIGGER_APPROACH_H
     7#define _MOVER_TRIGGER_APPROACH_H
     8
     9#include "mover_trigger.h"
     10
     11
     12class ApproachTrigger : public MoverTrigger
     13{
     14    ObjectListDeclaration(ApproachTrigger);
     15
     16    public:
     17        ApproachTrigger(const TiXmlElement* root = NULL);
     18        virtual void loadParams(const TiXmlElement* root);
     19        void setRadius(float radius) { this->radius = radius; }
     20        void setDistance(float x, float y, float z) { this->distanceX = x; this->distanceY = y; this->distanceZ = z; }
     21        void setOnlyHumans(bool onlyHumans = true) { this->onlyHumans = onlyHumans; }
     22        void setOnlyNPCs(bool onlyNPCs = true) { this->onlyNPCs = onlyNPCs; }
     23
     24    private:
     25        virtual bool checkIsTriggered();
     26        float radius;
     27        float distanceX;
     28        float distanceY;
     29        float distanceZ;
     30        bool onlyHumans;
     31        bool onlyNPCs;
     32};
     33
     34
     35#endif
     36
Note: See TracBrowser for help on using the repository browser.