Changeset 9008 in orxonox.OLD for trunk/src/world_entities
- Timestamp:
- Jul 2, 2006, 2:22:19 PM (19 years ago)
- Location:
- trunk/src/world_entities
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/world_entities/playable.cc
r8724 r9008 65 65 66 66 this->bDead = false; 67 67 68 68 this->subscribeReaction(CREngine::CR_PHYSICS_GROUND_WALK, CL_BSP_ENTITY); 69 69 … … 392 392 State::getGameRules()->onPlayerSpawn(); 393 393 394 395 if( this->getOwner() % 2 == 0)396 {397 // this->toList(OM_GROUP_00);398 this->setAbsCoor(213.37, 57.71, -47.98);399 this->setAbsDir(0, 0, 1, 0);400 }401 else402 { // red team403 // this->toList(OM_GROUP_01);404 this->setAbsCoor(-314.450, 40.701, 83.554);405 this->setAbsDir(1.0, -0.015, -0.012, 0.011);406 }407 394 this->reset(); 408 395 this->bDead = false; -
trunk/src/world_entities/space_ships/space_ship.cc
r8708 r9008 220 220 this->burstSystem->setColor(0.5, .5,.5,.8,.8); 221 221 this->burstSystem->setColor(1.0, .8,.8,.8,.0); 222 222 223 223 registerVar( new SynchronizeableVector( &velocity, &velocity, "velocity" ) ); 224 224 registerVar( new SynchronizeableQuaternion( &mouseDir, &mouseDir, "mousedir", PERMISSION_OWNER ) ); … … 384 384 this->shiftCoor(move); 385 385 386 // PRINTF(0)("id of %s is: %i\n", this->getName(), this->getOMListNumber()); 386 387 387 388 } … … 504 505 } 505 506 506 507 508 507 void SpaceShip::destroy( ) 508 { 509 PRINTF(0)("spaceship destroy\n"); 510 } 511 512 void SpaceShip::respawn( ) 513 { 514 toList( OM_PLAYERS ); 515 } 516 517 518 519 -
trunk/src/world_entities/space_ships/space_ship.h
r7954 r9008 36 36 virtual void postSpawn(); 37 37 virtual void leftWorld(); 38 39 virtual void destroy(); 40 virtual void respawn(); 38 41 39 42 virtual void collidesWith(WorldEntity* entity, const Vector& location); -
trunk/src/world_entities/spawning_point.cc
r8802 r9008 22 22 #include "world_entity.h" 23 23 24 #include "class_list.h" 25 24 26 #include "compiler.h" 25 27 … … 27 29 #include "game_rules.h" 28 30 31 #include "shared_network_data.h" 32 33 CREATE_FACTORY( SpawningPoint, CL_SPAWNING_POINT ); 29 34 30 35 /** 31 36 * constructor 32 37 */ 33 SpawningPoint::SpawningPoint (ClassID classid, const Vector& position) 34 { 35 this->setAbsCoor(position); 36 this->classid = classid; 37 this->mode = SPT_ALL_AT_ONCE; 38 this->delay = 0; 38 SpawningPoint::SpawningPoint( const TiXmlElement * root ) 39 { 40 this->setAbsCoor( 0, 0, 0 ); 39 41 40 42 this->init(); 41 } 42 43 44 /** 45 * standard constructor 46 */ 47 SpawningPoint::SpawningPoint (const Vector& position, ClassID classid, SpawningPointMode mode, float delay) 48 { 49 this->setAbsCoor(position); 50 this->classid = classid; 51 this->mode = mode; 52 this->delay = delay; 53 54 this->init(); 55 } 56 57 43 44 if (root != NULL) 45 this->loadParams(root); 46 } 58 47 59 48 void SpawningPoint::init() 60 49 { 61 50 this->setClassID(CL_SPAWNING_POINT, "SpawningPoint"); 51 PRINTF(0)("Created SpawningPoint\n"); 62 52 63 53 this->teamId = -1; 54 this->localTimer = 0.0f; 55 56 this->toList( OM_DEAD_TICK ); 57 58 MessageManager::getInstance()->registerMessageHandler( MSGID_RESPAWN, respawnMessageHandler, NULL ); 64 59 } 65 60 … … 81 76 WorldEntity::loadParams(root); 82 77 83 /* now load the frequency */84 LoadParam(root, "delay", this, SpawningPoint, setSpawningDelay)85 .describe("sets the delay of the spawning point");86 87 78 /* load teamId */ 88 79 LoadParam(root, "teamId", this, SpawningPoint, setTeamId) 89 80 .describe("sets teamId"); 90 91 92 /* now load the seed */93 // LoadParam(root, "entity", this, SpawningPoint, setSpawningEntity)94 // .describe("sets the spawning entity");95 96 /* now load the seed */97 /* LoadParam(root, "classid", this, SpawningPoint, setSpawningEntity)98 .describe("sets the class id of the entity to spawn")99 .defaultValues(CL_WORLD_ENTITY);*/100 81 } 101 82 … … 106 87 * @param entity WorldEntity to be added 107 88 */ 108 void SpawningPoint::pushEntity( WorldEntity* entity, float delay)89 void SpawningPoint::pushEntity(Playable* entity, float delay) 109 90 { 110 91 QueueEntry qe; 111 92 qe.entity = entity; 112 qe.list = entity->getOMListNumber();113 93 qe.respawnTime = this->localTimer + delay; 114 94 … … 120 100 * spawn the entity 121 101 */ 122 void SpawningPoint::spawn( WorldEntity* entity)123 { 124 PRINTF( 1)("Spawningpoint spawns newEntity (%s)\n", entity->getClassName());102 void SpawningPoint::spawn(Playable* entity) 103 { 104 PRINTF(0)("Spawningpoint spawns Entity (%s)\n", entity->getClassName()); 125 105 126 106 … … 129 109 130 110 //TODO set camera (not smooth) 111 112 if ( State::getGameRules() ) 113 { 114 (State::getGameRules())->registerSpawn( entity ); 115 } 116 117 entity->respawn(); 131 118 } 132 119 … … 141 128 { 142 129 this->localTimer += dt; 143 144 130 std::list<QueueEntry>::iterator it = this->queue.begin(); 145 131 for( ; it != this->queue.end(); ) 146 132 { 147 133 //PRINTF(0)("%f <= %f\n", it->respawnTime, this->localTimer); 148 134 if( it->respawnTime <= this->localTimer) 149 135 { … … 151 137 this->spawn(it->entity); 152 138 153 it->entity->toList( it->list ); 154 155 if ( State::getGameRules() ) 156 { 157 (State::getGameRules())->registerSpawn( it->entity ); 158 } 159 139 if ( SharedNetworkData::getInstance()->isGameServer() ) 140 this->sendRespawnMessage( it->entity->getUniqueID() ); 141 160 142 std::list<QueueEntry>::iterator delit = it; 161 143 it++; … … 179 161 */ 180 162 void SpawningPoint::draw() 181 {} 163 { 164 } 165 166 void SpawningPoint::sendRespawnMessage( int uniqueId ) 167 { 168 byte * buf = new byte[2*INTSIZE]; 169 170 assert( Converter::intToByteArray( this->getUniqueID(), buf, INTSIZE ) == INTSIZE ); 171 assert( Converter::intToByteArray( uniqueId, buf + INTSIZE, INTSIZE ) == INTSIZE ); 172 173 MessageManager::getInstance()->sendMessage( MSGID_RESPAWN, buf, 2*INTSIZE, RT_ALL_NOT_ME, 0, MP_HIGHBANDWIDTH ); 174 } 175 176 bool SpawningPoint::respawnMessageHandler( MessageId messageId, byte * data, int dataLength, void * someData, int userId ) 177 { 178 if ( SharedNetworkData::getInstance()->isGameServer() ) 179 { 180 PRINTF(2)("server received spawn message!\n"); 181 return true; 182 } 183 184 int spUniqueId; 185 int uniqueId; 186 187 if ( dataLength != 2*INTSIZE ) 188 { 189 PRINTF(2)("spawn message has wrong size: %d\n", dataLength ); 190 return true; 191 } 192 193 assert( Converter::byteArrayToInt( data, &spUniqueId ) == INTSIZE ); 194 assert( Converter::byteArrayToInt( data+INTSIZE, &uniqueId ) == INTSIZE ); 195 196 SpawningPoint * sp = NULL; 197 Playable * playable = NULL; 198 199 const std::list<BaseObject*> * list = ClassList::getList( CL_SPAWNING_POINT ); 200 201 if ( list ) 202 { 203 for ( std::list<BaseObject*>::const_iterator it = list->begin(); it != list->end(); it++ ) 204 { 205 if ( dynamic_cast<SpawningPoint*>(*it)->getUniqueID() == uniqueId ) 206 { 207 sp = dynamic_cast<SpawningPoint*>(*it); 208 break; 209 } 210 } 211 } 212 213 if ( !sp ) 214 { 215 PRINTF(2)("could not find spawning point\n"); 216 return false; 217 } 218 219 list = ClassList::getList( CL_PLAYABLE ); 220 221 if ( list ) 222 { 223 for ( std::list<BaseObject*>::const_iterator it = list->begin(); it != list->end(); it++ ) 224 { 225 if ( dynamic_cast<Playable*>(*it)->getUniqueID() == uniqueId ) 226 { 227 playable = dynamic_cast<Playable*>(*it); 228 break; 229 } 230 } 231 } 232 233 if ( !playable ) 234 { 235 PRINTF(2)("could not find playable\n"); 236 return false; 237 } 238 239 sp->spawn( playable ); 240 241 return true; 242 } 243 -
trunk/src/world_entities/spawning_point.h
r8802 r9008 10 10 #include "playable.h" 11 11 12 #include "message_manager.h" 13 12 14 #include <list> 13 15 … … 18 20 { 19 21 float respawnTime; 20 WorldEntity * entity; 21 OM_LIST list; 22 Playable * entity; 22 23 }; 23 24 … … 43 44 44 45 public: 45 SpawningPoint (ClassID classID, const Vector& position = Vector(0.0, 0.0, 0.0)); 46 SpawningPoint (const Vector& position, ClassID classID, SpawningPointMode type, float delay); 46 SpawningPoint(const TiXmlElement* root = NULL); 47 47 virtual ~SpawningPoint (); 48 48 void init(); … … 50 50 virtual void loadParams(const TiXmlElement* root); 51 51 52 /** sets the entity that is going to be spawned by this point @param classID: the id from the class_id.h file */53 void SpawningPoint::setSpawningEntity(ClassID classid) { this->classid = classid; }54 /** sets the frequency with which the point is going to spawn entities (1/sec) @param frequency: the frequency */55 void SpawningPoint::setSpawningDelay(float delay) { this->delay = delay; }56 /** sets the spawning point mode @param mode: the mode */57 void SpawningPoint::setSpawningMode(int mode) { this->mode = (SpawningPointMode)mode; }58 59 52 inline int getTeamId(){ return this->teamId; } 60 53 inline void setTeamId( int teamId ){ this->teamId = teamId; } 61 54 62 void pushEntity( WorldEntity* entity, float delay = 0);55 void pushEntity(Playable* entity, float delay = 0); 63 56 64 57 /** activates the spawning point */ … … 74 67 75 68 private: 76 void spawn(WorldEntity* entity); 69 void spawn(Playable* entity); 70 71 void sendRespawnMessage( int uniqueId ); 72 static bool respawnMessageHandler( MessageId messageId, byte * data, int dataLength, void * someData, int userId ); 77 73 78 74 79 75 private: 80 float delay; //!< the timer that counts down until the next spawn81 76 float localTimer; //!< the local timer 82 float seed; //!< the random seed of the position83 77 int teamId; //!< only spawn players of this team 84 ClassID classid; //!< the classid of the entity to spawn85 SpawningPointMode mode; //!< the mode of the spawning point86 78 std::list<QueueEntry> queue; //!< queue of waiting WorldEntities to be spawned 87 79 bool bSpawning; //!< flag to indicate if this spawning point is active or not -
trunk/src/world_entities/world_entity.cc
r9003 r9008 88 88 modelFileName_handle = registerVarId( new SynchronizeableString( &modelFileName, &modelFileName, "modelFileName" ) ); 89 89 scaling_handle = registerVarId( new SynchronizeableFloat( &scaling, &scaling, "scaling" ) ); 90 list_handle = registerVarId( new SynchronizeableInt( (int*)&objectListNumber, &list_write, "list" ) ); 90 91 } 91 92 … … 733 734 * @param damage damage to be dealt 734 735 */ 735 void WorldEntity::hit(float damage )736 void WorldEntity::hit(float damage, WorldEntity* killer) 736 737 { 737 738 this->decreaseHealth(damage); … … 748 749 749 750 if( State::getGameRules() != NULL) 750 State::getGameRules()->registerKill(Kill( NULL, this));751 State::getGameRules()->registerKill(Kill(killer, this)); 751 752 } 752 753 } … … 832 833 } 833 834 835 if ( std::find( id.begin(), id.end(), list_handle ) != id.end() ) 836 { 837 this->toList( (OM_LIST)list_write ); 838 } 839 834 840 PNode::varChangeHandler( id ); 835 841 } -
trunk/src/world_entities/world_entity.h
r9003 r9008 99 99 void setOnGround(bool flag) { this->bOnGround = flag; } 100 100 101 virtual void hit(float damage); 101 virtual void hit(float damage, WorldEntity* killer); 102 102 103 virtual void destroy(); 103 104 … … 195 196 int modelFileName_handle; //!< handle for syncing var 196 197 198 int list_write; //!< entity's list 199 int list_handle; //!< handle for list changes 200 197 201 CollisionHandle* collisionHandles[CREngine::CR_NUMBER]; //!< the list of the collision reactions 198 202 bool bReactive; //!< true if there is at least one collision reaction subscibed
Note: See TracChangeset
for help on using the changeset viewer.