Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 10487 in orxonox.OLD for trunk/src/world_entities/npcs/mover.cc


Ignore:
Timestamp:
Jan 29, 2007, 11:51:25 PM (17 years ago)
Author:
patrick
Message:

patches from x3n

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/world_entities/npcs/mover.cc

    r10423 r10487  
    1313   co-programmer:
    1414*/
     15
     16#include "sound/resource_sound_buffer.h"
    1517#include "util/loading/load_param.h"
    1618#include "util/loading/factory.h"
     
    2830Mover::Mover(const TiXmlElement* root)
    2931{
    30   this->registerObject(this, Mover::_objectList);
    31   this->toList(OM_GROUP_00);
    32  
    33   this->targetCoordinates = Vector(0, 0, 0);
    34   this->originCoordinates = Vector(0, 87, -256);
    35   this->actionRadius = 40.0;
    36   this->actionTime = 1.0;
    37 
    38   if (root != NULL)
    39     this->loadParams(root);
    40 
    41   this->updateNode(0.001);
    42   this->originCoordinates = this->getAbsCoor();
    43   this->state = Closed;
     32    this->registerObject(this, Mover::_objectList);
     33    this->toList(OM_COMMON);
     34
     35    this->targetCoordinates = Vector(0, 0, 0);
     36    this->originCoordinates = Vector(0, 87, -256);
     37    this->actionRadius = 40.0;
     38    this->actionTime = 1.0;
     39
     40    if (root != NULL)
     41        this->loadParams(root);
     42
     43    this->updateNode(0.001);
     44    this->originCoordinates = this->getAbsCoor();
     45    this->state = Closed;
     46
     47    this->soundSource_starting.setSourceNode(this);
     48    this->soundSource_moving.setSourceNode(this);
     49    this->soundSource_ending.setSourceNode(this);
     50
     51//    this->soundSource_starting.setRolloffFactor(0.0);
     52//    this->soundSource_moving.setRolloffFactor(0.0);
     53//    this->soundSource_ending.setRolloffFactor(0.0);
    4454}
    4555
    4656Mover::~Mover()
    4757{
     58    if (this->soundSource_starting.isPlaying())
     59        this->soundSource_starting.stop();
     60    if (this->soundSource_moving.isPlaying())
     61        this->soundSource_moving.stop();
     62    if (this->soundSource_ending.isPlaying())
     63        this->soundSource_ending.stop();
    4864}
    4965
     
    5470void Mover::loadParams(const TiXmlElement* root)
    5571{
    56   WorldEntity::loadParams(root);
    57 
    58   LoadParam(root, "rel-target-coor", this, Mover, setTargetCoordinates)
    59       .describe("sets the relative target coordinates of the door");
    60   LoadParam(root, "action-radius", this, Mover, setActionRadius)
    61       .describe("sets the action radius of the door")
    62       .defaultValues(40.0);
    63   LoadParam(root, "action-time", this, Mover, setActionTime)
    64       .describe("sets the action time of the door")
    65       .defaultValues(1.0);
     72    WorldEntity::loadParams(root);
     73
     74    LoadParam(root, "rel-target-coor", this, Mover, setTargetCoordinates)
     75        .describe("sets the relative target coordinates of the door");
     76    LoadParam(root, "action-radius", this, Mover, setActionRadius)
     77        .describe("sets the action radius of the door")
     78        .defaultValues(40.0);
     79    LoadParam(root, "action-time", this, Mover, setActionTime)
     80        .describe("sets the action time of the door")
     81        .defaultValues(1.0);
     82    LoadParam(root, "opening-sound", this, Mover, setOpeningSoundFile)
     83        .describe("Sets the file of the opening sound source");
     84    LoadParam(root, "opened-sound", this, Mover, setOpenedSoundFile)
     85        .describe("Sets the file of the opened sound source");
     86    LoadParam(root, "moving-sound", this, Mover, setMovingSoundFile)
     87        .describe("Sets the file of the moving sound source");
     88    LoadParam(root, "closing-sound", this, Mover, setClosingSoundFile)
     89        .describe("Sets the file of the closing sound source");
     90    LoadParam(root, "closed-sound", this, Mover, setClosedSoundFile)
     91        .describe("Sets the file of the closed sound source");
     92}
     93
     94void Mover::setOpeningSoundFile(const std::string& fileName)
     95{
     96    this->soundBuffer_opening = OrxSound::ResourceSoundBuffer(fileName);
     97}
     98
     99void Mover::setOpenedSoundFile(const std::string& fileName)
     100{
     101    this->soundBuffer_opened = OrxSound::ResourceSoundBuffer(fileName);
     102}
     103
     104void Mover::setMovingSoundFile(const std::string& fileName)
     105{
     106    this->soundBuffer_moving = OrxSound::ResourceSoundBuffer(fileName);
     107}
     108
     109void Mover::setClosingSoundFile(const std::string& fileName)
     110{
     111    this->soundBuffer_closing = OrxSound::ResourceSoundBuffer(fileName);
     112}
     113
     114void Mover::setClosedSoundFile(const std::string& fileName)
     115{
     116    this->soundBuffer_closed = OrxSound::ResourceSoundBuffer(fileName);
    66117}
    67118
     
    76127        {
    77128            this->state = Opening;
     129            if (this->soundBuffer_opening.loaded())
     130                this->soundSource_starting.play(this->soundBuffer_opening);
     131            if (this->soundBuffer_moving.loaded())
     132                this->soundSource_moving.play(this->soundBuffer_moving, 1.0, true);
    78133        }
    79134    }
     
    84139            this->state = Open;
    85140            this->setAbsCoor(this->originCoordinates + this->targetCoordinates);
     141            if (this->soundBuffer_opened.loaded())
     142                this->soundSource_ending.play(this->soundBuffer_opened);
     143            if (this->soundBuffer_moving.loaded())
     144                this->soundSource_moving.stop();
    86145        }
    87146    }
     
    91150        {
    92151            this->state = Closing;
     152            if (this->soundBuffer_closing.loaded())
     153                this->soundSource_starting.play(this->soundBuffer_closing);
     154            if (this->soundBuffer_moving.loaded())
     155                this->soundSource_moving.play(this->soundBuffer_moving, 1.0, true);
    93156        }
    94157    }
     
    99162            this->state = Closed;
    100163            this->setAbsCoor(this->originCoordinates);
     164            if (this->soundBuffer_closed.loaded())
     165                this->soundSource_ending.play(this->soundBuffer_closed);
     166            if (this->soundBuffer_moving.loaded())
     167                this->soundSource_moving.stop();
    101168        }
    102169        if (this->checkPlayerInActionRadius())
     
    145212bool Mover::checkPlayerInActionRadius()
    146213{
    147 
    148   WorldEntity* entity;
    149   Vector vDistance;
    150   float powerDistance;
    151 
    152   for (ObjectList<Playable>::const_iterator it = Playable::objectList().begin();
    153        it != Playable::objectList().end();
    154        ++it)
    155   // for all players
    156   {
    157     entity = (*it);
    158 
    159     vDistance = this->originCoordinates - entity->getAbsCoor();
    160     powerDistance = vDistance.x * vDistance.x + vDistance.z * vDistance.z;
    161 
    162     if( powerDistance < (this->actionRadius * this->actionRadius))
    163       return true;
    164   }
    165 
    166 
    167 
    168   for (ObjectList<GenericNPC>::const_iterator it = GenericNPC::objectList().begin();
    169        it != GenericNPC::objectList().end();
    170        ++it)
    171   {
    172     entity = (*it);
    173 
    174     vDistance = this->originCoordinates - entity->getAbsCoor();
    175     powerDistance = vDistance.x * vDistance.x + vDistance.z * vDistance.z;
    176 
    177     if( powerDistance < (this->actionRadius * this->actionRadius))
    178       return true;
    179   }
    180 
    181   return false;
    182 }
     214    WorldEntity* entity;
     215    float distance;
     216
     217    for (ObjectList<Playable>::const_iterator it = Playable::objectList().begin();
     218        it != Playable::objectList().end();
     219        ++it)
     220    // for all players
     221    {
     222        entity = (*it);
     223        distance = (this->originCoordinates - entity->getAbsCoor()).len();
     224        if (distance < this->actionRadius)
     225        {
     226            this->soundSource_starting.setSourceNode(entity);   // bad hack!
     227            this->soundSource_moving.setSourceNode(entity);     // TODO: make the sound louder without
     228            this->soundSource_ending.setSourceNode(entity);     // attaching him to the player
     229            return true;
     230        }
     231    }
     232
     233    for (ObjectList<GenericNPC>::const_iterator it = GenericNPC::objectList().begin();
     234        it != GenericNPC::objectList().end();
     235        ++it)
     236    {
     237        entity = (*it);
     238        distance = (this->originCoordinates - entity->getAbsCoor()).len();
     239        if (distance < this->actionRadius)
     240            return true;
     241    }
     242
     243    return false;
     244}
Note: See TracChangeset for help on using the changeset viewer.