void UnitInterface::spawnPlayerUnits(const iXY &location,
                                     PlayerID player_id,
                                     const PlayerUnitConfig &unit_config)
{
    iXY next_loc;
    UnitBase *unit;
    unsigned long unit_type_index;
    unsigned long unit_spawn_count;
    unsigned long unit_spawn_index;

    NetMessageEncoder encoder;

    unit_placement_matrix.reset( location );

    for ( unit_type_index = 0; unit_type_index < UnitProfileInterface::getNumUnitTypes(); unit_type_index++ )
    {

        unit_spawn_count = unit_config.getSpawnUnitCount( unit_type_index );
        for ( unit_spawn_index = 0; unit_spawn_index < unit_spawn_count; unit_spawn_index++ )
        {
            unit_placement_matrix.getNextEmptyLoc( &next_loc );
            unit = createUnit(unit_type_index, next_loc, player_id);
            UnitRemoteCreate create_mesg(unit->player->getID(), unit->id,
                    next_loc.x, next_loc.y, unit->unit_state.unit_type);

            if ( !encoder.encodeMessage(&create_mesg, sizeof(create_mesg)) )
            {
                LOGGER.info("UnitInterface encoder full, sending and resetting");
                SERVER->broadcastMessage(encoder.getEncodedMessage(),
                                         encoder.getEncodedLen());
                encoder.resetEncoder();
                encoder.encodeMessage(&create_mesg, sizeof(create_mesg));
            }
        } // ** for unit_spawn_index
    } // ** for unit_type_index

    if ( ! encoder.isEmpty() )
    {
        LOGGER.info("UnitInterface sending remaining");
        SERVER->broadcastMessage(encoder.getEncodedMessage(),
                                 encoder.getEncodedLen());
    }
}
void
ObjectiveInterface::syncObjectives( ClientSocket * client )
{
    NetMessageEncoder encoder;
    ObjectiveSyncMesg msg;

    for ( int i = 0; i < num_objectives; ++i )
    {
        msg.set(i);
        objective_list[i]->getSyncData( msg.sync_data );

        if ( ! encoder.encodeMessage(&msg, sizeof(msg)) )
        {
            client->sendMessage(encoder.getEncodedMessage(),
                                encoder.getEncodedLen());
            encoder.resetEncoder();
            encoder.encodeMessage(&msg, sizeof(msg)); // this time shuold be good
        }
    }

    client->sendMessage(encoder.getEncodedMessage(),
                        encoder.getEncodedLen());
}