MCPcopy Create free account
hub / github.com/Panzerschrek/Chasm-Reverse / SpawnPlayer

Method SpawnPlayer

PanzerChasm/server/map.cpp:237–304  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

235}
236
237EntityId Map::SpawnPlayer( const PlayerPtr& player )
238{
239 PC_ASSERT( player != nullptr );
240
241 const MapData::Monster* target_spawn= nullptr;
242
243 if( game_rules_ == GameRules::SinglePlayer || game_rules_ == GameRules::Cooperative )
244 {
245 // In campagn modes spawn players only on first spawn point.
246 unsigned int min_spawn_number= ~0u;
247
248 for( const MapData::Monster& monster : map_data_->monsters )
249 {
250 if( monster.monster_id == 0u && monster.difficulty_flags < min_spawn_number )
251 {
252 min_spawn_number= monster.difficulty_flags;
253 target_spawn= &monster;
254 }
255 }
256 }
257 else
258 {
259 // In deathmatch spawn players sequentially on all spawns.
260 unsigned int spawn_count= 0u;
261 for( const MapData::Monster& monster : map_data_->monsters )
262 {
263 if( monster.monster_id == 0u )
264 {
265 if( next_spawn_number_ == monster.difficulty_flags )
266 target_spawn= &monster;
267 spawn_count++;
268 }
269 }
270 PC_ASSERT( spawn_count > 0u );
271 if( spawn_count == 0u ) spawn_count= 1u;
272
273 next_spawn_number_= ( next_spawn_number_ + 1u ) % spawn_count;
274 }
275
276 if( target_spawn != nullptr )
277 {
278 player->Teleport(
279 m_Vec3(
280 target_spawn->pos,
281 GetFloorLevel( target_spawn->pos, GameConstants::player_radius ) ),
282 target_spawn->angle );
283 }
284 else
285 player->SetPosition( m_Vec3( 0.0f, 0.0f, 4.0f ) );
286
287 player->SetRandomGenerator( random_generator_ );
288 player->ResetActivatedProcedure();
289
290 const EntityId player_id= GetNextMonsterId();
291
292 players_.emplace( player_id, player );
293 const MonstersContainer::value_type& monster_value=
294 * monsters_.emplace( player_id, player ).first;

Callers 3

LoopMethod · 0.80
ChangeMapMethod · 0.80
operator()Method · 0.80

Calls 5

SetPositionMethod · 0.80
SetRandomGeneratorMethod · 0.80
TeleportMethod · 0.45
BuildStateMessageMethod · 0.45

Tested by

no test coverage detected