void PlayerInterface::setAlliance( const PlayerID& by_player, const PlayerID& with_player )
{
    assert( (by_player.getIndex() < max_players) && (with_player.getIndex() < max_players) );

    *(alliance_matrix + (with_player.getIndex() * max_players) + by_player.getIndex() ) = true;
    //*(alliance_matrix + (by_player.getIndex() * max_players) + with_player.getIndex() ) = true;
}
void PlayerInterface::setKill( const PlayerID &by_player, const PlayerID &on_player, unsigned short unit_type )
{
    assert( (by_player.getIndex() < max_players) && (on_player.getIndex() < max_players) );

    player_lists[ by_player.getIndex() ].incKills( unit_type );
    player_lists[ on_player.getIndex() ].incLosses( unit_type );
}
bool PlayerInterface::isAllied( const PlayerID& player, const PlayerID& with_player )
{
    bool val;

    assert( (player.getIndex() < max_players) && (with_player.getIndex() < max_players) );

    val = *(alliance_matrix + (with_player.getIndex() * max_players) + player.getIndex() );

    return( val );

}
void PlayerInterface::disconnectPlayerCleanup( PlayerID &player_id )
{
    PlayerAllianceUpdate allie_update;

    unsigned short player_index;
    unsigned short disconnect_player_index;

    disconnect_player_index = player_id.getIndex();

    for ( player_index = 0; player_index < max_players; player_index++ ) {
        if ( isAllied( disconnect_player_index, player_index ) == true ) {
            allie_update.set( disconnect_player_index, player_index, _player_break_alliance );
            SERVER->sendMessage( &allie_update, sizeof( PlayerAllianceUpdate ), 0 );
        }

        if ( isAllied( player_index, disconnect_player_index ) == true ) {
            allie_update.set( player_index, disconnect_player_index, _player_break_alliance );
            SERVER->sendMessage( &allie_update, sizeof( PlayerAllianceUpdate ), 0 );
        }

    } // ** for

    player_lists[ disconnect_player_index ].setStatus( _player_state_free );

    PlayerState *player_state = getPlayerState( player_id );

    PlayerStateSync player_state_update(player_state->getNetworkPlayerState());

    SERVER->sendMessage( &player_state_update, sizeof( PlayerStateSync ), 0 );
}
void PlayerInterface::startPlayerStateSync( const PlayerID &connect_player  )
{
    player_sync_index = 0;
    player_sync_connect_player_index = connect_player.getIndex();
    player_sync_connect_id = connect_player;
    player_sync_timer.changeRate( 4 );
    message_encoder.resetEncoder();
}
void PlayerInterface::spawnPlayer( const PlayerID &player, const iXY &location )
{
    unsigned short player_index;

    player_index = player.getIndex();
    assert( player_index < max_players );

    if ( player_lists[ player_index ].getStatus() != _player_state_free ) {
        UnitInterface::spawnPlayerUnits( location,
                                         player,
                                         player_lists[ player_index ].unit_config
                                       );
    } // ** if _player_state_active
}
bool ServerConnectDaemon::disconnectClient( PlayerID player_id )
{
    SERVER->shutdownClientTransport(player_id.getNetworkID());

    SERVER->removeClientFromSendList(player_id);
    ObjectiveInterface::disownPlayerObjectives(player_id.getIndex());
    UnitInterface::destroyPlayerUnits(player_id.getIndex());
    PlayerInterface::disconnectPlayerCleanup( player_id );

	for(std::list<ConnectQueueElement>::iterator i = connect_queue.begin();
			i != connect_queue.end(); /*nothing */) {
		if(i->new_player_id == player_id) {
			i = connect_queue.erase(i);
			continue;
		}

		++i;
	}
	if(connect_player_id == player_id) {
		connection_state = connect_state_idle;
	}

    return true;
}
Ejemplo n.º 8
0
// ******************************************************************
void GameManager::spawnPlayer( const PlayerID &player )
{
    sound->stopTankIdle();

    // ** Get a new spawn point and spawn the player **
    iXY spawn_point = MapInterface::getFreeSpawnPoint();
    PlayerInterface::spawnPlayer( player, spawn_point );

    //** Change the location of the view camera to the spawn point **
    iXY world_loc;
    MapInterface::mapXYtoPointXY( spawn_point, &world_loc );
    if ( PlayerInterface::getLocalPlayerIndex() == player.getIndex() ) {
        WorldViewInterface::setCameraPosition( world_loc );
    } else {
        SystemSetPlayerView set_view(world_loc.x, world_loc.y);
        SERVER->sendMessage(player, &set_view, sizeof(SystemSetPlayerView));
    }

    sound->playTankIdle();
}
bool PlayerInterface::testRulePlayerRespawn( bool *completed, PlayerState **player_state )
{
    PlayerID player;

    if ( respawn_rule_player_index == max_players ) {
        respawn_rule_player_index = 0;
        *completed = true;
        return( false );
    } else {
        *completed = false;
    }
    player = player_lists[ respawn_rule_player_index ].getPlayerID();

    if ( player_lists[ respawn_rule_player_index ].getStatus() == _player_state_active )
        if ( UnitInterface::getUnitCount( player.getIndex() ) == 0 ) {
            *player_state = &player_lists[ respawn_rule_player_index ];
            respawn_rule_player_index++;
            return( true );
        }

    respawn_rule_player_index++;
    return( false );
}