Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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


Ignore:
Timestamp:
Jun 26, 2006, 4:46:25 PM (18 years ago)
Author:
patrick
Message:

merged the network branche back to trunk

Location:
trunk/src/world_entities
Files:
4 edited

Legend:

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

    r8783 r8802  
    3030#include "generic_npc.h"
    3131
     32#include "animation/animation3d.h"
     33
    3234using namespace std;
    3335
     
    5557 */
    5658GenericNPC::~GenericNPC ()
    57 {}
     59{
     60  if( this->currentAnim != NULL)
     61    delete this->currentAnim;
     62}
    5863
    5964
     
    138143float GenericNPC::walkTo(float x, float y, float z, float qu, float qx, float qy, float qz)
    139144{
    140 
    141   return true;
     145  Vector destCoor = Vector(x, y, z);
     146  Quaternion destDir = Quaternion(Vector(qx, qy, qz), qu);
     147
     148  // check if this is the current goal
     149  if( this->destCoor != destCoor && this->destDir != destDir)
     150  {
     151    this->destCoor = Vector(x, y, 0.0f);
     152    this->destDir = Quaternion(Vector(qx, qy, qz), qu);
     153
     154    float time = 5.0f;
     155
     156    if( this->currentAnim != NULL)
     157      delete this->currentAnim;
     158
     159    this->currentAnim = new Animation3D(this);
     160    this->currentAnim->addKeyFrame(this->getAbsCoor(), this->getAbsDir(), 0.0f);
     161    this->currentAnim->addKeyFrame(this->destCoor, this->destDir, time);
     162  }
     163
     164  // calculate the distance
     165  Vector distance = this->getAbsCoor() - this->destCoor;
     166  return distance.len();
     167}
     168
     169
     170
     171/**
     172 * walk to a specific place with direction
     173 *
     174 * @param x: x coordinate to go to
     175 * @param y: y coordinate to go to
     176 * @param qu: angle to rotate
     177 * @param qx: x coordinate of rotation vector
     178 * @param qy: y coordinate of rotation vector
     179 * @param qz: z coordinate of rotation vector
     180 *
     181 */
     182float GenericNPC::walkTo(float x, float y, float qu, float qx, float qy, float qz)
     183{
     184  return this->walkTo(x, y, 0.0f, qu, qx, qy, qz);
    142185}
    143186
  • trunk/src/world_entities/npcs/generic_npc.h

    r8796 r8802  
    2222
    2323class TiXmlElement;
     24class Animation3D;
    2425
    2526
     
    7172   Vector                                  destCoor;
    7273   Quaternion                              destDir;
     74
     75   Animation3D*                            currentAnim;
    7376};
    7477
  • trunk/src/world_entities/spawning_point.cc

    r8068 r8802  
    2424#include "compiler.h"
    2525
    26 #include <map>
     26#include "state.h"
     27#include "game_rules.h"
    2728
    2829
     
    5960{
    6061  this->setClassID(CL_SPAWNING_POINT, "SpawningPoint");
     62 
     63  this->teamId = -1;
    6164}
    6265
     
    8184  LoadParam(root, "delay", this, SpawningPoint, setSpawningDelay)
    8285      .describe("sets the delay of the spawning point");
     86     
     87  /* load teamId */
     88  LoadParam(root, "teamId", this, SpawningPoint, setTeamId)
     89      .describe("sets teamId");
    8390
    8491
     
    101108void SpawningPoint::pushEntity(WorldEntity* entity, float delay)
    102109{
    103   this->queue[entity] = this->localTimer + delay;
     110  QueueEntry qe;
     111  qe.entity = entity;
     112  qe.list = entity->getOMListNumber();
     113  qe.respawnTime = this->localTimer + delay;
     114 
     115  queue.push_back( qe );
    104116}
    105117
     
    113125
    114126
    115   //BaseObject* spawningEntity = Factory::fabricate(this->classID);
    116   //   if( likely(this->world != NULL))
    117   //     this->world->spawn(dynamic_cast<WorldEntity*>(spawningEntity));
     127  entity->setAbsCoor( this->getAbsCoor() );
     128  entity->setAbsDir( this->getAbsDir() );
     129 
     130  //TODO set camera (not smooth)
    118131}
    119132
     
    129142  this->localTimer += dt;
    130143
    131   std::map<WorldEntity*, float>::iterator it = this->queue.begin();
    132   for( ; it != this->queue.end(); it++)
     144  std::list<QueueEntry>::iterator it = this->queue.begin();
     145  for( ; it != this->queue.end(); )
    133146  {
    134     //
    135     if( it->second <= this->localTimer)
     147   
     148    if( it->respawnTime <= this->localTimer)
    136149    {
    137150      //spawn the player
    138       this->spawn(it->first);
     151      this->spawn(it->entity);
     152     
     153      it->entity->toList( it->list );
     154     
     155      if ( State::getGameRules() )
     156      {
     157        (State::getGameRules())->registerSpawn( it->entity );
     158      }
     159     
     160      std::list<QueueEntry>::iterator delit = it;
     161      it++;
     162     
     163      queue.erase( delit );
     164     
     165      continue;
    139166    }
     167   
     168    it++;
    140169  }
    141170
  • trunk/src/world_entities/spawning_point.h

    r8068 r8802  
    88#define _SPAWNING_POINT
    99
    10 #include "world_entity.h"
     10#include "playable.h"
    1111
    12 #include <map>
     12#include <list>
    1313
    1414class World;
    1515class TiXmlElement;
    1616
     17struct QueueEntry
     18{
     19  float respawnTime;
     20  WorldEntity * entity;
     21  OM_LIST list;
     22};
    1723
    1824//!< used to indicate what type of objects are spawned by this spawning point
     
    5056    /** sets the spawning point mode @param mode: the mode */
    5157    void SpawningPoint::setSpawningMode(int mode) { this->mode = (SpawningPointMode)mode; }
     58   
     59    inline int getTeamId(){ return this->teamId; }
     60    inline void setTeamId( int teamId ){ this->teamId = teamId; }
    5261
    5362    void pushEntity(WorldEntity* entity, float delay = 0);
     
    7281    float                           localTimer;                     //!< the local timer
    7382    float                           seed;                           //!< the random seed of the position
     83    int                             teamId;                         //!< only spawn players of this team
    7484    ClassID                         classid;                        //!< the classid of the entity to spawn
    7585    SpawningPointMode               mode;                           //!< the mode of the spawning point
    76     std::map<WorldEntity*, float>   queue;                          //!< queue of waiting WorldEntities to be spawned
     86    std::list<QueueEntry>           queue;                          //!< queue of waiting WorldEntities to be spawned
    7787    bool                            bSpawning;                      //!< flag to indicate if this spawning point is active or not
    7888};
Note: See TracChangeset for help on using the changeset viewer.