Changeset 9008 in orxonox.OLD for trunk/src/world_entities/spawning_point.cc
- Timestamp:
- Jul 2, 2006, 2:22:19 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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
Note: See TracChangeset
for help on using the changeset viewer.