-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
executable file
·1521 lines (1484 loc) · 88 KB
/
main.cpp
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
/*
:DV company 2015
Пожалуйста, если читаете это, хотя бы просто подумайте, что Дима молодец, мне это важно...
*/
# ifdef WIN32
# include <windows.h>
# include "header\configurator.h";
# define CONF_FILE ".\\pd_win.conf"
# else
# include "header/configurator.h";
# include <unistd.h>
# include <stdlib.h>
# define CONF_FILE ".\/pd_lin.conf" // Реально не знаю как по другому пути к файлам в Линузе прокладывать...
# endif
# define DEBUG 0
# include <string>
# include <curses.h> // Для управления терминалом
# include <sstream> // Для str()
using namespace std;
/*--- Стандартные переменные ---*/
unsigned int maxX, maxY; // Размер терминала
bool auto_resolution = true;
unsigned int MXC, MYC; // Константное разрешение, берётся при запуске
const char *ver = "2.0";
struct bacterium { // Запись
int half_life /*Период жизни*/, id_clan /*id клана*/, position_dead /*Для памяти о положение смерти брата*/, time_birth /*Время деления*/;
bool predator /*Хищник или травоядное*/, activate/*Статус активации, для ускорения обработки массива */, eat;
bool left_right_action; // Из-за двумерной структуры массива, чтобы одна бактерия не обрабатывалась несеолько раз
};
struct settings {
unsigned int clans_bac; //Кол-во кланов бактерий (0 - рандом)
unsigned int num_zigzas, num_himanurs; // Кол-во кланов бактерий
unsigned int full_lives; // Период жизни бактерий
unsigned int power_of_zigzas, power_of_himanurs; // Кол - во от максимально возможного (%)
unsigned int lives_zigzas, lives_himanurs; // Процент от максимального кол-ва жизней
unsigned int division_zigzas, division_himanurs; // Процент задержки дерения (зависит от общего макс. кол-ва жизней), чем меньше , тем выше вероятность
unsigned int maxXmanual, maxYmanual; // Персональное разрешение
unsigned int extrapolation_level; // Уровень экстра поляции (%)
unsigned int eat_probability/*Вероятность добавлении пищи, 1 к set.eat_probability*/, eat_add /*Задержка добавления еды*/;
unsigned int bac_delay; // Задержка
unsigned int maxXY; // Поле для бактерий
unsigned int add_food_zigzas, add_food_himanurs; // Сколько жизней добавит съеденная точка
unsigned int zigzas_division_barrier, himanurs_division_barrier; // "Барьер" деления, если ниже, то не не будут делиться; Процент от макс. кол-ва жизней
unsigned int how_many_eat_zigzas, how_many_eat_himanurs; // Процент, сколько получит жизней от отъеденного у врага
bool angry_zigzas, angry_himanurs; // Атаковать травоядного/плотоядного или нет
bool full_logic_zigzas, full_logic_himanurs; // Следование за едой, сообщение собрату по клану о своей смерти и тд...
bool extrapolation; // Экстраполяция разрешения, позваляет выбрать разрешение больше, чем размер терминала
bool go_to_eat_himanurs, go_to_eat_zigzas; // Если рядом есть еда, то пойти к ней
};
settings standart_settings(settings set) {
set.clans_bac = 4;
set.num_zigzas = 2;
set.num_himanurs = 2;
set.full_lives = 100;
set.power_of_zigzas = 30; // %
set.power_of_himanurs = 15;
set.lives_zigzas = 85; // %
set.lives_himanurs = 100; // %
set.division_zigzas = 80; // %
set.division_himanurs = 50; // %
set.zigzas_division_barrier = 25; // %
set.himanurs_division_barrier = 25; // %
set.how_many_eat_zigzas = 50; // %
set.how_many_eat_himanurs = 50; // %
set.add_food_zigzas = 25;
set.add_food_himanurs = 40;
set.angry_zigzas = true;
set.angry_himanurs = true;
set.maxXmanual = 10;
set.maxYmanual = 10;
set.extrapolation_level = 100; // %
set.eat_probability = 4;
set.eat_add = 70;
set.bac_delay = 100;
set.full_logic_zigzas = true;
set.full_logic_himanurs = true;
set.extrapolation = false;
set.go_to_eat_himanurs = true;
set.go_to_eat_zigzas = true;
return set;
}
string str(int input) { // Из int в string
stringstream ss;
ss << "";
ss << input;
string str;
ss >> str;
return str;
}
settings load_conf(settings set, bool save_sate) { // Модуль загрузки или записи в конф. файл
if (save_sate) { // Если надо сохранить настройки
if (auto_resolution) configurator(CONF_FILE, "auto_resolution", "1", true); else configurator(CONF_FILE, "auto_resolution", "0", true);
configurator(CONF_FILE, "clans_bac", str(set.clans_bac), true);
configurator(CONF_FILE, "full_lives", str(set.full_lives), true);
configurator(CONF_FILE, "num_zigzas", str(set.num_zigzas), true);
configurator(CONF_FILE, "num_himanurs", str(set.num_himanurs), true);
configurator(CONF_FILE, "power_of_zigzas", str(set.power_of_zigzas), true);
configurator(CONF_FILE, "power_of_himanurs", str(set.power_of_himanurs), true);
configurator(CONF_FILE, "lives_zigzas", str(set.lives_zigzas), true);
configurator(CONF_FILE, "lives_himanurs", str(set.lives_himanurs), true);
configurator(CONF_FILE, "division_zigzas", str(set.division_zigzas), true);
configurator(CONF_FILE, "division_himanurs", str(set.division_himanurs), true);
configurator(CONF_FILE, "zigzas_division_barrier", str(set.zigzas_division_barrier), true);
configurator(CONF_FILE, "himanurs_division_barrier", str(set.himanurs_division_barrier), true);
configurator(CONF_FILE, "how_many_eat_zigzas", str(set.how_many_eat_zigzas), true);
configurator(CONF_FILE, "how_many_eat_himanurs", str(set.how_many_eat_himanurs), true);
configurator(CONF_FILE, "add_food_zigzas", str(set.add_food_zigzas), true);
configurator(CONF_FILE, "add_food_himanurs", str(set.add_food_himanurs), true);
if (set.angry_zigzas) configurator(CONF_FILE, "angry_zigzas", "1", true); else configurator(CONF_FILE, "angry_zigzas", "0", true);
if (set.angry_himanurs) configurator(CONF_FILE, "angry_himanurs", "1", true); else configurator(CONF_FILE, "angry_himanurs", "0", true);
configurator(CONF_FILE, "maxXmanual", str(set.maxXmanual), true);
configurator(CONF_FILE, "maxYmanual", str(set.maxYmanual), true);
configurator(CONF_FILE, "eat_probability", str(set.eat_probability), true);
configurator(CONF_FILE, "eat_add", str(set.eat_add), true);
configurator(CONF_FILE, "bac_delay", str(set.bac_delay), true);
if (set.extrapolation) configurator(CONF_FILE, "extrapolation_resolution", "1", true); else configurator(CONF_FILE, "extrapolation_resolution", "0", true);
configurator(CONF_FILE, "extrapolation_level", str(set.extrapolation_level), true);
if (set.full_logic_zigzas) configurator(CONF_FILE, "enemy_warning_zigzas", "1", true); else configurator(CONF_FILE, "enemy_warning_zigzas", "0", true);
if (set.full_logic_himanurs) configurator(CONF_FILE, "enemy_warning_himanurs", "1", true); else configurator(CONF_FILE, "enemy_warning_himanurs", "0", true);
if (set.go_to_eat_himanurs) configurator(CONF_FILE, "go_to_eat_himanurs", "1", true); else configurator(CONF_FILE, "go_to_eat_himanurs", "0", true);
if (set.go_to_eat_zigzas) configurator(CONF_FILE, "go_to_eat_zigzas", "1", true); else configurator(CONF_FILE, "go_to_eat_zigzas", "0", true);
return set;
}
if (configurator(CONF_FILE, "test", "0", false) == "0x0") { // Проверка, существует ли файл, если нет, то создать
add_to_file(CONF_FILE, "clans_bac = " + str(set.clans_bac));
add_to_file(CONF_FILE, "num_zigzas = " + str(set.num_zigzas));
add_to_file(CONF_FILE, "num_himanurs = " + str(set.num_himanurs));
add_to_file(CONF_FILE, "full_lives = " + str(set.full_lives));
add_to_file(CONF_FILE, "power_of_zigzas = " + str(set.power_of_zigzas));
add_to_file(CONF_FILE, "power_of_himanurs = " + str(set.power_of_himanurs));
add_to_file(CONF_FILE, "lives_zigzas = " + str(set.lives_zigzas));
add_to_file(CONF_FILE, "lives_himanurs = " + str(set.lives_himanurs));
add_to_file(CONF_FILE, "division_zigzas = " + str(set.division_zigzas));
add_to_file(CONF_FILE, "division_himanurs = " + str(set.division_himanurs));
add_to_file(CONF_FILE, "zigzas_division_barrier = " + str(set.zigzas_division_barrier));
add_to_file(CONF_FILE, "himanurs_division_barrier = " + str(set.himanurs_division_barrier));
add_to_file(CONF_FILE, "how_many_eat_zigzas = " + str(set.how_many_eat_zigzas));
add_to_file(CONF_FILE, "how_many_eat_himanurs = " + str(set.how_many_eat_himanurs));
add_to_file(CONF_FILE, "add_food_zigzas = " + str(set.add_food_zigzas));
add_to_file(CONF_FILE, "add_food_himanurs = " + str(set.add_food_himanurs));
if (set.angry_zigzas) add_to_file(CONF_FILE, "angry_zigzas = 1"); else add_to_file(CONF_FILE, "angry_zigzas = 0");
if (set.angry_himanurs) add_to_file(CONF_FILE, "angry_himanurs = 1"); else add_to_file(CONF_FILE, "angry_himanurs = 0");
if (auto_resolution) add_to_file(CONF_FILE, "auto_resolution = 1"); else add_to_file(CONF_FILE, "auto_resolution = 0");
add_to_file(CONF_FILE, "maxXmanual = " + str(set.maxXmanual));
add_to_file(CONF_FILE, "maxYmanual = " + str(set.maxYmanual));
if (set.extrapolation) add_to_file(CONF_FILE, "extrapolation_resolution = 1"); else add_to_file(CONF_FILE, "extrapolation_resolution = 0");
add_to_file(CONF_FILE, "extrapolation_level = " + str(set.extrapolation_level));
add_to_file(CONF_FILE, "eat_probability = " + str(set.eat_probability));
add_to_file(CONF_FILE, "eat_add = " + str(set.eat_add));
add_to_file(CONF_FILE, "bac_delay = " + str(set.bac_delay));
if (set.full_logic_zigzas) add_to_file(CONF_FILE, "enemy_warning_zigzas = 1"); else add_to_file(CONF_FILE, "enemy_warning_zigzas = 0");
if (set.full_logic_himanurs) add_to_file(CONF_FILE, "enemy_warning_himanurs = 1"); else add_to_file(CONF_FILE, "enemy_warning_himanurs = 0");
if (set.go_to_eat_zigzas) add_to_file(CONF_FILE, "go_to_eat_zigzas = 1"); else add_to_file(CONF_FILE, "go_to_eat_zigzas = 0");
if (set.go_to_eat_himanurs) add_to_file(CONF_FILE, "go_to_eat_himanurs = 1"); else add_to_file(CONF_FILE, "go_to_eat_himanurs = 0");
} else { // Если файл существует, то загрузить из него настройки
string temp_conf;
temp_conf = configurator(CONF_FILE, "go_to_eat_zigzas", "0", false);
if (temp_conf == "0") set.go_to_eat_zigzas = false; else set.go_to_eat_zigzas = true;
temp_conf = configurator(CONF_FILE, "go_to_eat_himanurs", "0", false);
if (temp_conf == "0") set.go_to_eat_himanurs = false; else set.go_to_eat_himanurs = true;
temp_conf = configurator(CONF_FILE, "auto_resolution", "0", false);
if (temp_conf == "0") auto_resolution = false; else auto_resolution = true;
temp_conf = configurator(CONF_FILE, "extrapolation_resolution", "0", false);
if (temp_conf == "0") set.extrapolation = false; else set.extrapolation = true;
temp_conf = configurator(CONF_FILE, "angry_zigzas", "0", false);
if (temp_conf == "0") set.angry_zigzas = false; else set.angry_zigzas = true;
temp_conf = configurator(CONF_FILE, "angry_himanurs", "0", false);
if (temp_conf == "0") set.angry_himanurs = false; else set.angry_himanurs = true;
temp_conf = configurator(CONF_FILE, "enemy_warning_zigzas", "0", false);
if (temp_conf == "0") set.full_logic_zigzas = false; else set.full_logic_zigzas = true;
temp_conf = configurator(CONF_FILE, "enemy_warning_himanurs", "0", false);
if (temp_conf == "0") set.full_logic_himanurs = false; else set.full_logic_himanurs = true;
temp_conf = configurator(CONF_FILE, "extrapolation_level", "0", false);
set.extrapolation_level = atoi(temp_conf.c_str());
temp_conf = configurator(CONF_FILE, "clans_bac", "0", false);
set.clans_bac = atoi(temp_conf.c_str());
temp_conf = configurator(CONF_FILE, "num_zigzas", "0", false);
set.num_zigzas = atoi(temp_conf.c_str());
temp_conf = configurator(CONF_FILE, "num_himanurs", "0", false);
set.num_himanurs = atoi(temp_conf.c_str());
temp_conf = configurator(CONF_FILE, "full_lives", "0", false);
set.full_lives = atoi(temp_conf.c_str());
temp_conf = configurator(CONF_FILE, "power_of_zigzas", "0", false);
set.power_of_zigzas = atoi(temp_conf.c_str());
temp_conf = configurator(CONF_FILE, "power_of_himanurs", "0", false);
set.power_of_himanurs = atoi(temp_conf.c_str());
temp_conf = configurator(CONF_FILE, "lives_zigzas", "0", false);
set.lives_zigzas = atoi(temp_conf.c_str());
temp_conf = configurator(CONF_FILE, "lives_himanurs", "0", false);
set.lives_himanurs = atoi(temp_conf.c_str());
temp_conf = configurator(CONF_FILE, "division_zigzas", "0", false);
set.division_zigzas = atoi(temp_conf.c_str());
temp_conf = configurator(CONF_FILE, "division_himanurs", "0", false);
set.division_himanurs = atoi(temp_conf.c_str());
temp_conf = configurator(CONF_FILE, "zigzas_division_barrier", "0", false);
set.zigzas_division_barrier = atoi(temp_conf.c_str());
temp_conf = configurator(CONF_FILE, "himanurs_division_barrier", "0", false);
set.himanurs_division_barrier = atoi(temp_conf.c_str());
temp_conf = configurator(CONF_FILE, "how_many_eat_zigzas", "0", false);
set.how_many_eat_zigzas = atoi(temp_conf.c_str());
temp_conf = configurator(CONF_FILE, "how_many_eat_himanurs", "0", false);
set.how_many_eat_himanurs = atoi(temp_conf.c_str());
temp_conf = configurator(CONF_FILE, "add_food_zigzas", "0", false);
set.add_food_zigzas = atoi(temp_conf.c_str());
temp_conf = configurator(CONF_FILE, "add_food_himanurs", "0", false);
set.add_food_himanurs = atoi(temp_conf.c_str());
temp_conf = configurator(CONF_FILE, "maxXmanual", "0", false);
set.maxXmanual = atoi(temp_conf.c_str());
temp_conf = configurator(CONF_FILE, "maxYmanual", "0", false);
set.maxYmanual = atoi(temp_conf.c_str());
temp_conf = configurator(CONF_FILE, "eat_probability", "0", false);
set.eat_probability = atoi(temp_conf.c_str());
temp_conf = configurator(CONF_FILE, "eat_add", "0", false);
set.eat_add = atoi(temp_conf.c_str());
temp_conf = configurator(CONF_FILE, "bac_delay", "0", false);
set.bac_delay = atoi(temp_conf.c_str());
}
return set;
}
# if (DEBUG == 1)
void debug(int num) {
timeout(-1);
mvprintw(0, 0, "Test %i", num);
getch();
timeout(0);
}
void debug_key() {
timeout(-1);
int deb_key_press;
while (deb_key_press != 27) { // Пока не нажат "ESC"
erase();
printw("Press key, \"ESC\" - for exit");
deb_key_press = getch();
erase();
printw("Key: \"%i\" Char: \"%c\" \n", deb_key_press, (char)deb_key_press);
printw("Press any key...");
getch();
}
}
# endif
int rand_local(int a, int b) { // Пришлось ввести эту функцию т. к. просто рандом глючит
if (a >= b) return b; // Чтобы не зависло, например, если 1 - 0
int rand_num = rand() % (b + 1) + (a - 1);
while ((rand_num < a) || (rand_num > b))
rand_num = rand() % (b + 1) + (a - 1);
return rand_num;
}
settings reslution_set(settings set) {
unsigned int selected = 0, maxXl, maxYl;
char char_auto_res, char_extr;
getmaxyx(stdscr, maxYl, maxXl); // Получение размера терминала
if (set.extrapolation) {
maxXl = MXC + (MXC * set.extrapolation_level / 100);
maxYl = MYC + (MYC * set.extrapolation_level / 100);
}
timeout(-1);
while (true) {
erase();
if (auto_resolution) char_auto_res = 'X'; else char_auto_res = '-';
if (set.extrapolation) char_extr = 'X'; else char_extr = '-';
if (selected == 0) printw(">"); else printw("-");
printw("Auto resolution < %c >\n", char_auto_res);
if (!auto_resolution) {
printw("\nResolution of window: %ix%i\n", maxXl, maxYl);
printw("Resolution now: %ix%i\n\n", set.maxXmanual, set.maxYmanual);
if (selected == 1) printw(">"); else printw("-");
printw("X: < %i >\n", set.maxXmanual);
if (selected == 2) printw(">"); else printw("-");
printw("Y: < %i >\n", set.maxYmanual);
if (selected == 3) printw(">"); else printw("-");
printw("Restore to standart\n\n");
if (selected == 4) printw(">"); else printw("-");
printw("Extrapolation rezolution < %c >\n", char_extr);
if (selected == 5) printw(">"); else printw("-");
if (set.extrapolation) {
printw("Extrapolation level < %i%% >\n", set.extrapolation_level + 100);
if (selected == 6) printw(">"); else printw("-");
printw("Back\n");
} else printw("Back\n");
} else {
if (selected == 1) printw(">"); else printw("-");
printw("Back\n");
}
switch (getch()) {
case KEY_UP: if (selected == 0) {
if (auto_resolution) selected = 1;
else {
if (set.extrapolation) selected = 6;
else selected = 5;
}
} else selected--; break;
case KEY_DOWN: if (auto_resolution) {
if ((selected + 1) > 1) selected = 0;
else selected++;
} else {
if (((selected + 1) > 5) && (!set.extrapolation)) selected = 0;
else if (((selected + 1) > 6) && (set.extrapolation)) selected = 0;
else selected++;
} break;
case KEY_LEFT: switch (selected) {
case 0: if (!auto_resolution) auto_resolution = true;
else auto_resolution = false;
break;
case 1: if (!auto_resolution) {
if (set.maxXmanual <= 10) set.maxXmanual = maxXl;
else set.maxXmanual--;
} break;
case 2: if (set.maxYmanual <= 10) set.maxYmanual = maxYl;
else set.maxYmanual--;
break;
case 4 : if (set.extrapolation) {
set.extrapolation = false;
maxXl = MXC;
maxYl = MYC;
if (set.maxXmanual > MXC) set.maxXmanual = MXC;
if (set.maxYmanual > MYC) set.maxYmanual = MYC;
} else {
maxXl = MXC + (MXC * set.extrapolation_level / 100);
maxYl = MYC + (MYC * set.extrapolation_level / 100);
set.extrapolation = true;
} break;
case 5: if (set.extrapolation) {
if (set.extrapolation_level > 0) set.extrapolation_level--;
else set.extrapolation_level = 100;
maxXl = MXC + (MXC * set.extrapolation_level / 100);
maxYl = MYC + (MYC * set.extrapolation_level / 100);
if (set.maxXmanual > maxXl) set.maxXmanual = maxXl;
if (set.maxYmanual > maxYl) set.maxYmanual = maxYl;
} break;
} break;
case KEY_RIGHT: switch (selected) {
case 0: if (auto_resolution) auto_resolution = false;
else auto_resolution = true;
break;
case 1: if (!auto_resolution) {
if (set.maxXmanual >= maxXl) set.maxXmanual = 10;
else set.maxXmanual++;
} break;
case 2: if (set.maxYmanual >= maxYl) set.maxYmanual = 10;
else set.maxYmanual++;
break;
case 4 : if (set.extrapolation) {
set.extrapolation = false;
maxXl = MXC;
maxYl = MYC;
if (set.maxXmanual > MXC) set.maxXmanual = MXC;
if (set.maxYmanual > MYC) set.maxYmanual = MYC;
} else {
maxXl = MXC + (MXC * set.extrapolation_level / 100);
maxYl = MYC + (MYC * set.extrapolation_level / 100);
set.extrapolation = true;
} break;
case 5: if (set.extrapolation) {
if (set.extrapolation_level < 100) set.extrapolation_level++;
else set.extrapolation_level = 0;
maxXl = MXC + (MXC * set.extrapolation_level / 100);
maxYl = MYC + (MYC * set.extrapolation_level / 100);
if (set.maxXmanual > maxXl) set.maxXmanual = maxXl;
if (set.maxYmanual > maxYl) set.maxYmanual = maxYl;
} break;
} break;
case '\n': if (auto_resolution) {if (selected == 1) return set;}
else {
if ((selected == 5) && (!set.extrapolation)) return set;
if (selected == 6) return set;
}
if (selected == 3) {
set.maxXmanual = maxXl;
set.maxYmanual = maxYl;
}
break;
case 27: return set; break;
}
}
return set;
}
void help (int point) { // Хелпа работает ваще не правильно (или просто не работает) и в ней полно ошибок...
erase();
switch (point) {
case -1: printw("Tab - for information about selected object\nEsc - exit or close\nM - menu (work on simulation)\nP - pause simulation\n"); break;
case 0: printw("How bacteria cause damage to the enemy (%%)\n"); break; // Сколько урона нанесёт бактерия врагу
case 1: printw("Percentage of lives a full life in the early\n"); break;
case 2: printw("The percentage of delays division of the maximum number of lives, the smaller, the higher the likelihood of imminent division\n"); break;
case 3: printw("If the health of the cells will be less, the cell will not divide\n"); break;
case 4: printw("How much food adds lives\n"); break;
case 5: printw("How many of the enemy adds lives\n"); break;
case 6: printw("Will the cell to attack the enemy\n"); break;
case 7: printw("Warning of the enemy\n"); break;
case 8: printw("Number of bacteria in the beginning\n"); break;
case 9: printw("The maximum number of lives at the beginning of\n"); break;
case 10: printw("The rate of bacteria\n"); break;
case 11: printw("Field size for bacteria\n"); break;
case 12: printw("How many strokes to add food\n"); break;
case 13: printw("Chance of add food in the cage is calculated as \"1 / value\"\n"); break;
case 14: printw("Setting behavior of a particular type of bacteria\n"); break;
case 15: printw("Setting behavior of a particular type of bacteria\n"); break;
# ifdef WIN32
case 16: printw("Download all settings from file pd_win.conf\n"); break;
case 17: printw("Save all settings to a file pd_win.conf\n"); break;
# else
case 16: printw("Download all settings from file pd_lin.conf\n"); break;
case 17: printw("Save all settings to a file pd_lin.conf\n"); break;
# endif
default: printw("Not found information for this element!\n"); break;
}
printw("\nPress any key...\n");
getch();
return;
}
int int_number (int value) { // Сколько знаков в числе
int count = 0; // Эта писька вообще где ипользкется!?
if (value == 0) count = 1; // Это вообще надо!???
for (; value > 0; count++) // Писал эту хрень точно не я...
value /= 10; // Да, в коде её нигде нет... Ладно надо предупредить, наверное...
return count; // ВНИМАНИЕ! ОСОБО ВАЖНЫЙ БЛОК! :)
}
#define MAX_POS_BAC_SET 8 // Сколько пунктов в настройках бактерий, для симуляции
settings zigzas_settings(settings set, bool on_simulation, unsigned int x, unsigned int y, int selected_out, int key_press) { // Не-не-не-не, даже под чем-то очень тяжелым я не буду комментить блоки настроек
int selected = 0, key_press_local, prefix = 0;
char char_angry, char_logic;
if (on_simulation) {selected = selected_out; prefix = 1;} // При симуляции не выводится один пункт, поэтому +1
while (true) {
if (!on_simulation) erase();
else attron(COLOR_PAIR(4) | A_BOLD);
if (selected == 0) mvprintw(y, x, ">"); else mvprintw(y, x, "-");
if (on_simulation) mvprintw(y, x + 1, " "); // Для ровного окошка при симуляции
mvprintw(y, x + 1, "Power of zigza's < %i%% > (%i)", set.power_of_zigzas, (set.full_lives * set.power_of_zigzas / 100));
if (selected == 1) mvprintw(y + 1, x, ">"); else mvprintw(y + 1, x, "-");
if (!on_simulation) mvprintw(y + 1, x + 1, "Start lives of zigza's < %i%% > (%i)", set.lives_zigzas, (set.full_lives * set.lives_zigzas / 100));
if (selected == (2 - prefix)) mvprintw(y + 2 - prefix, x, ">"); else mvprintw(y + 2 - prefix, x, "-");
if (on_simulation) mvprintw(y + 2 - prefix, x + 1, " "); // Для ровного окошка при симуляции
mvprintw(y + 2 - prefix, x + 1, "Division of zigza's < %i%% > (%i)", set.division_zigzas, (set.full_lives * set.division_zigzas / 100));
if (selected == (3 - prefix)) mvprintw(y + 3 - prefix, x, ">"); else mvprintw(y + 3 - prefix, x, "-");
if (on_simulation) mvprintw(y + 3 - prefix, x + 1, " "); // Для ровного окошка при симуляции
mvprintw(y + 3 - prefix, x + 1, "Division barrier < %i%% > (%i)", set.zigzas_division_barrier, (set.full_lives * set.zigzas_division_barrier / 100));
if (selected == (4 - prefix)) mvprintw(y + 4 - prefix, x, ">"); else mvprintw(y + 4 - prefix, x, "-");
if (on_simulation) mvprintw(y + 4 - prefix, x + 1, " "); // Для ровного окошка при симуляции
mvprintw(y + 4 - prefix, x + 1, "Calorie food < %i%% > (%i)", set.add_food_zigzas, (set.full_lives * set.add_food_zigzas / 100));
if (selected == (5 - prefix)) mvprintw(y + 5 - prefix, x, ">"); else mvprintw(y + 5 - prefix, x, "-");
if (on_simulation) mvprintw(y + 5 - prefix, x + 1, " "); // Для ровного окошка при симуляции
mvprintw(y + 5 - prefix, x + 1, "Calorie enemy < %i%% > (%i)", set.how_many_eat_zigzas, (set.power_of_zigzas * set.how_many_eat_zigzas / 100));
if (selected == (6 - prefix)) mvprintw(y + 6 - prefix, x, ">"); else mvprintw(y + 6 - prefix, x, "-");
if (on_simulation) mvprintw(y + 6 - prefix, x + 1, " "); // Для ровного окошка при симуляции
if (set.angry_zigzas) char_angry = 'X';
else char_angry = '-';
mvprintw(y + 6 - prefix, x + 1, "Angy < %c >", char_angry);
if (selected == (7 - prefix)) mvprintw(y + 7 - prefix, x, ">"); else mvprintw(y + 7 - prefix, x, "-");
if (on_simulation) mvprintw(y + 7 - prefix, x + 1, " "); // Для ровного окошка при симуляции
if (set.go_to_eat_zigzas) char_logic = 'X';
else char_logic = '-';
mvprintw(y + 7 - prefix, x + 1, "Go to eat < %c >", char_logic);
if (selected == (9 - prefix)) mvprintw(y + 9 - prefix, x, ">"); else mvprintw(y + 9 - prefix, x, "-");
if (set.full_logic_zigzas) char_logic = 'X';
else char_logic = '-';
if (on_simulation) mvprintw(y + 8 - prefix, x + 1, " "); // Для ровного окошка при симуляции
if (selected == 8 - prefix) mvprintw(y + 8 - prefix, x, ">"); else mvprintw(y + 8 - prefix, x, "-");
mvprintw(y + 8 - prefix, x + 1, "Tell friend about enemy < %c >", char_logic);
if (selected == 9 - prefix) mvprintw(y + 9 - prefix, x, ">"); else mvprintw(y + 9 - prefix, x, "-");
if (on_simulation) mvprintw(y + 9 - prefix, x + 1, " "); // Для ровного окошка при симуляции
mvprintw(y + 9 - prefix, x + 1, "Back");
if (on_simulation) attroff(COLOR_PAIR(4) | A_BOLD);
if (!on_simulation) key_press_local = getch();
else key_press_local = key_press;
switch (key_press_local) {
case 27: return set; break;
case KEY_LEFT: switch (selected) { // Не понял как всё это работает? Не лезь!
case 0: if (set.power_of_zigzas != 0) set.power_of_zigzas--; break;
case 1: if (on_simulation) {if (set.division_zigzas != 0) set.division_zigzas--; break;}
else {if (set.lives_zigzas != 0) set.lives_zigzas--;} break;
case 2: if (on_simulation) {if (set.zigzas_division_barrier != 0) set.zigzas_division_barrier--;}
else {if (set.division_zigzas != 0) set.division_zigzas--;} break;
case 3: if (on_simulation) {if (set.add_food_zigzas != 0) set.add_food_zigzas--;}
else {if (set.zigzas_division_barrier != 0) set.zigzas_division_barrier--;} break;
case 4: if (on_simulation) {if (set.how_many_eat_zigzas != 0) set.how_many_eat_zigzas--;}
else {if (set.add_food_zigzas != 0) set.add_food_zigzas--;} break;
case 5: if (on_simulation) {if (set.angry_zigzas) set.angry_zigzas = false; else set.angry_zigzas = true;}
else {if (set.how_many_eat_zigzas != 0) set.how_many_eat_zigzas--;} break;
case 6: if (!on_simulation) {if (set.angry_zigzas) set.angry_zigzas = false; else set.angry_zigzas = true;}
else {if (set.go_to_eat_zigzas) set.go_to_eat_zigzas = false; else set.go_to_eat_zigzas = true;} break;
case 7: if (!on_simulation) {if (set.go_to_eat_zigzas) set.go_to_eat_zigzas = false; else set.go_to_eat_zigzas = true;}
else {if (set.full_logic_zigzas) set.full_logic_zigzas = false; else set.full_logic_zigzas = true;} break;
case 8: if (!on_simulation) {if (set.full_logic_zigzas) set.full_logic_zigzas = false; else set.full_logic_zigzas = true;} break;
} break;
case KEY_RIGHT: switch (selected) {
case 0: if (set.power_of_zigzas < 100) set.power_of_zigzas++; break;
case 1: if (on_simulation) {if (set.division_zigzas < 100) set.division_zigzas++; break;}
else {if (set.lives_zigzas < 100) set.lives_zigzas++;} break;
case 2: if (on_simulation) {if (set.zigzas_division_barrier < 100) set.zigzas_division_barrier++;}
else {if (set.division_zigzas < 100) set.division_zigzas++;} break;
case 3: if (on_simulation) {if (set.add_food_zigzas < 100) set.add_food_zigzas++;}
else {if (set.zigzas_division_barrier < 100) set.zigzas_division_barrier++;} break;
case 4: if (on_simulation) {if (set.how_many_eat_zigzas < 100) set.how_many_eat_zigzas++;}
else {if (set.add_food_zigzas < 100) set.add_food_zigzas++;} break;
case 5: if (on_simulation) {if (set.angry_zigzas) set.angry_zigzas = false; else set.angry_zigzas = true;}
else {if (set.how_many_eat_zigzas < 100) set.how_many_eat_zigzas++;} break;
case 6: if (!on_simulation) {if (set.angry_zigzas) set.angry_zigzas = false; else set.angry_zigzas = true;}
else {if (set.go_to_eat_zigzas) set.go_to_eat_zigzas = false; else set.go_to_eat_zigzas = true;} break;
case 7: if (!on_simulation) {if (set.go_to_eat_zigzas) set.go_to_eat_zigzas = false; else set.go_to_eat_zigzas = true;}
else {if (set.full_logic_zigzas) set.full_logic_zigzas = false; else set.full_logic_zigzas = true;} break;
case 8: if (!on_simulation) {if (set.full_logic_zigzas) set.full_logic_zigzas = false; else set.full_logic_zigzas = true;} break;
} break;
case KEY_UP: if (selected == 0) selected = 9;
else selected--;
break;
case KEY_DOWN: if (selected == 9) selected = 0;
else selected++;
break;
case 9: if (selected != 9) help(selected); break;
case '\n': if (selected == 9) return set; break;
}
if (on_simulation) break;
}
return set;
}
settings himanurs_settings(settings set, bool on_simulation, unsigned int x, unsigned int y, int selected_out, int key_press) {
int selected = 0, key_press_local, prefix = 0;
char char_angry, char_logic;
if (on_simulation) {selected = selected_out; prefix = 1;} // При симуляции не выводится один пункт, поэтому +1
while (true) {
if (!on_simulation) erase();
else attron(COLOR_PAIR(4) | A_BOLD);
if (selected == 0) mvprintw(y, x, ">"); else mvprintw(y, x, "-");
if (on_simulation) mvprintw(y, x + 1, " "); // Для ровного окошка при симуляции
mvprintw(y, x + 1, "Power of himanur's < %i%% > (%i)", set.power_of_himanurs, (set.full_lives * set.power_of_himanurs / 100));
if (!on_simulation) mvprintw(y + 1, x + 1, "Start lives of himanur's < %i%% > (%i)", set.lives_himanurs, (set.full_lives * set.lives_himanurs / 100));
if (selected == 1) mvprintw(y + 1, x, ">"); else mvprintw(y + 1, x, "-");
if (selected == (2 - prefix)) mvprintw(y + 2 - prefix, x, ">"); else mvprintw(y + 2 - prefix, x, "-");
if (on_simulation) mvprintw(y + 2 - prefix, x + 1, " "); // Для ровного окошка при симуляции
mvprintw(y + 2 - prefix, x + 1, "Division of himanur's < %i%% > (%i)", set.division_himanurs, (set.full_lives * set.division_himanurs / 100));
if (selected == (3 - prefix)) mvprintw(y + 3 - prefix, x, ">"); else mvprintw(y + 3 - prefix, x, "-");
if (on_simulation) mvprintw(y + 3 - prefix, x + 1, " "); // Для ровного окошка при симуляции
mvprintw(y + 3 - prefix, x + 1, "Division barrier < %i%% > (%i)", set.himanurs_division_barrier, (set.full_lives * set.himanurs_division_barrier / 100));
if (selected == (4 - prefix)) mvprintw(y + 4 - prefix, x, ">"); else mvprintw(y + 4 - prefix, x, "-");
if (on_simulation) mvprintw(y + 4 - prefix, x + 1, " "); // Для ровного окошка при симуляции
mvprintw(y + 4 - prefix, x + 1, "Calorie food < %i%% > (%i)", set.add_food_himanurs, (set.full_lives * set.add_food_himanurs / 100));
if (selected == (5 - prefix)) mvprintw(y + 5 - prefix, x, ">"); else mvprintw(y + 5 - prefix, x, "-");
if (on_simulation) mvprintw(y + 5 - prefix, x + 1, " "); // Для ровного окошка при симуляции
mvprintw(y + 5 - prefix, x + 1, "Calorie enemy < %i%% > (%i)", set.how_many_eat_himanurs, (set.power_of_himanurs * set.how_many_eat_himanurs / 100));
if (selected == (6 - prefix)) mvprintw(y + 6 - prefix, x, ">"); else mvprintw(y + 6 - prefix, x, "-");
if (on_simulation) mvprintw(y + 6 - prefix, x + 1, " "); // Для ровного окошка при симуляции
if (set.angry_himanurs) char_angry = 'X';
else char_angry = '-';
mvprintw(y + 6 - prefix, x + 1, "Angy < %c >", char_angry);
if (selected == (7 - prefix)) mvprintw(y + 7 - prefix, x, ">"); else mvprintw(y + 7 - prefix, x, "-");
if (on_simulation) mvprintw(y + 7 - prefix, x + 1, " "); // Для ровного окошка при симуляции
if (set.go_to_eat_himanurs) char_logic = 'X';
else char_logic = '-';
mvprintw(y + 7 - prefix, x + 1, "Go to eat < %c >", char_logic);
if (selected == (9 - prefix)) mvprintw(y + 9 - prefix, x, ">"); else mvprintw(y + 9 - prefix, x, "-");
if (set.full_logic_himanurs) char_logic = 'X';
else char_logic = '-';
if (on_simulation) mvprintw(y + 8 - prefix, x + 1, " "); // Для ровного окошка при симуляции
if (selected == 8 - prefix) mvprintw(y + 8 - prefix, x, ">"); else mvprintw(y + 8 - prefix, x, "-");
mvprintw(y + 8 - prefix, x + 1, "Tell friend about enemy < %c >", char_logic);
if (selected == 9 - prefix) mvprintw(y + 9 - prefix, x, ">"); else mvprintw(y + 9 - prefix, x, "-");
if (on_simulation) mvprintw(y + 9 - prefix, x + 1, " "); // Для ровного окошка при симуляции
mvprintw(y + 9 - prefix, x + 1, "Back");
if (on_simulation) attroff(COLOR_PAIR(4) | A_BOLD);
if (!on_simulation) key_press_local = getch();
else key_press_local = key_press;
switch (key_press_local) { /*Место для вашей шутки*/
case 27: return set; break;
case KEY_LEFT: switch (selected) {
case 0: if (set.power_of_himanurs != 0) set.power_of_himanurs--; break;
case 1: if (on_simulation) {if (set.division_himanurs != 0) set.division_himanurs--; break;}
else {if (set.lives_himanurs != 0) set.lives_himanurs--;} break;
case 2: if (on_simulation) {if (set.himanurs_division_barrier != 0) set.himanurs_division_barrier--;}
else {if (set.division_himanurs != 0) set.division_himanurs--;} break;
case 3: if (on_simulation) {if (set.add_food_himanurs != 0) set.add_food_himanurs--;}
else {if (set.himanurs_division_barrier != 0) set.himanurs_division_barrier--;} break;
case 4: if (on_simulation) {if (set.how_many_eat_himanurs != 0) set.how_many_eat_himanurs--;}
else {if (set.add_food_himanurs != 0) set.add_food_himanurs--;} break;
case 5: if (on_simulation) {if (set.angry_himanurs) set.angry_himanurs = false; else set.angry_himanurs = true;}
else {if (set.how_many_eat_himanurs != 0) set.how_many_eat_himanurs--;} break;
case 6: if (!on_simulation) {if (set.angry_himanurs) set.angry_himanurs = false; else set.angry_himanurs = true;}
else {if (set.go_to_eat_himanurs) set.go_to_eat_himanurs = false; else set.go_to_eat_himanurs = true;} break;
case 7: if (!on_simulation) {if (set.go_to_eat_himanurs) set.go_to_eat_himanurs = false; else set.go_to_eat_himanurs = true;}
else {if (set.full_logic_himanurs) set.full_logic_himanurs = false; else set.full_logic_himanurs = true;} break;
case 8: if (!on_simulation) {if (set.full_logic_himanurs) set.full_logic_himanurs = false; else set.full_logic_himanurs = true;} break;
} break;
case KEY_RIGHT: switch (selected) {
case 0: if (set.power_of_himanurs < 100) set.power_of_himanurs++; break;
case 1: if (on_simulation) {if (set.division_himanurs < 100) set.division_himanurs++; break;}
else {if (set.lives_himanurs < 100) set.lives_himanurs++;} break;
case 2: if (on_simulation) {if (set.himanurs_division_barrier < 100) set.himanurs_division_barrier++;}
else {if (set.division_himanurs < 100) set.division_himanurs++;} break;
case 3: if (on_simulation) {if (set.add_food_himanurs < 100) set.add_food_himanurs++;}
else {if (set.himanurs_division_barrier < 100) set.himanurs_division_barrier++;} break;
case 4: if (on_simulation) {if (set.how_many_eat_himanurs < 100) set.how_many_eat_himanurs++;}
else {if (set.add_food_himanurs < 100) set.add_food_himanurs++;} break;
case 5: if (on_simulation) {if (set.angry_himanurs) set.angry_himanurs = false; else set.angry_himanurs = true;}
else {if (set.how_many_eat_himanurs < 100) set.how_many_eat_himanurs++;} break;
case 6: if (!on_simulation) {if (set.angry_himanurs) set.angry_himanurs = false; else set.angry_himanurs = true;}
else {if (set.go_to_eat_himanurs) set.go_to_eat_himanurs = false; else set.go_to_eat_himanurs = true;} break;
case 7: if (!on_simulation) {if (set.go_to_eat_himanurs) set.go_to_eat_himanurs = false; else set.go_to_eat_himanurs = true;}
else {if (set.full_logic_himanurs) set.full_logic_himanurs = false; else set.full_logic_himanurs = true;} break;
case 8: if (!on_simulation) {if (set.full_logic_himanurs) set.full_logic_himanurs = false; else set.full_logic_himanurs = true;} break;
} break;
case KEY_UP: if (selected == 0) selected = 9;
else selected--;
break;
case KEY_DOWN: if (selected == 9) selected = 0;
else selected++;
break;
case 9: if (selected != 9) help(selected); erase(); break;
case '\n': if (selected == 9) return set; break;
}
if (on_simulation) break;
}
return set;
}
settings float_settings(settings set, unsigned int x, unsigned int y, int selected, int key_press) {
attron(COLOR_PAIR(4) | A_BOLD);
if (selected == 0) mvprintw(y, x, ">"); else mvprintw(y, x, "-");
mvprintw(y, x + 1, " "); // Для ровного окошка при симуляции
mvprintw(y, x + 1, "Lives < %i >", set.full_lives);
if (selected == 1) mvprintw(y + 1, x, ">"); else mvprintw(y + 1, x, "-");
mvprintw(y + 1, x + 1, " "); // Для ровного окошка при симуляции
mvprintw(y + 1, x + 1, "Delay < %ims >", set.bac_delay);
if (selected == 2) mvprintw(y + 2, x, ">"); else mvprintw(y + 2, x, "-");
mvprintw(y + 2, x + 1, " "); // Для ровного окошка при симуляции
mvprintw(y + 2, x + 1, "During addition of food < %i >", set.eat_add);
if (selected == 3) mvprintw(y + 3, x, ">"); else mvprintw(y + 3, x, "-");
mvprintw(y + 3, x + 1, " "); // Для ровного окошка при симуляции
mvprintw(y + 3, x + 1, "Eat probability < %i >", set.eat_probability);
if (selected == 4) mvprintw(y + 4, x, ">"); else mvprintw(y + 4, x, "-");
mvprintw(y + 4, x + 1, " "); // Для ровного окошка при симуляции
mvprintw(y + 4, x + 1, "Settings zigza's");
if (selected == 5) mvprintw(y + 5, x, ">"); else mvprintw(y + 5, x, "-");
mvprintw(y + 5, x + 1, " "); // Для ровного окошка при симуляции
mvprintw(y + 5, x + 1, "Settings himanur's");
if (selected == 6) mvprintw(y + 6, x, ">"); else mvprintw(y + 6, x, "-");
mvprintw(y + 6, x + 1, " "); // Для ровного окошка при симуляции
mvprintw(y + 6, x + 1, "Load configuration file");
if (selected == 7) mvprintw(y + 7, x, ">"); else mvprintw(y + 7, x, "-");
mvprintw(y + 7, x + 1, " "); // Для ровного окошка при симуляции
mvprintw(y + 7, x + 1, "Windows position (X) < %i >", x);
if (selected == 8) mvprintw(y + 8, x, ">"); else mvprintw(y + 8, x, "-");
mvprintw(y + 8, x + 1, " "); // Для ровного окошка при симуляции
mvprintw(y + 8, x + 1, "Windows position (Y) < %i >", y);
if (selected == 9) mvprintw(y + 9, x, ">"); else mvprintw(y + 9, x, "-");
mvprintw(y + 9, x + 1, " "); // Для ровного окошка при симуляции
mvprintw(y + 9, x + 1, "Close");
attroff(COLOR_PAIR(4) | A_BOLD);
switch (key_press) {
case KEY_LEFT: switch (selected) {
case 0: if (set.full_lives <= 50) set.full_lives = 999;
else set.full_lives--;
break;
case 1: if (set.bac_delay == 0) set.bac_delay = 500;
else set.bac_delay -= 10;
break;
case 2: if (set.eat_add <= 0) set.eat_add = 999;
else set.eat_add--;
break;
case 3: if (set.eat_probability <= 0) set.eat_probability = 100;
else set.eat_probability--;
break;
} break;
case KEY_RIGHT: switch (selected) {
case 0: if (set.full_lives >= 999) set.full_lives = 50;
else set.full_lives++;
break;
case 1: if (set.bac_delay >= 500) set.bac_delay = 0;
else set.bac_delay += 10;
break;
case 2: if (set.eat_add >= 999) set.eat_add = 0;
else set.eat_add++;
break;
case 3: if (set.eat_probability >= 100) set.eat_probability = 0;
else set.eat_probability++;
break;
} break;
}
return set;
}
settings main_settings(settings set) {
int selected = 0, fix_num = 0;
if (set.clans_bac != 0) fix_num = 2;
else fix_num = 0;
while (true) {
timeout(-1);
erase();
if (selected == 0) printw(">"); else printw("-");
printw("Number of clans < %i >\n", set.clans_bac);
if (set.clans_bac != 0) {
if (selected == 1) printw(">"); else printw("-");
printw("Number of zigza's < %i >\n", set.num_zigzas);
if (selected == 2) printw(">"); else printw("-");
printw("Number of himanur's < %i >\n", set.num_himanurs);
}
if (selected == (1 + fix_num)) printw(">"); else printw("-");
printw("Lives < %i >\n", set.full_lives);
if (selected == (2 + fix_num)) printw(">"); else printw("-");
printw("Delay < %ims >\n", set.bac_delay);
if (selected == (3 + fix_num)) printw(">"); else printw("-");
printw("Resolution\n");
if (selected == (4 + fix_num)) printw(">"); else printw("-");
printw("During addition of food < %i >\n", set.eat_add);
if (selected == (5 + fix_num)) printw(">"); else printw("-");
printw("Eat probability < %i >\n", set.eat_probability);
if (selected == (6 + fix_num)) printw(">"); else printw("-");
printw("Settings zigza's\n");
if (selected == (7 + fix_num)) printw(">"); else printw("-");
printw("Settings himanur's\n");
if (selected == (8 + fix_num)) printw(">"); else printw("-");
printw("Load configuration file\n");
if (selected == (9 + fix_num)) printw(">"); else printw("-");
printw("Save configuration file\n");
if (selected == (10 + fix_num)) printw(">"); else printw("-");
printw("Back\n");
# if (DEBUG == 1)
if (selected == (11 + fix_num)) printw(">"); else printw("-");
printw("Debug key\n");
# endif
switch(getch()) {
case 27: return set; break;
/*case 9: if ((selected != 11) && (selected != 12)) { // ?????BUG!!!!!
if ((selected != 1) && (set.clans_bac == 0)) help(selected + 7 + fix_num);
else help(selected + 7);
} break;*/ // Вот поэтому хэлпа и не работает...
case KEY_UP:
# if (DEBUG == 1)
if (selected == 0) {
if (set.clans_bac == 0) selected = 11;
else selected = 13;
}
# else
if (selected == 0) {
if (set.clans_bac == 0) selected = 10;
else selected = 12;
}
# endif
else selected--;
break;
case KEY_DOWN:
# if (DEBUG == 1)
if ((selected == 11) && (set.clans_bac == 0)) selected = 0;
else if (set.clans_bac == 0) selected++;
if ((selected == 13) && (set.clans_bac != 0)) selected = 0;
else if (set.clans_bac != 0) selected++;
# else
if ((selected == 10) && (set.clans_bac == 0)) selected = 0;
else if (set.clans_bac == 0) selected++;
if ((selected == 12) && (set.clans_bac != 0)) selected = 0;
else if (set.clans_bac != 0) selected++;
# endif
break;
case KEY_LEFT: switch (selected) {
case 0: if (set.clans_bac == 0) break;
else {
set.clans_bac--;
if ((set.num_zigzas > set.num_himanurs) && (set.num_zigzas != 0)) set.num_zigzas--;
else if ((set.num_zigzas == set.num_himanurs) && (set.num_zigzas != 0)) set.num_zigzas--;
else if ((set.num_zigzas == set.num_himanurs) && (set.num_himanurs != 0)) set.num_zigzas--;
else if ((set.num_zigzas < set.num_himanurs) && (set.num_himanurs != 0)) set.num_himanurs--;
}
if (set.clans_bac == 0) fix_num = 0;
else fix_num = 2;
break;
case 1: if (set.clans_bac == 0) {
if (set.full_lives <= 50) set.full_lives = 999;
else set.full_lives--;
} else {
if ((set.num_zigzas != 0) && (set.num_himanurs != set.clans_bac)) {
set.num_zigzas--;
set.num_himanurs++;
}
} break;
case 2: if (set.clans_bac == 0) {
if (set.bac_delay == 0) set.bac_delay = 500;
else set.bac_delay -= 10;
} else {
if ((set.num_himanurs != 0) && (set.num_zigzas != set.clans_bac)) {
set.num_himanurs--;
set.num_zigzas++;
}
} break;
case 3: if (set.clans_bac != 0) {
if (set.full_lives <= 50) set.full_lives = 999;
else set.full_lives--;
} break;
case 4: if (set.clans_bac != 0) {
if (set.bac_delay == 0) set.bac_delay = 500;
else set.bac_delay -= 10;
} else {
if (set.eat_add <= 0) set.eat_add = 999;
else set.eat_add--;
} break;
case 5: if (set.clans_bac == 0) {
if (set.eat_probability <= 0) set.eat_probability = 100;
else set.eat_probability--;
} break;
case 6: if (set.clans_bac != 0) {
if (set.eat_add <= 0) set.eat_add = 999;
else set.eat_add--;
} break;
case 7: if (set.clans_bac != 0) {
if (set.eat_probability <= 0) set.eat_probability = 100;
else set.eat_probability--;
} break;
} break;
case KEY_RIGHT: switch (selected) {
case 0: if (set.clans_bac == 15) break;
else {
set.clans_bac++;
if ((set.num_zigzas > set.num_himanurs) && (set.num_zigzas < set.clans_bac)) set.num_zigzas++;
if ((set.num_zigzas == set.num_himanurs) && (set.num_zigzas < set.clans_bac)) set.num_zigzas++;
if ((set.num_zigzas < set.num_himanurs) && (set.num_himanurs < set.clans_bac)) set.num_himanurs++;
}
if (set.clans_bac == 0) fix_num = 0;
else fix_num = 2;
break;
case 1: if (set.clans_bac == 0) {
if (set.full_lives >= 999) set.full_lives = 50;
else set.full_lives++;
} else {
if ((set.num_himanurs != 0) && (set.num_zigzas != set.clans_bac)) {
set.num_himanurs--;
set.num_zigzas++;
}
} break;
case 2: if (set.clans_bac == 0) {
if (set.bac_delay >= 500) set.bac_delay = 0;
else set.bac_delay += 10;
} else {
if ((set.num_zigzas != 0) && (set.num_himanurs != set.clans_bac)) {
set.num_zigzas--;
set.num_himanurs++;
}
}break;
case 3: if (set.clans_bac != 0) {
if (set.full_lives >= 999) set.full_lives = 50;
else set.full_lives++;
} break;
case 4: if (set.clans_bac == 0) {
if (set.eat_add >= 999) set.eat_add = 0;
else set.eat_add++;
} else {
if (set.bac_delay >= 500) set.bac_delay = 0;
else set.bac_delay += 10;
}
break;
case 5: if (set.clans_bac == 0) {
if (set.eat_probability >= 100) set.eat_probability = 0;
else set.eat_probability++;
} break;
case 6: if (set.clans_bac != 0) {
if (set.eat_add >= 999) set.eat_add = 0;
else set.eat_add++;
} break;
case 7: if (set.clans_bac != 0) {
if (set.eat_probability >= 100) set.eat_probability = 0;
else set.eat_probability++;
} break;
} break;
case '\n': switch (selected) {
case 3: if (set.clans_bac == 0) set = reslution_set(set); break;
case 5: if (set.clans_bac != 0) set = reslution_set(set); break;
case 6: if (set.clans_bac == 0) set = zigzas_settings(set, false, 0, 0, 0, 0); break;
case 7: if (set.clans_bac == 0) set = himanurs_settings(set, false, 0, 0, 0, 0); break;
case 8: if (set.clans_bac == 0) {
erase(); printw("Are you sure? (Enter = yes/Other key = no)\n");
if (getch() == '\n') set = load_conf(set, false);
} else set = zigzas_settings(set, false, 0, 0, 0, 0);
break;
case 9: if (set.clans_bac == 0) {
erase(); printw("Are you sure? (Enter = yes/Other key = no)\n");
if (getch() == '\n') load_conf(set, true);
} else set = himanurs_settings(set, false, 0, 0, 0, 0);
break;
case 10: if (set.clans_bac != 0) {
erase(); printw("Are you sure? (Enter = yes/Other key = no)\n");
if (getch() == '\n') set = load_conf(set, false);
} else return set;
break;
case 11: if (set.clans_bac != 0) {
erase(); printw("Are you sure? (Enter = yes/Other key = no)\n");
if (getch() == '\n') load_conf(set, true);
}
# if (DEBUG == 1)
else debug_key();
# endif
break;
case 12: if (set.clans_bac != 0) return set; break;
# if (DEBUG == 1)
case 13: if (set.clans_bac != 0) debug_key(); break;
# endif
} break;
}
}
return set;
}
bool freedom_of_bacterium(bacterium ***bacteriums, int direction, unsigned int x, unsigned int y, bool see_under_bac) { // Проверка свободы движения для бактерий
int bac_level, x_pos = 0, y_pos = 0;
if (see_under_bac) bac_level = 1; // Дочерний уровень
else bac_level = 0;
switch (direction) {
case 1: y_pos = 1; if (y == 0) return false; break;
case 2: y_pos = -1; if ((y + 1) == maxY) return false; break;
case 3: x_pos = 1; if (x == 0) return false; break;
case 4: x_pos = -1; if ((x + 1) == maxX) return false; break;
} // Нуууууу... Тут всё понятно...
if (!bacteriums[x][y][bac_level].predator) {
if ((bacteriums[(int)x - x_pos][(int)y - y_pos][bac_level].activate) && (!bacteriums[(int)x - x_pos][(int)y - y_pos][bac_level].predator)) return false;
if ((bacteriums[(int)x - x_pos][(int)y - y_pos][bac_level].activate) && (bacteriums[(int)x - x_pos][(int)y - y_pos][bac_level].predator)) return true;
if ((see_under_bac) && (!bacteriums[(int)x - x_pos][(int)y - y_pos][0].activate)) return true;
if (!bacteriums[(int)x - x_pos][(int)y - y_pos][bac_level].activate) return true;
} else {
if ((bacteriums[(int)x - x_pos][(int)y - y_pos][bac_level].activate) && (bacteriums[(int)x - x_pos][(int)y - y_pos][bac_level].predator)) return false;
if ((bacteriums[(int)x - x_pos][(int)y - y_pos][bac_level].activate) && (!bacteriums[(int)x - x_pos][(int)y - y_pos][bac_level].predator)) return true;
if ((see_under_bac) && (!bacteriums[(int)x - x_pos][(int)y - y_pos][0].activate)) return true;
if (!bacteriums[(int)x - x_pos][(int)y - y_pos][bac_level].activate) return true;
}
return false;
}
int get_eat(bacterium ***bacteriums, const unsigned int x, const unsigned int y, bool see_under_bac) { // Шаг к еде
int rand_step_count = 4, rand_step;
while (rand_step_count > 0) {
rand_step = rand_local(1, rand_step_count);
if (freedom_of_bacterium(bacteriums, rand_step, x, y, see_under_bac)) {
switch (rand_step) {
case 1: if ((!bacteriums[x][y - 1][0].activate) && (bacteriums[x][y - 1][0].eat)) return 1; break;
case 2: if ((!bacteriums[x][y + 1][0].activate) && (bacteriums[x][y + 1][0].eat)) return 2; break;
case 3: if ((!bacteriums[x - 1][y][0].activate) && (bacteriums[x - 1][y][0].eat)) return 3; break;
case 4: if ((!bacteriums[x + 1][y][0].activate) && (bacteriums[x + 1][y][0].eat)) return 4; break;
}
if (rand_step_count == rand_step) rand_step_count--;
} else if (rand_step_count == rand_step) rand_step_count--;
}
return 0; // Если поблизости еды не найденойдено, то вернуть 0
}
bool birth(bacterium ***bacteriums, settings set, const unsigned int x, const unsigned int y, bool see_under_bac) { // Деление
int bac_level = 0, other_bac_level = 1, x_pos = 0, y_pos = 0;
if (see_under_bac) bac_level = 1;
if (bacteriums[x][y][bac_level].predator) {
if (bacteriums[x][y][bac_level].half_life < (int)(set.full_lives * set.zigzas_division_barrier / 100)) return false; // Если кол-во жизней меньше, чем заданное процентнов от макс. жизней, то не делиться
} else {
if (bacteriums[x][y][bac_level].half_life < (int)(set.full_lives * set.himanurs_division_barrier / 100)) return false; // Если кол-во жизней меньше, чем заданное процентнов от макс. жизней, то не делиться
}
int rand_step = rand_local(1, 4); // Выбор рандомной позиции
int rand_step_count = 4; // Защита от бесконечного поиска пустой клетки
while (!freedom_of_bacterium(bacteriums, rand_step, x, y, see_under_bac)) {
if (rand_step_count == rand_step) rand_step_count--;
rand_step = rand_local(1, rand_step_count);
if (rand_step_count <= 0) { // Если свободного места не найдено - то стоять на месте
bacteriums[x][y][bac_level].time_birth++;
rand_step = 0;
break;
}
}
switch (rand_step) {
case 1: y_pos = 1; break;
case 2: y_pos = -1; break;
case 3: x_pos = 1; break;
case 4: x_pos = -1; break;
default: return false; break;
}
if (!bacteriums[(int)x - x_pos][(int)y - y_pos][0].activate) other_bac_level = 0;
bacteriums[(int)x - x_pos][(int)y - y_pos][other_bac_level].activate = true;
bacteriums[(int)x - x_pos][(int)y - y_pos][other_bac_level].id_clan = bacteriums[x][y][bac_level].id_clan;
bacteriums[(int)x - x_pos][(int)y - y_pos][other_bac_level].half_life = bacteriums[x][y][bac_level].half_life / 2;
bacteriums[(int)x - x_pos][(int)y - y_pos][other_bac_level].half_life = bacteriums[x][y][bac_level].half_life / 2;
if (bacteriums[x][y][bac_level].predator) {
bacteriums[(int)x - x_pos][(int)y - y_pos][other_bac_level].predator = true;
bacteriums[(int)x - x_pos][(int)y - y_pos][other_bac_level].time_birth = rand_local(1, set.full_lives * set.division_zigzas / 100);
bacteriums[x][y][bac_level].time_birth = rand_local(1, set.full_lives * set.division_zigzas / 100);
} else {
bacteriums[(int)x - x_pos][(int)y - y_pos][other_bac_level].predator = false;
bacteriums[(int)x - x_pos][(int)y - y_pos][other_bac_level].time_birth = rand_local(1, set.full_lives * set.division_himanurs / 100);
bacteriums[x][y][bac_level].time_birth = rand_local(1, set.full_lives * set.division_himanurs / 100);
}
return true;
}