summaryrefslogtreecommitdiff
path: root/sdl-test/SDL_tuto/TestParserLemmingsLVL/parse_ini.yy
blob: d40a4185208235febc09a78be1ca5adb9b29cb14 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
%{
#include "y.tab.h"

#include "SDL/SDL.h"
#include "SDL/SDL_image.h"
#include "SDL/SDL_rotozoom.h"

#include <sys/types.h>
#include <dirent.h>

#include <stdio.h>
#include <stdlib.h>

	/** time per frame in microseconds - this is the timing everything else is based on */
#define FPS 30
	/** redraw animated level obejcts every 3rd frame (about 100ms) */
#define ANIM_STEP_FPS 3

// test pour agrandir la fenêtre de pixel qui memorise le terrain derrière le lemming pour rafraichir l'écran
// DECALLEM est utilisé ici pour la taille de la fenêtre
#define DECALLEMY 50
#define DECALLEMX 34
// test pour deplacer la fenêtre de pixel qui memorise le terrain derrière le lemming pour rafraichir l'écran
// DECALLEMY est utilisé ici pour effacer le bas du lemming
#define DECALLE_Y 15
// test pour deplacer la fenêtre de pixel qui memorise le terrain derrière le lemming pour rafraichir l'écran
// DECALLEMX est utilisé ici pour effacer le cote gauche du lemming
#define DECALLE_X 1

	// the original formula is: release lemming every 4+(99-speed)/2 time steps
	// where one step is 60ms (3s/50) or 66ms (4s/60).
	// Lemmini runs at 30ms/33ms, so the term has to be multiplied by 2
	// 8+(99-releaseRate) should be correct
	//releaseBase = 8 + (99 - releaseRate);

	extern FILE *yyin;

	const int TIME_WAIT_TRAP_START = 15000; // milliseconde

	const int INTERFACE_HEIGHT = 180;//180;
	//Les attributs de l'écran (640 * 480)
	const int SCREEN_WIDTH = 800;//1280
	const int SCREEN_HEIGHT = 500; // 480 //SCREEN_HEIGHT =  LEVEL_HEIGHT + INTERFACE_HEIGHT + 30;
	const int SCREEN_BPP = 32;

	//MINIMAP
	
#define MINIMAPLEM_X0 420 //636
#define MINIMAPLEM_Y0 45
#define MINIMAPLEM_MX 210 //464
#define MINIMAPLEM_MY 48 //120


#define MINIMAP_X0 420
#define MINIMAP_Y0 5 //325
#define MINIMAP_MX 350
#define MINIMAP_MY 175 //175



	const int INTER_BUTTON_X = 0;
	const int INTER_BUTTON_Y = 50;

	//Les dimensions du niveau
	const int LEVEL_WIDTH = 1664*2;
	const int LEVEL_HEIGHT = 160*2;

	// Decale le tableau d'objet
	//0: lemmfont.gif
	//1: numfont.gif
	//2: countdown.gif
	//3: cursor.gif
	//4: explode.gif
	//5: border.gif
	//6: replay.gif
	//7: select.gif
	//8: font7x10.bmp
	//9: alphabet.gif

	//10: mask_10.gif
	//11: mask_11.gif
	//12: mask_6.gif
	//13: mask_13.gif
	//14: mask_14.gif
	//15: mask_15.gif
	//16: imask_13.gif
	//17: imask_14.gif
	//18: imask_15.gif
#define NBR_ADD_OBJ 19
	//9-21 : icone_XX.gif
#define NBR_BUTTON_LEMMING 13
	const int ADD_OBJ = NBR_ADD_OBJ + NBR_BUTTON_LEMMING;

	//cyan pixel color
	Uint32 ccc_cyan= 0x00ffff;
	//yellow pixel color
	Uint32 ccc_yellow = 0xffff00;
	//Red pixel color
	Uint32 ccc_red= 0xff0000;
	//green pixel color
	Uint32 ccc_green= 0x00ff00;
	// erase surface;
	Uint32 ccc_black= 0x000000;

	// gimp
	Uint32 ccc_gimp = 0xffffff;

	//Blanc cursor
	Uint32 ccc_cursor = 0x000000;
	//Noir colorKeyGif
	Uint32 ccc_keyGif = 0x000000;
	// lemming color
	Uint32 ccc_lemming = 0x001a82;

	// object color
	// terrain
	Uint32 ccc_tRemove = 0x007f00ff; // Violet
	Uint32 ccc_tRemoveNoOverwrite = 0x009932cd; // Lilas
	Uint32 ccc_tFull = 0xff38b0de; // Ciel d'été
	Uint32 ccc_tNoOverwrite = 0xff0000ff; // bleu
	Uint32 ccc_tHidden = 0xff236b8e; // Bleu Acier

	// after conversion
	// destructible => brick	
	Uint32 ccc_tBrick = 0x00edaa;//0x00ed4f; // vert
	// empty => bgStencil
	Uint32 ccc_bgStencil = 0x000000;
	// steel
	// indestructible => steel
	Uint32 ccc_s = 0xff00aa;//0xff00ff;//rose bonbon

	// object
	Uint32 ccc_oPassive = 0x6b8ebb;//0x6b8e23; // Vert olive clair

	Uint32 ccc_oNoDigLeft = 0xff7fbb;//0xff7f00; // Thé
	Uint32 ccc_oNoDigRight = 0xd987bb;//0xd98719; // Ocre

	Uint32 ccc_oTrapDrown = 0x7fffbb;//0x7fff00;// Vert de Hooker
	Uint32 ccc_oTrapAndNoLem = 0x8c17bb;//0x8c1717; // Ecarlate
	Uint32 ccc_oTrapAndLem = 0xa62abb;//0xa62a2a; // Brun

	Uint32 ccc_oExit = 0xd9d9bb;//0xd9d919; // Blond
	Uint32 ccc_oEntry = 0x855ebb;//0x855e42; // Bronze

	Uint32 ccc_oUnknow = 0xffffbb;//0xffffff; // Blanc


	// error
	Uint32 ccc_error = 0x666669;

	// lemming
	Uint32 ccc_lWalk_on = 0xffddcc;

	Uint32 ccc_lStopper = 0xffffcb;

	Uint32 ccc_lStopperLeft = 0xffbbcb;
	Uint32 ccc_lStopperRight = 0xffcccb;




	// Config Cam
	const int CAM_VITESSE = 8;
	const int BOUND_SENSIBILITE = 50;



	//Les surfaces

	SDL_Surface *pTerrain = NULL; //Fond avec juste la map
	SDL_Surface *pSpr_Lem = NULL; // Fond + animations + Lemming
	SDL_Surface *pSprLemBack = NULL; // Fond + animations
	SDL_Surface *screen = NULL; // Ecran via la caméra
	SDL_Surface *pInterface = NULL; // Ecran du bas
	SDL_Surface *pStencil= NULL; // Ecran Stencil
	SDL_Surface *pStencilFixe= NULL; // Ecran Stencil Fixe

	struct list_int {
		int val;
		struct list_int *next;
	};

	struct val {
		int type;
		union ptr_u { char * str; struct list_int *ints;} ptr;
	};

	//DEBUT NEW CONCEPTION

	// DEBUT: MAP_STRUCTURE
#define NBR_STYLE_MAP 11
#define PARTICULE_COUNT 16

	enum eMapStyle {
		brick , bubble , crystal , dirt , fire , marble ,
		pillar , rock , snow , special, undefined 
	};

	char tabString_eMapStyle[NBR_STYLE_MAP][10] = {
		"brick" , "bubble" , "crystal" , "dirt" , "fire" , "marble" ,
		"pillar" , "rock" , "snow" , "special", "undefined" 
	};

	struct colorMap {
		Uint32 bgColor;// background color present in "style".ini
		Uint32 debrisColor;// debris color present in "style".ini
		Uint32* particleColor; //particle color present in "style".ini
	};

	struct spriteObjet {
		// ID == Objet.ID
		int state; // number of state in terraino_XX.gif;

		// animation types
		// 0 - don't animate
		// 1 - animate continously
		// 2 - trap - animate on trigger - else show first pic
		// 3 - entry animation: animate once at level start
		int anim;

		// object types
		// 0  - passive
		// 3  - no digging to the left
		// 4  - no digging to the right
		// 5  - trap which makes lemmings drown (water/quick sand/mud)
		// 6  - trap which replaces lemming with death animation
		// 7  - trap which triggers lemming death animation
		// 8  - exit
		// 32 - entry	 
		int type;

		int sound; // numero of sound
	};	

	struct mapStyle {
		enum eMapStyle style; // map' style
		int superLemming; // off = 0; on = 1;		
		int tiles; // number of terrain_XX.gif present in "style".ini
		int tilesObjet; //number of terraino_XX.gif
		int tilesSteel; // number of terrainom_XX.gif

		struct colorMap cmap; // level's info's color

		struct spriteObjet* tabDataSprO; // sprite'data ; default=NULL;
		SDL_Surface **tabGif; // all gif are stored in; default=NULL;
	};
	// FIN: MAP_STRUCTURE

	// DEBUT: LEMMINGS_STRUCTURE 
	// LEM_JOB == lemm_XX.gif


#define MAX_LEM_FALL 3
#define MAX_LEM_FALL_FLOATER 2
#define FALLER_MAX 126
#define FLOATER_TO_FALLER 32
#define MAX_LEM_FLOATER 2

	/** a jumper moves up two pixels per frame */
#define MAX_JUMPER_STEP 2
	/** if a walker jumps up 6 pixels, it becomes a jumper */
#define MAX_JUMPER_JUMP 4
#define MAX_BUILD_BRICK 9
#define MAX_BUILD_END 3

#define WALKER_OBSTACLE_HEIGHT 14
#define FALLER_STEP 3
#define FLOATER_STEP 2
#define FALL_DISTANCE_FALL 8
#define FALL_DISTANCE_FORCE_FALL  2 * FALL_DISTANCE_FALL
#define FALL_DISTANCE_FLOAT 32
#define JUMPER_STEP 2
#define WALKER_STEP 1
#define CLIMBER_STEP 1
#define BASHER_FALL_DISTANCE 6
#define STEPS_WARNING 9
#define STEPS_MAX 12

#define LEM_JOB 17
	//0:	walker
	//1:	faller
	//2:	climber
	//3:	climber_to_walker
	//4:	floater
	//5:	splat
	//6:	stopper
	//7:	drowning
	//8:	trap_death
	//9:	exIt
	//10:	bomber
	//11:	builder
	//12:	builder_end
	//13:	digger
	//14:	basher
	//15:	miner
	//16:	jumper
#define OTHER_LEM_JOB 6
	//17:	died
	//18:	enter
	//19:	safe
	//20: nuke
	//21: bomber_stopper
	//22: floater_start
#define	TOTAL_LEM_JOB LEM_JOB + OTHER_LEM_JOB


	enum eLemmingJob {
		walker , faller , climber , climber_to_walker , floater , 
		splat , stopper , drowning , trap_death , exIt , bomber,
		builder , builder_end , digger , basher , miner , jumper ,
		died , enter , safe , nuke , bomber_stopper , floater_start
	};

	char tabString_eLemmingJob[TOTAL_LEM_JOB][20] = {
		"walker" , "faller" , "climber" , "climber_to_walker" , "floater" , 
		"splat" , "stopper" , "drowning" , "trap_death" , "exIt" , "bomber",
		"builder" , "builder_end , digger" , "basher" , "miner" , "jumper",
		"died" , "enter" , "safe" , "nuke", "bomber_stopper", "floater_start"
	};

	struct lemmingMask {
		// ID == lemming.ID;
		int stateM; // number of state in mask_XX.gif;
		int dirM; // number of direction
		int cooldown; // after <cooldown> animations of lemming animation, do mask action and increase mask frame idx
	};

	struct lemmingImask {
		// ID == lemming.ID;
		int stateI; // number of state in imask_XX.gif;
		int dirI; // number of direction
	};

	struct lemmingJobAndSprite {
		// ID == lemming.ID;
		int state; // number of state in lemm_XX.gif;
		int dir; // direction of lemming: 0=left(do FlipLR); 1=right; default=1;
		int anim; // animation type: 0=loop, 1=once (state change if finished);

		// foot: director 's foot for collision 's test
		//	calcul the X' symetry if lemming.dir==0(left)
		int footX; // position X of right's lemming's foot;
		int footY; // position Y of right's lemming's foot;
		int footSize; // size of lemming's foot;

		// mask for screen ...
		struct lemmingMask* mask; // mask of this job; default=NULL;
		struct lemmingImask* imask; // imask of this job; default=NULL;
	};
	// FIN: LEMMINGS_STRUCTURE

	// DEBUT: INFOMAP
#define IDENT_COUNT 12

	enum eParaMap { 	
		releaseRate,numLemmings,numToRescue,timeLimit,
		numClimbers,numFloaters,numBombers,numBlockers,numBuilders,
		numBashers,numMiners,numDiggers 
	};

	char tabString_eParaMap[IDENT_COUNT][32] = {
		"releaseRate","numLemmings","numToRescue","timeLimit",
		"numClimbers","numFloaters","numBombers","numBlockers",
		"numBuilders","numBashers","numMiners","numDiggers"
	};

	struct cursor {
	
		int oldX; // positionX du cuseur;default=0
		int oldY; // positionY du cuseur;default=0
		int oldXI; // positionX dans l'interface; default=0;
		int oldYI; // positionY dans l'interface; default=0;
		int sizeC; // dans le cas où le curseur est à cheval entre 2 Surface
		int numScreen; // num ecran; default=0
		int numSwitch;
		SDL_Surface *imgC; // image de l'objet; default=NULL;
	};

	struct infoMap {
		char* name; // map name; default=NULL;
		int paraMap[IDENT_COUNT]; // some parameter of this map
		int xPos; // camera started position
		SDL_Surface *miniMapLem; // image de jeu ; default=NULL;
		int MaxFallDistance; // max pixel lemming fall before died;default=0;
		int nuke; // hiroshima= 1; default =0;
		int nbrEntry; // number of entry in this map; default=0;
		struct cursor cross; // info cursor
		struct mapStyle map; // map
		struct lemmingJobAndSprite *lemmingDATA; // DATA of lemmingJob; default=NULL; 
	};
	// FIN: INFOMAP

	// DEBUT: GAMEINIT
	struct paraTerrain {
		int modif; //modifier: 8=NO_OVERWRITE, 4=UPSIDE_DOWN, 2=REMOVE (combining allowed, 0=FULL);
	};

	struct paraObjet {
		int UD; // upside down (0,1);
		int paintMode;// paint modes: 8=VIS_ON_TERRAIN, 4=NO_OVERWRITE, 0=FULL (only one value possible)
		int cptState; // count number of frame for an animation at once, default=0;
		SDL_Surface *img; // image de l'objet; default=NULL;
	};

	struct paraSteel {
		int w;// weight
		int h;// height
	};

	struct paraLemming {
		int dir; // direction of lemming; default=1;
		int climber; // skill climber; default = 0;
		int blocker; // skill blocker; default = 0;
		int bomber; // skill bomber; default = -1;
		int floater; // skill floater; default = 0;
		int nuke; // nuked or not; default=0;
		int cptFall; // count number of pixel when lemming falling;default = 0;
		int cptFall2;// count number of pixel when lemming falling;default = 0;
		int cptJump; // count number of pixel when lemming jumping;default = 0;
		int cptBrick; // count number of brick ;default = 0;
		int cptBoom; // count number of boom ;default = -1;
		int cptState; // count number of frame for an animation at once, default=0;
		int oldX; //positionX de l'ancien font; default=x; 
		int oldY; //positionY de l'ancien font; default=y; 
		SDL_Surface *imgF; // font de l'image avant d'être écrasée par celle du lemming; default=NULL;
	};

	struct listeSimplementChainee {
		int ID; // ID for tabGif;
		int x; // x position;
		int y; // y position;

		union listeDataType { 
			struct paraTerrain *pt; // other para about terrain; default=NULL;
			struct paraObjet *po; // other para about objet; default=NULL;
			struct paraSteel *ps; // other para about steel; default=NULL;
			struct paraLemming *pl; // other para about lemming; default=NULL;
		} data;

		struct listeSimplementChainee *next;// default=NULL;
	};

	struct terrain {
		int nbr; // number of terrain on this map; default=0;
		struct listeSimplementChainee *lt; // list of terrain; default=NULL;
	};

	struct objet {
		int nbr; // number of objet on this map; default=0;
		struct listeSimplementChainee *lo; // list of objet; default=NULL;
	};

	struct steel {
		int nbr; // number of steel on this map; default=0;
		struct listeSimplementChainee *ls; // list of steel; default=NULL;
	};

	struct lemming {
		int nbrInput; // number of lemming will be create; default=0;
		int nbr; // number of lemming on this map; default=0;
		int nbrDied; // number of lemming Died on this map; default=0;
		int nbrSafe; // number of lemming Saved on this map; default=0;
		struct listeSimplementChainee *ll; // list of lemming; default=NULL;
	};

	// game use some cpt
#define NBR_CPT 20

	struct gameInit {
		struct infoMap mapI; // all DATA of the map;
		struct terrain t; // all DATA of terrain on this map;
		struct objet o; // all DATA of objet on this map;
		struct steel s; // all DATA of steel on this map;
		struct lemming l; // all DATA of lemming on this map;
		int boostFps; // grow up FPS *5; default=0;
		// 0-13 : BUTTON_LEMMING state button 0: off; 1: on;
		// 14 : CURSOR STATE
		// 15 : FREE CPT: for all need it ...; default=0;
		// 16 : NBR_ENTRY OPEN; default=0;
		// 17 : clic on mouse on lemning skill; default=-1;
		// 18 : clic on mouse on lemning;default=0;
		int cptGame[NBR_CPT]; // default=0;
	};
	// FIN: GAMEINIT

	//FIN NEW CONCEPTION

	enum sens { UD , LR };

	extern int yylineno; // Bidouille pour avoir le numero de ligne du lexer ^^

	int yylex();
	void yyerror(struct gameInit *gInit, char *s);

	SDL_Surface *load_image( char* filename, Uint32 cbg );

	//	void apply_surface( int x, int y, SDL_Surface* source, SDL_Surface* destination, SDL_Rect* clip );

	int init();

	SDL_Surface* flipSurfaceUD_LR(SDL_Surface* src, enum sens sensO, Uint32 c);

	int load_fields(char *folder, struct gameInit *gInit, int tabnum[255] );

	int afficher(struct gameInit *gInit);

	int load_files(struct gameInit *gInit);

	int clean_up();

	int anim_objet(int typeS, int typeO, int cptFps, int frames, int *cpt, struct gameInit *gInit);// returne le state de l'oblet a afficher

	Uint32 get_pixel32( int x, int y, SDL_Surface *surface );

	int putPixel(SDL_Surface *surface,Uint16 x,Uint16 y,Uint32 color);

	int checkPixelDOWN(int nbr,  int x, int y );

	int checkPixelUP(int nbr, int x, int y, int size );

	int outOfLowerMap(int y);

	int aboveGround(int x, int y);

	int midY(int y, int size);

	int reachedPlateau(int x, int y, int size, int dir);

	int stencilMid(int x, int y);

	int turnedByStopper(int x, int y, int dir);

	int explode(int x, int y, int size);

	int stateLemming(struct gameInit *gInit);

	int ereasePx(int x,int y,SDL_Surface *s,Uint32 bgColor);
	
	int putBrickPx(int x,int y,SDL_Surface *s,Uint32 bgColor,Uint32 debrisColor);

	struct listeSimplementChainee* rev_listeO (struct listeSimplementChainee* liste);

	int initGame(struct gameInit *gInit);

	int creationLemming(struct gameInit *gInit);

	int paint_terrain (struct gameInit *gInit, int choix);

	int paint_manip(SDL_Surface *spr,SDL_Rect from,SDL_Surface *t,SDL_Rect to,Uint32 ccc_t, Uint32 ccc_spr, int mode, SDL_Surface *stencil);

	int paint_objet (struct gameInit *gInit, int cptFps);
	
	int paint_objet_Init (struct gameInit *gInit);

	int paint_objet_stencil (struct gameInit *gInit, int cptFps);

	int supprLem (struct gameInit *gInit, int cptFps);

	int paint_lemming (struct gameInit *gInit, int cptFps);

	int test_O_UD(int UD);

	Uint32 string_to_Uint32 (char* c, int taille);

	Uint32* tab_of_string_to_Uint32 (char* c, int taille);

	int paint_letters (char* text);

	int findTerrain( struct gameInit *gInit,int x, int y, int x0);

	int paint_cursor(SDL_Surface *dst1, SDL_Surface *src, int x, int y, int x0, struct gameInit *gInit);

	int print_num(SDL_Surface *dst, SDL_Surface *font, int x, int y, int value);

	int print_alpha(SDL_Surface *dst, SDL_Surface *src, int x, int y, char* msg);

	int	paint_bomber(int x,int y,int xMax,SDL_Surface *cooldown,SDL_Surface *dst,int cpt);	

	int testAlpha(SDL_Surface *dst, SDL_Surface *src,SDL_Surface *src2, int x, int y);

	int legende (struct gameInit *gInit);

	int paint_interface(struct gameInit *gInit);

	int giveSkill (struct gameInit *gInit, struct listeSimplementChainee* k, int skill );

	int mouse_action (struct gameInit *gInit, int x, int y, int camX , int camY);

	int lancement();

	int test_blit(SDL_Surface *spr,SDL_Rect* from,SDL_Surface *t,SDL_Rect* to, int choix);

	int test_FillRect( SDL_Surface *t, SDL_Rect *to, Uint32 ccc, int choix);

	int miniMap (SDL_Surface *s, int x0, int y0, float coefX, float coefY);
	
	int miniMapLemming (struct gameInit *gInit);
	
	int restorCursor(struct gameInit *gInit, int choix);

	int paint_stencil=0;

%}

%parse-param { struct gameInit *gInit }

%union {char* str; int num; struct list_int *ints; struct val *val;}

%token LEXERROR
%token STYLE
%token NAME
%token SLEM
%token BGCOLOR
%token DEBRISCOLOR
%token PARTICLECOLOR
%token AFF
%token XC
%token EOL
%token VIR
%token <str> IDENT
%token <str> STR
%token <num> INT

%type <ints> extra_vals
%type <val> val

%start ini 

%%

ini:
| ini decl
| ini EOL

decl: STYLE AFF val {
	int ok=0;
	enum eMapStyle s; // STYLE
	////-DEBUG-printf("Le style\n");
	if ( $3->type != 0 ) { 
		//-DEBUG-printf("ERREUR: Fichier .ini corrompu (style n'est pas de style int)\n");
	} else {
		s=0;
		while(s<NBR_STYLE_MAP){

			if (	(strcmp($3->ptr.str,"undefined")!=0)&&
					(strcmp($3->ptr.str,tabString_eMapStyle[s]) == 0 )	){

				ok=2;
				gInit->mapI.map.style=s;
				break;
			}
			++s;
		}
		if (ok!=2) { 
			// BUG ...
			//-DEBUG-printf("Style [%s] invalide (undefined) !!\n",$3->ptr.str);
			exit(2);
		}
	}
}
| NAME AFF val {
	////-DEBUG-printf("Le name \n");
	gInit->mapI.name=$3->ptr.str; //FIXME
}
| SLEM AFF val {
	int res=99;
	////-DEBUG-printf("Le superlemming \n");
	if(strcmp($3->ptr.str,"true")==0){
		res = 1;
	}
	if(strcmp($3->ptr.str,"false")==0){
		res = 0;
	}
	if(res!=99){
		gInit->mapI.map.superLemming=res;
	} else {
		//-DEBUG-printf("superlemming value invalid: %d %s\n",res,$3->ptr.str);
		exit(1);
	}
}
| BGCOLOR AFF val {
	//-DEBUG-printf("BGCOLOR XC\n");
	gInit->mapI.map.cmap.bgColor = string_to_Uint32($3->ptr.str,6);
}
| DEBRISCOLOR AFF val  {
	//-DEBUG-printf("DEBRISCOLOR XC\n");
	gInit->mapI.map.cmap.debrisColor = string_to_Uint32($3->ptr.str,6);
}
| PARTICLECOLOR AFF val  {
	gInit->mapI.map.cmap.particleColor=tab_of_string_to_Uint32($3->ptr.str,6);	
}
| IDENT AFF val EOL	{
	enum eParaMap t; // parameter of this map
	int i=0,state=0;
	// cette variable sert a derteminer dans quel cas on se trouve

	// lvl*.ini => fichier de conf des d'une map de lemming
	// state==0: aucun token detecter
	// state==1: token para de la map detecter
	// state==2: token xPos detecter
	// state==3: token terrain_ detecter
	// state==4: token object_ detecter
	// state==5: token steel_ detecter

	// style.ini => fichire de conf des objets animes
	// state==6: token frames_ detecter  
	// state==7: token anim_ detecter  
	// state==8: token type_ detecter  	
	// state==9: token sound_ detecter  

	// state==10: token title detecter FIXME

	// lemming.ini => fichier de conf des lemmings
	// state==11: token lemm_ detecter 
	// state==12: token pos_ detecter 
	// state==13: token mask_ detecter 
	// state==14: token imask_ detecter 

	// liste terrain || objet || steel
	struct listeSimplementChainee **listeItem=NULL;

	////-DEBUG-printf("'%s' ^\n ", $1);
	// donne les parametres de la map
	t=0;
	while(t<IDENT_COUNT){
		if (strcmp($1,tabString_eParaMap[t]) == 0 ){
			state=1;
			gInit->mapI.paraMap[t]=$3->ptr.ints->val; 
			break;
		}
		++t;
	}
	if (state!=1){ 

		if (strcmp($1,"xPos") == 0){
			state=2;
			gInit->mapI.xPos=$3->ptr.ints->val;
		}

		if(strncmp($1,"terrain_",8) == 0){
			state=3;
			// init terrain
			if(gInit->t.lt==NULL){
				gInit->t.nbr=0;

			} else {
				gInit->t.nbr+=1;
			}
			listeItem=&gInit->t.lt;
		}

		if(strncmp($1,"object_",7) == 0){
			state=4;
			// init objet
			if(gInit->o.lo==NULL){
				gInit->o.nbr=0;
			} else {
				gInit->o.nbr+=1;
			}
			listeItem=&gInit->o.lo;
		}

		if(strncmp($1,"steel_",6) == 0){
			state=5;
			// init steel
			if(gInit->s.ls==NULL){
				gInit->s.nbr=0;
			} else {
				gInit->o.nbr+=1;
			}
			listeItem=&gInit->s.ls;
		}


		// Sprite Objet
		if(strncmp($1,"frames_",7) == 0){
			state=6;
			// 1ER CAS
			if(gInit->mapI.map.tilesObjet == 0){//-DEBUG-printf("ERREUR: tilesObjet == 0 => exit to prevent a segFault\n");
				exit(4);
			}
			if(gInit->mapI.map.tabDataSprO == NULL){
				gInit->mapI.map.tabDataSprO= malloc((sizeof(struct spriteObjet))*(gInit->mapI.map.tilesObjet));
				gInit->cptGame[15] = -1;
			} 
			gInit->cptGame[15] +=1;
			gInit->mapI.map.tabDataSprO[gInit->cptGame[15]].state=$3->ptr.ints->val;
		}

		if(strncmp($1,"anim_",5) == 0){
			state=7;
			gInit->mapI.map.tabDataSprO[gInit->cptGame[15]].anim=$3->ptr.ints->val;
		}

		if(strncmp($1,"type_",5) == 0){
			state=8;
			gInit->mapI.map.tabDataSprO[gInit->cptGame[15]].type=$3->ptr.ints->val;
		}

		if(strncmp($1,"sound_",6) == 0){
			state=9;
			gInit->mapI.map.tabDataSprO[gInit->cptGame[15]].sound=$3->ptr.ints->val;
		}
		// "style".ini
		if(strncmp($1,"tiles",5) == 0){
			state=10;
			if($3->ptr.ints->val!=gInit->mapI.map.tiles){
				//-DEBUG-printf("BUG: variable parse && nbrFichier are different %d waiting and  %d found\n",$3->ptr.ints->val,gInit->mapI.map.tiles);
				exit(2);
			}
			//gInit->mapI.map.tiles=$3->ptr.ints->val;
		}

		// lemming .ini
		if(strncmp($1,"lemm_",5)==0){
			state=11;
			// PREMIER CAS
			if(gInit->mapI.lemmingDATA == NULL){
				// 1ER CAS
				gInit->mapI.lemmingDATA=malloc((sizeof(struct lemmingJobAndSprite))*LEM_JOB);
				gInit->cptGame[15] = -1;
			} 
			gInit->cptGame[15] +=1;
			gInit->mapI.lemmingDATA[gInit->cptGame[15]].mask=NULL;
			gInit->mapI.lemmingDATA[gInit->cptGame[15]].imask=NULL;
		}

		if(strncmp($1,"pos_",4)==0){
			state=12;
		}

		if(strncmp($1,"mask_",5)==0){
			state=13;
			gInit->mapI.lemmingDATA[gInit->cptGame[15]].mask=malloc(sizeof(struct lemmingMask));
		}

		if(strncmp($1,"imask_",6)==0){
			state=14;
			gInit->mapI.lemmingDATA[gInit->cptGame[15]].imask=malloc(sizeof(struct lemmingImask));
		}

		if((state>2 && state<6)||(state>10 && state<15)){
			struct list_int *curr=$3->ptr.ints;

			struct listeSimplementChainee *k = malloc(sizeof(struct listeSimplementChainee));

			//k->data.pt=NULL;


			//i=0;
			switch(state){
				// 3: terrain
				case 3 : {i=0;k->data.pt=malloc(sizeof(struct paraTerrain));break;}
					 // 4: objet
				case 4 : {
						 i=4;
						 k->data.po=malloc(sizeof(struct paraObjet));
						 k->data.po->cptState=0;
						 break;
					 }
					 // 5 : steel
				case 5 : {i=9;k->ID=0;k->data.ps=malloc(sizeof(struct paraSteel));break;}

				case 11 : {i=13;break;}
				case 12 : {i=16;break;}
				case 13 : {i=19;break;}
				case 14 : {i=22;break;}
					  // en cas de BUG
				default: //-DEBUG-printf("BUG parser: state = %d\n",state);
					  exit(6);
			}
			
			while (curr!=NULL) {
				//	//-DEBUG-printf("%i ", curr->val);
				switch(i) {
					// pour les terrains
					case 0: k->ID=curr->val; break;
					case 3: k->x=curr->val; break;
					case 2: k->y=curr->val; break;
					case 1: {
						k->data.pt->modif=curr->val; 			
						switch(k->data.pt->modif){
							case 0:
							case 2:
							case 4:
							case 6:
							case 8:
							case 10:
							case 12:
							case 14:
							case 15:
							break;
							default: printf("Erreur valeur interdite pour modif Terrain %d\n",k->data.pt->modif);exit (9);
						} 
						break;
					}
						// pour les objets
					case 4: k->ID=curr->val; if(k->ID==1){++gInit->mapI.nbrEntry;} break;
					case 8: k->x=curr->val; break;
					case 7: k->y=curr->val; break;
					case 6: {
						k->data.po->paintMode=curr->val; 						
						switch(k->data.po->paintMode){
								case 0:
								case 2:
								case 4:
								case 8:
								break;
								default: printf("Erreur valeur interdite pour paint Objet %d\n",k->data.po->paintMode);exit (19);
							}
						break;
					}
					case 5: {
						k->data.po->UD = curr->val; 
						if((k->data.po->UD!=0)&&(k->data.po->UD!=1)){
							printf("Erreur valeur interdite pour UD Objet %d\n",k->data.po->UD);
							exit (29);
						} 
						break;
					}
						// pour les steels
					case 9:  k->x=curr->val; break;
					case 12: k->y=curr->val; break;
					case 11: k->data.ps->w = curr->val; break;
					case 10: k->data.ps->h = curr->val; break;
						 // pour les lemmings
						 // lemm_
					case 13: gInit->mapI.lemmingDATA[gInit->cptGame[15]].state=curr->val;break;
					case 15: gInit->mapI.lemmingDATA[gInit->cptGame[15]].dir=curr->val;break;
					case 14: gInit->mapI.lemmingDATA[gInit->cptGame[15]].anim=curr->val;break;
						 // pos_
					case 16: gInit->mapI.lemmingDATA[gInit->cptGame[15]].footX=curr->val;break;
					case 18: gInit->mapI.lemmingDATA[gInit->cptGame[15]].footY=curr->val;break;
					case 17: gInit->mapI.lemmingDATA[gInit->cptGame[15]].footSize=curr->val;break;		
						 // mask_
					case 19: gInit->mapI.lemmingDATA[gInit->cptGame[15]].mask->stateM=curr->val;break;
					case 21: gInit->mapI.lemmingDATA[gInit->cptGame[15]].mask->dirM=curr->val;break;
					case 20: gInit->mapI.lemmingDATA[gInit->cptGame[15]].mask->cooldown=curr->val;break;
						 // imask_
					case 22: gInit->mapI.lemmingDATA[gInit->cptGame[15]].imask->stateI=curr->val;break;
					case 23: gInit->mapI.lemmingDATA[gInit->cptGame[15]].imask->dirI=curr->val;break;
						 // en cas de BUG
					default: //-DEBUG-printf("BUG parser i = %d\n",i);
						 exit(7);
				}
				curr=curr->next;
				++i;
			}
			// fichier lvl*.ini
			if(state>2 && state<6){
				k->next=*listeItem;
				*listeItem=k;
			}
			//free(curr);
		} else {

			if(state == 0) {
				//-DEBUG-printf("BUG: no parse for this token : %s \n",$1);
				exit(8);
			}
		}
	} // FIN ok==0
}

val: INT extra_vals	{	
	     //	//-DEBUG-printf("creation de liste int ... \n");
	     $$=malloc(sizeof(struct val));
	     $$->type=1;
	     $$->ptr.ints=malloc(sizeof(struct list_int));
	     $$->ptr.ints->val=$1;
	     $$->ptr.ints->next=$2;
	     //	//-DEBUG-printf("liste int %d\n",$1);
     }
| STR	{	
	//	//-DEBUG-printf("creation de liste STR ...\n");
	$$=malloc(sizeof(struct val));
	$$->type=0;

	$$->ptr.str=malloc(sizeof(char)*strlen($1)+1);
	strcpy($$->ptr.str, $1);
	//	//-DEBUG-printf("liste STR %s\n",$1);
}
extra_vals:			{ $$=NULL; }
| extra_vals VIR INT	{ //FIXME : =>  VIR INT extra_vals
	$$=malloc(sizeof(struct list_int));
	$$->val=$3;
	$$->next=$1; 
}

%%

void yyerror(struct gameInit *gInit, char *s)
{
	//fprintf(stderr, "Syntax Error : '%s' at l%d,c%d-l%d,c%d\n", s, @$.first_column, @$.last_line, @$.last_column); // Nécessite l'option %locations et un lexer qui va bien
	fprintf(stderr, "(stdin):%i: error: %s\n", yylineno, s);
	exit(9);
}

#include "fonctions_integrees.c"
#include "fonctions_non_integrees.c"


int main (int argc, char **argv)
{	
	int res,i,num,lt;
	char *temp,*temp0;
	long tempsi;
	//Uint32 ctest;
	//int j,k;
	//argc=3;
	//argv[1]="1";
	//argv[2]="72";
	if (argc<2 || argc>3) { 
		fprintf(stderr, "Usage %s [Option] <Filename>\n",argv[0]);
		fprintf(stderr,"\nOption:\n\t- 1: on se place dans le dossier 1_orig\n");
		fprintf(stderr,"\t- 2: on se place dans le dossier 2_ohno\n");
		fprintf(stderr,"\t- 3: on se place dans le dossier 3_test\n");
		fprintf(stderr,"Filename:\n\t- numero du lvl (ex: 1, 4, 13, 65b )\n");
		return(44);
	}
	if (argc==3) {
		i=1;
		num=atoi(argv[2]);
		if (num >= 10) ++i;
		if (num >= 100) ++i;
		if (num >= 1000){
			fprintf(stderr,"Too many lvl (%d > 999)\n",num);
			return(45);
		}
		temp0=malloc(sizeof(char)*(3-i));// => [00] [0] []
		switch(i){ 
			case 1 : temp0 = "00";break;
			case 2 : temp0 = "0";break;
			case 3 : temp0 = "";break;
			default:fprintf(stderr,"BUG: i[=%d] > 3 ERREUR\n",i);return(46);
		}

		lt = (strlen("../../../../trunk/level/1_orig/lvl.ini")+5);// + 4 : 4 chiffres lvl.ini, +1 : string
		temp=malloc(sizeof(char)*lt);
		switch(atoi(argv[1])){
			case 1 : sprintf(temp,"../../../../trunk/level/1_orig/lvl0%s%d.ini",temp0,num);break;
			case 2 : sprintf(temp,"../../../../trunk/level/2_ohno/lvl1%s%d.ini",temp0,num);break;
			case 3 : sprintf(temp,"../../../../trunk/level/3_test/lvl2%s%d.ini",temp0,num);break;
			default:fprintf(stderr,"ERREUR: dossier [%d] inconnu\n",atoi(argv[1]));return(47);
		}
	} else {
		temp=malloc(sizeof(char)*(strlen(argv[1])+1));
		sprintf(temp,"%s",argv[1]);
	}
	yyin=fopen(temp, "r");
	//yyin=fopen("./lvlTest01.ini", "r");
	if (yyin==NULL) { 
		fprintf(stderr,"Filename INVALIDE: %s\n",temp);
		perror("Impossible d'ouvrir le niveau"); return(48); }

		/*
		   for(i=0;i<256;++i){
		   for(j=0;j<256;++j){
		   for(k=0;k<256;++k){
		   ctest = ((i<<16 | j<<8 | k) & 0xffffff);
		//-DEBUG-printf("[i]=%d, R = %X G = %X B = %X\n",
		i, ((ctest>>16) & 0xff), 
		((ctest>>8) & 0xff),
		(ctest & 0xff) );
		}}}*/

		res=lancement();
		tempsi = SDL_GetTicks();
		printf("code retour %d\n",res);
		printf("Duree d'execution: %ld:%ld:%ld \n",tempsi/(1000*3600),(tempsi/(1000*60))%60,(tempsi/1000)%60);
		//fclose(yyin); fait dans lancement

		return res;

}