void Robot01BlockCode::sendLinkTrainMessages(P2PNetworkInterface *sender) {
	if (possibleMotions && !possibleMotions->empty()) {
		Capability *firstCondition = possibleMotions->back()->capa;
		motionVector = firstCondition->getMotionVector(0,1);
		nextMotionVector = firstCondition->getMotionVector(1);
		// si ce n'est pas une queue de train, on propage au suivant
		stringstream info;
		info.str("");
		info << "FirstCondifition :"<< firstCondition->isHead << ":" << firstCondition->isEnd << firstCondition->name;
		scheduler->trace(info.str(),hostBlock->blockId,DARKORANGE);

		PointRel3D pos;
		if (firstCondition->isEnd) {
			pos = *firstCondition->linkPrevPos;
			P2PNetworkInterface *p2p = robotBlock->getP2PNetworkInterfaceByRelPos(
				Cell3DPosition(pos.x,pos.y,pos.z));
			AckTrainMessage *message = new AckTrainMessage(currentTrainGain>0);
			scheduler->schedule(new NetworkInterfaceEnqueueOutgoingEvent(scheduler->now() + COM_DELAY, message,p2p));
			stringstream info;
			info.str("");
			info << "send AckTrainMessage("<< int(currentTrainGain>0) << ") to " << p2p->connectedInterface->hostBlock->blockId;
			scheduler->trace(info.str(),hostBlock->blockId,GREEN);
			trainNext = NULL;
			trainPrevious = currentTrainGain>0?p2p->connectedInterface:NULL;
			robotBlock->setPrevNext(trainPrevious,trainNext);
		} else {
			pos = *firstCondition->linkNextPos;
			P2PNetworkInterface *p2p = robotBlock->getP2PNetworkInterfaceByRelPos(
				Cell3DPosition(pos.x,pos.y,pos.z));
			// si c'est la tête du train on envoie la nouvelle position
			// sinon on transmet celle recue
			TrainMessage *message;
			stringstream info;
			if (sender==NULL) {
				PointRel3D pos;
				pos.x = robotBlock->position[0]+motionVector.x;
				pos.y = robotBlock->position[1]+motionVector.y;
				pos.z = robotBlock->position[2]+motionVector.z;
				info.str("");
				info << "send TrainMessage("<<pos<<",1) to " << p2p->connectedInterface->hostBlock->blockId;
				message = new TrainMessage(pos,1);
			} else {
				message = new TrainMessage(currentTrainGoal,currentTrainGain+2*possibleMotions->back()->gain);
				info.str("");
				info << "send TrainMessage("<<currentTrainGoal<<","<<currentTrainGain+2*possibleMotions->back()->gain<<") to " << p2p->connectedInterface->hostBlock->blockId;
			}
			scheduler->schedule(new NetworkInterfaceEnqueueOutgoingEvent(scheduler->now() + COM_DELAY, message, p2p));
			scheduler->trace(info.str(),hostBlock->blockId,GREEN);

			trainNext = p2p->connectedInterface;
			robotBlock->setPrevNext(trainPrevious,trainNext);
		}
	} else if (sender) {
		AckTrainMessage *message = new AckTrainMessage(false);
		scheduler->schedule(new NetworkInterfaceEnqueueOutgoingEvent(scheduler->now() + COM_DELAY, message,sender));
		stringstream info;
		info.str("");
		info << "send AckTrainMessage(false) to " << sender->connectedInterface->hostBlock->blockId;
		scheduler->trace(info.str(),hostBlock->blockId,GREEN);
		trainNext = NULL;
		trainPrevious = NULL;
		robotBlock->setPrevNext(trainPrevious,trainNext);
	}
}