	integer, character varying, text, integer, integer, integer, integer, integer, integer
	/*ARGUMENTS*/
	/*user_id,char_name,char_infos,charIdMum,charIdDad,char_strength,char_const,char_dext,char_psy*/

/*identifiant du mimichant*/
DECLARE charId INTEGER;

/*Parent*/
DECLARE charIdMum ALIAS FOR $4;
DECLARE charPosMum POINT;
DECLARE charIdDad ALIAS FOR $5;

/*Couleur et graphisme des parents*/
DECLARE ColorMum character varying(6);
DECLARE HeadMum INT;
DECLARE EarsMum INT;
DECLARE CorpsMum INT;
DECLARE TailMum INT;

DECLARE ColorDad character varying(6);
DECLARE HeadDad INT;
DECLARE EarsDad INT;
DECLARE CorpsDad INT;
DECLARE TailDad INT;


/*aleatoire*/
DECLARE alea INT;
DECLARE pv INT;
DECLARE pa INT;
DECLARE papm INT;
DECLARE equipmax INT;
DECLARE sexe INT;

BEGIN

/*CARACTERISTIQUE COMMUNE*/
charId:=nextval('public.characters_char_id_seq'::text);
SELECT random(30,80) INTO pv;
SELECT random(50,100) INTO pa;
SELECT random(1,10) INTO papm;
SELECT random(10,30) INTO equipmax;

/*position de la mere=position de oeuf*/
SELECT char_pos from characters WHERE char_id=charIdMum INTO charPosMum;
INSERT INTO characters(char_id,user_id,char_name,char_infos,char_sex,char_money,char_pv,char_pa,char_papm,char_equipmax,char_pvmax,char_skincolor,char_head,char_ears,char_corps,char_tail,char_strength,char_const,char_dext,char_psy,char_pos)
VALUES(charId,$1,$2,$3,NULL,200,pv,pa,papm,equipmax,pv,NULL,NULL,NULL,NULL,NULL,$4,$5,$6,$7,charPosMum);

		/*Couleur et graphisme des parents*/
		SELECT char_skincolor from characters WHERE char_id=charIdMum INTO ColorMum;
		SELECT char_skincolor from characters WHERE char_id=charIdDad INTO ColorDad;
		SELECT char_head from characters WHERE char_id=charIdMum INTO HeadMum;
		SELECT char_head from characters WHERE char_id=charIdDad INTO HeadDad;
		SELECT char_ears from characters WHERE char_id=charIdMum INTO EarsMum;
		SELECT char_ears from characters WHERE char_id=charIdDad INTO EarsDad;
		SELECT char_corps from characters WHERE char_id=charIdMum INTO CorpsMum;
		SELECT char_corps from characters WHERE char_id=charIdDad INTO CorpsDad;
		SELECT char_tail from characters WHERE char_id=charIdMum INTO TailMum;
		SELECT char_tail from characters WHERE char_id=charIdDad INTO TailDad;
		
		/*sexe*/
		SELECT random(0,1) INTO sexe;
		IF(sexe=0)THEN UPDATE characters SET char_sex=FALSE WHERE char_id=charId;
		ELSE UPDATE characters SET char_sex=TRUE WHERE char_id=charId;
			
		/*Couleur et graphisme de enfant*/
		/*Couleur*/
		SELECT random(0,1) INTO alea;
		IF(alea=0)THEN UPDATE characters SET char_skincolor=ColorMum WHERE char_id=charId;
		ELSE UPDATE characters SET char_skincolor=ColorDad WHERE char_id=charId;
		END IF;
		
		/*Tete*/
		SELECT random(0,1) INTO alea;
		IF(alea=0)THEN UPDATE characters SET char_head=HeadMum WHERE char_id=charId;
		ELSE UPDATE characters SET char_head=HeadDad WHERE char_id=charId;
		END IF;
		
		/*Oreilles*/
		SELECT random(0,1) INTO alea;
		IF(alea=0)THEN UPDATE characters SET char_ears=EarsMum WHERE char_id=charId;
		ELSE UPDATE characters SET char_ears=EarsDad WHERE char_id=charId;
		END IF;
		
		/*Corps*/
		SELECT random(0,1) INTO alea;
		IF(alea=0)THEN UPDATE characters SET char_corps=CorpsMum WHERE char_id=charId;
		ELSE UPDATE characters SET char_corps=CorpsDad WHERE char_id=charId;
		END IF;
		
		/*Queue*/
		SELECT random(0,1) INTO alea;
		IF(alea=0)THEN UPDATE characters SET char_tail=TailMum WHERE char_id=charId;
		ELSE UPDATE characters SET char_tail=TailDad WHERE char_id=charId;
		END IF;
	END IF;
RETURN TRUE;
END ;
